[Insight-developers] partial template specialization for functions

gang song songgang97 at gmail.com
Wed May 4 17:54:20 EDT 2011


Thanks. This is very helpful -- to use the function template with the
types defined over image dimension!


-Gang


2011/5/4 Gaëtan Lehmann <gaetan.lehmann at jouy.inra.fr>:
>
> Le 4 mai 11 à 00:34, gang song a écrit :
>
>> Hi,
>>
>> I want to check the partial template specialization alternative
>> solution for functions in ITK. One example is in
>> LinearInterpolateImageFunction.h, the function
>> EvaluateAtContinuousIndex() implemented "template specialization"
>> using function overloading as:
>>
>>
>> template< class TInputImage, class TCoordRep = double >
>> class ITK_EXPORT LinearInterpolateImageFunction:
>>  public InterpolateImageFunction< TInputImage, TCoordRep >
>> {
>> ...
>> virtual inline OutputType EvaluateAtContinuousIndex(const
>>                                                     ContinuousIndexType &
>>                                                     index) const
>>  {
>>   return this->EvaluateOptimized(Dispatch< ImageDimension >(), index);
>>  }
>>
>>
>>  struct DispatchBase {};
>>  template< unsigned int >
>>  struct Dispatch: DispatchBase {};
>>
>>  inline OutputType EvaluateOptimized(const Dispatch< 0 > &,
>>                                     const ContinuousIndexType & index)
>> const
>>  {
>>   return 0;
>>  }
>>
>>  inline OutputType EvaluateOptimized(const Dispatch< 1 > &,
>>                                     const ContinuousIndexType & index)
>> const
>>  {
>>  // something else ...
>>  }
>> }
>>
>>
>>
>>
>> Is this the canonical way to make the function partial specialization ?
>
>
> Hi,
>
> This is one way to do that.
> For an example of another way, without using a dispatch class, you can look
> at
>
>  PerimeterFromInterceptCount
>
> in
>
>  Modules/Nonunit/Review/include/itkShapeLabelMapFilter.h
>
> Regards,
>
> Gaëtan
>
>
> --
> Gaëtan Lehmann
> Biologie du Développement et de la Reproduction
> INRA de Jouy-en-Josas (France)
> tel: +33 1 34 65 29 66    fax: 01 34 65 29 09
> http://voxel.jouy.inra.fr  http://www.itk.org
> http://www.mandriva.org  http://www.bepo.fr
>
>


More information about the Insight-developers mailing list