Medical Imaging Interaction Toolkit  2024.12.99-2f135637
Medical Imaging Interaction Toolkit
mitk::MultiLabelIOHelper Class Reference

The MultiLabelIOHelper is a static helper class that supports serialization of mitk::MultiLabelSegmentation. More...

#include <mitkMultiLabelIOHelper.h>

Classes

struct  LabelGroupMetaData
 Structure to hold label group metadata including labels and group properties. More...
 

Public Types

using GroupFileNameCallback = std::function< std::string(const mitk::MultiLabelSegmentation *, mitk::MultiLabelSegmentation::GroupIndexType)>
 
using LabelFileNameCallback = std::function< std::string(const mitk::MultiLabelSegmentation *, mitk::MultiLabelSegmentation::LabelValueType)>
 
using LabelFileValueCallback = std::function< mitk::MultiLabelSegmentation::LabelValueType(const mitk::MultiLabelSegmentation *, mitk::MultiLabelSegmentation::LabelValueType)>
 

Static Public Member Functions

static bool SaveLabelSetImagePreset (const std::string &presetFilename, const mitk::MultiLabelSegmentation *inputImage)
 Saves the mitk::LabelSet configuration of inputSegmentation to presetFilename. The preset is stored as "*.lsetp". More...
 
static bool LoadLabelSetImagePreset (const std::string &presetFilename, mitk::MultiLabelSegmentation *inputImage)
 Loads an existing preset for a mitk::MultiLabelSegmentation from presetFilename and applies it to inputSegmentation. More...
 
static itk::SmartPointer< mitk::LabelLoadLabelFromXMLDocument (const tinyxml2::XMLElement *labelElem)
 Creates a mitk::Label from an XML element. More...
 
static tinyxml2::XMLElement * GetLabelAsXMLElement (tinyxml2::XMLDocument &doc, const Label *label)
 Creates an XML element from a mitk::Label. More...
 
static tinyxml2::XMLElement * PropertyToXMLElement (tinyxml2::XMLDocument &doc, const std::string &key, const BaseProperty *property)
 Since a mitk::Label is basically a mitk::PropertyList this function converts the label's properties into XML. More...
 
static bool PropertyFromXMLElement (std::string &key, itk::SmartPointer< mitk::BaseProperty > &prop, const tinyxml2::XMLElement *elem)
 Since a mitk::Label is basically a mitk::PropertyList this function converts an XML element into a property. More...
 
static int GetIntByKey (const itk::MetaDataDictionary &dic, const std::string &key)
 
static std::string GetStringByKey (const itk::MetaDataDictionary &dic, const std::string &key)
 
static nlohmann::json SerializeMultLabelGroupsToJSON (const mitk::MultiLabelSegmentation *inputSegmentation, GroupFileNameCallback groupFileNameCallback=nullptr, LabelFileNameCallback labelFileNameCallback=nullptr, LabelFileValueCallback labelFileValueCallback=nullptr)
 Serialize meta data all groups of the multilabel segmentation to JSON format (v2) More...
 
static std::vector< LabelGroupMetaDataDeserializeMultiLabelGroupsFromJSON (const nlohmann::json &listOfLabelGroups)
 Deserialize meta data of multilabel groups from JSON format (v2) More...
 
static nlohmann::json SerializeLabelToJSON (const Label *label)
 Serialize a single label to JSON. More...
 
static mitk::Label::Pointer DeserializeLabelFromJSON (const nlohmann::json &labelJson)
 Deserialize a single label from JSON. More...
 
static nlohmann::json SerializeLabelPropertyToJSON (const BaseProperty *property)
 Serialize the property of a label to JSON. More...
 
template<typename TValueType >
static bool GetValueFromJson (const nlohmann::json &labelJson, const std::string &key, TValueType &value)
 

Detailed Description

The MultiLabelIOHelper is a static helper class that supports serialization of mitk::MultiLabelSegmentation.

This class provides static functions for converting mitk::Label into XML and also allows the serialization of mitk::LabelSet as presets

Definition at line 50 of file mitkMultiLabelIOHelper.h.

Member Typedef Documentation

◆ GroupFileNameCallback

◆ LabelFileNameCallback

◆ LabelFileValueCallback

Member Function Documentation

◆ DeserializeLabelFromJSON()

static mitk::Label::Pointer mitk::MultiLabelIOHelper::DeserializeLabelFromJSON ( const nlohmann::json labelJson)
static

Deserialize a single label from JSON.

Parameters
labelJsonJSON representation of the label
Returns
pointer to the deserialized label

◆ DeserializeMultiLabelGroupsFromJSON()

static std::vector<LabelGroupMetaData> mitk::MultiLabelIOHelper::DeserializeMultiLabelGroupsFromJSON ( const nlohmann::json listOfLabelGroups)
static

Deserialize meta data of multilabel groups from JSON format (v2)

Parameters
listOfLabelGroupsJSON representation of label groups
Returns
vector of label group metadata

◆ GetIntByKey()

static int mitk::MultiLabelIOHelper::GetIntByKey ( const itk::MetaDataDictionary &  dic,
const std::string &  key 
)
static

Helper that extracts the value of a key in a meta dictionary as int. If the key does not exist 0 is returned.

◆ GetLabelAsXMLElement()

static tinyxml2::XMLElement* mitk::MultiLabelIOHelper::GetLabelAsXMLElement ( tinyxml2::XMLDocument &  doc,
const Label label 
)
static

Creates an XML element from a mitk::Label.

Parameters
doc
labelthe mitk::Label from which the xml element will be created
Returns
the created XML element

◆ GetStringByKey()

static std::string mitk::MultiLabelIOHelper::GetStringByKey ( const itk::MetaDataDictionary &  dic,
const std::string &  key 
)
static

Helper that extracts the value of a key in a meta dictionary as string. If the key does not exist an empty string is returned.

◆ GetValueFromJson()

template<typename TValueType >
static bool mitk::MultiLabelIOHelper::GetValueFromJson ( const nlohmann::json labelJson,
const std::string &  key,
TValueType &  value 
)
inlinestatic

Definition at line 178 of file mitkMultiLabelIOHelper.h.

References MITK_ERROR.

◆ LoadLabelFromXMLDocument()

static itk::SmartPointer<mitk::Label> mitk::MultiLabelIOHelper::LoadLabelFromXMLDocument ( const tinyxml2::XMLElement *  labelElem)
static

Creates a mitk::Label from an XML element.

Parameters
labelElemthe xml element from which a mitk::Label will be created
Returns
the created mitk::Label

◆ LoadLabelSetImagePreset()

static bool mitk::MultiLabelIOHelper::LoadLabelSetImagePreset ( const std::string &  presetFilename,
mitk::MultiLabelSegmentation inputImage 
)
static

Loads an existing preset for a mitk::MultiLabelSegmentation from presetFilename and applies it to inputSegmentation.

Parameters
presetFilenamethe filename of the preset including the filesystem path
inputSegmentationthe image to which the loaded preset will be applied
Returns
true if the deserilization was successful and false otherwise

◆ PropertyFromXMLElement()

static bool mitk::MultiLabelIOHelper::PropertyFromXMLElement ( std::string &  key,
itk::SmartPointer< mitk::BaseProperty > &  prop,
const tinyxml2::XMLElement *  elem 
)
static

Since a mitk::Label is basically a mitk::PropertyList this function converts an XML element into a property.

Parameters
keythe property's key
propthe mitk::BaseProperty that will be created
elemthe XML elem from which the property will be created
Returns
true if the conversion was successful and false otherwise

◆ PropertyToXMLElement()

static tinyxml2::XMLElement* mitk::MultiLabelIOHelper::PropertyToXMLElement ( tinyxml2::XMLDocument &  doc,
const std::string &  key,
const BaseProperty property 
)
static

Since a mitk::Label is basically a mitk::PropertyList this function converts the label's properties into XML.

Parameters
doc
keythe property's key which will be used in the XML element
propertythe mitk::BaseProperty that should be converted
Returns
the created XML element

◆ SaveLabelSetImagePreset()

static bool mitk::MultiLabelIOHelper::SaveLabelSetImagePreset ( const std::string &  presetFilename,
const mitk::MultiLabelSegmentation inputImage 
)
static

Saves the mitk::LabelSet configuration of inputSegmentation to presetFilename. The preset is stored as "*.lsetp".

Parameters
presetFilenamethe filename including the filesystem path
inputSegmentationthe input image from which the preset should be generated
Returns
true if the serialization was successful and false otherwise

◆ SerializeLabelPropertyToJSON()

static nlohmann::json mitk::MultiLabelIOHelper::SerializeLabelPropertyToJSON ( const BaseProperty property)
static

Serialize the property of a label to JSON.

Parameters
propertyPointer to the property that should be serialized
Returns
JSON representation of the property

◆ SerializeLabelToJSON()

static nlohmann::json mitk::MultiLabelIOHelper::SerializeLabelToJSON ( const Label label)
static

Serialize a single label to JSON.

Parameters
labelthe label to serialize
Returns
JSON representation of the label

◆ SerializeMultLabelGroupsToJSON()

static nlohmann::json mitk::MultiLabelIOHelper::SerializeMultLabelGroupsToJSON ( const mitk::MultiLabelSegmentation inputSegmentation,
GroupFileNameCallback  groupFileNameCallback = nullptr,
LabelFileNameCallback  labelFileNameCallback = nullptr,
LabelFileValueCallback  labelFileValueCallback = nullptr 
)
static

Serialize meta data all groups of the multilabel segmentation to JSON format (v2)

Parameters
inputSegmentationthe multilabel segmentation to serialize
groupFileNameCallbackOptional call back function. If provided the property "file" on group level based on the returned string will be set.
labelFileNameCallbackOptional call back function. If provided the property "file" per label based on the returned string will be set.
labelFileValueCallbackOptional call back function. If provided the property "file_value" per label will be set according to the returned value.
Returns
JSON representation of the groups

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