]> Creatis software - gdcm.git/blob - src/gdcmHeaderEntry.cxx
Final solution (?) to embedded icone images
[gdcm.git] / src / gdcmHeaderEntry.cxx
1 // gdcmHeaderEntry.cxx
2 //-----------------------------------------------------------------------------
3 //
4 #include "gdcmHeaderEntry.h"
5 #include "gdcmTS.h"
6 #include "gdcmUtil.h"
7
8 #ifdef GDCM_NO_ANSI_STRING_STREAM
9 #  include <strstream>
10 #  define  ostringstream ostrstream
11 # else
12 #  include <sstream>
13 #endif
14 #include <iomanip> // for std::ios::left, ...
15
16
17 #define MAX_SIZE_PRINT_ELEMENT_VALUE 64
18
19 //-----------------------------------------------------------------------------
20 // Constructor / Destructor
21 /**
22  * \ingroup gdcmHeaderEntry
23  * \brief   Constructor from a given gdcmDictEntry
24  * @param   in Pointer to existing dictionary entry
25  */
26 gdcmHeaderEntry::gdcmHeaderEntry(gdcmDictEntry* in) {
27         ImplicitVR = false;
28         voidArea = NULL; // unsecure memory area to hold 'non string' values
29         entry = in;
30 }
31
32 //-----------------------------------------------------------------------------
33 // Print
34 void gdcmHeaderEntry::Print(std::ostream & os) {
35    size_t o;
36    unsigned short int g, e;
37    char st[20];
38    TSKey v;
39    std::string d2, vr;
40    gdcmTS * ts = gdcmGlobal::GetTS();
41    std::ostringstream s;
42    guint32 lgth;
43    char greltag[10];  //group element tag
44    g  = GetGroup();
45    e  = GetElement();
46    v  = GetValue();
47    o  = GetOffset();
48    vr = GetVR();
49    sprintf(greltag,"%04x|%04x ",g,e);           
50    s << greltag ;
51        
52    d2 = _CreateCleanString(v);  // replace non printable characters by '.'
53    if (printLevel>=2) { 
54       s << "lg : ";
55       lgth = GetReadLength(); // ReadLength, as opposed to UsableLength
56       if (lgth == 0xffffffff) {
57          sprintf(st,"x(ffff)");  // I said : "x(ffff)" !
58          s.setf(std::ios::left);
59          s << std::setw(10-strlen(st)) << " ";  
60          s << st << " ";
61          s.setf(std::ios::left);
62          s << std::setw(8) << "-1";      
63       } else {
64          sprintf(st,"x(%x)",lgth);
65          s.setf(std::ios::left);
66          s << std::setw(10-strlen(st)) << " ";  
67          s << st << " ";
68          s.setf(std::ios::left);
69          s << std::setw(8) << lgth; 
70       }
71       s << " Off.: ";
72       sprintf(st,"x(%x)",o); 
73       s << std::setw(10-strlen(st)) << " ";
74       s << st << " ";
75       s << std::setw(8) << o; 
76    }
77
78    s << "[" << vr  << "] ";
79
80    if (printLevel>=1) {      
81       s.setf(std::ios::left);
82       s << std::setw(66-GetName().length()) << " ";              
83    }
84     
85    s << "[" << GetName()<< "]";
86
87    if (voidArea != NULL) {
88        s << " [gdcm::Non String Data Loaded in Unsecure Area (" 
89          << GetLength() << ") ]";
90    } 
91    
92    else {             
93       if( (GetLength()<MAX_SIZE_PRINT_ELEMENT_VALUE) || 
94           (printLevel>=3)  || 
95           (d2.find("gdcm::NotLoaded.") < d2.length()) )
96          s << " [" << d2 << "]";
97       else 
98          s << " [gdcm::too long for print (" << GetLength() << ") ]";
99    }
100    
101    // Display the UID value (instead of displaying the rough code)  
102    if (g == 0x0002) {  // Any more to be displayed ?
103       if ( (e == 0x0010) || (e == 0x0002) )
104          s << "  ==>\t[" << ts->GetValue(v) << "]";
105    } else {
106       if (g == 0x0008) {
107          if ( (e == 0x0016) || (e == 0x1150)  )
108             s << "  ==>\t[" << ts->GetValue(v) << "]";
109       } else {
110          if (g == 0x0004) {
111             if ( (e == 0x1510) || (e == 0x1512)  )
112                s << "  ==>\t[" << ts->GetValue(v) << "]";
113          }     
114       }
115    }
116    //if (e == 0x0000) {        // elem 0x0000 --> group length 
117    if ( (vr == "UL") || (vr == "US") || (vr == "SL") || (vr == "SS") ) {
118       if (v == "4294967295") // to avoid troubles in convertion 
119          sprintf (st," x(ffffffff)");
120       else      
121          sprintf(st," x(%x)",(unsigned long)atof(v.c_str()));
122       s << st;
123    }
124    s << std::endl;
125    os << s.str();
126 }
127
128 //-----------------------------------------------------------------------------
129 // Public
130
131 //-----------------------------------------------------------------------------
132 // Protected
133
134 //-----------------------------------------------------------------------------
135 // Private
136
137 //-----------------------------------------------------------------------------