# Bounding Box of a Point Set#

## Synopsis#

Get the bounding box of a PointSet

## Results#

Output::

bounds: [0, 0.1, 0, 0.1, 0, 0] center: [0.05, 0.05, 0] diagonal length squared: 0.02

## Code#

### Python#

```#!/usr/bin/env python

import itk
import platform

Dimension = 3
CoordType = itk.ctype("float")
# Windows requires unsigned long long for 64-bit identifiers
if platform.system() == "Windows":
ElementIdentifierType = itk.ctype("unsigned long long")
else:
ElementIdentifierType = itk.ctype("unsigned long")

PointSetType = itk.PointSet[CoordType, Dimension]

pointSet = PointSetType.New()
points = pointSet.GetPoints()

# Create points
p0 = itk.Point[CoordType, Dimension]()
p1 = itk.Point[CoordType, Dimension]()
p2 = itk.Point[CoordType, Dimension]()

p0[0] = 0.0
p0[1] = 0.0
p0[2] = 0.0
p1[0] = 0.1
p1[1] = 0.0
p1[2] = 0.0
p2[0] = 0.0
p2[1] = 0.1
p2[2] = 0.0

points.InsertElement(0, p0)
points.InsertElement(1, p1)
points.InsertElement(2, p2)

VecContType = itk.VectorContainer[
ElementIdentifierType, itk.Point[CoordType, Dimension]
]
BoundingBoxType = itk.BoundingBox[
ElementIdentifierType, Dimension, CoordType, VecContType
]

boundingBox = BoundingBoxType.New()
boundingBox.SetPoints(points)
boundingBox.ComputeBoundingBox()

print("bounds: " + str(boundingBox.GetBounds()))
print("center: " + str(boundingBox.GetCenter()))
print("diagonal length squared: " + str(boundingBox.GetDiagonalLength2()))
```

### C++#

```#include "itkPoint.h"
#include "itkPointSet.h"
#include "itkBoundingBox.h"

int
main()
{
using CoordType = float;
constexpr unsigned int Dimension = 3;

using PointSetType = itk::PointSet<CoordType, Dimension>;

using PointIdentifier = PointSetType::PointIdentifier;
using PointType = PointSetType::PointType;
using PointsContainerPointer = PointSetType::PointsContainerPointer;

auto                   pointSet = PointSetType::New();
PointsContainerPointer points = pointSet->GetPoints();

// Create points
PointType p0, p1, p2;

p0[0] = 0.0;
p0[1] = 0.0;
p0[2] = 0.0;
p1[0] = 0.1;
p1[1] = 0.0;
p1[2] = 0.0;
p2[0] = 0.0;
p2[1] = 0.1;
p2[2] = 0.0;

points->InsertElement(0, p0);
points->InsertElement(1, p1);
points->InsertElement(2, p2);

using BoundingBoxType = itk::BoundingBox<PointIdentifier, Dimension, CoordType>;

auto boundingBox = BoundingBoxType::New();
boundingBox->SetPoints(points);
boundingBox->ComputeBoundingBox();

std::cout << "bounds: " << boundingBox->GetBounds() << std::endl;
std::cout << "center: " << boundingBox->GetCenter() << std::endl;
std::cout << "diagonal length squared: " << boundingBox->GetDiagonalLength2() << std::endl;

return EXIT_SUCCESS;
}
```

## Classes demonstrated#

template<typename TPixelType, unsigned int VDimension = 3, typename TMeshTraits = DefaultStaticMeshTraits<TPixelType, VDimension, VDimension>>
class PointSet : public itk::DataObject

A superclass of the N-dimensional mesh structure; supports point (geometric coordinate and attribute) definition.

PointSet is a superclass of the N-dimensional mesh structure (itk::Mesh). It provides the portion of the mesh definition for geometric coordinates (and associated attribute or pixel information). The defined API provides operations on points but does not tie down the underlying implementation and storage. A “MeshTraits” structure is used to define the container and identifier to access the points. See DefaultStaticMeshTraits for the set of type definitions needed. All types that are defined in the “MeshTraits” structure will have duplicate type alias in the resulting mesh itself.

PointSet has two template parameters. The first is the pixel type, or the type of data stored (optionally) with the points. The second is the “MeshTraits” structure controlling type information characterizing the point set. Most users will be happy with the defaults, and will not have to worry about this second argument.

Template parameters for PointSet:

TPixelType = The type stored as data for the point.

TMeshTraits = Type information structure for the point set.

ITK Sphinx Examples:

Subclassed by itk::Mesh< TPixelType, VDimension, TMeshTraits >

template<typename TPointIdentifier = IdentifierType, unsigned int VPointDimension = 3, typename TCoordRep = float, typename TPointsContainer = VectorContainer<TPointIdentifier, Point<TCoordRep, VPointDimension>>>
class BoundingBox : public itk::Object

Represent and compute information about bounding boxes.

BoundingBox is a supporting class that represents, computes, and caches information about bounding boxes. The bounding box can be computed from several sources, including manual specification and computation from an input points container.

This is a templated, n-dimensional version of the bounding box. Bounding boxes are represented by n pairs of (min,max) pairs, where min is the minimum coordinate value and max is the maximum coordinate value for coordinate axis i.

Template parameters for BoundingBox:

Template Parameters
• `TPointIdentifier`: The type used to access a particular point (i.e., a point’s id)

• `TCoordRep`: Numerical type with which to represent each coordinate value.

• `VPointDimension`: Geometric dimension of space.