Esempio 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();
        }
Esempio n. 2
0
        //public c3DWorld(Kitware.VTK.RenderWindowControl CurrentrenderWindowControl, Sequence Seq)
        //{
        //    this.ren1 = CurrentrenderWindowControl.RenderWindow.GetRenderers().GetFirstRenderer();
        //    this.renWin = CurrentrenderWindowControl.RenderWindow;
        //    if (Seq == null)
        //    {
        //        Xres = Yres = Zres = 0;
        //    }
        //    else
        //    {
        //        Xres = Seq.XResolution;
        //        Yres = Seq.YResolution;
        //        Zres = Seq.ZResolution;
        //    }
        //    ListPolyDataMapper = new List<vtkPolyDataMapper>();
        //    ListObject = new List<cObject3D>();
        //    ListVolume = new List<cVolume3D>();
        //}
        /// <summary>
        /// Create a 3D world
        /// </summary>
        /// <param name="CurrentrenderWindowControl">vtk Control</param>
        /// <param name="Dimensions">in pixels</param>
        /// <param name="Resolution">spatial resolutions</param>
        public c3DWorld(cPoint3D Dimensions, cPoint3D Resolution, RenderWindowControl CurrentrenderWindowControl, int[] WinPos)
        {
            // int[] Pos =  renWin.GetPosition();

            //,
            if (CurrentrenderWindowControl == null)
            {
                renWin = vtkRenderWindow.New();
                renWin.LineSmoothingOn();
                renWin.PointSmoothingOn();
                renWin.SetWindowName("3D World");
                renWin.BordersOn();
                renWin.DoubleBufferOn();

                renWin.SetSize(750, 500);

                //   if(WinPos!=null)            renWin.SetPosition(WinPos[0], WinPos[1]);
                // this.ren1 = CurrentrenderWindowControl.RenderWindow.GetRenderers().GetFirstRenderer();
                //CurrentrenderWindowControl.RenderWindow;
            }

            //// Menu Strip Construction
            //this.contextMenuStripActorPicker = new ContextMenuStrip();
            //ToolStripMenuItem StripMenuItemDisplay = new ToolStripMenuItem("Display");
            //contextMenuStripActorPicker.Items.Add(StripMenuItemDisplay);

            this.ren1 = vtkRenderer.New();
            //renWin = CurrentrenderWindowControl.RenderWindow;//vtkRenderWindow.New();

            renWin.AddRenderer(ren1);

            iren = new vtkRenderWindowInteractor();
            iren.SetRenderWindow(renWin);

            //iren.SetInteractorStyle(vtkInteractorStyleJoystickCamera.New());
            iren.SetInteractorStyle(vtkInteractorStyleTrackballCamera.New());
            //   iren.SetInteractorStyle(vtkInteractorStyleTerrain.New());

            // iren.LeftButtonPressEvt += new vtkObject.vtkObjectEventHandler(RenderWindow_LeftButtonPressEvt);
            iren.KeyPressEvt += new vtkObject.vtkObjectEventHandler(RenderWindow_KeyPressEvt);
            iren.RightButtonPressEvt += new vtkObject.vtkObjectEventHandler(RenderWindow_RightButtonPressEvt);

            //Render();
            //this.ren1 =

            Xres = Resolution.X;
            Yres = Resolution.Y;
            Zres = Resolution.Z;

            SizeX = (int)Dimensions.X;
            SizeY = (int)Dimensions.Y;
            SizeZ = (int)Dimensions.Z;

            //  double[] fp = ren1.GetActiveCamera().GetFocalPoint();
            //   double[] p = ren1.GetActiveCamera().GetPosition();

            //   ren1.GetActiveCamera().ParallelProjectionOn();

            //   double dist = Math.Sqrt((p[0] - fp[0]) * (p[0] - fp[0]) + (p[1] - fp[1]) * (p[1] - fp[1]) + (p[2] - fp[2]) * (p[2] - fp[2]));
            //    ren1.GetActiveCamera().SetPosition(fp[0], fp[1], fp[2] + dist*1000);
            //    ren1.GetActiveCamera().Zoom(2);
            //ren1.Render();
            //  this.Render();
            ListPolyDataMapper = new List<vtkPolyDataMapper>();
            ListObject = new List<cObject3D>();

            //     Vtk_CameraViewOrientation = ren1.GetActiveCamera();
        }
Esempio n. 3
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();
    }