]> Creatis software - gdcm.git/blob - src/gdcmDicomDir.h
* src/gdcmDocument.cxx : Set the file pointer TP to 0 in the constructors.
[gdcm.git] / src / gdcmDicomDir.h
1 /*=========================================================================
2   
3   Program:   gdcm
4   Module:    $RCSfile: gdcmDicomDir.h,v $
5   Language:  C++
6   Date:      $Date: 2004/11/09 13:10:44 $
7   Version:   $Revision: 1.38 $
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    void SetStartMethod(    DicomDir::Method*,
71                            void* = NULL,
72                            DicomDir::Method* = NULL );
73    void SetProgressMethod( DicomDir::Method*, 
74                            void* = NULL,
75                            DicomDir::Method* = NULL );
76    void SetEndMethod(      DicomDir::Method*,
77                            void* = NULL, 
78                            DicomDir::Method* = NULL );
79    void SetStartMethodArgDelete( DicomDir::Method* );
80    void SetProgressMethodArgDelete( DicomDir::Method* );
81    void SetEndMethodArgDelete( DicomDir::Method* );
82
83    /// GetProgress GetProgress
84    float GetProgress()  { return Progress; };
85
86    /// AbortProgress AbortProgress
87    void  AbortProgress() { Abort = true; };
88
89    /// IsAborted IsAborted
90    bool  IsAborted() { return Abort; };
91    
92    /// Adding
93    DicomDirMeta*    NewMeta();
94    DicomDirPatient* NewPatient();
95
96    /// Write  
97    bool WriteDicomDir(std::string const & fileName);
98
99    /// Types of the DicomDirObject within the DicomDir
100    typedef enum
101    {
102       GDCM_DICOMDIR_NONE,
103       GDCM_DICOMDIR_META,
104       GDCM_DICOMDIR_PATIENT,
105       GDCM_DICOMDIR_STUDY,
106       GDCM_DICOMDIR_SERIE,
107       GDCM_DICOMDIR_IMAGE
108    } DicomDirType;
109    
110 protected:
111    void CreateDicomDirChainedList(std::string const & path);
112    void CallStartMethod();
113    void CallProgressMethod();
114    void CallEndMethod();
115
116 private:
117    void Initialize();
118    void CreateDicomDir();
119    void AddDicomDirMeta();
120    void AddDicomDirPatientToEnd(SQItem* s);
121    void AddDicomDirStudyToEnd  (SQItem* s);
122    void AddDicomDirSerieToEnd  (SQItem* s);
123    void AddDicomDirImageToEnd  (SQItem* s);
124
125    void SetElements(std::string const & path, VectDocument const &list);
126    void SetElement (std::string const & path, DicomDirType type,
127                     Document* header);
128
129    static bool HeaderLessThan(Document* header1, Document* header2);
130    
131 // Variables
132
133    /// Pointer on *the* DicomDirObject 'DicomDirMeta Elements'
134    DicomDirMeta* MetaElems;
135
136    /// Chained list of DicomDirPatient (to be exploited recursively) 
137    ListDicomDirPatient Patients;
138
139    /// pointer to the initialisation method for any progress bar   
140    Method* StartMethod;
141    /// pointer to the incrementation method for any progress bar
142    Method* ProgressMethod;
143    /// pointer to the termination method for any progress bar
144    Method* EndMethod;
145    /// pointer to the ??? method for any progress bar   
146    Method* StartMethodArgDelete;
147    /// pointer to the ??? method for any progress bar
148    Method* ProgressMethodArgDelete;
149    /// pointer to the ??? method for any progress bar
150    Method* EndMethodArgDelete;
151    /// pointer to the ??? for any progress bar   
152    void* StartArg;
153    /// pointer to the ??? for any progress bar
154    void* ProgressArg;
155    /// pointer to the ??? for any progress bar   
156    void* EndArg;
157    /// value of the ??? for any progress bar
158    float Progress;
159    /// value of the ??? for any progress bar   
160    bool Abort;
161 };
162 } // end namespace gdcm
163 //-----------------------------------------------------------------------------
164 #endif