1 /*=========================================================================
4 Module: $RCSfile: gdcmDicomDirElement.cxx,v $
6 Date: $Date: 2005/01/20 11:09:23 $
7 Version: $Revision: 1.28 $
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 void FillDefaultDIRDict(DicomDirElement *dde);
30 //-----------------------------------------------------------------------------
31 // Constructor / Destructor
34 * \brief constructor : populates the chained lists
35 * from the file 'Dicts/DicomDir.dic'
37 DicomDirElement::DicomDirElement()
39 std::string filename = DictSet::BuildDictPath() + DICT_ELEM;
40 std::ifstream from(filename.c_str());
43 gdcmVerboseMacro( "Can't open DicomDirElement dictionary"
45 FillDefaultDIRDict( this );
56 from.getline(buff, 1024, ' ');
59 if( type == "metaElem" || type == "patientElem" ||
60 type == "studyElem" || type == "serieElem" ||
63 from >> std::hex >> elem.Group >> elem.Elem;
66 from.getline(buff, 1024, '"');
68 from.getline(buff, 1024, '"');
71 AddNewEntry(type, elem);
73 from.getline(buff, 1024, '\n');
80 * \brief canonical destructor
82 DicomDirElement::~DicomDirElement()
84 DicomDirMetaList.clear();
85 DicomDirPatientList.clear();
86 DicomDirStudyList.clear();
87 DicomDirSerieList.clear();
88 DicomDirImageList.clear();
91 //-----------------------------------------------------------------------------
95 * \todo add a 'Print Level' check
96 * @param os The output stream to be written to.
98 void DicomDirElement::Print(std::ostream &os)
100 std::ostringstream s;
101 std::list<Element>::iterator it;
102 //char greltag[10]; //group element tag
105 s << "Meta Elements :"<<std::endl;
106 for (it = DicomDirMetaList.begin(); it != DicomDirMetaList.end(); ++it)
108 greltag = Util::Format("%04x|%04x ",it->Group,it->Elem);
109 s << " (" << greltag << ") = " << it->Value << std::endl;
112 s << "Patient Elements :"<<std::endl;
113 for (it = DicomDirPatientList.begin(); it != DicomDirPatientList.end(); ++it)
115 greltag = Util::Format("%04x|%04x ",it->Group,it->Elem);
116 s << " (" << greltag << ") = " << it->Value << std::endl;
119 s << "Study Elements :"<<std::endl;
120 for (it = DicomDirStudyList.begin(); it != DicomDirStudyList.end(); ++it)
122 greltag = Util::Format("%04x|%04x ", it->Group, it->Elem);
123 s << " (" << greltag << ") = " << it->Value << std::endl;
126 s << "Serie Elements :"<<std::endl;
127 for (it = DicomDirSerieList.begin(); it != DicomDirSerieList.end(); ++it)
129 greltag = Util::Format("%04x|%04x ", it->Group, it->Elem);
130 s << " (" << greltag << ") = " << it->Value << std::endl;
133 s << "Image Elements :"<<std::endl;
134 for (it = DicomDirImageList.begin(); it != DicomDirImageList.end(); ++it)
136 greltag = Util::Format("%04x|%04x ", it->Group, it->Elem);
137 s << " (" << greltag << ") = " << it->Value << std::endl;
143 //-----------------------------------------------------------------------------
151 bool DicomDirElement::AddNewEntry(std::string const &type,
154 if( type == "metaElem" )
156 DicomDirMetaList.push_back(elem);
158 else if( type == "patientElem" )
160 DicomDirPatientList.push_back(elem);
162 else if( type == "studyElem" )
164 DicomDirStudyList.push_back(elem);
166 else if( type == "serieElem" )
168 DicomDirSerieList.push_back(elem);
170 else if( type == "imageElem" )
172 DicomDirImageList.push_back(elem);
180 //-----------------------------------------------------------------------------
183 //-----------------------------------------------------------------------------
186 //-----------------------------------------------------------------------------
188 } // end namespace gdcm