一次循环即可求得
void GetBoundsTuple(vtkSmartPointer<vtkPolyData> polydata, double Bounds[6][3])
{ //get the point with min_y
vtkIdType i, min_id = 0;
vtkIdType size = polydata->GetNumberOfPoints();
vtkPoints* points = polydata->GetPoints();
double* x;
x = points->GetPoint(0);
Bounds[0][0] = x[0];
Bounds[1][0] = x[0];
Bounds[2][1] = x[1];
Bounds[3][1] = x[1];
Bounds[4][2] = x[2];
Bounds[5][2] = x[2];
for (i = 1; i < size; i++)
{
x = points->GetPoint(i);
for (int j = 0; j < 3; ++j)
{
if (x[j] < Bounds[2 * j][j])
{
Bounds[2 * j][0] = x[0];
Bounds[2 * j][1] = x[1];
Bounds[2 * j][2] = x[2];
}
if (x[j] > Bounds[2 * j + 1][j]) {
Bounds[2 * j + 1][0] = x[0];
Bounds[2 * j + 1][1] = x[1];
Bounds[2 * j + 1][2] = x[2];
}
}
}
}