[vtkusers] How to create vtkActor2D from vtkContourFilter?

Andrej Gluhov realandron at gmail.com
Thu Apr 8 03:17:58 EDT 2010


Hi.
I have this problem of combining vtkActor and vtkActor2D for
vtkImageViewer2D. Images from vtkActor2D gets under 2D images. I understand
that the problem is converting vtkPolyData to vtkImageData, I could use
vtkImageData, but do not know how to create it on the contour points.

            //Create the RenderWindow, Renderer and RenderWindowInteractor
            vtkRenderer ren1 = new vtkRenderer();
            vtkRenderWindow renWin = reWin.GetRenderWindow();
            renWin.AddRenderer(ren1);
            vtkRenderWindowInteractor iren = new
vtkRenderWindowInteractor();
            iren.SetRenderWindow(renWin);

            vtkDICOMImageReader DicomReader = new vtkDICOMImageReader();
            DicomReader.SetFileName(m_strFilePath);
            DicomReader.Update();

            vtkImageMapper DicomMapper = new vtkImageMapper();
            DicomMapper.SetInputConnection(DicomReader.GetOutputPort());
            DicomMapper.SetColorWindow(255.0);
            DicomMapper.SetColorLevel(127.5);

            vtkActor2D DicomActor = new vtkActor2D();
            DicomActor.SetMapper(DicomMapper);

            vtkImageData vol = new vtkImageData();
            vol.SetDimensions(512, 512, 1);
            vol.SetSpacing(1, 1, 1);
            vol.SetOrigin(0, 0, 0);
            vol.SetScalarTypeToFloat();
            vol.AllocateScalars();

            vtkFloatArray scalars = new vtkFloatArray();
            for (int i = 0; i < 512; i++)
            {
                for (int j = 0; j < 512; j++)
                {
                    scalars.InsertTuple1(i * 512 + j, m_DoseMap[i * 512 +
j]);
                }
            }

            vol.GetPointData().SetScalars(scalars);
            vol.Update();

            double[] DoseRange = vol.GetScalarRange();

            vtkLookupTable LUT = new vtkLookupTable();
            LUT.SetTableRange(DoseRange[0], DoseRange[1]);//min dose,max
dose
            LUT.SetNumberOfColors(1000);
            LUT.SetSaturationRange(1, 1);
            LUT.SetHueRange(0.67, 0);//blue to red
            LUT.SetAlphaRange(0, 0.3);//opacity
            LUT.Build();

            vtkImageMapToColors mapToRGBA = new vtkImageMapToColors();
            mapToRGBA.SetInput(vol);
            mapToRGBA.SetOutputFormatToRGBA();
            mapToRGBA.SetLookupTable(LUT);

            vtkImageMapper ColorMapper = new vtkImageMapper();
            ColorMapper.SetInputConnection(mapToRGBA.GetOutputPort());
            ColorMapper.SetColorWindow(255.0);
            ColorMapper.SetColorLevel(127.5);

            vtkActor2D ColorActor = new vtkActor2D();
            ColorActor.SetMapper(ColorMapper);

            vtkContourFilter cf = new vtkContourFilter();
            cf.SetInput(vol);
            //cf.SetValue(0,
Convert.ToDouble(dataGridViewIsodose.Rows[i].Cells[1].Value));
            cf.SetValue(0, 100);
            cf.Update();

            vtkPolyDataMapper mapper = new vtkPolyDataMapper();
            mapper.SetInputConnection(cf.GetOutputPort());
            mapper.ScalarVisibilityOff();

            vtkActor actor = new vtkActor();
            actor.SetMapper(mapper);
            actor.GetProperty().SetColor(1, 0, 0);

            vtkImageViewer2 viewer = new vtkImageViewer2();
            viewer.SetupInteractor(iren);
            viewer.GetRenderer().AddActor(DicomActor);
            viewer.GetRenderer().AddActor(ColorActor);
            viewer.GetRenderer().AddActor(actor);
            viewer.GetRenderer().ResetCamera();
            viewer.Render();

Thanks in advance.

-- 
С Уважением,
Андрей.
Best regards, Andrew
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100408/c10b119f/attachment.htm>


More information about the vtkusers mailing list