00001
00002
00003 #include <fstream>
00004 #include <stdio.h>
00005
00006 #include "gdcmDicomDirElement.h"
00007 #include "gdcmUtil.h"
00008
00009 #ifndef PUB_DICT_PATH
00010 # define PUB_DICT_PATH "../Dicts/"
00011 #endif
00012 #define DICT_ELEM "DicomDir.dic"
00013
00014 #include <iostream>
00015 #ifdef GDCM_NO_ANSI_STRING_STREAM
00016 # include <strstream>
00017 # define ostringstream ostrstream
00018 # else
00019 # include <sstream>
00020 #endif
00021
00022
00023
00024
00029 gdcmDicomDirElement::gdcmDicomDirElement(void)
00030 {
00031 std::string filename=gdcmDictSet::BuildDictPath() + std::string(DICT_ELEM);
00032 std::ifstream from(filename.c_str());
00033 dbg.Error(!from, "gdcmDicomDirElement::gdcmDicomDirElement: can't open dictionary",filename.c_str());
00034
00035 char buff[1024];
00036 std::string type;
00037 gdcmElement elem;
00038
00039 while (!from.eof()) {
00040 eatwhite(from);
00041 from.getline(buff, 1024, ' ');
00042 type = buff;
00043
00044 if( (type=="metaElem") || (type=="patientElem") ||
00045 (type=="studyElem") || (type=="serieElem") ||
00046 (type=="imageElem") )
00047 {
00048 from >> std::hex >> elem.group >> elem.elem;
00049
00050 eatwhite(from);
00051 from.getline(buff, 1024, '"');
00052 eatwhite(from);
00053 from.getline(buff, 1024, '"');
00054 elem.value = buff;
00055
00056 if(type=="metaElem")
00057 MetaList.push_back(elem);
00058 else if(type=="patientElem")
00059 PatientList.push_back(elem);
00060 else if(type=="studyElem")
00061 StudyList.push_back(elem);
00062 else if(type=="serieElem")
00063 SerieList.push_back(elem);
00064 else if(type=="imageElem")
00065 ImageList.push_back(elem);
00066 }
00067
00068 from.getline(buff, 1024, '\n');
00069 }
00070 from.close();
00071 }
00072
00077 gdcmDicomDirElement::~gdcmDicomDirElement()
00078 {
00079 MetaList.clear();
00080 PatientList.clear();
00081 StudyList.clear();
00082 SerieList.clear();
00083 ImageList.clear();
00084 }
00085
00086
00087
00094 void gdcmDicomDirElement::Print(std::ostream &os)
00095 {
00096 std::ostringstream s;
00097 std::list<gdcmElement>::iterator it;
00098 char greltag[10];
00099
00100 s << "Meta Elements :"<<std::endl;
00101 for (it = MetaList.begin();it!=MetaList.end();++it)
00102 {
00103 sprintf(greltag,"%04x|%04x ",it->group,it->elem);
00104 s << " ("<<greltag<<") = "<< it->value<<std::endl;
00105 }
00106
00107 s << "Patient Elements :"<<std::endl;
00108 for (it = PatientList.begin();it!=PatientList.end();++it)
00109 {
00110 sprintf(greltag,"%04x|%04x ",it->group,it->elem);
00111 s << " ("<<greltag<<") = "<< it->value<<std::endl;
00112 }
00113
00114 s << "Study Elements :"<<std::endl;
00115 for (it = StudyList.begin();it!=StudyList.end();++it)
00116 {
00117 sprintf(greltag,"%04x|%04x ",it->group,it->elem);
00118 s << " ("<<greltag<<") = "<< it->value<<std::endl;
00119 }
00120
00121 s << "Serie Elements :"<<std::endl;
00122 for (it = SerieList.begin();it!=SerieList.end();++it)
00123 {
00124 sprintf(greltag,"%04x|%04x ",it->group,it->elem);
00125 s << " ("<<greltag<<") = "<< it->value<<std::endl;
00126 }
00127
00128 s << "Image Elements :"<<std::endl;
00129 for (it = ImageList.begin();it!=ImageList.end();++it)
00130 {
00131 sprintf(greltag,"%04x|%04x ",it->group,it->elem);
00132 s << " ("<<greltag<<") = "<< it->value<<std::endl;
00133 }
00134
00135 os << s.str();
00136 }
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147