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