QVTKOpenGLNativeWidget显示多个点云代码

3 篇文章 0 订阅
//可视化多个点云
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();
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值