[vtkusers] Rendering XYZRGBA segfaults randomly while XYZ doesn't in qvtkwidget subclass

Oon-Ee Ng ngoonee.talk at gmail.com
Wed Jan 14 02:23:17 EST 2015


I've subclassed QVtkWidget for use in my QT app displaying the sensor
data from an ASUS Xtion Pro Live. I include in this email the full
code I'm using. I have two overloaded showPointCloud functions, the
one which handles PointXYZ works fine but the one which handles
PointXYZRGBA segfaults most of the time.

The rare times which it 'works' (no recompile, just keep running the
same binary), I get visual (but not depth) artifacts. I attach two
screenshots showing the artifacts [1] and the actual scene [2].
Artifacts are always at the 'top' of the image as shown in the screen
shots.

This seems to me to indicate some form of memory corruption to me. How
can I fix this and/or further investigate?

[1] - https://www.dropbox.com/s/0s9kle77zohy9b6/WithArtifact.png?dl=0
[2] - https://www.dropbox.com/s/bjvtoqlsg3ilt6g/NoArtifact.png?dl=0

#include <QVTKWidget.h>
#include <pcl/visualization/pcl_visualizer.h>
#include <pcl/visualization/point_cloud_color_handlers.h>
#include <vtkRenderWindow.h>

class VTKPointCloudWidget : public QVTKWidget
{
    Q_OBJECT
public:
    explicit VTKPointCloudWidget(QWidget *parent = 0);
    ~VTKPointCloudWidget();
    void showPointCloud(pcl::PointCloud<pcl::PointXYZ>::Ptr pc);
    void showPointCloud(pcl::PointCloud<pcl::PointXYZRGBA>::Ptr pc);

private:
    pcl::visualization::PCLVisualizer vis;
};

VTKPointCloudWidget::VTKPointCloudWidget(QWidget *parent) :
    QVTKWidget(parent),
    vis("visor", false)
{
}

VTKPointCloudWidget::~VTKPointCloudWidget()
{
}

void VTKPointCloudWidget::showPointCloud(pcl::PointCloud<pcl::PointXYZ>::Ptr
pc) {
    if (!vis.updatePointCloud<pcl::PointXYZ>(pc)) {
        vis.setBackgroundColor(0,0,0);
        vis.addPointCloud<pcl::PointXYZ>(pc);
        vis.initCameraParameters();
        vtkSmartPointer<vtkRenderWindow> renderwindow = vis.getRenderWindow();
        this->SetRenderWindow(renderwindow);
        this->show();
    }
    else {
        this->update();
    }
}

void VTKPointCloudWidget::showPointCloud(pcl::PointCloud<pcl::PointXYZRGBA>::Ptr
pc) {
    pcl::visualization::PointCloudColorHandlerRGBField<pcl::PointXYZRGBA>
rgb(pc);
    if (!vis.updatePointCloud<pcl::PointXYZRGBA>(pc, rgb)) {
        vis.setBackgroundColor(0,0,0);
        vis.addPointCloud<pcl::PointXYZRGBA>(pc, rgb);
        vis.initCameraParameters();
        vtkSmartPointer<vtkRenderWindow> renderwindow = vis.getRenderWindow();
        this->SetRenderWindow(renderwindow);
        this->show();
    }
    else {
        this->update();
    }
}


More information about the vtkusers mailing list