vega
Public Member Functions | List of all members
vega::dicom::DataElement Class Reference

This class is used to contain the information in a single DataElement. More...

#include <vega/dicom/data_element.h>

Public Member Functions

 DataElement (std::shared_ptr< DataSet > parent=nullptr)
 
 DataElement (const std::string &name, std::shared_ptr< DataSet > parent=nullptr)
 
 DataElement (const Tag &tag, std::shared_ptr< DataSet > parent=nullptr)
 
 DataElement (const Tag &tag, const VR &vr, std::shared_ptr< DataSet > parent=nullptr)
 
const std::shared_ptr< const dictionary::Page > & page () const
 
void set_page (std::shared_ptr< const dictionary::Page > page)
 Sets the dictionary::Page for blank DataElements. More...
 
const DataElementHeaderheader () const
 
DataElementHeaderheader ()
 
const Tagtag () const
 
Tagtag ()
 
const VRvr () const
 
VRvr ()
 
const DataElementHeader::length_typelength () const
 
DataElementHeader::length_typelength ()
 
const std::weak_ptr< DataSet > & parent () const
 
std::weak_ptr< DataSet > & parent ()
 
const std::vector< std::shared_ptr< DataSet > > & data_sets () const
 
std::vector< std::shared_ptr< DataSet > > & data_sets ()
 
template<typename T >
void set_manipulator (std::shared_ptr< T > manipulator)
 
template<typename T >
std::shared_ptr< T > get_manipulator ()
 
std::string str () const
 Builds a string representation of the content of this DataElement. More...
 
bool is_sequence () const
 
std::vector< std::shared_ptr< DataSet > >::iterator begin ()
 
std::vector< std::shared_ptr< DataSet > >::const_iterator begin () const
 
std::vector< std::shared_ptr< DataSet > >::iterator end ()
 
std::vector< std::shared_ptr< DataSet > >::const_iterator end () const
 
bool operator== (const DataElement &other) const
 
bool operator!= (const DataElement &other) const
 
void log (Logger &logger) const
 

Detailed Description

This class is used to contain the information in a single DataElement.

This class corresponds to the part of a DICOM file called a "data element" (see DICOM documentation).

A DataElement has two main parts: a DataElementHeader and the data itself. The DataElementHeader is used to store the Tag which defines what type of data is stored, VR which defines the representation that the data is in, and a length which determines how much data is stored in the DataElement. The length never needs to be touched by the user of this library, because it is always dynamically determined when writing to file anyway. Furthermore, the user should also never need to concern themselves with modifying the tag or vr directly. This is because they are automatically filled when reading from a DICOM file, and they are automatically set for you when you instantiate a new DataElement yourself.

The data stored in the DataElement can take one of two forms: raw data, or sequence data. The details are explained in the DICOM documentation, but it is not necessary to understand these details to use this library. The main thing to know is that when the VR of a DataElement is vr::SQ (is_sequence() returns true), the DataElement stores a vector of DataSets, and otherwise (is_sequence() returns false) it stores raw data that is accessible through a manipulator.

Sequence

When the DataElement is a sequence, you can access the DataSet vector through the data_sets() method. This class also provides iterators through the begin() and end() methods so the DataSets can be looped over easily.

for (const auto& data_set : data_element) {
// Do something
}

Non-sequence

In this case, the DataElement stores raw data accessible through a manipulator object. The difficulty with using manipulators comes from the fact that what data is stored and how it is stored varies depending on the VR. This means that this information cannot be known at compile-time, and so must be provided through the templates of get_manipulator() and set_manipulator(). The advantage of using these manipulators is that they are each designed to make dealing with the data for each type of VR. See vega/manipulator.h for a list of allowed manipulators and how to use them.

Note that it is usually easier to use the wrapper class Element<T> instead of DataElement when dealing with raw data.

Constructor & Destructor Documentation

◆ DataElement() [1/4]

vega::dicom::DataElement::DataElement ( std::shared_ptr< DataSet parent = nullptr)

Creates a blank DataElement with the given parent.

Parameters
parentis the parent DataSet of the DataElement

◆ DataElement() [2/4]

vega::dicom::DataElement::DataElement ( const std::string &  name,
std::shared_ptr< DataSet parent = nullptr 
)

Creates a blank DataElement with tag given by the name.

The Tag and VR is read from the Dictionary using the name parameter. Can only use this constructor if the corresponding dictionary::Page has a single unique Tag. For example the dictionary entry "CurveDimensions" is defined to have tag (50xx,0005) where xx can be any hexadecimal digits, and so this would not be permitted.

Parameters
nameis the name of a Dictionary entry to read VR and Tag data from (e.g. "PatientName").
parentis the parent DataSet of the DataElement

◆ DataElement() [3/4]

vega::dicom::DataElement::DataElement ( const Tag tag,
std::shared_ptr< DataSet parent = nullptr 
)

Creates a blank DataElement with tag given by the tag.

Will raise an error if the given Tag is not present in the Dictionary, or if the Tag has a variable VR. For instance pixel data with tag (0x7FE0,0x0010) can have VR of vr::OB or vr::OW, and so you should use the constructor which takes a VR also.

Parameters
tagis the Tag of this DataElement.
parentis the parent DataSet of the DataElement

◆ DataElement() [4/4]

vega::dicom::DataElement::DataElement ( const Tag tag,
const VR vr,
std::shared_ptr< DataSet parent = nullptr 
)

Creates a blank DataElement with tag given by the tag and VR.

Will raise an error if the given dictionary::Page corresponding to the Tag is not found or if the VR is incompatible with it.

Parameters
tagis the Tag of this DataElement.
vris the VR of this DataElement.
parentis the parent DataSet of the DataElement (nullptr when at the root of the DICOM file)

Member Function Documentation

◆ begin() [1/2]

std::vector<std::shared_ptr<DataSet> >::iterator vega::dicom::DataElement::begin ( )
inline

◆ begin() [2/2]

std::vector<std::shared_ptr<DataSet> >::const_iterator vega::dicom::DataElement::begin ( ) const
inline

◆ data_sets() [1/2]

const std::vector<std::shared_ptr<DataSet> >& vega::dicom::DataElement::data_sets ( ) const
Returns
a vector of the this DataElement's sequence of DataSet objects.

◆ data_sets() [2/2]

std::vector<std::shared_ptr<DataSet> >& vega::dicom::DataElement::data_sets ( )

This method is used when building a new DataElement sequence by giving the user a reference.

Returns
a reference to the vector of the this DataElement's sequence of DataSet objects.

◆ end() [1/2]

std::vector<std::shared_ptr<DataSet> >::iterator vega::dicom::DataElement::end ( )
inline

◆ end() [2/2]

std::vector<std::shared_ptr<DataSet> >::const_iterator vega::dicom::DataElement::end ( ) const
inline

◆ get_manipulator()

template<typename T >
std::shared_ptr<T> vega::dicom::DataElement::get_manipulator ( )
inline

Returns a vega/manipulator.h manipulator object for the user to manipulate the content of this DataElement. If there is not yet a manipulator object, a new one is created and returned. If the received type T is compatible with the current existing manipulator, then a pointer to that is cast and returned. Otherwise if a new type is specified then a new manipulator is created from the existing raw data, so if it currently stores a list of 16 bit integers and you request a manipulator of 32 bit integers, then each 32 bit integer will be a pair of 16 bit integers.

auto manipulator = data_element->get_manipulator<vega::FL_Manipulator>();
manipulator->push_back(3.14f);

◆ header() [1/2]

const DataElementHeader& vega::dicom::DataElement::header ( ) const

◆ header() [2/2]

DataElementHeader& vega::dicom::DataElement::header ( )

◆ is_sequence()

bool vega::dicom::DataElement::is_sequence ( ) const
Returns
true when this DataElement is a sequence (has VR of vr::SQ).

◆ length() [1/2]

const DataElementHeader::length_type& vega::dicom::DataElement::length ( ) const

◆ length() [2/2]

DataElementHeader::length_type& vega::dicom::DataElement::length ( )

◆ log()

void vega::dicom::DataElement::log ( Logger logger) const

◆ operator!=()

bool vega::dicom::DataElement::operator!= ( const DataElement other) const

◆ operator==()

bool vega::dicom::DataElement::operator== ( const DataElement other) const

◆ page()

const std::shared_ptr<const dictionary::Page>& vega::dicom::DataElement::page ( ) const
Returns
the dictionary::Page corresponding to this DataElement's Tag.

◆ parent() [1/2]

const std::weak_ptr<DataSet>& vega::dicom::DataElement::parent ( ) const

◆ parent() [2/2]

std::weak_ptr<DataSet>& vega::dicom::DataElement::parent ( )

◆ set_manipulator()

template<typename T >
void vega::dicom::DataElement::set_manipulator ( std::shared_ptr< T >  manipulator)
inline

Given a user filled manipulator, this DataElement's internal manipulator will be set to this, and so any stored data is overwritten.

◆ set_page()

void vega::dicom::DataElement::set_page ( std::shared_ptr< const dictionary::Page page)

Sets the dictionary::Page for blank DataElements.

◆ str()

std::string vega::dicom::DataElement::str ( ) const

Builds a string representation of the content of this DataElement.

◆ tag() [1/2]

const Tag& vega::dicom::DataElement::tag ( ) const

◆ tag() [2/2]

Tag& vega::dicom::DataElement::tag ( )

◆ vr() [1/2]

const VR& vega::dicom::DataElement::vr ( ) const

◆ vr() [2/2]

VR& vega::dicom::DataElement::vr ( )

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