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

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: 2005/11/04 15:29:59 $
00007   Version:   $Revision: 1.42 $
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 
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       std::string strType;
00054       DicomElement elem;
00055       DicomDirType type;
00056 
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;
00084 
00085             from >> std::ws;
00086             from.getline(buff, 1024, '"');
00087             from >> std::ws;
00088             from.getline(buff, 1024, '"');
00089             elem.Value = buff;
00090 
00091             AddEntry(type, elem);
00092          }
00093          from.getline(buff, 1024, '\n');
00094       }
00095       from.close();
00096    }
00097 }
00098 
00102 DicomDirElement::~DicomDirElement()
00103 {
00104    DicomDirMetaList.clear();
00105    DicomDirPatientList.clear();
00106    DicomDirStudyList.clear();
00107    DicomDirSerieList.clear();
00108    DicomDirImageList.clear();
00109 }
00110 
00111 //-----------------------------------------------------------------------------
00112 // Public
00119 bool DicomDirElement::AddEntry(DicomDirType type, DicomElement const &elem)
00120 {
00121    switch( type )
00122    {
00123       case DD_IMAGE :
00124          DicomDirImageList.push_back(elem);
00125          break;
00126       case DD_SERIE :
00127          DicomDirSerieList.push_back(elem);
00128          break;
00129       case DD_STUDY :
00130          DicomDirStudyList.push_back(elem);
00131          break;
00132       case DD_PATIENT :
00133          DicomDirPatientList.push_back(elem);
00134          break;
00135       case DD_META :
00136          DicomDirMetaList.push_back(elem);
00137          break;
00138       default :
00139          return false;
00140    }
00141    return true;
00142 }
00143 
00151 void DicomDirElement::AddDicomDirElement(DicomDirType type,
00152                                          uint16_t group, uint16_t elem)
00153 {
00154    DicomElement el;
00155    el.Group = group;
00156    el.Elem  = elem;
00157    el.Value = "";
00158    AddEntry(type, el);
00159 }
00160 
00161 //-----------------------------------------------------------------------------
00162 // Protected
00163 
00164 //-----------------------------------------------------------------------------
00165 // Private
00166 
00167 //-----------------------------------------------------------------------------
00168 // Print
00173 void DicomDirElement::Print(std::ostream &os,std::string const &)
00174 {
00175    std::ostringstream s;
00176    std::list<DicomElement>::iterator it;
00177    //char greltag[10];  //group element tag
00178    TagKey greltag;
00179 
00180    s << "Meta Elements :"<<std::endl;
00181    for (it = DicomDirMetaList.begin(); it != DicomDirMetaList.end(); ++it)
00182    {
00183       greltag = DictEntry::TranslateToKey(it->Group,it->Elem);
00184       s << "   (" << greltag << ") = " << it->Value << std::endl;
00185    }
00186 
00187    s << "Patient Elements :"<<std::endl;
00188    for (it = DicomDirPatientList.begin(); it != DicomDirPatientList.end(); ++it)
00189    {
00190       greltag = DictEntry::TranslateToKey(it->Group,it->Elem);
00191       s << "   (" << greltag << ") = " << it->Value << std::endl;
00192    }
00193 
00194    s << "Study Elements :"<<std::endl;
00195    for (it = DicomDirStudyList.begin(); it != DicomDirStudyList.end(); ++it)
00196    {
00197       greltag = DictEntry::TranslateToKey(it->Group, it->Elem);
00198       s << "   (" << greltag << ") = " << it->Value << std::endl;
00199    }
00200 
00201    s << "Serie Elements :"<<std::endl;
00202    for (it = DicomDirSerieList.begin(); it != DicomDirSerieList.end(); ++it)
00203    {
00204       greltag = DictEntry::TranslateToKey( it->Group, it->Elem);
00205       s << "   (" << greltag << ") = " << it->Value << std::endl;
00206    }
00207 
00208    s << "Image Elements :"<<std::endl;
00209    for (it = DicomDirImageList.begin(); it != DicomDirImageList.end(); ++it)
00210    {
00211       greltag = DictEntry::TranslateToKey(it->Group, it->Elem);
00212       s << "   (" << greltag << ") = " << it->Value << std::endl;
00213    }
00214 
00215    os << s.str();
00216 }
00217 
00218 //-----------------------------------------------------------------------------
00219 } // end namespace gdcm

Generated on Fri Jan 20 10:14:24 2006 for gdcm by  doxygen 1.4.4