[vtkusers] Inconsistent Rendering

meakcey meakcey at gmail.com
Thu Jan 17 16:23:16 EST 2019


I am rendering point cloud on QVTKOpenGLWidget in Qt with the code below

void SceneWidget::renderCloud(pcl::PointCloud<pcl::PointNormal>::Ptr
p3cloud){

    vRenderer->Clear();
    vWindow = vtkSmartPointer<vtkGenericOpenGLRenderWindow>::New();
    SetRenderWindow(vWindow);
    vRenderer = vtkSmartPointer<vtkRenderer>::New();
    vRenderer->SetBackground(0.1, 0.1, 0.1);
    GetRenderWindow()->AddRenderer(vRenderer);

    vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
    vtkSmartPointer<vtkUnsignedCharArray> colors =
vtkSmartPointer<vtkUnsignedCharArray>::New();
    colors->SetNumberOfComponents(3);
    colors->SetName ("Colors");

    // Set point normals
    vtkSmartPointer<vtkDoubleArray> pointNormalsArray =
vtkSmartPointer<vtkDoubleArray>::New();
    pointNormalsArray->SetNumberOfComponents(3); //3d normals (ie x,y,z)
    pointNormalsArray->SetName("Normals");

    unsigned char tmpColor[3] = {200, 200, 100};
    for(unsigned int i=0; i<p3cloud->size(); i++){
        points->InsertNextPoint(p3cloud->points[i].x, p3cloud->points[i].y,
p3cloud->points[i].z);
        double pn[3] = {p3cloud->points[i].normal_x,
p3cloud->points[i].normal_y, p3cloud->points[i].normal_z};
        //pointNormalsArray->InsertNextTypedTuple(pn);
        colors->InsertNextTypedTuple(tmpColor);
    }

    vtkSmartPointer<vtkPolyData> pointsPoly =
vtkSmartPointer<vtkPolyData>::New();
    pointsPoly->SetPoints(points);

    vtkSmartPointer<vtkVertexGlyphFilter> vertexFilter =
vtkSmartPointer<vtkVertexGlyphFilter>::New();
    vertexFilter->SetInputData(pointsPoly);
    vertexFilter->Update();

    vPointCloud = vtkSmartPointer<vtkPolyData>::New();
    vPointCloud->ShallowCopy(vertexFilter->GetOutput());
    vPointCloud->GetPointData()->SetScalars(colors);

    sceneMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
    sceneMapper->SetInputData(vPointCloud);

    sceneActor = vtkSmartPointer<vtkActor>::New();
    sceneActor->SetMapper(sceneMapper);
    sceneActor->GetProperty()->SetPointSize(6);
    sceneActor->GetProperty()->EdgeVisibilityOff();

    vRenderer->AddActor(sceneActor);
    vRenderer->ResetCamera(sceneActor->GetBounds());

    glEnable( GL_POINT_SMOOTH );
    glEnable( GL_BLEND );
    glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
    //glPointSize( 5.0f );

    //renderVTK();
    this->GetRenderWindow()->Render();
}

I am always getting different result on the screen like attached in the
pictures

<http://vtk.1045678.n5.nabble.com/file/t342564/visualbad.jpg> 
<http://vtk.1045678.n5.nabble.com/file/t342564/visualgood.jpg> 

Something like it does not render normals. And also, when it is visualized
bad, getting rotations very slow. I did not understand root cause of it and
so how to solve that.



--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html


More information about the vtkusers mailing list