Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
mitk::ContourModelWriter Class Reference

XML-based writer for mitk::ContourModels. More...

#include <mitkContourModelWriter.h>

Inheritance diagram for mitk::ContourModelWriter:
Collaboration diagram for mitk::ContourModelWriter:

Public Member Functions

 ContourModelWriter (bool writeXMLHeader=true)
 Construct the writer, optionally including an XML header. More...
 
 ~ContourModelWriter () override
 
void Write () override
 Write the ContourModel to the configured output location. More...
 
void Write () override=0
 Write the base data to the specified location or output stream. More...
 
- Public Member Functions inherited from mitk::AbstractFileWriter
void SetInput (const BaseData *data) override
 Set the input data for writing. More...
 
const BaseData * GetInput () const override
 Get the input data. More...
 
void SetOutputLocation (const std::string &location) override
 Set the output file-system path, clearing any output stream. More...
 
std::string GetOutputLocation () const override
 Get the current output location. More...
 
void SetOutputStream (const std::string &location, std::ostream *os) override
 Set an output stream and associated location label. More...
 
std::ostream * GetOutputStream () const override
 Get the current output stream. More...
 
ConfidenceLevel GetConfidenceLevel () const override
 Determine confidence for writing the current input data. More...
 
MimeType GetRegisteredMimeType () const
 Get the MIME type that was registered for this writer. More...
 
Options GetOptions () const override
 Get the current option values. More...
 
us::Any GetOption (const std::string &name) const override
 Get the value of a specific option. More...
 
void SetOptions (const Options &options) override
 Set multiple options at once. More...
 
void SetOption (const std::string &name, const us::Any &value) override
 Set a single option value. More...
 
void AddProgressCallback (const ProgressCallback &callback) override
 Register a progress callback. More...
 
void RemoveProgressCallback (const ProgressCallback &callback) override
 Remove a previously registered progress callback. More...
 
us::ServiceRegistration< IFileWriter > RegisterService (us::ModuleContext *context=us::GetModuleContext())
 Register this writer as a CppMicroServices service. More...
 
void UnregisterService ()
 Unregister this writer from the CppMicroServices registry. More...
 
- Public Member Functions inherited from mitk::IFileWriter
 ~IFileWriter () override
 
- Public Member Functions inherited from mitk::IFileIO
virtual ~IFileIO ()
 

Static Public Attributes

static const char * XML_CONTOURMODEL
 
static const char * XML_HEAD
 
static const char * XML_GEOMETRY_INFO
 
static const char * XML_DATA
 
static const char * XML_TIME_STEP
 
static const char * XML_CONTROL_POINTS
 
static const char * XML_POINT
 
static const char * XML_X
 
static const char * XML_Y
 
static const char * XML_Z
 

Protected Member Functions

 ContourModelWriter (const ContourModelWriter &other)
 
mitk::ContourModelWriter * Clone () const override
 
template<typename T >
std::string ConvertToString (T value)
 Convert an arbitrary type to a string. More...
 
void WriteXML (const mitk::ContourModel *contourModel, std::ostream &out)
 Write an XML representation of the given contour model to a stream. More...
 
void WriteGeometryInformation (const mitk::TimeGeometry *geometry, std::ostream &out)
 Write the geometry information of a TimeGeometry to a stream. More...
 
void WriteXMLHeader (std::ostream &file)
 Write a standard XML header to the given stream. More...
 
void WriteStartElement (const char *const tag, std::ostream &file)
 Write a start element tag. More...
 
void WriteStartElementWithAttribut (const char *const tag, std::vector< std::string > attributes, std::vector< std::string > values, std::ostream &file)
 Write a start element tag with attributes. More...
 
void WriteEndElement (const char *const tag, std::ostream &file, const bool &indent=true)
 Write an end element tag. More...
 
void WriteCharacterData (const char *const data, std::ostream &file)
 Write character data inside a tag. More...
 
void WriteStartElement (std::string &tag, std::ostream &file)
 Write a start element tag (std::string overload). More...
 
void WriteEndElement (std::string &tag, std::ostream &file, const bool &indent=true)
 Write an end element tag (std::string overload). More...
 
void WriteCharacterData (std::string &data, std::ostream &file)
 Write character data inside a tag (std::string overload). More...
 
void WriteIndent (std::ostream &file)
 Write indentation spaces to the stream according to m_IndentDepth and m_Indent. More...
 
- Protected Member Functions inherited from mitk::AbstractFileWriter
 ~AbstractFileWriter () override
 
 AbstractFileWriter (const AbstractFileWriter &other)
 Copy constructor. More...
 
 AbstractFileWriter (const std::string &baseDataType)
 Construct a writer for the given BaseData type name. More...
 
 AbstractFileWriter (const std::string &baseDataType, const CustomMimeType &mimeType, const std::string &description)
 Construct a writer for the given BaseData type, MIME type, and description. More...
 
virtual us::ServiceProperties GetServiceProperties () const
 Get the service properties for registration. More...
 
virtual us::ServiceRegistration< CustomMimeType > RegisterMimeType (us::ModuleContext *context)
 Register a new CustomMimeType service object. More...
 
void SetMimeType (const CustomMimeType &mimeType)
 Set the MIME type this writer can handle. More...
 
const CustomMimeType * GetMimeType () const
 Get the MIME type this writer can handle. More...
 
void SetMimeTypePrefix (const std::string &prefix)
 Set the prefix used for auto-generated MIME type names. More...
 
std::string GetMimeTypePrefix () const
 Get the current MIME type name prefix. More...
 
void SetDescription (const std::string &description)
 Set a human-readable description of this writer. More...
 
std::string GetDescription () const
 Get the human-readable description of this writer. More...
 
void SetDefaultOptions (const Options &defaultOptions)
 Set the default options for this writer. More...
 
Options GetDefaultOptions () const
 Get the default options for this writer. More...
 
void SetRanking (int ranking)
 Set the service ranking for this file writer. More...
 
int GetRanking () const
 Get the service ranking for this file writer. More...
 
void SetBaseDataType (const std::string &baseDataType)
 Set the name of the mitk::BaseData sub-class this writer supports. More...
 
virtual std::string GetBaseDataType () const
 Get the name of the mitk::BaseData sub-class this writer supports. More...
 
void ValidateOutputLocation () const
 Validate the output location or stream. More...
 

Protected Attributes

bool m_WriteXMLHeader
 
unsigned int m_IndentDepth
 
unsigned int m_Indent
 

Additional Inherited Members

- Public Types inherited from mitk::IFileIO
enum  ConfidenceLevel { Unsupported , PartiallySupported , Supported }
 A confidence level describing the reader's or writer's ability to handle the given data or file format. More...
 
typedef std::map< std::string, us::Any > Options
 Options for reading or writing data. More...
 
typedef mitk::MessageAbstractDelegate1< float > ProgressCallback
 Callback delegate type for progress reporting. More...
 
- Static Public Member Functions inherited from mitk::IFileWriter
static std::string PROP_BASEDATA_TYPE ()
 Service property name for the supported mitk::BaseData sub-class. More...
 
- Static Public Member Functions inherited from mitk::IFileIO
static std::string PROP_DESCRIPTION ()
 Service property name for a human-readable description. More...
 
static std::string PROP_MIMETYPE ()
 Service property name for the mime-type associated with this reader or writer. More...
 

Detailed Description

XML-based writer for mitk::ContourModels.

XML-based writer for mitk::ContourModels. Multiple ContourModels can be written in a single XML file by simply setting multiple inputs to the filter.

The xml file will look like:

<?xml version="1.0" encoding="utf-8"?>
<contourModel>
<head>
<geometryInfo>
</geometryInfo>
</head>
<data>
<timestep n="0">
<controlPoints>
<point>
<x></x>
<y></y>
<z></z>
</point>
</controlPoint>
</timestep>
</data>
</contourModel>

Definition at line 54 of file mitkContourModelWriter.h.

Constructor & Destructor Documentation

◆ ContourModelWriter() [1/2]

mitk::ContourModelWriter::ContourModelWriter ( bool  writeXMLHeader = true)
explicit

Construct the writer, optionally including an XML header.

Parameters
writeXMLHeaderIf true (default), the XML declaration is written at the top of the file.

◆ ~ContourModelWriter()

mitk::ContourModelWriter::~ContourModelWriter ( )
override

◆ ContourModelWriter() [2/2]

mitk::ContourModelWriter::ContourModelWriter ( const ContourModelWriter &  other)
protected

Member Function Documentation

◆ Clone()

mitk::ContourModelWriter* mitk::ContourModelWriter::Clone ( ) const
overrideprotectedvirtual

◆ ConvertToString()

template<typename T >
std::string mitk::ContourModelWriter::ConvertToString ( T  value)
protected

Convert an arbitrary type to a string.

The type must support the << operator. Works for integral data types such as float, int, long, etc.

Template Parameters
TThe type to convert.
Parameters
valueThe value to convert.
Returns
The string representation of value.

◆ Write() [1/2]

void mitk::ContourModelWriter::Write ( )
overridevirtual

Write the ContourModel to the configured output location.

Implements mitk::AbstractFileWriter.

◆ Write() [2/2]

void mitk::AbstractFileWriter::Write
overridevirtual

Write the base data to the specified location or output stream.

Subclasses must implement this method. Call GetOutputStream() first and check for a non-null stream to write to. If the output stream is nullptr, use GetOutputLocation() to write to a local file-system path.

If the writer cannot use streams directly, use LocalFile to retrieve a temporary local file name instead.

Exceptions
mitk::Exceptionif writing fails.
See also
LocalFile
IFileWriter::Write()

Implements mitk::AbstractFileWriter.

◆ WriteCharacterData() [1/2]

void mitk::ContourModelWriter::WriteCharacterData ( const char *const  data,
std::ostream &  file 
)
protected

Write character data inside a tag.

Parameters
dataThe character data string.
fileThe output stream.

◆ WriteCharacterData() [2/2]

void mitk::ContourModelWriter::WriteCharacterData ( std::string &  data,
std::ostream &  file 
)
protected

Write character data inside a tag (std::string overload).

Parameters
dataThe character data string.
fileThe output stream.

◆ WriteEndElement() [1/2]

void mitk::ContourModelWriter::WriteEndElement ( const char *const  tag,
std::ostream &  file,
const bool &  indent = true 
)
protected

Write an end element tag.

End-elements following character data should pass indent = false.

Parameters
tagThe element tag name.
fileThe output stream.
indentWhether to write indentation before the tag.

◆ WriteEndElement() [2/2]

void mitk::ContourModelWriter::WriteEndElement ( std::string &  tag,
std::ostream &  file,
const bool &  indent = true 
)
protected

Write an end element tag (std::string overload).

Parameters
tagThe element tag name.
fileThe output stream.
indentWhether to write indentation before the tag.

◆ WriteGeometryInformation()

void mitk::ContourModelWriter::WriteGeometryInformation ( const mitk::TimeGeometry *  geometry,
std::ostream &  out 
)
protected

Write the geometry information of a TimeGeometry to a stream.

The root tag is not included.

Parameters
geometryThe TimeGeometry of the contour.
outThe output stream to write to.

◆ WriteIndent()

void mitk::ContourModelWriter::WriteIndent ( std::ostream &  file)
protected

Write indentation spaces to the stream according to m_IndentDepth and m_Indent.

◆ WriteStartElement() [1/2]

void mitk::ContourModelWriter::WriteStartElement ( const char *const  tag,
std::ostream &  file 
)
protected

Write a start element tag.

Parameters
tagThe element tag name.
fileThe output stream.

◆ WriteStartElement() [2/2]

void mitk::ContourModelWriter::WriteStartElement ( std::string &  tag,
std::ostream &  file 
)
protected

Write a start element tag (std::string overload).

Parameters
tagThe element tag name.
fileThe output stream.

◆ WriteStartElementWithAttribut()

void mitk::ContourModelWriter::WriteStartElementWithAttribut ( const char *const  tag,
std::vector< std::string >  attributes,
std::vector< std::string >  values,
std::ostream &  file 
)
protected

Write a start element tag with attributes.

Parameters
tagThe element tag name.
attributesThe attribute names.
valuesThe attribute values (parallel to attributes).
fileThe output stream.

◆ WriteXML()

void mitk::ContourModelWriter::WriteXML ( const mitk::ContourModel *  contourModel,
std::ostream &  out 
)
protected

Write an XML representation of the given contour model to a stream.

The XML header and root node are not included.

Parameters
contourModelThe contour model to be serialized.
outThe output stream to write to.

◆ WriteXMLHeader()

void mitk::ContourModelWriter::WriteXMLHeader ( std::ostream &  file)
protected

Write a standard XML header to the given stream.

Parameters
fileThe output stream.

Member Data Documentation

◆ m_Indent

unsigned int mitk::ContourModelWriter::m_Indent
protected

Definition at line 179 of file mitkContourModelWriter.h.

◆ m_IndentDepth

unsigned int mitk::ContourModelWriter::m_IndentDepth
protected

Definition at line 177 of file mitkContourModelWriter.h.

◆ m_WriteXMLHeader

bool mitk::ContourModelWriter::m_WriteXMLHeader
protected

Definition at line 175 of file mitkContourModelWriter.h.

◆ XML_CONTOURMODEL

const char* mitk::ContourModelWriter::XML_CONTOURMODEL
static

Definition at line 182 of file mitkContourModelWriter.h.

◆ XML_CONTROL_POINTS

const char* mitk::ContourModelWriter::XML_CONTROL_POINTS
static

Definition at line 192 of file mitkContourModelWriter.h.

◆ XML_DATA

const char* mitk::ContourModelWriter::XML_DATA
static

Definition at line 188 of file mitkContourModelWriter.h.

◆ XML_GEOMETRY_INFO

const char* mitk::ContourModelWriter::XML_GEOMETRY_INFO
static

Definition at line 186 of file mitkContourModelWriter.h.

◆ XML_HEAD

const char* mitk::ContourModelWriter::XML_HEAD
static

Definition at line 184 of file mitkContourModelWriter.h.

◆ XML_POINT

const char* mitk::ContourModelWriter::XML_POINT
static

Definition at line 194 of file mitkContourModelWriter.h.

◆ XML_TIME_STEP

const char* mitk::ContourModelWriter::XML_TIME_STEP
static

Definition at line 190 of file mitkContourModelWriter.h.

◆ XML_X

const char* mitk::ContourModelWriter::XML_X
static

Definition at line 196 of file mitkContourModelWriter.h.

◆ XML_Y

const char* mitk::ContourModelWriter::XML_Y
static

Definition at line 198 of file mitkContourModelWriter.h.

◆ XML_Z

const char* mitk::ContourModelWriter::XML_Z
static

Definition at line 200 of file mitkContourModelWriter.h.


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