]> Creatis software - gdcm.git/blob - src/gdcmDicomDir.h
* src/gdcmHeader.[cxx|h]:
[gdcm.git] / src / gdcmDicomDir.h
1 // gdcmDicomDir.h
2 //-----------------------------------------------------------------------------
3 #ifndef GDCMDICOMDIR_H
4 #define GDCMDICOMDIR_H
5
6 //#include "gdcmHeader.h"
7 #include "gdcmCommon.h"
8 #include "gdcmDocument.h"
9 #include "gdcmDicomDirPatient.h"
10 #include "gdcmDicomDirMeta.h"
11 #include "gdcmDicomDirElement.h"
12
13 #include <list>
14 #include <vector>
15
16 //-----------------------------------------------------------------------------
17 typedef std::list<gdcmDicomDirPatient *>   ListDicomDirPatient;
18 typedef std::vector<gdcmDocument *>  VectDocument;
19
20 typedef GDCM_EXPORT void(gdcmMethod)(void * = NULL);
21 //-----------------------------------------------------------------------------
22
23 /**
24  * \ingroup gdcmDicomDir
25  * \brief    gdcmDicomDir defines an object representing a DICOMDIR in memory.
26  *
27  */
28 class GDCM_EXPORT gdcmDicomDir: public gdcmDocument
29 {
30 public:
31 //   gdcmDicomDir(ListTag *l,
32 //                bool exception_on_error = false);
33    gdcmDicomDir(const char *FileName, 
34                 bool parseDir = false,
35                 bool exception_on_error = false);
36    gdcmDicomDir(bool exception_on_error = false); 
37                    
38    ~gdcmDicomDir(void);
39
40    /**
41     * \ingroup gdcmDicomDir
42     * \brief   Sets the print level for the Dicom Header 
43     * \note    0 for Light Print; 1 for 'medium' Print, 2 for Heavy
44     */
45    void SetPrintLevel(int level) 
46       { printLevel = level; };
47   /**
48     * \ingroup gdcmDicomDir
49     * \brief   canonical Printer 
50     * \sa    SetPrintLevel
51   */     
52    virtual void Print(std::ostream &os = std::cout);
53
54 // Informations contained in the parser
55    virtual bool IsReadable(void);
56
57 /// \brief   returns a pointer to the gdcmDicomDirMeta for this DICOMDIR. 
58    inline gdcmDicomDirMeta   *GetDicomDirMeta()      
59       {return metaElems;};
60
61  /// \brief   returns the PATIENT chained List for this DICOMDIR.    
62    inline ListDicomDirPatient &GetDicomDirPatients() 
63       {return patients;};
64
65 // Parsing
66    void ParseDirectory(void);
67    
68    void SetStartMethod(gdcmMethod *,void * =NULL,gdcmMethod * =NULL);
69    void SetStartMethodArgDelete(gdcmMethod *);
70    void SetProgressMethod(gdcmMethod *,void * =NULL,gdcmMethod * =NULL);
71    void SetProgressMethodArgDelete(gdcmMethod *);
72    void SetEndMethod(gdcmMethod *,void * =NULL,gdcmMethod * =NULL);
73    void SetEndMethodArgDelete(gdcmMethod *);
74
75 /// \brief GetProgress GetProgress
76    inline float GetProgress(void)  
77       {return(progress);};
78
79 /// \brief AbortProgress AbortProgress
80    inline void  AbortProgress(void)
81       {abort=true;      };
82
83 /// \brief IsAborted IsAborted
84       inline bool  IsAborted(void)
85       {return(abort);   };
86    
87 // Adding
88   gdcmDicomDirMeta *    NewMeta(void);
89   gdcmDicomDirPatient * NewPatient(void);
90
91 // Write
92    void WriteEntries(FILE *_fp);   
93    bool Write(std::string fileName);
94
95 /// Types of the gdcmObject within the gdcmDicomDir
96    typedef enum
97    {
98       GDCM_DICOMDIR_NONE,
99       GDCM_DICOMDIR_META,
100       GDCM_DICOMDIR_PATIENT,
101       GDCM_DICOMDIR_STUDY,
102       GDCM_DICOMDIR_SERIE,
103       GDCM_DICOMDIR_IMAGE,
104    } gdcmDicomDirType;
105    
106 protected:
107    void CreateDicomDirChainedList(std::string path);
108
109    void CallStartMethod(void);
110    void CallProgressMethod(void);
111    void CallEndMethod(void);
112
113 private:
114    void CreateDicomDir(void);
115 //   void AddObjectToEnd(gdcmDicomDirType type, gdcmSQItem *s);
116    void AddDicomDirMeta   ();
117    void AddDicomDirPatientToEnd(gdcmSQItem *s);
118    void AddDicomDirStudyToEnd  (gdcmSQItem *s);
119    void AddDicomDirSerieToEnd  (gdcmSQItem *s);
120    void AddDicomDirImageToEnd  (gdcmSQItem *s);
121
122    void SetElements(std::string &path, VectDocument &list);
123    void SetElement (std::string &path,gdcmDicomDirType type,
124                     gdcmDocument *header);
125    
126    void UpdateDirectoryRecordSequenceLength(void);
127
128    static bool HeaderLessThan(gdcmDocument *header1,gdcmDocument *header2);
129    
130 // Variables
131
132 /// \brief pointer on *the* gdcmObject 'DicomDirMeta Elements'
133    gdcmDicomDirMeta *metaElems;
134
135 /// \brief chained list of DicomDirPatient (to be exploited recursively) 
136    ListDicomDirPatient patients;
137
138 /// pointer to the initialisation method for any progress bar   
139    gdcmMethod *startMethod;
140 /// pointer to the incrementation method for any progress bar
141     gdcmMethod *progressMethod;
142 /// pointer to the tremination method for any progress bar
143    gdcmMethod *endMethod;
144 /// pointer to the ??? method for any progress bar   
145    gdcmMethod *startMethodArgDelete;
146 /// pointer to the ??? method for any progress bar
147    gdcmMethod *progressMethodArgDelete;
148 /// pointer to the ??? method for any progress bar
149    gdcmMethod *endMethodArgDelete;
150 /// pointer to the ??? for any progress bar   
151    void *startArg;
152 /// pointer to the ??? for any progress bar
153    void *progressArg;
154 /// pointer to the ??? for any progress bar   
155    void *endArg;
156 /// value of the ??? for any progress bar
157    float progress;
158 /// value of the ??? for any progress bar   
159    bool abort;
160 };
161
162 //-----------------------------------------------------------------------------
163 #endif