赞
踩
ubuntu 20.04
VTK 8.2
下载源码
git clone --recursive https://gitlab.kitware.com/vtk/vtk.git
使用版本管理工具,切换版本到8.2
更改编译选项,这里使用cmake-gui进行配置
1、编译类型修改为Release
2、安装路径可以设置,也可以不设置,不设置默认安装到/usr/local目录下
3、勾选VTK_Group_Qt
4、勾选Module_vtkGUISupportQtOpenGL
生成成功后,执行编译
cmake ..
make -j4
make install
CMakeLists
- find_package(VTK 8.2 COMPONENTS vtkGUISupportQt
- vtkGUISupportQtOpenGL
- vtkRenderingGL2PSOpenGL2
- vtkRenderingVolumeOpenGL2 REQUIRED)
-
- complice_module(${PROJECT_NAME})
-
-
- target_link_libraries( ${PROJECT_NAME} PRIVATE ${VTK_LIBRARIES}
.h
- #include <QVTKOpenGLNativeWidget.h>
- #include <pcl/visualization/pcl_visualizer.h>
- #include <vtkGenericOpenGLRenderWindow.h>
- #include <vtkOrientationMarkerWidget.h>
-
- class CloudView : public QVTKOpenGLNativeWidget
- {
- Q_OBJECT
- public:
- explicit CloudView(QWidget* parent = nullptr);
- private:
- pcl::visualization::PCLVisualizer::Ptr m_viewer;
- vtkSmartPointer<vtkRenderer> m_render;
- vtkSmartPointer<vtkGenericOpenGLRenderWindow> m_renderwindow;
- vtkSmartPointer<vtkOrientationMarkerWidget> m_axes;
- };
.cpp
-
- #include "cloudview.h"
- #include <vtkAutoInit.h>
- VTK_MODULE_INIT(vtkRenderingOpenGL2)
- VTK_MODULE_INIT(vtkInteractionStyle)
- VTK_MODULE_INIT(vtkRenderingVolumeOpenGL2)
- VTK_MODULE_INIT(vtkRenderingFreeType)
-
- #include <vtkAxesActor.h>
-
- CloudView::CloudView(QWidget* parent)
- : QVTKOpenGLNativeWidget(parent),
- m_render(vtkSmartPointer<vtkRenderer>::New()),
- m_renderwindow(vtkSmartPointer<vtkGenericOpenGLRenderWindow>::New()),
- m_axes(vtkSmartPointer<vtkOrientationMarkerWidget>::New())
- {
- m_renderwindow->AddRenderer(m_render);
- m_viewer.reset(new pcl::visualization::PCLVisualizer(m_render, m_renderwindow, "viewer", false));
-
- m_viewer->setupInteractor(this->GetInteractor(), this->GetRenderWindow());
- this->SetRenderWindow(m_viewer->getRenderWindow());
- m_viewer->setBackgroundColor((double)150.0 / 255.0, (double)150.0 / 255.0, (double)150.0 / 255.0);
- vtkSmartPointer<vtkAxesActor> actor = vtkSmartPointer<vtkAxesActor>::New();
- m_axes->SetOutlineColor(0.9300, 0.5700, 0.1300);
- m_axes->SetOrientationMarker(actor);
- m_axes->SetInteractor(m_viewer->getRenderWindow()->GetInteractor());
- m_axes->SetViewport(0.9, 0, 1, 0.15);
- m_axes->SetEnabled(true);
- m_axes->InteractiveOn();
- m_axes->InteractiveOff();
- m_viewer->getRenderWindow()->Render();
- }
-
- void CloudView::addPointCloud(const Cloud::Ptr& cloud)
- {
- if (!m_viewer->contains(cloud->id().toStdString()))
- m_viewer->addPointCloud<PointXYZRGBN>(cloud, cloud->id().toStdString());
- else
- {
- pcl::visualization::PointCloudColorHandlerRGBField<PointXYZRGBN> rgb(cloud);
- m_viewer->updatePointCloud<PointXYZRGBN>(cloud, rgb, cloud->id().toStdString());
- }
- if (cloud->pointSize() != 1)
- m_viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE,
- cloud->pointSize(), cloud->id().toStdString());
- if (cloud->opacity() != 1)
- m_viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_OPACITY,
- cloud->opacity(), cloud->id().toStdString());
- m_viewer->getRenderWindow()->Render();
- }
ui上拖拽一个openGl控件, 然后提升为CloudView,然后就可以显示点云数据了
- PointCloud::Ptr pointPtr;
-
- ui->cloudview->addPointCloud( cloud);
- ui->cloudview->resetCamera();
显示效果
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。