]> Creatis software - gdcm.git/blob - src/gdcmDicomDirSerie.cxx
Cosmetics
[gdcm.git] / src / gdcmDicomDirSerie.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmDicomDirSerie.cxx,v $
5   Language:  C++
6   Date:      $Date: 2005/01/28 17:01:29 $
7   Version:   $Revision: 1.36 $
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  * \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 }
52
53 //-----------------------------------------------------------------------------
54 // Print
55 /**
56  * \brief   Prints the Object
57  * @param os ostream to write to
58  * @param indent Indentation string to be prepended during printing
59  */ 
60 void DicomDirSerie::Print(std::ostream &os, std::string const &)
61 {
62    os << "SERIE" << std::endl;
63    DicomDirObject::Print(os);
64
65    for(ListDicomDirImage::iterator cc = Images.begin();
66                                    cc != Images.end();
67                                    ++cc)
68    {
69       (*cc)->SetPrintLevel(PrintLevel);
70       (*cc)->Print(os);
71    }
72 }
73
74 //-----------------------------------------------------------------------------
75 // Public
76 /**
77  * \brief   Writes the Object
78  * @param fp ofstream to write to
79  * @param t Type of the File (explicit VR, implicitVR, ...)
80  */ 
81 void DicomDirSerie::WriteContent(std::ofstream *fp, FileType t)
82 {
83    DicomDirObject::WriteContent(fp, t);
84
85    for(ListDicomDirImage::iterator cc = Images.begin();
86                                    cc!= Images.end();
87                                  ++cc )
88    {
89       (*cc)->WriteContent( fp, t );
90    }
91 }
92
93 /**
94  * \brief   adds a new Image (with the basic elements) to a partially created 
95  *          DICOMDIR
96  */
97 DicomDirImage *DicomDirSerie::NewImage()
98 {
99    DicomDirImage *st = new DicomDirImage();
100    Images.push_back(st);
101    return st;   
102 }
103
104 /**
105  * \brief  Remove all images in the serie 
106  */
107 void DicomDirSerie::ClearImage()
108 {
109    for(ListDicomDirImage::iterator cc = Images.begin();
110                                    cc != Images.end();
111                                    ++cc)
112    {
113       delete *cc;
114    }
115    Images.clear();
116 }
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 GetFirstEntry 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 // Protected
147
148 //-----------------------------------------------------------------------------
149 // Private
150
151 //-----------------------------------------------------------------------------
152 } // end namespace gdcm
153
154