[Insight-developers] itk::Vector,Point,Matrix and vnl_ref's

Luis Ibanez ibanez@cs.unc.edu
Sun, 7 Jan 2001 15:39:03 -0500 (EST)


It is probable that vnl already provide a solution
for our conflicts with itkVector, itkPoint.

Given that the vnl hierarchy has a "ref" class that 
allows to create a vector with user allocated memory. 
It is relatively easy to wrap any array as a vnl_vector. 
Which in some way is like using an Adapter:

T components[N];
vnl_vector_ref<T> vnlVector( N, components );

given that "vnl_vector_ref" class derives from "vnl_vector",
the previous variable "vnlVector" can be used whenever
a vnl_vector is expected.

Even a Java-like conversion on the fly is possible
(though that looks really bad) :

vnl_matrix<double,3,3>  matrix;
double components[3];
matrix * vnl_vector_ref<double>( 3, components);


---

With this option, we can go back and define itkPoint,
itkVector, itkCovariantVector and itkMatrix as classes 
that contain only an array of components, without using 
the vnl_vector internally at all, as Will proposed, and 
as itkPoint was originally designed for the itkMesh.  

Something like:

template<class T, unsigned int ND>
Vector{

private:
  T  m_Components[ ND ];
}



All the mathematical operations of vectors and points
are better defined directly in itkPoint and itkVector,
without using vnl at all. But if eventually, a vnl_vector
is needed from a itkVector, a conversion method can 
construct the corresponding vnl_vector_ref.

like:

vnl_vector_ref<T> Vector<T,ND>::GetVnlVector(void) const;


Matrix * Vector multiplications are solved by creating
an itkMatrix class that is just a data holder, and only
provides this product ( itkMatrix * itkVector). All the
other matrix operations being obtained by creating an 
vnl_matrix_ref and calling the corresponding vnl method.


A version of the geometric classes following this strategy
is available at:

http://www.cs.unc.edu/~ibanez/Insight/Code/Geometry

They are:

itkPoint
itkVector
itkCovariantVector
itkMatrix
itkAffineTransform (this is an adaptation of Pauls's class)

Test files for them are:

VectorTest.cpp
PointTest.cpp
MatrixTest.cpp

---

This approach respects the memory constraints,
provide directly in itk the basic operations between
points, vectors and matrices, and still allows easy 
access to vnl methods.

For example, an itkMatrix can be set to identity by doing:

itkMatrix<double, 4, 4> matrix;
matrix.GetVnlMatrix().set_identity();

---

With this support, the itkAffineTransform can still
be written in a simplified presentation.




Luis