MeVisLab Toolbox Reference
DCMTree_Tag.h
Go to the documentation of this file.
1 /*************************************************************************************
2 **
3 ** Copyright 2007, MeVis Medical Solutions AG
4 **
5 ** The user may use this file in accordance with the license agreement provided with
6 ** the Software or, alternatively, in accordance with the terms contained in a
7 ** written agreement between the user and MeVis Medical Solutions AG.
8 **
9 ** For further information use the contact form at https://www.mevislab.de/contact
10 **
11 **************************************************************************************/
12 
13 #ifndef DCM_TREE_TAG_H
14 #define DCM_TREE_TAG_H
15 
16 #include "DCMTree_Lib.h"
17 #include "DCMTree_TagInfo.h"
18 #include "DCMTree_Value.h"
19 #include "DCMTree_Defines.h"
20 
21 #ifdef _MSC_VER
22  // 4350: behaviour change
23  // 4365: signed/unsigned mismatch
24  // 4548: expression before comma has no effect; expected expression with side-effect
25  #pragma warning (push)
26  #pragma warning (disable : 4350 4365 4548)
27 #endif
28 
29 #include <istream>
30 #include <ostream>
31 #include <fstream>
32 
33 #ifdef _MSC_VER
34  #pragma warning (pop)
35 #endif
36 
37 namespace DCMTree
38 {
40 
43  {
44  public:
46  Tag();
47 
52  Tag(const TagInfo &info);
53 
55  Tag(const Tag &other);
56 
60  Tag(const Tag &other, unsigned short slot);
61 
63  ~Tag() override;
64 
69  Tag &operator=(const Tag &other);
70 
75  bool operator==( const Tag& other ) const;
76  bool operator!=( const Tag& other ) const;
77 
82  bool isEqual( const Tag& other, double tolerance = 0 ) const;
83 
87  virtual TagPtr copy() const;
88 
92  const TagInfo &info() const;
93 
98  const TreePtrVector &sequenceItems() const;
99 
105 
110  boost::uint32_t numberOfSequenceItems() const;
111 
117 
122  void dropSequenceItem(unsigned idx);
123 
127  virtual boost::uint32_t numberOfValues() const;
128 
134  void dropValues();
135 
139  bool isEmpty() const;
140 
144  bool isSequence() const;
145 
150  bool isNull (unsigned idx) const;
151 
156  bool isSequenceItemNull (unsigned idx) const;
157 
162  void setInfo (const TagInfo &info);
163 
173  void addSequenceItem (const TreePtr &sequence);
174 
179 
185  void setSequenceItem (const TreePtr &sequence,unsigned idx=0);
186 
193  std::string toString (unsigned int idx, StringTrimMode trimMode = DO_NOT_TRIM) const;
194 
202  std::string toString(StringTrimMode trimMode = DO_NOT_TRIM) const;
203 
209  void setValue (std::string value,unsigned int idx=0);
210 
215  void addValue (std::string value);
216 
222  Date toDate (unsigned int idx=0) const;
223 
229  void setValue (Date value,unsigned int idx=0);
230 
235  void addValue (Date value);
236 
242  Time toTime (unsigned int idx=0) const;
243 
249  void setValue (Time value,unsigned int idx=0);
250 
255  void addValue (Time value);
256 
262  DateTime toDateTime (unsigned int idx=0) const;
263 
269  void setValue (DateTime value,unsigned int idx=0);
270 
275  void addValue (DateTime value);
276 
282  float toFloat (unsigned int idx=0) const;
283 
289  void setValue (float value,unsigned int idx=0);
290 
295  void addValue (float value);
296 
302  double toDouble (unsigned int idx=0) const;
303 
309  void setValue (double value,unsigned int idx=0);
310 
315  void addValue (double value);
316 
322  int toInt (unsigned int idx=0) const;
323 
329  void setValue (int value,unsigned int idx=0);
330 
335  void addValue (int value);
336 
342  unsigned int toUInt (unsigned int idx=0) const;
343 
349  void setValue (unsigned int value,unsigned int idx=0);
350 
355  void addValue (unsigned int value);
356 
362  short int toShort (unsigned int idx=0) const;
363 
369  void setValue (short int value,unsigned int idx=0);
370 
375  void addValue (short int value);
376 
382  unsigned short toUShort (unsigned int idx=0) const;
383 
389  void setValue (unsigned short int value,unsigned int idx=0);
390 
395  void addValue (unsigned short int value);
396 
402  const Value &getValue (unsigned int idx=0) const;
403 
409  void setValue (const Value &value,unsigned int idx=0);
410 
415  virtual Value &addValue();
416 
421  virtual boost::uint32_t getValueSize (unsigned int idx) const;
422 
426  virtual boost::uint32_t getValueSize () const;
427 
433  virtual void fromStream (std::istream &in, bool readName);
434 
440  virtual void toStream (std::ostream &out, bool writeName) const;
441 
450  int compare(const Tag& tag, double tolerance = 0.0001) const;
451 
459  void setVr( Vr vr );
460 
461  void serializeX (DCMTree_Serialization::Sink &sink) const override;
463 
464  protected:
465  TagInfo const & tagInfo() const { return _info; }
466 
467  private:
474  int compareNumerical(const Tag& tag, int nMin, double tolerance) const;
475 
482  int compareBytes(const Tag& tag, int nMin) const;
483 
487  void typeAndRangeChecking (const VRCType &vrctype,const unsigned int &idx) const;
488 
492  void typeChecking (const VRCType &vrctype) const;
493 
497  bool isOfType(const VRCType &vrctype) const;
498 
502  void rangeChecking (const unsigned int &idx) const;
503 
507  void sequenceRangeChecking (const unsigned int &idx) const;
508 
509  TagInfo _info;
510  ValueVector _values;
511  TreePtrVector _sequences;
512  };
513 
514  inline std::ostream &operator << (std::ostream &out,const Tag &t)
515  {
516  t.toStream (out, false);
517  return out;
518  }
519 
520  inline std::istream &operator >> (std::istream &in,Tag &t)
521  {
522  t.fromStream (in, false);
523  return in;
524  }
525 }
526 
527 #endif
528 
529 
530 
#define DCMTREE_EXPORT
Class to carry meta-information about a specific tag.
Class to represent one dicom tag.
Definition: DCMTree_Tag.h:43
double toDouble(unsigned int idx=0) const
get the value of tag-value idx as double throws if type-checking failed throws if the index is out of...
virtual Value & addValue()
add a value and return a reference for further processing be careful - no type checking !
bool isEqual(const Tag &other, double tolerance=0) const
compare the tag with all contained values for equality; use tolerance for float value comparison
int toInt(unsigned int idx=0) const
get the value of tag-value idx as int throws if type-checking failed throws if the index is out of ra...
DateTime toDateTime(unsigned int idx=0) const
get the value of tag-value idx as datetime throws if type-checking failed throws if the index is out ...
bool operator==(const Tag &other) const
compare the tag with all contained values for equality
void setValue(std::string value, unsigned int idx=0)
set the value of tag-value idx as string throws if type-checking failed throws if the index is out of...
void serializeX(DCMTree_Serialization::Sink &sink) const override
Writes data of this object to Sink.
bool operator!=(const Tag &other) const
void addValue(float value)
add a value of this tag as float throws if type-checking failed
virtual boost::uint32_t numberOfValues() const
get the number of values of this tag
void addValue(std::string value)
convert string to one or more values and add them to this tag throws if not convertible
~Tag() override
dtor
void addValue(Date value)
add a value of this tag as date throws if type-checking failed
Tag(const Tag &other)
copy ctor - uses operator=
void addSequenceItem(const TreePtr &sequence)
add the given TreePtr as sequence to this tag the referenced Tree remains valid tag stores only the r...
void addValue(DateTime value)
add a value of this tag as datetime throws if type-checking failed
virtual void fromStream(std::istream &in, bool readName)
extract this instance from the given stream readName = true reads tag name(s) from stream,...
void addValue(Time value)
add a value of this tag as time throws if type-checking failed
bool isEmpty() const
return true if this tag has no sequences and no values
unsigned short toUShort(unsigned int idx=0) const
get the value of tag-value idx as unsigned short throws if type-checking failed throws if the index i...
void deserializeX(DCMTree_Serialization::Source &source) override
Overwrites data of this object with data from Source.
void setSequenceItem(const TreePtr &sequence, unsigned idx=0)
set the sequence with index idx same as addSequenceItem throws if the index is out of range
virtual TagPtr copy() const
make a deep-copy of this
void setValue(short int value, unsigned int idx=0)
set the value of tag-value idx as short throws if type-checking failed throws if the index is out of ...
void addValue(short int value)
add a value of this tag as short throws if type-checking failed
void addValue(double value)
add a value of this tag as double throws if type-checking failed
bool isSequence() const
return true if the vr of this tag is SQ
void setValue(DateTime value, unsigned int idx=0)
set the value of tag-value idx as datetime throws if type-checking failed throws if the index is out ...
int compare(const Tag &tag, double tolerance=0.0001) const
Copied from DicomTags (Marcus Barann).
virtual void toStream(std::ostream &out, bool writeName) const
copy this instance recursively into the given stream writeName = true writes tag name(s) to stream,...
void dropValues()
drop all values of this tag does not drop sequences! these are handled differently!
Tag(const Tag &other, unsigned short slot)
copy ctor for private tags with a given private slot
TagInfo const & tagInfo() const
Definition: DCMTree_Tag.h:465
short int toShort(unsigned int idx=0) const
get the value of tag-value idx as short throws if type-checking failed throws if the index is out of ...
unsigned int toUInt(unsigned int idx=0) const
get the value of tag-value idx as unsigned int throws if type-checking failed throws if the index is ...
void 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 ra...
const TagInfo & info() const
get the tag-info (type etc.) of this tag
const Value & getValue(unsigned int idx=0) const
get the value-object with index idx throws if the index is out of range be careful - no type checking...
TreePtrVector & sequenceItems()
access the probably embedded sequences of this tag throws if this tag is not of type SQ!
void setValue(int value, unsigned int idx=0)
set the value of tag-value idx as int throws if type-checking failed throws if the index is out of ra...
boost::uint32_t numberOfSequenceItems() const
get the number of embedded sequence items of this tag does not check for SQ
void setValue(double value, unsigned int idx=0)
set the value of tag-value idx as double throws if type-checking failed throws if the index is out of...
void setValue(unsigned short int value, unsigned int idx=0)
set the value of tag-value idx as unsigned short throws if type-checking failed throws if the index i...
Tag & operator=(const Tag &other)
deep copy all values from other to this handles self-assignment well
void addValue(int value)
add a value of this tag as int throws if type-checking failed
void setInfo(const TagInfo &info)
set the tag-info for this tag be careful if changing vr!
const TreePtrVector & sequenceItems() const
access the probably embedded sequences of this tag throws if this tag is not of type SQ!
std::string toString(unsigned int idx, StringTrimMode trimMode=DO_NOT_TRIM) const
get the value of tag-value idx as string throws if type-checking failed throws if the index is out of...
Tag(const TagInfo &info)
ctor info defines the datatype, name etc.
void setValue(const Value &value, unsigned int idx=0)
set the value-object with index idx throws if the index is out of range be careful - no type checking...
float toFloat(unsigned int idx=0) const
get the value of tag-value idx as float throws if type-checking failed throws if the index is out of ...
void setValue(Date value, unsigned int idx=0)
set the value of tag-value idx as date throws if type-checking failed throws if the index is out of r...
void setValue(Time value, unsigned int idx=0)
set the value of tag-value idx as time throws if type-checking failed throws if the index is out of r...
void addValue(unsigned int value)
add a value of this tag as unsigned int throws if type-checking failed
Date toDate(unsigned int idx=0) const
get the value of tag-value idx as date throws if type-checking failed throws if the index is out of r...
void setVr(Vr vr)
Set a new value representation if the VR is unknown.
void setValue(float value, unsigned int idx=0)
set the value of tag-value idx as float throws if type-checking failed throws if the index is out of ...
Time toTime(unsigned int idx=0) const
get the value of tag-value idx as time throws if type-checking failed throws if the index is out of r...
void setValue(unsigned int value, unsigned int idx=0)
set the value of tag-value idx as unsigned int throws if type-checking failed throws if the index is ...
bool isNull(unsigned idx) const
check if the values with index idx is null throws if the index is out of range
virtual boost::uint32_t getValueSize(unsigned int idx) const
get the size in bytes of the data of the value-object with index idx throws if the index is out of ra...
virtual boost::uint32_t getValueSize() const
get the total size in bytes of the data of the values
TreePtr & addSequenceItem()
add a sequence to this tag and return a reference to it for further processing
bool isSequenceItemNull(unsigned idx) const
checks if the sequence with index idx is null throws if the index is out of range
void addValue(unsigned short int value)
add a value of this tag as unsigned short throws if type-checking failed
void dropSequenceItems()
drop all sequences of this tag does not check for SQ (if not SQ you just drop nothing)
std::string toString(StringTrimMode trimMode=DO_NOT_TRIM) const
convert the complete tag to a string that means, all values are concatenated by a backslash and conve...
Class to store tag-values.
Definition: DCMTree_Value.h:45
Interface which provides a method to deserialize an object.
Interface which provides a method to serialize an object.
Interface of a data sink for the serialization of objects.
Interface of a data source for the deserialization of objects.
class to dump a DCMTree dicom message into a human readable file this class could be used as a starte...
std::pair< Date, Time > DateTime
DateTime.
Definition: DCMTree_Lib.h:201
Vr
DICOM VR.
Definition: DCMTree_Lib.h:208
std::istream & operator>>(std::istream &in, Message &m)
VRCType
vr interpretation in C++
Definition: DCMTree_Lib.h:217
boost::shared_ptr< Tag > TagPtr
shared-pointer to tag
Definition: DCMTree_Lib.h:59
std::vector< TreePtr > TreePtrVector
a vector of TreePtr - used for sequences
Definition: DCMTree_Lib.h:85
std::vector< Value > ValueVector
boost::shared_ptr< Tree > TreePtr
shared pointer to a DCMTree::Tree
Definition: DCMTree_Lib.h:70
StringTrimMode
Definition: DCMTree_Tag.h:39
@ TRIM_STRING
Definition: DCMTree_Tag.h:39
@ DO_NOT_TRIM
Definition: DCMTree_Tag.h:39
std::ostream & operator<<(std::ostream &out, const Message &m)
boost::graph_traits< ml_graph_ptr >::vertex_descriptor source(graph_traits< ml_graph_ptr >::edge_descriptor e, const ml_graph_ptr)
Returns the vertex descriptor for u of the edge (u,v) represented by e.
Date class for DCMTree library.
Definition: DCMTree_Lib.h:181
Time class for DCMTree library.
Definition: DCMTree_Lib.h:191