1 /*=========================================================================
4 Module: $RCSfile: gdcmDicomDirElement.cxx,v $
6 Date: $Date: 2004/08/01 02:39:09 $
7 Version: $Revision: 1.14 $
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.htm for details.
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.
17 =========================================================================*/
20 #include <stdio.h> // For sprintf
23 #include "gdcmDicomDirElement.h"
25 #include "gdcmDebug.h"
26 #include "gdcmDictSet.h"
29 //-----------------------------------------------------------------------------
30 // Constructor / Destructor
33 * \brief constructor : populates the chained lists
34 * from the file 'Dicts/DicomDir.dic'
36 gdcmDicomDirElement::gdcmDicomDirElement()
38 std::string filename = gdcmDictSet::BuildDictPath() + std::string(DICT_ELEM);
39 std::ifstream from(filename.c_str());
40 dbg.Error(!from, "gdcmDicomDirElement::gdcmDicomDirElement: can't open dictionary",filename.c_str());
49 from.getline(buff, 1024, ' ');
52 if( (type=="metaElem") || (type=="patientElem") ||
53 (type=="studyElem") || (type=="serieElem") ||
56 from >> std::hex >> elem.group >> elem.elem;
59 from.getline(buff, 1024, '"');
61 from.getline(buff, 1024, '"');
64 if( type == "metaElem" )
66 DicomDirMetaList.push_back(elem);
68 else if( type == "patientElem" )
70 DicomDirPatientList.push_back(elem);
72 else if( type == "studyElem" )
74 DicomDirStudyList.push_back(elem);
76 else if( type == "serieElem" )
78 DicomDirSerieList.push_back(elem);
80 else if( type == "imageElem" )
82 DicomDirImageList.push_back(elem);
85 from.getline(buff, 1024, '\n');
91 * \ingroup gdcmDicomDirElement
92 * \brief canonical destructor
94 gdcmDicomDirElement::~gdcmDicomDirElement()
96 DicomDirMetaList.clear();
97 DicomDirPatientList.clear();
98 DicomDirStudyList.clear();
99 DicomDirSerieList.clear();
100 DicomDirImageList.clear();
103 //-----------------------------------------------------------------------------
106 * \ingroup gdcmDicomDirElement
108 * \todo add a 'Print Level' check
109 * @param os The output stream to be written to.
111 void gdcmDicomDirElement::Print(std::ostream &os)
113 std::ostringstream s;
114 std::list<gdcmElement>::iterator it;
115 char greltag[10]; //group element tag
117 s << "Meta Elements :"<<std::endl;
118 for (it = DicomDirMetaList.begin(); it != DicomDirMetaList.end(); ++it)
120 sprintf(greltag,"%04x|%04x ",it->group,it->elem);
121 s << " ("<<greltag<<") = "<< it->value<<std::endl;
124 s << "Patient Elements :"<<std::endl;
125 for (it = DicomDirPatientList.begin(); it != DicomDirPatientList.end(); ++it)
127 sprintf(greltag,"%04x|%04x ",it->group,it->elem);
128 s << " ("<<greltag<<") = "<< it->value<<std::endl;
131 s << "Study Elements :"<<std::endl;
132 for (it = DicomDirStudyList.begin(); it != DicomDirStudyList.end(); ++it)
134 sprintf(greltag,"%04x|%04x ",it->group,it->elem);
135 s << " ("<<greltag<<") = "<< it->value<<std::endl;
138 s << "Serie Elements :"<<std::endl;
139 for (it = DicomDirSerieList.begin(); it != DicomDirSerieList.end(); ++it)
141 sprintf(greltag,"%04x|%04x ",it->group,it->elem);
142 s << " ("<<greltag<<") = "<< it->value<<std::endl;
145 s << "Image Elements :"<<std::endl;
146 for (it = DicomDirImageList.begin(); it != DicomDirImageList.end(); ++it)
148 sprintf(greltag,"%04x|%04x ",it->group,it->elem);
149 s << " ("<<greltag<<") = "<< it->value<<std::endl;
155 //-----------------------------------------------------------------------------
158 //-----------------------------------------------------------------------------
161 //-----------------------------------------------------------------------------
164 //-----------------------------------------------------------------------------