MeVisLab Toolbox Reference
ml::TypedCalculateOutputImageHandler< Derived, NumberOfInputImages, VariableType0, VariableType1, VariableType2, VariableType3 > Class Template Reference

#include <mlTypedHandlers.h>

Inheritance diagram for ml::TypedCalculateOutputImageHandler< Derived, NumberOfInputImages, VariableType0, VariableType1, VariableType2, VariableType3 >:
ml::internal::TypedHandlerBase< CalculateOutputImageHandler, Derived, NumberOfInputImages > ml::CalculateOutputImageHandler

Additional Inherited Members

Public Types inherited from ml::internal::TypedHandlerBase< CalculateOutputImageHandler, Derived, NumberOfInputImages >
enum  
Public Member Functions inherited from ml::internal::TypedHandlerBase< CalculateOutputImageHandler, Derived, NumberOfInputImages >
 TypedHandlerBase ()
void calculateOutputSubImage (SubImage *outImg, SubImage *inImgs, UserThreadData *userThreadData) override
 Overrides the calculateOutputSubImage of CalculateOutputImageHandler.
Public Member Functions inherited from ml::CalculateOutputImageHandler
virtual ~CalculateOutputImageHandler ()
 Destructor.
virtual SubImageBox calculateInputSubImageBox (int, const SubImageBox &outputSubImageBox)
virtual UserThreadDatacreateUserThreadData ()
Static Public Member Functions inherited from ml::internal::TypedHandlerBase< CalculateOutputImageHandler, Derived, NumberOfInputImages >
static void setupKnownProperties (PagedImage *outImg)
static bool verifyProperties (PagedImage *outImg)

Detailed Description

template<typename Derived, int NumberOfInputImages, template< typename, int, typename >class VariableType0 = internal::NoTypes, template< typename, int, typename >class VariableType1 = internal::NoTypes, template< typename, int, typename >class VariableType2 = internal::NoTypes, template< typename, int, typename >class VariableType3 = internal::NoTypes>
class ml::TypedCalculateOutputImageHandler< Derived, NumberOfInputImages, VariableType0, VariableType1, VariableType2, VariableType3 >

TypedCalculateOutputImageHandler can be used as a base class for a custom CalculateOutputImageHandler and supports up to four variable types. Its main feature is that it provides a mapping of the untyped SubImage instances of CalculateOutputImageHandler::calculateOutputSubImage to a call to a method called typedCalculateOutputSubImage() with typed subimages (TSubImage).

A derived class can pass up to four VariableType classes as template parameters and assign either variable types or fixed types to each output and input subimage. This configuration is provided by an anonymous enum that must be included in your derived handler class. This is necessary due to the template magic happening underneath, as all of this needs to be known at compile time.

In addition to that, the class has two static methods:

These methods can be called from Module::calculateOutputImageProperties() to set up the datatypes and read-only flags based on the static information, and to verify whether the given datatypes are valid and compatible with the VariableTypes used. This enables auto-invalidation of the output image if the current data type is not supported by the typedCalculateOutputSubImage instantiations.

Below follows a simple handler that supports one output and one input subimage of the same type:

// Create handler with one input image and MLVariableType0 = StandardTypes.
class ExampleHandler : public TypedCalculateOutputImageHandler<ExampleHandler, 1, StandardTypes>
{
public:
enum {
OutputSubImage_Type = MLVariableType0, // Output subimage uses MLVariableType0, thus it supports StandardTypes.
InputSubImage0_Type = MLVariableType0, // Input subimage 0 uses MLVariableType0 as well, so it will have the same data type as the OutputImage.
InputSubImage0_ReadOnly = true // Input subimage 0 is accessed read-only.
};
ExampleHandler(const PagedImage& outputImage, const Example& module)
{
// store some state here
}
template <typename OUTTYPE>
void typedCalculateOutputSubImage(TSubImage<OUTTYPE>& outSubImage,
const TSubImage<OUTTYPE>& inSubImage0,
UserThreadData* userThreadData)
{
// Compute outSubImage from inSubImage0, both having the same type (one of StandardTypes).
}
};
const int MLVariableType0
Defines to use the result type of variable type 0.

If the above handler should support all datatypes, use AllTypes instead of StandardTypes as template argument.

Now to a more complex example that has different output and input types (only showing the configuration parts):

// Example handler that supports a different output and input subimage type.
class ExampleHandler : public TypedCalculateOutputImageHandler<ExampleHandler, 1, StandardTypes, FloatTypes>
{
public:
enum {
OutputSubImage_Type = MLVariableType0, // Output subimage uses MLVariableType0, thus it supports StandardTypes.
InputSubImage0_Type = MLVariableType1, // Input subimage uses MLVariableType1, thus it supports having a different type than the output image and needs to be of type FloatTypes.
};
...
template <typename OUTTYPE, typename INTYPE0>
void typedCalculateOutputSubImage(TSubImage<OUTTYPE>& outSubImage,
const TSubImage<INTYPE0>& inSubImage0,
UserThreadData* userThreadData)
{
// Compute outSubImage from inSubImage0, input and output types can be different, INTYPE0 can be one of FloatTypes and OUTTYPE can be one of StandardTypes.
}
};
Base class for thread local data that is passed to CalculateOutputImageHandler::calculateOutputSubIma...
const int MLVariableType1
Defines to use the result type of variable type 1.

If the above input subimage should support all standard types, you could pass StandardTypes as second argument. Note that it is important that each template argument specifies on MLVariantType[0-3] and if each output/input subimage should support a different data type on its own (compared to having the same data type for all subimages), you need to pass the same VariableType multiple times (instead of, e.g., passing StandardTypes once, you need to pass it two times if input and output data type shall/may be different).

Another useful configuration is to have a fixed data type on the output image (e.g., because it always generates a MLint16 mask), but to support a variable data type on the input images. The example below illustrates this:

// Handler with fixed output data type and variable input data type on all three input subimages.
class ExampleHandler : public TypedCalculateOutputImageHandler<ExampleHandler,3,StandardTypes>
{
public:
enum {
OutputSubImage_Type = MLint16Type, // Output subimage always is of type MLint16Type.
InputSubImage0_Type = MLVariableType0, // All three subimages have the same variable type (one of StandardTypes).
};
template <typename INTYPE0>
void typedCalculateOutputSubImage(TSubImage<MLint16>& outSubImage,
const TSubImage<INTYPE0>& inSubImage0,
const TSubImage<INTYPE0>& inSubImage1,
const TSubImage<INTYPE0>& inSubImage2,
UserThreadData* userThreadData)
{
// Compute outSubImage from inSubImage[0-2], output subimage is always of type MLint16.
}
@ MLint16Type
Enumerator for the signed 16-bit ML integer type.
Definition mlTypeDefs.h:621

And now finally a more complex example, using all features of the typed handler:

class ExampleHandler : public TypedCalculateOutputImageHandler<ExampleHandler, 3, StandardTypes, StandardTypes>
{
public:
enum {
OutputSubImage_Type = MLVariableType0, // Output subimage types is one of StandardTypes.
InputSubImage1_Type = MLVariableType1, // Both input subimage 0 and 1 have the same variable type that is different from output subimage type
InputSubImage2_Type = MLdoubleType, // Input subimage 2 is always of type MLdouble.
InputSubImage2_ReadOnly = false // Input subimage 2 will be passed non-const and can be written to for temporary calculations.
};
template <typename OUTTYPE, typename INTYPE0>
void typedCalculateOutputSubImage(TSubImage<OUTTYPE>& outSubImage,
const TSubImage<INTYPE0>& inSubImage0,
const TSubImage<INTYPE0>& inSubImage1,
TSubImage<MLdouble>& inSubImage2,
UserThreadData* userThreadData)
{
// Compute outSubImage from inSubImage[0-2].
}
};
@ MLdoubleType
Enumerator for the signed 64-bit ML floating point type.
Definition mlTypeDefs.h:626

Definition at line 942 of file mlTypedHandlers.h.


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