Exemplo n.º 1
0
 void InitRenderWindow()
 {
     m_render.GradientBackgroundOn();
     m_render.SetBackground(32.0 / 255, 82.0 / 255, 112.0 / 255);
     m_render.SetBackground2(198.0 / 255, 198.0 / 255, 219.0 / 255);
     DrawAxes();
 }
Exemplo n.º 2
0
        // ===================== PUBLIC methods to modify Graphical View properties ===================

        public void ChangeBackgroundColor(bool gradient, double[] color1, double[] color2)
        {
            if (gradient == true)
            {
                Viewport.GradientBackgroundOn();
                Viewport.SetBackground(color1[0] / 255.0, color1[1] / 255.0, color1[2] / 255.0);
                Viewport.SetBackground2(color2[0] / 255.0, color2[1] / 255.0, color2[2] / 255.0);
            }
            else
            {
                Viewport.GradientBackgroundOff();
                Viewport.SetBackground(color1[0] / 255.0, color1[1] / 255.0, color1[2] / 255.0);
            }
        }
Exemplo n.º 3
0
        public static void ShowPolydata(string airwayPath)
        {
            if (!File.Exists(airwayPath))
            {
                MessageBox.Show("文件不存在!");
                return;
            }
            vtkRenderWindow renWin = vtkRenderWindow.New();

            renWin.SetSize(600, 600);

            vtkRenderWindowInteractor iren = new vtkRenderWindowInteractor();

            renWin.SetInteractor(iren);

            vtkInteractorStyleTrackballCamera interactorStyle = new vtkInteractorStyleTrackballCamera();

            iren.SetInteractorStyle(interactorStyle);

            vtkRenderer renderer = vtkRenderer.New();

            renderer.GradientBackgroundOn();
            renderer.SetBackground(0, 0, 0);
            renderer.SetBackground2(0, 0, 1);
            renWin.AddRenderer(renderer);
            vtkXMLPolyDataReader reader = new vtkXMLPolyDataReader();

            reader.SetFileName(airwayPath);
            reader.Update();

            vtkPolyDataMapper mapper = vtkPolyDataMapper.New();

            mapper.ScalarVisibilityOff();
            mapper.SetInput(reader.GetOutput());
            reader.Dispose();
            vtkActor actor = new vtkActor();

            actor.SetMapper(mapper);

            renderer.AddActor(actor);

            renWin.Render();
        }
Exemplo n.º 4
0
        public Simulation(vtkRenderWindow renderWindow)
        {
            RenderWindow = renderWindow;
            Renderer = renderWindow.GetRenderers().GetFirstRenderer();

            //Background
            Renderer.GradientBackgroundOn();
            Renderer.SetBackground((double)colorBackground.R / 255, (double)colorBackground.G / 255, (double)colorBackground.B / 255);
            Renderer.SetBackground2((double)colorBackground2.R / 255, (double)colorBackground2.G / 255, (double)colorBackground2.B / 255);

            //Base
            baseAxes.SetTotalLength(200, 200, 200);
            baseAxes.AxisLabelsOff();
            Renderer.AddActor(baseAxes);

            //Floor
            vtkPlaneSource planeSource = vtkPlaneSource.New();
            planeSource.SetOrigin(-1000.0, -1000.0, 0);
            planeSource.SetPoint1(-1000.0, 1000.0, 0);
            planeSource.SetPoint2(1000.0, -1000.0, 0);
            planeSource.Update();
            vtkPolyDataMapper mapper = vtkPolyDataMapper.New();
            vtkPolyData plane = planeSource.GetOutput();
            mapper.SetInput(plane);
            floor = vtkActor.New();
            floor.SetMapper(mapper);
            floor.GetProperty().SetColor(0.8, 0.8, 0.8);
            Renderer.AddActor(floor);

            //Robot1
            robot1Pos = new Position(-500, 0, 0, 0, 0, 0);
            //Robots.Robot1.Base = new Position(-500, 0, 0, 0, 0, 0);

            robot1part1 = LoadSTL(robot1part1, @"\Robot\agilus_00.stl", Color.FromArgb(25, 25, 25));
            robot1part2 = LoadSTL(robot1part2, @"\Robot\agilus_01.stl", Color.FromArgb(255, 110, 0));
            robot1part3 = LoadSTL(robot1part3, @"\Robot\agilus_02.stl", Color.FromArgb(255, 110, 0));
            robot1part4 = LoadSTL(robot1part4, @"\Robot\agilus_03.stl", Color.FromArgb(255, 110, 0));
            robot1part5 = LoadSTL(robot1part5, @"\Robot\agilus_04.stl", Color.FromArgb(255, 110, 0));
            robot1part6 = LoadSTL(robot1part6, @"\Robot\agilus_05.stl", Color.FromArgb(255, 110, 0));
            robot1part7 = LoadSTL(robot1part6, @"\Robot\agilus_06.stl", Color.DarkGray);
            robot1part1.SetPosition(robot1Pos.X, robot1Pos.Y, robot1Pos.Z);
            Renderer.AddActor(robot1part1);
            Renderer.AddActor(robot1part2);
            Renderer.AddActor(robot1part3);
            Renderer.AddActor(robot1part4);
            Renderer.AddActor(robot1part5);
            Renderer.AddActor(robot1part6);
            Renderer.AddActor(robot1part7);
            robot1axes1.SetTotalLength(200, 200, 200);
            robot1axes1.AxisLabelsOff();
            Renderer.AddActor(robot1axes1);
            robot1axes2.SetTotalLength(200, 200, 200);
            robot1axes2.AxisLabelsOff();
            Renderer.AddActor(robot1axes2);
            robot1axes3.SetTotalLength(200, 200, 200);
            robot1axes3.AxisLabelsOff();
            Renderer.AddActor(robot1axes3);
            robot1axes4.SetTotalLength(200, 200, 200);
            robot1axes4.AxisLabelsOff();
            Renderer.AddActor(robot1axes4);
            robot1axes5.SetTotalLength(200, 200, 200);
            robot1axes5.AxisLabelsOff();
            Renderer.AddActor(robot1axes5);
            robot1axes6.SetTotalLength(200, 200, 200);
            robot1axes6.AxisLabelsOff();
            Renderer.AddActor(robot1axes6);

            //Robot2
            robot2Pos = new Position(1000, 0, 0, 0, 0, 0);
            Robots.Robot2.Base = robot2Pos;
            robot2part1 = LoadSTL(robot2part1, @"\Robot\agilus_00.stl", Color.FromArgb(25, 25, 25));
            robot2part2 = LoadSTL(robot2part2, @"\Robot\agilus_01.stl", Color.FromArgb(255, 110, 0));
            robot2part3 = LoadSTL(robot2part3, @"\Robot\agilus_02.stl", Color.FromArgb(255, 110, 0));
            robot2part4 = LoadSTL(robot2part4, @"\Robot\agilus_03.stl", Color.FromArgb(255, 110, 0));
            robot2part5 = LoadSTL(robot2part5, @"\Robot\agilus_04.stl", Color.FromArgb(255, 110, 0));
            robot2part6 = LoadSTL(robot2part6, @"\Robot\agilus_05.stl", Color.FromArgb(255, 110, 0));
            robot2part7 = LoadSTL(robot2part6, @"\Robot\agilus_06.stl", Color.DarkGray);
            robot2part1.SetPosition(Robots.Robot2.Base.X, Robots.Robot2.Base.Y, Robots.Robot2.Base.Z);
            Renderer.AddActor(robot2part1);
            Renderer.AddActor(robot2part2);
            Renderer.AddActor(robot2part3);
            Renderer.AddActor(robot2part4);
            Renderer.AddActor(robot2part5);
            Renderer.AddActor(robot2part6);
            Renderer.AddActor(robot2part7);
            robot2axes1.SetTotalLength(200, 200, 200);
            robot2axes1.AxisLabelsOff();
            Renderer.AddActor(robot2axes1);
            robot2axes2.SetTotalLength(200, 200, 200);
            robot2axes2.AxisLabelsOff();
            Renderer.AddActor(robot2axes2);
            robot2axes3.SetTotalLength(200, 200, 200);
            robot2axes3.AxisLabelsOff();
            Renderer.AddActor(robot2axes3);
            robot2axes4.SetTotalLength(200, 200, 200);
            robot2axes4.AxisLabelsOff();
            Renderer.AddActor(robot2axes4);
            robot2axes5.SetTotalLength(200, 200, 200);
            robot2axes5.AxisLabelsOff();
            Renderer.AddActor(robot2axes5);
            robot2axes6.SetTotalLength(200, 200, 200);
            robot2axes6.AxisLabelsOff();
            Renderer.AddActor(robot2axes6);

            Renderer.AddActor(drawPointCloud());
            Renderer.Render();

            worker.DoWork += worker_DoWork;
            worker.RunWorkerAsync();
        }
Exemplo n.º 5
0
        public static void ShowPolydata(string airwayPath, string lesionPath)
        {
            vtkAppendPolyData appendPolydata = new vtkAppendPolyData();

            if (File.Exists(airwayPath))
            {
                vtkXMLPolyDataReader reader = new vtkXMLPolyDataReader();
                reader.SetFileName(airwayPath);
                reader.Update();
                appendPolydata.AddInput(reader.GetOutput());
                reader.Dispose();
            }
            else
            {
                MessageBox.Show("airwayPath : " + airwayPath + "文件不存在!");
            }

            if (File.Exists(lesionPath))
            {
                vtkXMLPolyDataReader reader = new vtkXMLPolyDataReader();
                reader.SetFileName(lesionPath);
                reader.Update();
                appendPolydata.AddInput(reader.GetOutput());
                reader.Dispose();
            }
            else
            {
                MessageBox.Show("lesionPath : " + lesionPath + "文件不存在!");
            }

            vtkRenderWindow renWin = vtkRenderWindow.New();

            renWin.SetSize(600, 600);

            vtkRenderWindowInteractor iren = new vtkRenderWindowInteractor();

            renWin.SetInteractor(iren);

            vtkInteractorStyleTrackballCamera interactorStyle = new vtkInteractorStyleTrackballCamera();

            iren.SetInteractorStyle(interactorStyle);

            vtkRenderer renderer = vtkRenderer.New();

            renderer.GradientBackgroundOn();
            renderer.SetBackground(0, 0, 0);
            renderer.SetBackground2(0, 0, 1);
            renWin.AddRenderer(renderer);


            vtkPolyDataMapper mapper = vtkPolyDataMapper.New();

            mapper.ScalarVisibilityOff();
            mapper.SetInput(appendPolydata.GetOutput());
            vtkActor actor = new vtkActor();

            actor.SetMapper(mapper);

            renderer.AddActor(actor);

            renderer.Render();
            renderer.ResetCamera();
            renWin.Render();

            //Thread thread = new Thread(new ThreadStart(
            //                                       delegate
            //                                       {
            //                                           iren.Start();
            //                                       }));
            //thread.Start();
        }
Exemplo n.º 6
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();
        }