[Insight-users] how to template the image dimension or vector dimesion in template function
Andreas Schuh
andreas.schuh.84 at googlemail.com
Wed Mar 18 17:33:29 EDT 2009
Hi Baoyun,
use the static constant itk::Vector::Dimension instead.
typedef typename itk::Vector< double, VectorPixelType::Dimension >
MeasurementVectorType;
itk::Vector::GetVectorDimension() is a static method that has to be
evaluated at runtime to get the number of components. For template
arguments you need constant values that can be derived at compile time.
itk::Vector::Dimension, therefore, is a public static const class
member, instead.
--
regards
Andreas
Baoyun Li schrieb:
> Dear Andreas and all:
>
> Can you please teach me how to template the image dimension or vector
> dimesion in template function.
>
> In the following template function, if I give the vector dimension as
>
> typedef typename itk::Vector< double,NumberOfComponents>
> MeasurementVectorType;
> where Numberof compoents is obtained as trait
> const unsigned int
> NumberOfComponents=VectorPixelType::GetVectorDimension();
>
> The program cannot be build.
>
> Why and how to solve the problem?
>
> Thanks
>
> Baoyun
>
>
> template <unsigned int Dim,unsigned int NumberOfComponents1,class
> TInputFilter, class TOutputFilter>
> void EMClustering( typename TInputFilter::Pointer& inputfilter,
> typename TOutputFilter::Pointer& outputfilter)
> {
> typedef typename TInputFilter::PixelType VectorPixelType;
> typedef typename TInputFilter::PixelType::SizeType Num;
> const unsigned int
> NumberOfComponents=VectorPixelType::GetVectorDimension();
> const unsigned int Dim1=TInputFilter::GetImageDimension();
>
> typedef typename itk::Vector< double,NumberOfComponents>
> MeasurementVectorType;
> typedef typename itk::Statistics::ListSample< MeasurementVectorType
> > SampleType;
> // SampleType::Pointer sample = SampleType::New();
> // sample->SetMeasurementVectorSize(NumberOfComponents );
> // MeasurementVectorType mv;
>
> };
>> ml>
>
More information about the Insight-users
mailing list