# Using vtkOBBTree::ComputeOBB

**URL:** https://discourse.vtk.org/t/using-vtkobbtree-computeobb/5558
**Category:** Support
**Created:** [April 16, 2021, 3:02pm UTC](https://discourse.vtk.org/t/using-vtkobbtree-computeobb/5558 "2021-04-16T15:02:51Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![spyridon97](https://discourse.vtk.org/user_avatar/discourse.vtk.org/spyridon97/32/7069_2.png) [@spyridon97](https://discourse.vtk.org/u/spyridon97)
#### Post date: [April 16, 2021, 3:02pm UTC](https://discourse.vtk.org/t/using-vtkobbtree-computeobb/5558/1 "2021-04-16T15:02:52Z")

</div>

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

```auto
    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?

---

<div class="post-metadata">

### Author: ![will.schroeder](https://discourse.vtk.org/user_avatar/discourse.vtk.org/will.schroeder/32/233_2.png) [@will.schroeder](https://discourse.vtk.org/u/will.schroeder)
#### Post date: [April 21, 2021, 2:51pm UTC](https://discourse.vtk.org/t/using-vtkobbtree-computeobb/5558/2 "2021-04-21T14:51:20Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![spyridon97](https://discourse.vtk.org/user_avatar/discourse.vtk.org/spyridon97/32/7069_2.png) [@spyridon97](https://discourse.vtk.org/u/spyridon97)
#### Post date: [April 21, 2021, 3:40pm UTC](https://discourse.vtk.org/t/using-vtkobbtree-computeobb/5558/3 "2021-04-21T15:40:38Z")

</div>

Thanks a lot!
