예제 #1
0
        public Sphere(ARenderable parent)
            : base(parent)
        {
            Name   = "Sphere";
            sphere = vtkSphereSource.New();
            sphere.SetThetaResolution(8);
            sphere.SetPhiResolution(16);

            shrink = vtkShrinkPolyData.New();
            shrink.SetInputConnection(sphere.GetOutputPort());
            shrink.SetShrinkFactor(0.9);

            move = vtkTransform.New();
            move.Translate(_random.NextDouble(), _random.NextDouble(), _random.NextDouble());
            moveFilter = vtkTransformPolyDataFilter.New();
            moveFilter.SetTransform(move);

            moveFilter.SetInputConnection(shrink.GetOutputPort());

            mapper = vtkPolyDataMapper.New();
            mapper.SetInputConnection(moveFilter.GetOutputPort());

            Actors = new ObservableCollection <vtkActor>();
            // The actor links the data pipeline to the rendering subsystem
            vtkActor actor = vtkActor.New();

            actor.SetMapper(mapper);
            actor.GetProperty().SetColor(1, 0, 0);
            Actors.Add(actor);
        }
예제 #2
0
        private void DrawSphere(double radius)
        {
            vtkSphereSource sphereSource = vtkSphereSource.New();

            sphereSource.SetThetaResolution(8);
            sphereSource.SetPhiResolution(16);
            sphereSource.SetRadius(radius);

            vtkShrinkPolyData shrink = vtkShrinkPolyData.New();

            shrink.SetInputConnection(sphereSource.GetOutputPort());
            shrink.SetShrinkFactor(0.9);

            vtkPolyDataMapper sphereMapper = vtkPolyDataMapper.New();

            //sphereMapper.SetInputConnection(sphereSource.GetOutputPort());
            sphereMapper.SetInputConnection(shrink.GetOutputPort());

            vtkActor sphereActor = vtkActor.New();

            sphereActor.SetMapper(sphereMapper);
            sphereActor.GetProperty().SetColor(1, 0, 0);

            vtkRenderer     sphereRender = vtkRenderer.New();
            vtkRenderWindow renWin       = myRenderWindowControl.RenderWindow;

            renWin.AddRenderer(sphereRender);

            sphereRender.AddActor(sphereActor);
            sphereRender.SetBackground(0.0, 0.0, 1.0);
        }
예제 #3
0
        private void ShrinkPolyData()
        {
            vtkSphereSource sphereSource = vtkSphereSource.New();

            sphereSource.SetRadius(10);
            sphereSource.SetPhiResolution(12);
            sphereSource.SetThetaResolution(12);
            sphereSource.Update();

            vtkShrinkPolyData shrinkFilter = vtkShrinkPolyData.New();

            shrinkFilter.SetInputConnection(sphereSource.GetOutputPort());
            shrinkFilter.Update();

            vtkPolyDataMapper mapper = vtkPolyDataMapper.New();

            mapper.SetInputConnection(shrinkFilter.GetOutputPort());

            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 the actors to the renderer, set the background and size
            renderer.AddActor(actor);
        }
        private void vtkPolyDataConnectivityFilter_LargestRegion()
        {
            // Small sphere
            vtkSphereSource sphereSource1 = vtkSphereSource.New();

            sphereSource1.Update();

            // Large sphere
            vtkSphereSource sphereSource2 = vtkSphereSource.New();

            sphereSource2.SetRadius(10);
            sphereSource2.SetCenter(25, 0, 0);
            sphereSource2.SetThetaResolution(10);
            sphereSource2.SetPhiResolution(10);
            sphereSource2.Update();

            vtkAppendPolyData appendFilter = vtkAppendPolyData.New();

            appendFilter.AddInputConnection(sphereSource1.GetOutputPort());
            appendFilter.AddInputConnection(sphereSource2.GetOutputPort());
            appendFilter.Update();

            vtkPolyDataConnectivityFilter connectivityFilter = vtkPolyDataConnectivityFilter.New();

            connectivityFilter.SetInputConnection(appendFilter.GetOutputPort());
            connectivityFilter.SetExtractionModeToLargestRegion();
            connectivityFilter.Update();

            // Create a mapper and actor for original data
            vtkPolyDataMapper originalMapper = vtkPolyDataMapper.New();

            originalMapper.SetInputConnection(appendFilter.GetOutputPort());
            originalMapper.Update();

            vtkActor originalActor = vtkActor.New();

            originalActor.SetMapper(originalMapper);

            // Create a mapper and actor for extracted data
            vtkPolyDataMapper extractedMapper = vtkPolyDataMapper.New();

            extractedMapper.SetInputConnection(connectivityFilter.GetOutputPort());
            extractedMapper.Update();

            vtkActor extractedActor = vtkActor.New();

            extractedActor.GetProperty().SetColor(1, 0, 0);
            extractedActor.SetMapper(extractedMapper);
            // get a reference to the renderwindow of our renderWindowControl1
            vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow;
            // renderer
            vtkRenderer renderer = renderWindow.GetRenderers().GetFirstRenderer();

            // set background color
            renderer.SetBackground(0.2, 0.3, 0.4);
            // add our actor to the renderer
            renderer.AddActor(originalActor);
            renderer.AddActor(extractedActor);
        }
예제 #5
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);
        }
예제 #6
0
        ///<summary>Entry Point</summary>
        static void Main(string[] args)
        {
            // Create a simple sphere. A pipeline is created.
            sphere = vtkSphereSource.New();
            sphere.SetThetaResolution(8);
            sphere.SetPhiResolution(16);

            shrink = vtkShrinkPolyData.New();
            shrink.SetInputConnection(sphere.GetOutputPort());
            shrink.SetShrinkFactor(0.9);

            mapper = vtkPolyDataMapper.New();
            mapper.SetInputConnection(shrink.GetOutputPort());

            // The actor links the data pipeline to the rendering subsystem
            actor = vtkActor.New();
            actor.SetMapper(mapper);
            actor.GetProperty().SetColor(1, 0, 0);

            // Create components of the rendering subsystem
            //
            ren1 = vtkRenderer.New();
            renWin = vtkRenderWindow.New();
            renWin.AddRenderer(ren1);
            iren = vtkRenderWindowInteractor.New();
            iren.SetRenderWindow(renWin);

            // Add the actors to the renderer, set the window size
            //
            ren1.AddViewProp(actor);
            renWin.SetSize(250, 250);
            renWin.Render();
            camera = ren1.GetActiveCamera();
            camera.Zoom(1.5);

            // render the image and start the event loop
            //
            renWin.Render();

            iren.Initialize();
            iren.Start();

            deleteAllVTKObjects();
        }
예제 #7
0
        private vtkActor CreateSphereActor(double radius)
        {
            Kitware.VTK.vtkActor a = new Kitware.VTK.vtkActor();

            vtkSphereSource sphereSource3D = new vtkSphereSource();

            sphereSource3D.SetCenter(0.0, 0.0, 0.0);
            sphereSource3D.SetRadius(radius);
            sphereSource3D.SetThetaResolution(10);
            sphereSource3D.SetPhiResolution(10);

            vtkPolyDataMapper sphereMapper3D = vtkPolyDataMapper.New();

            sphereMapper3D.SetInputConnection(sphereSource3D.GetOutputPort());
            a.SetMapper(sphereMapper3D);
            a.GetProperty().SetColor(0.95, 0.5, 0.3);
            a.GetProperty().SetOpacity(0.5);

            return(a);
        }
예제 #8
0
        public SpherePackage(vtkRenderer aRender)
        {
            _aRender = aRender;

            _sphereSource = vtkSphereSource.New();
            _sphereSource.SetRadius(3);
            _sphereSource.SetRadius(0.5);
            _sphereSource.SetThetaResolution(26);
            _sphereSource.SetPhiResolution(26);
            _sphereSource.ModifiedEvt += _sphereSource_ModifiedEvt;

            SphereMapper = vtkPolyDataMapper.New();
            SphereMapper.SetInputConnection(_sphereSource.GetOutputPort());

            _sphereActor = vtkActor.New();
            _sphereActor.SetMapper(SphereMapper);
            aRender.AddActor(_sphereActor);

            _aText = vtkVectorText.New();
            _aText.SetText("");

            vtkPolyDataMapper textMapper = vtkPolyDataMapper.New();

            textMapper.SetInputConnection(_aText.GetOutputPort());
            _textActor = vtkFollower.New();
            //textActor.GetProperty().SetColor(point.Color.X, point.Color.Y, point.Color.Z);
            _textActor.SetMapper(textMapper);
            //textActor.SetScale(0.2, 0.2, 0.2);
            //textActor.SetScale(4);
            _textActor.SetCamera(aRender.GetActiveCamera());
            aRender.AddActor(_textActor);

            //SetOpacity(0.5f);

            //VisOff();

            RandColor();
        }
예제 #9
0
        private void renderWindowControl1_Load(object sender, EventArgs e)
        {
            vtkSphereSource sphere = vtkSphereSource.New();

            sphere.SetThetaResolution(8);
            sphere.SetPhiResolution(16);

            vtkShrinkPolyData shrink = vtkShrinkPolyData.New();

            shrink.SetInputConnection(sphere.GetOutputPort());
            shrink.SetShrinkFactor(0.5);

            vtkPolyDataMapper mapper = vtkPolyDataMapper.New();

            mapper.SetInputConnection(shrink.GetOutputPort());

            vtkActor actor = vtkActor.New();

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

            vtkRenderer renderer = renderWindowControl1
                                   .RenderWindow.GetRenderers().GetFirstRenderer();
            vtkRenderWindow rendererWindow = renderWindowControl1
                                             .RenderWindow;

            renderer.AddViewProp(actor); //Actor to specjalizacja Prop
            rendererWindow.SetSize(250, 250);
            rendererWindow.Render();

            vtkCamera camera = renderer.GetActiveCamera();

            camera.Zoom(1.5);

            //do debugu
            //renderWindowControl1.AddTestActors = true;
        }
예제 #10
0
        private void renderWindowControl1_Load(object sender, EventArgs e)
        {
            // Create a simple sphere. A pipeline is created.
            vtkSphereSource sphere = vtkSphereSource.New();

            sphere.SetThetaResolution(8);
            sphere.SetPhiResolution(16);

            vtkShrinkPolyData shrink = vtkShrinkPolyData.New();

            shrink.SetInputConnection(sphere.GetOutputPort());
            shrink.SetShrinkFactor(0.9);

            vtkPolyDataMapper mapper = vtkPolyDataMapper.New();

            mapper.SetInputConnection(shrink.GetOutputPort());

            // The actor links the data pipeline to the rendering subsystem
            vtkActor actor = vtkActor.New();

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

            // Create components of the rendering subsystem
            //
            vtkRenderer     ren1   = renderWindowControl1.RenderWindow.GetRenderers().GetFirstRenderer();
            vtkRenderWindow renWin = renderWindowControl1.RenderWindow;

            // Add the actors to the renderer, set the window size
            //
            ren1.AddViewProp(actor);
            renWin.SetSize(250, 250);
            renWin.Render();
            vtkCamera camera = ren1.GetActiveCamera();

            camera.Zoom(1.5);
        }
예제 #11
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();
        }
예제 #12
0
    /// <summary>
    /// Entry Point
    /// </summary>
    /// <param name="argv"></param>
    public static void Main(String[] argv)
    {
        // This example demonstrates how to use 2D Delaunay triangulation.
        // We create a fancy image of a 2D Delaunay triangulation. Points are
        // randomly generated.
        // first we load in the standard vtk packages into tcl
        // Generate some random points
        math = vtkMath.New();
        points = vtkPoints.New();
        for(int i = 0; i < 50; i++)
        {
            points.InsertPoint(i, vtkMath.Random(0, 1), vtkMath.Random(0, 1), 0.0);
        }

        // Create a polydata with the points we just created.
        profile = vtkPolyData.New();
        profile.SetPoints(points);

        // Perform a 2D Delaunay triangulation on them.
        del = vtkDelaunay2D.New();
        del.SetInput(profile);
        del.SetTolerance(0.001);

        mapMesh = vtkPolyDataMapper.New();
        mapMesh.SetInputConnection(del.GetOutputPort());

        meshActor = vtkActor.New();
        meshActor.SetMapper(mapMesh);
        meshActor.GetProperty().SetColor(.1, .2, .4);

        // We will now create a nice looking mesh by wrapping the edges in tubes,
        // and putting fat spheres at the points.
        extract = vtkExtractEdges.New();
        extract.SetInputConnection(del.GetOutputPort());

        tubes = vtkTubeFilter.New();
        tubes.SetInputConnection(extract.GetOutputPort());
        tubes.SetRadius(0.01);
        tubes.SetNumberOfSides(6);

        mapEdges = vtkPolyDataMapper.New();
        mapEdges.SetInputConnection(tubes.GetOutputPort());

        edgeActor = vtkActor.New();
        edgeActor.SetMapper(mapEdges);
        edgeActor.GetProperty().SetColor(0.2000, 0.6300, 0.7900);
        edgeActor.GetProperty().SetSpecularColor(1, 1, 1);
        edgeActor.GetProperty().SetSpecular(0.3);
        edgeActor.GetProperty().SetSpecularPower(20);
        edgeActor.GetProperty().SetAmbient(0.2);
        edgeActor.GetProperty().SetDiffuse(0.8);

        ball = vtkSphereSource.New();
        ball.SetRadius(0.025);
        ball.SetThetaResolution(12);
        ball.SetPhiResolution(12);

        balls = vtkGlyph3D.New();
        balls.SetInputConnection(del.GetOutputPort());
        balls.SetSourceConnection(ball.GetOutputPort());

        mapBalls = vtkPolyDataMapper.New();
        mapBalls.SetInputConnection(balls.GetOutputPort());

        ballActor = vtkActor.New();
        ballActor.SetMapper(mapBalls);
        ballActor.GetProperty().SetColor(1.0000, 0.4118, 0.7059);
        ballActor.GetProperty().SetSpecularColor(1, 1, 1);
        ballActor.GetProperty().SetSpecular(0.3);
        ballActor.GetProperty().SetSpecularPower(20);
        ballActor.GetProperty().SetAmbient(0.2);
        ballActor.GetProperty().SetDiffuse(0.8);

        // Create graphics objects
        // Create the rendering window, renderer, and interactive renderer
        ren1 = vtkRenderer.New();
        renWin = vtkRenderWindow.New();
        renWin.AddRenderer(ren1);
        iren = vtkRenderWindowInteractor.New();
        iren.SetRenderWindow(renWin);

        // Add the actors to the renderer, set the background and size
        ren1.AddActor(ballActor);
        ren1.AddActor(edgeActor);
        ren1.SetBackground(1, 1, 1);
        renWin.SetSize(150, 150);

        // render the image
        ren1.ResetCamera();
        ren1.GetActiveCamera().Zoom(1.5);
        iren.Initialize();
        iren.Start();

        // Clean Up
        deleteAllVTKObjects();
    }
예제 #13
0
    /// <summary>
    /// The main entry method called by the CSharp driver
    /// </summary>
    /// <param name="argv"></param>
    public static void AVTenEllip(String [] argv)
    {
        //Prefix Content is: ""

          // create tensor ellipsoids[]
          // Create the RenderWindow, Renderer and interactive renderer[]
          //[]
          ren1 = vtkRenderer.New();
          renWin = vtkRenderWindow.New();
          renWin.SetMultiSamples(0);
          renWin.AddRenderer((vtkRenderer)ren1);
          iren = new vtkRenderWindowInteractor();
          iren.SetRenderWindow((vtkRenderWindow)renWin);
          //[]
          // Create tensor ellipsoids[]
          //[]
          // generate tensors[]
          ptLoad = new vtkPointLoad();
          ptLoad.SetLoadValue((double)100.0);
          ptLoad.SetSampleDimensions((int)6,(int)6,(int)6);
          ptLoad.ComputeEffectiveStressOn();
          ptLoad.SetModelBounds((double)-10,(double)10,(double)-10,(double)10,(double)-10,(double)10);
          // extract plane of data[]
          plane = new vtkImageDataGeometryFilter();
          plane.SetInputConnection((vtkAlgorithmOutput)ptLoad.GetOutputPort());
          plane.SetExtent((int)2,(int)2,(int)0,(int)99,(int)0,(int)99);
          // Generate ellipsoids[]
          sphere = new vtkSphereSource();
          sphere.SetThetaResolution((int)8);
          sphere.SetPhiResolution((int)8);
          ellipsoids = new vtkTensorGlyph();
          ellipsoids.SetInputConnection((vtkAlgorithmOutput)ptLoad.GetOutputPort());
          ellipsoids.SetSourceConnection((vtkAlgorithmOutput)sphere.GetOutputPort());
          ellipsoids.SetScaleFactor((double)10);
          ellipsoids.ClampScalingOn();
          ellipNormals = new vtkPolyDataNormals();
          ellipNormals.SetInputConnection((vtkAlgorithmOutput)ellipsoids.GetOutputPort());
          // Map contour[]
          lut = new vtkLogLookupTable();
          lut.SetHueRange((double).6667,(double)0.0);
          ellipMapper = vtkPolyDataMapper.New();
          ellipMapper.SetInputConnection((vtkAlgorithmOutput)ellipNormals.GetOutputPort());
          ellipMapper.SetLookupTable((vtkScalarsToColors)lut);
          plane.Update();
          //force update for scalar range[]
          ellipMapper.SetScalarRange((double)((vtkDataSet)plane.GetOutput()).GetScalarRange()[0],(double)((vtkDataSet)plane.GetOutput()).GetScalarRange()[1]);
          ellipActor = new vtkActor();
          ellipActor.SetMapper((vtkMapper)ellipMapper);
          //[]
          // Create outline around data[]
          //[]
          outline = new vtkOutlineFilter();
          outline.SetInputConnection((vtkAlgorithmOutput)ptLoad.GetOutputPort());
          outlineMapper = vtkPolyDataMapper.New();
          outlineMapper.SetInputConnection((vtkAlgorithmOutput)outline.GetOutputPort());
          outlineActor = new vtkActor();
          outlineActor.SetMapper((vtkMapper)outlineMapper);
          outlineActor.GetProperty().SetColor((double)0,(double)0,(double)0);
          //[]
          // Create cone indicating application of load[]
          //[]
          coneSrc = new vtkConeSource();
          coneSrc.SetRadius((double).5);
          coneSrc.SetHeight((double)2);
          coneMap = vtkPolyDataMapper.New();
          coneMap.SetInputConnection((vtkAlgorithmOutput)coneSrc.GetOutputPort());
          coneActor = new vtkActor();
          coneActor.SetMapper((vtkMapper)coneMap);
          coneActor.SetPosition((double)0,(double)0,(double)11);
          coneActor.RotateY((double)90);
          coneActor.GetProperty().SetColor((double)1,(double)0,(double)0);
          camera = new vtkCamera();
          camera.SetFocalPoint((double)0.113766,(double)-1.13665,(double)-1.01919);
          camera.SetPosition((double)-29.4886,(double)-63.1488,(double)26.5807);
          camera.SetViewAngle((double)24.4617);
          camera.SetViewUp((double)0.17138,(double)0.331163,(double)0.927879);
          camera.SetClippingRange((double)1,(double)100);
          ren1.AddActor((vtkProp)ellipActor);
          ren1.AddActor((vtkProp)outlineActor);
          ren1.AddActor((vtkProp)coneActor);
          ren1.SetBackground((double)1.0,(double)1.0,(double)1.0);
          ren1.SetActiveCamera((vtkCamera)camera);
          renWin.SetSize((int)400,(int)400);
          renWin.Render();
          // prevent the tk window from showing up then start the event loop[]

        //deleteAllVTKObjects();
    }
예제 #14
0
    /// <summary>
    /// The main entry method called by the CSharp driver
    /// </summary>
    /// <param name="argv"></param>
    public static void AVclosedSplines(String [] argv)
    {
        //Prefix Content is: ""

        // get the interactor ui[]
        // Now create the RenderWindow, Renderer and Interactor[]
        //[]
        ren1   = vtkRenderer.New();
        renWin = vtkRenderWindow.New();
        renWin.AddRenderer((vtkRenderer)ren1);
        iren = new vtkRenderWindowInteractor();
        iren.SetRenderWindow((vtkRenderWindow)renWin);
        math = new vtkMath();
        numberOfInputPoints = 30;
        aKSplineX           = new vtkKochanekSpline();
        aKSplineX.ClosedOn();
        aKSplineY = new vtkKochanekSpline();
        aKSplineY.ClosedOn();
        aKSplineZ = new vtkKochanekSpline();
        aKSplineZ.ClosedOn();
        aCSplineX = new vtkCardinalSpline();
        aCSplineX.ClosedOn();
        aCSplineY = new vtkCardinalSpline();
        aCSplineY.ClosedOn();
        aCSplineZ = new vtkCardinalSpline();
        aCSplineZ.ClosedOn();
        // add some points[]
        inputPoints = new vtkPoints();
        x           = -1.0;
        y           = -1.0;
        z           = 0.0;
        aKSplineX.AddPoint((double)0, (double)x);
        aKSplineY.AddPoint((double)0, (double)y);
        aKSplineZ.AddPoint((double)0, (double)z);
        aCSplineX.AddPoint((double)0, (double)x);
        aCSplineY.AddPoint((double)0, (double)y);
        aCSplineZ.AddPoint((double)0, (double)z);
        inputPoints.InsertPoint((int)0, (double)x, (double)y, (double)z);
        x = 1.0;
        y = -1.0;
        z = 0.0;
        aKSplineX.AddPoint((double)1, (double)x);
        aKSplineY.AddPoint((double)1, (double)y);
        aKSplineZ.AddPoint((double)1, (double)z);
        aCSplineX.AddPoint((double)1, (double)x);
        aCSplineY.AddPoint((double)1, (double)y);
        aCSplineZ.AddPoint((double)1, (double)z);
        inputPoints.InsertPoint((int)1, (double)x, (double)y, (double)z);
        x = 1.0;
        y = 1.0;
        z = 0.0;
        aKSplineX.AddPoint((double)2, (double)x);
        aKSplineY.AddPoint((double)2, (double)y);
        aKSplineZ.AddPoint((double)2, (double)z);
        aCSplineX.AddPoint((double)2, (double)x);
        aCSplineY.AddPoint((double)2, (double)y);
        aCSplineZ.AddPoint((double)2, (double)z);
        inputPoints.InsertPoint((int)2, (double)x, (double)y, (double)z);
        x = -1.0;
        y = 1.0;
        z = 0.0;
        aKSplineX.AddPoint((double)3, (double)x);
        aKSplineY.AddPoint((double)3, (double)y);
        aKSplineZ.AddPoint((double)3, (double)z);
        aCSplineX.AddPoint((double)3, (double)x);
        aCSplineY.AddPoint((double)3, (double)y);
        aCSplineZ.AddPoint((double)3, (double)z);
        inputPoints.InsertPoint((int)3, (double)x, (double)y, (double)z);
        inputData = new vtkPolyData();
        inputData.SetPoints((vtkPoints)inputPoints);
        balls = new vtkSphereSource();
        balls.SetRadius((double).04);
        balls.SetPhiResolution((int)10);
        balls.SetThetaResolution((int)10);
        balls.Update();
        glyphPoints = new vtkGlyph3D();
        glyphPoints.SetInputData((vtkDataObject)inputData);
        glyphPoints.SetSourceData((vtkPolyData)balls.GetOutput());
        glyphMapper = vtkPolyDataMapper.New();
        glyphMapper.SetInputConnection((vtkAlgorithmOutput)glyphPoints.GetOutputPort());
        glyph = new vtkActor();
        glyph.SetMapper((vtkMapper)glyphMapper);
        glyph.GetProperty().SetDiffuseColor((double)1.0000, 0.3882, 0.2784);
        glyph.GetProperty().SetSpecular((double).3);
        glyph.GetProperty().SetSpecularPower((double)30);
        ren1.AddActor((vtkProp)glyph);
        Kpoints              = new vtkPoints();
        Cpoints              = new vtkPoints();
        profileKData         = new vtkPolyData();
        profileCData         = new vtkPolyData();
        numberOfInputPoints  = 5;
        numberOfOutputPoints = 100;
        offset = 1.0;
        //method moved
        fit();
        lines = new vtkCellArray();
        lines.InsertNextCell((int)numberOfOutputPoints);
        i = 0;
        while ((i) < numberOfOutputPoints)
        {
            lines.InsertCellPoint((int)i);
            i = i + 1;
        }

        profileKData.SetPoints((vtkPoints)Kpoints);
        profileKData.SetLines((vtkCellArray)lines);
        profileCData.SetPoints((vtkPoints)Cpoints);
        profileCData.SetLines((vtkCellArray)lines);
        profileKTubes = new vtkTubeFilter();
        profileKTubes.SetNumberOfSides((int)8);
        profileKTubes.SetInputData((vtkDataObject)profileKData);
        profileKTubes.SetRadius((double).01);
        profileKMapper = vtkPolyDataMapper.New();
        profileKMapper.SetInputConnection((vtkAlgorithmOutput)profileKTubes.GetOutputPort());
        profileK = new vtkActor();
        profileK.SetMapper((vtkMapper)profileKMapper);
        profileK.GetProperty().SetDiffuseColor((double)0.8900, 0.8100, 0.3400);
        profileK.GetProperty().SetSpecular((double).3);
        profileK.GetProperty().SetSpecularPower((double)30);
        ren1.AddActor((vtkProp)profileK);
        profileCTubes = new vtkTubeFilter();
        profileCTubes.SetNumberOfSides((int)8);
        profileCTubes.SetInputData((vtkDataObject)profileCData);
        profileCTubes.SetRadius((double).01);
        profileCMapper = vtkPolyDataMapper.New();
        profileCMapper.SetInputConnection((vtkAlgorithmOutput)profileCTubes.GetOutputPort());
        profileC = new vtkActor();
        profileC.SetMapper((vtkMapper)profileCMapper);
        profileC.GetProperty().SetDiffuseColor((double)0.2000, 0.6300, 0.7900);
        profileC.GetProperty().SetSpecular((double).3);
        profileC.GetProperty().SetSpecularPower((double)30);
        ren1.AddActor((vtkProp)profileC);
        ren1.ResetCamera();
        ren1.GetActiveCamera().Dolly((double)1.5);
        ren1.ResetCameraClippingRange();
        renWin.SetSize((int)300, (int)300);
        // render the image[]
        //[]
        iren.Initialize();
        // prevent the tk window from showing up then start the event loop[]
        //method moved
        //method moved
        //method moved
        //method moved
        //method moved
        //method moved

//deleteAllVTKObjects();
    }
예제 #15
0
    /// <summary>
    /// The main entry method called by the CSharp driver
    /// </summary>
    /// <param name="argv"></param>
    public static void AVTestPolyDataPieces(String [] argv)
    {
        //Prefix Content is: ""

        math = new vtkMath();
        vtkMath.RandomSeed((int)22);
        pf = new vtkParallelFactory();
        vtkParallelFactory.RegisterFactory((vtkObjectFactory)pf);
        sphere = new vtkSphereSource();
        sphere.SetPhiResolution((int)32);
        sphere.SetThetaResolution((int)32);
        extract = new vtkExtractPolyDataPiece();
        extract.SetInputConnection((vtkAlgorithmOutput)sphere.GetOutputPort());
        normals = new vtkPolyDataNormals();
        normals.SetInputConnection((vtkAlgorithmOutput)extract.GetOutputPort());
        ps = new vtkPieceScalars();
        ps.SetInputConnection((vtkAlgorithmOutput)normals.GetOutputPort());
        mapper = vtkPolyDataMapper.New();
        mapper.SetInputConnection((vtkAlgorithmOutput)ps.GetOutputPort());
        mapper.SetNumberOfPieces((int)2);
        actor = new vtkActor();
        actor.SetMapper((vtkMapper)mapper);
        sphere2 = new vtkSphereSource();
        sphere2.SetPhiResolution((int)32);
        sphere2.SetThetaResolution((int)32);
        extract2 = new vtkExtractPolyDataPiece();
        extract2.SetInputConnection((vtkAlgorithmOutput)sphere2.GetOutputPort());
        mapper2 = vtkPolyDataMapper.New();
        mapper2.SetInputConnection((vtkAlgorithmOutput)extract2.GetOutputPort());
        mapper2.SetNumberOfPieces((int)2);
        mapper2.SetPiece((int)1);
        mapper2.SetScalarRange((double)0, (double)4);
        mapper2.SetScalarModeToUseCellFieldData();
        mapper2.SetColorModeToMapScalars();
        mapper2.ColorByArrayComponent((string)"vtkGhostLevels", (int)0);
        mapper2.SetGhostLevel((int)4);
        // check the pipeline size[]
        extract2.UpdateInformation();
        psize = new vtkPipelineSize();
        if ((psize.GetEstimatedSize((vtkAlgorithm)extract2, (int)0, (int)0)) > 100)
        {
            //puts skipedputs ['stderr', '"ERROR: Pipeline Size increased"']
        }


        if ((psize.GetNumberOfSubPieces((uint)10, (vtkPolyDataMapper)mapper2)) != 2)
        {
            //puts skipedputs ['stderr', '"ERROR: Number of sub pieces changed"']
        }


        actor2 = new vtkActor();
        actor2.SetMapper((vtkMapper)mapper2);
        actor2.SetPosition((double)1.5, (double)0, (double)0);
        sphere3 = new vtkSphereSource();
        sphere3.SetPhiResolution((int)32);
        sphere3.SetThetaResolution((int)32);
        extract3 = new vtkExtractPolyDataPiece();
        extract3.SetInputConnection((vtkAlgorithmOutput)sphere3.GetOutputPort());
        ps3 = new vtkPieceScalars();
        ps3.SetInputConnection((vtkAlgorithmOutput)extract3.GetOutputPort());
        mapper3 = vtkPolyDataMapper.New();
        mapper3.SetInputConnection((vtkAlgorithmOutput)ps3.GetOutputPort());
        mapper3.SetNumberOfSubPieces((int)8);
        mapper3.SetScalarRange((double)0, (double)8);
        actor3 = new vtkActor();
        actor3.SetMapper((vtkMapper)mapper3);
        actor3.SetPosition((double)0, (double)-1.5, (double)0);
        sphere4 = new vtkSphereSource();
        sphere4.SetPhiResolution((int)32);
        sphere4.SetThetaResolution((int)32);
        extract4 = new vtkExtractPolyDataPiece();
        extract4.SetInputConnection((vtkAlgorithmOutput)sphere4.GetOutputPort());
        ps4 = new vtkPieceScalars();
        ps4.RandomModeOn();
        ps4.SetScalarModeToCellData();
        ps4.SetInputConnection((vtkAlgorithmOutput)extract4.GetOutputPort());
        mapper4 = vtkPolyDataMapper.New();
        mapper4.SetInputConnection((vtkAlgorithmOutput)ps4.GetOutputPort());
        mapper4.SetNumberOfSubPieces((int)8);
        mapper4.SetScalarRange((double)0, (double)8);
        actor4 = new vtkActor();
        actor4.SetMapper((vtkMapper)mapper4);
        actor4.SetPosition((double)1.5, (double)-1.5, (double)0);
        ren = vtkRenderer.New();
        ren.AddActor((vtkProp)actor);
        ren.AddActor((vtkProp)actor2);
        ren.AddActor((vtkProp)actor3);
        ren.AddActor((vtkProp)actor4);
        renWin = vtkRenderWindow.New();
        renWin.AddRenderer((vtkRenderer)ren);
        iren = new vtkRenderWindowInteractor();
        iren.SetRenderWindow((vtkRenderWindow)renWin);
        iren.Initialize();

//deleteAllVTKObjects();
    }
예제 #16
0
        private void SelectAreaClick(vtkObject sender, vtkObjectEventArgs e)
        {
            int[]         clickPos = Inter.GetEventPosition();
            vtkAreaPicker picker   = vtkAreaPicker.New();

            picker.AreaPick(clickPos[0], clickPos[1], clickPos[0] + 100, clickPos[1] + 100, Viewport);

            if (picker.GetActor() != null)
            {
                vtkPlanes          Boundary = picker.GetFrustum();
                vtkExtractGeometry Box      = vtkExtractGeometry.New();
                Box.SetImplicitFunction(Boundary);
                Box.SetInput(picker.GetActor().GetMapper().GetInput());

                vtkVertexGlyphFilter glyphFilter = vtkVertexGlyphFilter.New();
                glyphFilter.SetInputConnection(Box.GetOutputPort());
                glyphFilter.Update();

                vtkPolyData         selected = glyphFilter.GetOutput();
                vtkPoints           points   = vtkPoints.New();
                vtkUnstructuredGrid grid     = vtkUnstructuredGrid.New();
                for (int i = 0; i < selected.GetNumberOfPoints(); i++)
                {
                    points.InsertNextPoint(selected.GetPoint(i)[0], selected.GetPoint(i)[1], selected.GetPoint(i)[2]);
                }
                grid.SetPoints(points);
                vtkSphereSource sphere = vtkSphereSource.New();
                sphere.SetPhiResolution(6);
                sphere.SetThetaResolution(6);
                sphere.SetRadius(0.1);
                vtkGlyph3D glyph3D = vtkGlyph3D.New();
                glyph3D.SetInput(grid);
                glyph3D.SetSourceConnection(sphere.GetOutputPort());

                vtkPolyDataMapper mapper = vtkPolyDataMapper.New();
                mapper.SetInputConnection(glyph3D.GetOutputPort());

                //double[] P = new double[3];
                //bool selected = false;
                //vtkPoints points = Faces.GetPoints();
                //double[] ClickedPoint = PointPicker.GetActor().GetMapper().GetInput().GetPoint(PointPicker.GetPointId());
                //for (int i = 0; i < points.GetNumberOfPoints(); i++)
                //{
                //    if (Math.Abs(points.GetPoint(i)[0] - ClickedPoint[0]) < 1e-6 &&
                //        Math.Abs(points.GetPoint(i)[1] - ClickedPoint[1]) < 1e-6 &&
                //        Math.Abs(points.GetPoint(i)[2] - ClickedPoint[2]) < 1e-6)
                //    {
                //        selected = true;
                //        P = points.GetPoint(i);
                //        break;
                //    }
                //}
                //
                //if (selected == true)
                //{
                //    SelectionPoints.InsertNextPoint(P[0], P[1], P[2]);
                //
                //    SelectionGlyph = vtkGlyph3D.New();
                //    SelectionGlyph.SetInput(SelectionPolyData);
                //    SelectionGlyph.SetSourceConnection(SelectionSphere.GetOutputPort());
                //    SelectionMapper.SetInputConnection(SelectionGlyph.GetOutputPort());
                //
                //    // Refresh Viewport
                //    Refresh();
                //}
            }
        }
예제 #17
0
        /// <summary>
        /// Generate a 3D mesh using marching-cubes algorithm. If voxel value is lower than 1 it is consider as background, else as object
        /// </summary>
        /// <param name="BinarySubImageSeq">The binary image</param>
        /// <param name="Colour">Mesh color</param>
        /// <param name="Pos">Postion of the object in the world</param>
        public cBiologicalSpot(Color Colour, cPoint3D Pos, double Intensity, double Radius)
        {
            this.Intensity = Intensity;
            VTK_Sphere = vtkSphereSource.New();
            VTK_Sphere.SetThetaResolution(6);
            VTK_Sphere.SetPhiResolution(6);
            VTK_Sphere.SetRadius(Radius);
            vtk_PolyDataMapper = vtkPolyDataMapper.New();
            vtk_PolyDataMapper.SetInputConnection(VTK_Sphere.GetOutputPort());

            this.SetPosition(new cPoint3D(Pos.X, Pos.Y, Pos.Z));
            this.Colour = Colour;

            CreateVTK3DObject(1);
            Information = new cInformation(this);
        }
예제 #18
0
        public void CreateViewport(Grid Window)
        {
            WindowsFormsHost VTK_Window = new WindowsFormsHost(); // Create Windows Forms Host for VTK Window

            RenWinControl = new RenderWindowControl();            // Initialize VTK Renderer Window Control

            // Clear input Window and add new host
            Window.Children.Clear();
            Window.Children.Add(VTK_Window);
            VTK_Window.Child = RenWinControl;

            // Create Render Window
            renderWindow = RenWinControl.RenderWindow;

            // Initialize Interactor
            Inter = vtkRenderWindowInteractor.New();
            Inter.LeftButtonPressEvt  += new vtkObject.vtkObjectEventHandler(SelectPointClick);
            Inter.RightButtonPressEvt += new vtkObject.vtkObjectEventHandler(UnselectPointClick);
            renderWindow.SetInteractor(Inter);
            Inter.Initialize();

            InterStyleTrack = vtkInteractorStyleTrackballCamera.New();
            //Inter.SetInteractorStyle(InterStyleTrack);
            InterStylePick = vtkInteractorStyleRubberBandPick.New();
            Inter.SetInteractorStyle(InterStylePick);

            // Initialize View
            Viewport = renderWindow.GetRenderers().GetFirstRenderer();
            Viewport.RemoveAllViewProps();
            CreateViewportBorder(Viewport, new double[3] {
                128.0, 128.0, 128.0
            });

            // Set default background color
            Viewport.GradientBackgroundOn();
            Viewport.SetBackground(163.0 / 255.0, 163.0 / 255.0, 163.0 / 255.0);
            Viewport.SetBackground2(45.0 / 255.0, 85.0 / 255.0, 125.0 / 255.0);

            // Other properties
            Viewport.GetActiveCamera().ParallelProjectionOn();

            // Initialize Selection objects
            AppendFaces       = vtkAppendPolyData.New();
            Faces             = vtkPolyData.New();
            SelectionMode     = false;
            SelectionSize     = 0.1;
            SelectionPoints   = vtkPoints.New();
            SelectionActor    = vtkActor.New();
            SelectionPolyData = vtkPolyData.New();
            SelectionPolyData.SetPoints(SelectionPoints);

            SelectionSphere = vtkSphereSource.New();
            SelectionSphere.SetPhiResolution(12);
            SelectionSphere.SetThetaResolution(12);
            SelectionSphere.SetRadius(SelectionSize);
            SelectionGlyph = vtkGlyph3D.New();
            SelectionGlyph.SetInput(SelectionPolyData);
            SelectionGlyph.SetSourceConnection(SelectionSphere.GetOutputPort());
            SelectionMapper = vtkPolyDataMapper.New();
            SelectionMapper.SetInputConnection(SelectionGlyph.GetOutputPort());

            SelectionActor.SetMapper(SelectionMapper);
            SelectionActor.GetProperty().SetColor(1, 1, 1);
            SelectionActor.VisibilityOn();
            Viewport.AddActor(SelectionActor);

            // Create new Properties and Objects
            CreateColorMap();
            CreateScalarBar();
            CreateAxes();
            CreateSlider();
            CreateClipPlane();
        }
예제 #19
0
        public cBiologicalSpot(Color Colour, cPoint3D Pos, double Intensity, double Radius, List<cInteractive3DObject> Containers, int ContainerMode)
        {
            this.Intensity = Intensity;

            this.Detected = true;

            this.Intensity = Intensity;
            VTK_Sphere = vtkSphereSource.New();
            VTK_Sphere.SetThetaResolution(10);
            VTK_Sphere.SetPhiResolution(10);
            VTK_Sphere.SetRadius(Radius);
            vtk_PolyDataMapper = vtkPolyDataMapper.New();
            vtk_PolyDataMapper.SetInputConnection(VTK_Sphere.GetOutputPort());

            this.SetPosition(new cPoint3D(Pos.X, Pos.Y, Pos.Z));
            this.Colour = Colour;

            CreateVTK3DObject(1);
            Information = new cInformation(this);

            this.Detected = true;

            /*
            vtkActor TmpActor = vtkActor.New();
            TmpActor.SetMapper(vtk_PolyDataMapper);
            TmpActor.SetPosition(Pos.X, Pos.Y, Pos.Z);

            //Console.WriteLine("PosX"+Pos.X+" PosY"+Pos.Y+" PosZ"+Pos.Z);
            cPoint3D Centroid = new cPoint3D((float)TmpActor.GetCenter()[0], (float)TmpActor.GetCenter()[1], (float)TmpActor.GetCenter()[2]);

            bool IsInside = false;
            for (int Idx = 0; Idx < Containers.Count; Idx++)
            {
                cBiological3DVolume CurrentContainer = (cBiological3DVolume)(Containers[Idx]);

                if (CurrentContainer.IsPointInside(Centroid))
                {
                    IsInside = true;
                    ContainerIdx = Idx;
                    break;
                }
            }
            if (IsInside)
            {
                this.Position = new cPoint3D(Pos.X, Pos.Y, Pos.Z);
                this.Colour = Colour;

                CreateVTK3DObject(1);

                vtk_PolyData = ContourObject.GetOutput();
                //  this.BackfaceCulling(false);

                Information = new cInformation(ContourObject, this);
                this.Detected = true;
            }
            else
            {
                this.Detected = false;
            }*/
        }
예제 #20
0
 public void SetResolution(int a, int b)
 {
     _sphereSource.SetPhiResolution(a);
     _sphereSource.SetThetaResolution(b);
 }
예제 #21
0
        private void PolygonalSurfaceContourLineInterpolator()
        {
            vtkPolyData     polyData;
            vtkSphereSource sphereSource = vtkSphereSource.New();

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

            polyData = sphereSource.GetOutput();
            // The Dijkstra interpolator will not accept cells that aren't triangles
            vtkTriangleFilter triangleFilter = vtkTriangleFilter.New();

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

            vtkPolyData pd = triangleFilter.GetOutput();

            //Create a mapper and actor
            vtkPolyDataMapper mapper = vtkPolyDataMapper.New();
            mapper.SetInputConnection(triangleFilter.GetOutputPort());

            vtkActor actor = vtkActor.New();
            actor.SetMapper(mapper);
            actor.GetProperty().SetInterpolationToFlat();

            // get a reference to the renderwindow of our renderWindowControl1
            vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow;
            // renderer
            vtkRenderer renderer = renderWindow.GetRenderers().GetFirstRenderer();
            // set background color
            renderer.SetBackground(0.3, 0.4, 0.5);
            // add our actor to the renderer
            renderer.AddActor(actor);

            // Here comes the contour widget stuff.....
            vtkContourWidget contourWidget = vtkContourWidget.New();
            contourWidget.SetInteractor(renderWindow.GetInteractor());
            vtkOrientedGlyphContourRepresentation rep =
                vtkOrientedGlyphContourRepresentation.SafeDownCast(
                    contourWidget.GetRepresentation());
            rep.GetLinesProperty().SetColor(1, 0.2, 0);
            rep.GetLinesProperty().SetLineWidth(3.0f);

            vtkPolygonalSurfacePointPlacer pointPlacer =
                vtkPolygonalSurfacePointPlacer.New();
            pointPlacer.AddProp(actor);
            pointPlacer.GetPolys().AddItem(pd);
            rep.SetPointPlacer(pointPlacer);

            vtkPolygonalSurfaceContourLineInterpolator interpolator =
                vtkPolygonalSurfaceContourLineInterpolator.New();
            interpolator.GetPolys().AddItem(pd);
            rep.SetLineInterpolator(interpolator);

            renderWindow.Render();
            contourWidget.EnabledOn();
        }
예제 #22
0
    /// <summary>
    /// The main entry method called by the CSharp driver
    /// </summary>
    /// <param name="argv"></param>
    public static void AVSelectionLoop(String [] argv)
    {
        //Prefix Content is: ""

        //[]
        // Demonstrate the use of implicit selection loop as well as closest point[]
        // connectivity[]
        //[]
        // create pipeline[]
        //[]
        sphere = new vtkSphereSource();
        sphere.SetRadius((double)1);
        sphere.SetPhiResolution((int)100);
        sphere.SetThetaResolution((int)100);
        selectionPoints = new vtkPoints();
        selectionPoints.InsertPoint((int)0, (double)0.07325, (double)0.8417, (double)0.5612);
        selectionPoints.InsertPoint((int)1, (double)0.07244, (double)0.6568, (double)0.7450);
        selectionPoints.InsertPoint((int)2, (double)0.1727, (double)0.4597, (double)0.8850);
        selectionPoints.InsertPoint((int)3, (double)0.3265, (double)0.6054, (double)0.7309);
        selectionPoints.InsertPoint((int)4, (double)0.5722, (double)0.5848, (double)0.5927);
        selectionPoints.InsertPoint((int)5, (double)0.4305, (double)0.8138, (double)0.4189);
        loop = new vtkImplicitSelectionLoop();
        loop.SetLoop((vtkPoints)selectionPoints);
        extract = new vtkExtractGeometry();
        extract.SetInputConnection((vtkAlgorithmOutput)sphere.GetOutputPort());
        extract.SetImplicitFunction((vtkImplicitFunction)loop);
        connect = new vtkConnectivityFilter();
        connect.SetInputConnection((vtkAlgorithmOutput)extract.GetOutputPort());
        connect.SetExtractionModeToClosestPointRegion();
        connect.SetClosestPoint((double)selectionPoints.GetPoint((int)0)[0], (double)selectionPoints.GetPoint((int)0)[1], (double)selectionPoints.GetPoint((int)0)[2]);
        clipMapper = new vtkDataSetMapper();
        clipMapper.SetInputConnection((vtkAlgorithmOutput)connect.GetOutputPort());
        backProp = new vtkProperty();
        backProp.SetDiffuseColor((double)1.0000, 0.3882, 0.2784);
        clipActor = new vtkActor();
        clipActor.SetMapper((vtkMapper)clipMapper);
        clipActor.GetProperty().SetColor((double)0.2000, 0.6300, 0.7900);
        clipActor.SetBackfaceProperty((vtkProperty)backProp);
        // Create graphics stuff[]
        //[]
        ren1   = vtkRenderer.New();
        renWin = vtkRenderWindow.New();
        renWin.AddRenderer((vtkRenderer)ren1);
        iren = new vtkRenderWindowInteractor();
        iren.SetRenderWindow((vtkRenderWindow)renWin);
        // Add the actors to the renderer, set the background and size[]
        //[]
        ren1.AddActor((vtkProp)clipActor);
        ren1.SetBackground((double)1, (double)1, (double)1);
        ren1.ResetCamera();
        ren1.GetActiveCamera().Azimuth((double)30);
        ren1.GetActiveCamera().Elevation((double)30);
        ren1.GetActiveCamera().Dolly((double)1.2);
        ren1.ResetCameraClippingRange();
        renWin.SetSize((int)400, (int)400);
        renWin.Render();
        // render the image[]
        //[]
        // prevent the tk window from showing up then start the event loop[]

//deleteAllVTKObjects();
    }
예제 #23
0
    /// <summary>
    /// The main entry method called by the CSharp driver
    /// </summary>
    /// <param name="argv"></param>
    public static void AVgaussian(String [] argv)
    {
        //Prefix Content is: ""

        ren1   = vtkRenderer.New();
        renWin = vtkRenderWindow.New();
        renWin.SetMultiSamples(0);
        renWin.AddRenderer((vtkRenderer)ren1);
        renWin.SetSize((int)300, (int)300);
        iren = new vtkRenderWindowInteractor();
        iren.SetRenderWindow((vtkRenderWindow)renWin);
        camera = new vtkCamera();
        camera.ParallelProjectionOn();
        camera.SetViewUp((double)0, (double)1, (double)0);
        camera.SetFocalPoint((double)12, (double)10.5, (double)15);
        camera.SetPosition((double)-70, (double)15, (double)34);
        camera.ComputeViewPlaneNormal();
        ren1.SetActiveCamera((vtkCamera)camera);
        // Create the reader for the data[]
        //vtkStructuredPointsReader reader[]
        reader = new vtkGaussianCubeReader();
        reader.SetFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/m4_TotalDensity.cube");
        reader.SetHBScale((double)1.1);
        reader.SetBScale((double)10);
        reader.Update();
        range    = reader.GetGridOutput().GetPointData().GetScalars().GetRange();
        min      = (double)(lindex(range, 0));
        max      = (double)(lindex(range, 1));
        readerSS = new vtkImageShiftScale();
        readerSS.SetInputData((vtkDataObject)reader.GetGridOutput());
        readerSS.SetShift((double)min * -1);
        readerSS.SetScale((double)255 / (max - min));
        readerSS.SetOutputScalarTypeToUnsignedChar();
        bounds = new vtkOutlineFilter();
        bounds.SetInputData((vtkDataObject)reader.GetGridOutput());
        boundsMapper = vtkPolyDataMapper.New();
        boundsMapper.SetInputConnection((vtkAlgorithmOutput)bounds.GetOutputPort());
        boundsActor = new vtkActor();
        boundsActor.SetMapper((vtkMapper)boundsMapper);
        boundsActor.GetProperty().SetColor((double)0, (double)0, (double)0);
        contour = new vtkContourFilter();
        contour.SetInputData((vtkDataObject)reader.GetGridOutput());
        contour.GenerateValues((int)5, (double)0, (double).05);
        contourMapper = vtkPolyDataMapper.New();
        contourMapper.SetInputConnection((vtkAlgorithmOutput)contour.GetOutputPort());
        contourMapper.SetScalarRange((double)0, (double).1);
        ((vtkLookupTable)contourMapper.GetLookupTable()).SetHueRange(0.32, 0);
        contourActor = new vtkActor();
        contourActor.SetMapper((vtkMapper)contourMapper);
        contourActor.GetProperty().SetOpacity((double).5);
        // Create transfer mapping scalar value to opacity[]
        opacityTransferFunction = new vtkPiecewiseFunction();
        opacityTransferFunction.AddPoint((double)0, (double)0.01);
        opacityTransferFunction.AddPoint((double)255, (double)0.35);
        opacityTransferFunction.ClampingOn();
        // Create transfer mapping scalar value to color[]
        colorTransferFunction = new vtkColorTransferFunction();
        colorTransferFunction.AddHSVPoint((double)0.0, (double)0.66, (double)1.0, (double)1.0);
        colorTransferFunction.AddHSVPoint((double)50.0, (double)0.33, (double)1.0, (double)1.0);
        colorTransferFunction.AddHSVPoint((double)100.0, (double)0.00, (double)1.0, (double)1.0);
        // The property describes how the data will look[]
        volumeProperty = new vtkVolumeProperty();
        volumeProperty.SetColor((vtkColorTransferFunction)colorTransferFunction);
        volumeProperty.SetScalarOpacity((vtkPiecewiseFunction)opacityTransferFunction);
        volumeProperty.SetInterpolationTypeToLinear();
        // The mapper / ray cast function know how to render the data[]
        compositeFunction = new vtkVolumeRayCastCompositeFunction();
        volumeMapper      = new vtkVolumeRayCastMapper();
        //vtkVolumeTextureMapper2D volumeMapper[]
        volumeMapper.SetVolumeRayCastFunction((vtkVolumeRayCastFunction)compositeFunction);
        volumeMapper.SetInputConnection((vtkAlgorithmOutput)readerSS.GetOutputPort());
        // The volume holds the mapper and the property and[]
        // can be used to position/orient the volume[]
        volume = new vtkVolume();
        volume.SetMapper((vtkAbstractVolumeMapper)volumeMapper);
        volume.SetProperty((vtkVolumeProperty)volumeProperty);
        ren1.AddVolume((vtkProp)volume);
        //ren1 AddActor contourActor[]
        ren1.AddActor((vtkProp)boundsActor);
        //#####################################################################[]
        Sphere = new vtkSphereSource();
        Sphere.SetCenter((double)0, (double)0, (double)0);
        Sphere.SetRadius((double)1);
        Sphere.SetThetaResolution((int)16);
        Sphere.SetStartTheta((double)0);
        Sphere.SetEndTheta((double)360);
        Sphere.SetPhiResolution((int)16);
        Sphere.SetStartPhi((double)0);
        Sphere.SetEndPhi((double)180);
        Glyph = new vtkGlyph3D();
        Glyph.SetInputConnection((vtkAlgorithmOutput)reader.GetOutputPort());
        Glyph.SetOrient((int)1);
        Glyph.SetColorMode((int)1);
        //Glyph ScalingOn[]
        Glyph.SetScaleMode((int)2);
        Glyph.SetScaleFactor((double).6);
        Glyph.SetSourceConnection(Sphere.GetOutputPort());
        AtomsMapper = vtkPolyDataMapper.New();
        AtomsMapper.SetInputConnection((vtkAlgorithmOutput)Glyph.GetOutputPort());
        AtomsMapper.SetImmediateModeRendering((int)1);
        AtomsMapper.UseLookupTableScalarRangeOff();
        AtomsMapper.SetScalarVisibility((int)1);
        AtomsMapper.SetScalarModeToDefault();
        Atoms = new vtkActor();
        Atoms.SetMapper((vtkMapper)AtomsMapper);
        Atoms.GetProperty().SetRepresentationToSurface();
        Atoms.GetProperty().SetInterpolationToGouraud();
        Atoms.GetProperty().SetAmbient((double)0.15);
        Atoms.GetProperty().SetDiffuse((double)0.85);
        Atoms.GetProperty().SetSpecular((double)0.1);
        Atoms.GetProperty().SetSpecularPower((double)100);
        Atoms.GetProperty().SetSpecularColor((double)1, (double)1, (double)1);
        Atoms.GetProperty().SetColor((double)1, (double)1, (double)1);
        Tube = new vtkTubeFilter();
        Tube.SetInputConnection((vtkAlgorithmOutput)reader.GetOutputPort());
        Tube.SetNumberOfSides((int)16);
        Tube.SetCapping((int)0);
        Tube.SetRadius((double)0.2);
        Tube.SetVaryRadius((int)0);
        Tube.SetRadiusFactor((double)10);
        BondsMapper = vtkPolyDataMapper.New();
        BondsMapper.SetInputConnection((vtkAlgorithmOutput)Tube.GetOutputPort());
        BondsMapper.SetImmediateModeRendering((int)1);
        BondsMapper.UseLookupTableScalarRangeOff();
        BondsMapper.SetScalarVisibility((int)1);
        BondsMapper.SetScalarModeToDefault();
        Bonds = new vtkActor();
        Bonds.SetMapper((vtkMapper)BondsMapper);
        Bonds.GetProperty().SetRepresentationToSurface();
        Bonds.GetProperty().SetInterpolationToGouraud();
        Bonds.GetProperty().SetAmbient((double)0.15);
        Bonds.GetProperty().SetDiffuse((double)0.85);
        Bonds.GetProperty().SetSpecular((double)0.1);
        Bonds.GetProperty().SetSpecularPower((double)100);
        Bonds.GetProperty().SetSpecularColor((double)1, (double)1, (double)1);
        Bonds.GetProperty().SetColor((double)1, (double)1, (double)1);
        ren1.AddActor((vtkProp)Bonds);
        ren1.AddActor((vtkProp)Atoms);
        //###################################################[]
        ren1.SetBackground((double)1, (double)1, (double)1);
        ren1.ResetCamera();
        renWin.Render();
        //method moved

        renWin.AbortCheckEvt += new Kitware.VTK.vtkObject.vtkObjectEventHandler(TkCheckAbort_Command.Execute);
        iren.Initialize();

//deleteAllVTKObjects();
    }
예제 #24
0
    /// <summary>
    /// The main entry method called by the CSharp driver
    /// </summary>
    /// <param name="argv"></param>
    public static void AVTestPolyDataPieces(String [] argv)
    {
        //Prefix Content is: ""

          math = new vtkMath();
          vtkMath.RandomSeed((int)22);
          pf = new vtkParallelFactory();
          vtkParallelFactory.RegisterFactory((vtkObjectFactory)pf);
          sphere = new vtkSphereSource();
          sphere.SetPhiResolution((int)32);
          sphere.SetThetaResolution((int)32);
          extract = new vtkExtractPolyDataPiece();
          extract.SetInputConnection((vtkAlgorithmOutput)sphere.GetOutputPort());
          normals = new vtkPolyDataNormals();
          normals.SetInputConnection((vtkAlgorithmOutput)extract.GetOutputPort());
          ps = new vtkPieceScalars();
          ps.SetInputConnection((vtkAlgorithmOutput)normals.GetOutputPort());
          mapper = vtkPolyDataMapper.New();
          mapper.SetInputConnection((vtkAlgorithmOutput)ps.GetOutputPort());
          mapper.SetNumberOfPieces((int)2);
          actor = new vtkActor();
          actor.SetMapper((vtkMapper)mapper);
          sphere2 = new vtkSphereSource();
          sphere2.SetPhiResolution((int)32);
          sphere2.SetThetaResolution((int)32);
          extract2 = new vtkExtractPolyDataPiece();
          extract2.SetInputConnection((vtkAlgorithmOutput)sphere2.GetOutputPort());
          mapper2 = vtkPolyDataMapper.New();
          mapper2.SetInputConnection((vtkAlgorithmOutput)extract2.GetOutputPort());
          mapper2.SetNumberOfPieces((int)2);
          mapper2.SetPiece((int)1);
          mapper2.SetScalarRange((double)0,(double)4);
          mapper2.SetScalarModeToUseCellFieldData();
          mapper2.SetColorModeToMapScalars();
          mapper2.ColorByArrayComponent((string)"vtkGhostLevels",(int)0);
          mapper2.SetGhostLevel((int)4);
          // check the pipeline size[]
          extract2.UpdateInformation();
          psize = new vtkPipelineSize();
          if ((psize.GetEstimatedSize((vtkAlgorithm)extract2,(int)0,(int)0)) > 100)
        {
          //puts skipedputs ['stderr', '"ERROR: Pipeline Size increased"']
        }

          if ((psize.GetNumberOfSubPieces((uint)10,(vtkPolyDataMapper)mapper2)) != 2)
        {
          //puts skipedputs ['stderr', '"ERROR: Number of sub pieces changed"']
        }

          actor2 = new vtkActor();
          actor2.SetMapper((vtkMapper)mapper2);
          actor2.SetPosition((double)1.5,(double)0,(double)0);
          sphere3 = new vtkSphereSource();
          sphere3.SetPhiResolution((int)32);
          sphere3.SetThetaResolution((int)32);
          extract3 = new vtkExtractPolyDataPiece();
          extract3.SetInputConnection((vtkAlgorithmOutput)sphere3.GetOutputPort());
          ps3 = new vtkPieceScalars();
          ps3.SetInputConnection((vtkAlgorithmOutput)extract3.GetOutputPort());
          mapper3 = vtkPolyDataMapper.New();
          mapper3.SetInputConnection((vtkAlgorithmOutput)ps3.GetOutputPort());
          mapper3.SetNumberOfSubPieces((int)8);
          mapper3.SetScalarRange((double)0,(double)8);
          actor3 = new vtkActor();
          actor3.SetMapper((vtkMapper)mapper3);
          actor3.SetPosition((double)0,(double)-1.5,(double)0);
          sphere4 = new vtkSphereSource();
          sphere4.SetPhiResolution((int)32);
          sphere4.SetThetaResolution((int)32);
          extract4 = new vtkExtractPolyDataPiece();
          extract4.SetInputConnection((vtkAlgorithmOutput)sphere4.GetOutputPort());
          ps4 = new vtkPieceScalars();
          ps4.RandomModeOn();
          ps4.SetScalarModeToCellData();
          ps4.SetInputConnection((vtkAlgorithmOutput)extract4.GetOutputPort());
          mapper4 = vtkPolyDataMapper.New();
          mapper4.SetInputConnection((vtkAlgorithmOutput)ps4.GetOutputPort());
          mapper4.SetNumberOfSubPieces((int)8);
          mapper4.SetScalarRange((double)0,(double)8);
          actor4 = new vtkActor();
          actor4.SetMapper((vtkMapper)mapper4);
          actor4.SetPosition((double)1.5,(double)-1.5,(double)0);
          ren = vtkRenderer.New();
          ren.AddActor((vtkProp)actor);
          ren.AddActor((vtkProp)actor2);
          ren.AddActor((vtkProp)actor3);
          ren.AddActor((vtkProp)actor4);
          renWin = vtkRenderWindow.New();
          renWin.AddRenderer((vtkRenderer)ren);
          iren = new vtkRenderWindowInteractor();
          iren.SetRenderWindow((vtkRenderWindow)renWin);
          iren.Initialize();

        //deleteAllVTKObjects();
    }
예제 #25
0
        private void WeightedTransformFilter()
        {
            // Use a sphere as a basis of the shape
            vtkSphereSource sphere = vtkSphereSource.New();

            sphere.SetPhiResolution(40);
            sphere.SetThetaResolution(40);
            sphere.Update();

            vtkPolyData sphereData = sphere.GetOutput();

            // Create a data array to hold the weighting coefficients
            vtkFloatArray tfarray = vtkFloatArray.New();
            int           npoints = sphereData.GetNumberOfPoints();

            tfarray.SetNumberOfComponents(2);
            tfarray.SetNumberOfTuples(npoints);

            // Parameterize the sphere along the z axis, and fill the weights
            // with (1.0-a, a) to linearly interpolate across the shape
            IntPtr pPoint = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(double)) * 3);

            double[] point = new double[3];
            for (int i = 0; i < npoints; i++)
            {
                sphereData.GetPoint(i, pPoint);
                Marshal.Copy(pPoint, point, 0, 3);
                double x = point[0];
                double y = point[1];
                double z = point[2];

                double zn  = z + 0.5;
                double zn1 = 1.0 - zn;
                if (zn > 1.0)
                {
                    zn = 1.0;
                }
                if (zn1 < 0.0)
                {
                    zn1 = 0.0;
                }

                tfarray.SetComponent(i, 0, zn1);
                tfarray.SetComponent(i, 1, zn);
            }
            Marshal.FreeHGlobal(pPoint);

            // Create field data to hold the array, and bind it to the sphere
            vtkFieldData fd = vtkFieldData.New();

            tfarray.SetName("weights");
            sphereData.GetPointData().AddArray(tfarray);

            // Use an ordinary transform to stretch the shape
            vtkTransform stretch = vtkTransform.New();

            stretch.Scale(1, 1, 3.2);

            vtkTransformFilter stretchFilter = vtkTransformFilter.New();

            stretchFilter.SetInputConnection(sphereData.GetProducerPort());
            stretchFilter.SetTransform(stretch);

            // Now, for the weighted transform stuff
            vtkWeightedTransformFilter weightedTrans = vtkWeightedTransformFilter.New();

            // Create two transforms to interpolate between
            vtkTransform identity = vtkTransform.New();

            identity.Identity();

            vtkTransform rotated      = vtkTransform.New();
            double       rotatedAngle = 45;

            rotated.RotateX(rotatedAngle);

            weightedTrans.SetNumberOfTransforms(2);
            weightedTrans.SetTransform(identity, 0);
            weightedTrans.SetTransform(rotated, 1);
            // which data array should the filter use ?
            weightedTrans.SetWeightArray("weights");

            weightedTrans.SetInputConnection(stretchFilter.GetOutputPort());

            vtkPolyDataMapper weightedTransMapper = vtkPolyDataMapper.New();

            weightedTransMapper.SetInputConnection(weightedTrans.GetOutputPort());
            vtkActor weightedTransActor = vtkActor.New();

            weightedTransActor.SetMapper(weightedTransMapper);
            weightedTransActor.GetProperty().SetDiffuseColor(0.8, 0.8, 0.1);
            weightedTransActor.GetProperty().SetRepresentationToSurface();

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

            // set background color
            renderer.SetBackground(0.2, 0.3, 0.4);
            // add our actor to the renderer
            renderer.AddActor(weightedTransActor);

            renderer.ResetCamera();
            renderer.GetActiveCamera().Azimuth(90);
            renderer.GetActiveCamera().Dolly(1);
        }
예제 #26
0
    /// <summary>
    /// The main entry method called by the CSharp driver
    /// </summary>
    /// <param name="argv"></param>
    public static void AVTenEllip(String [] argv)
    {
        //Prefix Content is: ""

        // create tensor ellipsoids[]
        // Create the RenderWindow, Renderer and interactive renderer[]
        //[]
        ren1   = vtkRenderer.New();
        renWin = vtkRenderWindow.New();
        renWin.SetMultiSamples(0);
        renWin.AddRenderer((vtkRenderer)ren1);
        iren = new vtkRenderWindowInteractor();
        iren.SetRenderWindow((vtkRenderWindow)renWin);
        //[]
        // Create tensor ellipsoids[]
        //[]
        // generate tensors[]
        ptLoad = new vtkPointLoad();
        ptLoad.SetLoadValue((double)100.0);
        ptLoad.SetSampleDimensions((int)6, (int)6, (int)6);
        ptLoad.ComputeEffectiveStressOn();
        ptLoad.SetModelBounds((double)-10, (double)10, (double)-10, (double)10, (double)-10, (double)10);
        // extract plane of data[]
        plane = new vtkImageDataGeometryFilter();
        plane.SetInputConnection((vtkAlgorithmOutput)ptLoad.GetOutputPort());
        plane.SetExtent((int)2, (int)2, (int)0, (int)99, (int)0, (int)99);
        // Generate ellipsoids[]
        sphere = new vtkSphereSource();
        sphere.SetThetaResolution((int)8);
        sphere.SetPhiResolution((int)8);
        ellipsoids = new vtkTensorGlyph();
        ellipsoids.SetInputConnection((vtkAlgorithmOutput)ptLoad.GetOutputPort());
        ellipsoids.SetSourceConnection((vtkAlgorithmOutput)sphere.GetOutputPort());
        ellipsoids.SetScaleFactor((double)10);
        ellipsoids.ClampScalingOn();
        ellipNormals = new vtkPolyDataNormals();
        ellipNormals.SetInputConnection((vtkAlgorithmOutput)ellipsoids.GetOutputPort());
        // Map contour[]
        lut = new vtkLogLookupTable();
        lut.SetHueRange((double).6667, (double)0.0);
        ellipMapper = vtkPolyDataMapper.New();
        ellipMapper.SetInputConnection((vtkAlgorithmOutput)ellipNormals.GetOutputPort());
        ellipMapper.SetLookupTable((vtkScalarsToColors)lut);
        plane.Update();
        //force update for scalar range[]
        ellipMapper.SetScalarRange((double)((vtkDataSet)plane.GetOutput()).GetScalarRange()[0], (double)((vtkDataSet)plane.GetOutput()).GetScalarRange()[1]);
        ellipActor = new vtkActor();
        ellipActor.SetMapper((vtkMapper)ellipMapper);
        //[]
        // Create outline around data[]
        //[]
        outline = new vtkOutlineFilter();
        outline.SetInputConnection((vtkAlgorithmOutput)ptLoad.GetOutputPort());
        outlineMapper = vtkPolyDataMapper.New();
        outlineMapper.SetInputConnection((vtkAlgorithmOutput)outline.GetOutputPort());
        outlineActor = new vtkActor();
        outlineActor.SetMapper((vtkMapper)outlineMapper);
        outlineActor.GetProperty().SetColor((double)0, (double)0, (double)0);
        //[]
        // Create cone indicating application of load[]
        //[]
        coneSrc = new vtkConeSource();
        coneSrc.SetRadius((double).5);
        coneSrc.SetHeight((double)2);
        coneMap = vtkPolyDataMapper.New();
        coneMap.SetInputConnection((vtkAlgorithmOutput)coneSrc.GetOutputPort());
        coneActor = new vtkActor();
        coneActor.SetMapper((vtkMapper)coneMap);
        coneActor.SetPosition((double)0, (double)0, (double)11);
        coneActor.RotateY((double)90);
        coneActor.GetProperty().SetColor((double)1, (double)0, (double)0);
        camera = new vtkCamera();
        camera.SetFocalPoint((double)0.113766, (double)-1.13665, (double)-1.01919);
        camera.SetPosition((double)-29.4886, (double)-63.1488, (double)26.5807);
        camera.SetViewAngle((double)24.4617);
        camera.SetViewUp((double)0.17138, (double)0.331163, (double)0.927879);
        camera.SetClippingRange((double)1, (double)100);
        ren1.AddActor((vtkProp)ellipActor);
        ren1.AddActor((vtkProp)outlineActor);
        ren1.AddActor((vtkProp)coneActor);
        ren1.SetBackground((double)1.0, (double)1.0, (double)1.0);
        ren1.SetActiveCamera((vtkCamera)camera);
        renWin.SetSize((int)400, (int)400);
        renWin.Render();
        // prevent the tk window from showing up then start the event loop[]

//deleteAllVTKObjects();
    }
예제 #27
0
    /// <summary>
    /// The main entry method called by the CSharp driver
    /// </summary>
    /// <param name="argv"></param>
    public static void AVStreamPolyData(String [] argv)
    {
        //Prefix Content is: ""

          NUMBER_OF_PIECES = 5;
          // Generate implicit model of a sphere[]
          //[]
          // Create renderer stuff[]
          //[]
          ren1 = vtkRenderer.New();
          renWin = vtkRenderWindow.New();
          renWin.AddRenderer((vtkRenderer)ren1);
          iren = new vtkRenderWindowInteractor();
          iren.SetRenderWindow((vtkRenderWindow)renWin);
          // create pipeline that handles ghost cells[]
          sphere = new vtkSphereSource();
          sphere.SetRadius((double)3);
          sphere.SetPhiResolution((int)100);
          sphere.SetThetaResolution((int)150);
          // sphere AddObserver StartEvent {tk_messageBox -message "Executing with piece [[sphere GetOutput] GetUpdatePiece]"}[]
          // Just playing with an alternative that is not currently used.[]
          //method moved
          // Just playing with an alternative that is not currently used.[]
          deci = new vtkDecimatePro();
          deci.SetInputConnection((vtkAlgorithmOutput)sphere.GetOutputPort());
          // this did not remove seams as I thought it would[]
          deci.BoundaryVertexDeletionOff();
          //deci PreserveTopologyOn[]
          // Since quadric Clustering does not handle borders properly yet,[]
          // the pieces will have dramatic "eams"[]
          q = new vtkQuadricClustering();
          q.SetInputConnection((vtkAlgorithmOutput)sphere.GetOutputPort());
          q.SetNumberOfXDivisions((int)5);
          q.SetNumberOfYDivisions((int)5);
          q.SetNumberOfZDivisions((int)10);
          q.UseInputPointsOn();
          streamer = new vtkPolyDataStreamer();
          //streamer SetInputConnection [deci GetOutputPort][]
          streamer.SetInputConnection((vtkAlgorithmOutput)q.GetOutputPort());
          //streamer SetInputConnection [pdn GetOutputPort][]
          streamer.SetNumberOfStreamDivisions((int)NUMBER_OF_PIECES);
          mapper = vtkPolyDataMapper.New();
          mapper.SetInputConnection((vtkAlgorithmOutput)streamer.GetOutputPort());
          mapper.ScalarVisibilityOff();
          mapper.SetPiece((int)0);
          mapper.SetNumberOfPieces((int)2);
          mapper.ImmediateModeRenderingOn();
          actor = new vtkActor();
          actor.SetMapper((vtkMapper)mapper);
          actor.GetProperty().SetColor((double) 0.8300, 0.2400, 0.1000 );
          // Add the actors to the renderer, set the background and size[]
          //[]
          ren1.GetActiveCamera().SetPosition((double)5,(double)5,(double)10);
          ren1.GetActiveCamera().SetFocalPoint((double)0,(double)0,(double)0);
          ren1.AddActor((vtkProp)actor);
          ren1.SetBackground((double)1,(double)1,(double)1);
          renWin.SetSize((int)300,(int)300);
          iren.Initialize();
          // render the image[]
          //[]
          // prevent the tk window from showing up then start the event loop[]

        //deleteAllVTKObjects();
    }
예제 #28
0
        private void CreateSphere(cPoint3D Center, double Radius, Color Colour, int Precision)
        {
            Position = new cPoint3D(Center.X, Center.Y, Center.Z);

            this.Radius = Radius;
            this.Colour = Colour;

            sphere = vtkSphereSource.New();
            sphere.SetThetaResolution(Precision);
            sphere.SetPhiResolution(Precision);
            sphere.SetRadius(Radius);
            vtk_PolyDataMapper = vtkPolyDataMapper.New();
            vtk_PolyDataMapper.SetInputConnection(sphere.GetOutputPort());

            CreateVTK3DObject(2);
        }
예제 #29
0
    /// <summary>
    /// The main entry method called by the CSharp driver
    /// </summary>
    /// <param name="argv"></param>
    public static void AVclosedSplines(String [] argv)
    {
        //Prefix Content is: ""

          // get the interactor ui[]
          // Now create the RenderWindow, Renderer and Interactor[]
          //[]
          ren1 = vtkRenderer.New();
          renWin = vtkRenderWindow.New();
          renWin.AddRenderer((vtkRenderer)ren1);
          iren = new vtkRenderWindowInteractor();
          iren.SetRenderWindow((vtkRenderWindow)renWin);
          math = new vtkMath();
          numberOfInputPoints = 30;
          aKSplineX = new vtkKochanekSpline();
          aKSplineX.ClosedOn();
          aKSplineY = new vtkKochanekSpline();
          aKSplineY.ClosedOn();
          aKSplineZ = new vtkKochanekSpline();
          aKSplineZ.ClosedOn();
          aCSplineX = new vtkCardinalSpline();
          aCSplineX.ClosedOn();
          aCSplineY = new vtkCardinalSpline();
          aCSplineY.ClosedOn();
          aCSplineZ = new vtkCardinalSpline();
          aCSplineZ.ClosedOn();
          // add some points[]
          inputPoints = new vtkPoints();
          x = -1.0;
          y = -1.0;
          z = 0.0;
          aKSplineX.AddPoint((double)0,(double)x);
          aKSplineY.AddPoint((double)0,(double)y);
          aKSplineZ.AddPoint((double)0,(double)z);
          aCSplineX.AddPoint((double)0,(double)x);
          aCSplineY.AddPoint((double)0,(double)y);
          aCSplineZ.AddPoint((double)0,(double)z);
          inputPoints.InsertPoint((int)0,(double)x,(double)y,(double)z);
          x = 1.0;
          y = -1.0;
          z = 0.0;
          aKSplineX.AddPoint((double)1,(double)x);
          aKSplineY.AddPoint((double)1,(double)y);
          aKSplineZ.AddPoint((double)1,(double)z);
          aCSplineX.AddPoint((double)1,(double)x);
          aCSplineY.AddPoint((double)1,(double)y);
          aCSplineZ.AddPoint((double)1,(double)z);
          inputPoints.InsertPoint((int)1,(double)x,(double)y,(double)z);
          x = 1.0;
          y = 1.0;
          z = 0.0;
          aKSplineX.AddPoint((double)2,(double)x);
          aKSplineY.AddPoint((double)2,(double)y);
          aKSplineZ.AddPoint((double)2,(double)z);
          aCSplineX.AddPoint((double)2,(double)x);
          aCSplineY.AddPoint((double)2,(double)y);
          aCSplineZ.AddPoint((double)2,(double)z);
          inputPoints.InsertPoint((int)2,(double)x,(double)y,(double)z);
          x = -1.0;
          y = 1.0;
          z = 0.0;
          aKSplineX.AddPoint((double)3,(double)x);
          aKSplineY.AddPoint((double)3,(double)y);
          aKSplineZ.AddPoint((double)3,(double)z);
          aCSplineX.AddPoint((double)3,(double)x);
          aCSplineY.AddPoint((double)3,(double)y);
          aCSplineZ.AddPoint((double)3,(double)z);
          inputPoints.InsertPoint((int)3,(double)x,(double)y,(double)z);
          inputData = new vtkPolyData();
          inputData.SetPoints((vtkPoints)inputPoints);
          balls = new vtkSphereSource();
          balls.SetRadius((double).04);
          balls.SetPhiResolution((int)10);
          balls.SetThetaResolution((int)10);
          glyphPoints = new vtkGlyph3D();
          glyphPoints.SetInput((vtkDataObject)inputData);
          glyphPoints.SetSource((vtkPolyData)balls.GetOutput());
          glyphMapper = vtkPolyDataMapper.New();
          glyphMapper.SetInputConnection((vtkAlgorithmOutput)glyphPoints.GetOutputPort());
          glyph = new vtkActor();
          glyph.SetMapper((vtkMapper)glyphMapper);
          glyph.GetProperty().SetDiffuseColor((double) 1.0000, 0.3882, 0.2784 );
          glyph.GetProperty().SetSpecular((double).3);
          glyph.GetProperty().SetSpecularPower((double)30);
          ren1.AddActor((vtkProp)glyph);
          Kpoints = new vtkPoints();
          Cpoints = new vtkPoints();
          profileKData = new vtkPolyData();
          profileCData = new vtkPolyData();
          numberOfInputPoints = 5;
          numberOfOutputPoints = 100;
          offset = 1.0;
          //method moved
          fit();
          lines = new vtkCellArray();
          lines.InsertNextCell((int)numberOfOutputPoints);
          i = 0;
          while((i) < numberOfOutputPoints)
        {
          lines.InsertCellPoint((int)i);
          i = i + 1;
        }

          profileKData.SetPoints((vtkPoints)Kpoints);
          profileKData.SetLines((vtkCellArray)lines);
          profileCData.SetPoints((vtkPoints)Cpoints);
          profileCData.SetLines((vtkCellArray)lines);
          profileKTubes = new vtkTubeFilter();
          profileKTubes.SetNumberOfSides((int)8);
          profileKTubes.SetInput((vtkDataObject)profileKData);
          profileKTubes.SetRadius((double).01);
          profileKMapper = vtkPolyDataMapper.New();
          profileKMapper.SetInputConnection((vtkAlgorithmOutput)profileKTubes.GetOutputPort());
          profileK = new vtkActor();
          profileK.SetMapper((vtkMapper)profileKMapper);
          profileK.GetProperty().SetDiffuseColor((double) 0.8900, 0.8100, 0.3400 );
          profileK.GetProperty().SetSpecular((double).3);
          profileK.GetProperty().SetSpecularPower((double)30);
          ren1.AddActor((vtkProp)profileK);
          profileCTubes = new vtkTubeFilter();
          profileCTubes.SetNumberOfSides((int)8);
          profileCTubes.SetInput((vtkDataObject)profileCData);
          profileCTubes.SetRadius((double).01);
          profileCMapper = vtkPolyDataMapper.New();
          profileCMapper.SetInputConnection((vtkAlgorithmOutput)profileCTubes.GetOutputPort());
          profileC = new vtkActor();
          profileC.SetMapper((vtkMapper)profileCMapper);
          profileC.GetProperty().SetDiffuseColor((double) 0.2000, 0.6300, 0.7900 );
          profileC.GetProperty().SetSpecular((double).3);
          profileC.GetProperty().SetSpecularPower((double)30);
          ren1.AddActor((vtkProp)profileC);
          ren1.ResetCamera();
          ren1.GetActiveCamera().Dolly((double)1.5);
          ren1.ResetCameraClippingRange();
          renWin.SetSize((int)300,(int)300);
          // render the image[]
          //[]
          iren.Initialize();
          // prevent the tk window from showing up then start the event loop[]
          //method moved
          //method moved
          //method moved
          //method moved
          //method moved
          //method moved

        //deleteAllVTKObjects();
    }
예제 #30
0
        private void ReadPDB()
        {
            // Path to vtk data must be set as an environment variable
            // VTK_DATA_ROOT = "C:\VTK\vtkdata-5.8.0"
            vtkTesting test     = vtkTesting.New();
            string     root     = test.GetDataRoot();
            string     filePath = System.IO.Path.Combine(root, @"Data\caffeine.pdb");

            vtkPDBReader pdb = vtkPDBReader.New();

            pdb.SetFileName(filePath);
            pdb.SetHBScale(1.0);
            pdb.SetBScale(1.0);
            pdb.Update();
            Debug.WriteLine("# of atoms is: " + pdb.GetNumberOfAtoms());
            // if molecule contains a lot of atoms, reduce the resolution of the sphere (represents an atom) for faster rendering
            int resolution = (int)Math.Floor(Math.Sqrt(300000.0 / pdb.GetNumberOfAtoms())); // 300000.0 is an empriric value

            if (resolution > 20)
            {
                resolution = 20;
            }
            else if (resolution < 4)
            {
                resolution = 4;
            }

            Debug.WriteLine("Resolution is: " + resolution);
            vtkSphereSource sphere = vtkSphereSource.New();

            sphere.SetCenter(0, 0, 0);
            sphere.SetRadius(1);
            sphere.SetThetaResolution(resolution);
            sphere.SetPhiResolution(resolution);

            vtkGlyph3D glyph = vtkGlyph3D.New();

            glyph.SetInputConnection(pdb.GetOutputPort());
            glyph.SetOrient(1);
            glyph.SetColorMode(1);
            // glyph.ScalingOn();
            glyph.SetScaleMode(2);
            glyph.SetScaleFactor(.25);
            glyph.SetSourceConnection(sphere.GetOutputPort());

            vtkPolyDataMapper atomMapper = vtkPolyDataMapper.New();

            atomMapper.SetInputConnection(glyph.GetOutputPort());
            atomMapper.UseLookupTableScalarRangeOff();
            atomMapper.ScalarVisibilityOn();
            atomMapper.SetScalarModeToDefault();

            vtkLODActor atom = vtkLODActor.New();

            atom.SetMapper(atomMapper);
            atom.GetProperty().SetRepresentationToSurface();
            atom.GetProperty().SetInterpolationToGouraud();
            atom.GetProperty().SetAmbient(0.15);
            atom.GetProperty().SetDiffuse(0.85);
            atom.GetProperty().SetSpecular(0.1);
            atom.GetProperty().SetSpecularPower(30);
            atom.GetProperty().SetSpecularColor(1, 1, 1);
            atom.SetNumberOfCloudPoints(30000);


            vtkTubeFilter tube = vtkTubeFilter.New();

            tube.SetInputConnection(pdb.GetOutputPort());
            tube.SetNumberOfSides(resolution);
            tube.CappingOff();
            tube.SetRadius(0.2);
            // turn off variation of tube radius with scalar values
            tube.SetVaryRadius(0);
            tube.SetRadiusFactor(10);

            vtkPolyDataMapper bondMapper = vtkPolyDataMapper.New();

            bondMapper.SetInputConnection(tube.GetOutputPort());
            bondMapper.UseLookupTableScalarRangeOff();
            bondMapper.ScalarVisibilityOff();
            bondMapper.SetScalarModeToDefault();

            vtkLODActor bond = vtkLODActor.New();

            bond.SetMapper(bondMapper);
            bond.GetProperty().SetRepresentationToSurface();
            bond.GetProperty().SetInterpolationToGouraud();
            bond.GetProperty().SetAmbient(0.15);
            bond.GetProperty().SetDiffuse(0.85);
            bond.GetProperty().SetSpecular(0.1);
            bond.GetProperty().SetSpecularPower(30);
            bond.GetProperty().SetSpecularColor(1, 1, 1);
            bond.GetProperty().SetDiffuseColor(1.0000, 0.8941, 0.70981);


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

            // set background color
            renderer.SetBackground(0.2, 0.3, 0.4);
            // add our actor to the renderer
            renderer.AddActor(atom);
            renderer.AddActor(bond);
        }
예제 #31
0
    /// <summary>
    /// The main entry method called by the CSharp driver
    /// </summary>
    /// <param name="argv"></param>
    public static void AVgaussian(String [] argv)
    {
        //Prefix Content is: ""

          ren1 = vtkRenderer.New();
          renWin = vtkRenderWindow.New();
          renWin.AddRenderer((vtkRenderer)ren1);
          renWin.SetSize((int)300,(int)300);
          iren = new vtkRenderWindowInteractor();
          iren.SetRenderWindow((vtkRenderWindow)renWin);
          camera = new vtkCamera();
          camera.ParallelProjectionOn();
          camera.SetViewUp((double)0,(double)1,(double)0);
          camera.SetFocalPoint((double)12,(double)10.5,(double)15);
          camera.SetPosition((double)-70,(double)15,(double)34);
          camera.ComputeViewPlaneNormal();
          ren1.SetActiveCamera((vtkCamera)camera);
          // Create the reader for the data[]
          //vtkStructuredPointsReader reader[]
          reader = new vtkGaussianCubeReader();
          reader.SetFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/m4_TotalDensity.cube");
          reader.SetHBScale((double)1.1);
          reader.SetBScale((double)10);
          reader.Update();
          range = reader.GetGridOutput().GetPointData().GetScalars().GetRange();
          min = (double)(lindex(range,0));
          max = (double)(lindex(range,1));
          readerSS = new vtkImageShiftScale();
          readerSS.SetInput((vtkDataObject)reader.GetGridOutput());
          readerSS.SetShift((double)min*-1);
          readerSS.SetScale((double)255/(max-min));
          readerSS.SetOutputScalarTypeToUnsignedChar();
          bounds = new vtkOutlineFilter();
          bounds.SetInput((vtkDataObject)reader.GetGridOutput());
          boundsMapper = vtkPolyDataMapper.New();
          boundsMapper.SetInputConnection((vtkAlgorithmOutput)bounds.GetOutputPort());
          boundsActor = new vtkActor();
          boundsActor.SetMapper((vtkMapper)boundsMapper);
          boundsActor.GetProperty().SetColor((double)0,(double)0,(double)0);
          contour = new vtkContourFilter();
          contour.SetInput((vtkDataObject)reader.GetGridOutput());
          contour.GenerateValues((int)5,(double)0,(double).05);
          contourMapper = vtkPolyDataMapper.New();
          contourMapper.SetInputConnection((vtkAlgorithmOutput)contour.GetOutputPort());
          contourMapper.SetScalarRange((double)0,(double).1);
          ((vtkLookupTable)contourMapper.GetLookupTable()).SetHueRange(0.32,0);
          contourActor = new vtkActor();
          contourActor.SetMapper((vtkMapper)contourMapper);
          contourActor.GetProperty().SetOpacity((double).5);
          // Create transfer mapping scalar value to opacity[]
          opacityTransferFunction = new vtkPiecewiseFunction();
          opacityTransferFunction.AddPoint((double)0,(double)0.01);
          opacityTransferFunction.AddPoint((double)255,(double)0.35);
          opacityTransferFunction.ClampingOn();
          // Create transfer mapping scalar value to color[]
          colorTransferFunction = new vtkColorTransferFunction();
          colorTransferFunction.AddHSVPoint((double)0.0,(double)0.66,(double)1.0,(double)1.0);
          colorTransferFunction.AddHSVPoint((double)50.0,(double)0.33,(double)1.0,(double)1.0);
          colorTransferFunction.AddHSVPoint((double)100.0,(double)0.00,(double)1.0,(double)1.0);
          // The property describes how the data will look[]
          volumeProperty = new vtkVolumeProperty();
          volumeProperty.SetColor((vtkColorTransferFunction)colorTransferFunction);
          volumeProperty.SetScalarOpacity((vtkPiecewiseFunction)opacityTransferFunction);
          volumeProperty.SetInterpolationTypeToLinear();
          // The mapper / ray cast function know how to render the data[]
          compositeFunction = new vtkVolumeRayCastCompositeFunction();
          volumeMapper = new vtkVolumeRayCastMapper();
          //vtkVolumeTextureMapper2D volumeMapper[]
          volumeMapper.SetVolumeRayCastFunction((vtkVolumeRayCastFunction)compositeFunction);
          volumeMapper.SetInputConnection((vtkAlgorithmOutput)readerSS.GetOutputPort());
          // The volume holds the mapper and the property and[]
          // can be used to position/orient the volume[]
          volume = new vtkVolume();
          volume.SetMapper((vtkAbstractVolumeMapper)volumeMapper);
          volume.SetProperty((vtkVolumeProperty)volumeProperty);
          ren1.AddVolume((vtkProp)volume);
          //ren1 AddActor contourActor[]
          ren1.AddActor((vtkProp)boundsActor);
          //#####################################################################[]
          Sphere = new vtkSphereSource();
          Sphere.SetCenter((double)0,(double)0,(double)0);
          Sphere.SetRadius((double)1);
          Sphere.SetThetaResolution((int)16);
          Sphere.SetStartTheta((double)0);
          Sphere.SetEndTheta((double)360);
          Sphere.SetPhiResolution((int)16);
          Sphere.SetStartPhi((double)0);
          Sphere.SetEndPhi((double)180);
          Glyph = new vtkGlyph3D();
          Glyph.SetInputConnection((vtkAlgorithmOutput)reader.GetOutputPort());
          Glyph.SetOrient((int)1);
          Glyph.SetColorMode((int)1);
          //Glyph ScalingOn[]
          Glyph.SetScaleMode((int)2);
          Glyph.SetScaleFactor((double).6);
          Glyph.SetSource((vtkPolyData)Sphere.GetOutput());
          AtomsMapper = vtkPolyDataMapper.New();
          AtomsMapper.SetInputConnection((vtkAlgorithmOutput)Glyph.GetOutputPort());
          AtomsMapper.SetImmediateModeRendering((int)1);
          AtomsMapper.UseLookupTableScalarRangeOff();
          AtomsMapper.SetScalarVisibility((int)1);
          AtomsMapper.SetScalarModeToDefault();
          Atoms = new vtkActor();
          Atoms.SetMapper((vtkMapper)AtomsMapper);
          Atoms.GetProperty().SetRepresentationToSurface();
          Atoms.GetProperty().SetInterpolationToGouraud();
          Atoms.GetProperty().SetAmbient((double)0.15);
          Atoms.GetProperty().SetDiffuse((double)0.85);
          Atoms.GetProperty().SetSpecular((double)0.1);
          Atoms.GetProperty().SetSpecularPower((double)100);
          Atoms.GetProperty().SetSpecularColor((double)1,(double)1,(double)1);
          Atoms.GetProperty().SetColor((double)1,(double)1,(double)1);
          Tube = new vtkTubeFilter();
          Tube.SetInputConnection((vtkAlgorithmOutput)reader.GetOutputPort());
          Tube.SetNumberOfSides((int)16);
          Tube.SetCapping((int)0);
          Tube.SetRadius((double)0.2);
          Tube.SetVaryRadius((int)0);
          Tube.SetRadiusFactor((double)10);
          BondsMapper = vtkPolyDataMapper.New();
          BondsMapper.SetInputConnection((vtkAlgorithmOutput)Tube.GetOutputPort());
          BondsMapper.SetImmediateModeRendering((int)1);
          BondsMapper.UseLookupTableScalarRangeOff();
          BondsMapper.SetScalarVisibility((int)1);
          BondsMapper.SetScalarModeToDefault();
          Bonds = new vtkActor();
          Bonds.SetMapper((vtkMapper)BondsMapper);
          Bonds.GetProperty().SetRepresentationToSurface();
          Bonds.GetProperty().SetInterpolationToGouraud();
          Bonds.GetProperty().SetAmbient((double)0.15);
          Bonds.GetProperty().SetDiffuse((double)0.85);
          Bonds.GetProperty().SetSpecular((double)0.1);
          Bonds.GetProperty().SetSpecularPower((double)100);
          Bonds.GetProperty().SetSpecularColor((double)1,(double)1,(double)1);
          Bonds.GetProperty().SetColor((double)1,(double)1,(double)1);
          ren1.AddActor((vtkProp)Bonds);
          ren1.AddActor((vtkProp)Atoms);
          //###################################################[]
          ren1.SetBackground((double)1,(double)1,(double)1);
          ren1.ResetCamera();
          renWin.Render();
          //method moved

          renWin.AbortCheckEvt += new Kitware.VTK.vtkObject.vtkObjectEventHandler(TkCheckAbort_Command.Execute);
          iren.Initialize();

        //deleteAllVTKObjects();
    }
예제 #32
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
        }
예제 #33
0
    /// <summary>
    /// The main entry method called by the CSharp driver
    /// </summary>
    /// <param name="argv"></param>
    public static void AVSelectionLoop(String [] argv)
    {
        //Prefix Content is: ""

          //[]
          // Demonstrate the use of implicit selection loop as well as closest point[]
          // connectivity[]
          //[]
          // create pipeline[]
          //[]
          sphere = new vtkSphereSource();
          sphere.SetRadius((double)1);
          sphere.SetPhiResolution((int)100);
          sphere.SetThetaResolution((int)100);
          selectionPoints = new vtkPoints();
          selectionPoints.InsertPoint((int)0,(double)0.07325,(double)0.8417,(double)0.5612);
          selectionPoints.InsertPoint((int)1,(double)0.07244,(double)0.6568,(double)0.7450);
          selectionPoints.InsertPoint((int)2,(double)0.1727,(double)0.4597,(double)0.8850);
          selectionPoints.InsertPoint((int)3,(double)0.3265,(double)0.6054,(double)0.7309);
          selectionPoints.InsertPoint((int)4,(double)0.5722,(double)0.5848,(double)0.5927);
          selectionPoints.InsertPoint((int)5,(double)0.4305,(double)0.8138,(double)0.4189);
          loop = new vtkImplicitSelectionLoop();
          loop.SetLoop((vtkPoints)selectionPoints);
          extract = new vtkExtractGeometry();
          extract.SetInputConnection((vtkAlgorithmOutput)sphere.GetOutputPort());
          extract.SetImplicitFunction((vtkImplicitFunction)loop);
          connect = new vtkConnectivityFilter();
          connect.SetInputConnection((vtkAlgorithmOutput)extract.GetOutputPort());
          connect.SetExtractionModeToClosestPointRegion();
          connect.SetClosestPoint((double)selectionPoints.GetPoint((int)0)[0], (double)selectionPoints.GetPoint((int)0)[1],(double)selectionPoints.GetPoint((int)0)[2]);
          clipMapper = new vtkDataSetMapper();
          clipMapper.SetInputConnection((vtkAlgorithmOutput)connect.GetOutputPort());
          backProp = new vtkProperty();
          backProp.SetDiffuseColor((double) 1.0000, 0.3882, 0.2784 );
          clipActor = new vtkActor();
          clipActor.SetMapper((vtkMapper)clipMapper);
          clipActor.GetProperty().SetColor((double) 0.2000, 0.6300, 0.7900 );
          clipActor.SetBackfaceProperty((vtkProperty)backProp);
          // Create graphics stuff[]
          //[]
          ren1 = vtkRenderer.New();
          renWin = vtkRenderWindow.New();
          renWin.AddRenderer((vtkRenderer)ren1);
          iren = new vtkRenderWindowInteractor();
          iren.SetRenderWindow((vtkRenderWindow)renWin);
          // Add the actors to the renderer, set the background and size[]
          //[]
          ren1.AddActor((vtkProp)clipActor);
          ren1.SetBackground((double)1,(double)1,(double)1);
          ren1.ResetCamera();
          ren1.GetActiveCamera().Azimuth((double)30);
          ren1.GetActiveCamera().Elevation((double)30);
          ren1.GetActiveCamera().Dolly((double)1.2);
          ren1.ResetCameraClippingRange();
          renWin.SetSize((int)400,(int)400);
          renWin.Render();
          // render the image[]
          //[]
          // prevent the tk window from showing up then start the event loop[]

        //deleteAllVTKObjects();
    }
예제 #34
0
    /// <summary>
    /// The main entry method called by the CSharp driver
    /// </summary>
    /// <param name="argv"></param>
    public static void AVStreamPolyData(String [] argv)
    {
        //Prefix Content is: ""

        NUMBER_OF_PIECES = 5;
        // Generate implicit model of a sphere[]
        //[]
        // Create renderer stuff[]
        //[]
        ren1   = vtkRenderer.New();
        renWin = vtkRenderWindow.New();
        renWin.AddRenderer((vtkRenderer)ren1);
        iren = new vtkRenderWindowInteractor();
        iren.SetRenderWindow((vtkRenderWindow)renWin);
        // create pipeline that handles ghost cells[]
        sphere = new vtkSphereSource();
        sphere.SetRadius((double)3);
        sphere.SetPhiResolution((int)100);
        sphere.SetThetaResolution((int)150);
        // sphere AddObserver StartEvent {tk_messageBox -message "Executing with piece [[sphere GetOutput] GetUpdatePiece]"}[]
        // Just playing with an alternative that is not currently used.[]
        //method moved
        // Just playing with an alternative that is not currently used.[]
        deci = new vtkDecimatePro();
        deci.SetInputConnection((vtkAlgorithmOutput)sphere.GetOutputPort());
        // this did not remove seams as I thought it would[]
        deci.BoundaryVertexDeletionOff();
        //deci PreserveTopologyOn[]
        // Since quadric Clustering does not handle borders properly yet,[]
        // the pieces will have dramatic "eams"[]
        q = new vtkQuadricClustering();
        q.SetInputConnection((vtkAlgorithmOutput)sphere.GetOutputPort());
        q.SetNumberOfXDivisions((int)5);
        q.SetNumberOfYDivisions((int)5);
        q.SetNumberOfZDivisions((int)10);
        q.UseInputPointsOn();
        streamer = new vtkPolyDataStreamer();
        //streamer SetInputConnection [deci GetOutputPort][]
        streamer.SetInputConnection((vtkAlgorithmOutput)q.GetOutputPort());
        //streamer SetInputConnection [pdn GetOutputPort][]
        streamer.SetNumberOfStreamDivisions((int)NUMBER_OF_PIECES);
        mapper = vtkPolyDataMapper.New();
        mapper.SetInputConnection((vtkAlgorithmOutput)streamer.GetOutputPort());
        mapper.ScalarVisibilityOff();
        mapper.SetPiece((int)0);
        mapper.SetNumberOfPieces((int)2);
        mapper.ImmediateModeRenderingOn();
        actor = new vtkActor();
        actor.SetMapper((vtkMapper)mapper);
        actor.GetProperty().SetColor((double)0.8300, 0.2400, 0.1000);
        // Add the actors to the renderer, set the background and size[]
        //[]
        ren1.GetActiveCamera().SetPosition((double)5, (double)5, (double)10);
        ren1.GetActiveCamera().SetFocalPoint((double)0, (double)0, (double)0);
        ren1.AddActor((vtkProp)actor);
        ren1.SetBackground((double)1, (double)1, (double)1);
        renWin.SetSize((int)300, (int)300);
        iren.Initialize();
        // render the image[]
        //[]
        // prevent the tk window from showing up then start the event loop[]

//deleteAllVTKObjects();
    }
예제 #35
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);
        }