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