【问题标题】:VTK pipeline updateVTK 管道更新
【发布时间】:2017-12-12 13:07:11
【问题描述】:

我在 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);

场景渲染良好。

问题

我想更新原始数据(即锥体)和要正确渲染的演员。

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

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

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

谢谢

[更新]

根据this 对类似帖子的回答,原始数据(vtkConeSource)被转换(在vtkAppendFilter 中添加时转换为vtkUnstructuredGrid),因此即使我跟踪原始数据,也会更改它们没用。

【问题讨论】:

    标签: c++ vtk


    【解决方案1】:

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

    【讨论】:

    • 感谢您的详尽回答和示例 Amit。正如您所提到的,问题确实是使用SetInputData 而不是SetInputConnection(在我的情况下AddInputData 更改为AddInputConnection
    • 好的。我没有注意到AddInputData,但很高兴它起作用了。
    • 这很好地提醒了AddInputData和AddInputConnection之间的区别
    猜你喜欢
    • 2017-12-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-03
    • 2021-10-14
    • 2019-08-28
    • 2021-10-12
    • 2022-09-27
    相关资源
    最近更新 更多