]> Creatis software - gdcm.git/blob - src/gdcmDicomDir.h
ENH: * Huge cleanup:
[gdcm.git] / src / gdcmDicomDir.h
1 /*=========================================================================
2   
3   Program:   gdcm
4   Module:    $RCSfile: gdcmDicomDir.h,v $
5   Language:  C++
6   Date:      $Date: 2004/12/03 20:16:57 $
7   Version:   $Revision: 1.41 $
8   
9   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10   l'Image). All rights reserved. See Doc/License.txt or
11   http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
12   
13      This software is distributed WITHOUT ANY WARRANTY; without even
14      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15      PURPOSE.  See the above copyright notices for more information.
16   
17 =========================================================================*/
18
19 #ifndef GDCMDICOMDIR_H
20 #define GDCMDICOMDIR_H
21
22 #include "gdcmDocument.h"
23
24 #include <list>
25 #include <vector>
26
27 namespace gdcm 
28 {
29 //-----------------------------------------------------------------------------
30 class DicomDirPatient;
31 class DicomDirMeta;
32 class DicomDirElement;
33 class DicomDirStudy;
34 class DicomDirSerie;
35 class DicomDirImage;
36 class SQItem;
37
38 typedef std::list<DicomDirPatient*>   ListDicomDirPatient;
39 typedef std::vector<Document*>  VectDocument;
40
41 //-----------------------------------------------------------------------------
42
43 /**
44  * \ingroup DicomDir
45  * \brief    DicomDir defines an object representing a DICOMDIR in memory.
46  *
47  */
48 class GDCM_EXPORT DicomDir: public Document
49 {
50 public:
51    typedef void(Method)(void*);
52
53    DicomDir( std::string const & filename, bool parseDir = false );
54    DicomDir(); 
55                    
56    ~DicomDir();
57
58    /// \brief   canonical Printer 
59    /// \sa    SetPrintLevel
60    void Print(std::ostream &os = std::cout);
61
62    /// Informations contained in the parser
63    virtual bool IsReadable();
64
65    /// Returns a pointer to the DicomDirMeta for this DICOMDIR. 
66    DicomDirMeta* GetDicomDirMeta() { return MetaElems; };
67
68    /// Returns the PATIENT chained List for this DICOMDIR.    
69    ListDicomDirPatient const & GetDicomDirPatients() const { return Patients; };
70
71    /// Parsing
72    void ParseDirectory();
73    
74    // Note: the DicomDir:: namespace prefix is needed by Swig in the 
75    //       following method declarations. Refer to gdcmPython/gdcm.i
76    //       for the reasons of this unecessary notation at C++ level.
77    void SetStartMethod(    DicomDir::Method*,
78                            void* = NULL,
79                            DicomDir::Method* = NULL );
80    void SetProgressMethod( DicomDir::Method*, 
81                            void* = NULL,
82                            DicomDir::Method* = NULL );
83    void SetEndMethod(      DicomDir::Method*,
84                            void* = NULL, 
85                            DicomDir::Method* = NULL );
86    void SetStartMethodArgDelete( DicomDir::Method* );
87    void SetProgressMethodArgDelete( DicomDir::Method* );
88    void SetEndMethodArgDelete( DicomDir::Method* );
89
90    /// GetProgress GetProgress
91    float GetProgress()  { return Progress; };
92
93    /// AbortProgress AbortProgress
94    void  AbortProgress() { Abort = true; };
95
96    /// IsAborted IsAborted
97    bool  IsAborted() { return Abort; };
98    
99    /// Adding
100    DicomDirMeta*    NewMeta();
101    DicomDirPatient* NewPatient();
102
103    /// Write  
104    bool WriteDicomDir(std::string const & fileName);
105
106    /// Types of the DicomDirObject within the DicomDir
107    typedef enum
108    {
109       GDCM_DICOMDIR_NONE,
110       GDCM_DICOMDIR_META,
111       GDCM_DICOMDIR_PATIENT,
112       GDCM_DICOMDIR_STUDY,
113       GDCM_DICOMDIR_SERIE,
114       GDCM_DICOMDIR_IMAGE
115    } DicomDirType;
116    
117 protected:
118    void CreateDicomDirChainedList(std::string const & path);
119    void CallStartMethod();
120    void CallProgressMethod();
121    void CallEndMethod();
122
123 private:
124    void Initialize();
125    void CreateDicomDir();
126
127    bool AddDicomDirMeta();
128    bool AddDicomDirPatientToEnd(DicomDirPatient* dd);
129    bool AddDicomDirStudyToEnd  (DicomDirStudy* dd);
130    bool AddDicomDirSerieToEnd  (DicomDirSerie* dd);
131    bool AddDicomDirImageToEnd  (DicomDirImage* dd);
132
133    void SetElements(std::string const & path, VectDocument const &list);
134    void SetElement (std::string const & path, DicomDirType type,
135                     Document* header);
136    void MoveSQItem(SQItem* dst,SQItem *src);
137
138    static bool HeaderLessThan(Document* header1, Document* header2);
139    
140 // Variables
141
142    /// Pointer on *the* DicomDirObject 'DicomDirMeta Elements'
143    DicomDirMeta* MetaElems;
144
145    /// Chained list of DicomDirPatient (to be exploited recursively) 
146    ListDicomDirPatient Patients;
147
148    /// pointer to the initialisation method for any progress bar   
149    Method* StartMethod;
150    /// pointer to the incrementation method for any progress bar
151    Method* ProgressMethod;
152    /// pointer to the termination method for any progress bar
153    Method* EndMethod;
154    /// pointer to the ??? method for any progress bar   
155    Method* StartMethodArgDelete;
156    /// pointer to the ??? method for any progress bar
157    Method* ProgressMethodArgDelete;
158    /// pointer to the ??? method for any progress bar
159    Method* EndMethodArgDelete;
160    /// pointer to the ??? for any progress bar   
161    void* StartArg;
162    /// pointer to the ??? for any progress bar
163    void* ProgressArg;
164    /// pointer to the ??? for any progress bar   
165    void* EndArg;
166    /// value of the ??? for any progress bar
167    float Progress;
168    /// value of the ??? for any progress bar   
169    bool Abort;
170 };
171 } // end namespace gdcm
172 //-----------------------------------------------------------------------------
173 #endif