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 {
119 os << TagToType<Group,Element>::GetVRString() <<
" ";
120 os << TagToType<Group,Element>::GetVMString() <<
" ";
123 os <<
"," << Internal[i];
176 std::copy(array, array+numel,
Internal);
185 std::ostringstream os;
195 if( os.str().size() % 2 )
213 #ifdef GDCM_WORDS_BIGENDIAN
247 std::stringstream ss;
264 std::stringstream 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 {
354 os << TagToType<Group,Element>::GetVRString() <<
" ";
355 os << TagToType<Group,Element>::GetVMString() <<
" ";
420 std::ostringstream os;
430 if( os.str().size() % 2 )
448 #ifdef GDCM_WORDS_BIGENDIAN
482 std::stringstream ss;
499 std::stringstream 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 >
592 void Print(std::ostream &os)
const {
594 os <<
GetVR() <<
" ";
595 os <<
GetVM() <<
" ";
598 os <<
"," << Internal[i];
637 std::copy(array, array+numel,
Internal);
649 std::ostringstream os;
658 if( os.str().size() % 2 )
693 std::stringstream ss;
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) {
807 void Write(std::ostream &_os)
const {
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 );
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:
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
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
ArrayType Internal[VMToLength< TVM >::Length]
Definition: gdcmAttribute.h:90
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:76
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
DataElement GetAsDataElement() const
Definition: gdcmAttribute.h:418
ArrayType Internal
Definition: gdcmAttribute.h:324
Definition: gdcmAttribute.h:89
Element class.
Definition: gdcmElement.h:69
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
GDCM_STATIC_ASSERT(((VR::VRType) TVR &(VR::VRType)(TagToType< Group, Element >::VRType)))
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:33
~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
static void Write(const T *data, unsigned long length, std::ostream &_os)
Definition: gdcmElement.h:253
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
ArrayType & operator[](unsigned int idx)
Definition: gdcmAttribute.h:158
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:138
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