in<br>/itkEuler3DTransform.txx<br>the rotation is applied either in X Y Z order, or Z X Y order (standard), where Y rotation is applied first.<br><br>Indeed, if I try different orders of rotation, I get different outcomes. I suppose this is due to round-off<br>
errors. <br>Why is Z X Y chosen as the standard way of multiplication?<br><br><br>Z Y X<br>image->GetDirection(): <br> 0.999695 0.0171452 0.0177517<br>-0.0174497 0.999701 0.0171452<br>-0.0174524 -0.0174497 0.999695<br>
<br>X Y Z<br>image->GetDirection(): <br>0.999695 0.0174497 0.0174524<br>-0.0177543 0.99969 0.0174497<br>-0.0171425 -0.0177543 0.999695<br><br>Z X Y<br>image->GetDirection(): <br> 0.99969 0.0174497 0.0177543<br>
-0.0177543 0.999695 0.0171425<br>-0.0174497 -0.0174524 0.999695<br><br>cheers, <br><br>Michael<br><br><br><br><br><br><div class="gmail_quote">On Tue, Mar 30, 2010 at 12:18 PM, michiel mentink <span dir="ltr"><<a href="mailto:michael.mentink@st-hughs.ox.ac.uk">michael.mentink@st-hughs.ox.ac.uk</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>ah just after posting I found it (figures!)<br><br>complete and correct code now:<div class="im">
<br><br> const ImageType::DirectionType & direction = image->GetDirection()<br></div> std::cout << "direction: " << std::endl << direction << std::endl << std::endl;<br>
<br> float angleX, angleY, angleZ;<br> angleX = angleY = angleZ = 1 * vnl_math::pi / 180.0; // in this case: rotation = 1 degree<div class="im"><br><br> const double cx = vcl_cos(angleX);<br> const double sx = vcl_sin(angleX);<br>
<br> typedef itk::Matrix<double,3,3> Matrix;<br> Matrix RotationX;<br> Matrix FinalRotation = image->GetDirection();<br><br></div> std::cout << "sin: " << sx << " Cos: " << cx << std::endl;<div class="im">
<br>
<br> RotationX[0][0] = 1; RotationX[0][1] = 0; RotationX[0][2] = 0; <br> RotationX[1][0] = 0; RotationX[1][1] = cx; RotationX[1][2] = sx; <br> RotationX[2][0] = 0; RotationX[2][1] = -sx; RotationX[2][2] = cx;<br>
<br></div><div class="im"> FinalRotation = direction*RotationX;<br><br> std::cout << "image->GetDirection(): " << std::endl << image->GetDirection() << std::endl;<br> std::cout << "RotationX: " << std::endl << RotationX << std::endl;<br>
std::cout << "FinalRotation: " << std::endl << FinalRotation << std::endl;<br> <br> image->SetDirection(FinalRotation);<br><br> std::cout << "image->GetDirection(): " << std::endl << image->GetDirection() << std::endl;<br>
<br><br></div>cheers, Michael<div><div></div><div class="h5"><br><br><br><br><br><br><div class="gmail_quote">On Tue, Mar 30, 2010 at 12:10 PM, michiel mentink <span dir="ltr"><<a href="mailto:michael.mentink@st-hughs.ox.ac.uk" target="_blank">michael.mentink@st-hughs.ox.ac.uk</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hello Frederic,<br><br>thanks for your suggestion.<br><br>although my code was working, I tried your suggestion. Unfortunately, it produces<br>
<br>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’<br>
<br><br>Anyway, I forgot to mention to use:<br><br> float angleX, angleY, angleZ;<br> angleX = angleY = angleZ = 1 * (3.14/180);<br><br>(multiply by pi and divide by 180 degrees, because ITK internally works with radians instead of degrees)<br>
<br>Which leads me to the question: vnl has a pi constant, and I remember vaguely having seen it somewhere as vnl::PI or something.<br>Does anyone know how to convince vnl to hand me pi constant?<br><br>cheers, Michael<div>
<div></div><div><br>
<br><br><br><div class="gmail_quote">On Tue, Mar 30, 2010 at 11:55 AM, Frederic Perez <span dir="ltr"><<a href="mailto:fredericpcx@gmail.com" target="_blank">fredericpcx@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hello Michiel,<br><br>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).<br>
<br>So here you are, my quickly written proposal (caution, I haven't compiled it):<br><br><div class="gmail_quote"><div> float angleX, angleY, angleZ;<br> angleX = angleY = angleZ = 5;<br><br> const double cx = vcl_cos(angleX);<br>
const double sx = vcl_sin(angleX);<div> <br> typedef itk::Matrix<double,3,3> Matrix;<br> Matrix RotationX;<br></div></div> <span style="background-color: rgb(255, 204, 204);">// Matrix FinalRotation = image->GetDirection(); -- Commented now <br>
</span><div><div><br> RotationX[0][0] = 1; RotationX[0][1] = 0; RotationX[0][2] = 0; <br> RotationX[1][0] = 0; RotationX[1][1] = cx; RotationX[1][2] = sx; <br>
RotationX[2][0] = 0; RotationX[2][1] = -sx; RotationX[2][2] = cx;<br><br></div></div> <span style="background-color: rgb(255, 255, 153);">const Matrix FinalRotation = direction*RotationX;</span><div><br><br>
std::cout << "image->GetDirection(): " << std::endl << image->GetDirection() << std::endl;<br>
std::cout << "RotationX: " << std::endl << RotationX << std::endl;<br> std::cout << "FinalRotation: " << std::endl << FinalRotation << std::endl;<br>
<br>
image->SetDirection(FinalRotation);<br><br> std::cout << "image->GetDirection(): " << std::endl << image->GetDirection() << std::endl;<br><br></div>Cheers,<br><br>Frederic<br>
</div>
<br><div style="display: inline;"></div>
</blockquote></div><br>
</div></div></blockquote></div><br>
</div></div></blockquote></div><br>