如何得到两个结合的vtkPolyData曲面的边界

How to get the bounds of two combined vtkPolyData surfaces?

本文关键字:结合 vtkPolyData 曲面 边界 两个 何得      更新时间:2023-10-16

我的VTK程序在使用vtkCubeAxesActor的坐标系中绘制vtkPolyData对象surface1。我以以下方式定位立方体轴:

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内置?

如何添加新的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演员之前计算几个vtkPolyData的边界

 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