Exemplo n.º 1
0
        private vtkActor DiskSector(double innerRadius, double radius, double clip1X, double clip1Y, double clip2X, double clip2Y, Color color)
        {
            vtkProperty arcColor = vtkProperty.New();

            arcColor.SetColor(color.r, color.g, color.b);

            vtkDiskSource outerDisk = vtkDiskSource.New();

            outerDisk.SetCircumferentialResolution(50);
            outerDisk.SetRadialResolution(50);
            outerDisk.SetInnerRadius(innerRadius);
            outerDisk.SetOuterRadius(innerRadius + radius);

            // Define a clipping plane
            vtkPlane clipPlane = vtkPlane.New();

            clipPlane.SetNormal(clip1X, clip1Y, 0);
            clipPlane.SetOrigin(0.0, 0.0, 0.0);

            // Define a clipping plane
            vtkPlane clipPlane2 = vtkPlane.New();

            clipPlane2.SetNormal(clip2X, clip2Y, 0);
            clipPlane2.SetOrigin(0, 0, 0);


            vtkClipPolyData clipper = vtkClipPolyData.New();

            clipper.SetInputConnection(outerDisk.GetOutputPort());
            clipper.SetClipFunction(clipPlane);

            vtkClipPolyData clipper2 = vtkClipPolyData.New();

            clipper2.SetInputConnection(clipper.GetOutputPort());
            clipper2.SetClipFunction(clipPlane2);


            // Visualize
            vtkPolyDataMapper mapper = vtkPolyDataMapper.New();

            mapper.SetInputConnection(clipper2.GetOutputPort());


            vtkActor actor = vtkActor.New();

            actor.SetMapper(mapper);
            actor.SetProperty(arcColor);


            return(actor);
        }
Exemplo n.º 2
0
        private void SolidClip()
        {
            // Create a superquadric
            vtkSuperquadricSource superquadricSource = vtkSuperquadricSource.New();

            superquadricSource.SetPhiRoundness(3.1);
            superquadricSource.SetThetaRoundness(2.2);

            // Define a clipping plane
            vtkPlane clipPlane = vtkPlane.New();

            clipPlane.SetNormal(1.0, -1.0, -1.0);
            clipPlane.SetOrigin(0.0, 0.0, 0.0);

            // Clip the source with the plane
            vtkClipPolyData clipper = vtkClipPolyData.New();

#if VTK_MAJOR_VERSION_5
            clipper.SetInputConnection(superquadricSource.GetOutputPort());
#else
            clipper.SetInputData(superquadricSource);
#endif
            clipper.SetClipFunction(clipPlane);

            //Create a mapper and actor
            vtkPolyDataMapper superquadricMapper = vtkPolyDataMapper.New();
#if VTK_MAJOR_VERSION_5
            superquadricMapper.SetInputConnection(clipper.GetOutputPort());
#else
            superquadricMapper.SetInputData(clipper);
#endif
            vtkActor superquadricActor = vtkActor.New();
            superquadricActor.SetMapper(superquadricMapper);

            // Create a property to be used for the back faces. Turn off all
            // shading by specifying 0 weights for specular and diffuse. Max the
            // ambient.
            vtkProperty backFaces = vtkProperty.New();
            backFaces.SetSpecular(0.0);
            backFaces.SetDiffuse(0.0);
            backFaces.SetAmbient(1.0);
            backFaces.SetAmbientColor(1.0000, 0.3882, 0.2784);

            superquadricActor.SetBackfaceProperty(backFaces);
            // 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(superquadricActor);
        }
Exemplo n.º 3
0
        static public vtkAlgorithmOutput genFrustumCone(double total_dis, double end_radius,
                                                        double distance, bool is_reverse)
        {
            vtkConeSource cone = vtkConeSource.New();

            cone.SetHeight(total_dis * 1.2);
            cone.SetRadius(end_radius * 1.2);
            cone.SetCenter(0, 0, total_dis * 0.4);
            cone.SetResolution(80);
            cone.SetDirection(0, 0, 1);
            cone.Update();

            vtkPlane plane = vtkPlane.New();

            plane.SetOrigin(0, 0, 0);
            plane.SetNormal(0, 0, 1);

            vtkClipPolyData clipPolyData = vtkClipPolyData.New();

            clipPolyData.SetInputConnection(cone.GetOutputPort());
            clipPolyData.SetClipFunction(plane);
            clipPolyData.GenerateClippedOutputOn();
            clipPolyData.Update();

            vtkPlane plane2 = vtkPlane.New();

            plane2.SetOrigin(0, 0, distance);
            plane2.SetNormal(0, 0, -1);

            vtkClipPolyData clipPolyData2 = vtkClipPolyData.New();

            clipPolyData2.SetInputConnection(clipPolyData.GetOutputPort());
            clipPolyData2.SetClipFunction(plane2);
            clipPolyData2.GenerateClippedOutputOn();
            clipPolyData2.Update();

            if (is_reverse)
            {
                vtkTransform transform = vtkTransform.New();
                transform.RotateWXYZ(180, 0, 1, 0);
                transform.Translate(0, 0, -distance);

                vtkTransformPolyDataFilter transFilter = vtkTransformPolyDataFilter.New();
                transFilter.SetInputConnection(clipPolyData2.GetOutputPort());
                transFilter.SetTransform(transform); //use vtkTransform (or maybe vtkLinearTransform)
                transFilter.Update();
                return(transFilter.GetOutputPort());
            }
            return(clipPolyData2.GetOutputPort());
        }
Exemplo n.º 4
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();
        }
Exemplo n.º 5
0
    /// <summary>
    /// A console application that creates a 
    /// vtkRenderWindow without a Windows Form
    /// </summary>
    /// <param name="argv"></param>
    public static void Main(String[] argv)
    {
        // Demonstrate how to use the vtkBoxWidget 3D widget,
        // This script uses a 3D box widget to define a "clipping box" to clip some
        // simple geometry (a mace). Make sure that you hit the "W" key to activate the widget.
        // Create a mace out of filters.
        sphere = vtkSphereSource.New();
        cone = vtkConeSource.New();
        glyph = vtkGlyph3D.New();

        glyph.SetInputConnection(sphere.GetOutputPort());
        glyph.SetSource(cone.GetOutput());
        glyph.SetVectorModeToUseNormal();
        glyph.SetScaleModeToScaleByVector();
        glyph.SetScaleFactor(0.25);

        // The sphere and spikes are appended into a single polydata. This just makes things
        // simpler to manage.
        apd = vtkAppendPolyData.New();
        apd.AddInput(glyph.GetOutput());
        apd.AddInput(sphere.GetOutput());

        maceMapper = vtkPolyDataMapper.New();
        maceMapper.SetInputConnection(apd.GetOutputPort());

        maceActor = vtkLODActor.New();
        maceActor.SetMapper(maceMapper);
        maceActor.VisibilityOn();

        // This portion of the code clips the mace with the vtkPlanes implicit function.
        // The clipped region is colored green.
        planes = vtkPlanes.New();
        clipper = vtkClipPolyData.New();

        clipper.SetInputConnection(apd.GetOutputPort());
        clipper.SetClipFunction(planes);
        clipper.InsideOutOn();

        selectMapper = vtkPolyDataMapper.New();
        selectMapper.SetInputConnection(clipper.GetOutputPort());

        selectActor = vtkLODActor.New();
        selectActor.SetMapper(selectMapper);
        selectActor.GetProperty().SetColor(0, 1, 0);
        selectActor.VisibilityOff();
        selectActor.SetScale(1.01, 1.01, 1.01);

        // Create the RenderWindow, Renderer and both Actors
        ren1 = vtkRenderer.New();
        renWin = vtkRenderWindow.New();
        renWin.AddRenderer(ren1);
        iren = vtkRenderWindowInteractor.New();
        iren.SetRenderWindow(renWin);

        // The SetInteractor method is how 3D widgets are associated with the render
        // window interactor. Internally, SetInteractor sets up a bunch of callbacks
        // using the Command/Observer mechanism (AddObserver()).
        boxWidget = vtkBoxWidget.New();
        boxWidget.SetInteractor(iren);
        boxWidget.SetPlaceFactor(1.25);
        ren1.AddActor(maceActor);
        ren1.AddActor(selectActor);

        // Add the actors to the renderer, set the background and size
        ren1.SetBackground(0.1, 0.2, 0.4);
        renWin.SetSize(300, 300);

        // Place the interactor initially. The input to a 3D widget is used to
        // initially position and scale the widget. The EndInteractionEvent is
        // observed which invokes the SelectPolygons callback.
        boxWidget.SetInput(glyph.GetOutput());
        boxWidget.PlaceWidget();
        boxWidget.EndInteractionEvt += new vtkObject.vtkObjectEventHandler(SelectPolygons);

        // render the image
        iren.Initialize();
        iren.Start();
        //Clean up
        deleteAllVTKObjects();
    }
Exemplo n.º 6
0
        private void SelectPolyData()
        {
            vtkSphereSource sphereSource = vtkSphereSource.New();

            sphereSource.Update();

            vtkPoints selectionPoints = vtkPoints.New();

            selectionPoints.InsertPoint(0, -0.16553, 0.135971, 0.451972);
            selectionPoints.InsertPoint(1, -0.0880123, -0.134952, 0.4747);
            selectionPoints.InsertPoint(2, 0.00292618, -0.134604, 0.482459);
            selectionPoints.InsertPoint(3, 0.0641941, 0.067112, 0.490947);
            selectionPoints.InsertPoint(4, 0.15577, 0.0734765, 0.469245);
            selectionPoints.InsertPoint(5, 0.166667, -0.129217, 0.454622);
            selectionPoints.InsertPoint(6, 0.241259, -0.123363, 0.420581);
            selectionPoints.InsertPoint(7, 0.240334, 0.0727106, 0.432555);
            selectionPoints.InsertPoint(8, 0.308529, 0.0844311, 0.384357);
            selectionPoints.InsertPoint(9, 0.32672, -0.121674, 0.359187);
            selectionPoints.InsertPoint(10, 0.380721, -0.117342, 0.302527);
            selectionPoints.InsertPoint(11, 0.387804, 0.0455074, 0.312375);
            selectionPoints.InsertPoint(12, 0.43943, -0.111673, 0.211707);
            selectionPoints.InsertPoint(13, 0.470984, -0.0801913, 0.147919);
            selectionPoints.InsertPoint(14, 0.436777, 0.0688872, 0.233021);
            selectionPoints.InsertPoint(15, 0.44874, 0.188852, 0.109882);
            selectionPoints.InsertPoint(16, 0.391352, 0.254285, 0.176943);
            selectionPoints.InsertPoint(17, 0.373274, 0.154162, 0.294296);
            selectionPoints.InsertPoint(18, 0.274659, 0.311654, 0.276609);
            selectionPoints.InsertPoint(19, 0.206068, 0.31396, 0.329702);
            selectionPoints.InsertPoint(20, 0.263789, 0.174982, 0.387308);
            selectionPoints.InsertPoint(21, 0.213034, 0.175485, 0.417142);
            selectionPoints.InsertPoint(22, 0.169113, 0.261974, 0.390286);
            selectionPoints.InsertPoint(23, 0.102552, 0.25997, 0.414814);
            selectionPoints.InsertPoint(24, 0.131512, 0.161254, 0.454705);
            selectionPoints.InsertPoint(25, 0.000192443, 0.156264, 0.475307);
            selectionPoints.InsertPoint(26, -0.0392091, 0.000251724, 0.499943);
            selectionPoints.InsertPoint(27, -0.096161, 0.159646, 0.46438);

            vtkSelectPolyData loop = vtkSelectPolyData.New();

            loop.SetInputConnection(sphereSource.GetOutputPort());
            loop.SetLoop(selectionPoints);
            loop.GenerateSelectionScalarsOn();
            loop.SetSelectionModeToSmallestRegion(); //negative scalars inside

            vtkClipPolyData clip =                   //clips out positive region
                                   vtkClipPolyData.New();

            clip.SetInputConnection(loop.GetOutputPort());

            vtkPolyDataMapper clipMapper = vtkPolyDataMapper.New();

            clipMapper.SetInputConnection(clip.GetOutputPort());

            vtkLODActor clipActor = vtkLODActor.New();

            clipActor.SetMapper(clipMapper);

            // 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, .2, .4);
            renderWindow.SetSize(500, 250);
            // add our actor to the renderer
            renderer.AddActor(clipActor);
        }