]> Creatis software - gdcm.git/blob - src/gdcmDicomDirSerie.cxx
* src/*.cxx : first parss to normalize file organisation
[gdcm.git] / src / gdcmDicomDirSerie.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmDicomDirSerie.cxx,v $
5   Language:  C++
6   Date:      $Date: 2005/02/01 10:29:55 $
7   Version:   $Revision: 1.37 $
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 *st = new DicomDirImage();
78    Images.push_back(st);
79    return st;   
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       delete *cc;
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 // Protected
125
126 //-----------------------------------------------------------------------------
127 // Private
128
129 //-----------------------------------------------------------------------------
130 // Print
131 /**
132  * \brief   Prints the Object
133  * @param os ostream to write to
134  * @param indent Indentation string to be prepended during printing
135  */ 
136 void DicomDirSerie::Print(std::ostream &os, std::string const &)
137 {
138    os << "SERIE" << std::endl;
139    DicomDirObject::Print(os);
140
141    for(ListDicomDirImage::iterator cc = Images.begin();
142                                    cc != Images.end();
143                                    ++cc)
144    {
145       (*cc)->SetPrintLevel(PrintLevel);
146       (*cc)->Print(os);
147    }
148 }
149
150 //-----------------------------------------------------------------------------
151 } // end namespace gdcm