[Solved] VTK 6.1 and Qt 5.3: 3D Objects in QVTKWidget with bad transparencies



  • Base: Debian 7.5 Wheezy 64 bits - Qt 5.3 installed from Online Installer; VTK 6.1 successfully compiled and installed manually with Qt support.

    Result: A 3D sphere is displayed in a 3D QVTK window. At first glance, It looks OK, but when sphere is rotated, several panels and parts of the sphere become transparent.

    Description:

    Tried the basic official example of VTK for Qt:

    In main.cpp:

    @#include <QApplication>

    #include <vtkAutoInit.h>
    VTK_MODULE_INIT(vtkRenderingOpenGL);
    VTK_MODULE_INIT(vtkInteractionStyle);

    #include <vtkSmartPointer.h>
    #include <vtkSphereSource.h>
    #include <vtkPolyDataMapper.h>
    #include <vtkActor.h>
    #include <vtkImageViewer.h>
    #include <vtkRenderWindowInteractor.h>
    #include <vtkInteractorStyleImage.h>
    #include <vtkRenderer.h>
    #include <vtkJPEGReader.h>
    #include <QVTKWidget.h>

    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);

    QVTKWidget widget;
      widget.resize(256,256);
    
      // Setup sphere
      vtkSmartPointer<vtkSphereSource> sphereSource =
          vtkSmartPointer<vtkSphereSource>::New();
      sphereSource->Update();
      vtkSmartPointer<vtkPolyDataMapper> sphereMapper =
          vtkSmartPointer<vtkPolyDataMapper>::New();
      sphereMapper->SetInputConnection(sphereSource->GetOutputPort());
      vtkSmartPointer<vtkActor> sphereActor =
          vtkSmartPointer<vtkActor>::New();
      sphereActor->SetMapper(sphereMapper);
    
      // Setup window
      vtkSmartPointer<vtkRenderWindow> renderWindow =
          vtkSmartPointer<vtkRenderWindow>::New();
    
      // Setup renderer
      vtkSmartPointer<vtkRenderer> renderer =
          vtkSmartPointer<vtkRenderer>::New();
      renderWindow->AddRenderer(renderer);
    
      renderer->AddActor(sphereActor);
      renderer->ResetCamera();
    
      widget.SetRenderWindow(renderWindow);
      widget.show();
    
    return a.exec(&#41;;
    

    }@

    And significantly, RenderWindowUISingleInheritance gives same result.



  • Thanks to StackOverflow, I got this question answered:

    http://stackoverflow.com/questions/24131430/vtk-6-1-and-qt-5-3-3d-objects-in-qvtkwidget-with-bad-transparencies/24148669#24148669

    The final code stands as follows:

    @#include <vtkAutoInit.h>
    VTK_MODULE_INIT(vtkRenderingOpenGL);
    VTK_MODULE_INIT(vtkInteractionStyle);

    #include <vtkSmartPointer.h>
    #include <vtkSphereSource.h>
    #include <vtkPolyDataMapper.h>
    #include <vtkActor.h>
    #include <vtkImageViewer.h>
    #include <vtkRenderWindowInteractor.h>
    #include <vtkInteractorStyleImage.h>
    #include <vtkRenderer.h>
    #include <vtkJPEGReader.h>
    #include <QVTKWidget.h>
    #include <vtkProperty.h>

    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);

    QVTKWidget widget;
      widget.resize(256,256);
    
      // Setup sphere
      vtkSmartPointer<vtkSphereSource> sphereSource =
          vtkSmartPointer<vtkSphereSource>::New();
      sphereSource->Update();
      vtkSmartPointer<vtkPolyDataMapper> sphereMapper =
          vtkSmartPointer<vtkPolyDataMapper>::New();
      sphereMapper->SetInputConnection(sphereSource->GetOutputPort());
      vtkSmartPointer<vtkActor> sphereActor =
          vtkSmartPointer<vtkActor>::New();
      sphereActor->GetProperty()->SetFrontfaceCulling(true);
      sphereActor->SetMapper(sphereMapper);
    
      // Setup window
      vtkSmartPointer<vtkRenderWindow> renderWindow =
          vtkSmartPointer<vtkRenderWindow>::New();
    
      // Setup renderer
      vtkSmartPointer<vtkRenderer> renderer =
          vtkSmartPointer<vtkRenderer>::New();
      renderWindow->AddRenderer(renderer);
    
      renderer->AddActor(sphereActor);
      renderer->ResetCamera();
    
      widget.SetRenderWindow(renderWindow);
      widget.show();
    
    return a.exec&#40;&#41;;
    

    }@

    Note the additions of:
    @
    #include <vtkProperty.h>@

    and
    @
    sphereActor->GetProperty()->SetFrontfaceCulling(true);@


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.