访问vtkActor构造对象并附加新数据

时间:2015-01-30 09:01:23

标签: c++ vtk

我正在使用VTK-6.1,我希望使用多个vtkActor创建一个vtkUnstructuredGrid。首先,我从网格中创建演员...

vtkSmartPointer<vtkActor> create_actor()
{
    vtkSmartPointer<vtkUnstructuredGrid> grid = create_grid_a();
    auto mapper = vtkSmartPointer<vtkDataSetMapper>::New();
    mapper->SetInputData(grid);
    auto actor = vtkSmartPointer<vtkActor>::New();
    actor->SetMapper(mapper);
    actor->GetProperty()->SetColor(0.5, 0.5, 0.5);
    actor->GetProperty()->SetEdgeVisibility(1);

    return actor;
}

然后我(尝试)使用另一个网格更新actor:

void update_actor(<vtkSmartPointer<vtkActor> actor)
{
    // get current grid
    vtkAlgorithm* algorithm = actor->GetMapper()->GetInputAlgorithm();
    actor_grid = dynamic_cast<vtkUnstructuredGrid>(algorithm);

    // create new grid
    vtkSmartPointer<vtkUnstructuredGrid> new_grid = create_grid_b();

    // combine grids
    auto append_filter = vtkSmartPointer<vtkAppendFilter>::New();
    append_filter->AddInputData(actor_grid);
    append_filter->AddInputData(new_grid);
    append_filter->Update();

    // update actor
    auto mapper = vtkSmartPointer<vtkDataSetMapper>::New();
    mapper->SetInputData(append_filter->GetOutput());
    actor->SetMapper(mapper);
}

问题是演员不包含网格组合。

备注:

create_grid_x()函数有点过于复杂而无法提供 肯定是有效的,因为第一个演员是正确创造的)

1中显示的

SafeDownCast也不起作用。

参考文献:

vtkActor reverse access

Appending data

1 个答案:

答案 0 :(得分:0)

有问题的部分是从vtkUnstructuredGrid检索vtkActor

// get current grid
vtkDataSet* actor_data = actor->getMapper()->GetInput();

...而不是使用vtkAlgorithm