Pergunta

I am rather new in Qt programming, and I am trying to visualize a point cloud from PCL inside a Qt Widget. I have tried to use this approach: https://stackoverflow.com/a/11939703/2339680, or (similar): http://www.pcl-users.org/QT-PCLVisualizer-mostly-working-td3285187.html.

I get the compile error: "invalid static_cast from type ‘vtkObjectBase* const’ to type ‘vtkRenderWindow*’" when trying to set the render window in my QVTKWidget.

For reference, I have included code from the second source below, which reproduces the error.

#include <pcl/sample_consensus/sac_model_plane.h>
#include <pcl/visualization/cloud_viewer.h>
#include <pcl/common/common.h>
#include <QVTKWidget.h>

int main(int argc, char** argv)
{
  QApplication app(argc, argv);

  QVTKWidget widget;
  widget.resize(512, 256);

  //
  {
    pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_xyz (new pcl::PointCloud<pcl::PointXYZ>);
    {

      for (float y = -0.5f; y <= 0.5f; y += 0.01f)
      {
        for (float z = -0.5f; z <= 0.5f; z += 0.01f)
        {
          pcl::PointXYZ point;
          point.x = 2.0f - y;
          point.y = y;
          point.z = z;
          cloud_xyz->points.push_back (point);
        }
      }
      cloud_xyz->width = cloud_xyz->points.size ();
      cloud_xyz->height = 1;

    }

    // this creates and displays a window named "test_viz"
    // upon calling PCLVisualizerInteractor interactor_->Initialize ();
    // how to disable that?
    pcl::visualization::PCLVisualizer pviz ("test_viz");

    pviz.addPointCloud<pcl::PointXYZ>(cloud_xyz);
    pviz.setBackgroundColor(0, 0, 0.1);

    vtkSmartPointer<vtkRenderWindow> renderWindow = pviz.getRenderWindow();
    widget.SetRenderWindow(renderWindow);
  }

  widget.show();
  app.exec();

  return EXIT_SUCCESS;
}

The error is occures at the line

widget.SetRenderWindow(renderWindow);

I am using Qt 4.8.0 and PCL 1.7.0. Does anyone know if it is possible to get around this?

Foi útil?

Solução

With inspiration from https://stackoverflow.com/a/5808864/2339680 i guess that the problem is, that vtkRenderWindow is only available to the compiler as a forward declaration. If you include

#include "vtkRenderWindow.h"

in the beginning, everything should compile.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top