1 /*=========================================================================
4 Module: $RCSfile: gdcmDicomDirElement.cxx,v $
6 Date: $Date: 2005/01/07 22:03:30 $
7 Version: $Revision: 1.26 $
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 * \ingroup DicomDirElement
80 * \brief canonical destructor
82 DicomDirElement::~DicomDirElement()
84 DicomDirMetaList.clear();
85 DicomDirPatientList.clear();
86 DicomDirStudyList.clear();
87 DicomDirSerieList.clear();
88 DicomDirImageList.clear();
91 //-----------------------------------------------------------------------------
94 * \ingroup DicomDirElement
96 * \todo add a 'Print Level' check
97 * @param os The output stream to be written to.
99 void DicomDirElement::Print(std::ostream &os)
101 std::ostringstream s;
102 std::list<Element>::iterator it;
103 //char greltag[10]; //group element tag
106 s << "Meta Elements :"<<std::endl;
107 for (it = DicomDirMetaList.begin(); it != DicomDirMetaList.end(); ++it)
109 greltag = Util::Format("%04x|%04x ",it->Group,it->Elem);
110 s << " (" << greltag << ") = " << it->Value << std::endl;
113 s << "Patient Elements :"<<std::endl;
114 for (it = DicomDirPatientList.begin(); it != DicomDirPatientList.end(); ++it)
116 greltag = Util::Format("%04x|%04x ",it->Group,it->Elem);
117 s << " (" << greltag << ") = " << it->Value << std::endl;
120 s << "Study Elements :"<<std::endl;
121 for (it = DicomDirStudyList.begin(); it != DicomDirStudyList.end(); ++it)
123 greltag = Util::Format("%04x|%04x ", it->Group, it->Elem);
124 s << " (" << greltag << ") = " << it->Value << std::endl;
127 s << "Serie Elements :"<<std::endl;
128 for (it = DicomDirSerieList.begin(); it != DicomDirSerieList.end(); ++it)
130 greltag = Util::Format("%04x|%04x ", it->Group, it->Elem);
131 s << " (" << greltag << ") = " << it->Value << std::endl;
134 s << "Image Elements :"<<std::endl;
135 for (it = DicomDirImageList.begin(); it != DicomDirImageList.end(); ++it)
137 greltag = Util::Format("%04x|%04x ", it->Group, it->Elem);
138 s << " (" << greltag << ") = " << it->Value << std::endl;
144 //-----------------------------------------------------------------------------
147 bool DicomDirElement::AddNewEntry(std::string const &type,
150 if( type == "metaElem" )
152 DicomDirMetaList.push_back(elem);
154 else if( type == "patientElem" )
156 DicomDirPatientList.push_back(elem);
158 else if( type == "studyElem" )
160 DicomDirStudyList.push_back(elem);
162 else if( type == "serieElem" )
164 DicomDirSerieList.push_back(elem);
166 else if( type == "imageElem" )
168 DicomDirImageList.push_back(elem);
176 //-----------------------------------------------------------------------------
179 //-----------------------------------------------------------------------------
182 //-----------------------------------------------------------------------------
184 } // end namespace gdcm