Qt5 PCL 点云展示 对 QVTKOpenGLNativeWidget 封装

myqvtkopenglnativewidget.h

#ifndef MYQVTKOPENGLNATIVEWIDGET_H
#define MYQVTKOPENGLNATIVEWIDGET_H
#include 
#include 

// Point Cloud Library
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 


// Boost
#include 
class MyQVTKOpenGLNativeWidget : public QVTKOpenGLNativeWidget
{
    Q_OBJECT
public:
    explicit MyQVTKOpenGLNativeWidget(QWidget *parent = nullptr);
    boost::shared_ptr getViewer();

signals:

protected:
    /** @brief The PCL visualizer object */
    boost::shared_ptr viewer_;

};

#endif // MYQVTKOPENGLNATIVEWIDGET_H

myqvtkopenglnativewidget.cpp

#include "myqvtkopenglnativewidget.h"
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

#include "vtkAutoInit.h"
VTK_MODULE_INIT(vtkRenderingOpenGL2);
VTK_MODULE_INIT(vtkInteractionStyle);
VTK_MODULE_INIT(vtkRenderingVolumeOpenGL2);
VTK_MODULE_INIT(vtkRenderingFreeType);


#include 
#include 
#include 
#include 

MyQVTKOpenGLNativeWidget::MyQVTKOpenGLNativeWidget(QWidget *parent)
    : QVTKOpenGLNativeWidget{parent}
{
    auto renderer2 = vtkSmartPointer::New();
    auto renderWindow2 = vtkSmartPointer::New();
    renderWindow2->AddRenderer(renderer2);
    viewer_.reset(new pcl::visualization::PCLVisualizer(renderer2, renderWindow2, "viewer", false));
    viewer_->setBackgroundColor(255, 255, 255);
    viewer_->setShowFPS(false);
    setRenderWindow(viewer_->getRenderWindow());
    viewer_->setupInteractor(this->interactor(), this->renderWindow());




    vtkAxesActor* axesActor =vtkAxesActor::New();
    axesActor->SetPosition(0, 0, 0);		//坐标系的原点位置
    axesActor->SetTotalLength(1, 1, 1);	//轴的长度
    axesActor->SetShaftType(0);	 //旋转轴的类型:圆柱体、线或者自定义(用于显示)
    axesActor->SetAxisLabels(1);  //是否显示标签
    axesActor->SetCylinderRadius(0.02);
    vtkOrientationMarkerWidget* widgetAxes =vtkOrientationMarkerWidget::New();
    widgetAxes->SetOrientationMarker(axesActor);
    widgetAxes->SetInteractor(this->interactor());
    widgetAxes->SetEnabled(1);
    widgetAxes->SetInteractive(0);
    this->update();
}
boost::shared_ptr MyQVTKOpenGLNativeWidget::getViewer(){
    return viewer_;
}

如果要在UI设计师界面中使用,先拖入openglWidget ,然后将这部件提升为MyQVTKOpenGLNativeWidget

你可能感兴趣的:(PCL,点云,QT5,PCL)