51template <
long long TVR,
int TVM>
68template<long long 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;
191 inline std::istream& operator>> (std::istream& in,
ignore_char const& ic) {
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;
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];
269template <
typename Float >
270std::string to_string ( Float data ) {
271 std::stringstream in;
275 - std::log( std::numeric_limits<Float>::epsilon() )
276 /
static_cast< Float
>( std::log( 10.0 ) ) );
277 if ( in << std::dec << std::setprecision(digits) << data ) {
280 throw "Impossible Conversion";
286static inline void clean(
char *mant) {
287 char *ix = mant + strlen(mant) - 1;
288 while((
'0' == *ix) && (ix > mant)) {
296static int add1(
char *buf,
int n) {
300 return add1(buf, n-1);
303 buf[n] = (char)(buf[n] + 1);
308static int doround(
char *buf,
unsigned int n) {
310 if (n >= strlen(buf))
return 0;
313 if ((c >=
'5') && (c <=
'9'))
return add1(buf, n-1);
317#if defined(_MSC_VER) && (_MSC_VER < 1900)
318#define snprintf _snprintf
321static int roundat(
char *buf,
size_t bufLen,
unsigned int i,
int iexp) {
341 snprintf(buf, bufLen,
"1e%d", iexp);
348template <
typename Float >
351 char *mant = line + 1;
360 snprintf(line,
sizeof(line),
"%1.16e", f);
361 if (line[0] ==
'-') {
365 snprintf(line,
sizeof(line),
"%1.16e", f);
368 i = (int)strcspn(mant,
"eE");
370 iexp = (int)strtol(mant + i + 1,
nullptr, 10);
371 lexp = snprintf(exp,
sizeof(exp),
"e%d", iexp);
372 if ((iexp >= size) || (iexp < -3)) {
373 i =
roundat(mant,
sizeof(line) - 1, size - 1 -lexp, iexp);
380 strncpy(buf + i + 2, mant + 1, size - 2 - lexp);
385 else if (iexp >= size - 2) {
386 roundat(mant,
sizeof(line) - 1, iexp + 1, iexp);
389 else if (iexp >= 0) {
390 i =
roundat(mant,
sizeof(line) - 1, size - 1, iexp);
395 strncpy(buf, mant, iexp + 1);
397 strncpy(buf + iexp + 2, mant + iexp + 1, size - iexp - 1);
403 i =
roundat(mant,
sizeof(line) - 1, size + 1 + iexp, iexp);
409 for(j=0; j< -1 - iexp; j++) {
412 strncpy(buf - iexp, mant, size + 1 + iexp);
417#if defined(_MSC_VER) && (_MSC_VER < 1900)
428 _os << to_string(data[0]);
434 for(
unsigned long i=1; i<length; ++i) {
437 _os <<
"\\" << to_string(data[i]);
456 const unsigned int type_size =
sizeof(T);
461 _is.read(
reinterpret_cast<char*
>(data+0), type_size);
462 for(
unsigned long i=1; i<length; ++i) {
464 _is.read(
reinterpret_cast<char*
>(data+i), type_size );
470 const unsigned int type_size =
sizeof(T);
474 _is.read(
reinterpret_cast<char*
>(data+0), type_size);
475 for(
unsigned long i=1; i<length; ++i) {
477 _is.read(
reinterpret_cast<char*
>(data+i), type_size );
484 static inline void Read(T* data,
unsigned long length,
486 const unsigned int type_size =
sizeof(T);
490 _is.read(
reinterpret_cast<char*
>(data+0), type_size);
491 for(
unsigned long i=1; i<length; ++i) {
493 _is.read(
reinterpret_cast<char*
>(data+i), type_size );
497 SwapperNoOp::SwapArray(data,length);
500 static inline void Write(
const T* data,
unsigned long length,
502 const unsigned int type_size =
sizeof(T);
508 T swappedData = SwapperNoOp::Swap(data[0]);
509 _os.write(
reinterpret_cast<const char*
>(&swappedData), type_size);
510 for(
unsigned long i=1; i<length;++i) {
512 swappedData = SwapperNoOp::Swap(data[i]);
513 _os.write(
reinterpret_cast<const char*
>(&swappedData), type_size );
529 Element(
const char array[])
532 const char sep =
'\\';
533 std::string sarray = array;
534 std::string::size_type pos1 = 0;
535 std::string::size_type pos2 = sarray.find(sep, pos1+1);
536 while(pos2 != std::string::npos)
538 Internal[i++] = sarray.substr(pos1, pos2-pos1);
540 pos2 = sarray.find(sep, pos1+1);
542 Internal[i] = sarray.substr(pos1, pos2-pos1);
545 assert( GetLength()-1 == i );
548 unsigned long GetLength()
const {
549 return VMToLength<TVM>::Length;
552 void Print(std::ostream &_os)
const {
554 for(
int i=1; i<VMToLength<TVM>::Length; ++i)
555 _os <<
"," << Internal[i];
558 void Read(std::istream &_is) {
559 EncodingImplementation<VR::VRASCII>::Read(Internal, GetLength(),_is);
561 void Write(std::ostream &_os)
const {
562 EncodingImplementation<VR::VRASCII>::Write(Internal, GetLength(),_os);
565 typename String Internal[VMToLength<TVM>::Length];
569class Element<VR::PN, TVM> :
public StringElement<TVM>
571 enum { ElementDisableCombinationsCheck =
sizeof ( ElementDisableCombinations<VR::PN, TVM> ) };
576template<
long long TVR>
582 explicit Element() { Internal=
nullptr; Length=0; Save =
false; }
600 const unsigned int size =
sizeof(
Type);
604 assert( (len / size) * size == len );
605 Type *internal =
new Type[len / size];
606 assert( Save ==
false );
610 memcpy(internal, Internal, len);
625 memcpy(Internal, array, len);
626 assert( Save ==
false );
630 assert( Length == 0 );
631 assert( Internal ==
nullptr );
632 assert( Save ==
false );
633 Length = len /
sizeof(
Type);
637 if( (len /
sizeof(
Type)) *
sizeof(
Type) != len ) { Internal =
nullptr; Length = 0; }
638 else Internal =
const_cast<Type*
>(array);
643 assert( idx < Length );
647 assert( idx < Length );
648 return Internal[idx];
652 return Internal[idx];
655 return GetValue(idx);
665 assert( Internal ==
nullptr );
670 std::stringstream ss;
680#ifdef GDCM_WORDS_BIGENDIAN
681 if( de.
GetVR() == VR::UN )
683 if( de.
GetVR() == VR::UN || de.
GetVR() == VR::INVALID )
701 void Print(std::ostream &_os)
const {
705 const unsigned long length = GetLength() < 25 ? GetLength() : 25;
706 for(
unsigned long i=1; i<length; ++i)
707 _os <<
"," << Internal[i];
710 if( !Internal )
return;
719 void Write(std::ostream &_os)
const {
727 assert( ret.
GetVR() != VR::SQ );
730 std::ostringstream os;
735 if( GetVR() != VR::UI )
737 if( os.str().size() % 2 )
758 SetArray(_val.Internal, _val.Length,
true);
770 assert( Internal ==
nullptr );
775 std::stringstream ss;
785 unsigned long Length;
793template<
long long TVR>
799 if( len != 1 && len != 2 )
return;
800 Parent::SetLength(len);
803template<
long long TVR>
810 if( len <= 1 )
return;
811 Parent::SetLength(len);
814template<
long long TVR>
821 if( len % 2 )
return;
822 Parent::SetLength(len);
825template<
long long TVR>
832 if( len <= 2 )
return;
833 Parent::SetLength(len);
836template<
long long TVR>
843 if( len % 3 )
return;
844 Parent::SetLength(len);
847template<
long long TVR>
853 if( len != 3 && len != 4 )
return;
854 Parent::SetLength(len);
872 void Print(std::ostream &_os)
const {
Class to represent binary value (array of bytes)
Definition gdcmByteValue.h:35
const void * GetVoidPointer() const
Definition gdcmByteValue.h:115
const char * GetPointer() const
Definition gdcmByteValue.h:110
VL GetLength() const override
Definition gdcmByteValue.h:77
Class to represent a Data Element either Implicit or Explicit.
Definition gdcmDataElement.h:59
VR const & GetVR() const
Definition gdcmDataElement.h:84
const ByteValue * GetByteValue() const
Definition gdcmDataElement.h:133
Value const & GetValue() const
Set/Get Value (bytes array, SQ of items, SQ of fragments):
Definition gdcmDataElement.h:94
void SetByteValue(const char *array, VL length)
Definition gdcmDataElement.h:126
void SetVR(VR const &vr)
Definition gdcmDataElement.h:88
A class which is used to produce compile errors for an invalid combination of template parameters.
Definition gdcmElement.h:52
Element< TVR, VM::VM1_n > Parent
Definition gdcmElement.h:797
void SetLength(int len)
Definition gdcmElement.h:798
Element()
Definition gdcmElement.h:582
void Read(std::istream &_is)
Definition gdcmElement.h:709
void SetNoSwap(Value const &v)
Definition gdcmElement.h:762
void SetLength(unsigned long len)
Definition gdcmElement.h:599
void WriteASCII(std::ostream &os) const
Definition gdcmElement.h:696
static VR GetVR()
Definition gdcmElement.h:590
VRToType< TVR >::Type & GetValue(unsigned int idx=0)
Definition gdcmElement.h:650
void Set(Value const &v)
Definition gdcmElement.h:657
static VM GetVM()
Definition gdcmElement.h:591
void SetFromDataElement(DataElement const &de)
Definition gdcmElement.h:677
void SetArray(const Type *array, unsigned long len, bool save=false)
Definition gdcmElement.h:621
Element & operator=(const Element &_val)
Definition gdcmElement.h:755
void Print(std::ostream &_os) const
Definition gdcmElement.h:701
unsigned long GetLength() const
Definition gdcmElement.h:596
DataElement GetAsDataElement() const
Definition gdcmElement.h:724
void SetValue(typename VRToType< TVR >::Type v, unsigned int idx=0)
Definition gdcmElement.h:642
VRToType< TVR >::Type Type
Definition gdcmElement.h:597
const VRToType< TVR >::Type & GetValue(unsigned int idx=0) const
Definition gdcmElement.h:646
~Element()
Definition gdcmElement.h:583
void Write(std::ostream &_os) const
Definition gdcmElement.h:719
Element(const Element &_val)
Definition gdcmElement.h:749
Element< TVR, VM::VM2_n > Parent
Definition gdcmElement.h:819
void SetLength(int len)
Definition gdcmElement.h:820
void SetLength(int len)
Definition gdcmElement.h:809
Element< TVR, VM::VM1_n > Parent
Definition gdcmElement.h:808
void SetLength(int len)
Definition gdcmElement.h:842
Element< TVR, VM::VM3_n > Parent
Definition gdcmElement.h:841
Element< TVR, VM::VM1_n > Parent
Definition gdcmElement.h:851
void SetLength(int len)
Definition gdcmElement.h:852
Element< TVR, VM::VM1_n > Parent
Definition gdcmElement.h:830
void SetLength(int len)
Definition gdcmElement.h:831
unsigned long GetLength() const
Definition gdcmElement.h:875
void Print(std::ostream &_os) const
Definition gdcmElement.h:872
Element class.
Definition gdcmElement.h:70
static VM GetVM()
Definition gdcmElement.h:77
DataElement GetAsDataElement() const
Definition gdcmElement.h:127
VRToType< TVR >::Type & GetValue(unsigned int idx=0)
Definition gdcmElement.h:98
VRToType< TVR >::Type Type
Definition gdcmElement.h:74
void Read(std::istream &_is)
Definition gdcmElement.h:150
unsigned long GetLength() const
Definition gdcmElement.h:79
void SetValue(typename VRToType< TVR >::Type v, unsigned int idx=0)
Definition gdcmElement.h:105
const VRToType< TVR >::Type & GetValue(unsigned int idx=0) const
Definition gdcmElement.h:94
const VRToType< TVR >::Type * GetValues() const
Definition gdcmElement.h:91
void Write(std::ostream &_os) const
Definition gdcmElement.h:154
void SetNoSwap(Value const &v)
Definition gdcmElement.h:173
static VR GetVR()
Definition gdcmElement.h:76
void Print(std::ostream &_os) const
Definition gdcmElement.h:85
void Set(Value const &v)
Definition gdcmElement.h:161
void SetFromDataElement(DataElement const &de)
Definition gdcmElement.h:110
static void ReadComputeLength(T *data, unsigned int &length, std::istream &_is)
Definition gdcmElement.h:204
static void ReadNoSwap(T *data, unsigned long length, std::istream &_is)
Definition gdcmElement.h:248
static void Write(const T *data, unsigned long length, std::ostream &_os)
Definition gdcmElement.h:253
static void Read(T *data, unsigned long length, std::istream &_is)
Definition gdcmElement.h:228
static void ReadNoSwap(T *data, unsigned long length, std::istream &_is)
Definition gdcmElement.h:468
static void Read(T *data, unsigned long length, std::istream &_is)
Definition gdcmElement.h:484
static void Write(const T *data, unsigned long length, std::ostream &_os)
Definition gdcmElement.h:500
static void ReadComputeLength(T *data, unsigned int &length, std::istream &_is)
Definition gdcmElement.h:454
EncodingImplementation.
Definition gdcmElement.h:41
uint32_t Type
Definition gdcmVL.h:32
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:68
VMType
Definition gdcmVM.h:70
VR class.
Definition gdcmVR.h:55
VRType
Definition gdcmVR.h:57
Class to represent the value of a Data Element.
Definition gdcmValue.h:32
static int add1(char *buf, int n)
Definition gdcmElement.h:296
static int roundat(char *buf, size_t bufLen, unsigned int i, int iexp)
Definition gdcmElement.h:321
static int doround(char *buf, unsigned int n)
Definition gdcmElement.h:308
static void clean(char *mant)
Definition gdcmElement.h:286
static void x16printf(char *buf, int size, Float f)
Definition gdcmElement.h:349
ignore_char const backslash('\\')
Definition gdcmElement.h:185
char m_char
Definition gdcmElement.h:187
ignore_char(char c)
Definition gdcmElement.h:186