1 /*=========================================================================
4 Module: $RCSfile: gdcmDicomDirElement.cxx,v $
6 Date: $Date: 2004/10/10 00:42:54 $
7 Version: $Revision: 1.19 $
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.
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 =========================================================================*/
19 #include "gdcmDicomDirElement.h"
21 #include "gdcmDebug.h"
22 #include "gdcmDictSet.h"
27 //-----------------------------------------------------------------------------
28 // Constructor / Destructor
31 * \brief constructor : populates the chained lists
32 * from the file 'Dicts/DicomDir.dic'
34 gdcmDicomDirElement::gdcmDicomDirElement()
36 std::string filename = gdcmDictSet::BuildDictPath() + std::string(DICT_ELEM);
37 std::ifstream from(filename.c_str());
38 dbg.Error(!from, "gdcmDicomDirElement::gdcmDicomDirElement: can't open dictionary",
48 from.getline(buff, 1024, ' ');
51 if( (type=="metaElem") || (type=="patientElem") ||
52 (type=="studyElem") || (type=="serieElem") ||
55 from >> std::hex >> elem.Group >> elem.Elem;
58 from.getline(buff, 1024, '"');
60 from.getline(buff, 1024, '"');
63 if( type == "metaElem" )
65 DicomDirMetaList.push_back(elem);
67 else if( type == "patientElem" )
69 DicomDirPatientList.push_back(elem);
71 else if( type == "studyElem" )
73 DicomDirStudyList.push_back(elem);
75 else if( type == "serieElem" )
77 DicomDirSerieList.push_back(elem);
79 else if( type == "imageElem" )
81 DicomDirImageList.push_back(elem);
84 from.getline(buff, 1024, '\n');
90 * \ingroup gdcmDicomDirElement
91 * \brief canonical destructor
93 gdcmDicomDirElement::~gdcmDicomDirElement()
95 DicomDirMetaList.clear();
96 DicomDirPatientList.clear();
97 DicomDirStudyList.clear();
98 DicomDirSerieList.clear();
99 DicomDirImageList.clear();
102 //-----------------------------------------------------------------------------
105 * \ingroup gdcmDicomDirElement
107 * \todo add a 'Print Level' check
108 * @param os The output stream to be written to.
110 void gdcmDicomDirElement::Print(std::ostream &os)
112 std::ostringstream s;
113 std::list<gdcmElement>::iterator it;
114 //char greltag[10]; //group element tag
117 s << "Meta Elements :"<<std::endl;
118 for (it = DicomDirMetaList.begin(); it != DicomDirMetaList.end(); ++it)
120 greltag = gdcmUtil::Format("%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 greltag = gdcmUtil::Format("%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 greltag = gdcmUtil::Format("%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 greltag = gdcmUtil::Format("%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 greltag = gdcmUtil::Format("%04x|%04x ", it->Group, it->Elem);
149 s << " (" << greltag << ") = " << it->Value << std::endl;
155 //-----------------------------------------------------------------------------
158 //-----------------------------------------------------------------------------
161 //-----------------------------------------------------------------------------
164 //-----------------------------------------------------------------------------