00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "gdcmVR.h"
00020 #include "gdcmUtil.h"
00021 #include "gdcmDictSet.h"
00022 #include "gdcmDebug.h"
00023
00024 #include <fstream>
00025 #include <iostream>
00026
00027 namespace gdcm
00028 {
00029
00030 void FillDefaultVRDict(VRHT &vr);
00031
00032
00033
00037 VR::VR()
00038 {
00039 std::string filename = DictSet::BuildDictPath() + DICT_VR;
00040 std::ifstream from(filename.c_str());
00041 if(!from)
00042 {
00043 gdcmWarningMacro("Can't open dictionary" << filename.c_str());
00044 FillDefaultVRDict(vr);
00045 }
00046 else
00047 {
00048 char buff[1024];
00049 VRKey key;
00050 VRAtr name;
00051
00052 while (!from.eof())
00053 {
00054 from >> std::ws;
00055 from.getline(buff, 1024, ' ');
00056 key = buff;
00057 from >> std::ws;
00058 from.getline(buff, 1024, ';');
00059 name = buff;
00060
00061 from >> std::ws;
00062 from.getline(buff, 1024, '\n');
00063
00064 if(key != "")
00065 {
00066 vr[key] = name;
00067 }
00068 }
00069 from.close();
00070 }
00071 }
00072
00076 VR::~VR()
00077 {
00078 vr.clear();
00079 }
00080
00081
00082
00087 int VR::Count(VRKey const &key)
00088 {
00089 return vr.count(key);
00090 }
00091
00097 bool VR::IsVROfBinaryRepresentable(VRKey const &tested)
00098 {
00099 if ( tested == GDCM_UNKNOWN)
00100 return true;
00101
00102 if ( IsVROfStringRepresentable(tested) )
00103 return false;
00104
00105 if ( IsVROfSequence(tested) )
00106 return false;
00107
00108 return true;
00109 }
00110
00117 bool VR::IsVROfStringRepresentable(VRKey const &tested)
00118 {
00119 return tested == "AE" ||
00120 tested == "AS" ||
00121 tested == "CS" ||
00122 tested == "DA" ||
00123 tested == "DS" ||
00124 tested == "IS" ||
00125 tested == "LO" ||
00126 tested == "LT" ||
00127 tested == "PN" ||
00128 tested == "SH" ||
00129 tested == "SL" ||
00130 tested == "SS" ||
00131 tested == "ST" ||
00132 tested == "TM" ||
00133 tested == "UI" ||
00134 tested == "UL" ||
00135 tested == "UN" ||
00136 tested == "US";
00137 }
00138
00144 bool VR::IsVROfSequence(VRKey const &tested)
00145 {
00146 return tested == "SQ";
00147 }
00148
00149 bool VR::IsValidVR(VRKey const &key)
00150 {
00151 return vr.find(key) != vr.end();
00152 }
00153
00154
00155
00156
00157
00158
00159
00160
00161
00166 void VR::Print(std::ostream &os)
00167 {
00168 std::ostringstream s;
00169
00170 for (VRHT::iterator it = vr.begin(); it != vr.end(); ++it)
00171 {
00172 s << "VR : " << it->first << " = " << it->second << std::endl;
00173 }
00174 os << s.str();
00175 }
00176
00177
00178 }