ActiViz.NET 5.8.0点云显示,重建,拾取

ActiViz.NET 5.8.0曲面重建

曲面重建

 vtkPolyData polydata = vtkPolyData.New();
                polydata.SetPoints(points);
                vtkDelaunay2D delaunay = vtkDelaunay2D.New();

                delaunay.SetInput(polydata);
                delaunay.Update();


                vtkDelaunay2D Delaunay_overall = vtkDelaunay2D.New();

                vtkPolyDataMapper triangulatedMapper = vtkPolyDataMapper.New();
                triangulatedMapper.SetInput(delaunay.GetOutput());
                if (depth_color)
                {
                    vtkElevationFilter ColoredGrid =
                        vtkElevationFilter.New();	//帮点上颜色,如不需要默认红色,注释即可
                    ColoredGrid.SetInputConnection(delaunay.GetOutputPort());
                    ColoredGrid.SetLowPoint(0, 0, MaxZ);
                    ColoredGrid.SetHighPoint(0, 0, MinZ);
                    triangulatedMapper.SetInputConnection(ColoredGrid.GetOutputPort());//将颜色映射上去
                }
                vtkActor triangulatedActor = vtkActor.New();
                triangulatedActor.SetMapper(triangulatedMapper);

                vtkActorCollection coll = renderer.GetActors();
                int count = coll.GetNumberOfItems();
                for (int i = 0; i <= count; i++)
                {
                    renderer.RemoveActor(renderer.GetActors().GetLastActor());
                }
                renderer.AddActor(triangulatedActor);
                renderer.SetBackground(.1, .2, .3);
                vtkInteractorStyleTrackballCamera style = vtkInteractorStyleTrackballCamera.New();	//移动摄像头
                
                renderer.ResetCamera();
                renderWindowInteractor.SetInteractorStyle(style); //交互模式  重要!
                renderWindowInteractor.Initialize();

点云显示

vtkPolyData polyData = vtkPolyData.New();
                polyData.SetPoints(points);
                //Color
                vtkVertexGlyphFilter glyphFilter = vtkVertexGlyphFilter.New();
                glyphFilter.SetInput(polyData);
                glyphFilter.Update();

                vtkElevationFilter ColoredGrid = vtkElevationFilter.New();	//帮点上颜色
                ColoredGrid.SetInputConnection(glyphFilter.GetOutputPort());
                ColoredGrid.SetLowPoint(0, 0, MaxZ);
                ColoredGrid.SetHighPoint(0, 0, MinZ);
                // Visualize
                vtkPolyDataMapper mapper = vtkPolyDataMapper.New();
                mapper.SetInputConnection(ColoredGrid.GetOutputPort());
                vtkActor triangulatedActor = triangulatedActor = vtkActor.New();
                triangulatedActor.SetMapper(mapper);

                vtkActorCollection coll = renderer.GetActors();
                int count = coll.GetNumberOfItems();
                for (int i = 0; i <= count; i++)
                {
                    renderer.RemoveActor(renderer.GetActors().GetLastActor());
                }
                renderer.AddActor(triangulatedActor);
                renderer.SetBackground(.1, .2, .3);
                vtkInteractorStyleTrackballCamera style = vtkInteractorStyleTrackballCamera.New();	//移动摄像头
                
                renderer.ResetCamera();
                renderWindowInteractor.SetInteractorStyle(style); //交互模式  重要!
                renderWindowInteractor.Initialize();

拾取

registeredPickUp();//注册拾取事件
void registeredPickUp()
        {
            this.Interactor = this.renderWindowControl1.RenderWindow.GetInteractor();
            this.InteractorHandler = new Kitware.VTK.vtkObject.vtkObjectEventHandler(Interactor_AnyEventHandler);
            this.Interactor.AnyEvt += this.InteractorHandler;
            vtkPointPicker pointPicker = vtkPointPicker.New();
            this.Interactor.SetPicker(pointPicker);  //设置点云拾取
            // 赋予我们自己的风格比内置风格更高的优先级
            //以便我们先看到事件:
            //
        }
        //3D显示控件的鼠标时间监听
        void Interactor_AnyEventHandler(Kitware.VTK.vtkObject sender, Kitware.VTK.vtkObjectEventArgs e)
        {
            if (pick_up)
            {
                int[] pos = this.Interactor.GetEventPosition();
                //鼠标左键事件
                if (Kitware.VTK.vtkCommand.GetStringFromEventId(e.EventId) == "LeftButtonPressEvent")
                {
                    this.Interactor.GetPicker().Pick(pos[0],   //注册
                        pos[1], 0,  // always zero.
                        zsy_3d_vtk.renderer);
                    double[] camera_zoom = zsy_3d_vtk.renderer.GetActiveCamera().GetPosition();
                    double[] picked = this.Interactor.GetPicker().GetPickPosition();
                    //Console.WriteLine(picked[0] + ":" + picked[1] + ":" + picked[2]);//拾取到的点数据
                    float[] point_3d = (float[])point;
                    labelX4.Text = "拾取点 : X : " + picked[0].ToString("F4") + "  Y : " + picked[1].ToString("F4") + "  Z : " + picked[2].ToString("F4") +
                        "   Z轴深度: " + (picked[2] - view_para[11]).ToString("F4") + " mm";
                    //对拾取点进行标记
                    vtkSphereSource sphereSource = vtkSphereSource.New();
                    sphereSource.Update();

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

                    vtkActor actor = vtkActor.New();
                    actor.SetMapper(mapper);
                    actor.SetPosition(picked[0], picked[1], picked[2]);
                    actor.SetScale(0.00471 * camera_zoom[2]);
                    actor.GetProperty().SetColor(1.0, 0.0, 0.0);
                    zsy_3d_vtk.renderer.AddActor(actor);
                }
                if (Kitware.VTK.vtkCommand.GetStringFromEventId(e.EventId) == "RightButtonPressEvent")
                {
                    vtkActorCollection coll = zsy_3d_vtk.renderer.GetActors();
                    if (coll.GetNumberOfItems() > 1)
                    {
                        zsy_3d_vtk.renderer.RemoveActor(coll.GetLastProp());
                    }
                }
            }
        }

你可能感兴趣的:(C#,点云,ActiViz,.net,拾取,重建)