gdcmDicomDirMeta.cxx

Go to the documentation of this file.
00001 /*=========================================================================
00002                                                                                 
00003   Program:   gdcm
00004   Module:    $RCSfile: gdcmDicomDirMeta.cxx,v $
00005   Language:  C++
00006   Date:      $Date: 2007/07/26 08:36:49 $
00007   Version:   $Revision: 1.38 $
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 "gdcmDicomDirMeta.h"
00020 #include "gdcmDocument.h"
00021 #include "gdcmDocEntry.h"
00022 #include "gdcmGlobal.h"
00023 #include "gdcmUtil.h"
00024 #include "gdcmDataEntry.h"
00025 
00026 namespace GDCM_NAME_SPACE 
00027 {
00028 //-----------------------------------------------------------------------------
00029 // Constructor / Destructor
00033 DicomDirMeta::DicomDirMeta(bool empty):
00034    DicomDirObject()
00035 {
00036    if ( !empty )
00037    {
00038       ListDicomDirStudyElem const &elemList = 
00039          Global::GetDicomDirElements()->GetDicomDirMetaElements();
00040       FillObject(elemList);
00041    }
00042 }
00043 
00047 DicomDirMeta::~DicomDirMeta() 
00048 {
00049 }
00050 
00051 //-----------------------------------------------------------------------------
00052 // Public
00059 void DicomDirMeta::WriteContent(std::ofstream *fp, FileType filetype,
00060                                                      bool insideMetaElements)
00061 {
00062    // 'File Meta Information Version'
00063    
00064    uint8_t fmiv[2] = {0x02,0x00};
00065    // FIXME : the following doesn't make the job (?!?)      
00066    //SetEntryBinArea(fmiv, 0x0002,0x0001, 2); 
00067    DataEntry *e00002_0001 = GetDataEntry(0x0002,0x0001);
00068    e00002_0001->CopyBinArea(fmiv, 2);
00069          
00070    // 'Media Storage SOP Instance UID'   
00071    DataEntry *e00002_0003 = GetDataEntry(0x0002,0x0003);
00072    e00002_0003->SetString(Util::CreateUniqueUID());
00073 
00074    // 'Implementation Class UID'
00075    DataEntry *e00002_0012 = GetDataEntry(0x0002,0x0012);
00076    e00002_0012->SetString(Util::CreateUniqueUID());   
00077    
00078    // Entry : 0002|0000 = group length -> recalculated
00079    DataEntry *e0000 = GetDataEntry(0x0002,0x0000);
00080    std::ostringstream sLen;
00081    sLen << ComputeGroup0002Length( );
00082    e0000->SetString(sLen.str());
00083    
00084    for (ListDocEntry::iterator i = DocEntries.begin();  
00085                                i!= DocEntries.end();
00086                              ++i)
00087    {   
00088    // true : we are in MetaElements
00089       (*i)->WriteContent(fp, filetype, true);
00090    }
00091 }
00092 
00096 int DicomDirMeta::ComputeGroup0002Length( ) 
00097 {
00098    uint16_t gr;
00099    VRKey vr;
00100    
00101    int groupLength = 0;
00102    bool found0002 = false;   
00103   
00104    // for each Tag in the DicomDirMeta
00105    DocEntry *entry = GetFirstEntry();
00106    while( entry )
00107    {
00108       gr = entry->GetGroup();
00109 
00110       if ( gr == 0x0002 )
00111       {
00112          found0002 = true;
00113 
00114          if ( entry->GetElement() != 0x0000 )
00115          {
00116             vr = entry->GetVR();
00117 
00118             if ( vr == "OB" ) 
00119             {
00120                groupLength +=  4;
00121             }
00122             groupLength += 2 + 2 + 4 + entry->GetLength();   
00123          }
00124       }
00125       else if (found0002 )
00126          break;
00127 
00128       entry = GetNextEntry();
00129    }
00130    return groupLength; 
00131 }
00132 
00133 //-----------------------------------------------------------------------------
00134 // Protected
00135 
00136 //-----------------------------------------------------------------------------
00137 // Private
00138 
00139 //-----------------------------------------------------------------------------
00140 // Print
00146 void DicomDirMeta::Print(std::ostream &os, std::string const & )
00147 {
00148    os << "META" << std::endl;
00149    // warning : META doesn't behave exactly like a Objet 
00150    for (ListDocEntry::iterator i = DocEntries.begin();
00151         i != DocEntries.end();
00152         ++i)
00153    {
00154       (*i)->SetPrintLevel(PrintLevel);
00155       (*i)->Print();
00156       os << std::endl;
00157    }
00158 }
00159 
00160 //-----------------------------------------------------------------------------
00161 } // end namespace gdcm

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