Medical Imaging Interaction Toolkit  2018.4.99-31d1c60d
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 _MITK_ExampleDataStructure_H
#define _MITK_ExampleDataStructure_H
#include "mitkBaseData.h"
namespace mitk
{
class MITKNEWMODULE_EXPORT ExampleDataStructure : public BaseData
{
public:
// 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);
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();
~ExampleDataStructure() override;
// this string is the data stored in this example data structure
std::string m_Data;
private:
};
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 (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
{
public:
// Deriving your own MimeType will probably be overkill in most situations.
class ExampleDataStructureMimeType : public CustomMimeType
{
public:
bool AppliesTo(const std::string &path) const override;
};
static std::string EXAMPLE_MIMETYPE_NAME();
// Simpler method of creating a new 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 .