VTK 6.1和Qt 5.3: 3D对象在QVTKWidget与不良透明度



Base: Debian 7.5 Wheezy 64位- Qt 5.3从Online Installer安装;在Qt支持下,vtk6.1已成功编译并手动安装。

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

描述:

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

在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给出了相同的结果。


<

解决方案/strong>

最终代码如下:

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

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

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

相关内容

  • 没有找到相关文章

最新更新