<div dir="ltr"><div><div><div><div>Dear VTKrs<br><br></div>I am trying to extract a single slice from an image volume and write the image to a file. <br><br></div>I have found and example using vtkImageResliceMapper and I have modified it below. However I am unable to properly save the image. <br>

<br></div>Suggestions for how to save the single image and the volume with only the single image slice much appreciated!<br><br></div>Many thanks,<br>Jesse<br><div><div><div><br><br>int main(int argc, char *argv[])<br>{<br>

        if (argc &lt; 3) {<br>                cout &lt;&lt; &quot;Usage: &quot; &lt;&lt; argv[0] &lt;&lt; &quot; Input_Image &quot; &lt;&lt; &quot;Output_Image&quot;&lt;&lt; endl;<br>                return EXIT_FAILURE;<br>

        }<br><br>        vtkSmartPointer&lt;vtkRenderer&gt; aRenderer = vtkSmartPointer&lt;vtkRenderer&gt;::New();<br>        vtkSmartPointer&lt;vtkRenderWindow&gt; renWin = vtkSmartPointer&lt;vtkRenderWindow&gt;::New();<br>

        renWin-&gt;AddRenderer(aRenderer);<br>        vtkSmartPointer&lt;vtkRenderWindowInteractor&gt; iren = vtkSmartPointer&lt;vtkRenderWindowInteractor&gt;::New();<br>        iren-&gt;SetRenderWindow(renWin);<br><br>        vtkSmartPointer&lt;vtkXMLImageDataReader&gt; reader = vtkSmartPointer&lt;vtkXMLImageDataReader&gt;::New();<br>

    reader-&gt;SetFileName(argv[1]);<br>    reader-&gt;Update();<br><br>        aRenderer-&gt;SetBackground(.2, .3, .4);<br>        renWin-&gt;SetSize(640, 480);<br><br><br>        // outline provides context around the data.<br>

        vtkSmartPointer&lt;vtkOutlineFilter&gt; outlineData = vtkSmartPointer&lt;vtkOutlineFilter&gt;::New();<br>        outlineData-&gt;SetInputConnection(reader-&gt;GetOutputPort());<br>        outlineData-&gt;Update();<br>

<br>        vtkSmartPointer&lt;vtkPolyDataMapper&gt; mapOutline = vtkSmartPointer&lt;vtkPolyDataMapper&gt;::New();<br>        mapOutline-&gt;SetInputConnection(outlineData-&gt;GetOutputPort());<br><br>        vtkSmartPointer&lt;vtkActor&gt; outline = vtkSmartPointer&lt;vtkActor&gt;::New();<br>

        outline-&gt;SetMapper(mapOutline);<br>        outline-&gt;GetProperty()-&gt;SetColor(0,0,0);<br><br>        // Setting of vtkImageResliceMapper<br>        vtkSmartPointer&lt;vtkImageResliceMapper&gt; im = vtkSmartPointer&lt;vtkImageResliceMapper&gt;::New();<br>

        im-&gt;SetInputConnection(reader-&gt;GetOutputPort());<br>        //im-&gt;SliceFacesCameraOn();<br>        //im-&gt;SliceAtFocalPointOn();<br>        im-&gt;BorderOff();<br><br>        vtkSmartPointer&lt;vtkPlane&gt; slicePlane = vtkSmartPointer&lt;vtkPlane&gt;::New();<br>

<br>        double testpoint[3];<br>        testpoint[0] = 49.72023;<br>        testpoint[1] = 94.96884;<br>        testpoint[2] = 24.4359779;<br><br>        double normal[3];<br>        normal[0] = -0.118968;<br>        normal[1] = -0.9534519;<br>

        normal[2] = 0.27708499;<br><br>        double testpoint2[3];<br>        testpoint2[0] = 47.7378;<br>        testpoint2[1] = 88.439;<br>        testpoint2[2] = 26.1231;<br><br>        double normal2[3];<br>        normal2[0] = -0.4399;<br>

        normal2[1] = -0.8165;<br>        normal2[2] = 0.3738968;<br><br>        slicePlane-&gt;SetNormal(normal2);<br>        slicePlane-&gt;SetOrigin(testpoint2);<br><br>        im-&gt;SetSlicePlane(slicePlane);<br><br>
<br>
<br>        // Setting of vtkImageProperty<br>        vtkSmartPointer&lt;vtkImageProperty&gt; ip = vtkSmartPointer&lt;vtkImageProperty&gt;::New();<br>        ip-&gt;SetColorWindow(2000);<br>        ip-&gt;SetColorLevel(1000);<br>

        ip-&gt;SetAmbient(0.0);<br>        ip-&gt;SetDiffuse(1.0);<br>        ip-&gt;SetOpacity(1.0);<br>        ip-&gt;SetInterpolationTypeToLinear();<br><br>        // Try of vtkImageSlice<br>        vtkSmartPointer&lt;vtkImageSlice&gt; imageSlice = vtkSmartPointer&lt;vtkImageSlice&gt;::New();<br>

        vtkSmartPointer&lt;vtkInteractorStyleImage &gt; styleImage = vtkSmartPointer&lt;vtkInteractorStyleImage &gt;::New();<br><br>        imageSlice-&gt;SetMapper(im);<br>        imageSlice-&gt;SetProperty(ip);<br><br>
        <br>
        vtkSmartPointer&lt;vtkXMLImageDataWriter&gt; writer =  <br>        vtkSmartPointer&lt;vtkXMLImageDataWriter&gt;::New();<br>        writer-&gt;SetFileName(argv[2]);<br>        writer-&gt;SetInputConnection(im-&gt;GetOutputPort());<br>

        writer-&gt;Write();<br><br>        styleImage-&gt;SetInteractionModeToImage3D();<br>        iren-&gt;SetInteractorStyle(styleImage);<br>        renWin-&gt;SetInteractor(iren);<br><br>        // Actors are added to the renderer.<br>

        aRenderer-&gt;AddActor(outline);<br>        aRenderer-&gt;AddViewProp(imageSlice);<br><br>        // camera Setting<br>        vtkSmartPointer&lt;vtkCamera&gt; aCamera = vtkSmartPointer&lt;vtkCamera&gt;::New();<br>

        aCamera-&gt;SetViewUp (0, 0, -1);<br>        aCamera-&gt;SetPosition (0, 1, 0);<br>        aCamera-&gt;SetFocalPoint (0, 0, 0);<br>        aCamera-&gt;ComputeViewPlaneNormal();<br>        aCamera-&gt;Azimuth(30.0);<br>

        aCamera-&gt;Elevation(30.0);<br>        aCamera-&gt;ParallelProjectionOn();<br>        aRenderer-&gt;SetActiveCamera(aCamera);<br><br><br>        renWin-&gt;Render();<br>        aRenderer-&gt;ResetCamera();<br>        aRenderer-&gt;ResetCameraClippingRange();<br>

<br>        // interact with data<br>        iren-&gt;Initialize();<br>        iren-&gt;Start();<br><br>        return EXIT_SUCCESS;<br>} <br></div></div></div></div>