[Insight-users] use Euler2DTransform or Euler3DTransform in a template function: template<class ImageDimension> void TempFunc(...)
Haiyong Xu
haiyeong at gmail.com
Wed Mar 24 08:53:34 EDT 2010
Hi there,
I'm writing a template function with ImageType as a template argument.
The question is that how can I create a itk::Transform<> instance
according to the image's dimension.
Euler2DTransform and Euler3DTransform are concrete child classes of
abstract class itk::Transform< TScalarType, NInputDimensions,
NOutputDimensions>.
An obvious way to do this is following:
/*******************************
other_itk_template_class; // this class takes ImgeType as template argument
1: if (ImateType::ImageDimension == 2)
2: other_itk_template_class->SetTransform(
Euler2DTransform<double>::New() );
3: else if (ImageDImension == 3)
4: other_itk_template_class->SetTransform(
Euler3DTransform<double>::New() );
// this causes a compile error. Because after instantiation of
other_itk_template_class, it only processes either 2D or 3D Image
object, therefore the Transform object have to be either 2D or 3D. If
we instantiate the other_itk_template_class with 2D image data, line 4
causes compile error; if we instantiate the other_itk_template_class
with 3D image data, line 2 causes compile error.
******************************/
I tried to use "#define", but it does not work either:
/***********************************
#define NTransform(num, name)
itk::Euler##num##DTransform<double>::Pointer name
NTransform(InputImage::ImageDimension, transform);
**********************************/
Appreciate any hints or helps.
--Haiyong Xu
More information about the Insight-users
mailing list