]> Creatis software - gdcm.git/blob - src/gdcmDicomDir.h
BUG: Do some voodoo magic do please SWIG -buggy- c++ parser
[gdcm.git] / src / gdcmDicomDir.h
1 /*=========================================================================
2   
3   Program:   gdcm
4   Module:    $RCSfile: gdcmDicomDir.h,v $
5   Language:  C++
6   Date:      $Date: 2006/05/22 14:09:45 $
7   Version:   $Revision: 1.76 $
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    GDCM_LEGACY( bool Load(std::string const &filename) )
60    bool Load( );
61    void Print(std::ostream &os = std::cout, std::string const &indent = "" );
62
63    /// Sets the root Directory name to parse, recursively
64    void SetDirectoryName(std::string const &dirName)
65         { ParseDir = true; if (Filename != dirName)
66                                Filename = dirName, IsDocumentModified = true;}
67    /// Accessor to \ref Filename
68    virtual void SetFileName(std::string const &fileName)
69                    { ParseDir = false; if (Filename != fileName)
70                               Filename = fileName, IsDocumentModified = true;}
71
72    // Informations contained in the parser
73    virtual bool IsReadable();
74
75    // Meta
76    DicomDirMeta *NewMeta();
77    /// Returns a pointer to the DicomDirMeta for this DICOMDIR. 
78    DicomDirMeta *GetMeta() { return MetaElems; }
79
80    // Patients
81    DicomDirPatient *NewPatient();
82    void ClearPatient();
83
84    DicomDirPatient *GetFirstPatient();
85    DicomDirPatient *GetNextPatient();
86
87    // Parsing
88    void ParseDirectory();
89
90    /// GetProgress GetProgress
91    float GetProgress() const { return Progress; }
92    /// AbortProgress AbortProgress
93    void  AbortProgress() { Abort = true; }
94    /// IsAborted IsAborted
95    bool  IsAborted() { return Abort; }
96
97    // Write
98    bool Write(std::string const &fileName);
99
100    bool Anonymize();
101
102    virtual void Copy(DocEntrySet *set);
103
104    /// Types of the DicomDirObject within the DicomDir
105    typedef enum
106    {
107       GDCM_DICOMDIR_NONE,
108       GDCM_DICOMDIR_META,
109       GDCM_DICOMDIR_PATIENT,
110       GDCM_DICOMDIR_STUDY,
111       GDCM_DICOMDIR_SERIE,
112       GDCM_DICOMDIR_VISIT,
113       GDCM_DICOMDIR_IMAGE
114    } DicomDirType;
115
116 protected:
117    DicomDir();
118    ~DicomDir();
119    GDCM_LEGACY( DicomDir(std::string const &filename, bool parseDir = false) )
120
121    void CreateDicomDirChainedList(std::string const &path);
122
123 private:
124    void Initialize();
125    void CreateDicomDir();
126    bool DoTheLoadingJob();
127    bool AddPatientToEnd(DicomDirPatient *dd);
128    bool AddStudyToEnd  (DicomDirStudy *dd);
129    bool AddSerieToEnd  (DicomDirSerie *dd);
130    bool AddVisitToEnd  (DicomDirVisit *dd);
131    bool AddImageToEnd  (DicomDirImage *dd);
132
133    void SetElements(std::string const &path, VectDocument const &list);
134    void SetElement (std::string const &path, DicomDirType type,
135                     Document *header);
136    void MoveSQItem(DocEntrySet *dst, DocEntrySet *src);
137
138    static bool HeaderLessThan(Document *header1, Document *header2);
139
140 // Variables
141
142    /// Pointer on *the* DicomDirObject 'DicomDirMeta Elements'
143    DicomDirMeta *MetaElems;
144
145    /// Chained list of DicomDirPatient (to be exploited hierarchicaly) 
146    ListDicomDirPatient Patients;
147    ListDicomDirPatient::iterator ItPatient;
148
149    /// value of the ??? for any progress bar   
150    bool ParseDir;
151
152 };
153 } // end namespace gdcm
154 //-----------------------------------------------------------------------------
155 #endif