Medical Imaging Interaction Toolkit  2016.11.0
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,
Division of Medical and Biological Informatics.
All rights reserved.
This software is distributed WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE.
See LICENSE.txt or http://www.mitk.org for details.
===================================================================*/
#ifndef _MITK_ExampleDataStructure_H
#define _MITK_ExampleDataStructure_H
#include <MitkNewModuleExports.h>
#include "mitkBaseData.h"
namespace mitk
{
class MITKNEWMODULE_EXPORT ExampleDataStructure : public BaseData
{
public:
// virtual methods that need to be implemented
virtual void UpdateOutputInformation() override;
virtual void SetRequestedRegionToLargestPossibleRegion() override;
virtual bool RequestedRegionIsOutsideOfTheBufferedRegion() override;
virtual bool VerifyRequestedRegion() override;
virtual void SetRequestedRegion(const itk::DataObject *) override;
// Macros
mitkClassMacro(ExampleDataStructure, BaseData);
itkFactorylessNewMacro(Self) itkCloneMacro(Self)
// Get macros
itkGetMacro(Data, std::string);
itkGetConstMacro(Data, std::string);
// Set macros
itkSetMacro(Data, std::string);
void AppendAString(const std::string input);
protected:
ExampleDataStructure();
virtual ~ExampleDataStructure();
// this string is the data stored in this example data structure
std::string m_Data;
private:
};
MITKNEWMODULE_EXPORT bool Equal(mitk::ExampleDataStructure *leftHandSide,
mitk::ExampleDataStructure *rightHandSide,
bool verbose);
} // namespace mitk
#endif /* _MITK_ExampleDataStructure_H */

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,
Division of Medical and Biological Informatics.
All rights reserved.
This software is distributed WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE.
See LICENSE.txt or http://www.mitk.org for details.
===================================================================*/
#ifndef MITKEXAMPLEIOMIMETYPES_H
#define MITKEXAMPLEIOMIMETYPES_H
#include <string>
namespace mitk
{
class ExampleIOMimeTypes
{
public:
// Deriving your own MimeType will probably be overkill in most situations.
class ExampleDataStructureMimeType : public CustomMimeType
{
public:
virtual bool AppliesTo(const std::string &path) const override;
virtual ExampleDataStructureMimeType *Clone() 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();
private:
// purposely not implemented
ExampleIOMimeTypes();
ExampleIOMimeTypes(const ExampleIOMimeTypes &);
};
}
#endif // MITKEXAMPLEIOMIMETYPES_H
Note
{ You do not need to create your own class to manage your MimeTypes. Instead they can be defined within the Reader/Writer. }

Adding readers and writers

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 mitk-.nosp@m.user.nosp@m.s@lis.nosp@m.ts.s.nosp@m.ource.nosp@m.forg.nosp@m.e.net! 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 a http://bugs.mitk.org .