VTK管道更新

问题描述 投票:0回答:1

我在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。

  • 如果我只有演员,我如何访问原始的锥形数据?这是否保证演员也会更新?因为当我决定跟踪原始数据(通过指针:整个实现是使用vtkSmartPointers)然后更改它们的一些属性时,管道没有更新。它不应该自动更新吗?
  • (当我改变演员(例如他们的能见度)时,场景渲染得很好)

原谅我,我不是VTK专家,管道很混乱。也许一种方法是简化我的管道。

谢谢

[更新]

根据this对类似帖子的回答,原始数据(vtkConeSource)被转换(在vtkUnstructuredGrid中添加到vtkAppendFilter)所以即使我跟踪原始数据,更改它们也是无用的。

c++ vtk
1个回答
0
投票

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

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

代替

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

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

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

#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;
}
© www.soinside.com 2019 - 2024. All rights reserved.