3

I'm trying to use QVTKOpenGLWidget in QTDesigner with vtkGenericOpenGlRenderWindow but I obtain a black window. When I use PCLVizualizer of PointCloud Library (PCL) with vtkGenericOpenGlRenderWindow, everything works fine. I'm trying to create a custom viewer the same way as PCL.

QMainPanel::QMainPanel( HWND hWnd ) :
    QWinWidget( hWnd ),
    ui(new Ui::QMainPanel)
{
    ui->setupUi(this);

    rendererTest = vtkSmartPointer<vtkRenderer>::New();
    rendererTest->GradientBackgroundOn();
    rendererTest->SetBackground(0.27,0.27,0.27);
    rendererTest->SetBackground2(0.44,0.44,0.44);
    windowTest = vtkSmartPointer<vtkGenericOpenGLRenderWindow>::New();
    windowTest->AddRenderer(rendererTest);
    interactorTest = vtkSmartPointer<vtkRenderWindowInteractor>::New();
    interactorTest->SetRenderWindow( windowTest );
    ui->openGLWidget->SetRenderWindow( windowTest ); //  QVTKOpenGLWidget *openGLWidget;
}

Thank you

Edit : Remove "Interactor" solved my problem.

genpfault
  • 51,148
  • 11
  • 85
  • 139
Sebastien247
  • 423
  • 5
  • 16
  • Up :) My problem is not solved :( – Sebastien247 Jun 15 '17 at 09:37
  • 1
    You should avoid editing your question to mark it as solved. Instead, write a complete answer to your original question, explaining how you solved your issue. Then, you can accept your own answer. This is perfectly valid regarding Stack Overflow rules, and makes easy for future readers to understand the problem and the solution – Antwane Jun 21 '17 at 10:15

1 Answers1

4

You will need to get the master version of PCL form https://github.com/PointCloudLibrary/pcl. This will give a PCLVisualizer with more constructors. So, you can use a custom widget like this:

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();
    }

gilbriatore
  • 658
  • 7
  • 12