gpt4 book ai didi

c++ - VTK 6.1 和 Qt 5.3 : 3D Objects in QVTKWidget with bad transparencies

转载 作者:行者123 更新时间:2023-11-30 01:52:43 25 4
gpt4 key购买 nike

基础 Debian 7.5 Wheezy 64 位 - 从在线安装程序安装的 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);

最佳答案

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

关于c++ - VTK 6.1 和 Qt 5.3 : 3D Objects in QVTKWidget with bad transparencies,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24131430/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com