Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/125.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ VTK管道更新_C++_Vtk - Fatal编程技术网

C++ VTK管道更新

C++ VTK管道更新,c++,vtk,C++,Vtk,我在Linux上使用VTK-62,C++(GCC-4.7.2),我有以下VTK流水线设置(请忽略实现,细节和重点在管道上:锥->过滤器>映射器->演员): 场景渲染得很好 问题 我希望更新原始数据(即圆锥体)和要正确渲染的角色 如果我只有演员,如何访问原始圆锥数据?这是否保证演员也会得到更新?因为当我决定跟踪原始数据(通过指针:整个实现是使用vtkSmartPointers)然后更改它们的一些属性时,管道没有更新。它不应该自动更新吗 (当我更改演员(例如,他们的可见性)时,场景渲染良好) 请

我在Linux上使用VTK-62,C++(GCC-4.7.2),我有以下VTK流水线设置(请忽略实现,细节和重点在管道上:锥->过滤器>映射器->演员):

场景渲染得很好

问题

我希望更新原始数据(即圆锥体)和要正确渲染的角色

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

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

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

谢谢

[更新]


根据一篇类似帖子的回复,原始数据(
vtkConeSource
)被转换(当添加到
vtkAppendFilter
中时,转换为
vtkunsttructuredGrid
),因此即使我跟踪原始数据,更改它们也是无用的。

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

currAlgoObj->SetInputConnection( prevAlgoObj->GetOutputPort() )
而不是

currAlgoObj->SetInputData( prevAlgo->GetOutput() )
然后,我们可以使用指向actor对象的指针更新管道,方法是执行
actor->GetMapper()->update()
,如下面的示例所示

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

#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
int main(int,char*[])
{
//设置数据管道
auto cone=vtkSmartPointer::New();
锥体->设置高度(1.0);
auto-appf=vtkSmartPointer::New();
appf->SetInputConnection(cone->GetOutputPort());
auto coneMapper=vtkSmartPointer::New();
coneMapper->SetInputConnection(appf->GetOutputPort());
auto coneActor=vtkSmartPointer::New();
coneActor->SetMapper(coneMapper);
//我们需要更新管道,否则不会呈现任何内容
coneActor->GetMapper()->Update();
//连接到管道的渲染部分
自动渲染器=vtkSmartPointer::New();
渲染器->添加器(coneActor);
渲染器->背景(0.1,0.2,0.4);
自动渲染窗口=vtkSmartPointer::New();
渲染窗口->设置大小(200200);
renderWindow->AddRenderer(渲染器);
自动渲染器=
vtkSmartPointer::New();
RenderWindowWinterActor->SetRenderWindow(renderWindow);
renderWindowInteractor->Start();
//更改圆锥体特性
锥体->设置高度(10.0);
//使用actor对象更新管道
coneActor->GetMapper()->Update();
自动渲染器2=vtkSmartPointer::New();
Render2->AddActor(coneActor);
渲染器2->后退(0.1,0.2,0.4);
auto renderWindow2=vtkSmartPointer::New();
renderWindow2->设置大小(200200);
renderWindow2->AddRenderer(渲染器2);
自动渲染器2=
vtkSmartPointer::New();
RenderWindowWinterActor2->SetRenderWindow(renderWindow2);
renderWindowInteractor2->Start();
返回退出成功;
}

感谢您的详细回答和示例Amit。正如您提到的,问题确实是使用
SetInputData
而不是
SetInputConnection
(在我的例子中,
AddInputData
更改为
AddInputConnection
)Ok。我没有注意到AddInputData,但很高兴它起了作用。这很好地提醒了AddInputData和AddInputConnection之间的区别
currAlgoObj->SetInputData( prevAlgo->GetOutput() )
#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;
}