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

michiel mentink michael.mentink at st-hughs.ox.ac.uk
Tue Mar 30 07:18:07 EDT 2010


ah just after posting I found it (figures!)

complete and correct code now:

  const ImageType::DirectionType & direction = image->GetDirection()
  std::cout << "direction: " << std::endl << direction << std::endl <<
std::endl;

  float angleX, angleY, angleZ;
  angleX = angleY = angleZ = 1  *   vnl_math::pi / 180.0;             // in
this case: rotation = 1 degree

  const double cx = vcl_cos(angleX);
  const double sx = vcl_sin(angleX);

  typedef itk::Matrix<double,3,3> Matrix;
  Matrix RotationX;
  Matrix FinalRotation = image->GetDirection();

  std::cout << "sin: " << sx << " Cos: " << cx << std::endl;

  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;

  FinalRotation = direction*RotationX;

  std::cout << "image->GetDirection(): " << std::endl <<
image->GetDirection() << std::endl;
  std::cout << "RotationX: " << std::endl << RotationX << std::endl;
  std::cout << "FinalRotation: " << std::endl << FinalRotation << std::endl;

  image->SetDirection(FinalRotation);

  std::cout << "image->GetDirection(): " << std::endl <<
image->GetDirection() << std::endl;


cheers, Michael





On Tue, Mar 30, 2010 at 12:10 PM, michiel mentink <
michael.mentink at st-hughs.ox.ac.uk> wrote:

> Hello Frederic,
>
> thanks for your suggestion.
>
> although my code was working, I tried your suggestion. Unfortunately, it
> produces
>
> error: no match for ‘operator*’ in
> ‘image.itk::SmartPointer<TObjectType>::operator-> [with TObjectType =
> itk::Image<float, 3u>]()->itk::ImageBase<VImageDimension>::GetDirection
> [with unsigned int VImageDimension = 3u] * RotationX’
>
>
> Anyway, I forgot to mention to use:
>
>   float angleX, angleY, angleZ;
>   angleX = angleY = angleZ = 1 * (3.14/180);
>
> (multiply by pi and divide by 180 degrees, because ITK internally works
> with radians instead of degrees)
>
> Which leads me to the question: vnl has a pi constant, and I remember
> vaguely having seen it somewhere as vnl::PI or something.
> Does anyone know how to convince vnl to hand me pi constant?
>
> cheers, Michael
>
>
>
>
> On Tue, Mar 30, 2010 at 11:55 AM, Frederic Perez <fredericpcx at gmail.com>wrote:
>
>> Hello Michiel,
>>
>> perhaps you could use a const Matrix object after all, since it looks to
>> me that FinalRotation is first built with image->GetDirection() but this
>> value is not actually used, and that the signature of itk::Image's is
>> SetDirection(const DirectionType direction).
>>
>> So here you are, my quickly written proposal (caution, I haven't compiled
>> it):
>>
>>   float angleX, angleY, angleZ;
>>   angleX = angleY = angleZ = 5;
>>
>>   const double cx = vcl_cos(angleX);
>>   const double sx = vcl_sin(angleX);
>>
>>   typedef itk::Matrix<double,3,3> Matrix;
>>   Matrix RotationX;
>>   // Matrix FinalRotation = image->GetDirection(); -- Commented now
>>
>>   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;
>>
>>   const Matrix FinalRotation = direction*RotationX;
>>
>>
>>   std::cout << "image->GetDirection(): " << std::endl <<
>> image->GetDirection() << std::endl;
>>   std::cout << "RotationX: " << std::endl << RotationX << std::endl;
>>   std::cout << "FinalRotation: " << std::endl << FinalRotation <<
>> std::endl;
>>
>>   image->SetDirection(FinalRotation);
>>
>>   std::cout << "image->GetDirection(): " << std::endl <<
>> image->GetDirection() << std::endl;
>>
>> Cheers,
>>
>> Frederic
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20100330/279c2763/attachment.htm>


More information about the Insight-users mailing list