]> Creatis software - gdcm.git/blob - src/gdcmDicomDirSerie.cxx
* src/ : rename some methods on Entry (SetXxx, InsertXxx) to have a better
[gdcm.git] / src / gdcmDicomDirSerie.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmDicomDirSerie.cxx,v $
5   Language:  C++
6   Date:      $Date: 2005/01/25 15:44:23 $
7   Version:   $Revision: 1.35 $
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 //-----------------------------------------------------------------------------
29 // Constructor / Destructor
30 /**
31  * \brief  Constructor 
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 // Print
54 /**
55  * \brief   Prints the Object
56  * @param os ostream to write to
57  * @param indent Indentation string to be prepended during printing
58  */ 
59 void DicomDirSerie::Print(std::ostream &os, std::string const &)
60 {
61    os << "SERIE" << std::endl;
62    DicomDirObject::Print(os);
63
64    for(ListDicomDirImage::iterator cc = Images.begin();
65                                    cc != Images.end();
66                                    ++cc)
67    {
68       (*cc)->SetPrintLevel(PrintLevel);
69       (*cc)->Print(os);
70    }
71 }
72
73 //-----------------------------------------------------------------------------
74 // Public
75 /**
76  * \brief   Writes the Object
77  * @param fp ofstream to write to
78  * @param t Type of the File (explicit VR, implicitVR, ...)
79  */ 
80 void DicomDirSerie::WriteContent(std::ofstream *fp, FileType t)
81 {
82    DicomDirObject::WriteContent(fp, t);
83
84    for(ListDicomDirImage::iterator cc = Images.begin();
85                                    cc!= Images.end();
86                                  ++cc )
87    {
88       (*cc)->WriteContent( fp, t );
89    }
90 }
91
92 /**
93  * \brief   adds a new Image (with the basic elements) to a partially created 
94  *          DICOMDIR
95  */
96 DicomDirImage *DicomDirSerie::NewImage()
97 {
98    DicomDirImage *st = new DicomDirImage();
99    Images.push_back(st);
100    return st;   
101 }
102
103 /**
104  * \brief  Remove all images in the serie 
105  */
106 void DicomDirSerie::ClearImage()
107 {
108    for(ListDicomDirImage::iterator cc = Images.begin();
109                                    cc != Images.end();
110                                    ++cc)
111    {
112       delete *cc;
113    }
114    Images.clear();
115 }
116
117 /**
118  * \brief   Get the first entry while visiting the DicomDirImage
119  * \return  The first DicomDirImage if found, otherwhise NULL
120  */
121 DicomDirImage *DicomDirSerie::GetFirstImage()
122 {
123    ItImage = Images.begin();
124    if (ItImage != Images.end())
125       return *ItImage;
126    return NULL;
127 }
128
129 /**
130  * \brief   Get the next entry while visiting the DicomDirImages
131  * \note : meaningfull only if GetFirstEntry already called
132  * \return  The next DicomDirImages if found, otherwhise NULL
133  */
134 DicomDirImage *DicomDirSerie::GetNextImage()
135 {
136    gdcmAssertMacro (ItImage != Images.end());
137
138    ++ItImage;
139    if (ItImage != Images.end())      
140       return *ItImage;
141    return NULL;
142 }
143  
144 /**
145  * \brief   Get the first entry while visiting the DicomDirImage
146  * \return  The first DicomDirImage if found, otherwhise NULL
147  */
148 DicomDirImage *DicomDirSerie::GetLastImage()
149 {
150    ItImage = Images.end();
151    if (ItImage != Images.begin())
152    {
153       --ItImage;
154       return *ItImage;
155    }
156    return NULL;
157 }
158
159 //-----------------------------------------------------------------------------
160 // Protected
161
162 //-----------------------------------------------------------------------------
163 // Private
164
165 //-----------------------------------------------------------------------------
166 } // end namespace gdcm
167
168