]> Creatis software - gdcm.git/blob - src/gdcmHeaderEntry.cxx
DICOMDIR related utilities (not checked as Windoze compilant)
[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         entry = in;
29 }
30
31 //-----------------------------------------------------------------------------
32 // Print
33 void gdcmHeaderEntry::Print(std::ostream & os) {
34    size_t o;
35    unsigned short int g, e;
36    char st[20];
37    TSKey v;
38    std::string d2, vr;
39    gdcmTS * ts = gdcmGlobal::GetTS();
40    std::ostringstream s;
41    guint32 lgth;
42    char greltag[10];  //group element tag
43    g  = GetGroup();
44    e  = GetElement();
45    v  = GetValue();
46    o  = GetOffset();
47    vr = GetVR();
48    sprintf(greltag,"%04x|%04x ",g,e);           
49    s << greltag ;
50        
51    d2 = _CreateCleanString(v);  // replace non printable characters by '.'
52    if (printLevel>=2) { 
53       s << "lg : ";
54       lgth = GetReadLength();
55       if (lgth == 0xffffffff) {
56          sprintf(st,"x(ffff)");  // I said : "x(ffff)" !
57          s.setf(std::ios::left);
58          s << std::setw(10-strlen(st)) << " ";  
59          s << st << " ";
60          s.setf(std::ios::left);
61          s << std::setw(8) << "-1";      
62       } else {
63          sprintf(st,"x(%x)",lgth);
64          s.setf(std::ios::left);
65          s << std::setw(10-strlen(st)) << " ";  
66          s << st << " ";
67          s.setf(std::ios::left);
68          s << std::setw(8) << lgth; 
69       }
70       s << " Off.: ";
71       sprintf(st,"x(%x)",o); 
72       s << std::setw(10-strlen(st)) << " ";
73       s << st << " ";
74       s << std::setw(8) << o; 
75    }
76
77    s << "[" << vr  << "] ";
78
79    if (printLevel>=1) {      
80       s.setf(std::ios::left);
81       s << std::setw(66-GetName().length()) << " ";              
82    }
83     
84    s << "[" << GetName()<< "]";
85
86      
87            
88    if( (GetLength()<MAX_SIZE_PRINT_ELEMENT_VALUE) || 
89        (printLevel>=3)  || 
90        (d2.find("gdcm::NotLoaded.") < d2.length()) )
91       s << " [" << d2 << "]";
92    else 
93       s << " [ gdcm::too long for print (" << GetLength() << ") ]";
94
95    // Display the UID value (instead of displaying the rough code)  
96    if (g == 0x0002) {  // Any more to be displayed ?
97       if ( (e == 0x0010) || (e == 0x0002) )
98          s << "  ==>\t[" << ts->GetValue(v) << "]";
99    } else {
100       if (g == 0x0008) {
101          if ( (e == 0x0016) || (e == 0x1150)  )
102             s << "  ==>\t[" << ts->GetValue(v) << "]";
103       } else {
104          if (g == 0x0004) {
105             if ( (e == 0x1510) || (e == 0x1512)  )
106                s << "  ==>\t[" << ts->GetValue(v) << "]";
107          }     
108       }
109    }
110    //if (e == 0x0000) {        // elem 0x0000 --> group length 
111    if ( (vr == "UL") || (vr == "US") || (vr == "SL") || (vr == "SS") ) {
112       if (v == "4294967295") // to avoid troubles in convertion 
113          sprintf (st," x(ffffffff)");
114       else      
115          sprintf(st," x(%x)",(unsigned long)atof(v.c_str()));
116       s << st;
117    }
118    s << std::endl;
119    os << s.str();
120 }
121
122 //-----------------------------------------------------------------------------
123 // Public
124
125 //-----------------------------------------------------------------------------
126 // Protected
127
128 //-----------------------------------------------------------------------------
129 // Private
130
131 //-----------------------------------------------------------------------------