]> Creatis software - gdcm.git/blob - src/gdcmDicomDir.h
c77f91a521781a529416f8b602a63ca5057142df
[gdcm.git] / src / gdcmDicomDir.h
1 /*=========================================================================
2   
3   Program:   gdcm
4   Module:    $RCSfile: gdcmDicomDir.h,v $
5   Language:  C++
6   Date:      $Date: 2004/11/16 10:25:53 $
7   Version:   $Revision: 1.39 $
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 "gdcmCommon.h"
23 #include "gdcmDocument.h"
24 #include "gdcmDicomDirPatient.h"
25 #include "gdcmDicomDirMeta.h"
26 #include "gdcmDicomDirElement.h"
27
28 #include <list>
29 #include <vector>
30
31 namespace gdcm 
32 {
33 //-----------------------------------------------------------------------------
34 typedef std::list<DicomDirPatient*>   ListDicomDirPatient;
35 typedef std::vector<Document*>  VectDocument;
36
37 //-----------------------------------------------------------------------------
38
39 /**
40  * \ingroup DicomDir
41  * \brief    DicomDir defines an object representing a DICOMDIR in memory.
42  *
43  */
44 class GDCM_EXPORT DicomDir: public Document
45 {
46 public:
47    typedef void(Method)(void*);
48
49    DicomDir( std::string const & filename, bool parseDir = false );
50    DicomDir(); 
51                    
52    ~DicomDir();
53
54    /// \brief   canonical Printer 
55    /// \sa    SetPrintLevel
56    void Print(std::ostream &os = std::cout);
57
58    /// Informations contained in the parser
59    virtual bool IsReadable();
60
61    /// Returns a pointer to the DicomDirMeta for this DICOMDIR. 
62    DicomDirMeta* GetDicomDirMeta() { return MetaElems; };
63
64    /// Returns the PATIENT chained List for this DICOMDIR.    
65    ListDicomDirPatient const & GetDicomDirPatients() const { return Patients; };
66
67    /// Parsing
68    void ParseDirectory();
69    
70    // Note: the DicomDir:: namespace prefix is needed by Swig in the 
71    //       following method declarations. Refer to gdcmPython/gdcm.i
72    //       for the reasons of this unecessary notation at C++ level.
73    void SetStartMethod(    DicomDir::Method*,
74                            void* = NULL,
75                            DicomDir::Method* = NULL );
76    void SetProgressMethod( DicomDir::Method*, 
77                            void* = NULL,
78                            DicomDir::Method* = NULL );
79    void SetEndMethod(      DicomDir::Method*,
80                            void* = NULL, 
81                            DicomDir::Method* = NULL );
82    void SetStartMethodArgDelete( DicomDir::Method* );
83    void SetProgressMethodArgDelete( DicomDir::Method* );
84    void SetEndMethodArgDelete( DicomDir::Method* );
85
86    /// GetProgress GetProgress
87    float GetProgress()  { return Progress; };
88
89    /// AbortProgress AbortProgress
90    void  AbortProgress() { Abort = true; };
91
92    /// IsAborted IsAborted
93    bool  IsAborted() { return Abort; };
94    
95    /// Adding
96    DicomDirMeta*    NewMeta();
97    DicomDirPatient* NewPatient();
98
99    /// Write  
100    bool WriteDicomDir(std::string const & fileName);
101
102    /// Types of the DicomDirObject within the DicomDir
103    typedef enum
104    {
105       GDCM_DICOMDIR_NONE,
106       GDCM_DICOMDIR_META,
107       GDCM_DICOMDIR_PATIENT,
108       GDCM_DICOMDIR_STUDY,
109       GDCM_DICOMDIR_SERIE,
110       GDCM_DICOMDIR_IMAGE
111    } DicomDirType;
112    
113 protected:
114    void CreateDicomDirChainedList(std::string const & path);
115    void CallStartMethod();
116    void CallProgressMethod();
117    void CallEndMethod();
118
119 private:
120    void Initialize();
121    void CreateDicomDir();
122    void AddDicomDirMeta();
123    void AddDicomDirPatientToEnd(SQItem* s);
124    void AddDicomDirStudyToEnd  (SQItem* s);
125    void AddDicomDirSerieToEnd  (SQItem* s);
126    void AddDicomDirImageToEnd  (SQItem* s);
127
128    void SetElements(std::string const & path, VectDocument const &list);
129    void SetElement (std::string const & path, DicomDirType type,
130                     Document* header);
131
132    static bool HeaderLessThan(Document* header1, Document* header2);
133    
134 // Variables
135
136    /// Pointer on *the* DicomDirObject 'DicomDirMeta Elements'
137    DicomDirMeta* MetaElems;
138
139    /// Chained list of DicomDirPatient (to be exploited recursively) 
140    ListDicomDirPatient Patients;
141
142    /// pointer to the initialisation method for any progress bar   
143    Method* StartMethod;
144    /// pointer to the incrementation method for any progress bar
145    Method* ProgressMethod;
146    /// pointer to the termination method for any progress bar
147    Method* EndMethod;
148    /// pointer to the ??? method for any progress bar   
149    Method* StartMethodArgDelete;
150    /// pointer to the ??? method for any progress bar
151    Method* ProgressMethodArgDelete;
152    /// pointer to the ??? method for any progress bar
153    Method* EndMethodArgDelete;
154    /// pointer to the ??? for any progress bar   
155    void* StartArg;
156    /// pointer to the ??? for any progress bar
157    void* ProgressArg;
158    /// pointer to the ??? for any progress bar   
159    void* EndArg;
160    /// value of the ??? for any progress bar
161    float Progress;
162    /// value of the ??? for any progress bar   
163    bool Abort;
164 };
165 } // end namespace gdcm
166 //-----------------------------------------------------------------------------
167 #endif