我的VTK程序使用surface1
在坐标系中绘制vtkPolyData对象vtkCubeAxesActor
。我按以下方式定位立方体轴:
cubeAxesActor->SetBounds( surface1->GetBounds() );
我最近添加了另一个vtkPolyData对象surface2
。有没有一种很好的方法来计算两个表面的“总”界限?
我知道我可以这样做:
float *bounds1 = surface1->GetBounds();
float *bounds2 = surface2->GetBounds();
float *bounds_total;
bounds_total[0] = min( bounds1[0], bounds2[0] );
bounds_total[1] = max( bounds1[1], bounds2[1] );
bounds_total[2] = min( bounds1[2], bounds2[2] );
// ...
但我想有更好的方法使用VTK内置插件?
答案 0 :(得分:3)
你是如何添加这个新vtkPolyData
的?
通过向vtkActor添加vtkPolyDataMapper(包含vtkPolyData),可以自动计算边界
vtkSphereSource *sphere = vtkSphereSource::New();
sphere->SetRadius(10.0);
sphere->Update();
vtkPolyDataMapper *map = vtkPolyDataMapper::New();
map->SetInputData(sphere->GetOutput());
vtkActor *aSphere = vtkActor::New();
aSphere->SetMapper(map);
std::cout << aSphere->GetBounds ()[0] << " "
<< aSphere->GetBounds ()[1] << std::endl; // print : -10 10
在使用vtkAppendPolyData
vtkSphereSource *sphere2 = vtkSphereSource::New();
sphere2->SetRadius(10.0);
sphere2->SetCenter (15, 15, 0);
sphere2->Update();
vtkAppendPolyData *app = vtkAppendPolyData::New();
app->AddInputData (sphere->GetOutput ());
app->AddInputData (sphere2->GetOutput ());
app->Update();
std::cout << app->GetOutput()->GetBounds ()[0] << " "
<< app->GetOutput()->GetBounds ()[1] << std::endl; // prints -10 25