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