[Insight-users] how to template the image dimension or vector dimesion in template function
Baoyun Li
baoyun_li123 at yahoo.com
Wed Mar 18 17:54:12 EDT 2009
Hi Andreas:
Thanks so much.
I understand why my program is wrong, but don not know the solution.
Thanks again.
baoyun
________________________________
From: Andreas Schuh <andreas.schuh.84 at googlemail.com>
To: Baoyun Li <baoyun_li123 at yahoo.com>
Cc: "insight-users at itk.org" <insight-users at itk.org>
Sent: Wednesday, March 18, 2009 4:33:29 PM
Subject: Re: how to template the image dimension or vector dimesion in template function
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>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20090318/826d349a/attachment.htm>
More information about the Insight-users
mailing list