Medical Imaging Interaction Toolkit  2024.06.99-5f7b36e7
Medical Imaging Interaction Toolkit
How to create a new custom data type

Prerequisites and further reading

We will use some concepts during this tutorial which we assume you are aware of, as well as taking advantage of infrastructure which needs to be set up. The following is a list of prerequisites which should be present to effectively use this tutorial.

Some concepts will only be briefly touched upon in this tutorial, for a more concise presentation of these concepts please refer to the following further reading.

Creating a new data type

A new data type needs to derive from mitk::BaseData in order to be handled by the mitk::DataStorage via mitk::DataNode. An example of a very simple data type is provided in the example module. This type encapsulates a string.

The Medical Imaging Interaction Toolkit (MITK)
Copyright (c) German Cancer Research Center (DKFZ)
All rights reserved.
Use of this source code is governed by a 3-clause BSD license that can be
found in the LICENSE file.
#ifndef mitkExampleDataStructure_h
#define mitkExampleDataStructure_h
#include "mitkBaseData.h"
namespace mitk
class MITKNEWMODULE_EXPORT ExampleDataStructure : public BaseData
// virtual methods that need to be implemented
void UpdateOutputInformation() override;
void SetRequestedRegionToLargestPossibleRegion() override;
bool RequestedRegionIsOutsideOfTheBufferedRegion() override;
bool VerifyRequestedRegion() override;
void SetRequestedRegion(const itk::DataObject *) override;
// Macros
mitkClassMacro(ExampleDataStructure, BaseData);
// Get macros
itkGetMacro(Data, std::string);
itkGetConstMacro(Data, std::string);
// Set macros
itkSetMacro(Data, std::string);
void AppendAString(const std::string input);
~ExampleDataStructure() override;
// this string is the data stored in this example data structure
std::string m_Data;
bool verbose);
} // namespace mitk

Overloading mitk::Equal to work with your data type will enable you to write simpler, standardized tests.

Adding readers and writers

In order for your data type to be read from and written to disk, you need to implement readers and writers. In order for your readers/writers to be registered and available even if your module has not been loaded (usually after just starting the application), it is advisable to implement them separately in a autoload module. The default location for this is "YourModuleName/autoload/IO".

More information regarding implementing IO and MimeTypes is available at Reader and Writer. An example MimeType is implemented for the example data structure.

The Medical Imaging Interaction Toolkit (MITK)
Copyright (c) German Cancer Research Center (DKFZ)
All rights reserved.
Use of this source code is governed by a 3-clause BSD license that can be
found in the LICENSE file.
#ifndef mitkExampleIOMimeTypes_h
#define mitkExampleIOMimeTypes_h
#include <string>
namespace mitk
class ExampleIOMimeTypes
// Deriving your own MimeType will probably be overkill in most situations.
class ExampleDataStructureMimeType : public CustomMimeType
bool AppliesTo(const std::string &path) const override;
static ExampleDataStructureMimeType EXAMPLE_MIMETYPE();
static std::string EXAMPLE_MIMETYPE_NAME();
// Simpler method of creating a new MimeType
static CustomMimeType EXAMPLE_TWO_MIMETYPE();
static std::string EXAMPLE_TWO_MIMETYPE_NAME();
// Get all example Mime Types
static std::vector<CustomMimeType *> Get();
// purposely not implemented
ExampleIOMimeTypes(const ExampleIOMimeTypes &);
{ You do not need to create your own class to manage your MimeTypes. Instead they can be defined within the Reader/Writer. }

Adding a mapper

If your data type needs a special way to render its data for the user, you need to implement a new mapper. More information can be found at Rendering Concept.

If you meet any difficulties during this How-To, don't hesitate to ask on the MITK mailing list! People there are kind and will try to help you. If you notice that there is an error, or that the code has changed so the way shown here is no longer correct, please open a bug report at .

Example Data Structure.
Definition: mitkExampleDataStructure.h:27
const MITKCORE_EXPORT ScalarType eps
Definition: MitkNewModuleExports.h:15
bool AppliesTo(const std::string &path) const override
Checks if the MimeType can handle file at the given location.
MITKNEWMODULE_EXPORT bool Equal(mitk::ExampleDataStructure *leftHandSide, mitk::ExampleDataStructure *rightHandSide, mitk::ScalarType eps, bool verbose)
Returns true if the example data structures are considered equal.
static std::string EXAMPLE_MIMETYPE_NAME()
Find image slices visible on a given plane.
Definition: RenderingTests.dox:1
ExampleDataStructureMimeType * Clone() const override
static CustomMimeType EXAMPLE_TWO_MIMETYPE()
static std::string EXAMPLE_TWO_MIMETYPE_NAME()
static std::vector< CustomMimeType * > Get()
static ExampleDataStructureMimeType EXAMPLE_MIMETYPE()
#define mitkClassMacro(className, SuperClassName)
Definition: mitkCommon.h:36
double ScalarType
Definition: mitkNumericConstants.h:20