Example #1
0
        public XmlPolyDataPackage(string vtpFile, vtkRenderer renderer)
        {
            //Console.WriteLine(string.Format("VTP文件 = {0}", vtpFile));

            if (File.Exists(vtpFile))
            {
                if (vtpFile.EndsWith(".vtp"))
                {
                    //Console.WriteLine(string.Format("VTP文件 = {0}已存在", vtpFile));
                    reader = vtkXMLPolyDataReader.New();
                    reader.SetFileName(vtpFile);
                    reader.Update();

                    PolyData = reader.GetOutput();
                }
                else if (vtpFile.EndsWith(".stl"))
                {
                    PolyData = VTKUtil.ReadSTLPolyData(vtpFile);
                }

                vtkCamera camera = vtkCamera.New();

                var sortPolydata = new vtkDepthSortPolyData();
                sortPolydata.SetInput(PolyData);
                sortPolydata.SetCamera(camera);
                sortPolydata.SetDirectionToFrontToBack();
                sortPolydata.SetVector(1, 1, 1);
                sortPolydata.SetSortScalars(1);
                sortPolydata.Update();

                _polyDataMapper = vtkPolyDataMapper.New();
                _polyDataMapper.ScalarVisibilityOff();
                _polyDataMapper.SetInput(sortPolydata.GetOutput());
                _polyDataMapper.Update();

                actor = vtkActor.New();
                actor.SetMapper(_polyDataMapper);
                actor.GetProperty().SetColor(1, 1, 1);

                //marchingCubeActor.GetProperty().BackfaceCullingOn();
                //marchingCubeActor.GetProperty().FrontfaceCullingOn();
                //marchingCubeActor.GetProperty().BackfaceCullingOff();

                // now, tell the renderer our actors
                renderer.AddActor(actor);

                this.renderer = renderer;
            }
            else
            {
                throw new Exception(string.Format("VTP文件 = {0}不存在。", vtpFile));
            }

            //正面观();
        }
Example #2
0
        public static void ShowPolydata(string airwayPath)
        {
            if (!File.Exists(airwayPath))
            {
                MessageBox.Show("文件不存在!");
                return;
            }
            vtkRenderWindow renWin = vtkRenderWindow.New();

            renWin.SetSize(600, 600);

            vtkRenderWindowInteractor iren = new vtkRenderWindowInteractor();

            renWin.SetInteractor(iren);

            vtkInteractorStyleTrackballCamera interactorStyle = new vtkInteractorStyleTrackballCamera();

            iren.SetInteractorStyle(interactorStyle);

            vtkRenderer renderer = vtkRenderer.New();

            renderer.GradientBackgroundOn();
            renderer.SetBackground(0, 0, 0);
            renderer.SetBackground2(0, 0, 1);
            renWin.AddRenderer(renderer);
            vtkXMLPolyDataReader reader = new vtkXMLPolyDataReader();

            reader.SetFileName(airwayPath);
            reader.Update();

            vtkPolyDataMapper mapper = vtkPolyDataMapper.New();

            mapper.ScalarVisibilityOff();
            mapper.SetInput(reader.GetOutput());
            reader.Dispose();
            vtkActor actor = new vtkActor();

            actor.SetMapper(mapper);

            renderer.AddActor(actor);

            renWin.Render();
        }
Example #3
0
        private static void FindAllArrayNames(string filePath)
        {
            vtkPolyData polydata = vtkPolyData.New();

            if (filePath == null)
            {
                vtkSphereSource sphereSource = vtkSphereSource.New();
                sphereSource.Update();
                vtkXMLPolyDataWriter writer = vtkXMLPolyDataWriter.New();
                writer.SetFileName(@"c:\vtk\vtkdata-5.8.0\Data\testFindAllArrayNames.vtp");
                writer.SetInputConnection(sphereSource.GetOutputPort());
                writer.Write();
                polydata = sphereSource.GetOutput();
            }
            else
            {
                vtkXMLPolyDataReader reader = vtkXMLPolyDataReader.New();
                reader.SetFileName(filePath);
                reader.Update();
                polydata = reader.GetOutput();
            }
            FindAllData(ref polydata);
        }
        internal static vtkPolyData ReadPolyData(this string vtpFileName)
        {
            if (string.IsNullOrEmpty(vtpFileName))
            {
                throw new Exception("Empty filename is given.");
            }
            if (!File.Exists(vtpFileName))
            {
                throw new FileNotFoundException(string.Format("{0} not found", vtpFileName), vtpFileName);
            }

            //File.ReadAllBytes(vtpFileName);

            if (vtpFileName.EndsWith(".vtp"))
            {
                vtkXMLPolyDataReader reader = vtkXMLPolyDataReader.New();
                reader.SetFileName(vtpFileName);
                reader.Update();
                vtkPolyData polyData = reader.GetOutput();
                reader.Dispose();
                return(polyData);
            }
            else if (vtpFileName.EndsWith(".stl"))
            {
                return(VTKUtil.ReadSTLPolyData(vtpFileName));
            }
            else
            {
                vtkXMLPolyDataReader reader = vtkXMLPolyDataReader.New();
                reader.SetFileName(vtpFileName);
                reader.Update();
                vtkPolyData polyData = reader.GetOutput();
                reader.Dispose();
                return(polyData);
                //throw new Exception(string.Format("Unknown file type = " + vtpFileName));
            }
        }
Example #5
0
        private void CapClip(string filePath)
        {
            // PolyData to process
            vtkPolyData polyData;

            if (filePath != null)
            {
                vtkXMLPolyDataReader reader = vtkXMLPolyDataReader.New();
                reader.SetFileName(filePath);
                reader.Update();
                polyData = reader.GetOutput();
            }
            else
            {
                // Create a sphere
                vtkSphereSource sphereSource = vtkSphereSource.New();
                sphereSource.SetThetaResolution(20);
                sphereSource.SetPhiResolution(11);

                vtkPlane plane = vtkPlane.New();
                plane.SetOrigin(0, 0, 0);
                plane.SetNormal(1.0, -1.0, -1.0);

                vtkClipPolyData clipper = vtkClipPolyData.New();
                clipper.SetInputConnection(sphereSource.GetOutputPort());
                clipper.SetClipFunction(plane);
                clipper.SetValue(0);
                clipper.Update();

                polyData = clipper.GetOutput();
            }

            vtkDataSetMapper clipMapper = vtkDataSetMapper.New();

#if VTK_MAJOR_VERSION_5
            clipMapper.SetInput(polyData);
#else
            clipMapper.SetInputData(polyData);
#endif

            vtkActor clipActor = vtkActor.New();
            clipActor.SetMapper(clipMapper);
            clipActor.GetProperty().SetColor(1.0000, 0.3882, 0.2784);
            clipActor.GetProperty().SetInterpolationToFlat();

            // Now extract feature edges
            vtkFeatureEdges boundaryEdges = vtkFeatureEdges.New();
#if VTK_MAJOR_VERSION_5
            boundaryEdges.SetInput(polyData);
#else
            boundaryEdges.SetInputData(polyData);
#endif
            boundaryEdges.BoundaryEdgesOn();
            boundaryEdges.FeatureEdgesOff();
            boundaryEdges.NonManifoldEdgesOff();
            boundaryEdges.ManifoldEdgesOff();

            vtkStripper boundaryStrips = vtkStripper.New();
            boundaryStrips.SetInputConnection(boundaryEdges.GetOutputPort());
            boundaryStrips.Update();

            // Change the polylines into polygons
            vtkPolyData boundaryPoly = vtkPolyData.New();
            boundaryPoly.SetPoints(boundaryStrips.GetOutput().GetPoints());
            boundaryPoly.SetPolys(boundaryStrips.GetOutput().GetLines());

            vtkPolyDataMapper boundaryMapper = vtkPolyDataMapper.New();
#if VTK_MAJOR_VERSION_5
            boundaryMapper.SetInput(boundaryPoly);
#else
            boundaryMapper.SetInputData(boundaryPoly);
#endif

            vtkActor boundaryActor = vtkActor.New();
            boundaryActor.SetMapper(boundaryMapper);
            boundaryActor.GetProperty().SetColor(0.8900, 0.8100, 0.3400);
            // get a reference to the renderwindow of our renderWindowControl1
            vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow;
            // renderer
            vtkRenderer renderer = renderWindow.GetRenderers().GetFirstRenderer();
            // set background color
            renderer.SetBackground(.2, .3, .4);
            // add our actor to the renderer
            renderer.AddActor(clipActor);
            renderer.AddActor(boundaryActor);
            // Generate an interesting view
            //
            renderer.ResetCamera();
            renderer.GetActiveCamera().Azimuth(30);
            renderer.GetActiveCamera().Elevation(30);
            renderer.GetActiveCamera().Dolly(1.2);
            renderer.ResetCameraClippingRange();
        }
Example #6
0
        private void OBBDicer(string filePath)
        {
            vtkPolyData inputPolyData;

            if (filePath != null)
            {
                vtkXMLPolyDataReader reader = vtkXMLPolyDataReader.New();
                reader.SetFileName(filePath);
                reader.Update();
                inputPolyData = reader.GetOutput();
            }
            else
            {
                vtkSphereSource sphereSource = vtkSphereSource.New();
                sphereSource.SetThetaResolution(30);
                sphereSource.SetPhiResolution(15);
                sphereSource.Update();
                inputPolyData = sphereSource.GetOutput();
            }

            // Create pipeline
            vtkOBBDicer dicer = vtkOBBDicer.New();

#if VTK_MAJOR_VERSION_5
            dicer.SetInput(inputPolyData);
#else
            dicer.SetInputData(inputPolyData);
#endif
            dicer.SetNumberOfPieces(4);
            dicer.SetDiceModeToSpecifiedNumberOfPieces();
            dicer.Update();

            vtkPolyDataMapper inputMapper = vtkPolyDataMapper.New();
            inputMapper.SetInputConnection(dicer.GetOutputPort());
            inputMapper.SetScalarRange(0, dicer.GetNumberOfActualPieces());

            Debug.WriteLine("Asked for: "
                            + dicer.GetNumberOfPieces() + " pieces, got: "
                            + dicer.GetNumberOfActualPieces());

            vtkActor inputActor = vtkActor.New();
            inputActor.SetMapper(inputMapper);
            inputActor.GetProperty().SetInterpolationToFlat();

            vtkOutlineCornerFilter outline = vtkOutlineCornerFilter.New();
#if VTK_MAJOR_VERSION_5
            outline.SetInput(inputPolyData);
#else
            outline.SetInputData(inputPolyData);
#endif

            vtkPolyDataMapper outlineMapper = vtkPolyDataMapper.New();
            outlineMapper.SetInputConnection(outline.GetOutputPort());

            vtkActor outlineActor = vtkActor.New();
            outlineActor.SetMapper(outlineMapper);
            outlineActor.GetProperty().SetColor(0, 0, 0);
            // get a reference to the renderwindow of our renderWindowControl1
            vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow;
            // renderer
            vtkRenderer renderer = renderWindow.GetRenderers().GetFirstRenderer();
            // set background color
            renderer.SetBackground(.2, .3, .4);
            // add our actor to the renderer
            renderer.AddActor(inputActor);
            renderer.AddActor(outlineActor);
        }
Example #7
0
        private void ContoursFromPolyData(string filePath)
        {
            vtkPolyData inputPolyData;

            if (filePath != null)
            {
                vtkXMLPolyDataReader reader = vtkXMLPolyDataReader.New();
                reader.SetFileName(filePath);
                reader.Update();
                inputPolyData = reader.GetOutput();
            }
            else
            {
                vtkSphereSource sphereSource = vtkSphereSource.New();
                sphereSource.SetThetaResolution(30);
                sphereSource.SetPhiResolution(15);
                sphereSource.Update();
                inputPolyData = sphereSource.GetOutput();
            }

            vtkPolyDataMapper inputMapper = vtkPolyDataMapper.New();

#if VTK_MAJOR_VERSION_5
            inputMapper.SetInput(inputPolyData);
#else
            inputMapper.SetInputData(inputPolyData);
#endif

            // Create a plane to cut
            vtkPlane plane  = vtkPlane.New();
            double[] center = inputPolyData.GetCenter();
            double[] bounds = inputPolyData.GetBounds();
            plane.SetOrigin(center[0], center[1], center[2]);
            plane.SetNormal(1, 1, 1);


            float[] centerf   = new float[] { (float)center[0], (float)center[1], (float)center[2] };
            float[] minBoundf = new float[] { (float)bounds[0], (float)bounds[2], (float)bounds[4] };
            float[] maxBoundf = new float[] { (float)bounds[1], (float)bounds[3], (float)bounds[5] };
            IntPtr  pCenter   = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(float)) * 3);
            IntPtr  pMinBound = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(float)) * 3);
            IntPtr  pMaxBound = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(float)) * 3);
            Marshal.Copy(centerf, 0, pCenter, 3);
            Marshal.Copy(minBoundf, 0, pMinBound, 3);
            Marshal.Copy(maxBoundf, 0, pMaxBound, 3);

            // vtkMath.Distance2BetweenPoints accepts floats only
            double distanceMin = Math.Sqrt(vtkMath.Distance2BetweenPoints(pMinBound, pCenter));
            double distanceMax = Math.Sqrt(vtkMath.Distance2BetweenPoints(pMaxBound, pCenter));

            Marshal.FreeHGlobal(pCenter);
            Marshal.FreeHGlobal(pMinBound);
            Marshal.FreeHGlobal(pMaxBound);
            // Create cutter
            vtkCutter cutter = vtkCutter.New();
            cutter.SetCutFunction(plane);
#if VTK_MAJOR_VERSION_5
            cutter.SetInput(inputPolyData);
#else
            cutter.SetInputData(inputPolyData);
#endif
            cutter.GenerateValues(20, -distanceMin, distanceMax);
            vtkPolyDataMapper cutterMapper = vtkPolyDataMapper.New();
            cutterMapper.SetInputConnection(cutter.GetOutputPort());
            cutterMapper.ScalarVisibilityOff();

            // Create plane actor
            vtkActor planeActor = vtkActor.New();
            planeActor.GetProperty().SetColor(1.0, 0.0, 0.0);
            planeActor.GetProperty().SetLineWidth(3);
            planeActor.SetMapper(cutterMapper);

            // Create input actor
            vtkActor inputActor = vtkActor.New();
            inputActor.GetProperty().SetColor(1.0, 0.8941, 0.7686); // bisque
            inputActor.SetMapper(inputMapper);

            // get a reference to the renderwindow of our renderWindowControl1
            vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow;
            // renderer
            vtkRenderer renderer = renderWindow.GetRenderers().GetFirstRenderer();
            // set background color
            renderer.SetBackground(.2, .3, .4);
            renderer.AddActor(inputActor);
            renderer.AddActor(planeActor); //display the contour lines
        }
Example #8
0
        public bool Read_Poly_Data_File(string filename)
        {
            //Initalize VTK Reader
            vtkXMLPolyDataReader reader = new vtkXMLPolyDataReader();

            reader.SetFileName(filename);

            reader.Update();

            vtkPolyData polydata = reader.GetOutput();

            if (polydata == null)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Invalid Poly data Input");

                return(false);
            }

            // Read Point Coordinates
            int numPoints = (int)polydata.GetNumberOfPoints();

            List <Vector3d> point_dat = new List <Vector3d>();

            if (numPoints != 0)
            {
                double[] pt;

                for (int i = 0; i < numPoints; i++)
                {
                    pt = polydata.GetPoint(i);

                    point_dat.Add(new Vector3d((float)pt[0], (float)pt[1], (float)pt[2]));
                }
                if (this.vertex_data.ContainsKey("vertices"))
                {
                    this.vertex_data["vertices"] = point_dat;
                }
                else
                {
                    this.vertex_data.Add("vertices", point_dat);
                }
                Console.WriteLine("All points read in correctly!");
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("---------------No Points existent");
            }

            // Read Point Indices
            int numpolydatacells = (int)polydata.GetNumberOfCells();

            vtkCell   polydataCell;
            vtkIdList pts;

            if (numpolydatacells != 0)
            {
                int counter = 0;
                cells.SetNumberOfCells(numpolydatacells);

                for (int i = 0; i < numpolydatacells; i++)
                {
                    polydataCell = polydata.GetCell(i);

                    int numCellPoints = (int)polydataCell.GetNumberOfPoints();
                    cells.InsertNextCell(polydataCell);

                    Vector3 trianglePoints = new Vector3();
                    if (numCellPoints == 3)
                    {
                        pts = polydataCell.GetPointIds();

                        int one   = (int)pts.GetId(0);
                        int two   = (int)pts.GetId(1);
                        int three = (int)pts.GetId(2);
                        //this.Get_Triangle(counter, pts);
                        trianglePoints = new Vector3(one, two, three);
                        counter++;
                    }
                    triangleList.Add(trianglePoints);
                }
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("---------------No Triangles existent");
            }

            // Read point data
            vtkPointData pointData = polydata.GetPointData();

            // Load point attributes
            this.Load_Point_Attributes(pointData);

            return(true);
        }
Example #9
0
        public static void ShowPolydata(string airwayPath, string lesionPath)
        {
            vtkAppendPolyData appendPolydata = new vtkAppendPolyData();

            if (File.Exists(airwayPath))
            {
                vtkXMLPolyDataReader reader = new vtkXMLPolyDataReader();
                reader.SetFileName(airwayPath);
                reader.Update();
                appendPolydata.AddInput(reader.GetOutput());
                reader.Dispose();
            }
            else
            {
                MessageBox.Show("airwayPath : " + airwayPath + "文件不存在!");
            }

            if (File.Exists(lesionPath))
            {
                vtkXMLPolyDataReader reader = new vtkXMLPolyDataReader();
                reader.SetFileName(lesionPath);
                reader.Update();
                appendPolydata.AddInput(reader.GetOutput());
                reader.Dispose();
            }
            else
            {
                MessageBox.Show("lesionPath : " + lesionPath + "文件不存在!");
            }

            vtkRenderWindow renWin = vtkRenderWindow.New();

            renWin.SetSize(600, 600);

            vtkRenderWindowInteractor iren = new vtkRenderWindowInteractor();

            renWin.SetInteractor(iren);

            vtkInteractorStyleTrackballCamera interactorStyle = new vtkInteractorStyleTrackballCamera();

            iren.SetInteractorStyle(interactorStyle);

            vtkRenderer renderer = vtkRenderer.New();

            renderer.GradientBackgroundOn();
            renderer.SetBackground(0, 0, 0);
            renderer.SetBackground2(0, 0, 1);
            renWin.AddRenderer(renderer);


            vtkPolyDataMapper mapper = vtkPolyDataMapper.New();

            mapper.ScalarVisibilityOff();
            mapper.SetInput(appendPolydata.GetOutput());
            vtkActor actor = new vtkActor();

            actor.SetMapper(mapper);

            renderer.AddActor(actor);

            renderer.Render();
            renderer.ResetCamera();
            renWin.Render();

            //Thread thread = new Thread(new ThreadStart(
            //                                       delegate
            //                                       {
            //                                           iren.Start();
            //                                       }));
            //thread.Start();
        }
Example #10
0
        private void FillHoles(string filePath)
        {
            vtkPolyData input = vtkPolyData.New();

            if (filePath == null)
            {
                GenerateData(ref input);
            }
            else
            {
                vtkXMLPolyDataReader reader = vtkXMLPolyDataReader.New();
                reader.SetFileName(filePath);
                reader.Update();

                input.ShallowCopy(reader.GetOutput());
            }

            vtkFillHolesFilter fillHolesFilter = vtkFillHolesFilter.New();

#if VTK_MAJOR_VERSION_5
            fillHolesFilter.SetInputConnection(input.GetProducerPort());
#else
            fillHolesFilter.SetInputData(input);
#endif

            fillHolesFilter.Update();

            // Create a mapper and actor
            vtkPolyDataMapper originalMapper = vtkPolyDataMapper.New();
#if VTK_MAJOR_VERSION_5
            originalMapper.SetInputConnection(input.GetProducerPort());
#else
            originalMapper.SetInputData(input);
#endif

            vtkActor originalActor = vtkActor.New();
            originalActor.SetMapper(originalMapper);

            vtkPolyDataMapper filledMapper = vtkPolyDataMapper.New();
            filledMapper.SetInputConnection(fillHolesFilter.GetOutputPort());

            vtkActor filledActor = vtkActor.New();
            filledActor.SetMapper(filledMapper);

            vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow;
            this.Size = new System.Drawing.Size(612, 352);

            // Define viewport ranges
            // (xmin, ymin, xmax, ymax)
            double[] leftViewport  = new double[] { 0.0, 0.0, 0.5, 1.0 };
            double[] rightViewport = new double[] { 0.5, 0.0, 1.0, 1.0 };

            // Setup both renderers
            vtkRenderer leftRenderer = vtkRenderer.New();
            renderWindow.AddRenderer(leftRenderer);
            leftRenderer.SetViewport(leftViewport[0], leftViewport[1], leftViewport[2], leftViewport[3]);
            leftRenderer.SetBackground(.6, .5, .4);

            vtkRenderer rightRenderer = vtkRenderer.New();
            renderWindow.AddRenderer(rightRenderer);
            rightRenderer.SetViewport(rightViewport[0], rightViewport[1], rightViewport[2], rightViewport[3]);
            rightRenderer.SetBackground(.4, .5, .6);

            // Add the sphere to the left and the cube to the right
            leftRenderer.AddActor(originalActor);
            rightRenderer.AddActor(filledActor);
            leftRenderer.ResetCamera();
            rightRenderer.ResetCamera();
            renderWindow.Render();
        }
Example #11
0
        private void FilledContours(string filePath, int numberOfContours)
        {
            // Read the file
            vtkXMLPolyDataReader reader = vtkXMLPolyDataReader.New();

            reader.SetFileName(filePath);
            reader.Update(); // Update so that we can get the scalar range

            double[] scalarRange = reader.GetOutput().GetPointData().GetScalars().GetRange();

            vtkAppendPolyData appendFilledContours = vtkAppendPolyData.New();

            double delta = (scalarRange[1] - scalarRange[0]) / (numberOfContours - 1);

            // Keep the clippers alive
            List <vtkClipPolyData> clippersLo = new List <vtkClipPolyData>();
            List <vtkClipPolyData> clippersHi = new List <vtkClipPolyData>();

            for (int i = 0; i < numberOfContours; i++)
            {
                double valueLo = scalarRange[0] + i * delta;
                double valueHi = scalarRange[0] + (i + 1) * delta;

                clippersLo.Add(vtkClipPolyData.New());
                clippersLo[i].SetValue(valueLo);
                if (i == 0)
                {
                    clippersLo[i].SetInputConnection(reader.GetOutputPort());
                }
                else
                {
                    clippersLo[i].SetInputConnection(clippersHi[i - 1].GetOutputPort(1));
                }
                clippersLo[i].InsideOutOff();
                clippersLo[i].Update();

                clippersHi.Add(vtkClipPolyData.New());
                clippersHi[i].SetValue(valueHi);
                clippersHi[i].SetInputConnection(clippersLo[i].GetOutputPort());
                clippersHi[i].GenerateClippedOutputOn();
                clippersHi[i].InsideOutOn();
                clippersHi[i].Update();
                if (clippersHi[i].GetOutput().GetNumberOfCells() == 0)
                {
                    continue;
                }

                vtkFloatArray cd = vtkFloatArray.New();
                cd.SetNumberOfComponents(1);
                cd.SetNumberOfTuples(clippersHi[i].GetOutput().GetNumberOfCells());
                cd.FillComponent(0, valueLo);

                clippersHi[i].GetOutput().GetCellData().SetScalars(cd);
                appendFilledContours.AddInputConnection(clippersHi[i].GetOutputPort());
            }

            vtkCleanPolyData filledContours = vtkCleanPolyData.New();

            filledContours.SetInputConnection(appendFilledContours.GetOutputPort());

            vtkLookupTable lut = vtkLookupTable.New();

            lut.SetNumberOfTableValues(numberOfContours + 1);
            lut.Build();
            vtkPolyDataMapper contourMapper = vtkPolyDataMapper.New();

            contourMapper.SetInputConnection(filledContours.GetOutputPort());
            contourMapper.SetScalarRange(scalarRange[0], scalarRange[1]);
            contourMapper.SetScalarModeToUseCellData();
            contourMapper.SetLookupTable(lut);

            vtkActor contourActor = vtkActor.New();

            contourActor.SetMapper(contourMapper);
            contourActor.GetProperty().SetInterpolationToFlat();

            vtkContourFilter contours = vtkContourFilter.New();

            contours.SetInputConnection(filledContours.GetOutputPort());
            contours.GenerateValues(numberOfContours, scalarRange[0], scalarRange[1]);

            vtkPolyDataMapper contourLineMapperer = vtkPolyDataMapper.New();

            contourLineMapperer.SetInputConnection(contours.GetOutputPort());
            contourLineMapperer.SetScalarRange(scalarRange[0], scalarRange[1]);
            contourLineMapperer.ScalarVisibilityOff();

            vtkActor contourLineActor = vtkActor.New();

            contourLineActor.SetMapper(contourLineMapperer);
            contourLineActor.GetProperty().SetLineWidth(2);

            // get a reference to the renderwindow of our renderWindowControl1
            vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow;
            // renderer
            vtkRenderer renderer = renderWindow.GetRenderers().GetFirstRenderer();

            // set background color
            renderer.SetBackground(.2, .3, .4);
            // add our actor to the renderer
            renderer.AddActor(contourActor);
            renderer.AddActor(contourLineActor);
        }