1 /*=========================================================================
4 Module: $RCSfile: gdcmDicomDirElement.cxx,v $
6 Date: $Date: 2004/08/27 15:48:44 $
7 Version: $Revision: 1.15 $
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",
50 from.getline(buff, 1024, ' ');
53 if( (type=="metaElem") || (type=="patientElem") ||
54 (type=="studyElem") || (type=="serieElem") ||
57 from >> std::hex >> elem.group >> elem.elem;
60 from.getline(buff, 1024, '"');
62 from.getline(buff, 1024, '"');
65 if( type == "metaElem" )
67 DicomDirMetaList.push_back(elem);
69 else if( type == "patientElem" )
71 DicomDirPatientList.push_back(elem);
73 else if( type == "studyElem" )
75 DicomDirStudyList.push_back(elem);
77 else if( type == "serieElem" )
79 DicomDirSerieList.push_back(elem);
81 else if( type == "imageElem" )
83 DicomDirImageList.push_back(elem);
86 from.getline(buff, 1024, '\n');
92 * \ingroup gdcmDicomDirElement
93 * \brief canonical destructor
95 gdcmDicomDirElement::~gdcmDicomDirElement()
97 DicomDirMetaList.clear();
98 DicomDirPatientList.clear();
99 DicomDirStudyList.clear();
100 DicomDirSerieList.clear();
101 DicomDirImageList.clear();
104 //-----------------------------------------------------------------------------
107 * \ingroup gdcmDicomDirElement
109 * \todo add a 'Print Level' check
110 * @param os The output stream to be written to.
112 void gdcmDicomDirElement::Print(std::ostream &os)
114 std::ostringstream s;
115 std::list<gdcmElement>::iterator it;
116 char greltag[10]; //group element tag
118 s << "Meta Elements :"<<std::endl;
119 for (it = DicomDirMetaList.begin(); it != DicomDirMetaList.end(); ++it)
121 sprintf(greltag,"%04x|%04x ",it->group,it->elem);
122 s << " ("<<greltag<<") = "<< it->value<<std::endl;
125 s << "Patient Elements :"<<std::endl;
126 for (it = DicomDirPatientList.begin(); it != DicomDirPatientList.end(); ++it)
128 sprintf(greltag,"%04x|%04x ",it->group,it->elem);
129 s << " ("<<greltag<<") = "<< it->value<<std::endl;
132 s << "Study Elements :"<<std::endl;
133 for (it = DicomDirStudyList.begin(); it != DicomDirStudyList.end(); ++it)
135 sprintf(greltag,"%04x|%04x ",it->group,it->elem);
136 s << " ("<<greltag<<") = "<< it->value<<std::endl;
139 s << "Serie Elements :"<<std::endl;
140 for (it = DicomDirSerieList.begin(); it != DicomDirSerieList.end(); ++it)
142 sprintf(greltag,"%04x|%04x ",it->group,it->elem);
143 s << " ("<<greltag<<") = "<< it->value<<std::endl;
146 s << "Image Elements :"<<std::endl;
147 for (it = DicomDirImageList.begin(); it != DicomDirImageList.end(); ++it)
149 sprintf(greltag,"%04x|%04x ",it->group,it->elem);
150 s << " ("<<greltag<<") = "<< it->value<<std::endl;
156 //-----------------------------------------------------------------------------
159 //-----------------------------------------------------------------------------
162 //-----------------------------------------------------------------------------
165 //-----------------------------------------------------------------------------