1 /*=========================================================================
4 Module: $RCSfile: gdcmDicomDirElement.cxx,v $
6 Date: $Date: 2005/01/24 14:14:10 $
7 Version: $Revision: 1.31 $
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 );
57 from.getline(buff, 1024, ' ');
60 if( strType == "metaElem" )
62 else if( strType == "patientElem" )
64 else if( strType == "studyElem" )
66 else if( strType == "serieElem" )
68 else if( strType == "imageElem" )
72 gdcmVerboseMacro("Unknown type found in the file : "
77 if( type!=DD_UNKNOWN )
79 from >> std::hex >> elem.Group >> elem.Elem;
82 from.getline(buff, 1024, '"');
84 from.getline(buff, 1024, '"');
89 from.getline(buff, 1024, '\n');
96 * \brief canonical destructor
98 DicomDirElement::~DicomDirElement()
100 DicomDirMetaList.clear();
101 DicomDirPatientList.clear();
102 DicomDirStudyList.clear();
103 DicomDirSerieList.clear();
104 DicomDirImageList.clear();
107 //-----------------------------------------------------------------------------
111 * \todo add a 'Print Level' check
112 * @param os The output stream to be written to.
114 void DicomDirElement::Print(std::ostream &os)
116 std::ostringstream s;
117 std::list<Element>::iterator it;
118 //char greltag[10]; //group element tag
121 s << "Meta Elements :"<<std::endl;
122 for (it = DicomDirMetaList.begin(); it != DicomDirMetaList.end(); ++it)
124 greltag = Util::Format("%04x|%04x ",it->Group,it->Elem);
125 s << " (" << greltag << ") = " << it->Value << std::endl;
128 s << "Patient Elements :"<<std::endl;
129 for (it = DicomDirPatientList.begin(); it != DicomDirPatientList.end(); ++it)
131 greltag = Util::Format("%04x|%04x ",it->Group,it->Elem);
132 s << " (" << greltag << ") = " << it->Value << std::endl;
135 s << "Study Elements :"<<std::endl;
136 for (it = DicomDirStudyList.begin(); it != DicomDirStudyList.end(); ++it)
138 greltag = Util::Format("%04x|%04x ", it->Group, it->Elem);
139 s << " (" << greltag << ") = " << it->Value << std::endl;
142 s << "Serie Elements :"<<std::endl;
143 for (it = DicomDirSerieList.begin(); it != DicomDirSerieList.end(); ++it)
145 greltag = Util::Format("%04x|%04x ", it->Group, it->Elem);
146 s << " (" << greltag << ") = " << it->Value << std::endl;
149 s << "Image Elements :"<<std::endl;
150 for (it = DicomDirImageList.begin(); it != DicomDirImageList.end(); ++it)
152 greltag = Util::Format("%04x|%04x ", it->Group, it->Elem);
153 s << " (" << greltag << ") = " << it->Value << std::endl;
159 //-----------------------------------------------------------------------------
162 * \brief Add an entry
166 bool DicomDirElement::AddEntry(DicomDirType type, Element const &elem)
171 DicomDirMetaList.push_back(elem);
174 DicomDirPatientList.push_back(elem);
177 DicomDirStudyList.push_back(elem);
180 DicomDirSerieList.push_back(elem);
183 DicomDirImageList.push_back(elem);
190 //-----------------------------------------------------------------------------
193 //-----------------------------------------------------------------------------
196 //-----------------------------------------------------------------------------
198 } // end namespace gdcm