gpt4 book ai didi

c++ - VTK管道更新

转载 作者:行者123 更新时间:2023-12-03 12:49:06 33 4
gpt4 key购买 nike

我在 Linux 上使用 VTK-6.2、C++ (gcc-4.7.2),并且我有以下 VTK 管道设置(请忽略实现、细节并关注管道:cone->filter->mapper->actor) :

// cone/initialize
vtkConeSource cone;

// add cone(s) to filter
vtkAppendFilter filter;
filter.AddInputData(cone.GetOutput());

// add filter to mapper
vtkDataSetMapper mapper;
mapper.SetInputData(filter->GetOutput());

// actor
vtkActor actor;
actor.SetMapper(mapper);

场景渲染良好。

问题

我想更新原始数据(即锥体)和 Actor 以正确渲染。

  • 如果我只有 Actor ,如何访问原始圆锥体数据?这是否保证 Actor 也会更新?因为当我决定跟踪原始数据(通过指针:整个实现是使用 vtkSmartPointer )然后更改它们的一些属性时,管道没有更新。不是应该自动更新吗?

  • (当我更改 Actor (例如他们的可见性)时,场景渲染良好)

请原谅,我不是 VTK 专家,而且管道很困惑。也许一种方法是简化我的管道。

谢谢

[更新]

根据this回答类似的帖子,原始数据(vtkConeSource)被转换(在vtkAppendFilter中添加时转换为vtkUnstructedGrid),所以即使我跟踪原始数据,改变它们是没有用的。

最佳答案

VTK 管道是需求驱动的管道。即使管道的元素之一被修改,它们也不会自动更新。我们需要显式调用Update()最后的功能vtkAlgorithm (或其派生类对象)的管道来更新整个管道。设置管道的正确方法是当我们连接两个派生自 vtkAlgorithm 的对象时。类型是使用

currAlgoObj->SetInputConnection( prevAlgoObj->GetOutputPort() )

而不是

currAlgoObj->SetInputData( prevAlgo->GetOutput() )

然后我们可以通过执行 actor->GetMapper()->Update() 使用指向 actor 对象的指针来更新管道。如下面的示例所示。

在此示例中,我们将从锥体源创建一个锥体,并将其传递给 vtkAppendFilter然后更改原始锥体源的高度并将其渲染在另一个窗口中以查看更新后的锥体。 (您必须关闭第一个渲染窗 Eloquent 能在第二个窗口中看到更新后的圆锥体。)

#include <vtkConeSource.h>
#include <vtkDataSetMapper.h>
#include <vtkActor.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkSmartPointer.h>
#include <vtkAppendFilter.h>

int main(int, char *[])
{
// Set up the data pipeline
auto cone = vtkSmartPointer<vtkConeSource>::New();
cone->SetHeight( 1.0 );

auto appf = vtkSmartPointer<vtkAppendFilter>::New();
appf->SetInputConnection( cone->GetOutputPort() );

auto coneMapper = vtkSmartPointer<vtkDataSetMapper>::New();
coneMapper->SetInputConnection( appf->GetOutputPort() );

auto coneActor = vtkSmartPointer<vtkActor>::New();
coneActor->SetMapper( coneMapper );

// We need to update the pipeline otherwise nothing will be rendered
coneActor->GetMapper()->Update();

// Connect to the rendering portion of the pipeline
auto renderer = vtkSmartPointer<vtkRenderer>::New();
renderer->AddActor( coneActor );
renderer->SetBackground( 0.1, 0.2, 0.4 );

auto renderWindow = vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->SetSize( 200, 200 );
renderWindow->AddRenderer(renderer);

auto renderWindowInteractor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
renderWindowInteractor->SetRenderWindow(renderWindow);
renderWindowInteractor->Start();

// Change cone property
cone->SetHeight( 10.0 );

//Update the pipeline using the actor object
coneActor->GetMapper()->Update();

auto renderer2 = vtkSmartPointer<vtkRenderer>::New();
renderer2->AddActor( coneActor );
renderer2->SetBackground( 0.1, 0.2, 0.4 );

auto renderWindow2 = vtkSmartPointer<vtkRenderWindow>::New();
renderWindow2->SetSize( 200, 200 );
renderWindow2->AddRenderer(renderer2);

auto renderWindowInteractor2 =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
renderWindowInteractor2->SetRenderWindow(renderWindow2);

renderWindowInteractor2->Start();

return EXIT_SUCCESS;
}

关于c++ - VTK管道更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47773443/

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