]> Creatis software - gdcm.git/blob - src/gdcmDicomDirElement.cxx
cc83188dd8e4926c0d731f44611de96b9954cfbe
[gdcm.git] / src / gdcmDicomDirElement.cxx
1 // gdcmDicomDirElement.cxx
2 //-----------------------------------------------------------------------------
3 #include <fstream>
4
5 #include "gdcmDicomDirElement.h"
6 #include "gdcmUtil.h"
7
8 #ifndef PUB_DICT_PATH
9 #  define PUB_DICT_PATH     "../Dicts/"
10 #endif
11 #define DICT_ELEM "DicomDir.dic"
12
13 #include <iostream>
14 #ifdef GDCM_NO_ANSI_STRING_STREAM
15 #  include <strstream>
16 #  define  ostringstream ostrstream
17 # else
18 #  include <sstream>
19 #endif
20
21 //-----------------------------------------------------------------------------
22 // Constructor / Destructor
23 gdcmDicomDirElement::gdcmDicomDirElement(void) 
24 {
25    std::string filename=gdcmDictSet::BuildDictPath() + std::string(DICT_ELEM);
26    std::ifstream from(filename.c_str());
27    dbg.Error(!from, "gdcmDicomDirElement::gdcmDicomDirElement: can't open dictionary",filename.c_str());
28
29    char buff[1024];
30    std::string type;
31    gdcmElement elem;
32
33    while (!from.eof()) {
34       eatwhite(from);
35       from.getline(buff, 1024, ' ');
36       type = buff;
37
38       if( (type=="metaElem") || (type=="patientElem") || 
39           (type=="studyElem") || (type=="serieElem") || 
40           (type=="imageElem") )
41       {
42          from >> std::hex >> elem.group >> elem.elem;
43
44          eatwhite(from);
45          from.getline(buff, 1024, '"');
46          eatwhite(from);
47          from.getline(buff, 1024, '"');
48          elem.value = buff;
49
50          if(type=="metaElem")
51             MetaList.push_back(elem);
52          else if(type=="patientElem")
53             PatientList.push_back(elem);
54          else if(type=="studyElem")
55             StudyList.push_back(elem);
56          else if(type=="serieElem")
57             SerieList.push_back(elem);
58          else if(type=="imageElem")
59             ImageList.push_back(elem);
60       }
61
62       from.getline(buff, 1024, '\n');
63    }
64    from.close();
65 }
66
67 gdcmDicomDirElement::~gdcmDicomDirElement() 
68 {
69    MetaList.clear();
70    PatientList.clear();
71    StudyList.clear();
72    SerieList.clear();
73    ImageList.clear();
74 }
75
76 //-----------------------------------------------------------------------------
77 // Print
78 /**
79  * \ingroup gdcmVR
80  * \brief   Print all 
81  * @param   os The output stream to be written to.
82  */
83 void gdcmDicomDirElement::Print(std::ostream &os) 
84 {
85    std::ostringstream s;
86    std::list<gdcmElement>::iterator it;
87    char greltag[10];  //group element tag
88
89    s << "Meta Elements :"<<std::endl;
90    for (it = MetaList.begin();it!=MetaList.end();++it)
91    {
92       sprintf(greltag,"%04x|%04x ",it->group,it->elem);
93       s << "   ("<<greltag<<") = "<< it->value<<std::endl;
94    }
95
96    s << "Patient Elements :"<<std::endl;
97    for (it = PatientList.begin();it!=PatientList.end();++it)
98    {
99       sprintf(greltag,"%04x|%04x ",it->group,it->elem);
100       s << "   ("<<greltag<<") = "<< it->value<<std::endl;
101    }
102
103    s << "Study Elements :"<<std::endl;
104    for (it = StudyList.begin();it!=StudyList.end();++it)
105    {
106       sprintf(greltag,"%04x|%04x ",it->group,it->elem);
107       s << "   ("<<greltag<<") = "<< it->value<<std::endl;
108    }
109
110    s << "Serie Elements :"<<std::endl;
111    for (it = SerieList.begin();it!=SerieList.end();++it)
112    {
113       sprintf(greltag,"%04x|%04x ",it->group,it->elem);
114       s << "   ("<<greltag<<") = "<< it->value<<std::endl;
115    }
116
117    s << "Image Elements :"<<std::endl;
118    for (it = ImageList.begin();it!=ImageList.end();++it)
119    {
120       sprintf(greltag,"%04x|%04x ",it->group,it->elem);
121       s << "   ("<<greltag<<") = "<< it->value<<std::endl;
122    }
123
124    os << s.str();
125 }
126
127 //-----------------------------------------------------------------------------
128 // Public
129
130 //-----------------------------------------------------------------------------
131 // Protected
132
133 //-----------------------------------------------------------------------------
134 // Private
135
136 //-----------------------------------------------------------------------------