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