QVTKOpenGLWidget + Qt + PCLVisualizer

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

QVTKOpenGLWidget + Qt + PCLVisualizer

Geucimar
This post was updated on .
Hi guys, after the constructor added in PCL master
(https://github.com/PointCloudLibrary/pcl/pull/2004#issuecomment-341698328),
I've wrote a custom widget to use QVTKOpenGLWidget + Qt + PCLVisualizer. I'm
sharing code here, have fun:

*VideoQVTKOpenGLWidget.h*

#ifndef VIDEOQVKTOPENGLWIDGET_H    
#define VIDEOQVKTOPENGLWIDGET_H  
#include  <QWidget>    
#include  <QVTKOpenGLWidget.h>  
#include  <pcl/visualization/pcl_visualizer.h>    

using namespace pcl::visualization;    

class VideoQVTKOpenGLWidget : public QVTKOpenGLWidget  
{      
   public:        
       explicit VideoQVTKOpenGLWidget(QWidget *parent = 0);      
       void populateCloud(pcl::PointCloud <pcl::PointXYZRGBA>::Ptr cloud);    

   private:        
      boost::shared_ptr <PCLVisualizer> _viewer;vtkSmartPointer <vtkGenericOpenGLRenderWindow> _renderWindow;    
};  
#endif // VIDEOQVKTOPENGLWIDGET_H


*VideoQVTKOpenGLWidget.cpp*

#include "VideoQVTKOpenGLWidget.h"    
#include  <vtkPointPicker.h>    
#include  <vtkGenericOpenGLRenderWindow.h>  

VideoQVTKOpenGLWidget::VideoQVTKOpenGLWidget(QWidget *parent)      :
QVTKOpenGLWidget(parent)    
{      
    auto renderer = vtkSmartPointer <vtkRenderer>::New();      
   _renderWindow = vtkSmartPointer <vtkGenericOpenGLRenderWindow>::New();    
   _renderWindow->AddRenderer(renderer);      
   _viewer.reset(new PCLVisualizer(renderer, _renderWindow, "viewer", false));
   this->SetRenderWindow(_viewer->getRenderWindow());
   this->update();    
}    

void VideoQVTKOpenGLWidget::populateCloud(pcl::PointCloud <pcl::PointXYZRGBA>::Ptr cloud)    
{    
   if(!_viewer->updatePointCloud(cloud, "cloud"))
   {      
      _viewer->addPointCloud(cloud, "cloud");      
   }    
   _renderWindow->Render();    
}