]> Creatis software - gdcm.git/blob - src/gdcmDicomDir.h
* Some classes inherit now from gdcm::RefCounter
[gdcm.git] / src / gdcmDicomDir.h
1 /*=========================================================================
2   
3   Program:   gdcm
4   Module:    $RCSfile: gdcmDicomDir.h,v $
5   Language:  C++
6   Date:      $Date: 2005/10/25 14:52:33 $
7   Version:   $Revision: 1.69 $
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    static DicomDir *New() {return new DicomDir();}
57
58    typedef void Method(void*);
59
60    GDCM_LEGACY( bool Load(std::string const &filename) );
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    /// DEPRECATED : use SetDirectoryName
74    GDCM_LEGACY( void SetParseDir(bool parseDir) );
75    
76    // Informations contained in the parser
77    virtual bool IsReadable();
78
79    // Meta
80    DicomDirMeta *NewMeta();
81    /// Returns a pointer to the DicomDirMeta for this DICOMDIR. 
82    DicomDirMeta *GetMeta() { return MetaElems; }
83
84    // Patients
85    DicomDirPatient *NewPatient();
86    void ClearPatient();
87
88    DicomDirPatient *GetFirstPatient();
89    DicomDirPatient *GetNextPatient();
90
91    // Parsing
92    void ParseDirectory();
93
94    // Note: the DicomDir:: namespace prefix is needed by Swig in the 
95    //       following method declarations. Refer to gdcmPython/gdcm.i
96    //       for the reasons of this unnecessary notation at C++ level.
97    void SetStartMethod(    DicomDir::Method *method,
98                            void *arg = NULL );
99    void SetProgressMethod( DicomDir::Method *method,
100                            void *arg = NULL );
101    void SetEndMethod(      DicomDir::Method *method,
102                            void *arg = NULL );
103    // Note: replace DicomDir::Method *method to void(*method)(void *) to
104    //       avoid wrapping problems with the typemap conversions
105    void SetStartMethod(    void(*method)(void *), // DicomDir::Method *method
106                            void *arg,
107                            void(*argDelete)(void *));
108    void SetProgressMethod( void(*method)(void *), // DicomDir::Method *method
109                            void *arg,
110                            void(*argDelete)(void *));
111    void SetEndMethod(      void(*method)(void *), // DicomDir::Method *method
112                            void *arg, 
113                            void(*argDelete)(void *));
114    void SetStartMethodArgDelete   ( DicomDir::Method *method );
115    void SetProgressMethodArgDelete( DicomDir::Method *method );
116    void SetEndMethodArgDelete     ( DicomDir::Method *method );
117
118    /// GetProgress GetProgress
119    float GetProgress()   { return Progress; }
120    /// AbortProgress AbortProgress
121    void  AbortProgress() { Abort = true; }
122    /// IsAborted IsAborted
123    bool  IsAborted() { return Abort; }
124
125    // Write
126    bool Write(std::string const &fileName);
127
128    bool Anonymize();
129
130    /// Types of the DicomDirObject within the DicomDir
131    typedef enum
132    {
133       GDCM_DICOMDIR_NONE,
134       GDCM_DICOMDIR_META,
135       GDCM_DICOMDIR_PATIENT,
136       GDCM_DICOMDIR_STUDY,
137       GDCM_DICOMDIR_SERIE,
138       GDCM_DICOMDIR_VISIT,
139       GDCM_DICOMDIR_IMAGE
140    } DicomDirType;
141    
142 protected:
143    DicomDir(); 
144    ~DicomDir();
145
146    void CreateDicomDirChainedList(std::string const &path);
147    void CallStartMethod();
148    void CallProgressMethod();
149    void CallEndMethod();
150
151 private:
152    void Initialize();
153    void CreateDicomDir();
154    bool DoTheLoadingJob();
155    bool AddPatientToEnd(DicomDirPatient *dd);
156    bool AddStudyToEnd  (DicomDirStudy *dd);
157    bool AddSerieToEnd  (DicomDirSerie *dd);
158    bool AddVisitToEnd  (DicomDirVisit *dd);
159    bool AddImageToEnd  (DicomDirImage *dd);
160
161    void SetElements(std::string const &path, VectDocument const &list);
162    void SetElement (std::string const &path, DicomDirType type,
163                     Document *header);
164    void MoveSQItem(DocEntrySet *dst, DocEntrySet *src);
165
166    static bool HeaderLessThan(Document *header1, Document *header2);
167    
168 // Variables
169
170    /// Pointer on *the* DicomDirObject 'DicomDirMeta Elements'
171    DicomDirMeta *MetaElems;
172
173    /// Chained list of DicomDirPatient (to be exploited hierarchicaly) 
174    ListDicomDirPatient Patients;
175    ListDicomDirPatient::iterator ItPatient;
176
177    /// pointer to the initialisation method for any progress bar   
178    Method *StartMethod;
179    /// pointer to the incrementation method for any progress bar
180    Method *ProgressMethod;
181    /// pointer to the termination method for any progress bar
182    Method *EndMethod;
183    /// pointer to the ??? method for any progress bar   
184    Method *StartMethodArgDelete;
185    /// pointer to the ??? method for any progress bar
186    Method* ProgressMethodArgDelete;
187    /// pointer to the ??? method for any progress bar
188    Method *EndMethodArgDelete;
189    /// pointer to the ??? for any progress bar   
190    void *StartArg;
191    /// pointer to the ??? for any progress bar
192    void *ProgressArg;
193    /// pointer to the ??? for any progress bar   
194    void *EndArg;
195    /// value of the ??? for any progress bar
196    float Progress;
197    /// value of the ??? for any progress bar   
198    bool Abort;
199    bool ParseDir;
200 };
201 } // end namespace gdcm
202 //-----------------------------------------------------------------------------
203 #endif