I am trying to use template function to do interpolation for pixel values.
I have two classes of interpolators that implements the interpolation algorithm.
class LinearInterpolator;
class NearestNeighborInterpolator;
I have different classes of images;
class ColorImage;
class GrayScaleImage;
I then have a function that does interpolation utilizing the specific interpolator you pick.
template<typename InterpType, typename ImageType, typename PelType>
bool getValue(const ImageType& image, PelPosition pos, PelType* pelValue);
In my calling code I have
getValue<LinearInterpolator>(ima开发者_如何学运维ge, pos, pelValue);
And I get the compiler error "missing template argument list". My question is: is what I am trying to do completely infeasible or am I missing something here.
All right. The full class declaration for LinearInterpolator actually looks like this...
template <
typename ImageType,
typename OutputPixelType = typename ImageType::Pixel,
typename FieldType = double,
template<typename From, typename To, typename Enable = void> class OutputPixelConverter = StaticCast
>
class LinearInterpolator : public AbstractInterpolator;
So I ended up taking the InterpType out of the type parameter list and passing in an enum as the parameter...
Old >>>>>
template<typename InterpType, typename ImageType, typename PelType>
bool getValue(const ImageType& image, PelPosition pos, PelType* pelValue);
New >>>>>
template<typename ImageType, typename PelType>
bool getValue(InterpType interp, const ImageType& image, PelPosition pos, PelType* pelValue);
If there is a better way of doing it, please comment.
精彩评论