]> Creatis software - gdcm.git/blob - src/gdcmDicomDirSerie.cxx
* Add the Copy method in all datas
[gdcm.git] / src / gdcmDicomDirSerie.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmDicomDirSerie.cxx,v $
5   Language:  C++
6   Date:      $Date: 2005/11/29 12:48:46 $
7   Version:   $Revision: 1.40 $
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 "gdcmGlobal.h"
23 #include "gdcmDebug.h"
24
25 namespace gdcm 
26 {
27 //-----------------------------------------------------------------------------
28 // Constructor / Destructor
29 /**
30  * \brief  Constructor
31  * \note End user must use : DicomDirStudy::NewSerie() 
32  */
33 DicomDirSerie::DicomDirSerie(bool empty):
34    DicomDirObject()
35 {
36    if ( !empty )
37    {
38       ListDicomDirSerieElem const &elemList = 
39          Global::GetDicomDirElements()->GetDicomDirSerieElements();   
40       FillObject(elemList);
41    }
42 }
43
44 /**
45  * \brief   Canonical destructor.
46  */
47 DicomDirSerie::~DicomDirSerie() 
48 {
49    ClearImage();
50 }
51
52 //-----------------------------------------------------------------------------
53 // Public
54 /**
55  * \brief   Writes the Object
56  * @param fp ofstream to write to
57  * @param t Type of the File (explicit VR, implicitVR, ...)
58  */ 
59 void DicomDirSerie::WriteContent(std::ofstream *fp, FileType t)
60 {
61    DicomDirObject::WriteContent(fp, t);
62
63    for(ListDicomDirImage::iterator cc = Images.begin();
64                                    cc!= Images.end();
65                                  ++cc )
66    {
67       (*cc)->WriteContent( fp, t );
68    }
69 }
70
71 /**
72  * \brief   adds a new Image (with the basic elements) to a partially created 
73  *          DICOMDIR
74  */
75 DicomDirImage *DicomDirSerie::NewImage()
76 {
77    DicomDirImage *dd = DicomDirImage::New();
78    Images.push_back(dd);
79    return dd;   
80 }
81
82 /**
83  * \brief  Remove all images in the serie 
84  */
85 void DicomDirSerie::ClearImage()
86 {
87    for(ListDicomDirImage::iterator cc = Images.begin();
88                                    cc != Images.end();
89                                    ++cc)
90    {
91       (*cc)->Delete();
92    }
93    Images.clear();
94 }
95
96 /**
97  * \brief   Get the first entry while visiting the DicomDirImage
98  * \return  The first DicomDirImage if DicomDirserie not empty, otherwhise NULL
99  */
100 DicomDirImage *DicomDirSerie::GetFirstImage()
101 {
102    ItImage = Images.begin();
103    if (ItImage != Images.end())
104       return *ItImage;
105    return NULL;
106 }
107
108 /**
109  * \brief   Get the next entry while visiting the DicomDirImages
110  * \note : meaningfull only if GetFirstEntry already called
111  * \return  The next DicomDirImages if found, otherwhise NULL
112  */
113 DicomDirImage *DicomDirSerie::GetNextImage()
114 {
115    gdcmAssertMacro (ItImage != Images.end());
116
117    ++ItImage;
118    if (ItImage != Images.end())      
119       return *ItImage;
120    return NULL;
121 }
122
123 /**
124  * \brief Copies all the attributes from an other DocEntrySet 
125  * @param set entry to copy from
126  * @remarks The contained DocEntries a not copied, only referenced
127  */
128 void DicomDirSerie::Copy(DocEntrySet *set)
129 {
130    // Remove all previous childs
131    ClearImage();
132
133    DicomDirObject::Copy(set);
134
135    DicomDirSerie *ddEntry = dynamic_cast<DicomDirSerie *>(set);
136    if( ddEntry )
137    {
138       Images = ddEntry->Images;
139       for(ItImage = Images.begin();ItImage != Images.end();++ItImage)
140          (*ItImage)->Register();
141    }
142 }
143
144 //-----------------------------------------------------------------------------
145 // Protected
146
147 //-----------------------------------------------------------------------------
148 // Private
149
150 //-----------------------------------------------------------------------------
151 // Print
152 /**
153  * \brief   Prints the Object
154  * @param os ostream to write to
155  * @param indent Indentation string to be prepended during printing
156  */ 
157 void DicomDirSerie::Print(std::ostream &os, std::string const &)
158 {
159    os << "SERIE" << std::endl;
160    DicomDirObject::Print(os);
161
162    for(ListDicomDirImage::iterator cc = Images.begin();
163                                    cc != Images.end();
164                                    ++cc)
165    {
166       (*cc)->SetPrintLevel(PrintLevel);
167       (*cc)->Print(os);
168    }
169 }
170
171 //-----------------------------------------------------------------------------
172 } // end namespace gdcm