コード例 #1
0
        private void MarchingCubes()
        {
            vtkSphereSource sphereSource = vtkSphereSource.New();

            sphereSource.SetPhiResolution(20);
            sphereSource.SetThetaResolution(20);
            sphereSource.Update();

            double[] bounds = sphereSource.GetOutput().GetBounds();
            for (int i = 0; i < 6; i += 2)
            {
                double range = bounds[i + 1] - bounds[i];
                bounds[i]     = bounds[i] - .1 * range;
                bounds[i + 1] = bounds[i + 1] + .1 * range;
            }
            vtkVoxelModeller voxelModeller = vtkVoxelModeller.New();

            voxelModeller.SetSampleDimensions(50, 50, 50);
            voxelModeller.SetModelBounds(bounds[0], bounds[1], bounds[2], bounds[3], bounds[4], bounds[5]);
            voxelModeller.SetScalarTypeToFloat();
            voxelModeller.SetMaximumDistance(.1);

#if VTK_MAJOR_VERSION_5
            voxelModeller.SetInputConnection(sphereSource.GetOutputPort());
#else
            voxelModeller.SetInputData(sphereSource);
#endif
            vtkMarchingCubes surface = vtkMarchingCubes.New();

#if VTK_MAJOR_VERSION_5
            surface.SetInputConnection(voxelModeller.GetOutputPort());
#else
            surface.SetInputData(voxelModeller);
#endif
            surface.ComputeNormalsOn();
            surface.SetValue(0, 0.5);
            vtkPolyDataMapper mapper = vtkPolyDataMapper.New();
#if VTK_MAJOR_VERSION_5
            mapper.SetInputConnection(surface.GetOutputPort());
#else
            mapper.SetInputData(surface);
#endif
            vtkActor actor = vtkActor.New();
            actor.SetMapper(mapper);

            // 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(actor);
        }
コード例 #2
0
        private void ExtractLargestIsoSurface(string filePath, double threshold, bool extractLargest)
        {
            // Load data
            vtkStructuredPointsReader reader = vtkStructuredPointsReader.New();

            reader.SetFileName(filePath);

            // Create a 3D model using marching cubes
            vtkMarchingCubes mc = vtkMarchingCubes.New();

            mc.SetInputConnection(reader.GetOutputPort());
            mc.ComputeNormalsOn();
            mc.ComputeGradientsOn();
            mc.SetValue(0, threshold); // second value acts as threshold

            // To remain largest region
            vtkPolyDataConnectivityFilter confilter = vtkPolyDataConnectivityFilter.New();

            confilter.SetInputConnection(mc.GetOutputPort());
            confilter.SetExtractionModeToLargestRegion();

            // Create a mapper
            vtkPolyDataMapper mapper = vtkPolyDataMapper.New();

            if (extractLargest)
            {
                mapper.SetInputConnection(confilter.GetOutputPort());
            }
            else
            {
                mapper.SetInputConnection(mc.GetOutputPort());
            }

            mapper.ScalarVisibilityOff(); // utilize actor's property I set

            // Visualize
            vtkActor actor = vtkActor.New();

            actor.GetProperty().SetColor(1, 1, 1);
            actor.SetMapper(mapper);

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

            // add our actor to the renderer
            renderer.AddActor(actor);
        }
コード例 #3
0
        public static vtkPolyData MarchingCubeImageData(vtkImageData imageData, double ISO)
        {
            // extract the skin
            vtkMarchingCubes _skinExtractor = new vtkMarchingCubes();

            _skinExtractor.SetInput(imageData);
            _skinExtractor.Update();
            Console.WriteLine("Extractor.Update(); Done");

            //_skinExtractor.SetValue(0, 155);
            _skinExtractor.SetValue(0, ISO);
            _skinExtractor.Update();

            vtkStripper _skinStripper = new vtkStripper();

            _skinStripper.SetInput(_skinExtractor.GetOutput());
            _skinStripper.Update();
            Console.WriteLine("Stripper.Update(); Done");

            vtkPolyData ret = _skinStripper.GetOutput();

            return(ret);
        }