MFC单文档中进行plc点云显示_scalaMFC单文档中进行plc点云显示_scala_02
 1     m_viewer.reset(new pcl::visualization::PCLVisualizer("viewer", false));//初始化pcl::viewer对象    
 2         m_viewer->addCoordinateSystem(); //设置对应的坐标系
 3         m_viewer->setBackgroundColor(0.0, 0.0, 0.0);//设置背景颜色
 4         m_viewer->initCameraParameters();//初始化相机的参数
 5         m_win = m_viewer->getRenderWindow();//将view中的渲染窗口的句柄传递给vtk window
 6         m_iren = vtkRenderWindowInteractor::New(); //初始化vtkwindow交互的对象 
 7         m_viewer->resetCamera();//使点云显示在屏幕中间,并绕中心操
 8 
 9 
10         CRect rect;
11         GetClientRect(&rect);//实时获取MFC窗口大小
12         m_win->SetSize(rect.right - rect.left, rect.bottom - rect.top);//根据当前窗口的大小设置vtk 窗口的大小
13         //m_viewer->addCoordinateSystem(1);
14         m_win->SetPosition(0, 0);
15         m_win->SetParentId(this->m_hWnd);//设置vtk窗口的句柄
16         //m_iren->SetRenderWindow(m_win);//将vtk交互对象与vtk window绑定 
17         //m_viewer->createInteractor();
18         //m_viewer->setCameraPosition(0, 20, 0, 0, 1, 0);
19 
20 
21 
22 
23 
24 
25         //1.创建vtkRenderer对象,用于渲染
26         vtkSmartPointer<vtkRenderer > aRenderer = vtkSmartPointer<vtkRenderer >::New();
27         //2.将vtkRender绑定到vtkRenderWindow
28         m_win->AddRenderer(aRenderer);
29         //3.将vtkRenderWindow绑定到vtkRenderWindowInteractor
30         m_iren->SetRenderWindow(m_win);
31         //4 vtkpolydata 读取 
32         vtkSmartPointer<vtkPolyDataReader> vtkReader = vtkSmartPointer<vtkPolyDataReader >::New();
33         vtkReader->SetFileName("G://001_project_code//LmsAnGangGanMeiPeng//test_data//pit_reconstruct.vtk");
34         //5.声明vtkPolyDataMapper
35         vtkSmartPointer<vtkPolyDataMapper > skinMapper = vtkSmartPointer<vtkPolyDataMapper >::New();
36         //6.将vtkpolydata绑定到vtkPolyDataMapper
37         skinMapper->SetInputConnection(vtkReader->GetOutputPort());
38         skinMapper->ScalarVisibilityOn();//打开颜色渐变色显示
39         //7.声明actor
40         vtkSmartPointer<vtkActor > skin = vtkSmartPointer<vtkActor >::New();
41         //8.将vtkPolyDataMapper绑定actor
42         skin->SetMapper(skinMapper);
43 
44         vtkSmartPointer<vtkCamera > aCamera = vtkSmartPointer<vtkCamera >::New();
45         //aCamera->SetViewUp(0, 0, -1);
46         //aCamera->SetPosition(0, 1, 0);
47         aCamera->SetViewUp(0, 0, -1); //视角设置
48         aCamera->SetPosition(3328, 5466, 20066);
49         aCamera->SetFocalPoint(3328, 5466, 10066);
50         //aCamera->SetFocalPoint(0, 0, 0);
51         aCamera->ComputeViewPlaneNormal();
52         //aCamera->Azimuth(30.0);
53         //aCamera->Elevation(30.0);
54         //aCamera->Dolly(1.5);
55 
56         //9.将actor绑定到Render
57         aRenderer->AddActor(skin);
58         aRenderer->SetActiveCamera(aCamera);
59         aRenderer->ResetCamera();
60         //aRenderer->SetBackground(.2, .3, .4);
61 
62 
63         aRenderer->SetBackground(.1, .3, .1);
64         aRenderer->ResetCameraClippingRange();
View Code