]> Creatis software - gdcm.git/blob - src/gdcmDicomDir.h
Add the VISIT object within DicomDir
[gdcm.git] / src / gdcmDicomDir.h
1 /*=========================================================================
2   
3   Program:   gdcm
4   Module:    $RCSfile: gdcmDicomDir.h,v $
5   Language:  C++
6   Date:      $Date: 2005/07/08 19:07:12 $
7   Version:   $Revision: 1.63 $
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 DicomDirVisit;
36 class DicomDirImage;
37 class SQItem;
38
39 typedef std::list<DicomDirPatient *>   ListDicomDirPatient;
40 typedef std::vector<Document *>  VectDocument;
41
42 //-----------------------------------------------------------------------------
43 /**
44  * \brief   DicomDir defines an object representing a DICOMDIR in memory
45  *  as a tree-like structure DicomDirPatient 
46  *                            -> DicomDirStudy 
47  *                                -> DicomDirSerie
48  *                                    -> DicomDirImage
49  */
50 class GDCM_EXPORT DicomDir: public Document
51 {
52 public:
53    typedef void Method(void*);
54
55    DicomDir( std::string const &filename, bool parseDir = false );
56    DicomDir(); 
57                    
58    ~DicomDir();
59
60    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    void SetParseDir(bool parseDir)  { ParseDir = 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