1 /*=========================================================================
4 Module: $RCSfile: gdcmVR.cxx,v $
6 Date: $Date: 2007/09/25 15:21:57 $
7 Version: $Revision: 1.62 $
9 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10 l'Image). All rights reserved. See Doc/License.txt or
11 http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
13 This software is distributed WITHOUT ANY WARRANTY; without even
14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 PURPOSE. See the above copyright notices for more information.
17 =========================================================================*/
21 #include "gdcmDictSet.h"
22 #include "gdcmDebug.h"
28 namespace GDCM_NAME_SPACE
30 //-----------------------------------------------------------------------------
31 /// \brief auto generated function, to fill up the 'Value Representation'
32 /// Dictionnary, if relevant file is not found on user's disk
33 void FillDefaultVRDict(VRHT &vr);
35 //-----------------------------------------------------------------------------
36 // Constructor / Destructor
42 std::string filename = DictSet::BuildDictPath() + DICT_VR;
43 std::ifstream from(filename.c_str());
46 gdcmWarningMacro("Can't open dictionary " << filename.c_str());
47 FillDefaultVRDict(vr);
58 from.getline(buff, 1024, ' ');
59 if( strcmp(buff,"") == 0)
64 from.getline(buff, 1024, ';');
68 from.getline(buff, 1024, '\n');
84 //-----------------------------------------------------------------------------
88 * \brief Simple predicate that checks whether the given argument
89 * corresponds to the Value Representation of a DataEntry .
90 * @param tested value representation to check for.
92 bool VR::IsVROfBinaryRepresentable(VRKey const &tested)
94 if ( IsVROfStringRepresentable(tested) )
97 if ( IsVROfSequence(tested) )
104 * \brief Simple predicate that checks whether the given argument
105 * corresponds to the Value Representation of a
106 * 'std::string representable' value.
107 * @param tested value representation to be checked.
109 bool VR::IsVROfStringRepresentable(VRKey const &tested)
111 return tested == "AE" ||
133 // --> will *never* work : any rotten value would be considered as OK !
135 return tested != "OB" &&
138 tested != "AT" && // Attribute Tag ?!? contain no printable character
139 tested != "UN" && // UN is an actual VR !
143 /// \brief returns the length of a elementary elem whose VR is passed
144 unsigned short VR::GetAtomicElementLength(VRKey const &tested)
146 // Unsigned & signed short
147 if( tested == "US" || tested == "SS" )
149 // Unsigned & signed long
150 if( tested == "UL" || tested == "SL" )
162 if( tested == "OF" || tested == "OL")
167 // VS6 need a single implementation in the dll
168 #if defined(_MSC_VER) && (_MSC_VER == 1200)
169 /// \brief checks is a supposed-to-be VR is a 'legal' one.
170 bool VR::IsValidVR(VRKey const &key)
172 return vr.find(key) != vr.end();
173 #ifdef USECOMPLETELYUNTESTEDCODE
174 // to avoid to search in a std::map of std::string,
175 // since each std::string is 2 characters longs, we check the array
176 // (29 char comparisons in the worst case!)
178 // "RT" is an undocumented VR, found in some Siemens images.
179 // We added it here to be able to read these images.
180 // Dict/gdcmVR.dic, Document has to be updated, too.
181 static const char VRvalues[] =
182 "AEASATCSDADSDTFLFDISLOLTOBOWOLOFPNSHSLSQSSSTTMUIULUNUSUTRT";
184 //int nbVal = strlen(VRvalues)/2; // save CPU time.
187 const char *pt = VRvalues;
188 for (int i=0;i<nbVal;i++)
190 if(key[0] == *pt++) {
191 if(key[1] == *pt++) {
205 //-----------------------------------------------------------------------------
208 //-----------------------------------------------------------------------------
211 //-----------------------------------------------------------------------------
215 * @param os The output stream to be written to.
217 void VR::Print(std::ostream &os,std::string const &)
219 for (VRHT::iterator it = vr.begin(); it != vr.end(); ++it)
221 os << "VR : " << it->first << " = " << it->second << std::endl;
225 //-----------------------------------------------------------------------------
226 } // end namespace gdcm