MeVisLab Toolbox Reference
DCMTree::Tag Class Reference

Class to represent one DICOM tag. More...

#include <DCMTree_Tag.h>

Inheritance diagram for DCMTree::Tag:
DCMTree_Serialization::Serializable DCMTree_Serialization::Deserializable DCMTree::MFPixelTag DCMTree::PixelDataTag

Public Member Functions

 Tag ()
 Constructor. More...
 
 Tag (const TagInfo &info)
 Constructor info defines the data type, name, etc., of this tag. More...
 
 Tag (const Tag &other)
 Copy constructor that uses operator=. More...
 
 Tag (const Tag &other, unsigned short slot)
 Copy constructor for private tags with a given private slot. More...
 
 ~Tag () override
 Destructor. More...
 
Tagoperator= (const Tag &other)
 Deep copies all values from other to this. More...
 
bool operator== (const Tag &other) const
 Compares the tag with all contained values for equality. More...
 
bool operator!= (const Tag &other) const
 
bool isEqual (const Tag &other, double tolerance=0) const
 Compares the tag with all contained values for equality; use tolerance for float value comparison. More...
 
virtual TagPtr copy () const
 Makes a deep copy of this. More...
 
const TagInfoinfo () const
 Returns the tag information (type, etc.) of this tag. More...
 
const TreePtrVectorsequenceItems () const
 Accesses the probably embedded sequences of this tag. More...
 
TreePtrVectorsequenceItems ()
 Accesses the probably embedded sequences of this tag. More...
 
boost::uint32_t numberOfSequenceItems () const
 Returns the number of embedded sequence items of this tag. More...
 
void dropSequenceItems ()
 Drops all sequences of this tag. More...
 
void dropSequenceItem (unsigned idx)
 Drop the idx sequences of this tag. More...
 
virtual boost::uint32_t numberOfValues () const
 Returns the number of values of this tag. More...
 
void dropValues ()
 Drop all values of this tag. More...
 
bool isEmpty () const
 Returns true if this tag has no sequences and no values. More...
 
bool isSequence () const
 Returns true if the VR of this tag is SQ. More...
 
bool isNull (unsigned idx) const
 Checks whether the values with index idx is null. More...
 
bool isSequenceItemNull (unsigned idx) const
 Checks whether the sequence with index idx is null. More...
 
void setInfo (const TagInfo &info)
 Sets the tag info for this tag. More...
 
void addSequenceItem (const TreePtr &sequence)
 Adds the given TreePtr as a sequence to this tag. More...
 
TreePtraddSequenceItem ()
 Adds a sequence to this tag and returns a reference to it for further processing. More...
 
void setSequenceItem (const TreePtr &sequence, unsigned idx=0)
 Sets the sequence with index idx. More...
 
std::string toString (unsigned int idx, StringTrimMode trimMode=DO_NOT_TRIM) const
 Returns the value of tag value idx as a string. More...
 
std::string toString (StringTrimMode trimMode=DO_NOT_TRIM) const
 Converts the complete tag to a string. More...
 
void setValue (std::string value, unsigned int idx=0)
 Sets the value of tag value idx as string. More...
 
void addValue (std::string value)
 Converts string to one or more values and add them to this tag. More...
 
Date toDate (unsigned int idx=0) const
 Returns the value of tag value idx as date. More...
 
void setValue (Date value, unsigned int idx=0)
 Sets the value of tag value idx as date. More...
 
void addValue (Date value)
 Adds a value of this tag as date. More...
 
Time toTime (unsigned int idx=0) const
 Returns the value of tag value idx as time. More...
 
void setValue (Time value, unsigned int idx=0)
 Sets thevalue of tag value idx as time. More...
 
void addValue (Time value)
 Adds a value of this tag as time. More...
 
DateTime toDateTime (unsigned int idx=0) const
 Returns the value of tag value idx as datetime. More...
 
void setValue (DateTime value, unsigned int idx=0)
 Sets the value of tag value idx as datetime. More...
 
void addValue (DateTime value)
 Adds a value of this tag as datetime. More...
 
float toFloat (unsigned int idx=0) const
 Returns the value of tag value idx as float. More...
 
void setValue (float value, unsigned int idx=0)
 Sets the value of tag value idx as float. More...
 
void addValue (float value)
 Adds a value of this tag as float. More...
 
double toDouble (unsigned int idx=0) const
 Returns the value of tag value idx as double. More...
 
void setValue (double value, unsigned int idx=0)
 Sets the value of tag value idx as double. More...
 
void addValue (double value)
 Adds a value of this tag as double. More...
 
int toInt (unsigned int idx=0) const
 Returns the value of tag value idx as int. More...
 
void setValue (int value, unsigned int idx=0)
 Sets the value of tag value idx as int. More...
 
void addValue (int value)
 Adds a value of this tag as int. More...
 
unsigned int toUInt (unsigned int idx=0) const
 Returns the value of tag-value idx as unsigned int. More...
 
void setValue (unsigned int value, unsigned int idx=0)
 Sets the value of tag value idx as unsigned int. More...
 
void addValue (unsigned int value)
 Adds a value of this tag as unsigned int. More...
 
short int toShort (unsigned int idx=0) const
 Returns the value of tag value idx as short. More...
 
void setValue (short int value, unsigned int idx=0)
 Sets the value of tag value idx as short. More...
 
void addValue (short int value)
 Adds a value of this tag as short. More...
 
unsigned short toUShort (unsigned int idx=0) const
 Returns the value of tag value idx as unsigned short. More...
 
void setValue (unsigned short int value, unsigned int idx=0)
 Sets the value of tag value idx as unsigned short. More...
 
void addValue (unsigned short int value)
 Adds a value of this tag as unsigned short. More...
 
const ValuegetValue (unsigned int idx=0) const
 Returns the value object with index idx. More...
 
void setValue (const Value &value, unsigned int idx=0)
 Sets the value object with index idx. More...
 
virtual ValueaddValue ()
 Adds a value and return a reference for further processing. More...
 
virtual boost::uint32_t getValueSize (unsigned int idx) const
 Returns the size in bytes of the data of the value-object with index idx. More...
 
virtual boost::uint32_t getValueSize () const
 Returns the total size in bytes of the data of the values. More...
 
virtual void fromStream (std::istream &in, bool readName, size_t maxSize=0)
 Extracts this instance from the given stream. More...
 
virtual void toStream (std::ostream &out, bool writeName) const
 Copies this instance recursively into the given stream. More...
 
int compare (const Tag &tag, double tolerance=0.0001) const
 Compares this to tag and returns -1 if this < tag, 0 if this == tag, and 1 if this > tag. More...
 
void setVr (Vr vr)
 Sets a new value representation if the VR is unknown. More...
 
void serializeX (DCMTree_Serialization::Sink &sink) const override
 Writes data of this object to sink. More...
 
void deserializeX (DCMTree_Serialization::Source &source) override
 Overwrites data of this object with data from source. More...
 
- Public Member Functions inherited from DCMTree_Serialization::Serializable
virtual ~Serializable ()
 Empty. More...
 
- Public Member Functions inherited from DCMTree_Serialization::Deserializable
virtual ~Deserializable ()
 Empty. More...
 

Protected Member Functions

TagInfo const & tagInfo () const
 

Detailed Description

Class to represent one DICOM tag.

Definition at line 42 of file DCMTree_Tag.h.

Constructor & Destructor Documentation

◆ Tag() [1/4]

DCMTree::Tag::Tag ( )

Constructor.

◆ Tag() [2/4]

DCMTree::Tag::Tag ( const TagInfo info)

Constructor info defines the data type, name, etc., of this tag.

◆ Tag() [3/4]

DCMTree::Tag::Tag ( const Tag other)

Copy constructor that uses operator=.

◆ Tag() [4/4]

DCMTree::Tag::Tag ( const Tag other,
unsigned short  slot 
)

Copy constructor for private tags with a given private slot.

Parameters
slotA value between 0x10 and 0xFF that will be used as the upper byte in the tag element.

◆ ~Tag()

DCMTree::Tag::~Tag ( )
override

Destructor.

Member Function Documentation

◆ addSequenceItem() [1/2]

TreePtr& DCMTree::Tag::addSequenceItem ( )

Adds a sequence to this tag and returns a reference to it for further processing.

◆ addSequenceItem() [2/2]

void DCMTree::Tag::addSequenceItem ( const TreePtr sequence)

Adds the given TreePtr as a sequence to this tag.

The referenced Tree remains valid. Tag stores only the reference. If the referenced data is changed externally, this tag references the changes, too. If you need a dedicated copy, make one with Tree::copy! Shared pointers are to used to make it easier to edit/process sequences and to avoid copies

◆ addValue() [1/11]

virtual Value& DCMTree::Tag::addValue ( )
virtual

Adds a value and return a reference for further processing.

Be careful - no type checking!

◆ addValue() [2/11]

void DCMTree::Tag::addValue ( Date  value)

Adds a value of this tag as date.

Throws if type checking failed.

◆ addValue() [3/11]

void DCMTree::Tag::addValue ( DateTime  value)

Adds a value of this tag as datetime.

Throws if type checking failed.

◆ addValue() [4/11]

void DCMTree::Tag::addValue ( double  value)

Adds a value of this tag as double.

Throws if type checking failed.

◆ addValue() [5/11]

void DCMTree::Tag::addValue ( float  value)

Adds a value of this tag as float.

Throws if type checking failed.

◆ addValue() [6/11]

void DCMTree::Tag::addValue ( int  value)

Adds a value of this tag as int.

Throws if type checking failed.

◆ addValue() [7/11]

void DCMTree::Tag::addValue ( short int  value)

Adds a value of this tag as short.

Throws if type checking failed.

◆ addValue() [8/11]

void DCMTree::Tag::addValue ( std::string  value)

Converts string to one or more values and add them to this tag.

Throws if not convertible.

◆ addValue() [9/11]

void DCMTree::Tag::addValue ( Time  value)

Adds a value of this tag as time.

Throws if type checking failed.

◆ addValue() [10/11]

void DCMTree::Tag::addValue ( unsigned int  value)

Adds a value of this tag as unsigned int.

Throws if type checking failed.

◆ addValue() [11/11]

void DCMTree::Tag::addValue ( unsigned short int  value)

Adds a value of this tag as unsigned short.

Throws if type checking failed.

◆ compare()

int DCMTree::Tag::compare ( const Tag tag,
double  tolerance = 0.0001 
) const

Compares this to tag and returns -1 if this < tag, 0 if this == tag, and 1 if this > tag.

Comparison is performed value-by-value if both tags are numeric; otherwise, byte-by-byte. If one tag is numeric and the other is a string, this results in nonsense. tolerance specifies the relative difference that is still accepted for 'equal' result.

◆ copy()

virtual TagPtr DCMTree::Tag::copy ( ) const
virtual

Makes a deep copy of this.

Reimplemented in DCMTree::MFPixelTag.

◆ deserializeX()

void DCMTree::Tag::deserializeX ( DCMTree_Serialization::Source source)
overridevirtual

Overwrites data of this object with data from source.

All the rules stated for SCR::Serializable::serializeX apply correspondingly.

See also
SCR::Serializable::serializeX

Implements DCMTree_Serialization::Deserializable.

◆ dropSequenceItem()

void DCMTree::Tag::dropSequenceItem ( unsigned  idx)

Drop the idx sequences of this tag.

Throws if this tag tag is not of type SQ or the index is out of range.

◆ dropSequenceItems()

void DCMTree::Tag::dropSequenceItems ( )

Drops all sequences of this tag.

Does not check for SQ (if not SQ, you just drop nothing).

◆ dropValues()

void DCMTree::Tag::dropValues ( )

Drop all values of this tag.

Does not drop sequences! These are handled differently!

◆ fromStream()

virtual void DCMTree::Tag::fromStream ( std::istream &  in,
bool  readName,
size_t  maxSize = 0 
)
virtual

Extracts this instance from the given stream.

readName = true reads tag name(s) from stream, false assumes that no name(s) is/are in stream. maxSize > 0 will interrupt loops with further stream reading operations if maxSize is exceeded within the loop. IMPORTANT: This method is used for file format persistence; thus stream contents must be maintained compatible.

Referenced by DCMTree::operator>>().

◆ getValue()

const Value& DCMTree::Tag::getValue ( unsigned int  idx = 0) const

Returns the value object with index idx.

Throws if the index is out of range. Be careful - no type checking!

◆ getValueSize() [1/2]

virtual boost::uint32_t DCMTree::Tag::getValueSize ( ) const
virtual

Returns the total size in bytes of the data of the values.

Reimplemented in DCMTree::MFPixelTag.

◆ getValueSize() [2/2]

virtual boost::uint32_t DCMTree::Tag::getValueSize ( unsigned int  idx) const
virtual

Returns the size in bytes of the data of the value-object with index idx.

Throws if the index is out of range.

Reimplemented in DCMTree::MFPixelTag.

◆ info()

const TagInfo& DCMTree::Tag::info ( ) const

Returns the tag information (type, etc.) of this tag.

◆ isEmpty()

bool DCMTree::Tag::isEmpty ( ) const

Returns true if this tag has no sequences and no values.

◆ isEqual()

bool DCMTree::Tag::isEqual ( const Tag other,
double  tolerance = 0 
) const

Compares the tag with all contained values for equality; use tolerance for float value comparison.

◆ isNull()

bool DCMTree::Tag::isNull ( unsigned  idx) const

Checks whether the values with index idx is null.

Throws if the index is out of range.

◆ isSequence()

bool DCMTree::Tag::isSequence ( ) const

Returns true if the VR of this tag is SQ.

◆ isSequenceItemNull()

bool DCMTree::Tag::isSequenceItemNull ( unsigned  idx) const

Checks whether the sequence with index idx is null.

Throws if the index is out of range.

◆ numberOfSequenceItems()

boost::uint32_t DCMTree::Tag::numberOfSequenceItems ( ) const

Returns the number of embedded sequence items of this tag.

Does not check for SQ.

◆ numberOfValues()

virtual boost::uint32_t DCMTree::Tag::numberOfValues ( ) const
virtual

Returns the number of values of this tag.

Reimplemented in DCMTree::MFPixelTag.

◆ operator!=()

bool DCMTree::Tag::operator!= ( const Tag other) const

◆ operator=()

Tag& DCMTree::Tag::operator= ( const Tag other)

Deep copies all values from other to this.

Handles self assignment well.

◆ operator==()

bool DCMTree::Tag::operator== ( const Tag other) const

Compares the tag with all contained values for equality.

◆ sequenceItems() [1/2]

TreePtrVector& DCMTree::Tag::sequenceItems ( )

Accesses the probably embedded sequences of this tag.

Throws if this tag is not of type SQ!

◆ sequenceItems() [2/2]

const TreePtrVector& DCMTree::Tag::sequenceItems ( ) const

Accesses the probably embedded sequences of this tag.

Throws if this tag is not of type SQ!

◆ serializeX()

void DCMTree::Tag::serializeX ( DCMTree_Serialization::Sink sink) const
overridevirtual

Writes data of this object to sink.

Implementations of Serializable::serializeX should strictly follow this pattern:

class C: public SCR::Serializable { T1 _m1; T2 _m2; T3 _m3; public: void serializeX(SCR::Sink &sink) const { SCR::serializeX(sink, _m1); SCR::serializeX(sink, _m2); SCR::serializeX(sink, _m3); } };

That is, you should call some overloading of SCR::serializeX for every member.

If some of the types T1, T2, T3 are not serializable, you should make them serializable.

See also
SCR

Implements DCMTree_Serialization::Serializable.

◆ setInfo()

void DCMTree::Tag::setInfo ( const TagInfo info)

Sets the tag info for this tag.

Be careful if changing the VR!

◆ setSequenceItem()

void DCMTree::Tag::setSequenceItem ( const TreePtr sequence,
unsigned  idx = 0 
)

Sets the sequence with index idx.

Same as addSequenceItem. Throws if the index is out of range.

◆ setValue() [1/11]

void DCMTree::Tag::setValue ( const Value value,
unsigned int  idx = 0 
)

Sets the value object with index idx.

Throws if the index is out of range. Be careful - no type checking!

◆ setValue() [2/11]

void DCMTree::Tag::setValue ( Date  value,
unsigned int  idx = 0 
)

Sets the value of tag value idx as date.

Throws if type checking failed. Throws if the index is out of range.

◆ setValue() [3/11]

void DCMTree::Tag::setValue ( DateTime  value,
unsigned int  idx = 0 
)

Sets the value of tag value idx as datetime.

Throws if type checking failed. Throws if the index is out of range.

◆ setValue() [4/11]

void DCMTree::Tag::setValue ( double  value,
unsigned int  idx = 0 
)

Sets the value of tag value idx as double.

Throws if type checking failed. Throws if the index is out of range.

◆ setValue() [5/11]

void DCMTree::Tag::setValue ( float  value,
unsigned int  idx = 0 
)

Sets the value of tag value idx as float.

Throws if type checking failed. Throws if the index is out of range.

◆ setValue() [6/11]

void DCMTree::Tag::setValue ( int  value,
unsigned int  idx = 0 
)

Sets the value of tag value idx as int.

Throws if type checking failed. Throws if the index is out of range.

◆ setValue() [7/11]

void DCMTree::Tag::setValue ( short int  value,
unsigned int  idx = 0 
)

Sets the value of tag value idx as short.

Throws if type checking failed. Throws if the index is out of range.

◆ setValue() [8/11]

void DCMTree::Tag::setValue ( std::string  value,
unsigned int  idx = 0 
)

Sets the value of tag value idx as string.

Throws if type checking failed. Throws if the index is out of range.

◆ setValue() [9/11]

void DCMTree::Tag::setValue ( Time  value,
unsigned int  idx = 0 
)

Sets thevalue of tag value idx as time.

Throws if type checking failed. Throws if the index is out of range.

◆ setValue() [10/11]

void DCMTree::Tag::setValue ( unsigned int  value,
unsigned int  idx = 0 
)

Sets the value of tag value idx as unsigned int.

Throws if type checking failed. Throws if the index is out of range.

◆ setValue() [11/11]

void DCMTree::Tag::setValue ( unsigned short int  value,
unsigned int  idx = 0 
)

Sets the value of tag value idx as unsigned short.

Throws if type checking failed. Throws if the index is out of range.

◆ setVr()

void DCMTree::Tag::setVr ( Vr  vr)

Sets a new value representation if the VR is unknown.

This is needed mainly for private tags with unknown VR, or can be used for still unsupported tags. The new VR is set only if the current VR is unknown, and the existing value is converted to the new VR. This may also mean that the number of values changes.

◆ tagInfo()

TagInfo const& DCMTree::Tag::tagInfo ( ) const
inlineprotected

Definition at line 465 of file DCMTree_Tag.h.

◆ toDate()

Date DCMTree::Tag::toDate ( unsigned int  idx = 0) const

Returns the value of tag value idx as date.

Throws if type checking failed. Throws if the index is out of range.

◆ toDateTime()

DateTime DCMTree::Tag::toDateTime ( unsigned int  idx = 0) const

Returns the value of tag value idx as datetime.

Throws if type checking failed. Throws if the index is out of range.

◆ toDouble()

double DCMTree::Tag::toDouble ( unsigned int  idx = 0) const

Returns the value of tag value idx as double.

Throws if type checking failed. Throws if the index is out of range.

◆ toFloat()

float DCMTree::Tag::toFloat ( unsigned int  idx = 0) const

Returns the value of tag value idx as float.

Throws if type checking failed. Throws if the index is out of range.

◆ toInt()

int DCMTree::Tag::toInt ( unsigned int  idx = 0) const

Returns the value of tag value idx as int.

Throws if type checking failed. Throws if the index is out of range.

◆ toShort()

short int DCMTree::Tag::toShort ( unsigned int  idx = 0) const

Returns the value of tag value idx as short.

Throws if type checking failed. Throws if the index is out of range.

◆ toStream()

virtual void DCMTree::Tag::toStream ( std::ostream &  out,
bool  writeName 
) const
virtual

Copies this instance recursively into the given stream.

writeName = true writes tag name(s) to stream, false writes no name(s) into stream. IMPORTANT: This method is used for file format persistence; thus stream contents must be maintained compatible.

Referenced by DCMTree::operator<<().

◆ toString() [1/2]

std::string DCMTree::Tag::toString ( StringTrimMode  trimMode = DO_NOT_TRIM) const

Converts the complete tag to a string.

That means that all values are concatenated by a backslash and converted to a string. Throws if not convertible. trimMode offers the possibility to trim leading and trailing spaces.

◆ toString() [2/2]

std::string DCMTree::Tag::toString ( unsigned int  idx,
StringTrimMode  trimMode = DO_NOT_TRIM 
) const

Returns the value of tag value idx as a string.

Throws if type checking failed. Throws if the index is out of range. trimMode offers the possibility to trim leading and trailing spaces.

◆ toTime()

Time DCMTree::Tag::toTime ( unsigned int  idx = 0) const

Returns the value of tag value idx as time.

Throws if type checking failed. Throws if the index is out of range.

◆ toUInt()

unsigned int DCMTree::Tag::toUInt ( unsigned int  idx = 0) const

Returns the value of tag-value idx as unsigned int.

Throws if type-checking failed. Throws if the index is out of range.

◆ toUShort()

unsigned short DCMTree::Tag::toUShort ( unsigned int  idx = 0) const

Returns the value of tag value idx as unsigned short.

Throws if type checking failed. Throws if the index is out of range.


The documentation for this class was generated from the following file: