00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
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>
00027 #include <fstream>
00028
00029 namespace gdcm
00030 {
00031
00032 #define MAX_SIZE_PRINT_ELEMENT_VALUE 64
00033
00034
00035
00040 DocEntry::DocEntry(DictEntry *in)
00041 {
00042 ImplicitVR = false;
00043 DicomDict = in;
00044 SetKey( in->GetKey( ) );
00045 Offset = 0 ;
00046
00047
00048 ReadLength = 0;
00049 Length = 0;
00050 }
00051
00052
00053
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
00070
00071
00072 return;
00073 }
00074
00075
00076
00077 binary_write( *fp, group);
00078 binary_write( *fp, el);
00079
00080 if ( filetype == ExplicitVR )
00081 {
00082
00083 if (group == 0xfffe)
00084 {
00085
00086
00087
00088
00089
00090
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
00103
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
00118
00119
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
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;
00156 }
00157 else
00158 {
00159 if ( GetVR()=="OB" || GetVR()=="OW" || GetVR()=="SQ" )
00160 {
00161 l = l + 12;
00162 }
00163 else
00164 {
00165 l = l + 8;
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
00203
00204
00205
00206
00207
00208
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();
00234 if (lgth == 0xffffffff)
00235 {
00236 st = Util::Format("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 }