1

基础: Debian 7.5 Wheezy 64 bits - 从在线安装程序安装的 Qt 5.3;VTK 6.1 在 Qt 支持下成功编译和手动安装。

结果: 3D 球体显示在 3D QVTK 窗口中。乍一看,它看起来不错,但是当球体旋转时,球体的几个面板和部分变得透明。

描述:

尝试了 VTK for Qt 的基本官方示例:

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

重要的是,RenderWindowUISingleInheritance 给出了相同的结果。


解决方案

最终代码如下:

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

注意添加:

#include <vtkProperty.h>

sphereActor->GetProperty()->SetFrontfaceCulling(true);
4

2 回答 2

3

看起来 Frontface 剔除默认情况下是关闭的。尝试添加 sphereActor->GetProperty()->FrontfaceCullingOn();

于 2014-06-10T18:47:19.753 回答
1

似乎可以解决这个透明度问题的另一个选项是使用 QVTKWidget2 而不是 QVTKWidget。

于 2015-01-07T09:18:19.793 回答