1 /*=========================================================================
4 Module: $RCSfile: gdcmDicomDirElement.cxx,v $
6 Date: $Date: 2004/11/04 15:59:37 $
7 Version: $Revision: 1.22 $
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());
44 "DicomDirElement::DicomDirElement: can't open dictionary",
46 FillDefaultDIRDict( this );
57 from.getline(buff, 1024, ' ');
60 if( type == "metaElem" || type == "patientElem" ||
61 type == "studyElem" || type == "serieElem" ||
64 from >> std::hex >> elem.Group >> elem.Elem;
67 from.getline(buff, 1024, '"');
69 from.getline(buff, 1024, '"');
72 AddNewEntry(type, elem);
74 from.getline(buff, 1024, '\n');
81 * \ingroup DicomDirElement
82 * \brief canonical destructor
84 DicomDirElement::~DicomDirElement()
86 DicomDirMetaList.clear();
87 DicomDirPatientList.clear();
88 DicomDirStudyList.clear();
89 DicomDirSerieList.clear();
90 DicomDirImageList.clear();
93 //-----------------------------------------------------------------------------
96 * \ingroup DicomDirElement
98 * \todo add a 'Print Level' check
99 * @param os The output stream to be written to.
101 void DicomDirElement::Print(std::ostream &os)
103 std::ostringstream s;
104 std::list<Element>::iterator it;
105 //char greltag[10]; //group element tag
108 s << "Meta Elements :"<<std::endl;
109 for (it = DicomDirMetaList.begin(); it != DicomDirMetaList.end(); ++it)
111 greltag = Util::Format("%04x|%04x ",it->Group,it->Elem);
112 s << " (" << greltag << ") = " << it->Value << std::endl;
115 s << "Patient Elements :"<<std::endl;
116 for (it = DicomDirPatientList.begin(); it != DicomDirPatientList.end(); ++it)
118 greltag = Util::Format("%04x|%04x ",it->Group,it->Elem);
119 s << " (" << greltag << ") = " << it->Value << std::endl;
122 s << "Study Elements :"<<std::endl;
123 for (it = DicomDirStudyList.begin(); it != DicomDirStudyList.end(); ++it)
125 greltag = Util::Format("%04x|%04x ", it->Group, it->Elem);
126 s << " (" << greltag << ") = " << it->Value << std::endl;
129 s << "Serie Elements :"<<std::endl;
130 for (it = DicomDirSerieList.begin(); it != DicomDirSerieList.end(); ++it)
132 greltag = Util::Format("%04x|%04x ", it->Group, it->Elem);
133 s << " (" << greltag << ") = " << it->Value << std::endl;
136 s << "Image Elements :"<<std::endl;
137 for (it = DicomDirImageList.begin(); it != DicomDirImageList.end(); ++it)
139 greltag = Util::Format("%04x|%04x ", it->Group, it->Elem);
140 s << " (" << greltag << ") = " << it->Value << std::endl;
146 //-----------------------------------------------------------------------------
149 bool DicomDirElement::AddNewEntry(std::string const & type,
150 Element const & elem)
152 if( type == "metaElem" )
154 DicomDirMetaList.push_back(elem);
156 else if( type == "patientElem" )
158 DicomDirPatientList.push_back(elem);
160 else if( type == "studyElem" )
162 DicomDirStudyList.push_back(elem);
164 else if( type == "serieElem" )
166 DicomDirSerieList.push_back(elem);
168 else if( type == "imageElem" )
170 DicomDirImageList.push_back(elem);
178 //-----------------------------------------------------------------------------
181 //-----------------------------------------------------------------------------
184 //-----------------------------------------------------------------------------
186 } // end namespace gdcm