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

gdcmDocEntry.cxx

Go to the documentation of this file.
00001 /*=========================================================================
00002                                                                                 
00003   Program:   gdcm
00004   Module:    $RCSfile: gdcmDocEntry.cxx,v $
00005   Language:  C++
00006   Date:      $Date: 2005/02/06 14:43:27 $
00007   Version:   $Revision: 1.53 $
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 "gdcmDocEntry.h"
00020 #include "gdcmTS.h"
00021 #include "gdcmVR.h"
00022 #include "gdcmGlobal.h"
00023 #include "gdcmUtil.h"
00024 #include "gdcmDebug.h"
00025 
00026 #include <iomanip> // for std::ios::left, ...
00027 #include <fstream>
00028 
00029 namespace gdcm 
00030 {
00031 //-----------------------------------------------------------------------------
00032 #define MAX_SIZE_PRINT_ELEMENT_VALUE 64
00033 
00034 //-----------------------------------------------------------------------------
00035 // Constructor / Destructor
00040 DocEntry::DocEntry(DictEntry *in)
00041 {
00042    ImplicitVR = false;
00043    DicomDict  = in;
00044    SetKey( in->GetKey( ) );
00045    Offset     = 0 ; // To avoid further missprinting
00046 
00047    // init some variables
00048    ReadLength = 0;
00049    Length = 0;
00050 }
00051 
00052 //-----------------------------------------------------------------------------
00053 // Public
00059 void DocEntry::WriteContent(std::ofstream *fp, FileType filetype)
00060 {
00061    uint32_t ffff  = 0xffffffff;
00062    uint16_t group = GetGroup();
00063    VRKey vr       = GetVR();
00064    uint16_t el    = GetElement();
00065    uint32_t lgth  = GetLength();
00066 
00067    if ( group == 0xfffe && el == 0x0000 )
00068    {
00069      // Fix in order to make some MR PHILIPS images e-film readable
00070      // see gdcmData/gdcm-MR-PHILIPS-16-Multi-Seq.dcm:
00071      // we just *always* ignore spurious fffe|0000 tag !   
00072       return;
00073    }
00074    //
00075    // ----------- Writes the common part
00076    //
00077    binary_write( *fp, group); //group number
00078    binary_write( *fp, el);    //element number
00079 
00080    if ( filetype == ExplicitVR )
00081    {
00082       // Special case of delimiters:
00083       if (group == 0xfffe)
00084       {
00085          // Delimiters have NO Value Representation
00086          // Hence we skip writing the VR.
00087          // In order to avoid further troubles, we choose to write them
00088          // as 'no-length' Item Delimitors (we pad by writing 0xffffffff)
00089          // We shall force the end of a given Item by writting 
00090          //  a Item Delimitation Item (fffe, e00d)
00091 
00092          uint32_t ff = 0xffffffff;
00093          binary_write(*fp, ff);
00094          return;
00095       }
00096 
00097       uint16_t z = 0;
00098       uint16_t shortLgr = lgth;
00099 
00100       if (vr == GDCM_UNKNOWN)
00101       {
00102          // Unknown was 'written'
00103          // deal with Little Endian            
00104          binary_write(*fp, shortLgr);
00105          binary_write(*fp, z);
00106       }
00107       else
00108       {
00109          binary_write(*fp, vr);
00110          gdcmAssertMacro( vr.size() == 2 );
00111                   
00112          if ( (vr == "OB") || (vr == "OW") || (vr == "SQ") || (vr == "UN") )
00113          {
00114             binary_write(*fp, z);
00115             if (vr == "SQ")
00116             {
00117                // we set SQ length to ffffffff
00118                // and  we shall write a Sequence Delimitor Item 
00119                // at the end of the Sequence! 
00120                binary_write(*fp, ffff);
00121             }
00122             else
00123             {
00124                binary_write(*fp, lgth);
00125             }
00126          }
00127          else
00128          {
00129             binary_write(*fp, shortLgr);
00130          }
00131       }
00132    } 
00133    else // IMPLICIT VR 
00134    { 
00135       if (vr == "SQ")
00136       {
00137          binary_write(*fp, ffff);
00138       }
00139       else
00140       {
00141          binary_write(*fp, lgth);
00142       }
00143    }
00144 }
00145 
00150 uint32_t DocEntry::GetFullLength()
00151 {
00152    uint32_t l = GetReadLength();
00153    if ( IsImplicitVR() )
00154    {
00155       l = l + 8;  // 2 (gr) + 2 (el) + 4 (lgth) 
00156    }
00157    else
00158    {
00159       if ( GetVR()=="OB" || GetVR()=="OW" || GetVR()=="SQ" )
00160       {
00161          l = l + 12; // 2 (gr) + 2 (el) + 2 (vr) + 2 (unused) + 4 (lgth)
00162       }
00163       else
00164       {
00165          l = l + 8;  // 2 (gr) + 2 (el) + 2 (vr) + 2 (lgth)
00166       }
00167    }
00168    return l;
00169 }
00170 
00175 bool DocEntry::IsItemDelimitor()
00176 {
00177    return (GetGroup() == 0xfffe && GetElement() == 0xe00d);
00178 }
00179 
00184 bool DocEntry::IsSequenceDelimitor()
00185 {
00186    return (GetGroup() == 0xfffe && GetElement() == 0xe0dd);
00187 }
00188 
00193 void DocEntry::Copy(DocEntry *doc)
00194 {
00195    Length     = doc->Length;
00196    ReadLength = doc->ReadLength;
00197    ImplicitVR = doc->ImplicitVR;
00198    Offset     = doc->Offset;
00199 }
00200 
00201 //-----------------------------------------------------------------------------
00202 // Protected
00203 
00204 //-----------------------------------------------------------------------------
00205 // Private
00206 
00207 //-----------------------------------------------------------------------------
00208 // Print
00214 void DocEntry::Print(std::ostream &os, std::string const & )
00215 {
00216    size_t o;
00217    std::string st;
00218    TSKey v;
00219    std::string d2, vr;
00220    std::ostringstream s;
00221    uint32_t lgth;
00222 
00223    o  = GetOffset();
00224    vr = GetVR();
00225    if(vr==GDCM_UNKNOWN)
00226       vr="  ";
00227 
00228    s << DictEntry::TranslateToKey(GetGroup(),GetElement()); 
00229 
00230    if (PrintLevel >= 2)
00231    {
00232       s << " lg : ";
00233       lgth = GetReadLength(); // ReadLength, as opposed to Length
00234       if (lgth == 0xffffffff)
00235       {
00236          st = Util::Format("x(ffff)");  // I said : "x(ffff)" !
00237          s.setf(std::ios::left);
00238          s << std::setw(10-st.size()) << " ";  
00239          s << st << " ";
00240          s.setf(std::ios::left);
00241          s << std::setw(8) << "-1"; 
00242       }
00243       else
00244       {
00245          st = Util::Format("x(%x)",lgth);
00246          s.setf(std::ios::left);
00247          s << std::setw(10-st.size()) << " ";
00248          s << st << " ";
00249          s.setf(std::ios::left);
00250          s << std::setw(8) << lgth; 
00251       }
00252       s << " Off.: ";
00253       st = Util::Format("x(%x)",o); 
00254       s << std::setw(10-st.size()) << " ";
00255       s << st << " ";
00256       s << std::setw(8) << o; 
00257    }
00258 
00259    s << "[" << vr  << "] ";
00260 
00261    if (PrintLevel >= 1)
00262    {
00263       s.setf(std::ios::left);
00264       s << std::setw(66-GetName().length()) << " ";
00265    }
00266     
00267    s << "[" << GetName()<< "]";
00268    os << s.str();      
00269 }
00270 
00271 //-----------------------------------------------------------------------------
00272 } // end namespace gdcm

Generated on Thu Feb 10 22:17:57 2005 for gdcm by doxygen 1.3.6