[Insight-users] itkMatrix error: discards qualifiers??

michiel mentink michael.mentink at st-hughs.ox.ac.uk
Tue Mar 30 06:14:44 EDT 2010


Dear Luis,

thank you for your reply, now I understand what is meant!

Direction is from an image:

  const ImageType::DirectionType & direction = image->GetDirection();

I'm trying to rotate the image by just changing the direction matrix of the
image.

Unfortunately, when I just leave out 'const' from that line, the compiler
complains
that it's not the same type as expected.

Maybe I should just create a new matrix, copy the value of
image->GetDirection()
into it, apply the rotation, and use image->SetDirection()?

cheers, Michael


On Mon, Mar 29, 2010 at 11:04 PM, Luis Ibanez <luis.ibanez at kitware.com>wrote:

> Hi Michiel,
>
>
> It is excellent that you are diving into the code
> looking for deeper understanding !
>
>
> The message that you get indicates that you are
> attempting to change the value of a variable that
> has been declared "const" previously.
>
> The "const" declaration is a promise made to the
> compiler, stating that you will not change the value
> of that variable.
>
> When the compiler catch you breaking that promise,
> it get angry at you and gives you the error message:
>
> "error: passing ‘const   X to  Z discards qualifiers"
>
>
> Where the "qualifier" refers to the "const" property
> of that variable.
>
>
> The error message indicates that you are calling
> the operator=() method on a const matrix (as left
> argument of the = ).
>
>
> You did so, with an expression such as:
>
>
>  const MatrixType  myConstMatrixThatWillNeverChange;
>
>  myConstMatrixThatWillNeverChange = anotherMatrix;
>
>
> This may also happens implicitly if the matrix
> happens to be a member variable of a class,
> and you attempt to do such assignment inside
> a "const" method of the class.
>
>
> If you share with use the exact declaration of your
> "direction" matrix we could tell you more about how
> to get around the problem.
>
>
>       Regards,
>
>
>             Luis
>
>
>
> --------------------------------------------------------------------------
> On Mon, Mar 29, 2010 at 12:01 PM, michiel mentink
> <michael.mentink at st-hughs.ox.ac.uk> wrote:
> >
> > In an autodidactic effort, I'm trying to rotate an image by 'hand', by
> > multiplying the 'direction' matrix of an image by a rotation matrix.
> >
> > To do that, I'm copying bits out of itkEuler3DTransform.txx
> > In that file, a RotationX matrix is defined:
> >
> > Matrix<TScalarType,3,3> RotationX
> >
> > However, when I try doing that, I'm getting the following error:
> >
> > error: passing ‘const itk::Matrix<double, 3u, 3u>’ as ‘this’ argument of
> > ‘const itk::Matrix<T, NRows, NColumns>& itk::Matrix<T, NRows,
> > NColumns>::operator=(const itk::Matrix<T, NRows, NColumns>&) [with T =
> > double, unsigned int NRows = 3u, unsigned int NColumns = 3u]’ discards
> > qualifiers
> >
> > 1) What does this mean?
> > 2) How do I get my beloved Matrix?
> >
> > #include <itkMatrix.h>
> > #include <vnl/vnl_matrix.h>
> >
> >   typedef itk::Matrix<double,3,3> Matrix;
> >
> >   Matrix RotationX;
> >  // ImageType::DirectionType RotationX;
> >
> > //  vnl_matrix_fixed<double,3,3> RotationX;
> >
> >   RotationX[0][0] = 1; RotationX[0][1] =   0; RotationX[0][2] = 0;
> >   RotationX[1][0] = 0; RotationX[1][1] =  cx; RotationX[1][2] = sx;
> >   RotationX[2][0] = 0; RotationX[2][1] = -sx; RotationX[2][2] = cx;
> >
> >   direction = direction*RotationX;
> >
> > cheers,
> >
> > Michael
> >
> >
> >
> >
> > _____________________________________
> > Powered by www.kitware.com
> >
> > Visit other Kitware open-source projects at
> > http://www.kitware.com/opensource/opensource.html
> >
> > Kitware offers ITK Training Courses, for more information visit:
> > http://www.kitware.com/products/protraining.html
> >
> > Please keep messages on-topic and check the ITK FAQ at:
> > http://www.itk.org/Wiki/ITK_FAQ
> >
> > Follow this link to subscribe/unsubscribe:
> > http://www.itk.org/mailman/listinfo/insight-users
> >
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20100330/a47de8f8/attachment.htm>


More information about the Insight-users mailing list