Question

My VTK program draws a vtkPolyData object surface1 in a coordinate system using a vtkCubeAxesActor. I position the cube axes in the following way:

cubeAxesActor->SetBounds( surface1->GetBounds() );

I recently added another vtkPolyData object, surface2. Is there a good way to calculate the "total" bounds for the two surfaces?

I know that I could do something like this:

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] );
// ...

But I suppose there is a better way using VTK built-ins?

Was it helpful?

Solution

How did you add this new vtkPolyData ? By adding a vtkPolyDataMapper (which contains a vtkPolyData) to an vtkActor, the bounds are aumatically calculated

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

You can compute bounds of several vtkPolyData before using an actor with 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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top