Using vtkOBBTree::ComputeOBB

Hello everyone,

I have a point set, and I want to calculate its minimum bounding box. I need it so I can create an oriented image which I will populate afterward. For the image, I use the ITK library.

So far this is my code

    itk::Image<unsigned char, 3>::Pointer
    createEmptyMinimumImageFromPolyData(const vtkSmartPointer<vtkPolyData>& polyData, double spacing, const size_t* padding)
    {
        constexpr unsigned int Dimension = 3;
        using PixelType = unsigned char;
        using ImageType = itk::Image<PixelType, Dimension>;

        ImageType::Pointer image = ImageType::New();

        double boxCorner[3];
        double boxSize[3];
        ImageType::DirectionType direction;
        vtkOBBTree::ComputeOBB(polyData->GetPoints(), boxCorner, direction[0], direction[1], direction[2], boxSize);

        std::cout << "\n" << boxCorner[0] << " " << boxCorner[1] << " " << boxCorner[2] << std::endl;
        std::cout << direction;
        std::cout << boxSize[0] << " " << boxSize[1] << " " << boxSize[2] << std::endl;
    }

The output of this code is the following:

Box corner: 159.687 168.385 265.907
max: 23.0858 14.1807 -156.695
mid: -10.8491 97.6434 7.23822
min: 67.1796 6.68576 10.5026
size: 1316.78 385.623 220.006

I understand what the corner is, and I presume that min, mid, max all together constitute the direction matrix that I will need for the image. What I am lacking is the extent of the image a.k.a the size(?). The size that I get as output does not make sense to me, because if I try to get the bounds of the AABB of the same polyData the result is:

X range: 162.154 to 234.889 (delta: 72.735)
Y range: 174.194 to 271.959 (delta: 97.765)
Z range: 115.696 to 275.091 (delta: 159.395)

So my question is, is the size that I am getting correct? If it’s not, how am I supposed to extract that?

I believe size contains the eigenvalues of the OBB extraction process. You’d have to dig into the Jacobi extraction process to understand the details of the eigenvector / eigenvalue scaling to the OBB axes etc.

Thanks a lot!