00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "gdcmDicomDirElement.h"
00020 #include "gdcmUtil.h"
00021 #include "gdcmDebug.h"
00022 #include "gdcmDictSet.h"
00023
00024 #include <fstream>
00025 #include <iostream>
00026
00027 namespace gdcm
00028 {
00029
00030 void FillDefaultDIRDict(DicomDirElement *dde);
00031
00032
00033
00038 DicomDirElement::DicomDirElement()
00039 {
00040 std::string filename = DictSet::BuildDictPath() + DICT_ELEM;
00041 std::ifstream from(filename.c_str());
00042 if(!from)
00043 {
00044 gdcmWarningMacro( "Can't open DicomDirElement dictionary"
00045 << filename.c_str());
00046 FillDefaultDIRDict( this );
00047 }
00048 else
00049 {
00050 char buff[1024];
00051 std::string strType;
00052 Element elem;
00053 DicomDirType type;
00054
00055 while (!from.eof())
00056 {
00057 from >> std::ws;
00058 from.getline(buff, 1024, ' ');
00059 strType = buff;
00060
00061 if( strType == "metaElem" )
00062 type = DD_META;
00063 else if( strType == "patientElem" )
00064 type = DD_PATIENT;
00065 else if( strType == "studyElem" )
00066 type = DD_STUDY;
00067 else if( strType == "serieElem" )
00068 type = DD_SERIE;
00069 else if( strType == "imageElem" )
00070 type = DD_IMAGE;
00071 else
00072 {
00073 gdcmWarningMacro("Unknown type found in the file : "
00074 <<filename.c_str());
00075 type = DD_UNKNOWN;
00076 }
00077
00078 if( type!=DD_UNKNOWN )
00079 {
00080 from >> std::hex >> elem.Group >> elem.Elem;
00081
00082 from >> std::ws;
00083 from.getline(buff, 1024, '"');
00084 from >> std::ws;
00085 from.getline(buff, 1024, '"');
00086 elem.Value = buff;
00087
00088 AddEntry(type, elem);
00089 }
00090 from.getline(buff, 1024, '\n');
00091 }
00092 from.close();
00093 }
00094 }
00095
00099 DicomDirElement::~DicomDirElement()
00100 {
00101 DicomDirMetaList.clear();
00102 DicomDirPatientList.clear();
00103 DicomDirStudyList.clear();
00104 DicomDirSerieList.clear();
00105 DicomDirImageList.clear();
00106 }
00107
00108
00109
00116 bool DicomDirElement::AddEntry(DicomDirType type, Element const &elem)
00117 {
00118 switch( type )
00119 {
00120 case DD_META :
00121 DicomDirMetaList.push_back(elem);
00122 break;
00123 case DD_PATIENT :
00124 DicomDirPatientList.push_back(elem);
00125 break;
00126 case DD_STUDY :
00127 DicomDirStudyList.push_back(elem);
00128 break;
00129 case DD_SERIE :
00130 DicomDirSerieList.push_back(elem);
00131 break;
00132 case DD_IMAGE :
00133 DicomDirImageList.push_back(elem);
00134 break;
00135 default :
00136 return false;
00137 }
00138 return true;
00139 }
00140
00148 void DicomDirElement::AddDicomDirElement(DicomDirType type,
00149 uint16_t group, uint16_t elem)
00150 {
00151 Element el;
00152 el.Group = group;
00153 el.Elem = elem;
00154 el.Value = "";
00155 AddEntry(type, el);
00156 }
00157
00158
00159
00160
00161
00162
00163
00164
00169 void DicomDirElement::Print(std::ostream &os)
00170 {
00171 std::ostringstream s;
00172 std::list<Element>::iterator it;
00173
00174 std::string greltag;
00175
00176 s << "Meta Elements :"<<std::endl;
00177 for (it = DicomDirMetaList.begin(); it != DicomDirMetaList.end(); ++it)
00178 {
00179 greltag = Util::Format("%04x|%04x ",it->Group,it->Elem);
00180 s << " (" << greltag << ") = " << it->Value << std::endl;
00181 }
00182
00183 s << "Patient Elements :"<<std::endl;
00184 for (it = DicomDirPatientList.begin(); it != DicomDirPatientList.end(); ++it)
00185 {
00186 greltag = Util::Format("%04x|%04x ",it->Group,it->Elem);
00187 s << " (" << greltag << ") = " << it->Value << std::endl;
00188 }
00189
00190 s << "Study Elements :"<<std::endl;
00191 for (it = DicomDirStudyList.begin(); it != DicomDirStudyList.end(); ++it)
00192 {
00193 greltag = Util::Format("%04x|%04x ", it->Group, it->Elem);
00194 s << " (" << greltag << ") = " << it->Value << std::endl;
00195 }
00196
00197 s << "Serie Elements :"<<std::endl;
00198 for (it = DicomDirSerieList.begin(); it != DicomDirSerieList.end(); ++it)
00199 {
00200 greltag = Util::Format("%04x|%04x ", it->Group, it->Elem);
00201 s << " (" << greltag << ") = " << it->Value << std::endl;
00202 }
00203
00204 s << "Image Elements :"<<std::endl;
00205 for (it = DicomDirImageList.begin(); it != DicomDirImageList.end(); ++it)
00206 {
00207 greltag = Util::Format("%04x|%04x ", it->Group, it->Elem);
00208 s << " (" << greltag << ") = " << it->Value << std::endl;
00209 }
00210
00211 os << s.str();
00212 }
00213
00214
00215 }