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.
#ifndef mitkExampleDataStructure_h
#define mitkExampleDataStructure_h
#include <MitkNewModuleExports.h>
{
class MITKNEWMODULE_EXPORT ExampleDataStructure : public BaseData
{
public:
void UpdateOutputInformation() override;
void SetRequestedRegionToLargestPossibleRegion() override;
bool RequestedRegionIsOutsideOfTheBufferedRegion() override;
bool VerifyRequestedRegion() override;
void SetRequestedRegion(const itk::DataObject *) override;
itkFactorylessNewMacro(Self);
itkCloneMacro(Self);
itkGetMacro(Data, std::string);
itkGetConstMacro(Data, std::string);
itkSetMacro(Data, std::string);
void AppendAString(const std::string input);
protected:
ExampleDataStructure();
~ExampleDataStructure() override;
std::string m_Data;
private:
};
bool verbose);
}
#endif
#define mitkClassMacro(className, SuperClassName)
Find image slices visible on a given plane.
MITKCORE_EXPORT const ScalarType eps
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.
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.
#ifndef mitkExampleIOMimeTypes_h
#define mitkExampleIOMimeTypes_h
#include <string>
{
class ExampleIOMimeTypes
{
public:
class ExampleDataStructureMimeType : public CustomMimeType
{
public:
bool AppliesTo(
const std::string &path)
const override;
};
static std::vector<CustomMimeType *>
Get();
private:
ExampleIOMimeTypes();
ExampleIOMimeTypes(const ExampleIOMimeTypes &);
};
}
#endif
ExampleDataStructureMimeType * Clone() const override
bool AppliesTo(const std::string &path) const override
Checks if the MimeType can handle file at the given location.
ExampleDataStructureMimeType()
static std::string EXAMPLE_MIMETYPE_NAME()
static std::string EXAMPLE_TWO_MIMETYPE_NAME()
static CustomMimeType EXAMPLE_TWO_MIMETYPE()
static ExampleDataStructureMimeType EXAMPLE_MIMETYPE()
static std::vector< CustomMimeType * > Get()
- Note
- { 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 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 at https://phabricator.mitk.org/maniphest/ .