Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

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: 2005/02/05 01:37:09 $
00007   Version:   $Revision: 1.35 $
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 
00027 namespace gdcm 
00028 {
00029 //-----------------------------------------------------------------------------
00030 void FillDefaultVRDict(VRHT &vr);
00031 
00032 //-----------------------------------------------------------------------------
00033 // Constructor / Destructor
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 // Public
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 // Protected
00156 
00157 //-----------------------------------------------------------------------------
00158 // Private
00159 
00160 //-----------------------------------------------------------------------------
00161 // Print
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 } // end namespace gdcm

Generated on Thu Feb 10 22:18:00 2005 for gdcm by doxygen 1.3.6