[Insight-users] itkMatrix
Luis Ibanez
luis . ibanez at kitware . com
Mon, 15 Dec 2003 23:31:18 -0500
Hi Corinne,
A) About the product of ITK rectangular matrices:
You are right, the ITK implementation of the matrix
does not support the generic case of rectangular matrices
product. The main reason for this is that the vnl_matrix
is available, so we only added the ITK layer required for
using matrices for the purpose of image registration.
The fact that the itkMatrix is templated over number of
rows and number of columns make quite hard to implement
the generic MxN by NxK matrix multiplication. It will have
to be a function templated over M,N,K. Something like:
template< class T,
unsigned int M,
unsigned int N,
unsigned int K>
itk::Matrix< T, M, K >
operator*( itk::Matrix< T, M, N >,
itk::Matrix< T, N, K > )
{
....
}
We didn't implement such an operator mainly because you
can easily do the operation by invoking GetVnlMatrix()
on the ITK matrices.
-----
B) About the link error message that you get:
This is due to the fact that VNL uses explicit
instantiations of its templated classes.
ITK does not perform explicit instantiation.
There are advantages and disadvantages on
each approach and their supporters will defend
their decisions passionately....
One of the disadvantages of explicit instantiation
is that the developers must select a set of template
argumets to be instantiated... but a user can always
find an extra type that has not been instantiated
(this is your case).
vnl_matrix_fixed happens to be explicitly
instantiated for double,2,3 but not for
float,2,3
You will find the explicit instantiation in the file
Insight/Utilities/vxl/vnl/vnl_double_3x2.h
you may simply copy and modify this file in order
to create vnl_float_3x2.h by replacing all internal
instances of "double" with "float. Then add this new
file to the CMakeLists.txt file and recompile the
vnl directory in your binary build.
This new explicit instantiation will now show up
in the VNL library and the link error message of
your application should disaper.
Please let us know if you have further questions,
Thanks,
Luis
--------------------------
Corinne Mattmann wrote:
> Hi Luis,
>
> Thanks for your answer. You were right, I had an "old" ITK version. I
> made a CVS update today and VNL-VNL and ITK-VNL multiplications are now
> working fine. But the ITK-ITK still doesn't (I still get the same
> error-message). I guess it is because the operator*(const Self &
> matrix)-function in itkMatrix.txx (see below) has the same return-type
> as the left-hand operand. But if I want to multiply a 2x3 with a 3x2
> matrix, the result is a 2x2 matrix which is not covered by the above
> mentioned function. Is that right?
>
> /**
> * Product by a matrix
> */
> template<class T, unsigned int NRows, unsigned int NColumns >
> Matrix<T, NRows, NColumns>
> Matrix<T, NRows, NColumns>
> ::operator*( const Self & matrix ) const
> {
> Self result;
> result = m_Matrix * matrix.m_Matrix;
> return result;
> }
>
>
>
> I have another problem: A link error. If I use the following code,
> everything works fine.
> itk::Matrix<double,2,3> m4;
> m4.Fill(1.0);
> m4.GetTranspose();
> But if I change the Matrix-Type to float (itk::Matrix<float,2,3> m4;), I
> get the following link error:
>
> Linking...
> Creating library
> D:\packwin\vtkMy\bin\bin\Debug/TestExtrapolateDeformationFieldFilter.lib
> and object
> D:\packwin\vtkMy\bin\bin\Debug/TestExtrapolateDeformationFieldFilter.exp
> TestExtrapolateDeformationFieldFilter.obj : error LNK2001: unresolved
> external symbol "public: void __thiscall
> vnl_matrix_fixed<float,2,3>::fill(float)"
> (?fill@?$vnl_matrix_fixed at M$01$02@@QAEXM at Z)
> TestExtrapolateDeformationFieldFilter.obj : error LNK2001: unresolved
> external symbol "public: class vnl_matrix_fixed<float,3,2> __thiscall
> vnl_matrix_fixed<float,2,3>::transpose(void)const "
> (?transpose@?$vnl_matrix_fixed at M$01$02@@QBE?AV?$vnl_matri
> x_fixed at M$02$01@@XZ)
> D:\packwin\vtkMy\bin\bin\Debug/TestExtrapolateDeformationFieldFilter.exe
> : fatal error LNK1120: 2 unresolved externals
> Error executing link.exe.
>
> Why can't it find the two functions if I declare the Matrix-Type to
> float?
>
> Thanks very much for all your answers,
> Corinne
>
>
>
> -----Original Message-----
> From: Luis Ibanez [mailto:luis . ibanez at kitware . com]
> Sent: Monday, December 15, 2003 1:52 PM
> To: Corinne Mattmann
> Cc: insight-users at itk . org
> Subject: Re: [Insight-users] itkMatrix : bug ID 412
>
>
>
> Hi Corinne,
>
> What version of ITK are you using ?
>
> This seems to be related to a bug in itkMatrix.txx that
> was recently fixed.
>
> It is bug ID=412: http://www . itk . org/Bug/bug . php?op=show&bugid=412&pos=5
>
> The return type of the operator*() in itk::Matrix<> was incorrect. This
> prevented non-square matrices to multiply correctly.
>
> The bug report was made on the users-list:
> http://www . itk . org/pipermail/insight-users/2003-November/005710 . html
>
> The notification for the fix was:
> http://www . itk . org/pipermail/insight-users/2003-December/005726 . html
>
> You may have to update your CVS checkout.
> Please look at the instructions posted in the recent email:
> http://www . itk . org/pipermail/insight-users/2003-December/005930 . html
>
>
> Regards,
>
>
> Luis
>
>