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