1

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

And significantly, RenderWindowUISingleInheritance gives same result.


SOLUTION

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

Note the additions of:

#include <vtkProperty.h>

and

sphereActor->GetProperty()->SetFrontfaceCulling(true);
Bull
  • 748
  • 1
  • 11
  • 24

2 Answers2

3

Looks like Frontface culling is off by default. Try adding sphereActor->GetProperty()->FrontfaceCullingOn();

andrjas
  • 260
  • 1
  • 5
1

Another option that seems to solves this transparency problem is to use QVTKWidget2 instead of QVTKWidget.

  • 1
    This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post - you can always comment on your own posts, and once you have sufficient [reputation](http://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](http://stackoverflow.com/help/privileges/comment). – duggu Jan 07 '15 at 09:53
  • The change in FrontfaceCullingOn proposed as a solution is not a solution, but an optical effect. If you do the same with a cone, you will notice that the faces shown are located at the back of the object and not at the front. I have the same problem here and I could not find an other solution than using QVTKWidget2 instead of QVTKWidget. This is just to leave a potential solution for the other users. – jlabroquere Jan 07 '15 at 11:39
  • The issue also shows up with displaying points so changing to front face culling won't work there and I had to go with the QVTKWidget2 solution. Oddly enough I only saw the issue in Linux with integrated graphics. – mattking Jan 26 '15 at 17:25