Main Page | File List | Related Pages

gdcmHeaderEntry.cxx

00001 // gdcmHeaderEntry.cxx
00002 //-----------------------------------------------------------------------------
00003 //
00004 #include "gdcmHeaderEntry.h"
00005 #include "gdcmTS.h"
00006 #include "gdcmUtil.h"
00007 
00008 #ifdef GDCM_NO_ANSI_STRING_STREAM
00009 #  include <strstream>
00010 #  define  ostringstream ostrstream
00011 # else
00012 #  include <sstream>
00013 #endif
00014 #include <iomanip> // for std::ios::left, ...
00015 
00016 
00017 #define MAX_SIZE_PRINT_ELEMENT_VALUE 64
00018 
00019 //-----------------------------------------------------------------------------
00020 // Constructor / Destructor
00026 gdcmHeaderEntry::gdcmHeaderEntry(gdcmDictEntry* in) {
00027         ImplicitVR = false;
00028         voidArea = NULL; // unsecure memory area to hold 'non string' values
00029         entry = in;
00030 }
00031 
00032 //-----------------------------------------------------------------------------
00033 // Print
00038 void gdcmHeaderEntry::Print(std::ostream & os) {
00039    size_t o;
00040    unsigned short int g, e;
00041    char st[20];
00042    TSKey v;
00043    std::string d2, vr;
00044    gdcmTS * ts = gdcmGlobal::GetTS();
00045    std::ostringstream s;
00046    guint32 lgth;
00047    char greltag[10];  //group element tag
00048 
00049    g  = GetGroup();
00050    e  = GetElement();
00051    v  = GetValue();
00052    o  = GetOffset();
00053    vr = GetVR();
00054    sprintf(greltag,"%04x|%04x ",g,e);           
00055    s << greltag ;
00056        
00057    d2 = _CreateCleanString(v);  // replace non printable characters by '.'
00058    if (printLevel>=2) { 
00059       s << "lg : ";
00060       lgth = GetReadLength(); // ReadLength, as opposed to UsableLength
00061       if (lgth == 0xffffffff) {
00062          sprintf(st,"x(ffff)");  // I said : "x(ffff)" !
00063          s.setf(std::ios::left);
00064          s << std::setw(10-strlen(st)) << " ";  
00065          s << st << " ";
00066          s.setf(std::ios::left);
00067          s << std::setw(8) << "-1";      
00068       } else {
00069          sprintf(st,"x(%x)",lgth);
00070          s.setf(std::ios::left);
00071          s << std::setw(10-strlen(st)) << " ";  
00072          s << st << " ";
00073          s.setf(std::ios::left);
00074          s << std::setw(8) << lgth; 
00075       }
00076       s << " Off.: ";
00077       sprintf(st,"x(%x)",o); 
00078       s << std::setw(10-strlen(st)) << " ";
00079       s << st << " ";
00080       s << std::setw(8) << o; 
00081    }
00082 
00083    s << "[" << vr  << "] ";
00084 
00085    if (printLevel>=1) {      
00086       s.setf(std::ios::left);
00087       s << std::setw(66-GetName().length()) << " ";              
00088    }
00089     
00090    s << "[" << GetName()<< "]";
00091 
00092    if (voidArea != NULL) {
00093        s << " [gdcm::Non String Data Loaded in Unsecure Area (" 
00094          << GetLength() << ") ]";
00095    } 
00096    
00097    else {             
00098       if( (GetLength()<MAX_SIZE_PRINT_ELEMENT_VALUE) || 
00099           (printLevel>=3)  || 
00100           (d2.find("gdcm::NotLoaded.") < d2.length()) )
00101          s << " [" << d2 << "]";
00102       else 
00103          s << " [gdcm::too long for print (" << GetLength() << ") ]";
00104    }
00105    
00106    // Display the UID value (instead of displaying the rough code)  
00107    if (g == 0x0002) {  // Any more to be displayed ?
00108       if ( (e == 0x0010) || (e == 0x0002) )
00109          s << "  ==>\t[" << ts->GetValue(v) << "]";
00110    } else {
00111       if (g == 0x0008) {
00112          if ( (e == 0x0016) || (e == 0x1150)  )
00113             s << "  ==>\t[" << ts->GetValue(v) << "]";
00114       } else {
00115          if (g == 0x0004) {
00116             if ( (e == 0x1510) || (e == 0x1512)  )
00117                s << "  ==>\t[" << ts->GetValue(v) << "]";
00118          }     
00119       }
00120    }
00121    //if (e == 0x0000) {        // elem 0x0000 --> group length 
00122    if ( (vr == "UL") || (vr == "US") || (vr == "SL") || (vr == "SS") ) {
00123       if (v == "4294967295") // to avoid troubles in convertion 
00124          sprintf (st," x(ffffffff)");
00125       else      
00126          sprintf(st," x(%x)",(unsigned long)atof(v.c_str()));
00127       s << st;
00128    }
00129    s << std::endl;
00130    os << s.str();
00131 }
00132 
00133 //-----------------------------------------------------------------------------
00134 // Public
00135 
00136 //-----------------------------------------------------------------------------
00137 // Protected
00138 
00139 //-----------------------------------------------------------------------------
00140 // Private
00141 
00142 //-----------------------------------------------------------------------------

Generated on Mon Feb 14 16:13:44 2005 for gdcm by doxygen 1.3.6