14#ifndef GDCMATTRIBUTE_H
15#define GDCMATTRIBUTE_H
19#include "gdcmTagToType.h"
41 static inline uint16_t
Read(std::istream &_is) {
43 _is.read((
char*)&l, 2);
47 static inline void Write(std::ostream &os) { (void)os;
53 static inline uint32_t
Read(std::istream &_is) {
58 _is.read((
char*)&l, 4);
62 static inline void Write(std::ostream &os) { (void)os;
81template<uint16_t Group, uint16_t Element,
82 long long TVR = TagToType<Group, Element>::VRType,
83 int TVM = TagToType<Group, Element>::VMType
117 void Print(std::ostream &os)
const {
118 os << GetTag() <<
" ";
119 os << TagToType<Group,Element>::GetVRString() <<
" ";
120 os << TagToType<Group,Element>::GetVMString() <<
" ";
122 for(
unsigned int i=1; i<GetNumberOfValues(); ++i)
123 os <<
"," << Internal[i];
140 return std::equal(Internal, Internal+GetNumberOfValues(),
145 return !std::equal(Internal, Internal+GetNumberOfValues(),
150 return std::lexicographical_compare(Internal, Internal+GetNumberOfValues(),
155 assert( idx < GetNumberOfValues() );
156 return Internal[idx];
159 return GetValue(idx);
163 assert( idx < GetNumberOfValues() );
164 return Internal[idx];
167 return GetValue(idx);
170 assert( idx < GetNumberOfValues() );
174 assert( array && numel && numel == GetNumberOfValues() );
176 std::copy(array, array+numel, Internal);
185 std::ostringstream os;
188 GetNumberOfValues(),os);
189 ret.
SetVR( GetVR() );
190 assert( ret.
GetVR() != VR::SQ );
193 if( GetVR() != VR::UI )
195 if( os.str().size() % 2 )
208 assert(
Tag(Group,
Element) == de.
GetTag() || Group == 0x6000 || Group == 0x5000 );
209 assert( GetVR() != VR::INVALID );
210 assert( GetVR().Compatible( de.
GetVR() ) || de.
GetVR() == VR::INVALID );
213#ifdef GDCM_WORDS_BIGENDIAN
214 if( de.
GetVR() == VR::UN )
216 if( de.
GetVR() == VR::UN || de.
GetVR() == VR::INVALID )
223 SetByteValueNoSwap(bv);
247 std::stringstream ss;
251 GetNumberOfValues(),ss);
264 std::stringstream ss;
268 GetNumberOfValues(),ss);
273 void Read(std::istream &_is) {
274 const uint16_t cref[] = { Group,
Element };
276 _is.read((
char*)&c,
sizeof(c));
277 assert( c[0] == cref[0] && c[1] == cref[1] );
280 const uint32_t lref = GetLength() *
sizeof(
typename VRToType<TVR>::Type );
281 uint32_t l = VRVLSize< (TVR & VR::VL32) >::Read(_is);
282 l /=
sizeof(
typename VRToType<TVR>::Type );
283 return EncodingImplementation<VRToEncoding<TVR>::Mode>::Read(Internal,
286 void Write(std::ostream &_os)
const {
287 uint16_t c[] = { Group, Element };
288 _os.write((
char*)&c, 4);
289 uint32_t l = GetLength() *
sizeof(
typename VRToType<TVR>::Type );
290 _os.write((
char*)&l, 4);
291 return EncodingImplementation<VRToEncoding<TVR>::Mode>::Write(Internal,
294 void Read(std::istream &_is) {
295 uint16_t cref[] = { Group, Element };
297 _is.read((
char*)&c, 4);
298 const uint32_t lref = GetLength() *
sizeof(
typename VRToType<TVR>::Type );
300 _is.read((
char*)&l, 4);
301 l /=
sizeof(
typename VRToType<TVR>::Type );
302 return EncodingImplementation<VRToEncoding<TVR>::Mode>::Read(Internal,
305 void Write(std::ostream &_os)
const {
306 uint16_t c[] = { Group, Element };
307 _os.write((
char*)&c, 4);
308 uint32_t l = GetLength() *
sizeof(
typename VRToType<TVR>::Type );
309 _os.write((
char*)&l, 4);
310 return EncodingImplementation<VRToEncoding<TVR>::Mode>::Write(Internal,
317template<u
int16_t Group, u
int16_t Element,
long long TVR >
352 void Print(std::ostream &os)
const {
353 os << GetTag() <<
" ";
354 os << TagToType<Group,Element>::GetVRString() <<
" ";
355 os << TagToType<Group,Element>::GetVMString() <<
" ";
372 return std::equal(&Internal, &Internal+GetNumberOfValues(),
377 return !std::equal(&Internal, &Internal+GetNumberOfValues(),
382 return std::lexicographical_compare(&Internal, &Internal+GetNumberOfValues(),
420 std::ostringstream os;
423 GetNumberOfValues(),os);
424 ret.
SetVR( GetVR() );
425 assert( ret.
GetVR() != VR::SQ );
428 if( GetVR() != VR::UI )
430 if( os.str().size() % 2 )
443 assert(
Tag(Group,
Element) == de.
GetTag() || Group == 0x6000 || Group == 0x5000 );
444 assert( GetVR() != VR::INVALID );
445 assert( GetVR().Compatible( de.
GetVR() ) || de.
GetVR() == VR::INVALID );
448#ifdef GDCM_WORDS_BIGENDIAN
449 if( de.
GetVR() == VR::UN )
451 if( de.
GetVR() == VR::UN || de.
GetVR() == VR::INVALID )
458 SetByteValueNoSwap(bv);
482 std::stringstream ss;
486 GetNumberOfValues(),ss);
499 std::stringstream ss;
503 GetNumberOfValues(),ss);
508 void Read(std::istream &_is) {
509 const uint16_t cref[] = { Group,
Element };
511 _is.read((
char*)&c,
sizeof(c));
512 assert( c[0] == cref[0] && c[1] == cref[1] );
515 const uint32_t lref = GetLength() *
sizeof(
typename VRToType<TVR>::Type );
516 uint32_t l = VRVLSize< (TVR & VR::VL32) >::Read(_is);
517 l /=
sizeof(
typename VRToType<TVR>::Type );
518 return EncodingImplementation<VRToEncoding<TVR>::Mode>::Read(Internal,
521 void Write(std::ostream &_os)
const {
522 uint16_t c[] = { Group, Element };
523 _os.write((
char*)&c, 4);
524 uint32_t l = GetLength() *
sizeof(
typename VRToType<TVR>::Type );
525 _os.write((
char*)&l, 4);
526 return EncodingImplementation<VRToEncoding<TVR>::Mode>::Write(Internal,
529 void Read(std::istream &_is) {
530 uint16_t cref[] = { Group, Element };
532 _is.read((
char*)&c, 4);
533 const uint32_t lref = GetLength() *
sizeof(
typename VRToType<TVR>::Type );
535 _is.read((
char*)&l, 4);
536 l /=
sizeof(
typename VRToType<TVR>::Type );
537 return EncodingImplementation<VRToEncoding<TVR>::Mode>::Read(Internal,
540 void Write(std::ostream &_os)
const {
541 uint16_t c[] = { Group, Element };
542 _os.write((
char*)&c, 4);
543 uint32_t l = GetLength() *
sizeof(
typename VRToType<TVR>::Type );
544 _os.write((
char*)&l, 4);
545 return EncodingImplementation<VRToEncoding<TVR>::Mode>::Write(Internal,
554template<u
int16_t Group, u
int16_t Element,
long long TVR >
574 explicit Attribute() { Internal=
nullptr; Length=0; Own =
true; }
586 SetValues(
nullptr, numel,
true);
592 void Print(std::ostream &os)
const {
593 os << GetTag() <<
" ";
594 os << GetVR() <<
" ";
595 os << GetVM() <<
" ";
597 for(
unsigned int i=1; i<GetNumberOfValues(); ++i)
598 os <<
"," << Internal[i];
601 assert( idx < GetNumberOfValues() );
602 return Internal[idx];
605 return GetValue(idx);
609 assert( idx < GetNumberOfValues() );
610 return Internal[idx];
613 return GetValue(idx);
616 assert( idx < GetNumberOfValues() );
626 if( Own )
delete[] Internal;
631 assert( Internal ==
nullptr );
636 std::copy(array, array+numel, Internal);
640 Internal =
const_cast<ArrayType*
>(array);
643 assert( numel == GetNumberOfValues() );
648 std::ostringstream os;
652 GetNumberOfValues(),os);
655 if( GetVR() != VR::UI )
657 if( os.str().size() % 2 )
664 ret.
SetVR( GetVR() );
665 assert( ret.
GetVR() != VR::SQ );
672 assert( GetTag() == de.
GetTag() || GetTag().GetGroup() == 0x6000
673 || GetTag().GetGroup() == 0x5000 );
674 assert( GetVR().Compatible( de.
GetVR() ) );
692 std::stringstream ss;
707 SetValues( internal, Length,
true );
722template<u
int16_t Group, u
int16_t Element,
long long TVR>
729template<u
int16_t Group, u
int16_t Element,
long long TVR>
736template<u
int16_t Group, u
int16_t Element,
long long TVR>
743template<u
int16_t Group, u
int16_t Element,
long long TVR>
750template<u
int16_t Group, u
int16_t Element,
long long TVR>
757template<u
int16_t Group, u
int16_t Element,
long long TVR>
774 Attribute(
const char array[])
777 const char sep =
'\\';
778 std::string sarray = array;
779 std::string::size_type pos1 = 0;
780 std::string::size_type pos2 = sarray.find(sep, pos1+1);
781 while(pos2 != std::string::npos)
783 Internal[i++] = sarray.substr(pos1, pos2-pos1);
785 pos2 = sarray.find(sep, pos1+1);
787 Internal[i] = sarray.substr(pos1, pos2-pos1);
790 assert( GetLength()-1 == i );
793 unsigned long GetLength()
const {
794 return VMToLength<TVM>::Length;
797 void Print(std::ostream &_os)
const {
799 for(
int i=1; i<VMToLength<TVM>::Length; ++i)
800 _os <<
"," << Internal[i];
803 void Read(std::istream &_is) {
804 EncodingImplementation<VR::VRASCII>::Read(Internal, GetLength(),_is);
806 void Write(std::ostream &_os)
const {
807 EncodingImplementation<VR::VRASCII>::Write(Internal, GetLength(),_os);
810 typename String Internal[VMToLength<TVM>::Length];
814class Attribute<VR::PN, TVM> :
public StringAttribute<TVM>
827 explicit Attribute() { Internal=0; Length=0; }
836 unsigned long GetLength()
const {
return Length; }
837 typedef typename VRToType<TVR>::Type ArrayType;
838 void SetLength(
unsigned long len) {
839 const unsigned int size =
sizeof(ArrayType);
843 assert( (len / size) * size == len );
844 ArrayType *internal =
new ArrayType[len / size];
845 memcpy(internal, Internal, Length * size);
855 void SetArray(
const ArrayType *array,
unsigned long len,
859 memcpy(Internal, array, len);
869 void Print(std::ostream &_os)
const {
873 const unsigned long length = GetLength() < 25 ? GetLength() : 25;
874 for(
unsigned long i=1; i<length; ++i)
875 _os <<
"," << Internal[i];
877 void Read(std::istream &_is) {
878 EncodingImplementation<VRToEncoding<TVR>::Mode>::Read(Internal,
881 void Write(std::ostream &_os)
const {
882 EncodingImplementation<VRToEncoding<TVR>::Mode>::Write(Internal,
892 Attribute &operator=(
const Attribute &_val) {
895 SetArray(_val.Internal, _val.Length,
true);
900 typename VRToType<TVR>::Type *Internal;
901 unsigned long Length;
912 typedef Attribute<TVR, VM::VM1_n> Parent;
913 void SetLength(
int len) {
914 if( len <= 1 )
return;
915 Parent::SetLength(len);
922 typedef Attribute<TVR, VM::VM2_n> Parent;
923 void SetLength(
int len) {
924 if( len % 2 )
return;
925 Parent::SetLength(len);
932 typedef Attribute<TVR, VM::VM1_n> Parent;
933 void SetLength(
int len) {
934 if( len <= 2 )
return;
935 Parent::SetLength(len);
942 typedef Attribute<TVR, VM::VM3_n> Parent;
943 void SetLength(
int len) {
944 if( len % 3 )
return;
945 Parent::SetLength(len);
961 char Internal[VMToLength<VM::VM5>::Length];
962 void Print(std::ostream &_os)
const {
970template <
int TVM>
class Attribute<VR::OB, TVM>;
976template <
int TVM>
class Attribute<VR::OW, TVM>;
981class
Attribute<0x7fe0,0x0010, VR::OW, VM::VM1>
985 unsigned long Length;
987 void Print(std::ostream &_os)
const {
990 void SetBytes(
char *bytes,
unsigned long length) {
994 void Read(std::istream &_is) {
996 _is.read((
char*)&c, 4);
998 _is.read((
char*)&l, 4);
1000 _is.read( Internal, Length );
1002 void Write(std::ostream &_os)
const {
1003 uint16_t c[] = {0x7fe0, 0x0010};
1004 _os.write((
char*)&c, 4);
1005 _os.write((
char*)&Length, 4);
1006 _os.write( Internal, Length );
bool operator!=(const Attribute &att) const
Definition gdcmAttribute.h:375
const ArrayType * GetValues() const
Definition gdcmAttribute.h:413
VRToType< TVR >::Type ArrayType
Definition gdcmAttribute.h:321
static VR GetDictVR()
Definition gdcmAttribute.h:340
void SetValue(ArrayType v)
Definition gdcmAttribute.h:401
DataElement GetAsDataElement() const
Definition gdcmAttribute.h:418
GDCM_STATIC_ASSERT(((((VR::VRType) TVR &VR::VR_VM1) &&((VM::VMType) VM::VM1==VM::VM1))||!((VR::VRType) TVR &VR::VR_VM1)))
void SetFromDataSet(DataSet const &ds)
Definition gdcmAttribute.h:464
void Set(DataSet const &ds)
Definition gdcmAttribute.h:461
void SetFromDataElement(DataElement const &de)
Definition gdcmAttribute.h:441
static VM GetVM()
Definition gdcmAttribute.h:335
void SetByteValue(const ByteValue *bv)
Definition gdcmAttribute.h:489
ArrayType Internal
Definition gdcmAttribute.h:324
bool operator==(const Attribute &att) const
Definition gdcmAttribute.h:370
void SetByteValueNoSwap(const ByteValue *bv)
Definition gdcmAttribute.h:472
static Tag GetTag()
Definition gdcmAttribute.h:333
ArrayType const & GetValue() const
Definition gdcmAttribute.h:394
bool operator<(const Attribute &att) const
Definition gdcmAttribute.h:380
static VM GetDictVM()
Definition gdcmAttribute.h:341
GDCM_STATIC_ASSERT(((VM::VMType) VM::VM1 &(VM::VMType)(TagToType< Group, Element >::VMType)))
static VR GetVR()
Definition gdcmAttribute.h:334
GDCM_STATIC_ASSERT(VMToLength< VM::VM1 >::Length==1)
unsigned int GetNumberOfValues() const
Definition gdcmAttribute.h:346
void Print(std::ostream &os) const
Definition gdcmAttribute.h:352
GDCM_STATIC_ASSERT(((VR::VRType) TVR &(VR::VRType)(TagToType< Group, Element >::VRType)))
ArrayType & GetValue()
Definition gdcmAttribute.h:386
VM GetVM() const
Definition gdcmAttribute.h:726
VM GetVM() const
Definition gdcmAttribute.h:733
void SetValue(ArrayType v)
Definition gdcmAttribute.h:619
void Print(std::ostream &os) const
Definition gdcmAttribute.h:592
ArrayType const & GetValue(unsigned int idx=0) const
Definition gdcmAttribute.h:608
void SetFromDataSet(DataSet const &ds)
Definition gdcmAttribute.h:682
void Set(DataSet const &ds)
Definition gdcmAttribute.h:679
static VR GetVR()
Definition gdcmAttribute.h:567
GDCM_STATIC_ASSERT(((VR::VRType) TVR &(VR::VRType)(TagToType< Group, Element >::VRType)))
~Attribute()
Definition gdcmAttribute.h:575
static Tag GetTag()
Definition gdcmAttribute.h:566
GDCM_STATIC_ASSERT(((((VR::VRType) TVR &VR::VR_VM1) &&((VM::VMType) TagToType< Group, Element >::VMType==VM::VM1))||!((VR::VRType) TVR &VR::VR_VM1)))
unsigned int GetNumberOfValues() const
Definition gdcmAttribute.h:582
void SetNumberOfValues(unsigned int numel)
Definition gdcmAttribute.h:584
static VM GetDictVM()
Definition gdcmAttribute.h:571
DataElement GetAsDataElement() const
Definition gdcmAttribute.h:646
const ArrayType * GetValues() const
Definition gdcmAttribute.h:589
void SetValue(unsigned int idx, ArrayType v)
Definition gdcmAttribute.h:615
Attribute()
Definition gdcmAttribute.h:574
ArrayType & GetValue(unsigned int idx=0)
Definition gdcmAttribute.h:600
VRToType< TVR >::Type ArrayType
Definition gdcmAttribute.h:558
void SetByteValue(const ByteValue *bv)
Definition gdcmAttribute.h:690
GDCM_STATIC_ASSERT((VM::VM1_n &(VM::VMType)(TagToType< Group, Element >::VMType)))
static VR GetDictVR()
Definition gdcmAttribute.h:570
static VM GetVM()
Definition gdcmAttribute.h:568
void SetValues(const ArrayType *array, unsigned int numel, bool own=false)
Definition gdcmAttribute.h:621
void SetFromDataElement(DataElement const &de)
Definition gdcmAttribute.h:670
static VM GetVM()
Definition gdcmAttribute.h:747
VM GetVM() const
Definition gdcmAttribute.h:740
static VM GetVM()
Definition gdcmAttribute.h:761
static VM GetVM()
Definition gdcmAttribute.h:754
Attribute class This class use template metaprograming tricks to let the user know when the template ...
Definition gdcmAttribute.h:86
bool operator==(const Attribute &att) const
Definition gdcmAttribute.h:138
static VR GetVR()
Definition gdcmAttribute.h:99
void SetValue(ArrayType v, unsigned int idx=0)
Definition gdcmAttribute.h:169
const ArrayType * GetValues() const
Definition gdcmAttribute.h:178
void SetByteValue(const ByteValue *bv)
Definition gdcmAttribute.h:254
ArrayType const & GetValue(unsigned int idx=0) const
Definition gdcmAttribute.h:162
ArrayType & GetValue(unsigned int idx=0)
Definition gdcmAttribute.h:154
void SetValues(const ArrayType *array, unsigned int numel=VMType)
Definition gdcmAttribute.h:173
void Set(DataSet const &ds)
Definition gdcmAttribute.h:226
static VM GetVM()
Definition gdcmAttribute.h:100
static Tag GetTag()
Definition gdcmAttribute.h:98
static VR GetDictVR()
Definition gdcmAttribute.h:105
bool operator<(const Attribute &att) const
Definition gdcmAttribute.h:148
VRToType< TVR >::Type ArrayType
Definition gdcmAttribute.h:88
GDCM_STATIC_ASSERT(((VR::VRType) TVR &(VR::VRType)(TagToType< Group, Element >::VRType)))
GDCM_STATIC_ASSERT(((((VR::VRType) TVR &VR::VR_VM1) &&((VM::VMType) TVM==VM::VM1))||!((VR::VRType) TVR &VR::VR_VM1)))
void SetFromDataSet(DataSet const &ds)
Definition gdcmAttribute.h:229
bool operator!=(const Attribute &att) const
Definition gdcmAttribute.h:143
void SetFromDataElement(DataElement const &de)
Definition gdcmAttribute.h:206
DataElement GetAsDataElement() const
Definition gdcmAttribute.h:183
void SetByteValueNoSwap(const ByteValue *bv)
Definition gdcmAttribute.h:237
void Print(std::ostream &os) const
Definition gdcmAttribute.h:117
unsigned int GetNumberOfValues() const
Definition gdcmAttribute.h:111
static VM GetDictVM()
Definition gdcmAttribute.h:106
GDCM_STATIC_ASSERT(((VM::VMType) TVM &(VM::VMType)(TagToType< Group, Element >::VMType)))
Class to represent binary value (array of bytes)
Definition gdcmByteValue.h:35
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
const Tag & GetTag() const
Get Tag.
Definition gdcmDataElement.h:67
VR const & GetVR() const
Definition gdcmDataElement.h:84
const ByteValue * GetByteValue() const
Definition gdcmDataElement.h:133
bool IsEmpty() const
Check if Data Element is empty.
Definition gdcmDataElement.h:106
void SetByteValue(const char *array, VL length)
Definition gdcmDataElement.h:126
void SetVR(VR const &vr)
Definition gdcmDataElement.h:88
Class to represent a Data Set (which contains Data Elements)
Definition gdcmDataSet.h:56
const DataElement & GetDataElement(const Tag &t) const
Definition gdcmDataSet.h:188
bool FindDataElement(const PrivateTag &t) const
Look up if private tag 't' is present in the dataset:
Element class.
Definition gdcmElement.h:70
EncodingImplementation.
Definition gdcmElement.h:41
Class to represent a DICOM Data Element (Attribute) Tag (Group, Element).
Definition gdcmTag.h:39
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
static uint16_t Read(std::istream &_is)
Definition gdcmAttribute.h:41
static void Write(std::ostream &os)
Definition gdcmAttribute.h:47
static uint32_t Read(std::istream &_is)
Definition gdcmAttribute.h:53
static void Write(std::ostream &os)
Definition gdcmAttribute.h:62
Definition gdcmAttribute.h:36
VR class.
Definition gdcmVR.h:55
VRType
Definition gdcmVR.h:57
Attribute
Definition gdcmTerminal.h:49