<div dir="ltr"><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small">Hi Sidartha,</div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small"><br></div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small">the code looks OK. The index is [0,0,0] by default, so just setting size is enough. My idea was not to apply translation2, then you would not have to set origin on the resample filter (it would start from [0,0,0]).</div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small"><br></div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small">I think you are forgetting to apply second translation, and you are not applying any transformation to the resample filter. Something like this is needed:</div><div class="gmail_default"><font face="verdana, sans-serif">filter->SetTransform(eulerTransform</font><span style="font-family:verdana,sans-serif">);</span></div><div class="gmail_default"><span style="font-family:verdana,sans-serif"><br></span></div><div class="gmail_default"><span style="font-family:verdana,sans-serif">What results are you getting?</span></div><div class="gmail_default"><div dir="ltr"><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small"><br></div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small">Regards,</div><div class="gmail_default"><font face="verdana, sans-serif">Dženan Zukić, PhD, Senior R&D Engineer, Kitware (Carrboro, N.C.)</font></div></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Apr 13, 2017 at 9:04 AM, sidharta <span dir="ltr"><<a href="mailto:sidharta.gupta93@gmail.com" target="_blank">sidharta.gupta93@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Dženan,<br>
<br>
So I am doing something as follows:<br>
<br>
// Vectors for calculating normal_to_plane - The plane/slice I want to<br>
extract<br>
<br>
Vector3d ST, SP, normal_to_plane; // This is a custom 3D Vector library<br>
ST = traj_start - traj_end; // start and end of the trajectory - vector 1<br>
SP = traj_start - third_point; // start and third point gives another vector<br>
- vector 2<br>
// Now with two vectors I can get the direction of the normal to the plane<br>
normal_to_plane = ST.cross(SP); // cross product essentially<br>
<br>
// Getting angles between normal to the plane and the coordinate axes<br>
double angle_plane_z = std::acos((normal_to_plane[2] * 1) /<br>
norm(normal_to_plane)); // angle between plane and z axis<br>
double angle_plane_y = std::acos((normal_to_plane[1] * 1) /<br>
norm(normal_to_plane)); // angle between plane and y axis<br>
double angle_plane_x = std::acos((normal_to_plane[0] * 1) /<br>
norm(normal_to_plane)); // angle between plane and x axis<br>
<br>
// Instantiate an Euler Transform<br>
typedef itk::Euler3DTransform<double> ETransformType;<br>
ETransformType::Pointer eulerTransform = ETransformType::New();<br>
<br>
// This because - Quote from ITKSoftwareGuide "Rotations are performed<br>
around the origin of physical coordinates—not the image origin nor the image<br>
center"<br>
ETransformType::<wbr>OutputVectorType translation1;<br>
translation1[0] = -origin_dcm[0]; // origin_dcm is the origin of the dicom<br>
translation1[1] = -origin_dcm[1];<br>
translation1[2] = -origin_dcm[2];<br>
eulerTransform->Translate(<wbr>translation1);<br>
eulerTransform->SetRotation(<wbr>angle_plane_x, angle_plane_y, angle_plane_z);<br>
<br>
// Get back to the origin of the dicom<br>
ETransformType::<wbr>OutputVectorType translation2;<br>
translation2[0] = origin_dcm[0];<br>
translation2[1] = origin_dcm[1];<br>
translation2[2] = origin_dcm[2];<br>
<br>
// Instantiate the ResampleFilter<br>
// typedef double InternalPixelType;<br>
// typedef itk::Image< InternalPixelType, Dimension > InternalImageType; //<br>
For clarity<br>
typedef itk::ResampleImageFilter<<wbr>InternalImageType, InternalImageType><br>
ResampleFilterType;<br>
<br>
ResampleFilterType::Pointer filter = ResampleFilterType::New();<br>
<br>
typedef itk::<wbr>NearestNeighborInterpolateImag<wbr>eFunction<<br>
                InternalImageType, double> InterpolatorType;<br>
InterpolatorType::Pointer interpolator = InterpolatorType::New();<br>
filter->SetInterpolator(<wbr>interpolator);<br>
<br>
filter->SetDefaultPixelValue(<wbr>0);<br>
filter->SetOutputSpacing(<wbr>image->GetSpacing());<br>
filter->SetOutputOrigin(image-<wbr>>GetOrigin()); // If I change this to<br>
traj_start, the dicom looks completely off, as in not intended.<br>
filter->SetOutputDirection(<wbr>image->GetDirection()); // I have my doubts about<br>
this too<br>
filter->SetSize(image-><wbr>GetSize()); // Of course, as you suggested, I would<br>
set the thickness here as 1, but I was doing this for testing purposes.<br>
filter->SetInput(image);<br>
<br>
So, what do you think about this code? Am I doing it correctly? I feel<br>
really dumb asking you to check my code but unfortunately I can't find any<br>
relevant example for 3D resampling. Additionally, (no offense) but I don't<br>
get what you mean by "target region index" with respect to the resampling<br>
filter? Do you mean the SetOrigin()? As you also see, I am essentially not<br>
applying any translation to the origin. Just a rotation for testing<br>
purposes.<br>
<span class=""><br>
Thank you for your time.<br>
Best Regards,<br>
</span>Sidharta<br>
<br>
<br>
<br>
<br>
<br>
--<br>
View this message in context: <a href="http://itk-users.7.n7.nabble.com/Extract-slice-from-ResampleFilter-tp38074p38110.html" rel="noreferrer" target="_blank">http://itk-users.7.n7.nabble.<wbr>com/Extract-slice-from-<wbr>ResampleFilter-tp38074p38110.<wbr>html</a><br>
<div class="HOEnZb"><div class="h5">Sent from the ITK - Users mailing list archive at Nabble.com.<br>
______________________________<wbr>_______<br>
Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at<br>
<a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/<wbr>opensource/opensource.html</a><br>
<br>
Kitware offers ITK Training Courses, for more information visit:<br>
<a href="http://www.kitware.com/products/protraining.php" rel="noreferrer" target="_blank">http://www.kitware.com/<wbr>products/protraining.php</a><br>
<br>
Please keep messages on-topic and check the ITK FAQ at:<br>
<a href="http://www.itk.org/Wiki/ITK_FAQ" rel="noreferrer" target="_blank">http://www.itk.org/Wiki/ITK_<wbr>FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://public.kitware.com/mailman/listinfo/insight-users" rel="noreferrer" target="_blank">http://public.kitware.com/<wbr>mailman/listinfo/insight-users</a><br>
</div></div></blockquote></div><br></div>