Exemplo n.º 1
2
        static void Main(string[] args)
        {
            // This example demonstrates the use of vtk3DSImporter.
            // vtk3DSImporter is used to load 3D Studio files.  Unlike writers,
            // importers can load scenes (data as well as lights, cameras, actors
            // etc.). Importers will either generate an instance of vtkRenderWindow
            // and/or vtkRenderer or will use the ones you specify.
            string VTK_DATA_ROOT = vtk.vtkDotNetUtil.vtkGetDataRoot();

            // Create the importer and read a file
            vtk.vtk3DSImporter importer = new vtk.vtk3DSImporter();
            importer.ComputeNormalsOn();
            importer.SetFileName(VTK_DATA_ROOT + "/Data/iflamigm.3ds");
            importer.Read();

            // Here we let the importer create a renderer and a render window for
            // us. We could have also create and assigned those ourselves like so:
            // renWin = vtk.vtkRenderWindow();
            // importer.SetRenderWindow(renWin);

            // Assign an interactor.
            // We have to ask the importer for it's render window.
            vtk.vtkRenderWindow renWin = importer.GetRenderWindow();
            vtk.vtkRenderWindowInteractor iren = new vtk.vtkRenderWindowInteractor();
            iren.SetRenderWindow(renWin);

            // Set the render window's size
            renWin.SetSize(300, 300);

            // Set some properties on the renderer.
            // We have to ask the importer for it's renderer.
            vtk.vtkRenderer ren = importer.GetRenderer();
            ren.SetBackground(0.1, 0.2, 0.4);

            // Position the camera:
            // change view up to +z
            vtk.vtkCamera camera = ren.GetActiveCamera();
            camera.SetPosition(0, 1, 0);
            camera.SetFocalPoint(0, 0, 0);
            camera.SetViewUp(0, 0, 1);
            // let the renderer compute good position and focal point
            ren.ResetCamera();
            camera.Dolly(1.4);
            ren.ResetCameraClippingRange();

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

            vtk.vtkWin32OpenGLRenderWindow win32win =
                vtk.vtkWin32OpenGLRenderWindow.SafeDownCast(renWin);
            if (null != win32win) win32win.Clean();
        }
Exemplo n.º 2
0
        public void SetWindows(vtk.vtkRenderWindow renWint)
        {
            renWin = new vtk.vtkRenderWindow();

            iren   = new vtk.vtkRenderWindowInteractor();
            renWin = renWint;
            ren2   = new vtk.vtkRenderer();
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            string VTK_DATA_ROOT = vtk.vtkDotNetUtil.vtkGetDataRoot();

            // Create the reader and read a data file.  Connect the mapper and
            // actor.
            vtk.vtkSTLReader sr = new vtk.vtkSTLReader();
            sr.SetFileName(VTK_DATA_ROOT + "/Data/42400-IDGH.stl");

            vtk.vtkPolyDataMapper stlMapper = new vtk.vtkPolyDataMapper();
            stlMapper.SetInputConnection(sr.GetOutputPort());

            vtk.vtkLODActor stlActor = new vtk.vtkLODActor();
            stlActor.SetMapper(stlMapper);

            // Create the Renderer, RenderWindow, and RenderWindowInteractor
            vtk.vtkRenderer ren = new vtk.vtkRenderer();
            vtk.vtkRenderWindow renWin = new vtk.vtkRenderWindow();
            renWin.AddRenderer(ren);
            vtk.vtkRenderWindowInteractor iren = new vtk.vtkRenderWindowInteractor();
            iren.SetRenderWindow(renWin);

            // Add the actors to the render; set the background and size
            ren.AddActor(stlActor);
            ren.SetBackground(0.1, 0.2, 0.4);
            renWin.SetSize(500, 500);

            // Zoom in closer
            ren.ResetCamera();
            vtk.vtkCamera cam1 = ren.GetActiveCamera();
            cam1.Zoom(1.4);

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

            vtk.vtkWin32OpenGLRenderWindow win32win =
                vtk.vtkWin32OpenGLRenderWindow.SafeDownCast(renWin);
            if (null != win32win) win32win.Clean();
        }
Exemplo n.º 4
0
        void AddConeToWindow(vtk.vtkRenderWindow renWin)
        {
            //
            // Next we create an instance of vtkConeSource and set some of its
            // properties. The instance of vtkConeSource "cone" is part of a visualization
            // pipeline (it is a source process object); it produces data (output type is
            // vtkPolyData) which other filters may process.
            //
            vtk.vtkConeSource cone = new vtk.vtkConeSource();
            cone.SetHeight(3.0f);
            cone.SetRadius(1.0f);
            cone.SetResolution(10);

            //
            // In this example we terminate the pipeline with a mapper process object.
            // (Intermediate filters such as vtkShrinkPolyData could be inserted in
            // between the source and the mapper.)  We create an instance of
            // vtkPolyDataMapper to map the polygonal data into graphics primitives. We
            // connect the output of the cone souece to the input of this mapper.
            //
            vtk.vtkPolyDataMapper coneMapper = new vtk.vtkPolyDataMapper();
            coneMapper.SetInput(cone.GetOutput());

            //
            // Create an actor to represent the cone. The actor orchestrates rendering of
            // the mapper's graphics primitives. An actor also refers to properties via a
            // vtkProperty instance, and includes an internal transformation matrix. We
            // set this actor's mapper to be coneMapper which we created above.
            //
            vtk.vtkActor coneActor = new vtk.vtkActor();
            coneActor.SetMapper(coneMapper);

            //
            // Create the Renderer and assign actors to it. A renderer is like a
            // viewport. It is part or all of a window on the screen and it is
            // responsible for drawing the actors it has.  We also set the background
            // color here
            //
            vtk.vtkRenderer ren1 = new vtk.vtkRenderer();
            ren1.AddActor(coneActor);
            ren1.SetBackground(0.1f, 0.2f, 0.4f);

            //
            // Finally we create the render window which will show up on the screen
            // We put our renderer into the render window using AddRenderer. We also
            // set the size to be 300 pixels by 300
            //
            renWin.AddRenderer(ren1);

            vtk.vtkRenderWindowInteractor iren = renWin.GetInteractor();

            {
                m_boxWidget = new vtk.vtkBoxWidget();
                m_boxWidget.SetInteractor(iren);
                m_boxWidget.SetPlaceFactor(1.25f);

                m_boxWidget.SetProp3D(coneActor);
                m_boxWidget.PlaceWidget();

                m_boxWidget.AddObserver((uint)vtk.EventIds.InteractionEvent,
                                        new vtk.vtkDotNetCallback(myCallback));

                m_boxWidget.On();
            }
        }
Exemplo n.º 5
0
        void Run()
        {
            // Create a selection window.  We will display the point and cell ids
            // that lie within this window.
            int xmin = 200;
            xLength = 100;
            xmax = xmin + xLength;
            int ymin = 200;
            yLength = 100;
            ymax = ymin + yLength;

            pts = new vtk.vtkPoints();
            pts.InsertPoint(0, xmin, ymin, 0);
            pts.InsertPoint(1, xmax, ymin, 0);
            pts.InsertPoint(2, xmax, ymax, 0);
            pts.InsertPoint(3, xmin, ymax, 0);
            vtk.vtkCellArray rect = new vtk.vtkCellArray();
            rect.InsertNextCell(5);
            rect.InsertCellPoint(0);
            rect.InsertCellPoint(1);
            rect.InsertCellPoint(2);
            rect.InsertCellPoint(3);
            rect.InsertCellPoint(0);
            vtk.vtkPolyData selectRect = new vtk.vtkPolyData();
            selectRect.SetPoints(pts);
            selectRect.SetLines(rect);
            vtk.vtkPolyDataMapper2D rectMapper = new vtk.vtkPolyDataMapper2D();
            rectMapper.SetInput(selectRect);
            vtk.vtkActor2D rectActor = new vtk.vtkActor2D();
            rectActor.SetMapper(rectMapper);

            // Create a sphere and its associated mapper and actor.
            vtk.vtkSphereSource sphere = new vtk.vtkSphereSource();
            vtk.vtkPolyDataMapper sphereMapper = new vtk.vtkPolyDataMapper();
            sphereMapper.SetInputConnection(sphere.GetOutputPort());
            vtk.vtkPolyDataMapper.GlobalImmediateModeRenderingOn();
            vtk.vtkActor sphereActor = new vtk.vtkActor();
            sphereActor.SetMapper(sphereMapper);

            // Generate data arrays containing point and cell ids
            vtk.vtkIdFilter ids = new vtk.vtkIdFilter();
            ids.SetInputConnection(sphere.GetOutputPort());
            ids.PointIdsOn();
            ids.CellIdsOn();
            ids.FieldDataOn();

            // Create the renderer here because vtkSelectVisiblePoints needs it.
            vtk.vtkRenderer ren = new vtk.vtkRenderer();

            // Create labels for points
            visPts = new vtk.vtkSelectVisiblePoints();
            visPts.SetInputConnection(ids.GetOutputPort());
            visPts.SetRenderer(ren);
            visPts.SelectionWindowOn();
            visPts.SetSelection(xmin, xmin + xLength, ymin, ymin + yLength);

            // Create the mapper to display the point ids.  Specify the format to
            // use for the labels.  Also create the associated actor.
            vtk.vtkLabeledDataMapper ldm = new vtk.vtkLabeledDataMapper();
            ldm.SetInputConnection(visPts.GetOutputPort());
            ldm.SetLabelFormat("%g");
            ldm.SetLabelModeToLabelFieldData();
            vtk.vtkActor2D pointLabels = new vtk.vtkActor2D();
            pointLabels.SetMapper(ldm);

            // Create labels for cells
            vtk.vtkCellCenters cc = new vtk.vtkCellCenters();
            cc.SetInputConnection(ids.GetOutputPort());
            visCells = new vtk.vtkSelectVisiblePoints();
            visCells.SetInputConnection(cc.GetOutputPort());
            visCells.SetRenderer(ren);
            visCells.SelectionWindowOn();
            visCells.SetSelection(xmin, xmin + xLength, ymin, ymin + yLength);

            // Create the mapper to display the cell ids.  Specify the format to
            // use for the labels.  Also create the associated actor.
            vtk.vtkLabeledDataMapper cellMapper = new vtk.vtkLabeledDataMapper();
            cellMapper.SetInputConnection(visCells.GetOutputPort());
            cellMapper.SetLabelFormat("%g");
            cellMapper.SetLabelModeToLabelFieldData();
            cellMapper.GetLabelTextProperty().SetColor(0, 1, 0);
            vtk.vtkActor2D cellLabels = new vtk.vtkActor2D();
            cellLabels.SetMapper(cellMapper);

            // Create the RenderWindow and RenderWindowInteractor
            renWin = new vtk.vtkRenderWindow();
            renWin.AddRenderer(ren);
            vtk.vtkRenderWindowInteractor iren = new vtk.vtkRenderWindowInteractor();
            iren.SetRenderWindow(renWin);

            // Add the actors to the renderer; set the background and size;
            // render
            ren.AddActor(sphereActor);
            ren.AddActor2D(rectActor);
            ren.AddActor2D(pointLabels);
            ren.AddActor2D(cellLabels);

            ren.SetBackground(1, 1, 1);
            renWin.SetSize(500, 500);

            // Initialize the interactor.
            iren.Initialize();
            renWin.Render();

            // Move the selection window across the data set.
            MoveWindow();

            // Put the selection window in the center of the render window.
            // This works because the xmin = ymin = 200, xLength = yLength = 100, and
            // the render window size is 500 x 500.
            PlaceWindow(xmin, ymin);

            // Now start normal interaction.
            iren.Start();
            vtk.vtkWin32OpenGLRenderWindow win32win =
                vtk.vtkWin32OpenGLRenderWindow.SafeDownCast(renWin);
            if (null != win32win) win32win.Clean();
        }