pcl-qt使用QVTKWidget 与PCLVisualizer 显示雷达点云
Posted kabe
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了pcl-qt使用QVTKWidget 与PCLVisualizer 显示雷达点云相关的知识,希望对你有一定的参考价值。
#ifndef PCLVIEWER_H #define PCLVIEWER_H #include "defines.h" #include <iostream> #include "radarserviceprovider.h" #include "radarserviceprovider32.h" #include "radarserviceproviderbase.h" // Qt #include <QWidget> #include <QObject> #include <QTimer> // Point Cloud Library //#include "pcl/visualization/pcl_visualizer.h" #include "pcl/pcl_visualizer.h" #include <vtkRenderWindow.h> #include<QMutex> #include<QDialog> #include "QVTKWidget.h" class vtkRenderer; class vtkRenderWindowInteractor; class vtkImageViewer2; #define MAX_READ_LENGTH 5000 namespace Ui { class PCLViewer; }; class PCLViewer : public QVTKWidget { Q_OBJECT public: EIGEN_MAKE_ALIGNED_OPERATOR_NEW explicit PCLViewer (QWidget *parent = 0,int width =200,int height =200); ~PCLViewer (); protected: boost::shared_ptr<pcl::visualization::PCLVisualizer> m_viewerOrg; PointCloudT::Ptr m_cloudOrg; private slots: void combineRadarData(); private: int m_height; int m_width; PointCloudT m_pOrgData; PointCloudT m_ptestData; bool m_frontArrivedFlag; //?????????????? bool m_backArrivedFlag; // ??????????????? int m_cubeSize; QStringList m_idList; QStringList m_idSituationList; pcl::visualization::Camera m_cam; bool m_viewFollow = true; QTimer *m_timer; QMutex m_lidarBackMutex; QMutex m_lidarfrontMutex; QMutex m_situationTargetsMutex; QMutex m_lidarTargetsMutex; }; #endif // PCLVIEWER_H
项目是两个雷达数据一起显示的。
#include "pclviewer.h" #include <vtkOutputWindow.h> #include <vtkPolyDataAlgorithm.h> #include "service.h" #include <QFile> #include<QFileDevice> #include<QXmlStreamReader> #include"config.h" #include "src/datacache.h" #include<QMessageBox> #include "service.h" #include<QMutexLocker> #include"math.h" #include "vtkRenderer.h" #include "vtkRenderWindowInteractor.h" #include "vtkConeSource.h" #include <vtkImageViewer2.h> #include <vtkPNGReader.h> #define MAX_POINT_NUM 1 PCLViewer::PCLViewer (QWidget *parent, int width, int height) : QVTKWidget(parent),m_frontArrivedFlag(false),m_backArrivedFlag(false), m_width(width),m_height(height) { qDebug()<<"width:height"<<width<<":"<<height; this->setFixedSize(width,height); m_cubeSize =0; vtkOutputWindow::SetGlobalWarningDisplay(0); m_cloudOrg.reset(new PointCloudT); m_cloudOrg->points.resize(MAX_POINT_NUM); m_viewerOrg.reset (new pcl::visualization::PCLVisualizer ("viewer", false)); this->SetRenderWindow (m_viewerOrg->getRenderWindow ()); m_viewerOrg->setupInteractor (this->GetInteractor (), this->GetRenderWindow ()); m_viewerOrg->resetCamera(); m_viewerOrg->addPointCloud (m_cloudOrg, "cloud"); m_viewerOrg->setCameraPosition(0, 0, 72, 0, 1, 0, 0); std::vector<pcl::visualization::Camera> cam; m_viewerOrg->getCameras(cam); m_cam =cam[0]; } void PCLViewer::combineRadarData() { if(m_viewFollow) { float offsetx = 视觉x坐标 ; float offsety = 视觉y坐标; m_cam.pos[0] = offsetx; m_cam.pos[1]= offsety; m_cam.pos[2]=72; m_cam.focal[0] = offsetx; m_cam.focal[1]= offsety; m_cam.focal[2]=0; m_cam.view[0]=0; m_cam.view[1]=1; m_cam.view[2]=0; m_viewerOrg->setCameraParameters(m_cam); } if(m_threadList.count()>0) // m_threadList接收线程列表 { PointCloudT::Ptr data =m_threadList.at(0)->readData(); PointCloudT combine = *data; for(int i =1;i<m_threadList.count();i++ ) { PointCloudT::Ptr backData = m_threadList.at(i)->readData() ; combine += *backData; } PointCloudT::Ptr pCombine = combine.makeShared(); m_viewerOrg->updatePointCloud(pCombine, "cloud"); this->update(); } for(auto p: m_threadList) { p->setDataUsed(); } }
以上是关于pcl-qt使用QVTKWidget 与PCLVisualizer 显示雷达点云的主要内容,如果未能解决你的问题,请参考以下文章