Hi,
Just a quick question regarding oriented bounding boxes. I am struggling to interpret the meaning of size
variable in ComputeOBB
function. Below I am attaching a minimal example which creates a sphere, an ellipsoid and a rotated ellipsoid. When I look at the values of min
, mid
and max
then I can clearly see the lengths of my bounding boxes. For size
the docs say:
sorted list of relative “sizes” of axes for comparison purposes.
which sounds a bit mysterious to me, but the word “relative” is clearly key to my lack of understanding. Could anyone elaborate please? Thanks.
Example:
#include <vtkNew.h>
#include <vtkOBBTree.h>
#include <vtkPoints.h>
#include <vtkSphereSource.h>
#include <vtkParametricEllipsoid.h>
#include <vtkTransform.h>
#include <vtkParametricFunctionSource.h>
#include <vtkTransformPolyDataFilter.h>
class OBBFunctor {
private:
vtkNew<vtkOBBTree> OBB;
public:
OBBFunctor() {};
void operator() (vtkSmartPointer<vtkPolyData> data) const
{
double corner[3] = {0.0, 0.0 ,0.0};
double max[3] = {0.0, 0.0 ,0.0};
double mid[3] = {0.0, 0.0, 0.0};
double min[3] = {0.0, 0.0, 0.0};
double size[3] = {0.0, 0.0, 0.0};
OBB->ComputeOBB(data, corner, max, mid, min, size);
std::cout << "Origin:\t" << corner[0] << " " << corner[1] << " " << corner[2] << std::endl
<< "Max:\t" << max[0] << " " << max[1] << " " << max[2] << std::endl
<< "Mid:\t" << mid[0] << " " << mid[1] << " " << mid[2] << std::endl
<< "Min:\t" << min[0] << " " << min[1] << " " << min[2] << std::endl
<< "Size:\t" << size[0] << " " << size[1] << " " << size[2] << std::endl;
}
};
int main ( int argc, char *argv[] )
{
vtkNew<vtkSphereSource> sphere;
sphere->SetCenter(0.0, 0.0, 0.0);
sphere->SetRadius(1.0);
sphere->SetThetaResolution(128);
sphere->SetPhiResolution(128);
sphere->Update();
vtkNew<vtkParametricEllipsoid> ellipsoid;
ellipsoid->SetXRadius(1.0);
ellipsoid->SetYRadius(2.0);
ellipsoid->SetZRadius(3.0);
vtkNew<vtkParametricFunctionSource> parametricFunctionSource;
parametricFunctionSource->SetUResolution(64);
parametricFunctionSource->SetVResolution(64);
parametricFunctionSource->SetWResolution(64);
parametricFunctionSource->SetScalarModeToNone();
parametricFunctionSource->GenerateTextureCoordinatesOff();
parametricFunctionSource->SetParametricFunction(ellipsoid);
parametricFunctionSource->Update();
vtkNew<vtkTransform> transform;
transform->RotateX(30.0);
vtkNew<vtkTransformPolyDataFilter> transformed_ellipsoid;
transformed_ellipsoid->SetTransform(transform);
transformed_ellipsoid->SetInputConnection(parametricFunctionSource->GetOutputPort());
transformed_ellipsoid->Update();
OBBFunctor print_obb;
std::cout << "A sphere." << std::endl;
print_obb(sphere->GetOutput());
std::cout << "The original ellipsoid." << std::endl;
print_obb(parametricFunctionSource->GetOutput());
std::cout << "The transformed ellipsoid!" << std::endl;
print_obb(transformed_ellipsoid->GetOutput());
return EXIT_SUCCESS;
}
Output:
A sphere.
Origin: 0.978708 -1.02027 -1
Max: 2.89524e-14 3.00906e-14 2
Mid: -1.99898 0.0415672 2.83122e-14
Min: 0.0415672 1.99898 -3.0677e-14
Size: 0.333273 0.333179 0.333179
The original ellipsoid.
Origin: -0.998446 -1.99876 3
Max: 2.83922e-17 7.14057e-12 -6
Mid: -9.39699e-17 3.99751 4.75742e-12
Min: 1.99814 4.69704e-17 9.45524e-18
Size: 2.50416 1.22338 0.414305
The transformed ellipsoid!
Origin: -0.998446 -3.23097 1.5987
Max: 9.20086e-17 3 -5.19615
Mid: -2.14944e-17 3.46195 1.99876
Min: 1.99814 -6.016e-18 3.19078e-17
Size: 2.50416 1.22338 0.414305