]> Creatis software - gdcm.git/blob - src/gdcmDicomDir.h
Doxygenation
[gdcm.git] / src / gdcmDicomDir.h
1 /*=========================================================================
2   
3   Program:   gdcm
4   Module:    $RCSfile: gdcmDicomDir.h,v $
5   Language:  C++
6   Date:      $Date: 2005/11/21 09:46:25 $
7   Version:   $Revision: 1.70 $
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 #include "gdcmDebug.h"
24
25 #include <list>
26 #include <vector>
27
28 namespace gdcm 
29 {
30 //-----------------------------------------------------------------------------
31 class DicomDirPatient;
32 class DicomDirMeta;
33 class DicomDirElement;
34 class DicomDirStudy;
35 class DicomDirSerie;
36 class DicomDirVisit;
37 class DicomDirImage;
38 class SQItem;
39
40 typedef std::list<DicomDirPatient *> ListDicomDirPatient;
41 typedef std::vector<Document *> VectDocument;
42
43 //-----------------------------------------------------------------------------
44 /**
45  * \brief   DicomDir defines an object representing a DICOMDIR in memory
46  *  as a tree-like structure DicomDirPatient 
47  *                            -> DicomDirStudy 
48  *                                -> DicomDirSerie
49  *                                    -> DicomDirImage
50  */
51 class GDCM_EXPORT DicomDir: public Document
52 {
53    gdcmTypeMacro(DicomDir);
54
55 public:
56 /// \brief Constructs a DicomDir with a RefCounter
57    static DicomDir *New() {return new DicomDir();}
58
59    typedef void Method(void*);
60
61    bool Load( );
62    void Print(std::ostream &os = std::cout, std::string const &indent = "" );
63    
64    /// Sets the root Directory name to parse, recursively
65    void SetDirectoryName(std::string const &dirName) 
66         { ParseDir = true; if (Filename != dirName)
67                                Filename = dirName, IsDocumentModified = true; }
68    /// Accessor to \ref Filename
69    virtual void SetFileName(std::string const &fileName) 
70                    { ParseDir = false; if (Filename != fileName)
71                               Filename = fileName, IsDocumentModified = true;}
72    
73    // Informations contained in the parser
74    virtual bool IsReadable();
75
76    // Meta
77    DicomDirMeta *NewMeta();
78    /// Returns a pointer to the DicomDirMeta for this DICOMDIR. 
79    DicomDirMeta *GetMeta() { return MetaElems; }
80
81    // Patients
82    DicomDirPatient *NewPatient();
83    void ClearPatient();
84
85    DicomDirPatient *GetFirstPatient();
86    DicomDirPatient *GetNextPatient();
87
88    // Parsing
89    void ParseDirectory();
90
91    // Note: the DicomDir:: namespace prefix is needed by Swig in the 
92    //       following method declarations. Refer to gdcmPython/gdcm.i
93    //       for the reasons of this unnecessary notation at C++ level.
94    void SetStartMethod(    DicomDir::Method *method,
95                            void *arg = NULL );
96    void SetProgressMethod( DicomDir::Method *method,
97                            void *arg = NULL );
98    void SetEndMethod(      DicomDir::Method *method,
99                            void *arg = NULL );
100    // Note: replace DicomDir::Method *method to void(*method)(void *) to
101    //       avoid wrapping problems with the typemap conversions
102    void SetStartMethod(    void(*method)(void *), // DicomDir::Method *method
103                            void *arg,
104                            void(*argDelete)(void *));
105    void SetProgressMethod( void(*method)(void *), // DicomDir::Method *method
106                            void *arg,
107                            void(*argDelete)(void *));
108    void SetEndMethod(      void(*method)(void *), // DicomDir::Method *method
109                            void *arg, 
110                            void(*argDelete)(void *));
111    void SetStartMethodArgDelete   ( DicomDir::Method *method );
112    void SetProgressMethodArgDelete( DicomDir::Method *method );
113    void SetEndMethodArgDelete     ( DicomDir::Method *method );
114
115    /// GetProgress GetProgress
116    float GetProgress()   { return Progress; }
117    /// AbortProgress AbortProgress
118    void  AbortProgress() { Abort = true; }
119    /// IsAborted IsAborted
120    bool  IsAborted() { return Abort; }
121
122    // Write
123    bool Write(std::string const &fileName);
124
125    bool Anonymize();
126
127    /// Types of the DicomDirObject within the DicomDir
128    typedef enum
129    {
130       GDCM_DICOMDIR_NONE,
131       GDCM_DICOMDIR_META,
132       GDCM_DICOMDIR_PATIENT,
133       GDCM_DICOMDIR_STUDY,
134       GDCM_DICOMDIR_SERIE,
135       GDCM_DICOMDIR_VISIT,
136       GDCM_DICOMDIR_IMAGE
137    } DicomDirType;
138    
139 protected:
140    DicomDir(); 
141    ~DicomDir();
142
143    void CreateDicomDirChainedList(std::string const &path);
144    void CallStartMethod();
145    void CallProgressMethod();
146    void CallEndMethod();
147
148 private:
149    void Initialize();
150    void CreateDicomDir();
151    bool DoTheLoadingJob();
152    bool AddPatientToEnd(DicomDirPatient *dd);
153    bool AddStudyToEnd  (DicomDirStudy *dd);
154    bool AddSerieToEnd  (DicomDirSerie *dd);
155    bool AddVisitToEnd  (DicomDirVisit *dd);
156    bool AddImageToEnd  (DicomDirImage *dd);
157
158    void SetElements(std::string const &path, VectDocument const &list);
159    void SetElement (std::string const &path, DicomDirType type,
160                     Document *header);
161    void MoveSQItem(DocEntrySet *dst, DocEntrySet *src);
162
163    static bool HeaderLessThan(Document *header1, Document *header2);
164    
165 // Variables
166
167    /// Pointer on *the* DicomDirObject 'DicomDirMeta Elements'
168    DicomDirMeta *MetaElems;
169
170    /// Chained list of DicomDirPatient (to be exploited hierarchicaly) 
171    ListDicomDirPatient Patients;
172    ListDicomDirPatient::iterator ItPatient;
173
174    /// pointer to the initialisation method for any progress bar   
175    Method *StartMethod;
176    /// pointer to the incrementation method for any progress bar
177    Method *ProgressMethod;
178    /// pointer to the termination method for any progress bar
179    Method *EndMethod;
180    /// pointer to the ??? method for any progress bar   
181    Method *StartMethodArgDelete;
182    /// pointer to the ??? method for any progress bar
183    Method* ProgressMethodArgDelete;
184    /// pointer to the ??? method for any progress bar
185    Method *EndMethodArgDelete;
186    /// pointer to the ??? for any progress bar   
187    void *StartArg;
188    /// pointer to the ??? for any progress bar
189    void *ProgressArg;
190    /// pointer to the ??? for any progress bar   
191    void *EndArg;
192    /// value of the ??? for any progress bar
193    float Progress;
194    /// value of the ??? for any progress bar   
195    bool Abort;
196    bool ParseDir;
197 };
198 } // end namespace gdcm
199 //-----------------------------------------------------------------------------
200 #endif