//可视化多个点云
void PointsProcess::MultVisualize(pcl::PointCloud<pcl::PointXYZ>::Ptr cloud1,pcl::PointCloud<pcl::PointXYZ>::Ptr cloud2,QVTKOpenGLNativeWidget *vtkWidget){
vtkSmartPointer<vtkPoints> result_points = vtkSmartPointer<vtkPoints>::New();
vtkSmartPointer<vtkPoints> source_points = vtkSmartPointer<vtkPoints>::New();
vtkNew<vtkNamedColors> colors;
for(int i = 0;i < cloud1->points.size();i++)
{
result_points->InsertNextPoint(cloud1->points[i].x,cloud1->points[i].y,cloud1->points[i].z);
}
for(int i = 0;i < cloud2->points.size();i++)
{
source_points->InsertNextPoint(cloud2->points[i].x,cloud2->points[i].y,cloud2->points[i].z);
}
std::cout << "点云配准数量cloud_result: " << cloud1->points.size() << std::endl;
QString str=QString::number(cloud1->points.size());
pui->textEdit->append("点云配准数量cloud_result: "+str);
std::cout << "背景点云数量cloud: " << cloud2->points.size() << std::endl;
str=QString::number(cloud2->points.size());
pui->textEdit->append("背景点云数量cloud: "+str);
//设置数据1
vtkSmartPointer<vtkPolyData> m_data1 = vtkSmartPointer<vtkPolyData>::New();
m_data1->SetPoints(result_points);
vtkSmartPointer<vtkVertexGlyphFilter> m_vertexGlyphFilter1 = vtkSmartPointer<vtkVertexGlyphFilter>::New();
m_vertexGlyphFilter1->SetInputData(m_data1);
m_vertexGlyphFilter1->Update();
//设置数据2
vtkSmartPointer<vtkPolyData> m_data2 = vtkSmartPointer<vtkPolyData>::New();
m_data2->SetPoints(source_points);
vtkSmartPointer<vtkVertexGlyphFilter> m_vertexGlyphFilter2 = vtkSmartPointer<vtkVertexGlyphFilter>::New();
m_vertexGlyphFilter2->SetInputData(m_data2);
m_vertexGlyphFilter2->Update();
//数据类型转换物体1
vtkSmartPointer<vtkPolyDataMapper> m_dataMapper1 = vtkSmartPointer<vtkPolyDataMapper>::New();
m_dataMapper1->SetInputConnection(m_vertexGlyphFilter1->GetOutputPort());
m_dataMapper1->Update();
//数据类型转换物体2
vtkSmartPointer<vtkPolyDataMapper> m_dataMapper2 = vtkSmartPointer<vtkPolyDataMapper>::New();
m_dataMapper2->SetInputConnection(m_vertexGlyphFilter2->GetOutputPort());
m_dataMapper2->Update();
//演员1
vtkSmartPointer<vtkActor> m_actor1 = vtkSmartPointer<vtkActor>::New();
//演员1
vtkSmartPointer<vtkActor> m_actor2 = vtkSmartPointer<vtkActor>::New();
//演员1手持物体1
m_actor1->SetMapper(m_dataMapper1);
m_actor1->GetProperty()->SetColor(colors->GetColor3d("Red").GetData());
m_actor1->GetProperty()->SetAmbient(0.5);
m_actor1->GetProperty()->SetPointSize(2);
//演员2手持物体2
m_actor2->SetMapper(m_dataMapper2);
m_actor2->GetProperty()->SetColor(colors->GetColor3d("Green").GetData());
m_actor2->GetProperty()->SetAmbient(0.5);
m_actor2->GetProperty()->SetPointSize(2);
//舞台
vtkSmartPointer<vtkRenderer> m_renderer = vtkRenderer::New();
// m_renderer->RemoveAllViewProps();
//舞台添加演员
m_renderer->AddActor(m_actor2);
m_renderer->AddActor(m_actor1);
//窗口
vtkSmartPointer<vtkGenericOpenGLRenderWindow> m_renderWindow = vtkSmartPointer<vtkGenericOpenGLRenderWindow>::New();
//窗口添加舞台
m_renderWindow->AddRenderer(m_renderer);
m_renderWindow->SetInteractor(vtkWidget->GetInteractor());
//放入qtwidget
vtkWidget->SetRenderWindow(m_renderWindow);
vtkWidget->update();
m_renderWindow->Render();
}
QVTKOpenGLNativeWidget显示多个点云代码
最新推荐文章于 2024-10-02 16:02:30 发布