<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">Hello Carlos,<div><br></div><div>The reason the transform needs to be inverted is the way the transform is applied to meshes vs resampling for images.</div><div><br></div><div>For resampling images the transform is used to map from the physical space of the output image domain to the physical space of the input image domain. Where as for meshes it's directly applied to the input physical points.</div><div><br></div><div>Please checkout section 2.9 of the ITK software guide[1] for more information on Geometric Transforms and the ResampleImageFilter.</div><div><br></div><div><br></div><div>HTH,</div><div>Brad</div><div><br></div><div>[1] <a href="http://www.itk.org/ITK/help/documentation.html">http://www.itk.org/ITK/help/documentation.html</a></div><div><br><div><div>On Sep 24, 2015, at 9:43 AM, Carlos Henrique Villa Pinto <<a href="mailto:chvillap@gmail.com">chvillap@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><div dir="ltr">Hi, Andras. Thank you very much for your answer.<div><br></div><div>I'm not very experienced with B-Spline transforms and 3D meshes, so maybe this is a silly question, but... why exactly do I need inverse transforms (forward for the mesh, inverse for the image), considering that I want to deform both the same way? Could you elaborate, or perhaps give me some links with explanations, please?</div><div><br></div><div>By the way, I generated a deformation field from the transform I created, and visualized/played with it in 3D Slicer. As expected, applying such transform to the original MR image in 3D Slicer results in the same deformed image that I get using my ITK code. However, when I apply the same transform to the original mesh (again in 3D Slicer), the result is a deformed mesh that is neither the same result that I obtain with my ITK code (using the itk::TransformMeshFilter class) nor the expected result (a mesh aligned to the brain structure in the deformed image). And applying the inverse transform (also calculated in 3D Slicer) doesn't give me better results at all. So now I'm even more confused.</div><div><br></div><div>Any other insights would be greatly appreciated.</div><div><br></div><div>Thanks.</div><div>[]s<br></div></div><div class="gmail_extra"><br><div class="gmail_quote">2015-09-23 10:56 GMT-03:00 Andras Lasso <span dir="ltr"><<a href="mailto:lasso@queensu.ca" target="_blank">lasso@queensu.ca</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div lang="EN-US" link="blue" vlink="purple">
<div><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">You need forward transform to deform a mesh and inverse (resampling) transform to transform the corresponding image. Make sure the transform that you generate
is invertible:<u></u><u></u></span></p><p><u></u><span style="font-size:11.0pt;font-family:Symbol;color:#1f497d"><span>·<span style="font:7.0pt "Times New Roman"">
</span></span></span><u></u><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">Displace control points just so much that there is no “folding” in the field (two different areas are transformed to the same area)<u></u><u></u></span></p><p><u></u><span style="font-size:11.0pt;font-family:Symbol;color:#1f497d"><span>·<span style="font:7.0pt "Times New Roman"">
</span></span></span><u></u><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">Make the grid larger than the image so that the displacements are all zero at the boundary (as ITK transforms cannot extrapolate to have smooth boundary
conditions but they just cut the displacement to 0; if there is discontinuity in the field then inverse computation will fail)<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">You can play with non-linear transforms, import/export from ITK, visualize them, invert them, combine them, apply to volumes, surfaces, points, etc. in 3D Slicer,
see:<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size: 10pt; font-family: 'Segoe UI', sans-serif;"><a href="http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Modules/Transforms" target="_blank">http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Modules/Transforms</a><u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">Andras<u></u><u></u></span></p><p class="MsoNormal"><a name="14ffa7e366cd0707__MailEndCompose"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"><u></u> <u></u></span></a></p><p class="MsoNormal"><b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">From:</span></b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"> Community [mailto:<a href="mailto:community-bounces@itk.org" target="_blank">community-bounces@itk.org</a>]
<b>On Behalf Of </b>Carlos Henrique Villa Pinto<br>
<b>Sent:</b> September 23, 2015 9:38 AM<br>
<b>To:</b> <a href="mailto:insight-users@itk.org" target="_blank">insight-users@itk.org</a><br>
<b>Subject:</b> [ITK] [ITK-users] Applying a B-Spline transform to a 3D mesh<u></u><u></u></span></p><div><div class="h5"><p class="MsoNormal"><u></u> <u></u></p>
<div>
<div><p class="MsoNormal"><span style="font-size:9.5pt">Hi everyone,<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"><u></u> <u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt">I have a 3D MR brain image and a set of 3D meshes of different brain structures aligned to it. I'm trying to write a very simple program in which I create a B-Spline transform (with random parameters) and apply
such transform to the image and to the meshes in order to deform them all together.<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"><u></u> <u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt">Am I wrong to assume that, if I apply exactly the same transform to an image and to a mesh which is perfectly aligned to a specific brain structure in such image, the resulting deformed mesh should be aligned
to the same brain structure in the deformed image? Because that's not what it's happening in practice. The transform deforms the meshes to some extent, but the deformed meshes do not match the brain structures in the deformed image, even though the applied
transform is the same for all. So I guess I must be doing something wrong...<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"><u></u> <u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt">The source code is below. I'm using ITK 4.8, and the MR image (NIfTI) and meshes (VTK) used in my tests come from the NAC Brain Atlas (<a href="https://www.slicer.org/publications/item/view/2037" target="_blank">https://www.slicer.org/publications/item/view/2037</a>).<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"><u></u> <u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt">Any insight about what is possibly causing these results would be appreciated. Thanks in advance.<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"><u></u> <u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"><u></u> <u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt">#include <iostream><u></u><u></u></span></p>
</div>
<div>
<div><p class="MsoNormal"><span style="font-size:9.5pt">#include <vector><u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt">#include <cstdlib><u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt">#include <cstring><u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt">#include <cmath><u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt">#include <ctime><u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"><u></u> <u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt">#include <itkImage.h><u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt">#include <itkImageFileReader.h><u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt">#include <itkImageFileWriter.h><u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt">#include <itkMesh.h><u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt">#include <itkMeshFileReader.h><u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt">#include <itkMeshFileWriter.h><u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt">#include <itkBSplineTransform.h><u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt">#include <itkResampleImageFilter.h><u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt">#include <itkTransformMeshFilter.h><u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt">#include <itkLinearInterpolateImageFunction.h><u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"><u></u> <u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt">int main(int argc, char const *argv[])<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt">{<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> if (argc < 3)<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> {<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> std::cerr << "Usage: " << argv[0]<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> << " gridNodesInOneDimension inputImage [inputMesh1, ...]"<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> << std::endl;<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"><u></u> <u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> return EXIT_FAILURE;<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> }<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"><u></u> <u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> srand(time(NULL));<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"><u></u> <u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> const int splineOrder = 3;<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> const int dimensions = 3;<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"><u></u> <u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> typedef itk::Image<double, dimensions> ImageType;<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> typedef itk::ImageFileReader<ImageType> ImageReaderType;<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> typedef itk::ImageFileWriter<ImageType> ImageWriterType;<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"><u></u> <u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> typedef itk::Mesh<double, dimensions> MeshType;<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> typedef itk::MeshFileReader<MeshType> MeshReaderType;<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> typedef itk::MeshFileWriter<MeshType> MeshWriterType;<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"><u></u> <u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> typedef itk::BSplineTransform<double, dimensions, splineOrder><u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> BSplineTransformType;<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> typedef itk::ResampleImageFilter<ImageType, ImageType, double><u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> ResampleImageFilterType;<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> typedef itk::TransformMeshFilter<MeshType, MeshType, BSplineTransformType><u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> TransformMeshFilterType;<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> typedef itk::LinearInterpolateImageFunction<ImageType, double><u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> LinearInterpolatorType;<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"><u></u> <u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> // ============================================================================================<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> // Reading the input image<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> // ============================================================================================<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"><u></u> <u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> ImageReaderType::Pointer imageReader = ImageReaderType::New();<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> imageReader->SetFileName(argv[2]);<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> imageReader->Update();<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"><u></u> <u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> ImageType::Pointer inputImage = imageReader->GetOutput();<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"><u></u> <u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> // ============================================================================================<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> // Reading the input meshes<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> // ============================================================================================<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"><u></u> <u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> std::vector<MeshType::Pointer> inputMeshVector;<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"><u></u> <u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> for (int i = 3; i < argc; ++i)<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> {<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> MeshReaderType::Pointer meshReader = MeshReaderType::New();<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> meshReader->SetFileName(argv[i]);<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> meshReader->Update();<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"><u></u> <u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> MeshType::Pointer inputMesh = meshReader->GetOutput();<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> inputMeshVector.push_back(inputMesh);<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> }<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"><u></u> <u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> // ============================================================================================<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> // Generating the parameters of the B-Spline transform<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> // ============================================================================================<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"><u></u> <u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> const int gridNodesInOneDimension = atoi(argv[1]);<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"><u></u> <u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> BSplineTransformType::Pointer bsplineTransform = BSplineTransformType::New();<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> BSplineTransformType::PhysicalDimensionsType physicalDimensions;<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> BSplineTransformType::MeshSizeType meshSize;<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"><u></u> <u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> for (int i = 0; i < dimensions; ++i)<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> {<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> physicalDimensions[i] = inputImage->GetSpacing()[i] *<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> static_cast<double>(inputImage->GetLargestPossibleRegion().GetSize()[i] - 1);<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> }<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> meshSize.Fill(gridNodesInOneDimension - splineOrder);<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> <u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> bsplineTransform->SetTransformDomainOrigin(inputImage->GetOrigin());<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> bsplineTransform->SetTransformDomainDirection(inputImage->GetDirection());<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> bsplineTransform->SetTransformDomainPhysicalDimensions(physicalDimensions);<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> bsplineTransform->SetTransformDomainMeshSize(meshSize);<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"><u></u> <u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> BSplineTransformType::ParametersType parameters(bsplineTransform->GetNumberOfParameters());<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"><u></u> <u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> double minValue = -20.0;<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> double maxValue = 20.0;<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> for (int i = 0; i < bsplineTransform->GetNumberOfParameters(); ++i)<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> {<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> parameters[i] = (double) rand() / RAND_MAX * (maxValue - minValue) + minValue;<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> std::cout << parameters[i] << " ";<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> }<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> std::cout << std::endl;<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"><u></u> <u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> bsplineTransform->SetParameters(parameters);<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"><u></u> <u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> // ============================================================================================<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> // Applying the B-Spline transform to the input image<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> // ============================================================================================<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"><u></u> <u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> LinearInterpolatorType::Pointer linearInterpolator = LinearInterpolatorType::New();<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"><u></u> <u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> ResampleImageFilterType::Pointer resampleFilter = ResampleImageFilterType::New();<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> resampleFilter->SetTransform(bsplineTransform);<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> resampleFilter->SetInterpolator(linearInterpolator);<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> resampleFilter->SetInput(inputImage);<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> resampleFilter->SetSize(inputImage->GetLargestPossibleRegion().GetSize());<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> resampleFilter->SetOutputStartIndex(inputImage->GetLargestPossibleRegion().GetIndex());<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> resampleFilter->SetOutputOrigin(inputImage->GetOrigin());<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> resampleFilter->SetOutputSpacing(inputImage->GetSpacing());<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> resampleFilter->SetOutputDirection(inputImage->GetDirection());<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> resampleFilter->Update();<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"><u></u> <u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> // ============================================================================================<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> // Applying the B-Spline transform to the meshes<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> // ============================================================================================<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"><u></u> <u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> std::vector<MeshType::Pointer> outputMeshVector;<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"><u></u> <u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> for (int i = 0; i < inputMeshVector.size(); ++i)<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> {<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> TransformMeshFilterType::Pointer transformFilter = TransformMeshFilterType::New();<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> transformFilter->SetInput(inputMeshVector[i]);<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> transformFilter->SetTransform(bsplineTransform);<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> transformFilter->Update();<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"><u></u> <u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> outputMeshVector.push_back(transformFilter->GetOutput());<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> }<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"><u></u> <u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> // ============================================================================================<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> // Writing the transformed image<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> // ============================================================================================<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"><u></u> <u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> char outputImageFileName[256];<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> int length1 = strlen(argv[2]) - 4;<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"><u></u> <u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> strncpy(outputImageFileName, argv[2], length1);<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> outputImageFileName[length1] = '\0';<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> strcat(outputImageFileName, "_transformed.nii");<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"><u></u> <u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> ImageWriterType::Pointer imageWriter = ImageWriterType::New();<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> imageWriter->SetFileName(outputImageFileName);<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> imageWriter->SetInput(resampleFilter->GetOutput());<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> imageWriter->Update();<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"><u></u> <u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> // ============================================================================================<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> // Writing the transformed meshes<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> // ============================================================================================<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"><u></u> <u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> for (int i = 0; i < outputMeshVector.size(); ++i)<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> {<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> char outputMeshFilename[256];<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> int length2 = strlen(argv[i + 3]) - 4;<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"><u></u> <u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> strncpy(outputMeshFilename, argv[i + 3], length2);<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> outputMeshFilename[length2] = '\0';<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> strcat(outputMeshFilename, "_transformed.vtk");<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"><u></u> <u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> MeshType::Pointer outputMesh = outputMeshVector[i];<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"><u></u> <u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> MeshWriterType::Pointer meshWriter = MeshWriterType::New();<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> meshWriter->SetFileName(outputMeshFilename);<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> meshWriter->SetInput(outputMesh);<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> meshWriter->Update();<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> }<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"><u></u> <u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"> return EXIT_SUCCESS;<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt">}<u></u><u></u></span></p>
</div>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"><u></u> <u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt"><u></u> <u></u></span></p>
</div>
<div><p class="MsoNormal"><span style="font-size:9.5pt">[]s<u></u><u></u></span></p>
</div>
<div><p class="MsoNormal"><u></u> <u></u></p>
</div><p class="MsoNormal">-- <u></u><u></u></p>
<div>
<div><p class="MsoNormal">Carlos Henrique Villa Pinto<u></u><u></u></p>
<div><p class="MsoNormal">Graduate Student in Computer Science<u></u><u></u></p>
</div>
<div><p class="MsoNormal">Federal University of São Carlos - Brazil<u></u><u></u></p>
</div>
<div><p class="MsoNormal">XCS<u></u><u></u></p>
</div>
</div>
</div>
</div>
</div></div></div>
</div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr">Carlos Henrique Villa Pinto<div>Graduate Student in Computer Science</div><div>Federal University of São Carlos - Brazil</div><div>XCS</div></div></div>
</div>
_____________________________________<br>Powered by <a href="http://www.kitware.com">www.kitware.com</a><br><br>Visit other Kitware open-source projects at<br><a href="http://www.kitware.com/opensource/opensource.html">http://www.kitware.com/opensource/opensource.html</a><br><br>Kitware offers ITK Training Courses, for more information visit:<br>http://www.kitware.com/products/protraining.php<br><br>Please keep messages on-topic and check the ITK FAQ at:<br>http://www.itk.org/Wiki/ITK_FAQ<br><br>Follow this link to subscribe/unsubscribe:<br>http://public.kitware.com/mailman/listinfo/insight-users<br></blockquote></div><br></div></body></html>