我们最近在使用深度剥离第二次渲染透明对象后遇到了VTK(v7)的奇怪行为。
第一个渲染效果很好,渲染透明度。关闭渲染窗口并创建另一个窗口(相同的设置)后,vtk显示一个空渲染,并且关闭该窗口后application / python崩溃。
问题事件名称:APPCRASH
应用程序名称:Test.exe
应用版本:0.0.0.0
申请时间戳:57be97a5
故障模块名称:nvoglv64.DLL
故障模块版本:9.18.13.2762
故障模块时间戳:526ed933
例外代码:c0000005
例外抵消:000000000062e180
我在下面添加了一个小例子,python(3.5)和C ++似乎表现得相似。
C ++:
#include "vtkCylinderSource.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkProperty.h"
#include "vtkCamera.h"
#include "vtkSmartPointer.h"
int main()
{
// This creates a polygonal cylinder model with eight circumferential facets
// (i.e, in practice an octagonal prism).
vtkSmartPointer<vtkCylinderSource> cylinder =
vtkSmartPointer<vtkCylinderSource>::New();
cylinder->SetResolution(8);
// The mapper is responsible for pushing the geometry into the graphics library.
// It may also do color mapping, if scalars or other attributes are defined.
vtkSmartPointer<vtkPolyDataMapper> cylinderMapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
cylinderMapper->SetInputConnection(cylinder->GetOutputPort());
// The actor is a grouping mechanism: besides the geometry (mapper), it
// also has a property, transformation matrix, and/or texture map.
// Here we set its color and rotate it around the X and Y axes.
vtkSmartPointer<vtkActor> cylinderActor =
vtkSmartPointer<vtkActor>::New();
cylinderActor->SetMapper(cylinderMapper);
cylinderActor->GetProperty()->SetColor(1.0000, 0.3882, 0.2784);
cylinderActor->RotateX(30.0);
cylinderActor->RotateY(-45.0);
cylinderActor->GetProperty()->SetOpacity(0.5);
// The renderer generates the image
// which is then displayed on the render window.
// It can be thought of as a scene to which the actor is added
vtkSmartPointer<vtkRenderer> renderer =
vtkSmartPointer<vtkRenderer>::New();
renderer->AddActor(cylinderActor);
renderer->SetBackground(0.1, 0.2, 0.4);
// Zoom in a little by accessing the camera and invoking its "Zoom" method.
renderer->ResetCamera();
renderer->GetActiveCamera()->Zoom(1.5);
// The render window is the actual GUI window
// that appears on the computer screen
vtkSmartPointer<vtkRenderWindow> renderWindow =
vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->SetSize(200, 200);
renderWindow->AddRenderer(renderer);
// 1. Use a render window with alpha bits (as initial value is 0 (false)):
renderWindow->SetAlphaBitPlanes(true);
// 2. Force to not pick a framebuffer with a multisample buffer
// (as initial value is 8):
renderWindow->SetMultiSamples(0);
// 3. Choose to use depth peeling (if supported) (initial value is 0 (false)):
renderer->SetUseDepthPeeling(true);
// 4. Set depth peeling parameters
// - Set the maximum number of rendering passes (initial value is 4):
renderer->SetMaximumNumberOfPeels(100);
// - Set the occlusion ratio (initial value is 0.0, exact image):
renderer->SetOcclusionRatio(0.1);
// The render window interactor captures mouse events
// and will perform appropriate camera or actor manipulation
// depending on the nature of the events.
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
renderWindowInteractor->SetRenderWindow(renderWindow);
// This starts the event loop and as a side effect causes an initial render.
renderWindowInteractor->Start();
// This creates a polygonal cylinder model with eight circumferential facets
// (i.e, in practice an octagonal prism).
vtkSmartPointer<vtkCylinderSource> cylinder2 =
vtkSmartPointer<vtkCylinderSource>::New();
cylinder2->SetResolution(8);
// The mapper is responsible for pushing the geometry into the graphics library.
// It may also do color mapping, if scalars or other attributes are defined.
vtkSmartPointer<vtkPolyDataMapper> cylinderMapper2 =
vtkSmartPointer<vtkPolyDataMapper>::New();
cylinderMapper2->SetInputConnection(cylinder2->GetOutputPort());
// The actor is a grouping mechanism: besides the geometry (mapper), it
// also has a property, transformation matrix, and/or texture map.
// Here we set its color and rotate it around the X and Y axes.
vtkSmartPointer<vtkActor> cylinderActor2 =
vtkSmartPointer<vtkActor>::New();
cylinderActor2->SetMapper(cylinderMapper2);
cylinderActor2->GetProperty()->SetColor(1.0000, 0.3882, 0.2784);
cylinderActor2->RotateX(30.0);
cylinderActor2->RotateY(-45.0);
cylinderActor2->GetProperty()->SetOpacity(0.5);
// The renderer generates the image
// which is then displayed on the render window.
// It can be thought of as a scene to which the actor is added
vtkSmartPointer<vtkRenderer> renderer2 =
vtkSmartPointer<vtkRenderer>::New();
renderer2->AddActor(cylinderActor);
renderer2->SetBackground(0.1, 0.2, 0.4);
// Zoom in a little by accessing the camera and invoking its "Zoom" method.
renderer2->ResetCamera();
renderer2->GetActiveCamera()->Zoom(1.5);
// The render window is the actual GUI window
// that appears on the computer screen
vtkSmartPointer<vtkRenderWindow> renderWindow2 =
vtkSmartPointer<vtkRenderWindow>::New();
renderWindow2->SetSize(200, 200);
renderWindow2->AddRenderer(renderer2);
// 1. Use a render window with alpha bits (as initial value is 0 (false)):
renderWindow2->SetAlphaBitPlanes(true);
// 2. Force to not pick a framebuffer with a multisample buffer
// (as initial value is 8):
renderWindow2->SetMultiSamples(0);
// 3. Choose to use depth peeling (if supported) (initial value is 0 (false)):
renderer2->SetUseDepthPeeling(true);
// 4. Set depth peeling parameters
// - Set the maximum number of rendering passes (initial value is 4):
renderer2->SetMaximumNumberOfPeels(100);
// - Set the occlusion ratio (initial value is 0.0, exact image):
renderer2->SetOcclusionRatio(0.1);
// The render window interactor captures mouse events
// and will perform appropriate camera or actor manipulation
// depending on the nature of the events.
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor2 =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
renderWindowInteractor2->SetRenderWindow(renderWindow2);
// This starts the event loop and as a side effect causes an initial render.
renderWindowInteractor2->Start();
return 0;
}
和python:
import vtk
###
# First Render
###
ren = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren)
ren.SetBackground([1., 1., 1.])
ren.SetUseDepthPeeling(1)
ren.SetOcclusionRatio(0.1)
ren.SetMaximumNumberOfPeels(100)
renWin.SetMultiSamples(0)
renWin.SetAlphaBitPlanes(1)
# create a renderwindowinteractor
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
# create source
source = vtk.vtkCylinderSource()
source.SetCenter(0, 0, 0)
source.SetRadius(5.0)
source.SetHeight(7.0)
source.SetResolution(100)
source.Update()
# mapper
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputData(source.GetOutput())
# actor
actor = vtk.vtkActor()
actor.SetMapper(mapper)
actor.GetProperty().SetOpacity(0.5)
# assign actor to the renderer
ren.AddActor(actor)
ren.ResetCamera()
# enable user interface interactor
iren.Initialize()
renWin.Render()
# print(ren)
iren.Start()
# close_window(iren)
# del renWin, ren
###
# Second Render
###
ren = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren)
ren.SetBackground([1., 1., 1.])
ren.SetUseDepthPeeling(1)
ren.SetOcclusionRatio(0.1)
ren.SetMaximumNumberOfPeels(100)
renWin.SetMultiSamples(0)
renWin.SetAlphaBitPlanes(1)
# create a renderwindowinteractor
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
# create source
source = vtk.vtkCylinderSource()
source.SetCenter(0, 0, 0)
source.SetRadius(5.0)
source.SetHeight(7.0)
source.SetResolution(100)
source.Update()
# mapper
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputData(source.GetOutput())
# actor
actor = vtk.vtkActor()
actor.SetMapper(mapper)
actor.GetProperty().SetOpacity(0.5)
# assign actor to the renderer
ren.AddActor(actor)
ren.ResetCamera()
# enable user interface interactor
iren.Initialize()
renWin.Render()
iren.Start()