[Insight-developers] transform internal types

M.Staring at lumc.nl M.Staring at lumc.nl
Thu May 6 12:07:14 EDT 2010


Hi Brad,

Thanks for your response!

> 
> Hello,
> 
> I am not sure making the TransformBase a tempted type is a good idea.
> 
> The registration framework uses this class as a polymorphic 
> interface to transforms. So that one interface can be used to 
> manipulate multiple types. This is different then much of ITK 
> which uses templated objects with out explicit virtual 
> interfaces. By making TransformBase have a templeted argument 
> there is no longer a single interface as 
> TransformBase<double> is a different type then 
> TransformBase<float> are different types!

It seems that the registration framework uses the itk::Transform instead
of the itk::TransformBase. That class (itk::Transform) is a templated
class, but it can still be used as an interface in the registration
framework for many derived transforms. 

But, I guess it is easier in other cases to have a non-templated base
class.

> 
> Your initial post indicated that you are trying to pass these 
> arguments to the GPU, and that is the motivation for needing 
> floats. Perhaps it would be easier to use an adaptor design 
> pattern to change the interface of TransformBase, so that the 
> array could be converted when it needs to be uploaded to the GPU?

That is indeed easier, but I like to circumvent the explicit casting and
copying of potentially large arrays.

A second reason is that the double precision of the ParametersType is
often thrown away when specifying a float precision type for the
transform. So, why use double precision, if in the end you don't, or
when it's not needed for an application.

-----------------------------------

I checked the image registration framework, and it seems I'm not lucky:
The ImageToImageMetric defines

  typedef Transform<CoordinateRepresentationType, MovDim,FixDim>
TransformType;

where

typedef typename Superclass::ParametersValueType
CoordinateRepresentationType;

which is again hard-coded to be a double in itk::CostFunction.
Apparently, the registration framework only works with an
itk::Transform<double,dim,dim>. So, even with the proposed patch I'm
still not there, and I can't use the same trick as before (with using
the ScalarType), since the ImageToImageMetric is only templated over
fixed and moving image type.

-----------------------------------

The only (desperate) thing I can think of now is to define an
ITK_GLOBAL_INTERNAL_PRECISION_TYPE_IS_DOUBLE, which defaults to true,
but can be set to false with cmake. Then do something like:

#ifdef ITK_GLOBAL_INTERNAL_PRECISION_TYPE_IS_DOUBLE
  typedef  double  ParametersValueType;
#else
  typedef  float   ParametersValueType;
#endif

in the TransformBase and something similar in CostFunction, and maybe
other places in ITK.

This way I can at least compile an ITK flavour with the required
precision.

(The downside of this solution is that it is not easily possible to
sometimes use float and sometimes use double within one program.)


I hope someone else has a better idea.

> 
> Good luck,
> Brad

Thanks :-)

Regards,

Marius

> 
> On May 6, 2010, at 10:45 AM, M.Staring at lumc.nl wrote:
> 
> 
> 	Hi,
> 	
> 	
> 
> 
> 		However, backward compatibility problems occur:
> 		
> 
> 		1) Transform< float,  indim, outdim > is 
> changed wrt the 
> 		
> 
> 		ParametersType
> 		
> 
> 		2) there is no ParametersType typedef in TransformBase 
> 		
> 
> 		anymore, so code that uses 
> TransformBase::ParametersType does 
> 		
> 
> 		not work anymore.
> 		
> 
> 
> 	When I tried to really implement it, I got in trouble 
> with (2) moving
> 	the ParametersType typedef from TransformBase, because 
> the TransformIO
> 	classes depend on it.
> 	
> 	So, as an alternative solution I added a template 
> parameter TScalarType
> 	to the TransformBase, like
> 	
> 	#ifdef ITK_USE_TRANSFORM_SCALARTYPE_FOR_PARAMETERSTYPE
> 	template <class TScalarType = double >
> 	#endif
> 	
> 	and then do:
> 	
> 	#ifdef ITK_USE_TRANSFORM_SCALARTYPE_FOR_PARAMETERSTYPE
> 	 typedef  TScalarType                     ParametersValueType;
> 	 typedef  Array< ParametersValueType >    ParametersType;
> 	#else
> 	 typedef  double                          ParametersValueType;
> 	 typedef  Array< ParametersValueType >    ParametersType;
> 	#endif
> 	
> 	I also had to make some small changes to TransformIO 
> classes. The
> 	complete patch is attached to this email. The good news 
> is that the
> 	experimental build succeeded.
> 	
> 	With kind regards,
> 	
> 	Marius
> 	<Insight_changes1.patch><ATT00001..txt>
> 
> 
> ========================================================
> 
> Bradley Lowekamp  
> 
> Lockheed Martin Contractor for
> 
> Office of High Performance Computing and Communications
> 
> National Library of Medicine 
> 
> blowekamp at mail.nih.gov
> 
> 
> 
> 


More information about the Insight-developers mailing list