]> Creatis software - gdcm.git/blob - src/gdcmDicomDir.h
99d867803d9a46e646606bc032b0a77d315da754
[gdcm.git] / src / gdcmDicomDir.h
1 /*=========================================================================
2   
3   Program:   gdcm
4   Module:    $RCSfile: gdcmDicomDir.h,v $
5   Language:  C++
6   Date:      $Date: 2004/07/19 03:34:11 $
7   Version:   $Revision: 1.25 $
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.htm 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 //-----------------------------------------------------------------------------
32 typedef std::list<gdcmDicomDirPatient*>   ListDicomDirPatient;
33 typedef std::vector<gdcmDocument*>  VectDocument;
34
35 typedef GDCM_EXPORT void(gdcmMethod)(void * = NULL);
36 //-----------------------------------------------------------------------------
37
38 /**
39  * \ingroup gdcmDicomDir
40  * \brief    gdcmDicomDir defines an object representing a DICOMDIR in memory.
41  *
42  */
43 class GDCM_EXPORT gdcmDicomDir: public gdcmDocument
44 {
45 public:
46    gdcmDicomDir(std::string const & fileName, 
47                 bool parseDir = false,
48                 bool exception_on_error = false);
49    gdcmDicomDir(bool exception_on_error = false); 
50                    
51    ~gdcmDicomDir();
52
53    /// \brief   canonical Printer 
54    /// \sa    SetPrintLevel
55    virtual void Print(std::ostream &os = std::cout);
56
57 // Informations contained in the parser
58    virtual bool IsReadable();
59
60    /// Returns a pointer to the gdcmDicomDirMeta for this DICOMDIR. 
61    gdcmDicomDirMeta* GetDicomDirMeta() { return metaElems; };
62
63    /// Returns the PATIENT chained List for this DICOMDIR.    
64    ListDicomDirPatient &GetDicomDirPatients() { return patients; };
65
66 // Parsing
67    void ParseDirectory();
68    
69    void SetStartMethod(gdcmMethod *,void * =NULL,gdcmMethod * =NULL);
70    void SetStartMethodArgDelete(gdcmMethod *);
71    void SetProgressMethod(gdcmMethod *,void * =NULL,gdcmMethod * =NULL);
72    void SetProgressMethodArgDelete(gdcmMethod *);
73    void SetEndMethod(gdcmMethod *,void * =NULL,gdcmMethod * =NULL);
74    void SetEndMethodArgDelete(gdcmMethod *);
75
76    /// GetProgress GetProgress
77    float GetProgress()  { return progress; };
78
79    /// AbortProgress AbortProgress
80    void  AbortProgress() { abort = true; };
81
82    /// IsAborted IsAborted
83    bool  IsAborted() { return abort; };
84    
85 // Adding
86    gdcmDicomDirMeta*    NewMeta();
87    gdcmDicomDirPatient* NewPatient();
88
89 // Write
90    void WriteEntries(FILE *_fp);   
91    bool Write(std::string const & fileName);
92
93    /// Types of the gdcmObject within the gdcmDicomDir
94    typedef enum
95    {
96       GDCM_DICOMDIR_NONE,
97       GDCM_DICOMDIR_META,
98       GDCM_DICOMDIR_PATIENT,
99       GDCM_DICOMDIR_STUDY,
100       GDCM_DICOMDIR_SERIE,
101       GDCM_DICOMDIR_IMAGE,
102    } gdcmDicomDirType;
103    
104 protected:
105    void CreateDicomDirChainedList(std::string const & path);
106    void CallStartMethod();
107    void CallProgressMethod();
108    void CallEndMethod();
109
110 private:
111    void Initialize();
112    void CreateDicomDir();
113    void AddDicomDirMeta();
114    void AddDicomDirPatientToEnd(gdcmSQItem *s);
115    void AddDicomDirStudyToEnd  (gdcmSQItem *s);
116    void AddDicomDirSerieToEnd  (gdcmSQItem *s);
117    void AddDicomDirImageToEnd  (gdcmSQItem *s);
118
119    void SetElements(std::string &path, VectDocument &list);
120    void SetElement (std::string &path,gdcmDicomDirType type,
121                     gdcmDocument *header);
122    
123    void UpdateDirectoryRecordSequenceLength();
124
125    static bool HeaderLessThan(gdcmDocument *header1,gdcmDocument *header2);
126    
127 // Variables
128
129    /// Pointer on *the* gdcmObject 'DicomDirMeta Elements'
130    gdcmDicomDirMeta *metaElems;
131
132    /// Chained list of DicomDirPatient (to be exploited recursively) 
133    ListDicomDirPatient patients;
134
135 /// pointer to the initialisation method for any progress bar   
136    gdcmMethod *startMethod;
137 /// pointer to the incrementation method for any progress bar
138     gdcmMethod *progressMethod;
139 /// pointer to the termination method for any progress bar
140    gdcmMethod *endMethod;
141 /// pointer to the ??? method for any progress bar   
142    gdcmMethod *startMethodArgDelete;
143 /// pointer to the ??? method for any progress bar
144    gdcmMethod *progressMethodArgDelete;
145 /// pointer to the ??? method for any progress bar
146    gdcmMethod *endMethodArgDelete;
147 /// pointer to the ??? for any progress bar   
148    void *startArg;
149 /// pointer to the ??? for any progress bar
150    void *progressArg;
151 /// pointer to the ??? for any progress bar   
152    void *endArg;
153 /// value of the ??? for any progress bar
154    float progress;
155 /// value of the ??? for any progress bar   
156    bool abort;
157 };
158
159 //-----------------------------------------------------------------------------
160 #endif