]> Creatis software - gdcm.git/blob - src/gdcmDicomDir.h
On the way to gdcm2 ...
[gdcm.git] / src / gdcmDicomDir.h
1 /*=========================================================================
2   
3   Program:   gdcm
4   Module:    $RCSfile: gdcmDicomDir.h,v $
5   Language:  C++
6   Date:      $Date: 2005/07/07 16:37:41 $
7   Version:   $Revision: 1.61 $
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  * \brief   DicomDir defines an object representing a DICOMDIR in memory
44  *  as a tree-like structure DicomDirPatient 
45  *                            -> DicomDirStudy 
46  *                                -> DicomDirSerie
47  *                                    -> DicomDirImage
48  */
49 class GDCM_EXPORT DicomDir: public Document
50 {
51 public:
52    typedef void Method(void*);
53
54    DicomDir( std::string const &filename, bool parseDir = false );
55    DicomDir(); 
56                    
57    ~DicomDir();
58
59    bool Load( std::string const &filename );
60    bool Load( );
61    void Print(std::ostream &os = std::cout, std::string const &indent = "" );
62
63    void SetParseDir(bool parseDir)  { ParseDir = parseDir; };
64    // Informations contained in the parser
65    virtual bool IsReadable();
66
67    // Meta
68    DicomDirMeta *NewMeta();
69    /// Returns a pointer to the DicomDirMeta for this DICOMDIR. 
70    DicomDirMeta *GetMeta() { return MetaElems; };
71
72    // Patients
73    DicomDirPatient *NewPatient();
74    void ClearPatient();
75
76    DicomDirPatient *GetFirstPatient();
77    DicomDirPatient *GetNextPatient();
78
79    // Parsing
80    void ParseDirectory();
81
82    // Note: the DicomDir:: namespace prefix is needed by Swig in the 
83    //       following method declarations. Refer to gdcmPython/gdcm.i
84    //       for the reasons of this unnecessary notation at C++ level.
85    void SetStartMethod(    DicomDir::Method *method,
86                            void *arg = NULL,
87                            DicomDir::Method *argDelete = NULL );
88    void SetProgressMethod( DicomDir::Method *method, 
89                            void *arg = NULL,
90                            DicomDir::Method *argDelete = NULL );
91    void SetEndMethod(      DicomDir::Method *method,
92                            void *arg = NULL, 
93                            DicomDir::Method *argDelete = NULL );
94    void SetStartMethodArgDelete   ( DicomDir::Method *m );
95    void SetProgressMethodArgDelete( DicomDir::Method *m );
96    void SetEndMethodArgDelete     ( DicomDir::Method *m );
97
98    /// GetProgress GetProgress
99    float GetProgress()  { return Progress; };
100    /// AbortProgress AbortProgress
101    void  AbortProgress() { Abort = true; };
102    /// IsAborted IsAborted
103    bool  IsAborted() { return Abort; };
104
105    // Write
106    bool WriteDicomDir(std::string const &fileName);
107
108    bool AnonymizeDicomDir();
109
110    /// Types of the DicomDirObject within the DicomDir
111    typedef enum
112    {
113       GDCM_DICOMDIR_NONE,
114       GDCM_DICOMDIR_META,
115       GDCM_DICOMDIR_PATIENT,
116       GDCM_DICOMDIR_STUDY,
117       GDCM_DICOMDIR_SERIE,
118       GDCM_DICOMDIR_IMAGE
119    } DicomDirType;
120    
121 protected:
122    void CreateDicomDirChainedList(std::string const &path);
123    void CallStartMethod();
124    void CallProgressMethod();
125    void CallEndMethod();
126
127 private:
128    void Initialize();
129    void CreateDicomDir();
130    bool DoTheLoadingJob();
131    bool AddPatientToEnd(DicomDirPatient *dd);
132    bool AddStudyToEnd  (DicomDirStudy *dd);
133    bool AddSerieToEnd  (DicomDirSerie *dd);
134    bool AddImageToEnd  (DicomDirImage *dd);
135
136    void SetElements(std::string const &path, VectDocument const &list);
137    void SetElement (std::string const &path, DicomDirType type,
138                     Document *header);
139    void MoveSQItem(DocEntrySet *dst, DocEntrySet *src);
140
141    static bool HeaderLessThan(Document *header1, Document *header2);
142    
143 // Variables
144
145    /// Pointer on *the* DicomDirObject 'DicomDirMeta Elements'
146    DicomDirMeta *MetaElems;
147
148    /// Chained list of DicomDirPatient (to be exploited hierarchicaly) 
149    ListDicomDirPatient Patients;
150    ListDicomDirPatient::iterator ItPatient;
151
152    /// pointer to the initialisation method for any progress bar   
153    Method *StartMethod;
154    /// pointer to the incrementation method for any progress bar
155    Method *ProgressMethod;
156    /// pointer to the termination method for any progress bar
157    Method *EndMethod;
158    /// pointer to the ??? method for any progress bar   
159    Method *StartMethodArgDelete;
160    /// pointer to the ??? method for any progress bar
161    Method* ProgressMethodArgDelete;
162    /// pointer to the ??? method for any progress bar
163    Method *EndMethodArgDelete;
164    /// pointer to the ??? for any progress bar   
165    void *StartArg;
166    /// pointer to the ??? for any progress bar
167    void *ProgressArg;
168    /// pointer to the ??? for any progress bar   
169    void *EndArg;
170    /// value of the ??? for any progress bar
171    float Progress;
172    /// value of the ??? for any progress bar   
173    bool Abort;
174    bool ParseDir;
175 };
176 } // end namespace gdcm
177 //-----------------------------------------------------------------------------
178 #endif