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