]> Creatis software - gdcm.git/blob - src/gdcmDicomDir.h
* Add the Copy method in all datas
[gdcm.git] / src / gdcmDicomDir.h
1 /*=========================================================================
2   
3   Program:   gdcm
4   Module:    $RCSfile: gdcmDicomDir.h,v $
5   Language:  C++
6   Date:      $Date: 2005/11/29 12:48:46 $
7   Version:   $Revision: 1.72 $
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 "gdcmDocument.h"
23 #include "gdcmDebug.h"
24
25 #include <list>
26 #include <vector>
27
28 namespace gdcm 
29 {
30 //-----------------------------------------------------------------------------
31 class DicomDirPatient;
32 class DicomDirMeta;
33 class DicomDirElement;
34 class DicomDirStudy;
35 class DicomDirSerie;
36 class DicomDirVisit;
37 class DicomDirImage;
38 class SQItem;
39
40 typedef std::list<DicomDirPatient *> ListDicomDirPatient;
41 typedef std::vector<Document *> VectDocument;
42
43 //-----------------------------------------------------------------------------
44 /**
45  * \brief   DicomDir defines an object representing a DICOMDIR in memory
46  *  as a tree-like structure DicomDirPatient 
47  *                            -> DicomDirStudy 
48  *                                -> DicomDirSerie
49  *                                    -> DicomDirImage
50  */
51 class GDCM_EXPORT DicomDir: public Document
52 {
53    gdcmTypeMacro(DicomDir);
54
55 public:
56 /// \brief Constructs a DicomDir with a RefCounter
57    static DicomDir *New() {return new DicomDir();}
58
59    bool Load( );
60    void Print(std::ostream &os = std::cout, std::string const &indent = "" );
61    
62    /// Sets the root Directory name to parse, recursively
63    void SetDirectoryName(std::string const &dirName) 
64         { ParseDir = true; if (Filename != dirName)
65                                Filename = dirName, IsDocumentModified = true; }
66    /// Accessor to \ref Filename
67    virtual void SetFileName(std::string const &fileName) 
68                    { ParseDir = false; if (Filename != fileName)
69                               Filename = fileName, IsDocumentModified = true;}
70    
71    // Informations contained in the parser
72    virtual bool IsReadable();
73
74    // Meta
75    DicomDirMeta *NewMeta();
76    /// Returns a pointer to the DicomDirMeta for this DICOMDIR. 
77    DicomDirMeta *GetMeta() { return MetaElems; }
78
79    // Patients
80    DicomDirPatient *NewPatient();
81    void ClearPatient();
82
83    DicomDirPatient *GetFirstPatient();
84    DicomDirPatient *GetNextPatient();
85
86    // Parsing
87    void ParseDirectory();
88
89    /// GetProgress GetProgress
90    float GetProgress() const { return Progress; }
91    /// AbortProgress AbortProgress
92    void  AbortProgress() { Abort = true; }
93    /// IsAborted IsAborted
94    bool  IsAborted() { return Abort; }
95
96    // Write
97    bool Write(std::string const &fileName);
98
99    bool Anonymize();
100
101    virtual void Copy(DocEntrySet *set);
102
103    /// Types of the DicomDirObject within the DicomDir
104    typedef enum
105    {
106       GDCM_DICOMDIR_NONE,
107       GDCM_DICOMDIR_META,
108       GDCM_DICOMDIR_PATIENT,
109       GDCM_DICOMDIR_STUDY,
110       GDCM_DICOMDIR_SERIE,
111       GDCM_DICOMDIR_VISIT,
112       GDCM_DICOMDIR_IMAGE
113    } DicomDirType;
114    
115 protected:
116    DicomDir(); 
117    ~DicomDir();
118
119    void CreateDicomDirChainedList(std::string const &path);
120    void CallStartMethod();
121    void CallProgressMethod();
122    void CallEndMethod();
123
124 private:
125    void Initialize();
126    void CreateDicomDir();
127    bool DoTheLoadingJob();
128    bool AddPatientToEnd(DicomDirPatient *dd);
129    bool AddStudyToEnd  (DicomDirStudy *dd);
130    bool AddSerieToEnd  (DicomDirSerie *dd);
131    bool AddVisitToEnd  (DicomDirVisit *dd);
132    bool AddImageToEnd  (DicomDirImage *dd);
133
134    void SetElements(std::string const &path, VectDocument const &list);
135    void SetElement (std::string const &path, DicomDirType type,
136                     Document *header);
137    void MoveSQItem(DocEntrySet *dst, DocEntrySet *src);
138
139    static bool HeaderLessThan(Document *header1, Document *header2);
140    
141 // Variables
142
143    /// Pointer on *the* DicomDirObject 'DicomDirMeta Elements'
144    DicomDirMeta *MetaElems;
145
146    /// Chained list of DicomDirPatient (to be exploited hierarchicaly) 
147    ListDicomDirPatient Patients;
148    ListDicomDirPatient::iterator ItPatient;
149
150    /// value of the ??? for any progress bar
151    float Progress;
152    /// value of the ??? for any progress bar   
153    bool ParseDir;
154
155    mutable bool Abort;
156 };
157 } // end namespace gdcm
158 //-----------------------------------------------------------------------------
159 #endif