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

Provides functionality to load and save MITK scene files (.mitk). More...

#include <mitkSceneIO.h>

Inheritance diagram for mitk::SceneIO:
Collaboration diagram for mitk::SceneIO:

Public Types

typedef DataStorage::SetOfObjects FailedBaseDataListType
 Type for a list of DataNodes whose BaseData failed to serialize/deserialize. More...
 

Public Member Functions

 mitkClassMacroItkParent (SceneIO, itk::Object)
 
Pointer Clone () const
 
virtual DataStorage::Pointer LoadScene (const std::string &filename, DataStorage *storage=nullptr, bool clearStorageFirst=false)
 Loads a scene from an MITK scene file. More...
 
virtual DataStorage::Pointer LoadSceneUnzipped (const std::string &indexfilename, DataStorage *storage=nullptr, bool clearStorageFirst=false)
 Loads a scene from an already-unpacked directory. More...
 
virtual bool SaveScene (DataStorage::SetOfObjects::ConstPointer sceneNodes, const DataStorage *storage, const std::string &filename)
 Saves a scene of DataNodes to a .mitk scene file (ZIP archive). More...
 
const FailedBaseDataListType * GetFailedNodes ()
 Returns DataNodes whose BaseData failed to be written during the most recent SaveScene() call. More...
 
const PropertyList * GetFailedProperties ()
 Returns properties that failed to be written during the most recent SaveScene() call. More...
 

Static Public Member Functions

static Pointer New ()
 

Protected Member Functions

 SceneIO ()
 
 ~SceneIO () override
 
std::string CreateEmptyTempDirectory ()
 
tinyxml2::XMLElement * SaveBaseData (tinyxml2::XMLDocument &doc, BaseData *data, const std::string &filenamehint, bool &error)
 
tinyxml2::XMLElement * SavePropertyList (tinyxml2::XMLDocument &doc, const IPropertyTransience *transience, PropertyList *propertyList, const BaseData *nodeData, const std::string &filenamehint)
 
void OnUnzipError (const void *pSender, std::pair< const Poco::Zip::ZipLocalFileHeader, const std::string > &info)
 
void OnUnzipOk (const void *pSender, std::pair< const Poco::Zip::ZipLocalFileHeader, const Poco::Path > &info)
 

Protected Attributes

FailedBaseDataListType::Pointer m_FailedNodes
 
PropertyList::Pointer m_FailedProperties
 
std::string m_WorkingDirectory
 
unsigned int m_UnzipErrors
 

Detailed Description

Provides functionality to load and save MITK scene files (.mitk).

SceneIO handles the complete scene serialization pipeline:

  • Loading: Unzips a .mitk scene file, parses index.xml, and reconstructs DataNodes with their data, properties, and parent/child relationships into a DataStorage.
  • Saving: Serializes DataNodes from a DataStorage into temporary files, writes an index.xml, and packages everything into a ZIP archive.

Scene files (.mitk) are ZIP archives containing:

  • An index.xml file describing all nodes, their relationships, and references to serialized data and property files.
  • Serialized BaseData files (images, surfaces, etc.).
  • Serialized PropertyList XML files.

After loading or saving, failed nodes and properties can be queried to determine what could not be processed.

See also
SceneReader, BaseDataSerializer, PropertyListSerializer

Definition at line 56 of file mitkSceneIO.h.

Member Typedef Documentation

◆ FailedBaseDataListType

Type for a list of DataNodes whose BaseData failed to serialize/deserialize.

Definition at line 64 of file mitkSceneIO.h.

Constructor & Destructor Documentation

◆ SceneIO()

mitk::SceneIO::SceneIO ( )
protected

◆ ~SceneIO()

mitk::SceneIO::~SceneIO ( )
overrideprotected

Member Function Documentation

◆ Clone()

Pointer mitk::SceneIO::Clone ( ) const

◆ CreateEmptyTempDirectory()

std::string mitk::SceneIO::CreateEmptyTempDirectory ( )
protected

◆ GetFailedNodes()

const FailedBaseDataListType* mitk::SceneIO::GetFailedNodes ( )

Returns DataNodes whose BaseData failed to be written during the most recent SaveScene() call.

Note
These accessors currently reflect save-side failures only. Load paths (both the legacy XML reader and SceneJsonReader) report per-node errors via MITK_ERROR log output and the reader's return value, not via this list.
Returns
Pointer to the list of failed nodes, or nullptr if none failed.

◆ GetFailedProperties()

const PropertyList* mitk::SceneIO::GetFailedProperties ( )

Returns properties that failed to be written during the most recent SaveScene() call.

The properties may originate from:

Note
See GetFailedNodes() — load paths do not populate this list.
Returns
Pointer to the PropertyList of failed properties, or nullptr if none failed.

◆ LoadScene()

virtual DataStorage::Pointer mitk::SceneIO::LoadScene ( const std::string &  filename,
DataStorage *  storage = nullptr,
bool  clearStorageFirst = false 
)
virtual

Loads a scene from an MITK scene file.

Accepts either a .mitk ZIP archive (unpacked to a temporary directory, then dispatched via index.json if present, else index.xml) or a standalone .mitkscene.json file.

Parameters
[in]filenameFull path to the scene file.
[in]storageIf non-null, this DataStorage is populated instead of creating a new StandaloneDataStorage.
[in]clearStorageFirstIf true, the provided DataStorage is cleared before loading new objects into it. For the JSON path, clearing is deferred until after the scene descriptor has been validated so that a malformed file does not wipe the caller's session.
Returns
A DataStorage containing all successfully loaded scene objects and their relationships. Per-node load failures are reported via MITK_ERROR log output; GetFailedNodes() / GetFailedProperties() reflect save-side failures only and are not populated here.
Note
For the JSON path, this method does not throw: exceptions raised by SceneJsonReader (JSON parse errors, missing data files, property-map resolution errors) are caught and logged as MITK_ERROR, and the returned DataStorage may be empty or partially populated. The legacy XML path retains its existing behavior and may propagate exceptions from the underlying reader; callers that need to handle both formats uniformly should wrap the call in their own try/catch.
Postcondition
The temporary directory is deleted after loading.

◆ LoadSceneUnzipped()

virtual DataStorage::Pointer mitk::SceneIO::LoadSceneUnzipped ( const std::string &  indexfilename,
DataStorage *  storage = nullptr,
bool  clearStorageFirst = false 
)
virtual

Loads a scene from an already-unpacked directory.

Similar to LoadScene(), but operates on an unpacked scene directory rather than a ZIP archive. Assumes the given file is the index.xml of the scene and uses its parent directory as the working directory.

Parameters
[in]indexfilenameFull path to the scene's index.xml file.
[in]storageIf non-null, this DataStorage is populated instead of creating a new StandaloneDataStorage.
[in]clearStorageFirstIf true, the provided DataStorage is cleared before loading new objects into it.
Returns
A DataStorage containing all successfully loaded scene objects and their relationships. Per-node load failures are reported via MITK_ERROR log output; GetFailedNodes() / GetFailedProperties() reflect save-side failures only and are not populated here.

◆ mitkClassMacroItkParent()

mitk::SceneIO::mitkClassMacroItkParent ( SceneIO  ,
itk::Object   
)

◆ New()

static Pointer mitk::SceneIO::New ( )
static

◆ OnUnzipError()

void mitk::SceneIO::OnUnzipError ( const void *  pSender,
std::pair< const Poco::Zip::ZipLocalFileHeader, const std::string > &  info 
)
protected

◆ OnUnzipOk()

void mitk::SceneIO::OnUnzipOk ( const void *  pSender,
std::pair< const Poco::Zip::ZipLocalFileHeader, const Poco::Path > &  info 
)
protected

◆ SaveBaseData()

tinyxml2::XMLElement* mitk::SceneIO::SaveBaseData ( tinyxml2::XMLDocument &  doc,
BaseData *  data,
const std::string &  filenamehint,
bool &  error 
)
protected

◆ SavePropertyList()

tinyxml2::XMLElement* mitk::SceneIO::SavePropertyList ( tinyxml2::XMLDocument &  doc,
const IPropertyTransience *  transience,
PropertyList *  propertyList,
const BaseData *  nodeData,
const std::string &  filenamehint 
)
protected

◆ SaveScene()

virtual bool mitk::SceneIO::SaveScene ( DataStorage::SetOfObjects::ConstPointer  sceneNodes,
const DataStorage *  storage,
const std::string &  filename 
)
virtual

Saves a scene of DataNodes to a .mitk scene file (ZIP archive).

Serializes the given set of DataNodes (including their data, properties, and parent/child relationships from the DataStorage) into a temporary directory, creates an index.xml, and packages everything into a ZIP archive at the specified filename.

Parameters
[in]sceneNodesThe set of DataNodes to save.
[in]storageThe DataStorage containing the nodes and their relationships.
[in]filenameFull path for the output .mitk scene file.
Returns
True if the scene was saved completely and successfully. False if any problem occurred. Note that a partial scene file may still be written. Query GetFailedNodes() and GetFailedProperties() for details.
Precondition
sceneNodes must not be null.
storage must not be null.
filename must not be empty.

Member Data Documentation

◆ m_FailedNodes

FailedBaseDataListType::Pointer mitk::SceneIO::m_FailedNodes
protected

Definition at line 189 of file mitkSceneIO.h.

◆ m_FailedProperties

PropertyList::Pointer mitk::SceneIO::m_FailedProperties
protected

Definition at line 190 of file mitkSceneIO.h.

◆ m_UnzipErrors

unsigned int mitk::SceneIO::m_UnzipErrors
protected

Definition at line 193 of file mitkSceneIO.h.

◆ m_WorkingDirectory

std::string mitk::SceneIO::m_WorkingDirectory
protected

Definition at line 192 of file mitkSceneIO.h.


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