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 #include <string.h>
00027 
00028 namespace GDCM_NAME_SPACE 
00029 {
00030 
00033 void FillDefaultVRDict(VRHT &vr);
00034 
00035 
00036 
00040 VR::VR() 
00041 {
00042    std::string filename = DictSet::BuildDictPath() + DICT_VR;
00043    std::ifstream from(filename.c_str());
00044    if ( !from )
00045    {
00046       gdcmWarningMacro("Can't open dictionary " << filename.c_str());
00047       FillDefaultVRDict(vr);
00048    }
00049    else
00050    {
00051       char buff[1024];
00052       VRKey key;
00053       VRAtr name;
00054    
00055       while (!from.eof()) 
00056       {
00057          from >> std::ws;
00058          from.getline(buff, 1024, ' ');
00059          if( strcmp(buff,"") == 0)
00060             continue;
00061 
00062          key = buff;
00063          from >> std::ws;
00064          from.getline(buff, 1024, ';');
00065          name = buff;
00066    
00067          from >> std::ws;
00068          from.getline(buff, 1024, '\n');
00069    
00070          vr[key] = name;
00071       }
00072       from.close();
00073    }
00074 }
00075 
00079 VR::~VR()
00080 {
00081    vr.clear();
00082 }
00083 
00084 
00085 
00086 
00092 bool VR::IsVROfBinaryRepresentable(VRKey const &tested)
00093 {
00094    if ( IsVROfStringRepresentable(tested) )
00095       return false;
00096 
00097    if ( IsVROfSequence(tested) )
00098       return false;
00099 
00100    return true;
00101 }
00102 
00109 bool VR::IsVROfStringRepresentable(VRKey const &tested)
00110 {
00111    return tested == "AE" ||
00112           tested == "AS" ||
00113           tested == "CS" ||
00114           tested == "DA" ||
00115           tested == "DS" ||
00116           tested == "FL" ||
00117           tested == "FD" ||
00118           tested == "IS" || 
00119           tested == "LO" ||
00120           tested == "LT" ||
00121           tested == "PN" ||
00122           tested == "SH" ||
00123           tested == "SL" ||
00124           tested == "SS" ||
00125           tested == "ST" ||
00126           tested == "TM" ||
00127           tested == "UI" ||
00128           tested == "UL" ||
00129           tested == "US" ||
00130           tested == "UT";
00131 
00132    
00133    
00134 
00135 
00136 
00137 
00138 
00139 
00140 
00141 
00142 }
00144 unsigned short VR::GetAtomicElementLength(VRKey const &tested)
00145 {
00146    
00147    if( tested == "US" || tested == "SS" )
00148       return 2;
00149    
00150    if( tested == "UL" || tested == "SL" )
00151       return 4;
00152    
00153    if( tested == "FL" )
00154       return 4;
00155    
00156    if( tested == "FD" )
00157       return 8;
00158    
00159    if( tested == "OW" )
00160       return 2;
00161    
00162    if( tested == "OF" )
00163       return 4;   
00164    return 1;
00165 }
00166 
00167 
00168 #if defined(_MSC_VER) && (_MSC_VER == 1200)
00169 
00170 bool VR::IsValidVR(VRKey const &tested)
00171 {
00172 
00173   static const char VRvalues[] =
00174     "AEASCSDADSFLFDISLOLTPNSHSLSSSTTMUIULUSUTOBOWOFATUNSQ";
00175 
00176   int nbVal = 26;
00177   const char *pt = VRvalues;
00178   for (int i=0;i<nbVal;i++)
00179   {
00180      if(tested[0] == *pt++) {
00181        if(tested[1] == *pt++)
00182           return true;
00183      }  
00184      else {
00185         pt++;
00186      }        
00187   }
00188   return false;
00189 
00190 }
00191 #endif
00192 
00193 
00194 
00195 
00196 
00197 
00198 
00199 
00200 
00205 void VR::Print(std::ostream &os,std::string const &) 
00206 {
00207    for (VRHT::iterator it = vr.begin(); it != vr.end(); ++it)
00208    {
00209       os << "VR : " << it->first << " = " << it->second << std::endl;
00210    }
00211 }
00212 
00213 
00214 }