1 /*=========================================================================
4 Module: $RCSfile: gdcmDicomDirElement.cxx,v $
6 Date: $Date: 2005/01/18 07:53:42 $
7 Version: $Revision: 1.27 $
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 dictionary" << filename.c_str());
44 FillDefaultDIRDict( this );
55 from.getline(buff, 1024, ' ');
58 if( type == "metaElem" || type == "patientElem" ||
59 type == "studyElem" || type == "serieElem" ||
62 from >> std::hex >> elem.Group >> elem.Elem;
65 from.getline(buff, 1024, '"');
67 from.getline(buff, 1024, '"');
70 AddNewEntry(type, elem);
72 from.getline(buff, 1024, '\n');
79 * \brief canonical destructor
81 DicomDirElement::~DicomDirElement()
83 DicomDirMetaList.clear();
84 DicomDirPatientList.clear();
85 DicomDirStudyList.clear();
86 DicomDirSerieList.clear();
87 DicomDirImageList.clear();
90 //-----------------------------------------------------------------------------
94 * \todo add a 'Print Level' check
95 * @param os The output stream to be written to.
97 void DicomDirElement::Print(std::ostream &os)
100 std::list<Element>::iterator it;
101 //char greltag[10]; //group element tag
104 s << "Meta Elements :"<<std::endl;
105 for (it = DicomDirMetaList.begin(); it != DicomDirMetaList.end(); ++it)
107 greltag = Util::Format("%04x|%04x ",it->Group,it->Elem);
108 s << " (" << greltag << ") = " << it->Value << std::endl;
111 s << "Patient Elements :"<<std::endl;
112 for (it = DicomDirPatientList.begin(); it != DicomDirPatientList.end(); ++it)
114 greltag = Util::Format("%04x|%04x ",it->Group,it->Elem);
115 s << " (" << greltag << ") = " << it->Value << std::endl;
118 s << "Study Elements :"<<std::endl;
119 for (it = DicomDirStudyList.begin(); it != DicomDirStudyList.end(); ++it)
121 greltag = Util::Format("%04x|%04x ", it->Group, it->Elem);
122 s << " (" << greltag << ") = " << it->Value << std::endl;
125 s << "Serie Elements :"<<std::endl;
126 for (it = DicomDirSerieList.begin(); it != DicomDirSerieList.end(); ++it)
128 greltag = Util::Format("%04x|%04x ", it->Group, it->Elem);
129 s << " (" << greltag << ") = " << it->Value << std::endl;
132 s << "Image Elements :"<<std::endl;
133 for (it = DicomDirImageList.begin(); it != DicomDirImageList.end(); ++it)
135 greltag = Util::Format("%04x|%04x ", it->Group, it->Elem);
136 s << " (" << greltag << ") = " << it->Value << std::endl;
142 //-----------------------------------------------------------------------------
150 bool DicomDirElement::AddNewEntry(std::string const &type,
153 if( type == "metaElem" )
155 DicomDirMetaList.push_back(elem);
157 else if( type == "patientElem" )
159 DicomDirPatientList.push_back(elem);
161 else if( type == "studyElem" )
163 DicomDirStudyList.push_back(elem);
165 else if( type == "serieElem" )
167 DicomDirSerieList.push_back(elem);
169 else if( type == "imageElem" )
171 DicomDirImageList.push_back(elem);
179 //-----------------------------------------------------------------------------
182 //-----------------------------------------------------------------------------
185 //-----------------------------------------------------------------------------
187 } // end namespace gdcm