gdcmVR.cxx

Go to the documentation of this file.
00001 /*=========================================================================
00002                                                                                 
00003   Program:   gdcm
00004   Module:    $RCSfile: gdcmVR.cxx,v $
00005   Language:  C++
00006   Date:      $Date: 2007/06/22 10:02:48 $
00007   Version:   $Revision: 1.56 $
00008                                                                                 
00009   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
00010   l'Image). All rights reserved. See Doc/License.txt or
00011   http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
00012                                                                                 
00013      This software is distributed WITHOUT ANY WARRANTY; without even
00014      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00015      PURPOSE.  See the above copyright notices for more information.
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 // Constructor / Destructor
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 // Public
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    // Should be quicker
00133    // --> will *never* work : any rotten value would be considered as OK !
00134 /*
00135    return tested != "OB" &&
00136           tested != "OW" &&
00137           tested != "OF" &&
00138           tested != "AT" && // Attribute Tag ?!? contain no printable character
00139           tested != "UN" && // UN is an actual VR !
00140           tested != "SQ" ;
00141 */
00142 }
00144 unsigned short VR::GetAtomicElementLength(VRKey const &tested)
00145 {
00146    // Unsigned & signed short
00147    if( tested == "US" || tested == "SS" )
00148       return 2;
00149    // Unsigned & signed long
00150    if( tested == "UL" || tested == "SL" )
00151       return 4;
00152    // Float
00153    if( tested == "FL" )
00154       return 4;
00155    // Double
00156    if( tested == "FD" )
00157       return 8;
00158    // Word string
00159    if( tested == "OW" )
00160       return 2;
00161    // Float string
00162    if( tested == "OF" )
00163       return 4;   
00164    return 1;
00165 }
00166 
00167 // VS6 need a single implementation in the dll
00168 #if defined(_MSC_VER) && (_MSC_VER == 1200)
00169 
00170 bool VR::IsValidVR(VRKey const &tested)
00171 {
00172 //  return vr.find(key) != vr.end();
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 // Protected
00195 
00196 //-----------------------------------------------------------------------------
00197 // Private
00198 
00199 //-----------------------------------------------------------------------------
00200 // Print
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 } // end namespace gdcm

Generated on Fri Aug 24 12:59:32 2007 for gdcm by  doxygen 1.4.6