]> Creatis software - gdcm.git/blob - src/gdcmDicomDirSerie.cxx
Fix mistypings
[gdcm.git] / src / gdcmDicomDirSerie.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmDicomDirSerie.cxx,v $
5   Language:  C++
6   Date:      $Date: 2007/10/08 15:20:17 $
7   Version:   $Revision: 1.46 $
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_NAME_SPACE 
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, bool , bool )
62 {
63    DicomDirObject::WriteContent(fp, t, false, true);
64
65    for(ListDicomDirImage::iterator cc = Images.begin();
66                                    cc!= Images.end();
67                                  ++cc )
68    {
69       (*cc)->WriteContent( fp, t, false, true );
70    } 
71    for(ListDicomDirPrivate::iterator cc2 = Privates.begin();
72                                      cc2!= Privates.end();
73                                    ++cc2 )
74    {
75       (*cc2)->WriteContent( fp, t, false, true);
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   adds a new Private (with the basic elements) to a partially created 
92  *          DICOMDIR
93  */
94  
95 DicomDirPrivate *DicomDirSerie::NewPrivate()
96 {
97    DicomDirPrivate *dd = DicomDirPrivate::New();
98    Privates.push_back(dd);
99    return dd;   
100 }
101
102 /**
103  * \brief  Remove all 'Privates'  in the serie 
104  */
105 void DicomDirSerie::ClearPrivate()
106 {
107    for(ListDicomDirPrivate::iterator cc = Privates.begin();
108                                      cc!= Privates.end();
109                                    ++cc)
110    {
111       (*cc)->Delete();
112    }
113    Privates.clear();
114 }
115
116 /**
117  * \brief  Remove all 'Images' in the serie 
118  */
119 void DicomDirSerie::ClearImage()
120 {
121    for(ListDicomDirImage::iterator cc = Images.begin();
122                                    cc!= Images.end();
123                                  ++cc)
124    {
125       (*cc)->Delete();
126    }
127    Images.clear();
128 }
129
130 /**
131  * \brief   Get the first entry while visiting the DicomDirImage
132  * \return  The first DicomDirImage if DicomDirserie not empty, otherwhise NULL
133  */
134 DicomDirImage *DicomDirSerie::GetFirstImage()
135 {
136    ItImage = Images.begin();
137    if (ItImage != Images.end())
138       return *ItImage;
139    return NULL;
140 }
141
142 /**
143  * \brief   Get the next entry while visiting the DicomDirImages
144  * \note : meaningfull only if GetFirstImage already called
145  * \return  The next DicomDirImages if found, otherwhise NULL
146  */
147 DicomDirImage *DicomDirSerie::GetNextImage()
148 {
149    gdcmAssertMacro (ItImage != Images.end());
150
151    ++ItImage;
152    if (ItImage != Images.end())      
153       return *ItImage;
154    return NULL;
155 }
156
157 /**
158  * \brief   Get the first entry while visiting the DicomDirPrivate
159  * \return  The first DicomDirPrivate if DicomDirserie not empty, otherwhise NULL
160  */
161 DicomDirPrivate *DicomDirSerie::GetFirstPrivate()
162 {
163    ItPrivate = Privates.begin();
164    if (ItPrivate != Privates.end())
165       return *ItPrivate;
166    return NULL;
167 }
168
169 /**
170  * \brief   Get the next entry while visiting the DicomDirPrivates
171  * \note : meaningfull only if GetFirstPrivate already called
172  * \return  The next DicomDirPrivates if found, otherwhise NULL
173  */
174 DicomDirPrivate *DicomDirSerie::GetNextPrivate()
175 {
176    gdcmAssertMacro (ItPrivate != Privates.end());
177
178    ++ItPrivate;
179    if (ItPrivate != Privates.end())      
180       return *ItPrivate;
181    return NULL;
182 }
183
184 /**
185  * \brief Copies all the attributes from an other DocEntrySet 
186  * @param set entry to copy from
187  * @remarks The contained DocEntries a not copied, only referenced
188  */
189 void DicomDirSerie::Copy(DocEntrySet *set)
190 {
191    // Remove all previous childs
192    ClearImage();
193    ClearPrivate();
194    
195    DicomDirObject::Copy(set);
196
197    DicomDirSerie *ddEntry = dynamic_cast<DicomDirSerie *>(set);
198    if( ddEntry )
199    {
200       Images = ddEntry->Images;
201       for(ItImage = Images.begin();ItImage != Images.end();++ItImage)
202          (*ItImage)->Register();
203
204       Privates = ddEntry->Privates;
205       for(ItPrivate = Privates.begin();ItPrivate != Privates.end();++ItPrivate)
206          (*ItPrivate)->Register();
207    }   
208 }
209
210 //-----------------------------------------------------------------------------
211 // Protected
212
213 //-----------------------------------------------------------------------------
214 // Private
215
216 //-----------------------------------------------------------------------------
217 // Print
218 /**
219  * \brief   Prints the Object
220  * @param os ostream to write to
221  * @param indent Indentation string to be prepended during printing
222  */ 
223 void DicomDirSerie::Print(std::ostream &os, std::string const &)
224 {
225    os << "SERIE" << std::endl;
226    DicomDirObject::Print(os);
227
228    for(ListDicomDirImage::iterator cc = Images.begin();
229                                    cc != Images.end();
230                                    ++cc)
231    {
232       (*cc)->SetPrintLevel(PrintLevel);
233       (*cc)->Print(os);
234    }
235
236    for(ListDicomDirPrivate::iterator cc2 = Privates.begin();
237                                      cc2 != Privates.end();
238                                    ++cc2)
239    {
240       (*cc2)->SetPrintLevel(PrintLevel);
241       (*cc2)->Print(os);
242    }   
243    
244 }
245
246 //-----------------------------------------------------------------------------
247 } // end namespace gdcm