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;
81 template<uint16_t Group, uint16_t Element,
82 int 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];
158 ArrayType & operator[] (
unsigned int idx) {
159 return GetValue(idx);
162 ArrayType
const &
GetValue(
unsigned int idx = 0)
const {
163 assert( idx < GetNumberOfValues() );
164 return Internal[idx];
166 ArrayType
const & operator[] (
unsigned int idx)
const {
167 return GetValue(idx);
170 assert( idx < GetNumberOfValues() );
173 void SetValues(
const ArrayType* array,
unsigned int numel = VMType ) {
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( GetTag() == de.
GetTag() || GetTag().
GetGroup() == 0x6000 || GetTag().GetGroup() == 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);
271 #if 0 // TODO FIXME the implicit way:
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 );
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);
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 );
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);
317 template<u
int16_t Group, u
int16_t Element,
int 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( GetTag() == de.
GetTag() || GetTag().
GetGroup() == 0x6000 || GetTag().GetGroup() == 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);
506 #if 0 // TODO FIXME the implicit way:
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 );
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);
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 );
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);
554 template<u
int16_t Group, u
int16_t Element,
int TVR >
574 explicit Attribute() { Internal=0; Length=0; Own =
true; }
586 SetValues(NULL, 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];
604 ArrayType &operator[] (
unsigned int idx) {
605 return GetValue(idx);
608 ArrayType
const &
GetValue(
unsigned int idx = 0)
const {
609 assert( idx < GetNumberOfValues() );
610 return Internal[idx];
612 ArrayType
const & operator[] (
unsigned int idx)
const {
613 return GetValue(idx);
616 assert( idx < GetNumberOfValues() );
621 void SetValues(
const ArrayType *array,
unsigned int numel,
bool own =
false)
626 if( Own )
delete[] Internal;
631 assert( Internal == 0 );
635 Internal =
new ArrayType[numel];
637 std::copy(array, array+numel, Internal);
641 Internal =
const_cast<ArrayType*
>(array);
644 assert( numel == GetNumberOfValues() );
649 std::ostringstream os;
653 GetNumberOfValues(),os);
656 if( GetVR() != VR::UI )
658 if( os.str().size() % 2 )
665 ret.
SetVR( GetVR() );
666 assert( ret.
GetVR() != VR::SQ );
674 || GetTag().GetGroup() == 0x5000 );
675 assert( GetVR().Compatible( de.
GetVR() ) );
693 std::stringstream ss;
698 ArrayType buffer[256];
708 SetValues(
internal, Length,
true );
723 template<u
int16_t Group, u
int16_t Element,
int TVR>
730 template<u
int16_t Group, u
int16_t Element,
int TVR>
737 template<u
int16_t Group, u
int16_t Element,
int TVR>
744 template<u
int16_t Group, u
int16_t Element,
int TVR>
751 template<u
int16_t Group, u
int16_t Element,
int TVR>
758 template<u
int16_t Group, u
int16_t Element,
int TVR>
778 const char sep =
'\\';
779 std::string sarray = array;
780 std::string::size_type pos1 = 0;
781 std::string::size_type pos2 = sarray.find(sep, pos1+1);
782 while(pos2 != std::string::npos)
784 Internal[i++] = sarray.substr(pos1, pos2-pos1);
786 pos2 = sarray.find(sep, pos1+1);
788 Internal[i] = sarray.substr(pos1, pos2-pos1);
791 assert( GetLength()-1 == i );
794 unsigned long GetLength()
const {
795 return VMToLength<TVM>::Length;
798 void Print(std::ostream &_os)
const {
800 for(
int i=1; i<VMToLength<TVM>::Length; ++i)
801 _os <<
"," << Internal[i];
804 void Read(std::istream &_is) {
805 EncodingImplementation<VR::VRASCII>::Read(Internal, GetLength(),_is);
807 void Write(std::ostream &_os)
const {
808 EncodingImplementation<VR::VRASCII>::Write(Internal, GetLength(),_os);
811 typename String Internal[VMToLength<TVM>::Length];
815 class Attribute<VR::PN, TVM> :
public StringAttribute<TVM>
828 explicit Attribute() { Internal=0; Length=0; }
837 unsigned long GetLength()
const {
return Length; }
838 typedef typename VRToType<TVR>::Type ArrayType;
839 void SetLength(
unsigned long len) {
840 const unsigned int size =
sizeof(ArrayType);
844 assert( (len / size) * size == len );
845 ArrayType *
internal =
new ArrayType[len / size];
846 memcpy(
internal, Internal, Length * size);
856 void SetArray(
const ArrayType *array,
unsigned long len,
860 memcpy(Internal, array, len);
870 void Print(std::ostream &_os)
const {
874 const unsigned long length = GetLength() < 25 ? GetLength() : 25;
875 for(
unsigned long i=1; i<length; ++i)
876 _os <<
"," << Internal[i];
878 void Read(std::istream &_is) {
882 void Write(std::ostream &_os)
const {
896 SetArray(_val.Internal, _val.Length,
true);
901 typename VRToType<TVR>::Type *Internal;
902 unsigned long Length;
913 typedef Attribute<TVR, VM::VM1_n> Parent;
914 void SetLength(
int len) {
915 if( len <= 1 )
return;
916 Parent::SetLength(len);
923 typedef Attribute<TVR, VM::VM2_n> Parent;
924 void SetLength(
int len) {
925 if( len % 2 )
return;
926 Parent::SetLength(len);
933 typedef Attribute<TVR, VM::VM1_n> Parent;
934 void SetLength(
int len) {
935 if( len <= 2 )
return;
936 Parent::SetLength(len);
943 typedef Attribute<TVR, VM::VM3_n> Parent;
944 void SetLength(
int len) {
945 if( len % 3 )
return;
946 Parent::SetLength(len);
962 char Internal[VMToLength<VM::VM5>::Length];
963 void Print(std::ostream &_os)
const {
971 template <
int TVM>
class Attribute<VR::OB, TVM>;
977 template <
int TVM>
class Attribute<VR::OW, TVM>;
982 class
Attribute<0x7fe0,0x0010, VR::OW, VM::VM1>
986 unsigned long Length;
988 void Print(std::ostream &_os)
const {
991 void SetBytes(
char *bytes,
unsigned long length) {
995 void Read(std::istream &_is) {
997 _is.read((
char*)&c, 4);
999 _is.read((
char*)&l, 4);
1001 _is.read( Internal, Length );
1003 void Write(std::ostream &_os)
const {
1004 uint16_t c[] = {0x7fe0, 0x0010};
1005 _os.write((
char*)&c, 4);
1006 _os.write((
char*)&Length, 4);
1007 _os.write( Internal, Length );
1050 #endif //GDCMATTRIBUTE_H
void Set(DataSet const &ds)
Definition: gdcmAttribute.h:461
void SetVR(VR const &vr)
Definition: gdcmDataElement.h:88
static VR GetDictVR()
Definition: gdcmAttribute.h:105
void SetByteValue(const ByteValue *bv)
Definition: gdcmAttribute.h:489
const ArrayType * GetValues() const
Definition: gdcmAttribute.h:413
static VR GetVR()
Definition: gdcmAttribute.h:99
bool IsEmpty() const
Check if Data Element is empty.
Definition: gdcmDataElement.h:103
Class to represent a Data Set (which contains Data Elements) A Data Set represents an instance of a r...
Definition: gdcmDataSet.h:55
void Set(DataSet const &ds)
Definition: gdcmAttribute.h:680
static Tag GetTag()
Definition: gdcmAttribute.h:566
void Print(std::ostream &os) const
Definition: gdcmAttribute.h:117
static VR GetDictVR()
Definition: gdcmAttribute.h:570
static void Write(std::ostream &os)
Definition: gdcmAttribute.h:62
bool operator==(const Attribute &att) const
Definition: gdcmAttribute.h:370
bool FindDataElement(const PrivateTag &t) const
Look up if private tag 't' is present in the dataset:
void SetByteValue(const char *array, VL length)
Definition: gdcmDataElement.h:123
VM GetVM() const
Definition: gdcmAttribute.h:734
void SetValue(ArrayType v)
Definition: gdcmAttribute.h:619
bool operator!=(const Attribute &att) const
Definition: gdcmAttribute.h:375
VRType
Definition: gdcmVR.h:57
static VM GetDictVM()
Definition: gdcmAttribute.h:341
const DataElement & GetDataElement(const Tag &t) const
Definition: gdcmDataSet.h:178
static VM GetVM()
Definition: gdcmAttribute.h:100
const ArrayType * GetValues() const
Definition: gdcmAttribute.h:589
bool operator<(const Attribute &att) const
Definition: gdcmAttribute.h:148
void SetByteValueNoSwap(const ByteValue *bv)
Definition: gdcmAttribute.h:472
DataElement GetAsDataElement() const
Definition: gdcmAttribute.h:183
void SetValue(ArrayType v, unsigned int idx=0)
Definition: gdcmAttribute.h:169
static Tag GetTag()
Definition: gdcmAttribute.h:333
VRToType< TVR >::Type ArrayType
Definition: gdcmAttribute.h:88
VL GetLength() const
Definition: gdcmByteValue.h:78
VM GetVM() const
Definition: gdcmAttribute.h:741
void SetByteValue(const ByteValue *bv)
Definition: gdcmAttribute.h:254
DataElement GetAsDataElement() const
Definition: gdcmAttribute.h:647
ArrayType const & GetValue() const
Definition: gdcmAttribute.h:394
#define GDCM_STATIC_ASSERT(B)
The GDCM_JOIN + LINE is needed to create a uniq identifier.
Definition: gdcmStaticAssert.h:36
DataElement GetAsDataElement() const
Definition: gdcmAttribute.h:418
ArrayType Internal
Definition: gdcmAttribute.h:324
void SetNumberOfValues(unsigned int numel)
Definition: gdcmAttribute.h:584
static VM GetVM()
Definition: gdcmAttribute.h:762
const ByteValue * GetByteValue() const
Definition: gdcmDataElement.h:130
void SetValue(unsigned int idx, ArrayType v)
Definition: gdcmAttribute.h:615
static Tag GetTag()
Definition: gdcmAttribute.h:98
static VM GetVM()
Definition: gdcmAttribute.h:335
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
~Attribute()
Definition: gdcmAttribute.h:575
ArrayType const & GetValue(unsigned int idx=0) const
Definition: gdcmAttribute.h:162
void Set(DataSet const &ds)
Definition: gdcmAttribute.h:226
ArrayType & GetValue(unsigned int idx=0)
Definition: gdcmAttribute.h:600
const ArrayType * GetValues() const
Definition: gdcmAttribute.h:178
bool operator!=(const Attribute &att) const
Definition: gdcmAttribute.h:143
Attribute()
Definition: gdcmAttribute.h:574
VR const & GetVR() const
Definition: gdcmDataElement.h:84
void SetValues(const ArrayType *array, unsigned int numel, bool own=false)
Definition: gdcmAttribute.h:621
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 VM GetVM()
Definition: gdcmAttribute.h:755
void Print(std::ostream &os) const
Definition: gdcmAttribute.h:592
static void Write(std::ostream &os)
Definition: gdcmAttribute.h:47
VRToType< TVR >::Type ArrayType
Definition: gdcmAttribute.h:321
void Print(std::ostream &os) const
Definition: gdcmAttribute.h:352
Attribute class This class use template metaprograming tricks to let the user know when the template ...
Definition: gdcmAttribute.h:85
void SetFromDataElement(DataElement const &de)
Definition: gdcmAttribute.h:441
void SetFromDataSet(DataSet const &ds)
Definition: gdcmAttribute.h:683
static uint32_t Read(std::istream &_is)
Definition: gdcmAttribute.h:53
void SetFromDataElement(DataElement const &de)
Definition: gdcmAttribute.h:671
unsigned int GetNumberOfValues() const
Definition: gdcmAttribute.h:111
void SetByteValueNoSwap(const ByteValue *bv)
Definition: gdcmAttribute.h:237
void SetFromDataSet(DataSet const &ds)
Definition: gdcmAttribute.h:464
Attribute
Definition: gdcmTerminal.h:48
void SetByteValue(const ByteValue *bv)
Definition: gdcmAttribute.h:691
static VM GetDictVM()
Definition: gdcmAttribute.h:106
ArrayType & GetValue()
Definition: gdcmAttribute.h:386
static VR GetVR()
Definition: gdcmAttribute.h:334
const Tag & GetTag() const
Get Tag.
Definition: gdcmDataElement.h:67
unsigned int GetNumberOfValues() const
Definition: gdcmAttribute.h:346
static VM GetVM()
Definition: gdcmAttribute.h:568
static VR GetDictVR()
Definition: gdcmAttribute.h:340
void SetFromDataSet(DataSet const &ds)
Definition: gdcmAttribute.h:229
void SetFromDataElement(DataElement const &de)
Definition: gdcmAttribute.h:206
ArrayType & GetValue(unsigned int idx=0)
Definition: gdcmAttribute.h:154
EncodingImplementation.
Definition: gdcmElement.h:41
void SetValues(const ArrayType *array, unsigned int numel=VMType)
Definition: gdcmAttribute.h:173
const char * GetPointer() const
Definition: gdcmByteValue.h:111
bool operator==(const Attribute &att) const
Definition: gdcmAttribute.h:138
unsigned int GetNumberOfValues() const
Definition: gdcmAttribute.h:582
bool operator<(const Attribute &att) const
Definition: gdcmAttribute.h:380
static uint16_t Read(std::istream &_is)
Definition: gdcmAttribute.h:41
Class to represent a DICOM Data Element (Attribute) Tag (Group, Element). Basically an uint32_t which...
Definition: gdcmTag.h:38
void SetValue(ArrayType v)
Definition: gdcmAttribute.h:401
static VM GetDictVM()
Definition: gdcmAttribute.h:571
uint16_t GetGroup() const
Returns the 'Group number' of the given Tag.
Definition: gdcmTag.h:55
VRToType< TVR >::Type ArrayType
Definition: gdcmAttribute.h:558
static VM GetVM()
Definition: gdcmAttribute.h:748
Mode
Definition: gdcmTerminal.h:32
VR class This is adapted from DICOM standard The biggest difference is the INVALID VR and the composi...
Definition: gdcmVR.h:54
VM GetVM() const
Definition: gdcmAttribute.h:727
VMType
Definition: gdcmVM.h:70
Definition: gdcmAttribute.h:36
ArrayType const & GetValue(unsigned int idx=0) const
Definition: gdcmAttribute.h:608
static VR GetVR()
Definition: gdcmAttribute.h:567
uint32_t Type
Definition: gdcmVL.h:32