]> Creatis software - gdcm.git/blob - src/gdcmDicomDirSerie.cxx
Deal with PRIVATE (at PrintDicomDir time, not MakeDicomDir time ...)
[gdcm.git] / src / gdcmDicomDirSerie.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmDicomDirSerie.cxx,v $
5   Language:  C++
6   Date:      $Date: 2007/03/23 15:30:15 $
7   Version:   $Revision: 1.41 $
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 #include "gdcmDicomDirSerie.h"
20 #include "gdcmDicomDirElement.h"
21 #include "gdcmDicomDirImage.h"
22 #include "gdcmDicomDirPrivate.h"
23 #include "gdcmGlobal.h"
24 #include "gdcmDebug.h"
25
26 namespace gdcm 
27 {
28 //-----------------------------------------------------------------------------
29 // Constructor / Destructor
30 /**
31  * \brief  Constructor
32  * \note End user must use : DicomDirStudy::NewSerie() 
33  */
34 DicomDirSerie::DicomDirSerie(bool empty):
35    DicomDirObject()
36 {
37    if ( !empty )
38    {
39       ListDicomDirSerieElem const &elemList = 
40          Global::GetDicomDirElements()->GetDicomDirSerieElements();   
41       FillObject(elemList);
42    }
43 }
44
45 /**
46  * \brief   Canonical destructor.
47  */
48 DicomDirSerie::~DicomDirSerie() 
49 {
50    ClearImage();
51    ClearPrivate();  // For SIEMENS 'CSA non image'
52 }
53
54 //-----------------------------------------------------------------------------
55 // Public
56 /**
57  * \brief   Writes the Object
58  * @param fp ofstream to write to
59  * @param t Type of the File (explicit VR, implicitVR, ...)
60  */ 
61 void DicomDirSerie::WriteContent(std::ofstream *fp, FileType t)
62 {
63    DicomDirObject::WriteContent(fp, t);
64
65    for(ListDicomDirImage::iterator cc = Images.begin();
66                                    cc!= Images.end();
67                                  ++cc )
68    {
69       (*cc)->WriteContent( fp, t );
70    } 
71    for(ListDicomDirPrivate::iterator cc2 = Privates.begin();
72                                      cc2!= Privates.end();
73                                    ++cc2 )
74    {
75       (*cc2)->WriteContent( fp, t );
76    }   
77 }
78
79 /**
80  * \brief   adds a new Image (with the basic elements) to a partially created 
81  *          DICOMDIR
82  */
83 DicomDirImage *DicomDirSerie::NewImage()
84 {
85    DicomDirImage *dd = DicomDirImage::New();
86    Images.push_back(dd);
87    return dd;   
88 }
89
90 /**
91  * \brief  Remove all 'Images' in the serie 
92  */
93 void DicomDirSerie::ClearPrivate()
94 {
95    for(ListDicomDirPrivate::iterator cc = Privates.begin();
96                                      cc!= Privates.end();
97                                    ++cc)
98    {
99       (*cc)->Delete();
100    }
101    Privates.clear();
102 }
103
104
105 /**
106  * \brief  Remove all 'Privates' in the serie 
107  */
108 void DicomDirSerie::ClearImage()
109 {
110    for(ListDicomDirImage::iterator cc = Images.begin();
111                                    cc!= Images.end();
112                                  ++cc)
113    {
114       (*cc)->Delete();
115    }
116    Images.clear();
117 }
118 /**
119  * \brief   Get the first entry while visiting the DicomDirImage
120  * \return  The first DicomDirImage if DicomDirserie not empty, otherwhise NULL
121  */
122 DicomDirImage *DicomDirSerie::GetFirstImage()
123 {
124    ItImage = Images.begin();
125    if (ItImage != Images.end())
126       return *ItImage;
127    return NULL;
128 }
129
130 /**
131  * \brief   Get the next entry while visiting the DicomDirImages
132  * \note : meaningfull only if GetFirstImage already called
133  * \return  The next DicomDirImages if found, otherwhise NULL
134  */
135 DicomDirImage *DicomDirSerie::GetNextImage()
136 {
137    gdcmAssertMacro (ItImage != Images.end());
138
139    ++ItImage;
140    if (ItImage != Images.end())      
141       return *ItImage;
142    return NULL;
143 }
144
145 /**
146  * \brief   Get the first entry while visiting the DicomDirPrivate
147  * \return  The first DicomDirPrivate if DicomDirserie not empty, otherwhise NULL
148  */
149 DicomDirPrivate *DicomDirSerie::GetFirstPrivate()
150 {
151    ItPrivate = Privates.begin();
152    if (ItPrivate != Privates.end())
153       return *ItPrivate;
154    return NULL;
155 }
156
157 /**
158  * \brief   Get the next entry while visiting the DicomDirPrivates
159  * \note : meaningfull only if GetFirstPrivate already called
160  * \return  The next DicomDirPrivates if found, otherwhise NULL
161  */
162 DicomDirPrivate *DicomDirSerie::GetNextPrivate()
163 {
164    gdcmAssertMacro (ItPrivate != Privates.end());
165
166    ++ItPrivate;
167    if (ItPrivate != Privates.end())      
168       return *ItPrivate;
169    return NULL;
170 }
171
172 /**
173  * \brief Copies all the attributes from an other DocEntrySet 
174  * @param set entry to copy from
175  * @remarks The contained DocEntries a not copied, only referenced
176  */
177 void DicomDirSerie::Copy(DocEntrySet *set)
178 {
179    // Remove all previous childs
180    ClearImage();
181    ClearPrivate();
182    
183    DicomDirObject::Copy(set);
184
185    DicomDirSerie *ddEntry = dynamic_cast<DicomDirSerie *>(set);
186    if( ddEntry )
187    {
188       Images = ddEntry->Images;
189       for(ItImage = Images.begin();ItImage != Images.end();++ItImage)
190          (*ItImage)->Register();
191
192       Privates = ddEntry->Privates;
193       for(ItPrivate = Privates.begin();ItPrivate != Privates.end();++ItPrivate)
194          (*ItPrivate)->Register();
195    }   
196 }
197
198 //-----------------------------------------------------------------------------
199 // Protected
200
201 //-----------------------------------------------------------------------------
202 // Private
203
204 //-----------------------------------------------------------------------------
205 // Print
206 /**
207  * \brief   Prints the Object
208  * @param os ostream to write to
209  * @param indent Indentation string to be prepended during printing
210  */ 
211 void DicomDirSerie::Print(std::ostream &os, std::string const &)
212 {
213    os << "SERIE" << std::endl;
214    DicomDirObject::Print(os);
215
216    for(ListDicomDirImage::iterator cc = Images.begin();
217                                    cc != Images.end();
218                                    ++cc)
219    {
220       (*cc)->SetPrintLevel(PrintLevel);
221       (*cc)->Print(os);
222    }
223
224    for(ListDicomDirPrivate::iterator cc2 = Privates.begin();
225                                      cc2 != Privates.end();
226                                    ++cc2)
227    {
228       (*cc2)->SetPrintLevel(PrintLevel);
229       (*cc2)->Print(os);
230    }   
231    
232 }
233
234 //-----------------------------------------------------------------------------
235 } // end namespace gdcm