1 /*=========================================================================
4 Module: $RCSfile: gdcmDicomDirElement.cxx,v $
6 Date: $Date: 2005/02/01 10:29:54 $
7 Version: $Revision: 1.33 $
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"
29 //-----------------------------------------------------------------------------
30 void FillDefaultDIRDict(DicomDirElement *dde);
32 //-----------------------------------------------------------------------------
33 // Constructor / Destructor
35 * \brief constructor : populates the chained lists
36 * from the file 'Dicts/DicomDir.dic'
38 DicomDirElement::DicomDirElement()
40 std::string filename = DictSet::BuildDictPath() + DICT_ELEM;
41 std::ifstream from(filename.c_str());
44 gdcmVerboseMacro( "Can't open DicomDirElement dictionary"
46 FillDefaultDIRDict( this );
58 from.getline(buff, 1024, ' ');
61 if( strType == "metaElem" )
63 else if( strType == "patientElem" )
65 else if( strType == "studyElem" )
67 else if( strType == "serieElem" )
69 else if( strType == "imageElem" )
73 gdcmVerboseMacro("Unknown type found in the file : "
78 if( type!=DD_UNKNOWN )
80 from >> std::hex >> elem.Group >> elem.Elem;
83 from.getline(buff, 1024, '"');
85 from.getline(buff, 1024, '"');
90 from.getline(buff, 1024, '\n');
97 * \brief canonical destructor
99 DicomDirElement::~DicomDirElement()
101 DicomDirMetaList.clear();
102 DicomDirPatientList.clear();
103 DicomDirStudyList.clear();
104 DicomDirSerieList.clear();
105 DicomDirImageList.clear();
108 //-----------------------------------------------------------------------------
111 * \brief Add an entry
115 bool DicomDirElement::AddEntry(DicomDirType type, Element const &elem)
120 DicomDirMetaList.push_back(elem);
123 DicomDirPatientList.push_back(elem);
126 DicomDirStudyList.push_back(elem);
129 DicomDirSerieList.push_back(elem);
132 DicomDirImageList.push_back(elem);
140 //-----------------------------------------------------------------------------
143 //-----------------------------------------------------------------------------
146 //-----------------------------------------------------------------------------
150 * @param os The output stream to be written to.
152 void DicomDirElement::Print(std::ostream &os)
154 std::ostringstream s;
155 std::list<Element>::iterator it;
156 //char greltag[10]; //group element tag
159 s << "Meta Elements :"<<std::endl;
160 for (it = DicomDirMetaList.begin(); it != DicomDirMetaList.end(); ++it)
162 greltag = Util::Format("%04x|%04x ",it->Group,it->Elem);
163 s << " (" << greltag << ") = " << it->Value << std::endl;
166 s << "Patient Elements :"<<std::endl;
167 for (it = DicomDirPatientList.begin(); it != DicomDirPatientList.end(); ++it)
169 greltag = Util::Format("%04x|%04x ",it->Group,it->Elem);
170 s << " (" << greltag << ") = " << it->Value << std::endl;
173 s << "Study Elements :"<<std::endl;
174 for (it = DicomDirStudyList.begin(); it != DicomDirStudyList.end(); ++it)
176 greltag = Util::Format("%04x|%04x ", it->Group, it->Elem);
177 s << " (" << greltag << ") = " << it->Value << std::endl;
180 s << "Serie Elements :"<<std::endl;
181 for (it = DicomDirSerieList.begin(); it != DicomDirSerieList.end(); ++it)
183 greltag = Util::Format("%04x|%04x ", it->Group, it->Elem);
184 s << " (" << greltag << ") = " << it->Value << std::endl;
187 s << "Image Elements :"<<std::endl;
188 for (it = DicomDirImageList.begin(); it != DicomDirImageList.end(); ++it)
190 greltag = Util::Format("%04x|%04x ", it->Group, it->Elem);
191 s << " (" << greltag << ") = " << it->Value << std::endl;
197 //-----------------------------------------------------------------------------
198 } // end namespace gdcm