1 /*=========================================================================
4 Module: $RCSfile: gdcmDicomDirElement.cxx,v $
6 Date: $Date: 2005/02/07 14:48:34 $
7 Version: $Revision: 1.35 $
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 //-----------------------------------------------------------------------------
30 void FillDefaultDIRDict(DicomDirElement *dde);
32 //-----------------------------------------------------------------------------
33 // Constructor / Destructor
35 * \brief constructor : populates the chained lists
36 * from the file 'Dicts/DicomDir.dic'
38 DicomDirElement::DicomDirElement()
40 std::string filename = DictSet::BuildDictPath() + DICT_ELEM;
41 std::ifstream from(filename.c_str());
44 gdcmWarningMacro( "Can't open DicomDirElement dictionary"
46 FillDefaultDIRDict( this );
58 from.getline(buff, 1024, ' ');
61 if( strType == "metaElem" )
63 else if( strType == "patientElem" )
65 else if( strType == "studyElem" )
67 else if( strType == "serieElem" )
69 else if( strType == "imageElem" )
73 gdcmWarningMacro("Unknown type found in the file : "
78 if( type!=DD_UNKNOWN )
80 from >> std::hex >> elem.Group >> elem.Elem;
83 from.getline(buff, 1024, '"');
85 from.getline(buff, 1024, '"');
90 from.getline(buff, 1024, '\n');
97 * \brief canonical destructor
99 DicomDirElement::~DicomDirElement()
101 DicomDirMetaList.clear();
102 DicomDirPatientList.clear();
103 DicomDirStudyList.clear();
104 DicomDirSerieList.clear();
105 DicomDirImageList.clear();
108 //-----------------------------------------------------------------------------
111 * \brief Add an entry to one of the DicomDir Elements
112 * (Patient, Study, Serie, Image)
113 * @param type Element type (DD_PATIENT, DD_STUDY, DD_SERIE, DD_IMAGE)
116 bool DicomDirElement::AddEntry(DicomDirType type, Element const &elem)
121 DicomDirMetaList.push_back(elem);
124 DicomDirPatientList.push_back(elem);
127 DicomDirStudyList.push_back(elem);
130 DicomDirSerieList.push_back(elem);
133 DicomDirImageList.push_back(elem);
142 * \brief Add an entry to one of the DicomDir Elements
143 * (Patient, Study, Serie, Image)
144 * @param type Element type (DD_PATIENT, DD_STUDY, DD_SERIE, DD_IMAGE)
145 * @param group Group number of the entry to be added
146 * @param elem Element number of the entry to be added
148 void DicomDirElement::AddDicomDirElement(DicomDirType type,
149 uint16_t group, uint16_t elem)
157 //-----------------------------------------------------------------------------
160 //-----------------------------------------------------------------------------
163 //-----------------------------------------------------------------------------
167 * @param os The output stream to be written to.
169 void DicomDirElement::Print(std::ostream &os)
171 std::ostringstream s;
172 std::list<Element>::iterator it;
173 //char greltag[10]; //group element tag
176 s << "Meta Elements :"<<std::endl;
177 for (it = DicomDirMetaList.begin(); it != DicomDirMetaList.end(); ++it)
179 greltag = Util::Format("%04x|%04x ",it->Group,it->Elem);
180 s << " (" << greltag << ") = " << it->Value << std::endl;
183 s << "Patient Elements :"<<std::endl;
184 for (it = DicomDirPatientList.begin(); it != DicomDirPatientList.end(); ++it)
186 greltag = Util::Format("%04x|%04x ",it->Group,it->Elem);
187 s << " (" << greltag << ") = " << it->Value << std::endl;
190 s << "Study Elements :"<<std::endl;
191 for (it = DicomDirStudyList.begin(); it != DicomDirStudyList.end(); ++it)
193 greltag = Util::Format("%04x|%04x ", it->Group, it->Elem);
194 s << " (" << greltag << ") = " << it->Value << std::endl;
197 s << "Serie Elements :"<<std::endl;
198 for (it = DicomDirSerieList.begin(); it != DicomDirSerieList.end(); ++it)
200 greltag = Util::Format("%04x|%04x ", it->Group, it->Elem);
201 s << " (" << greltag << ") = " << it->Value << std::endl;
204 s << "Image Elements :"<<std::endl;
205 for (it = DicomDirImageList.begin(); it != DicomDirImageList.end(); ++it)
207 greltag = Util::Format("%04x|%04x ", it->Group, it->Elem);
208 s << " (" << greltag << ") = " << it->Value << std::endl;
214 //-----------------------------------------------------------------------------
215 } // end namespace gdcm