[vtkusers] Help with output of vtkImageReslice

Neel Patel 0-0-0 siva.yedithi at gmail.com
Mon May 22 18:24:10 EDT 2017


Hi. I'm fairly new to VTK and I can write some small/simple programs.
Recently I decided to try slicing a 3D cube that is spilt into black, gray
and white regions. The split colors were mostly to get familiar with which
axis I'm cutting through/viewing. I've looked at the ImageSlicing.cxx
example and tried to use that as a guide. I can get a slice but it looks
nothing like part the original cube. 
<http://vtk.1045678.n5.nabble.com/file/n5743352/slicing_output.png> 

Also I've pasted the code that I'm using to get the slice. The colors seem
right but are mixed up in the wrong order. I'm not sure if it's because I
did something wrong in the process or the lookup table, which admittedly I'm
not very familiar with. Any help would be greatly appreciated. Thanks!

// Filters
            int[] extent = imageImport.GetOutput().GetExtent();
            double[] spacing = imageImport.GetOutput().GetSpacing();
            double[] origin = imageImport.GetOutput().GetOrigin();

            double[] center = new double[3];
            center[0] = origin[0] + spacing[0] * 0.5 * (extent[0] +
extent[1]);
            center[1] = origin[1] + spacing[1] * 0.5 * (extent[2] +
extent[3]);
            center[2] = origin[2] + spacing[2] * 0.5 * (extent[4] +
extent[5]);

            // Matrices for axial, coronal, sagittal, oblique view
orientations
            double[] axialElements = {
                     1, 0, 0, 0,
                     0, 1, 0, 0,
                     0, 0, 1, 0,
                     0, 0, 0, 1 };

            //static double coronalElements[16] = {
            //         1, 0, 0, 0,
            //         0, 0, 1, 0,
            //         0,-1, 0, 0,
            //         0, 0, 0, 1 };

            //  double[] sagittalElements = {
            //0, 0,-1, 0,
            //1, 0, 0, 0,
            //0,-1, 0, 0,
            //0, 0, 0, 1 };

            //static double obliqueElements[16] = {
            //         1, 0, 0, 0,
            //         0, 0.866025, -0.5, 0,
            //         0, 0.5, 0.866025, 0,
            //         0, 0, 0, 1 };

            GCHandle atp = GCHandle.Alloc(axialElements,
GCHandleType.Pinned);

            vtkMatrix4x4 resliceAxes = vtkMatrix4x4.New();
            resliceAxes.DeepCopy(atp.AddrOfPinnedObject());

            // Set the point through which to slice
            resliceAxes.SetElement(0, 3, center[0]);
            resliceAxes.SetElement(1, 3, center[1]);
            resliceAxes.SetElement(2, 3, center[2]);


            vtkImageReslice reslice = vtkImageReslice.New();
            reslice.SetInputConnection(imageImport.GetOutputPort());
            reslice.SetOutputDimensionality(2);
            reslice.SetResliceAxesOrigin(0, 0, 0);
            reslice.SetResliceAxes(resliceAxes);
            reslice.SetInterpolationModeToNearestNeighbor();

            //// Create a greyscale lookup table
            vtkLookupTable table = vtkLookupTable.New();
            table.SetRange(0, 500); // image intensity range
            table.SetValueRange(0.0, 1); // from black to white
            table.SetSaturationRange(0.0, 0); // no color saturation
            table.SetRampToLinear();
            table.Build();

            // Map the image through the lookup table
            vtkImageMapToColors color = vtkImageMapToColors.New();
            color.SetLookupTable(table);
            color.SetInputConnection(reslice.GetOutputPort());

            // Display the image
            vtkImageActor actor = vtkImageActor.New();
            actor.SetInput(color.GetOutput());

            vtkRenderer renderer =
renderWindowControl2.RenderWindow.GetRenderers().GetFirstRenderer();
            renderer.SetBackground(1, 1, 1);
            renderer.AddActor(actor);



--
View this message in context: http://vtk.1045678.n5.nabble.com/Help-with-output-of-vtkImageReslice-tp5743352.html
Sent from the VTK - Users mailing list archive at Nabble.com.


More information about the vtkusers mailing list