[vtkusers] Cannot translate an image using vtkImageReslice

David Gobbi david.gobbi at gmail.com
Thu Jul 17 09:49:17 EDT 2014


You must also call thickReslice->SetOutputOrigin(...);
Set the output origin to be the same as the origin of the
original mandelbrot.


On Thu, Jul 17, 2014 at 6:50 AM,  <ahmed at mufradat.com> wrote:
> Hello Everyone,
>
> Can somebody please tell me what am I doing wrong in the following code?
> using vtkImageReslice I can rotate or scale the image but whatever
> parameters I use to translate the image the output image stays identical to
> the input one. I was expecting the Mandelbrot to be shifted along the x,y
> but that never happens.
>
>
> Best Regards,
> Ahmed
>
>
> FYI the following code was adapted from
> http://www.vtk.org/Wiki/VTK/Examples/Cxx/ImageData/ExtractVOI
>
> #include <vtkVersion.h>
> #include <vtkSmartPointer.h>
> #include <vtkImageData.h>
> #include <vtkImageMapper3D.h>
> #include <vtkExtractVOI.h>
> #include <vtkRenderWindow.h>
> #include <vtkRenderWindowInteractor.h>
> #include <vtkInteractorStyleImage.h>
> #include <vtkRenderer.h>
> #include <vtkImageActor.h>
> #include <vtkImageCast.h>
> #include <vtkImageMandelbrotSource.h>
> #include <vtkImageReslice.h>
> #include <vtkTransform.h>
> int main(int, char *[])
> {
>   // Create an image
>   vtkSmartPointer<vtkImageMandelbrotSource> source =
>     vtkSmartPointer<vtkImageMandelbrotSource>::New();
>   source->Update();
>
>   int* inputDims = source->GetOutput()->GetDimensions();
>   std::cout << "Dims: " << " x: " << inputDims[0]
>                         << " y: " << inputDims[1]
>                         << " z: " << inputDims[2] << std::endl;
>   std::cout << "Number of points: " <<
> source->GetOutput()->GetNumberOfPoints() << std::endl;
>   std::cout << "Number of cells: " <<
> source->GetOutput()->GetNumberOfCells() << std::endl;
>
>          vtkTransform *transform3= vtkTransform::New();
>           transform3->Translate(10, 10,0);
>            //transform3->Scale(0.05,0.05,0.05);
>            //transform3->RotateZ(90);
>
>          vtkImageReslice *thickReslice = vtkImageReslice::New();
>          thickReslice->SetInputConnection(source->GetOutputPort());
>          thickReslice->SetInterpolationModeToLinear();
>          thickReslice->SetOutputDimensionality(2);
>          thickReslice->SetBackgroundLevel(-1000);
>          thickReslice->SetOutputExtent(0,1000,0,1000,0,0);
>          thickReslice->SetResliceAxes(transform3->GetMatrix());
>          thickReslice->Update();
>
>   vtkImageData* extracted = thickReslice->GetOutput();
>
>   int* extractedDims = extracted->GetDimensions();
>   std::cout << "Dims: " << " x: " << extractedDims[0]
>                         << " y: " << extractedDims[1]
>                         << " z: " << extractedDims[2] << std::endl;
>   std::cout << "Number of points: " << extracted->GetNumberOfPoints() <<
> std::endl;
>   std::cout << "Number of cells: " << extracted->GetNumberOfCells() <<
> std::endl;
>
>   vtkSmartPointer<vtkImageCast> inputCastFilter =
>     vtkSmartPointer<vtkImageCast>::New();
>   inputCastFilter->SetInputConnection(source->GetOutputPort());
>   inputCastFilter->SetOutputScalarTypeToUnsignedChar();
>   inputCastFilter->Update();
>
>   vtkSmartPointer<vtkImageCast> extractedCastFilter =
>     vtkSmartPointer<vtkImageCast>::New();
> #if VTK_MAJOR_VERSION <= 5
>   extractedCastFilter->SetInputConnection(extracted->GetProducerPort());
> #else
>   extractedCastFilter->SetInputData(extracted);
> #endif
>   extractedCastFilter->SetOutputScalarTypeToUnsignedChar();
>   extractedCastFilter->Update();
>
>   // Create actors
>   vtkSmartPointer<vtkImageActor> inputActor =
>     vtkSmartPointer<vtkImageActor>::New();
>   inputActor->GetMapper()->SetInputConnection(
>     inputCastFilter->GetOutputPort());
>
>   vtkSmartPointer<vtkImageActor> extractedActor =
>     vtkSmartPointer<vtkImageActor>::New();
>   extractedActor->GetMapper()->SetInputConnection(
>     extractedCastFilter->GetOutputPort());
>
>   // There will be one render window
>   vtkSmartPointer<vtkRenderWindow> renderWindow =
>     vtkSmartPointer<vtkRenderWindow>::New();
>   renderWindow->SetSize(600, 300);
>
>   // And one interactor
>   vtkSmartPointer<vtkRenderWindowInteractor> interactor =
>     vtkSmartPointer<vtkRenderWindowInteractor>::New();
>   interactor->SetRenderWindow(renderWindow);
>
>   // Define viewport ranges
>   // (xmin, ymin, xmax, ymax)
>   double leftViewport[4] = {0.0, 0.0, 0.5, 1.0};
>   double rightViewport[4] = {0.5, 0.0, 1.0, 1.0};
>
>   // Setup both renderers
>   vtkSmartPointer<vtkRenderer> leftRenderer =
>     vtkSmartPointer<vtkRenderer>::New();
>   renderWindow->AddRenderer(leftRenderer);
>   leftRenderer->SetViewport(leftViewport);
>   leftRenderer->SetBackground(.6, .5, .4);
>
>   vtkSmartPointer<vtkRenderer> rightRenderer =
>     vtkSmartPointer<vtkRenderer>::New();
>   renderWindow->AddRenderer(rightRenderer);
>   rightRenderer->SetViewport(rightViewport);
>   rightRenderer->SetBackground(.4, .5, .6);
>
>   leftRenderer->AddActor(inputActor);
>   rightRenderer->AddActor(extractedActor);
>
>   leftRenderer->ResetCamera();
>
>   rightRenderer->ResetCamera();
>
>   renderWindow->Render();
>   interactor->Start();
>
>
>   return EXIT_SUCCESS;
> }
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/vtkusers


More information about the vtkusers mailing list