コード例 #1
0
        static public vtkProp3D genQuadricSurfaceActor(CompontData data, vtkProperty pro)
        {
            if (data.restriction != null)
            {
                return(genActorByRestriction(data, pro));
            }
            QuadricSurfaceData s = (QuadricSurfaceData)data;

            vtkQuadric quadric = vtkQuadric.New();

            quadric.SetCoefficients(s.param[0], s.param[1], s.param[2], s.param[3], s.param[4], s.param[5], s.param[6],
                                    s.param[7], s.param[8], s.param[9] + 1);

            //二次函数采样分辨率
            vtkSampleFunction sample = vtkSampleFunction.New();

            sample.SetSampleDimensions(60, 60, 30);
            sample.SetImplicitFunction(quadric);
            sample.SetModelBounds(s.param[10], s.param[11], s.param[12], s.param[13], s.param[14], s.param[15]);
            vtkContourFilter contourFilter = vtkContourFilter.New();

            contourFilter.SetInputConnection(sample.GetOutputPort());
            contourFilter.GenerateValues(1, 1, 1);
            contourFilter.Update();

            return(genUserActor(data, contourFilter.GetOutputPort(), pro));
        }
コード例 #2
0
        private void ImplicitBoolean()
        {
            vtkSphere sphere1 = vtkSphere.New();

            sphere1.SetCenter(.9, 0, 0);
            vtkSphere sphere2 = vtkSphere.New();

            sphere2.SetCenter(-.9, 0, 0);

            vtkImplicitBoolean implicitBoolean = vtkImplicitBoolean.New();

            implicitBoolean.AddFunction(sphere1);
            implicitBoolean.AddFunction(sphere2);
            implicitBoolean.SetOperationTypeToUnion();
            //implicitBoolean.SetOperationTypeToIntersection();

            // Sample the function
            vtkSampleFunction sample = vtkSampleFunction.New();

            sample.SetSampleDimensions(50, 50, 50);
            sample.SetImplicitFunction(implicitBoolean);
            double value = 3.0;
            double xmin = -value, xmax = value,
                   ymin = -value, ymax = value,
                   zmin = -value, zmax = value;

            sample.SetModelBounds(xmin, xmax, ymin, ymax, zmin, zmax);

            // Create the 0 isosurface
            vtkContourFilter contours       = vtkContourFilter.New();

#if VTK_MAJOR_VERSION_5
            contours.SetInputConnection(sample.GetOutputPort());
#else
            contours.SetInputData(sample);
#endif
            contours.GenerateValues(1, 1, 1);

            // Map the contours to graphical primitives
            vtkPolyDataMapper contourMapper = vtkPolyDataMapper.New();
#if VTK_MAJOR_VERSION_5
            contourMapper.SetInputConnection(contours.GetOutputPort());
#else
            contourMapper.SetInputData(contours);
#endif
            contourMapper.ScalarVisibilityOff();

            // Create an actor for the contours
            vtkActor contourActor           = vtkActor.New();
            contourActor.SetMapper(contourMapper);
            // 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(contourActor);
        }
コード例 #3
0
        private void SampleFunction()
        {
            vtkSphere sphere = vtkSphere.New();

            // Sample the function
            vtkSampleFunction sample = vtkSampleFunction.New();

            sample.SetSampleDimensions(50, 50, 50);
            sample.SetImplicitFunction(sphere);
            double value = 2.0;
            double xmin = -value, xmax = value, ymin = -value, ymax = value, zmin = -value, zmax = value;

            sample.SetModelBounds(xmin, xmax, ymin, ymax, zmin, zmax);

            // Create the 0 isosurface
            vtkContourFilter contours       = vtkContourFilter.New();

#if VTK_MAJOR_VERSION_5
            contours.SetInputConnection(sample.GetOutputPort());
#else
            contours.SetInputData(sample);
#endif
            contours.GenerateValues(1, 1, 1);

            // Map the contours to graphical primitives
            vtkPolyDataMapper contourMapper = vtkPolyDataMapper.New();
#if VTK_MAJOR_VERSION_5
            contourMapper.SetInputConnection(contours.GetOutputPort());
#else
            contourMapper.SetInputData(contours);
#endif
            contourMapper.SetScalarRange(0.0, 1.2);

            // Create an actor for the contours
            vtkActor contourActor           = vtkActor.New();
            contourActor.SetMapper(contourMapper);

            // -- create a box around the function to indicate the sampling volume --

            // Create outline
            vtkOutlineFilter outline = vtkOutlineFilter.New();
#if VTK_MAJOR_VERSION_5
            outline.SetInputConnection(sample.GetOutputPort());
#else
            outline.SetInputData(sample);
#endif

            // Map it to graphics primitives
            vtkPolyDataMapper outlineMapper = vtkPolyDataMapper.New();
#if VTK_MAJOR_VERSION_5
            outlineMapper.SetInputConnection(outline.GetOutputPort());
#else
            outlineMapper.SetInputData(outline);
#endif

            // Create an actor for it
            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(1.0, 1.0, 1.0);
            // add our actor to the renderer
            renderer.AddActor(contourActor);
            renderer.AddActor(outlineActor);
        }