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

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: 2005/11/04 15:33:35 $
00007   Version:   $Revision: 1.34 $
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 namespace gdcm 
00026 {
00027 //-----------------------------------------------------------------------------
00028 // Constructor / Destructor
00032 DicomDirMeta::DicomDirMeta(bool empty):
00033    DicomDirObject()
00034 {
00035    if ( !empty )
00036    {
00037       ListDicomDirStudyElem const &elemList = 
00038          Global::GetDicomDirElements()->GetDicomDirMetaElements();
00039       FillObject(elemList);
00040    }
00041 }
00042 
00046 DicomDirMeta::~DicomDirMeta() 
00047 {
00048 }
00049 
00050 //-----------------------------------------------------------------------------
00051 // Public
00058 void DicomDirMeta::WriteContent(std::ofstream *fp, FileType filetype)
00059 {  
00060    // 'File Meta Information Version'
00061    
00062    uint8_t fmiv[2] = {0x02,0x00};
00063    // FIXME : the following doesn't make the job (?!?)      
00064    //SetEntryBinArea(fmiv, 0x0002,0x0001, 2); 
00065    DataEntry *e00002_0001 = GetDataEntry(0x0002,0x0001);
00066    e00002_0001->CopyBinArea(fmiv, 2);
00067          
00068    // 'Media Storage SOP Instance UID'   
00069    DataEntry *e00002_0003 = GetDataEntry(0x0002,0x0003);
00070    e00002_0003->SetString(Util::CreateUniqueUID());
00071 
00072    // 'Implementation Class UID'
00073    DataEntry *e00002_0012 = GetDataEntry(0x0002,0x0012);
00074    e00002_0012->SetString(Util::CreateUniqueUID());   
00075    
00076    // Entry : 0002|0000 = group length -> recalculated
00077    DataEntry *e0000 = GetDataEntry(0x0002,0x0000);
00078    std::ostringstream sLen;
00079    sLen << ComputeGroup0002Length( );
00080    e0000->SetString(sLen.str());
00081    
00082    for (ListDocEntry::iterator i = DocEntries.begin();  
00083                               i != DocEntries.end();
00084                               ++i)
00085    {
00086       (*i)->WriteContent(fp, filetype);
00087    }
00088 }
00089 
00093 int DicomDirMeta::ComputeGroup0002Length( ) 
00094 {
00095    uint16_t gr;
00096    VRKey vr;
00097    
00098    int groupLength = 0;
00099    bool found0002 = false;   
00100   
00101    // for each Tag in the DicomDirMeta
00102    DocEntry *entry = GetFirstEntry();
00103    while( entry )
00104    {
00105       gr = entry->GetGroup();
00106 
00107       if ( gr == 0x0002 )
00108       {
00109          found0002 = true;
00110 
00111          if ( entry->GetElement() != 0x0000 )
00112          {
00113             vr = entry->GetVR();
00114 
00115             if ( vr == "OB" ) 
00116             {
00117                groupLength +=  4;
00118             }
00119             groupLength += 2 + 2 + 4 + entry->GetLength();   
00120          }
00121       }
00122       else if (found0002 )
00123          break;
00124 
00125       entry = GetNextEntry();
00126    }
00127    return groupLength; 
00128 }
00129 
00130 //-----------------------------------------------------------------------------
00131 // Protected
00132 
00133 //-----------------------------------------------------------------------------
00134 // Private
00135 
00136 //-----------------------------------------------------------------------------
00137 // Print
00143 void DicomDirMeta::Print(std::ostream &os, std::string const & )
00144 {
00145    os << "META" << std::endl;
00146    // warning : META doesn't behave exactly like a Objet 
00147    for (ListDocEntry::iterator i = DocEntries.begin();
00148         i != DocEntries.end();
00149         ++i)
00150    {
00151       (*i)->SetPrintLevel(PrintLevel);
00152       (*i)->Print();
00153       os << std::endl;
00154    }
00155 }
00156 
00157 //-----------------------------------------------------------------------------
00158 } // end namespace gdcm

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