[Insight-developers] Statistics Refactoring : A few problems

Karthik Krishnan Karthik.Krishnan at kitware.com
Thu Jul 21 17:46:41 EDT 2005


The goal was of using partial specialization here was 2 things.

1. The Statistics framework has things like

class Sample< MeasurementVectorType >
{
itkStaticConstMacro( MeasurementVectorSize, unsigned int, 
MeasurementVectorType::Length );
}

and classes using these static const macros all over the place.

Partial specialization would help preserve the static const macros in 
cases where fixed length containers were used, by replacing the above 
line with

class Sample< MeasurementVectorType >
{
itkStaticConstMacro(MeasurementVectorSize, unsigned int,
MeasurementVectorTraits< MeasurementVectorType >::MeasurementVectorLength);
}

This would let people retain those macros and not break their code every 
time somebody had something like SampleType::MeasurementVectorSize


2. Sure enough as Jim pointed out in the earlier mail and as you've 
pointed out below, it is possible to do this with template function 
overloading.

  template<class TValueType, unsigned int TLength>
  unsigned GetSize(FixedArray<TValueType, Tlength)
  { return Tlength; }

 - The static const macros can't be preserved.

 - I need an argument to be able to use this. I couldn't preserve typdefs, for instance people saying HistogramType::MeanType must now be itk::Array< double > and not automatically inferred from the type( Array< double > for variable length vectors and FixedArray< double, MeasurementVectorLength > for fixed length vectors (as was the case until now)).

  - Have people set the measurement vector size explicitly. For instance you have to have an explicit call stating sample->SetMeasurementVectorSize( s ); You cannot do this in the default constructor as in 
    sample->SetMeasurementVectorSize( MeasurementVectorTraits< MeasurementVectorType >::MeasurementVectorLength ); which is the correct value for fixed length containers and 0 if not, in which case you will need to explicitly set it yourself.
 
There is essentially a little bit of an API change that users may have with the statistics framework when the static const macro is not available any more.

But I guess that may be unavoidable.

THanks
Regards
Karthik






Kris Thielemans wrote:

>Hi Karthik
>
>I really am not familiar with ITK yet, and definitely not with what
>you're trying to do. So I'll probably miss the ball completely. I
>apologise in advance.
>
>Reading the WIKI I see
>--------
> MeasurementVectorTraits< MeasurementVectorType >::GetSize()
>
> This returns the length of MeasurementVectorType, which will be the
>true  length of a FixedArray, Vector, vnl_vector_fixed, Point etc and 0
>otherwise
>-------
>
>This is a bit different from what you said in the email
>
>  
>
>>I need something like:
>>
>>template<class TValueType, unsigned int TLength> class
>>MeasurementVectorTraits<FixedArray<TValueType, TLength > > {
>>public:
>>  itkStaticConstMacro( MeasurementVectorLength, unsigned int, 
>>TLength );  .......
>>}
>>
>>    
>>
>
>I wonder though about a few things:
>
>- how useful is it to have a GetSize (or MeasurementVectorLength) that's
>wrong for variable length arrays? Won't you then have to write code that
>treats variable length arrays differently anyway?
>
>- is your probably not solvable by not using traits, but by using
>function overloading:
>
>  template<class TValueType, unsigned int TLength>
>  unsigned GetSize(FixedArray<TValueType, Tlength)
>  { return Tlength; }
>
>  // and so on for other types of fixed arrays and indeed variable
>length
>
>VC6.0 can usually handle such function overloads (although not always,
>and don't ask me when it can't). 
>
>Of course, the above function approach does not work for compile time
>constants. 
>
>Kris Thielemans
>Hammersmith Imanet Ltd, part of GE Healthcare
>Du Cane Road
>London W12 0NN
>UK
>http://www.HammersmithImanet.com/~kris
> 
>
>
>  
>


More information about the Insight-developers mailing list