gdcmDicomDirElement.cxx

Go to the documentation of this file.
00001 /*=========================================================================
00002                                                                                 
00003   Program:   gdcm
00004   Module:    $RCSfile: gdcmDicomDirElement.cxx,v $
00005   Language:  C++
00006   Date:      $Date: 2007/05/23 14:18:08 $
00007   Version:   $Revision: 1.45 $
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 "gdcmDicomDirElement.h"
00020 #include "gdcmUtil.h"
00021 #include "gdcmDebug.h"
00022 #include "gdcmDictSet.h"
00023 
00024 #include <fstream>
00025 #include <iostream>
00026 
00027 namespace GDCM_NAME_SPACE 
00028 {
00029 //-----------------------------------------------------------------------------
00032 void FillDefaultDIRDict(DicomDirElement *dde);
00033 
00034 //-----------------------------------------------------------------------------
00035 // Constructor / Destructor
00040 DicomDirElement::DicomDirElement()
00041 {
00042    std::string filename = DictSet::BuildDictPath() + DICT_ELEM;
00043    std::ifstream from(filename.c_str());
00044    if ( !from )
00045    {
00046       gdcmWarningMacro( "Can't open DicomDirElement dictionary" 
00047                         << filename.c_str());
00048       FillDefaultDIRDict( this );
00049    }
00050    else
00051    {
00052       char buff[1024];
00053       char buff2[1024];
00054       std::string strType;
00055       DicomElement elem;
00056       DicomDirType type;
00057       while (!from.eof())
00058       {
00059          from >> std::ws;
00060          from.getline(buff, 1024, ' ');
00061          strType = buff;
00062 
00063          if ( strType == "imageElem" )
00064             type = DD_IMAGE;
00065          else if ( strType == "serieElem" )
00066             type = DD_SERIE;
00067          else if ( strType == "studyElem" )
00068             type = DD_STUDY;
00069          else if ( strType == "patientElem" )
00070             type = DD_PATIENT;
00071          else if ( strType == "metaElem" )
00072             type = DD_META;
00073          else
00074          {
00075             gdcmWarningMacro("Unknown type (" << strType 
00076                              << ") found in the file : "
00077                              << filename.c_str());
00078             type = DD_UNKNOWN;
00079          }
00080 
00081          if ( type!=DD_UNKNOWN )
00082          {
00083             from >> std::hex >> elem.Group >> elem.Elem;//  >> elem.VR;
00084 
00085             from.getline(buff2, 1024, '"');
00086             from >> std::ws;
00087             from.getline(buff2, 1024, '"');
00088             elem.VR[0] = buff2[0];
00089             elem.VR[1] = buff2[1];
00090  // std::cout << "VR : [" <<  elem.VR[0] << elem.VR[1] << "]" << std::endl;  // JPR
00091             from >> std::ws;
00092             from.getline(buff, 1024, '"');
00093             from >> std::ws;
00094             from.getline(buff, 1024, '"');
00095             elem.Value = buff;
00096     
00097             AddEntry(type, elem);
00098          }
00099          from.getline(buff, 1024, '\n');
00100       }
00101       from.close();
00102    }
00103 }
00104 
00108 DicomDirElement::~DicomDirElement()
00109 {
00110    DicomDirMetaList.clear();
00111    DicomDirPatientList.clear();
00112    DicomDirStudyList.clear();
00113    DicomDirSerieList.clear();
00114    DicomDirImageList.clear();
00115 }
00116 
00117 //-----------------------------------------------------------------------------
00118 // Public
00125 bool DicomDirElement::AddEntry(DicomDirType type, DicomElement const &elem)
00126 {
00127    switch( type )
00128    {
00129       case DD_IMAGE :
00130          DicomDirImageList.push_back(elem);
00131          break;
00132       case DD_SERIE :
00133          DicomDirSerieList.push_back(elem);
00134          break;
00135       case DD_STUDY :
00136          DicomDirStudyList.push_back(elem);
00137          break;
00138       case DD_PATIENT :
00139          DicomDirPatientList.push_back(elem);
00140          break;
00141       case DD_META :
00142          DicomDirMetaList.push_back(elem);
00143          break;
00144       default :
00145          return false;
00146    }
00147    return true;
00148 }
00149 
00158 void DicomDirElement::AddDicomDirElement(DicomDirType type,
00159                                          uint16_t group, uint16_t elem, VRKey vr)
00160 {
00161    DicomElement el;
00162    el.Group = group;
00163    el.Elem  = elem;
00164    el.VR    = vr;
00165    el.Value = "";
00166    AddEntry(type, el);
00167 }
00168 
00169 //-----------------------------------------------------------------------------
00170 // Protected
00171 
00172 //-----------------------------------------------------------------------------
00173 // Private
00174 
00175 //-----------------------------------------------------------------------------
00176 // Print
00181 void DicomDirElement::Print(std::ostream &os,std::string const &)
00182 {
00183    std::ostringstream s;
00184    std::list<DicomElement>::iterator it;
00185    TagKey greltag;
00186 
00187    s << "Meta Elements :"<<std::endl;
00188    for (it = DicomDirMetaList.begin(); it != DicomDirMetaList.end(); ++it)
00189    {
00190       greltag = DictEntry::TranslateToKey(it->Group,it->Elem);
00191       s << "   (" << greltag << ") = " << it->Value << std::endl;
00192    }
00193 
00194    s << "Patient Elements :"<<std::endl;
00195    for (it = DicomDirPatientList.begin(); it != DicomDirPatientList.end(); ++it)
00196    {
00197       greltag = DictEntry::TranslateToKey(it->Group,it->Elem);
00198       s << "   (" << greltag << ") = " << it->Value << std::endl;
00199    }
00200 
00201    s << "Study Elements :"<<std::endl;
00202    for (it = DicomDirStudyList.begin(); it != DicomDirStudyList.end(); ++it)
00203    {
00204       greltag = DictEntry::TranslateToKey(it->Group, it->Elem);
00205       s << "   (" << greltag << ") = " << it->Value << std::endl;
00206    }
00207 
00208    s << "Serie Elements :"<<std::endl;
00209    for (it = DicomDirSerieList.begin(); it != DicomDirSerieList.end(); ++it)
00210    {
00211       greltag = DictEntry::TranslateToKey( it->Group, it->Elem);
00212       s << "   (" << greltag << ") = " << it->Value << std::endl;
00213    }
00214 
00215    s << "Image Elements :"<<std::endl;
00216    for (it = DicomDirImageList.begin(); it != DicomDirImageList.end(); ++it)
00217    {
00218       greltag = DictEntry::TranslateToKey(it->Group, it->Elem);
00219       s << "   (" << greltag << ") = " << it->Value << std::endl;
00220    }
00221 
00222    os << s.str();
00223 }
00224 
00225 //-----------------------------------------------------------------------------
00226 } // end namespace gdcm

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