]> Creatis software - gdcm.git/blob - src/gdcmDicomDir.h
f51c9f4cd0a8b4d8e3a1e5c73fe659d7241673b1
[gdcm.git] / src / gdcmDicomDir.h
1 /*=========================================================================
2   
3   Program:   gdcm
4   Module:    $RCSfile: gdcmDicomDir.h,v $
5   Language:  C++
6   Date:      $Date: 2005/07/21 05:02:11 $
7   Version:   $Revision: 1.66 $
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 public:
54    typedef void Method(void*);
55
56    DicomDir(); 
57    GDCM_LEGACY( DicomDir(std::string const &filename, bool parseDir = false) ); 
58    ~DicomDir();
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                            DicomDir::Method *argDelete = NULL );
100    void SetProgressMethod( DicomDir::Method *method, 
101                            void *arg = NULL,
102                            DicomDir::Method *argDelete = NULL );
103    void SetEndMethod(      DicomDir::Method *method,
104                            void *arg = NULL, 
105                            DicomDir::Method *argDelete = NULL );
106    void SetStartMethodArgDelete   ( DicomDir::Method *m );
107    void SetProgressMethodArgDelete( DicomDir::Method *m );
108    void SetEndMethodArgDelete     ( DicomDir::Method *m );
109
110    /// GetProgress GetProgress
111    float GetProgress()   { return Progress; }
112    /// AbortProgress AbortProgress
113    void  AbortProgress() { Abort = true; }
114    /// IsAborted IsAborted
115    bool  IsAborted() { return Abort; }
116
117    // Write
118    bool WriteDicomDir(std::string const &fileName);
119
120    bool AnonymizeDicomDir();
121
122    /// Types of the DicomDirObject within the DicomDir
123    typedef enum
124    {
125       GDCM_DICOMDIR_NONE,
126       GDCM_DICOMDIR_META,
127       GDCM_DICOMDIR_PATIENT,
128       GDCM_DICOMDIR_STUDY,
129       GDCM_DICOMDIR_SERIE,
130       GDCM_DICOMDIR_VISIT,
131       GDCM_DICOMDIR_IMAGE
132    } DicomDirType;
133    
134 protected:
135    void CreateDicomDirChainedList(std::string const &path);
136    void CallStartMethod();
137    void CallProgressMethod();
138    void CallEndMethod();
139
140 private:
141    void Initialize();
142    void CreateDicomDir();
143    bool DoTheLoadingJob();
144    bool AddPatientToEnd(DicomDirPatient *dd);
145    bool AddStudyToEnd  (DicomDirStudy *dd);
146    bool AddSerieToEnd  (DicomDirSerie *dd);
147    bool AddVisitToEnd  (DicomDirVisit *dd);
148    bool AddImageToEnd  (DicomDirImage *dd);
149
150    void SetElements(std::string const &path, VectDocument const &list);
151    void SetElement (std::string const &path, DicomDirType type,
152                     Document *header);
153    void MoveSQItem(DocEntrySet *dst, DocEntrySet *src);
154
155    static bool HeaderLessThan(Document *header1, Document *header2);
156    
157 // Variables
158
159    /// Pointer on *the* DicomDirObject 'DicomDirMeta Elements'
160    DicomDirMeta *MetaElems;
161
162    /// Chained list of DicomDirPatient (to be exploited hierarchicaly) 
163    ListDicomDirPatient Patients;
164    ListDicomDirPatient::iterator ItPatient;
165
166    /// pointer to the initialisation method for any progress bar   
167    Method *StartMethod;
168    /// pointer to the incrementation method for any progress bar
169    Method *ProgressMethod;
170    /// pointer to the termination method for any progress bar
171    Method *EndMethod;
172    /// pointer to the ??? method for any progress bar   
173    Method *StartMethodArgDelete;
174    /// pointer to the ??? method for any progress bar
175    Method* ProgressMethodArgDelete;
176    /// pointer to the ??? method for any progress bar
177    Method *EndMethodArgDelete;
178    /// pointer to the ??? for any progress bar   
179    void *StartArg;
180    /// pointer to the ??? for any progress bar
181    void *ProgressArg;
182    /// pointer to the ??? for any progress bar   
183    void *EndArg;
184    /// value of the ??? for any progress bar
185    float Progress;
186    /// value of the ??? for any progress bar   
187    bool Abort;
188    bool ParseDir;
189 };
190 } // end namespace gdcm
191 //-----------------------------------------------------------------------------
192 #endif