[Insight-developers] RE: Metrics: Removing some template parameters
Luis Ibanez
luis.ibanez@kitware.com
Tue, 19 Feb 2002 21:32:12 -0500
The advantage of : std::vector<T> is that it carries its size
internally, while for (T*) will have to pass an additional integer
around and rely more on user awareness and .... hope !
For the case of Transforms/Metrics/Optimizers we don't need
the array to change size at run time. That is, for a Transform X
the size of its parameters is completly defined. If we switch
to transform Y, this new transform can have a different number
of parameters than X. We want the Metrics to have a pointer to a
itk::Transfrom class and be able to switch transform at run-time.
So, the capabilities of the std::vector<> for growing and shrinking
are not really required.
We could create our own small class:
template <typename T>
class AShortAndClearNameHere {
public:
itkGetMacro( NumberOfElements, unsigned int );
T & operator[]( unsigned int i) { return m_Elements[i]; }
const T & operator[]( unsigned int i) const { return m_Elements[i]; }
Constructor(unsigned int N) { m_Elements = new T[N]; }
Destructor() { delete [] m_Elements; }
private:
unsigned int m_NumberOfElements
T * m_Elements;
}
It is a bit like an itk::Array but with size defined at construction time.
We don't expect this class to manage hundreds of parameters.
In most cases we are talking about 3 to 30 parameters...
That is quite close to a vnl_vector(),...
but the advantage of creating an itk class it to be able to customize
it for our needs instead of having to adapt to vnl. This class is
just a container and will not require to perform any mathematical
operations...
\warning This change propagates all over the toolkit !
Our preliminary test for removing the 4th and 5th template
parameters of itk::Transforms shows that changing itk::Transform
implies to modify itk::AffineTransform and then itk::Image
(because it contains transforms internally), ImageAdaptors,
Optimizers and Metrics... so we may want to do it only once.
Luis
===========================================
Lydia Ng wrote:
>
>As a group should we lock down on a consistent way of passing
>around a variable sized array for all filters
>- in some places people have used (T *) and in other
>places people have used (std::vector<T> &)
>
>Comments?
>
>- Lydia
>