Exemplo n.º 1
2
        static void Main()
        {
            string VTK_DATA_ROOT = "C:/Program Files/VTKData";

            // Create a vtkBYUReader and read in a data set.
            vtkBYUReader fohe = new vtkBYUReader();
            fohe.SetGeometryFileName(VTK_DATA_ROOT + "/Data/teapot.g");

            // Create a vtkPolyDataNormals filter to calculate the normals of the
            // data set.
            vtkPolyDataNormals normals = new vtkPolyDataNormals();
            normals.SetInputConnection(fohe.GetOutputPort());
            // Set up the associated mapper and actor.
            vtkPolyDataMapper foheMapper = new vtkPolyDataMapper();
            foheMapper.SetInputConnection(normals.GetOutputPort());
            vtkLODActor foheActor = new vtkLODActor();
            foheActor.SetMapper(foheMapper);

            // Create a vtkOutlineFilter to draw the bounding box of the data set.
            // Also create the associated mapper and actor.
            vtkOutlineFilter outline = new vtkOutlineFilter();
            outline.SetInputConnection(normals.GetOutputPort());
            vtkPolyDataMapper mapOutline = new vtkPolyDataMapper();
            mapOutline.SetInputConnection(outline.GetOutputPort());
            vtkActor outlineActor = new vtkActor();
            outlineActor.SetMapper(mapOutline);
            outlineActor.GetProperty().SetColor(0, 0, 0);

            // Create a vtkCamera, and set the camera parameters.
            vtkCamera camera = new vtkCamera();
            camera.SetClippingRange(1.60187, 20.0842);
            camera.SetFocalPoint(0.21406, 1.5, 0);
            camera.SetPosition(8.3761, 4.94858, 4.12505);
            camera.SetViewUp(0.180325, 0.549245, -0.815974);

            // Create a vtkLight, and set the light parameters.
            vtkLight light = new vtkLight();
            light.SetFocalPoint(0.21406, 1.5, 0);
            light.SetPosition(8.3761, 4.94858, 4.12505);

            // Create the Renderers.  Assign them the appropriate viewport
            // coordinates, active camera, and light.
            vtkRenderer ren = new vtkRenderer();
            ren.SetViewport(0, 0, 0.5, 1.0);
            ren.SetActiveCamera(camera);
            ren.AddLight(light);
            vtkRenderer ren2 = new vtkRenderer();
            ren2.SetViewport(0.5, 0, 1.0, 1.0);
            ren2.SetActiveCamera(camera);
            ren2.AddLight(light);

            // Create the RenderWindow and RenderWindowInteractor.
            vtkRenderWindow renWin = new vtkRenderWindow();
            renWin.AddRenderer(ren);
            renWin.AddRenderer(ren2);
            renWin.SetWindowName("VTK - Cube Axes");
            renWin.SetSize(600, 300);
            vtkRenderWindowInteractor iren = new vtkRenderWindowInteractor();
            iren.SetRenderWindow(renWin);

            // Add the actors to the renderer, and set the background.
            ren.AddViewProp(foheActor);
            ren.AddViewProp(outlineActor);
            ren2.AddViewProp(foheActor);
            ren2.AddViewProp(outlineActor);

            ren.SetBackground(0.1, 0.2, 0.4);
            ren2.SetBackground(0.1, 0.2, 0.4);

            // Create a text property for both cube axes
            vtkTextProperty tprop = new vtkTextProperty();
            tprop.SetColor(1, 1, 1);
            tprop.ShadowOn();

            // Create a vtkCubeAxesActor2D.  Use the outer edges of the bounding box to
            // draw the axes.  Add the actor to the renderer.
            vtkCubeAxesActor2D axes = new vtkCubeAxesActor2D();
            axes.SetInput(normals.GetOutput());
            axes.SetCamera(ren.GetActiveCamera());
            axes.SetLabelFormat("%6.4g");
            axes.SetFlyModeToOuterEdges();
            axes.SetFontFactor(0.8);
            axes.SetAxisTitleTextProperty(tprop);
            axes.SetAxisLabelTextProperty(tprop);
            ren.AddViewProp(axes);

            // Create a vtkCubeAxesActor2D.  Use the closest vertex to the camera to
            // determine where to draw the axes.  Add the actor to the renderer.
            vtkCubeAxesActor2D axes2 = new vtkCubeAxesActor2D();
            axes2.SetViewProp(foheActor);
            axes2.SetCamera(ren2.GetActiveCamera());
            axes2.SetLabelFormat("%6.4g");
            axes2.SetFlyModeToClosestTriad();
            axes2.SetFontFactor(0.8);
            axes2.ScalingOff();
            axes2.SetAxisTitleTextProperty(tprop);
            axes2.SetAxisLabelTextProperty(tprop);
            ren2.AddViewProp(axes2);

            renWin.AddObserver((uint) EventIds.AbortCheckEvent, CheckAbort);

            iren.Initialize();
            renWin.Render();
            iren.Start();

            vtkWin32OpenGLRenderWindow win32win =
                vtkWin32OpenGLRenderWindow.SafeDownCast(renWin);
            if (null != win32win) win32win.Clean();
        }
Exemplo n.º 2
0
        public void AddMeToTheWorld(vtkRenderer World)
        {
            if (vtk_Actor != null)
                World.AddViewProp(this.vtk_Actor);

            if (ListActors != null)
                for (int i = 0; i < ListActors.Count; i++) World.AddViewProp(this.ListActors[i]);
        }
Exemplo n.º 3
0
        private void AddLayers(DrawArgs args)
        {
            IAssociatedTissues volume = args.SceneGraph.ParentPresentationImage as IAssociatedTissues;

            if (volume == null)
            {
                return;
            }

            GraphicCollection layers = volume.TissueLayers;
            vtkPropCollection props  = _vtkRenderer.GetViewProps();

            foreach (VolumeGraphic volumeGraphic in layers)
            {
                if (props.IsItemPresent(volumeGraphic.VtkProp) == 0)
                {
                    _vtkRenderer.AddViewProp(volumeGraphic.VtkProp);
                }

                //if (volumeLayer.OldVtkProp != null)
                //{

                //    if (props.IsItemPresent(volumeLayer.OldVtkProp) != 0)
                //    {
                //        props.RemoveItem(volumeLayer.OldVtkProp);
                //        volumeLayer.OldVtkProp = null;
                //    }
                //}
            }
        }
Exemplo n.º 4
0
        public override sealed void InitializeSceneGraph(vtkRenderer vtkRenderer)
        {
            if (Disposed)
            {
                return;
            }

            var rootProp = ModelRootProp;
            var origin   = Owner.Origin ?? Vector3D.Null;

            rootProp.SetPosition(origin.X, origin.Y, origin.Z);

            // preinitialize the prop transform matrix
            using (var userMatrix = new vtkMatrix4x4())
                rootProp.SetUserMatrix(userMatrix);

            vtkRenderer.AddViewProp(rootProp);

            using (var renderWindow = vtkRenderer.GetRenderWindow())
            {
                var cameraDistance = GetNominalCameraDistance();
                var clientSize     = renderWindow.GetSize();
                var camera         = AddNewVtkObject <vtkCamera>();
                camera.ParallelProjectionOn();
                camera.SetParallelScale(0.5 * clientSize[1]);
                camera.SetPosition(0, 0, cameraDistance);
                camera.SetFocalPoint(0, 0, 0);
                camera.SetClippingRange(10, 2 * cameraDistance);
                camera.ComputeViewPlaneNormal();
                camera.SetViewUp(0, 1, 0);
                vtkRenderer.SetActiveCamera(camera);
            }
        }
Exemplo n.º 5
0
        private void CreateViewportBorder(vtkRenderer renderer, double[] color)
        {
            ModelLoaded = false;

            // points start at upper right and proceed anti-clockwise
            vtkPoints points = vtkPoints.New();

            points.SetNumberOfPoints(4);
            points.InsertPoint(0, 1, 1, 0);
            points.InsertPoint(1, 1e-3, 1, 0);
            points.InsertPoint(2, 1e-3, 1e-3, 0);
            points.InsertPoint(3, 1, 1e-3, 0);

            // create cells, and lines
            vtkCellArray cells = vtkCellArray.New();

            cells.Initialize();

            vtkPolyLine lines = vtkPolyLine.New();

            lines.GetPointIds().SetNumberOfIds(5);
            for (int i = 0; i < 4; ++i)
            {
                lines.GetPointIds().SetId(i, i);
            }
            lines.GetPointIds().SetId(4, 0);
            cells.InsertNextCell(lines);

            // now make tge polydata and display it
            vtkPolyData poly = vtkPolyData.New();

            poly.Initialize();
            poly.SetPoints(points);
            poly.SetLines(cells);

            // use normalized viewport coordinates since
            // they are independent of window size
            vtkCoordinate coordinate = vtkCoordinate.New();

            coordinate.SetCoordinateSystemToNormalizedViewport();

            vtkPolyDataMapper2D mapper = vtkPolyDataMapper2D.New();

            mapper.SetInput(poly);
            mapper.SetTransformCoordinate(coordinate);

            vtkActor2D actor = vtkActor2D.New();

            actor.SetMapper(mapper);
            actor.GetProperty().SetColor(color[0], color[1], color[2]);
            // line width should be at least 2 to be visible at extremes

            actor.GetProperty().SetLineWidth((float)2.0); // Line Width

            renderer.AddViewProp(actor);
        }
Exemplo n.º 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();
        }
        private void AddLayers(DrawArgs args)
        {
            IAssociatedTissues volume = args.SceneGraph.ParentPresentationImage as IAssociatedTissues;

            if (volume == null)
            {
                return;
            }

            GraphicCollection layers = volume.TissueLayers;
            vtkPropCollection props  = _vtkRenderer.GetViewProps();

            foreach (var graphic in layers)
            {
                var volumeGraphic = (VolumeGraphic)graphic;
                if (props.IsItemPresent(volumeGraphic.VtkProp) == 0)
                {
                    _vtkRenderer.AddViewProp(volumeGraphic.VtkProp);
                }
            }
        }
Exemplo n.º 8
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);
        }
Exemplo n.º 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;
        }
        public CornerAnnotationActorPackage(vtkRenderer aRender)
        {
            cornerAnnotation = vtkCornerAnnotation.New();
            cornerAnnotation.SetLinearFontScaleFactor(2);
            cornerAnnotation.GetTextProperty().ShadowOn();
            cornerAnnotation.SetNonlinearFontScaleFactor(1);
            cornerAnnotation.SetMaximumFontSize(20);
            cornerAnnotation.SetText(0, "lower left");
            cornerAnnotation.SetText(1, "lower right");
            cornerAnnotation.SetText(2, "upper left");
            cornerAnnotation.SetText(3, "upper right");
            cornerAnnotation.GetTextProperty().SetColor(0.8, 0.8, 0.8);
            cornerAnnotation.GetTextProperty().SetColor(1, 1, 1);
            //cornerAnnotation.GetTextProperty().SetFontFamily(4);
            cornerAnnotation.GetTextProperty().BoldOn();
            //.SetFontFamilyToArial();

            cornerAnnotation.SetText(0, " ");
            cornerAnnotation.SetText(1, " ");
            cornerAnnotation.SetText(2, " ");
            cornerAnnotation.SetText(3, " ");

            aRender.AddViewProp(cornerAnnotation);
        }
Exemplo n.º 11
0
    /// <summary>
    /// An example that does not use a Windows Form
    /// </summary>
    /// <param name="argv"></param>
    public static void Main(String[] argv)
    {
        // This example demonstrates the use of vtkCubeAxesActor2D to indicate the
        // position in space that the camera is currently viewing.
        // The vtkCubeAxesActor2D draws axes on the bounding box of the data set and
        // labels the axes with x-y-z coordinates.
        //
        // First we include the VTK Tcl packages which will make available
        // all of the vtk commands to Tcl
        //
        // Create a vtkBYUReader and read in a data set.
        //
        fohe = vtkBYUReader.New();
        fohe.SetGeometryFileName("../../../teapot.g");

        // Create a vtkPolyDataNormals filter to calculate the normals of the data set.
        normals = vtkPolyDataNormals.New();
        normals.SetInputConnection(fohe.GetOutputPort());

        // Set up the associated mapper and actor.
        foheMapper = vtkPolyDataMapper.New();
        foheMapper.SetInputConnection(normals.GetOutputPort());

        foheActor = vtkLODActor.New();
        foheActor.SetMapper(foheMapper);

        // Create a vtkOutlineFilter to draw the bounding box of the data set.  Also
        // create the associated mapper and actor.
        outline = vtkOutlineFilter.New();
        outline.SetInputConnection(normals.GetOutputPort());

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

        outlineActor = vtkActor.New();
        outlineActor.SetMapper(mapOutline);
        outlineActor.GetProperty().SetColor(0, 0, 0);

        // Create a vtkCamera, and set the camera parameters.
        camera = vtkCamera.New();
        camera.SetClippingRange(1.60187, 20.0842);
        camera.SetFocalPoint(0.21406, 1.5, 0);
        camera.SetPosition(8.3761, 4.94858, 4.12505);
        camera.SetViewUp(0.180325, 0.549245, -0.815974);

        // Create a vtkLight, and set the light parameters.
        light = vtkLight.New();
        light.SetFocalPoint(0.21406, 1.5, 0);
        light.SetPosition(8.3761, 4.94858, 4.12505);

        // Create the Renderers.  Assign them the appropriate viewport coordinates,
        // active camera, and light.
        ren1 = vtkRenderer.New();
        ren1.SetViewport(0, 0, 0.5, 1.0);
        ren1.SetActiveCamera(camera);
        ren1.AddLight(light);

        ren2 = vtkRenderer.New();
        ren2.SetViewport(0.5, 0, 1.0, 1.0);
        ren2.SetActiveCamera(camera);
        ren2.AddLight(light);

        // Create the RenderWindow and RenderWindowInteractor.
        renWin = vtkRenderWindow.New();
        renWin.AddRenderer(ren1);
        renWin.AddRenderer(ren2);
        renWin.SetWindowName("VTK - Cube Axes");
        renWin.SetSize(600, 300);
        iren = vtkRenderWindowInteractor.New();
        iren.SetRenderWindow(renWin);

        // Add the actors to the renderer, and set the background.
        ren1.AddViewProp(foheActor);
        ren1.AddViewProp(outlineActor);
        ren2.AddViewProp(foheActor);
        ren2.AddViewProp(outlineActor);
        ren1.SetBackground(0.1, 0.2, 0.4);
        ren2.SetBackground(0.1, 0.2, 0.4);

        // Create a text property for both cube axes
        tprop = vtkTextProperty.New();
        tprop.SetColor(1, 1, 1);
        tprop.ShadowOn();

        // Create a vtkCubeAxesActor2D.  Use the outer edges of the bounding box to
        // draw the axes.  Add the actor to the renderer.
        axes = vtkCubeAxesActor2D.New();
        axes.SetInput(normals.GetOutput());
        axes.SetCamera(ren1.GetActiveCamera());
        axes.SetLabelFormat("%6.4g");
        axes.SetFlyModeToOuterEdges();
        axes.SetFontFactor(0.8);
        axes.SetAxisTitleTextProperty(tprop);
        axes.SetAxisLabelTextProperty(tprop);
        ren1.AddViewProp(axes);

        // Create a vtkCubeAxesActor2D.  Use the closest vertex to the camera to
        // determine where to draw the axes.  Add the actor to the renderer.
        axes2 = vtkCubeAxesActor2D.New();
        axes2.SetViewProp(foheActor);
        axes2.SetCamera(ren2.GetActiveCamera());
        axes2.SetLabelFormat("%6.4g");
        axes2.SetFlyModeToClosestTriad();
        axes2.SetFontFactor(0.8);
        axes2.ScalingOff();
        axes2.SetAxisTitleTextProperty(tprop);
        axes2.SetAxisLabelTextProperty(tprop);
        ren2.AddViewProp(axes2);

        // Render
        renWin.Render();

        // Set the user method (bound to key 'u')
        iren.Initialize();
        iren.Start();

        // Set up a check for aborting rendering.
        renWin.AbortCheckEvt += new vtkObject.vtkObjectEventHandler(TkCheckAbort);

        //Clean Up
        deleteAllVTKObjects();
    }
Exemplo n.º 12
0
        private void Window_Activated(object sender, EventArgs e)
        {
            vtkPolyData   cube    = new vtkPolyData();
            vtkPoints     points  = new vtkPoints();
            vtkCellArray  polys   = new vtkCellArray();
            vtkFloatArray scalars = new vtkFloatArray();

            Kitware.VTK.RenderWindowControl vtkControl = new Kitware.VTK.RenderWindowControl();
            vtkControl.AddTestActors = false;
            vtkControl.Location      = new System.Drawing.Point(10, 10);
            vtkControl.Name          = "_renwin";
            vtkControl.Size          = new System.Drawing.Size(100, 100);
            vtkControl.TabIndex      = 0;
            vtkControl.TestText      = null;
            vtkControl.Dock          = System.Windows.Forms.DockStyle.Fill;
            vtkformhost.Child        = vtkControl;
            vtkformhost.Visibility   = System.Windows.Visibility.Visible;


            int i;

            float[][] x = new float[8][]
            {
                new float[] { 0, 0, 0 }, //第0个点的坐标
                new float[] { 1, 0, 0 }, //第1个点的坐标
                new float[] { 1, 1, 0 }, //第2个点的坐标
                new float[] { 0, 1, 0 }, //3
                new float[] { 0, 0, 1 }, //4
                new float[] { 1, 0, 1 }, //5
                new float[] { 1, 1, 1 }, //6
                new float[] { 0, 1, 1 } //7
            };
            for (i = 0; i < 8; i++)
            {
                points.InsertPoint(i, x[i][0], x[i][1], x[i][2]);                    //加载点,创建数据结构的几何
            }
            List <int[]> temp = new List <int[]>();

            int[] temparray0 = new int[4] {
                0, 1, 2, 3
            };                                           //第0,1,2,3个点连接在一起,成为一个单元
            int[] temparray1 = new int[4] {
                4, 5, 6, 7
            };                                           //第4,5,6,7个点连接在一起,成为一个单元
            int[] temparray2 = new int[4] {
                0, 1, 5, 4
            };
            int[] temparray3 = new int[4] {
                1, 2, 6, 5
            };
            int[] temparray4 = new int[4] {
                2, 3, 7, 6
            };
            int[] temparray5 = new int[4] {
                3, 0, 4, 7
            };
            temp.Add(temparray0);
            temp.Add(temparray1);
            temp.Add(temparray2);
            temp.Add(temparray3);
            temp.Add(temparray4);
            temp.Add(temparray5);
            //因为在activiz中没有vtkIdType这个类,所以用了其他的方法代替C++代码中的实现。
            for (int j = 0; j < temp.Count; j++)
            {
                IntPtr pP = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(int)) * 4);
                Marshal.Copy(temp[j], 0, pP, 4);
                polys.InsertNextCell(4, pP);//加载单元,定义数据集的拓扑
                Marshal.FreeHGlobal(pP);
            }
            for (i = 0; i < 8; i++)
            {
                scalars.InsertTuple1(i, i);                    //为每一个点设置点属性。
            }
            cube.SetPoints(points);
            cube.SetPolys(polys);
            cube.GetPointData().SetScalars(scalars);

            vtkPolyDataMapper cubemapper = new vtkPainterPolyDataMapper();

            cubemapper.SetInput(cube);
            cubemapper.SetScalarRange(0, 7);

            vtkActor cubeactor = new vtkActor();

            cubeactor.SetMapper(cubemapper);

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


            // Add the actors to the renderer, set the window size
            //
            ren1.AddViewProp(cubeactor);
            _renwin.SetSize(250, 250);
            _renwin.Render();
            ren1.ResetCamera();
        }