51 template <
int TVR,
int TVM>
68 template<int TVR, int TVM>
85 void Print(std::ostream &_os)
const {
87 for(
int i=1; i<VMToLength<TVM>::Length; ++i)
88 _os <<
"," << Internal[i];
100 return Internal[idx];
103 return GetValue(idx);
113 #ifdef GDCM_WORDS_BIGENDIAN
114 if( de.
GetVR() == VR::UN )
116 if( de.
GetVR() == VR::UN || de.
GetVR() == VR::INVALID )
129 std::ostringstream os;
133 assert( ret.
GetVR() != VR::SQ );
136 if( GetVR() != VR::UI )
138 if( os.str().size() % 2 )
154 void Write(std::ostream &_os)
const {
165 std::stringstream ss;
177 std::stringstream ss;
193 in.clear(in.rdstate() & ~
std::ios_base::failbit);
194 if (in.get() != ic.
m_char)
195 in.setstate(std::ios_base::failbit);
212 while( _is >> data[length++] )
217 assert( sep ==
'\\' || sep ==
' ' );
218 if( sep ==
' ' ) length--;
221 while( _is >> std::ws >> data[length++] >> std::ws >>
backslash )
228 static inline void Read(T* data,
unsigned long length,
235 _is >> std::ws >> data[0];
238 for(
unsigned long i=1; i<length;++i) {
241 _is >> std::ws >> sep;
242 assert( sep ==
'\\' );
243 _is >> std::ws >> data[i];
250 Read(data,length,_is);
253 static inline void Write(
const T* data,
unsigned long length,
259 for(
unsigned long i=1; i<length; ++i) {
261 _os <<
"\\" << data[i];
266 template <
typename Float >
268 std::stringstream in;
272 - std::log( std::numeric_limits<Float>::epsilon() )
273 / std::log( 10.0 ) );
274 if ( in << std::dec << std::setprecision(digits) << data ) {
277 throw "Impossible Conversion";
288 for(
unsigned long i=1; i<length; ++i) {
299 for(
unsigned long i=1; i<length; ++i) {
316 const unsigned int type_size =
sizeof(T);
321 _is.read( reinterpret_cast<char*>(data+0), type_size);
322 for(
unsigned long i=1; i<length; ++i) {
324 _is.read( reinterpret_cast<char*>(data+i), type_size );
330 const unsigned int type_size =
sizeof(T);
334 _is.read( reinterpret_cast<char*>(data+0), type_size);
335 for(
unsigned long i=1; i<length; ++i) {
337 _is.read( reinterpret_cast<char*>(data+i), type_size );
344 static inline void Read(T* data,
unsigned long length,
346 const unsigned int type_size =
sizeof(T);
350 _is.read( reinterpret_cast<char*>(data+0), type_size);
351 for(
unsigned long i=1; i<length; ++i) {
353 _is.read( reinterpret_cast<char*>(data+i), type_size );
357 SwapperNoOp::SwapArray(data,length);
360 static inline void Write(
const T* data,
unsigned long length,
362 const unsigned int type_size =
sizeof(T);
368 T swappedData = SwapperNoOp::Swap(data[0]);
369 _os.write( reinterpret_cast<const char*>(&swappedData), type_size);
370 for(
unsigned long i=1; i<length;++i) {
372 swappedData = SwapperNoOp::Swap(data[i]);
373 _os.write( reinterpret_cast<const char*>(&swappedData), type_size );
389 Element(
const char array[])
392 const char sep =
'\\';
393 std::string sarray = array;
394 std::string::size_type pos1 = 0;
395 std::string::size_type pos2 = sarray.find(sep, pos1+1);
396 while(pos2 != std::string::npos)
398 Internal[i++] = sarray.substr(pos1, pos2-pos1);
400 pos2 = sarray.find(sep, pos1+1);
402 Internal[i] = sarray.substr(pos1, pos2-pos1);
405 assert( GetLength()-1 == i );
408 unsigned long GetLength()
const {
409 return VMToLength<TVM>::Length;
412 void Print(std::ostream &_os)
const {
414 for(
int i=1; i<VMToLength<TVM>::Length; ++i)
415 _os <<
"," << Internal[i];
418 void Read(std::istream &_is) {
419 EncodingImplementation<VR::VRASCII>::Read(Internal, GetLength(),_is);
421 void Write(std::ostream &_os)
const {
422 EncodingImplementation<VR::VRASCII>::Write(Internal, GetLength(),_os);
425 typename String Internal[VMToLength<TVM>::Length];
429 class Element<VR::PN, TVM> :
public StringElement<TVM>
431 enum { ElementDisableCombinationsCheck =
sizeof ( ElementDisableCombinations<VR::PN, TVM> ) };
442 explicit Element() { Internal=0; Length=0; Save =
false; }
460 const unsigned int size =
sizeof(Type);
464 assert( (len / size) * size == len );
465 Type *
internal =
new Type[len / size];
466 assert( Save ==
false );
470 memcpy(
internal, Internal, len);
481 void SetArray(
const Type *array,
unsigned long len,
485 memcpy(Internal, array, len);
486 assert( Save ==
false );
490 assert( Length == 0 );
491 assert( Internal == 0 );
492 assert( Save ==
false );
493 Length = len /
sizeof(Type);
497 if( (len /
sizeof(Type)) *
sizeof(Type) != len ) { Internal = 0; Length = 0; }
498 else Internal =
const_cast<Type*
>(array);
503 assert( idx < Length );
507 assert( idx < Length );
508 return Internal[idx];
512 return Internal[idx];
515 return GetValue(idx);
525 assert( Internal == 0 );
530 std::stringstream ss;
540 #ifdef GDCM_WORDS_BIGENDIAN
541 if( de.
GetVR() == VR::UN )
543 if( de.
GetVR() == VR::UN || de.
GetVR() == VR::INVALID )
561 void Print(std::ostream &_os)
const {
565 const unsigned long length = GetLength() < 25 ? GetLength() : 25;
566 for(
unsigned long i=1; i<length; ++i)
567 _os <<
"," << Internal[i];
570 if( !Internal )
return;
579 void Write(std::ostream &_os)
const {
587 assert( ret.
GetVR() != VR::SQ );
590 std::ostringstream os;
595 if( GetVR() != VR::UI )
597 if( os.str().size() % 2 )
618 SetArray(_val.Internal, _val.Length,
true);
630 assert( Internal == 0 );
635 std::stringstream ss;
645 unsigned long Length;
659 if( len != 1 || len != 2 )
return;
660 Parent::SetLength(len);
670 if( len <= 1 )
return;
671 Parent::SetLength(len);
681 if( len % 2 )
return;
682 Parent::SetLength(len);
692 if( len <= 2 )
return;
693 Parent::SetLength(len);
703 if( len % 3 )
return;
704 Parent::SetLength(len);
722 void Print(std::ostream &_os)
const {
741 #endif //GDCMELEMENT_H
void SetVR(VR const &vr)
Definition: gdcmDataElement.h:88
Element(const Element &_val)
Definition: gdcmElement.h:609
unsigned long GetLength() const
Definition: gdcmElement.h:725
static void Read(T *data, unsigned long length, std::istream &_is)
Definition: gdcmElement.h:228
void SetByteValue(const char *array, VL length)
Definition: gdcmDataElement.h:123
void Print(std::ostream &_os) const
Definition: gdcmElement.h:85
std::istream & operator>>(std::istream &in, ignore_char const &ic)
Definition: gdcmElement.h:191
void SetLength(int len)
Definition: gdcmElement.h:702
void SetLength(int len)
Definition: gdcmElement.h:680
VRType
Definition: gdcmVR.h:57
void SetNoSwap(Value const &v)
Definition: gdcmElement.h:622
void SetValue(typename VRToType< TVR >::Type v, unsigned int idx=0)
Definition: gdcmElement.h:105
unsigned long GetLength() const
Definition: gdcmElement.h:79
char m_char
Definition: gdcmElement.h:187
VRBINARY
Definition: gdcmVR.h:284
void Write(std::ostream &_os) const
Definition: gdcmElement.h:154
Class to represent the value of a Data Element.
Definition: gdcmValue.h:31
VRToType< TVR >::Type & GetValue(unsigned int idx=0)
Definition: gdcmElement.h:98
void SetLength(unsigned long len)
Definition: gdcmElement.h:459
VL GetLength() const
Definition: gdcmByteValue.h:78
const VRToType< TVR >::Type * GetValues() const
Definition: gdcmElement.h:91
Element< TVR, VM::VM1_n > Parent
Definition: gdcmElement.h:690
void SetLength(int len)
Definition: gdcmElement.h:691
unsigned long GetLength() const
Definition: gdcmElement.h:456
void Read(std::istream &_is)
Definition: gdcmElement.h:569
Definition: gdcmElement.h:185
static void Write(const T *data, unsigned long length, std::ostream &_os)
Definition: gdcmElement.h:360
void SetNoSwap(Value const &v)
Definition: gdcmElement.h:173
static void Read(T *data, unsigned long length, std::istream &_is)
Definition: gdcmElement.h:344
A class which is used to produce compile errors for an invalid combination of template parameters...
Definition: gdcmElement.h:52
std::string to_string(Float data)
Definition: gdcmElement.h:267
void SetFromDataElement(DataElement const &de)
Definition: gdcmElement.h:537
Element class.
Definition: gdcmElement.h:69
Definition: gdcmElement.h:686
const ByteValue * GetByteValue() const
Definition: gdcmDataElement.h:130
Definition: gdcmElement.h:437
Definition: gdcmElement.h:664
DataElement GetAsDataElement() const
Definition: gdcmElement.h:584
void SetFromDataElement(DataElement const &de)
Definition: gdcmElement.h:110
Class to represent a Data Element either Implicit or Explicit.
Definition: gdcmDataElement.h:58
Class to represent binary value (array of bytes)
Definition: gdcmByteValue.h:35
void Write(std::ostream &_os) const
Definition: gdcmElement.h:579
Element< TVR, VM::VM2_n > Parent
Definition: gdcmElement.h:679
~Element()
Definition: gdcmElement.h:443
void WriteASCII(std::ostream &os) const
Definition: gdcmElement.h:556
static void Write(const T *data, unsigned long length, std::ostream &_os)
Definition: gdcmElement.h:253
VR const & GetVR() const
Definition: gdcmDataElement.h:84
Value Multiplicity Looking at the DICOMV3 dict only there is very few cases: 1 2 3 4 5 6 8 16 24 1-2 ...
Definition: gdcmVM.h:67
static void ReadComputeLength(T *data, unsigned int &length, std::istream &_is)
Definition: gdcmElement.h:204
static VR GetVR()
Definition: gdcmElement.h:76
Value const & GetValue() const
Set/Get Value (bytes array, SQ of items, SQ of fragments):
Definition: gdcmDataElement.h:94
ignore_char const backslash('\\')
static void ReadNoSwap(T *data, unsigned long length, std::istream &_is)
Definition: gdcmElement.h:248
void Print(std::ostream &_os) const
Definition: gdcmElement.h:561
void Set(Value const &v)
Definition: gdcmElement.h:161
Element & operator=(const Element &_val)
Definition: gdcmElement.h:615
void SetLength(int len)
Definition: gdcmElement.h:669
Element< TVR, VM::VM1_n > Parent
Definition: gdcmElement.h:657
const VRToType< TVR >::Type & GetValue(unsigned int idx=0) const
Definition: gdcmElement.h:506
void SetValue(typename VRToType< TVR >::Type v, unsigned int idx=0)
Definition: gdcmElement.h:502
VRToType< TVR >::Type & GetValue(unsigned int idx=0)
Definition: gdcmElement.h:510
Element< TVR, VM::VM3_n > Parent
Definition: gdcmElement.h:701
void SetArray(const Type *array, unsigned long len, bool save=false)
Definition: gdcmElement.h:481
void Read(std::istream &_is)
Definition: gdcmElement.h:150
VRToType< TVR >::Type Type
Definition: gdcmElement.h:74
DataElement GetAsDataElement() const
Definition: gdcmElement.h:127
EncodingImplementation.
Definition: gdcmElement.h:41
void Print(std::ostream &_os) const
Definition: gdcmElement.h:722
const char * GetPointer() const
Definition: gdcmByteValue.h:111
static void ReadNoSwap(T *data, unsigned long length, std::istream &_is)
Definition: gdcmElement.h:328
void SetLength(int len)
Definition: gdcmElement.h:658
ignore_char(char c)
Definition: gdcmElement.h:186
static void ReadComputeLength(T *data, unsigned int &length, std::istream &_is)
Definition: gdcmElement.h:314
static VM GetVM()
Definition: gdcmElement.h:77
void Set(Value const &v)
Definition: gdcmElement.h:517
VR class This is adapted from DICOM standard The biggest difference is the INVALID VR and the composi...
Definition: gdcmVR.h:54
Element()
Definition: gdcmElement.h:442
VRToType< TVR >::Type Type
Definition: gdcmElement.h:457
VMType
Definition: gdcmVM.h:70
static VR GetVR()
Definition: gdcmElement.h:450
static VM GetVM()
Definition: gdcmElement.h:451
uint32_t Type
Definition: gdcmVL.h:32
Element< TVR, VM::VM1_n > Parent
Definition: gdcmElement.h:668
const VRToType< TVR >::Type & GetValue(unsigned int idx=0) const
Definition: gdcmElement.h:94