1 /*=========================================================================
4 Module: $RCSfile: gdcmDicomDirElement.cxx,v $
6 Date: $Date: 2007/03/23 15:30:15 $
7 Version: $Revision: 1.44 $
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 /// \brief auto generate function, to fill up the default elements for
31 /// a DICOMDIR, if relevant file is not found on user's disk
32 void FillDefaultDIRDict(DicomDirElement *dde);
34 //-----------------------------------------------------------------------------
35 // Constructor / Destructor
37 * \brief constructor : populates the chained lists
38 * from the file 'Dicts/DicomDir.dic'
40 DicomDirElement::DicomDirElement()
42 std::string filename = DictSet::BuildDictPath() + DICT_ELEM;
43 std::ifstream from(filename.c_str());
46 gdcmWarningMacro( "Can't open DicomDirElement dictionary"
48 FillDefaultDIRDict( this );
60 from.getline(buff, 1024, ' ');
63 if ( strType == "imageElem" )
65 else if ( strType == "serieElem" )
67 else if ( strType == "studyElem" )
69 else if ( strType == "patientElem" )
71 else if ( strType == "metaElem" )
75 gdcmWarningMacro("Unknown type (" << strType
76 << ") found in the file : "
81 if ( type!=DD_UNKNOWN )
83 from >> std::hex >> elem.Group >> elem.Elem;// >> elem.VR;
85 from.getline(buff2, 1024, '"');
87 from.getline(buff2, 1024, '"');
88 elem.VR[0] = buff2[0];
89 elem.VR[1] = buff2[1];
90 // std::cout << "VR : [" << elem.VR[0] << elem.VR[1] << "]" << std::endl; // JPR
92 from.getline(buff, 1024, '"');
94 from.getline(buff, 1024, '"');
99 from.getline(buff, 1024, '\n');
106 * \brief canonical destructor
108 DicomDirElement::~DicomDirElement()
110 DicomDirMetaList.clear();
111 DicomDirPatientList.clear();
112 DicomDirStudyList.clear();
113 DicomDirSerieList.clear();
114 DicomDirImageList.clear();
117 //-----------------------------------------------------------------------------
120 * \brief Add an entry to one of the DicomDir Elements
121 * (Patient, Study, Serie, Image)
122 * @param type Element type (DD_PATIENT, DD_STUDY, DD_SERIE, DD_IMAGE)
125 bool DicomDirElement::AddEntry(DicomDirType type, DicomElement const &elem)
130 DicomDirImageList.push_back(elem);
133 DicomDirSerieList.push_back(elem);
136 DicomDirStudyList.push_back(elem);
139 DicomDirPatientList.push_back(elem);
142 DicomDirMetaList.push_back(elem);
151 * \brief Add an entry to one of the DicomDir Elements
152 * (Patient, Study, Serie, Image)
153 * @param type Element type (DD_PATIENT, DD_STUDY, DD_SERIE, DD_IMAGE)
154 * @param group Group number of the entry to be added
155 * @param elem Element number of the entry to be added
156 * @param vr Value Representation of the entry to be added
158 void DicomDirElement::AddDicomDirElement(DicomDirType type,
159 uint16_t group, uint16_t elem, VRKey vr)
169 //-----------------------------------------------------------------------------
172 //-----------------------------------------------------------------------------
175 //-----------------------------------------------------------------------------
179 * @param os The output stream to be written to.
181 void DicomDirElement::Print(std::ostream &os,std::string const &)
183 std::ostringstream s;
184 std::list<DicomElement>::iterator it;
187 s << "Meta Elements :"<<std::endl;
188 for (it = DicomDirMetaList.begin(); it != DicomDirMetaList.end(); ++it)
190 greltag = DictEntry::TranslateToKey(it->Group,it->Elem);
191 s << " (" << greltag << ") = " << it->Value << std::endl;
194 s << "Patient Elements :"<<std::endl;
195 for (it = DicomDirPatientList.begin(); it != DicomDirPatientList.end(); ++it)
197 greltag = DictEntry::TranslateToKey(it->Group,it->Elem);
198 s << " (" << greltag << ") = " << it->Value << std::endl;
201 s << "Study Elements :"<<std::endl;
202 for (it = DicomDirStudyList.begin(); it != DicomDirStudyList.end(); ++it)
204 greltag = DictEntry::TranslateToKey(it->Group, it->Elem);
205 s << " (" << greltag << ") = " << it->Value << std::endl;
208 s << "Serie Elements :"<<std::endl;
209 for (it = DicomDirSerieList.begin(); it != DicomDirSerieList.end(); ++it)
211 greltag = DictEntry::TranslateToKey( it->Group, it->Elem);
212 s << " (" << greltag << ") = " << it->Value << std::endl;
215 s << "Image Elements :"<<std::endl;
216 for (it = DicomDirImageList.begin(); it != DicomDirImageList.end(); ++it)
218 greltag = DictEntry::TranslateToKey(it->Group, it->Elem);
219 s << " (" << greltag << ") = " << it->Value << std::endl;
225 //-----------------------------------------------------------------------------
226 } // end namespace gdcm