[vtkusers] save slice from vtk image volume

Jesse Ross-Jones jesse.rj at gmail.com
Wed Dec 4 09:05:37 EST 2013


Hi David,
Thanks for the reply. In that case I would need to render the image to the
window and set the camera origin and direction to point to the image then
save that to  a file?

I have been trying with the vtkProbefilter to extract the image that I
want. I am using the same plane origin and normal as before.


        vtkSmartPointer<vtkPlaneSource> PlaneSource =
vtkSmartPointer<vtkPlaneSource>::New();
        PlaneSource->SetCenter(testpoint2);
        PlaneSource->SetNormal(normal2);

        vtkPolyData *Plane = PlaneSource -> GetOutput();

        vtkProbeFilter *Probe = vtkProbeFilter::New();

        Probe->SetInput(Plane);
        Probe->SetSource(reader->GetOutput());
        //Probe->SetInputConnection(reader->GetOutputPort);
        Probe->SpatialMatchOn();
        Probe->Update();

However, with this method it seems I can only seem to be able to save a
vtkpolydata file of the plane. Is it possible to use the vtkProbeFilter to
obtain a slice of an image volume?

Many thanks,
Jesse


On Wed, Dec 4, 2013 at 2:44 PM, David Gobbi <david.gobbi at gmail.com> wrote:

> Hi Jessie,
>
> The vtkImageResliceMapper just draws the slice to the screen, it does
> not produce it as a output on its output port.  So the following line
> of code will not work:
>
> writer->SetInputConnection(im->GetOutputPort());
>
> The only way to get the image from vtkImageResliceMapper is to capture
> the contents of the render window, with vtkWindowToImageFilter.
>
>   David
>
>
> On Wed, Dec 4, 2013 at 1:43 AM, Jesse Ross-Jones <jesse.rj at gmail.com>
> wrote:
> > Dear VTKrs
> >
> > I am trying to extract a single slice from an image volume and write the
> > image to a file.
> >
> > I have found and example using vtkImageResliceMapper and I have modified
> it
> > below. However I am unable to properly save the image.
> >
> > Suggestions for how to save the single image and the volume with only the
> > single image slice much appreciated!
> >
> > Many thanks,
> > Jesse
> >
> >
> > int main(int argc, char *argv[])
> > {
> >         if (argc < 3) {
> >                 cout << "Usage: " << argv[0] << " Input_Image " <<
> > "Output_Image"<< endl;
> >                 return EXIT_FAILURE;
> >         }
> >
> >         vtkSmartPointer<vtkRenderer> aRenderer =
> > vtkSmartPointer<vtkRenderer>::New();
> >         vtkSmartPointer<vtkRenderWindow> renWin =
> > vtkSmartPointer<vtkRenderWindow>::New();
> >         renWin->AddRenderer(aRenderer);
> >         vtkSmartPointer<vtkRenderWindowInteractor> iren =
> > vtkSmartPointer<vtkRenderWindowInteractor>::New();
> >         iren->SetRenderWindow(renWin);
> >
> >         vtkSmartPointer<vtkXMLImageDataReader> reader =
> > vtkSmartPointer<vtkXMLImageDataReader>::New();
> >     reader->SetFileName(argv[1]);
> >     reader->Update();
> >
> >         aRenderer->SetBackground(.2, .3, .4);
> >         renWin->SetSize(640, 480);
> >
> >
> >         // outline provides context around the data.
> >         vtkSmartPointer<vtkOutlineFilter> outlineData =
> > vtkSmartPointer<vtkOutlineFilter>::New();
> >         outlineData->SetInputConnection(reader->GetOutputPort());
> >         outlineData->Update();
> >
> >         vtkSmartPointer<vtkPolyDataMapper> mapOutline =
> > vtkSmartPointer<vtkPolyDataMapper>::New();
> >         mapOutline->SetInputConnection(outlineData->GetOutputPort());
> >
> >         vtkSmartPointer<vtkActor> outline =
> > vtkSmartPointer<vtkActor>::New();
> >         outline->SetMapper(mapOutline);
> >         outline->GetProperty()->SetColor(0,0,0);
> >
> >         // Setting of vtkImageResliceMapper
> >         vtkSmartPointer<vtkImageResliceMapper> im =
> > vtkSmartPointer<vtkImageResliceMapper>::New();
> >         im->SetInputConnection(reader->GetOutputPort());
> >         //im->SliceFacesCameraOn();
> >         //im->SliceAtFocalPointOn();
> >         im->BorderOff();
> >
> >         vtkSmartPointer<vtkPlane> slicePlane =
> > vtkSmartPointer<vtkPlane>::New();
> >
> >         double testpoint[3];
> >         testpoint[0] = 49.72023;
> >         testpoint[1] = 94.96884;
> >         testpoint[2] = 24.4359779;
> >
> >         double normal[3];
> >         normal[0] = -0.118968;
> >         normal[1] = -0.9534519;
> >         normal[2] = 0.27708499;
> >
> >         double testpoint2[3];
> >         testpoint2[0] = 47.7378;
> >         testpoint2[1] = 88.439;
> >         testpoint2[2] = 26.1231;
> >
> >         double normal2[3];
> >         normal2[0] = -0.4399;
> >         normal2[1] = -0.8165;
> >         normal2[2] = 0.3738968;
> >
> >         slicePlane->SetNormal(normal2);
> >         slicePlane->SetOrigin(testpoint2);
> >
> >         im->SetSlicePlane(slicePlane);
> >
> >
> >
> >         // Setting of vtkImageProperty
> >         vtkSmartPointer<vtkImageProperty> ip =
> > vtkSmartPointer<vtkImageProperty>::New();
> >         ip->SetColorWindow(2000);
> >         ip->SetColorLevel(1000);
> >         ip->SetAmbient(0.0);
> >         ip->SetDiffuse(1.0);
> >         ip->SetOpacity(1.0);
> >         ip->SetInterpolationTypeToLinear();
> >
> >         // Try of vtkImageSlice
> >         vtkSmartPointer<vtkImageSlice> imageSlice =
> > vtkSmartPointer<vtkImageSlice>::New();
> >         vtkSmartPointer<vtkInteractorStyleImage > styleImage =
> > vtkSmartPointer<vtkInteractorStyleImage >::New();
> >
> >         imageSlice->SetMapper(im);
> >         imageSlice->SetProperty(ip);
> >
> >
> >         vtkSmartPointer<vtkXMLImageDataWriter> writer =
> >         vtkSmartPointer<vtkXMLImageDataWriter>::New();
> >         writer->SetFileName(argv[2]);
> >         writer->SetInputConnection(im->GetOutputPort());
> >         writer->Write();
> >
> >         styleImage->SetInteractionModeToImage3D();
> >         iren->SetInteractorStyle(styleImage);
> >         renWin->SetInteractor(iren);
> >
> >         // Actors are added to the renderer.
> >         aRenderer->AddActor(outline);
> >         aRenderer->AddViewProp(imageSlice);
> >
> >         // camera Setting
> >         vtkSmartPointer<vtkCamera> aCamera =
> > vtkSmartPointer<vtkCamera>::New();
> >         aCamera->SetViewUp (0, 0, -1);
> >         aCamera->SetPosition (0, 1, 0);
> >         aCamera->SetFocalPoint (0, 0, 0);
> >         aCamera->ComputeViewPlaneNormal();
> >         aCamera->Azimuth(30.0);
> >         aCamera->Elevation(30.0);
> >         aCamera->ParallelProjectionOn();
> >         aRenderer->SetActiveCamera(aCamera);
> >
> >
> >         renWin->Render();
> >         aRenderer->ResetCamera();
> >         aRenderer->ResetCameraClippingRange();
> >
> >         // interact with data
> >         iren->Initialize();
> >         iren->Start();
> >
> >         return EXIT_SUCCESS;
> > }
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20131204/c9e3d41b/attachment.htm>


More information about the vtkusers mailing list