gdcmValidator.cxx

Go to the documentation of this file.
00001 /*=========================================================================
00002                                                                                 
00003   Program:   gdcm
00004   Module:    $RCSfile: gdcmValidator.cxx,v $
00005   Language:  C++
00006   Date:      $Date: 2007/08/21 12:51:10 $
00007   Version:   $Revision: 1.16 $
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 "gdcmValidator.h"
00020 #include "gdcmElementSet.h"
00021 #include "gdcmDataEntry.h"
00022 #include "gdcmUtil.h"
00023 #include "gdcmDebug.h" // hidden way to include sstream
00024 #include <map>
00025 
00026 
00027 namespace GDCM_NAME_SPACE 
00028 {
00029 //-----------------------------------------------------------------------------
00030 typedef std::map<uint16_t, int> GroupHT;    //  Hash Table
00031 //-----------------------------------------------------------------------------
00033 Validator::Validator()
00034 {
00035 }
00037 Validator::~Validator()
00038 {
00039 }
00040 
00041 // Function to compare the VM found while parsing d->GetString()
00042 // compare to the one from the dictionary
00043 bool CheckVM(DataEntry *entry)
00044 {
00045   // Don't waste time checking tags where VM is OB and OW, since we know
00046   // it's always 1, whatever the actual length (found on disc)
00047   
00048   if ( entry->GetVR() == "OB" ||  entry->GetVR() == "OW" )
00049      return true;
00050 
00051   const std::string &s = entry->GetString();
00052 
00053   unsigned int n = Util::CountSubstring( s , "\\");
00054   
00055   n++; // number of '\' + 1 == Value Multiplicity
00056 
00057   std::string vmFromDict = entry->GetVM();
00058   if ( vmFromDict == "1-n" || vmFromDict == "2-n" || vmFromDict == "3-n" )
00059      return true;
00060      
00061   unsigned int m;
00062   std::istringstream is;
00063   is.str( vmFromDict );
00064   is >> m;
00065 
00066   return n == m;
00067 }
00068 
00069 void Validator::SetInput(ElementSet *input)
00070 {
00071 
00072 DocEntry *d;
00073 /*
00074 // First stage to check group length
00075   GroupHT grHT;
00076   d=input->GetFirstEntry();
00077   while(d)
00078   {
00079     grHT[d->GetGroup()] = 0;
00080     d=input->GetNextEntry();
00081   }
00082   for (GroupHT::iterator it = grHT.begin(); it != grHT.end(); ++it)
00083   {
00084       std::cout << std::hex << it->first << std::endl; 
00085   }
00086 */
00087 
00088   // berk for now SetInput do two things at the same time
00089   d=input->GetFirstEntry();
00090   if (!d)
00091   {
00092      std::cout << "No Entry found" << std::endl;
00093      return;
00094   }
00095   while(d)
00096   { 
00097     if ( DataEntry *v = dynamic_cast<DataEntry *>(d) )
00098     {
00099       if ( v->GetVM() != GDCM_NAME_SPACE::GDCM_UNKNOWN )
00100          if ( !CheckVM(v) )
00101          {
00102             if (v->GetVM() == "FIXME" )
00103               std::cout << "For Tag " <<  v->GetKey() << " VM = ["
00104                        << v->GetVM() << "]" << std::endl;
00105 
00106             std::cout << "Tag (" <<  v->GetKey() 
00107                       << ")-> [" << v->GetName() << "] VR :" << v->GetVR()
00108                       << " contains an illegal VM. Expected VM :[" 
00109                       << v->GetVM() << "], value [" << v->GetString() << "]"
00110                       << std::endl;
00111          }
00112 
00113       if ( v->GetReadLength() % 2 )
00114       {
00115         std::cout << "Tag (" <<  v->GetKey()
00116                   << ")-> [" << v->GetName() << "] has an uneven length :"
00117                   << v->GetReadLength()
00118                   << " [" << v->GetString() << "] "
00119                   << std::endl;
00120       }
00121     }
00122     else
00123     {
00124       // We skip pb of SQ recursive exploration
00125     }
00126     d=input->GetNextEntry();
00127   }
00128 }
00129 
00130 } // end namespace gdcm

Generated on Fri Aug 24 12:53:19 2007 for gdcm by  doxygen 1.4.6