ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
cloudViewer::t::geometry::OrientedBoundingBox Class Reference

A bounding box oriented along an arbitrary frame of reference. More...

#include <BoundingVolume.h>

Inheritance diagram for cloudViewer::t::geometry::OrientedBoundingBox:
[legend]
Collaboration diagram for cloudViewer::t::geometry::OrientedBoundingBox:
[legend]

Public Member Functions

 OrientedBoundingBox (const core::Device &device=core::Device("CPU:0"))
 Construct an empty OrientedBoundingBox on the provided device. More...
 
 OrientedBoundingBox (const core::Tensor &center, const core::Tensor &rotation, const core::Tensor &extent)
 Construct an OrientedBoundingBox from center, rotation and extent. More...
 
virtual ~OrientedBoundingBox () override
 
core::Device GetDevice () const override
 Returns the device attribute of this OrientedBoundingBox. More...
 
core::Dtype GetDtype () const
 Returns the data type attribute of this OrientedBoundingBox. More...
 
OrientedBoundingBox To (const core::Device &device, bool copy=false) const
 
OrientedBoundingBox Clone () const
 Returns copy of the OrientedBoundingBox on the same device. More...
 
OrientedBoundingBox & Clear () override
 Clear all elements in the geometry. More...
 
bool IsEmpty () const override
 Returns true iff the geometry is empty. More...
 
void SetCenter (const core::Tensor &center)
 Set the center of the box. If the data type of the given tensor differs from the data type of the box, an exception will be thrown. More...
 
void SetRotation (const core::Tensor &rotation)
 Set the rotation matrix of the box. If the data type of the given tensor differs from the data type of the box, an exception will be thrown. More...
 
void SetExtent (const core::Tensor &extent)
 Set the extent of the box. If the data type of the given tensor differs from the data type of the box, an exception will be thrown. More...
 
void SetColor (const core::Tensor &color)
 Set the color of the box. More...
 
core::Tensor GetMinBound () const
 
core::Tensor GetMaxBound () const
 
core::Tensor GetColor () const
 
core::Tensor GetCenter () const
 
core::Tensor GetRotation () const
 
core::Tensor GetExtent () const
 
OrientedBoundingBox & Translate (const core::Tensor &translation, bool relative=true)
 Translate the oriented box by the given translation. If relative is true, the translation is added to the center of the box. If false, the center will be assigned to the translation. More...
 
OrientedBoundingBox & Rotate (const core::Tensor &rotation, const utility::optional< core::Tensor > &center=utility::nullopt)
 Rotate the oriented box by the given rotation matrix. If the rotation matrix is not orthogonal, the rotation will no be applied. The rotation center will be the box center if it is not specified. More...
 
OrientedBoundingBox & Transform (const core::Tensor &transformation)
 Transform the oriented box by the given transformation matrix. More...
 
OrientedBoundingBox & Scale (double scale, const utility::optional< core::Tensor > &center=utility::nullopt)
 Scale the axis-aligned box. If $mi$ is the min_bound and $ma$ is the max_bound of the axis aligned bounding box, and $s$ and $c$ are the provided scaling factor and center respectively, then the new min_bound and max_bound are given by $mi = c + s (mi - c)$ and $ma = c + s (ma - c)$. The scaling center will be the box center if it is not specified. More...
 
double Volume () const
 Returns the volume of the bounding box. More...
 
core::Tensor GetBoxPoints () const
 Returns the eight points that define the bounding box. More...
 
core::Tensor GetPointIndicesWithinBoundingBox (const core::Tensor &points) const
 Indices to points that are within the bounding box. More...
 
std::string ToString () const
 Text description. More...
 
cloudViewer::geometry::OrientedBoundingBox ToLegacy () const
 Convert to a legacy CloudViewer oriented box. More...
 
AxisAlignedBoundingBox GetAxisAlignedBoundingBox () const
 Convert to an axis-aligned box. More...
 
- Public Member Functions inherited from cloudViewer::t::geometry::Geometry
virtual ~Geometry ()
 
GeometryType GetGeometryType () const
 Returns one of registered geometry types. More...
 
int Dimension () const
 Returns whether the geometry is 2D or 3D. More...
 
std::string GetName () const
 
void SetName (const std::string &name)
 
- Public Member Functions inherited from cloudViewer::core::IsDevice
 IsDevice ()=default
 
virtual ~IsDevice ()=default
 
bool IsCPU () const
 
bool IsCUDA () const
 
bool IsSYCL () const
 
- Public Member Functions inherited from cloudViewer::t::geometry::DrawableGeometry
 DrawableGeometry ()
 
 ~DrawableGeometry ()
 
bool HasMaterial () const
 Check if a material has been applied to this Geometry with SetMaterial. More...
 
visualization::rendering::Material & GetMaterial ()
 Get material associated with this Geometry. More...
 
const visualization::rendering::Material & GetMaterial () const
 Get const reference to material associated with this Geometry. More...
 
void SetMaterial (const visualization::rendering::Material &material)
 Set the material properties associate with this Geometry. More...
 

Static Public Member Functions

static OrientedBoundingBox CreateFromAxisAlignedBoundingBox (const AxisAlignedBoundingBox &aabb)
 
static OrientedBoundingBox FromLegacy (const cloudViewer::geometry::OrientedBoundingBox &box, const core::Dtype &dtype=core::Float32, const core::Device &device=core::Device("CPU:0"))
 
static OrientedBoundingBox CreateFromPoints (const core::Tensor &points, bool robust=false, MethodOBBCreate method=MethodOBBCreate::MINIMAL_APPROX)
 

Protected Attributes

core::Device device_ = core::Device("CPU:0")
 
core::Dtype dtype_ = core::Float32
 
core::Tensor center_
 
core::Tensor rotation_
 
core::Tensor extent_
 
core::Tensor color_
 

Additional Inherited Members

- Public Types inherited from cloudViewer::t::geometry::Geometry
enum  GeometryType {
  GeometryType::Unspecified = 0, GeometryType::PointCloud = 1, GeometryType::VoxelGrid = 2, GeometryType::Octree = 3,
  GeometryType::LineSet = 4, GeometryType::MeshBase = 5, GeometryType::TriangleMesh = 6, GeometryType::HalfEdgeTriangleMesh = 7,
  GeometryType::Image = 8, GeometryType::RGBDImage = 9, GeometryType::TetraMesh = 10, GeometryType::OrientedBoundingBox = 11,
  GeometryType::AxisAlignedBoundingBox = 12
}
 Specifies possible geometry types. More...
 
- Protected Member Functions inherited from cloudViewer::t::geometry::Geometry
 Geometry (GeometryType type, int dimension)
 Parameterized Constructor. More...
 

Detailed Description

A bounding box oriented along an arbitrary frame of reference.

Constructor & Destructor Documentation

◆ OrientedBoundingBox() [1/2]

cloudViewer::t::geometry::OrientedBoundingBox::OrientedBoundingBox ( const core::Device &  device = core::Device("CPU:0"))

Construct an empty OrientedBoundingBox on the provided device.

Referenced by CreateFromPoints().

◆ OrientedBoundingBox() [2/2]

cloudViewer::t::geometry::OrientedBoundingBox::OrientedBoundingBox ( const core::Tensor &  center,
const core::Tensor &  rotation,
const core::Tensor &  extent 
)

Construct an OrientedBoundingBox from center, rotation and extent.

The OrientedBoundingBox will be created on the device of the given tensors, which must be on the same device and have the same data type.

Parameters
centerCenter of the bounding box. Tensor of shape {3,}, and type float32 or float64.
rotationRotation matrix of the bounding box. Tensor of shape {3, 3}, and type float32 or float64.
extentExtent of the bounding box. Tensor of shape {3,}, and type float32 or float64.

References AssertTensorDevice, AssertTensorDtype, AssertTensorDtypes, AssertTensorShape, cloudViewer::core::Float32, cloudViewer::core::Float64, cloudViewer::core::Tensor::GetDevice(), cloudViewer::core::Tensor::GetDtype(), and rotation.

◆ ~OrientedBoundingBox()

virtual cloudViewer::t::geometry::OrientedBoundingBox::~OrientedBoundingBox ( )
inlineoverridevirtual

Member Function Documentation

◆ Clear()

OrientedBoundingBox & cloudViewer::t::geometry::OrientedBoundingBox::Clear ( )
overridevirtual

◆ Clone()

OrientedBoundingBox cloudViewer::t::geometry::OrientedBoundingBox::Clone ( ) const
inline

Returns copy of the OrientedBoundingBox on the same device.

References GetDevice(), and To().

◆ CreateFromAxisAlignedBoundingBox()

◆ CreateFromPoints()

OrientedBoundingBox cloudViewer::t::geometry::OrientedBoundingBox::CreateFromPoints ( const core::Tensor &  points,
bool  robust = false,
MethodOBBCreate  method = MethodOBBCreate::MINIMAL_APPROX 
)
static

Creates an oriented bounding box with various algorithms.

Parameters
pointsA list of points with data type of float32 or float64 (N x 3 tensor, where N must be larger than 3).
robustIf set to true uses a more robust method which works in degenerate cases but introduces noise to the points coordinates.
methodThis is one of PCA, MINIMAL_APPROX, MINIMAL_JYLANKI in the cloudViewer::t::geometry::MethodOBBCreate namespace.
  • PCA computes an oriented bounding box using the principal component analysis of the convex hull.
  • MINIMAL_APPROX computes an oriented bounding box using a fast approximation algorithm. The algorithm makes use of the fact that at least one edge of the convex hull must be collinear with an edge of the minimum bounding box: for each triangle in the convex hull, calculate the minimal axis aligned box in the frame of that triangle. at the end, return the box with the smallest volume.
  • MINIMAL_JYLANKI computes an oriented bounding box using a more accurate but slower algorithm. This algorithm is inspired by the article "An Exact Algorithm for Finding Minimum Oriented Bounding Boxes" written by Jukka Jylänki. The original implementation can be found at the following address: https://github.com/juj/MathGeoLib/blob/55053da5e3e55a83043af7324944407b174c3724/src/Geometry/OBB.cpp#L987
Returns
OrientedBoundingBox with same data type and device as input points.

References AssertTensorDtypes, AssertTensorShape, cloudViewer::t::geometry::kernel::minimum_obb::ComputeMinimumOBBApprox(), cloudViewer::t::geometry::kernel::minimum_obb::ComputeMinimumOBBJylanki(), ecvOrientedBBox::CreateFromPoints(), cloudViewer::core::Float32, cloudViewer::core::Float64, FromLegacy(), LogError, cloudViewer::t::geometry::MINIMAL_APPROX, cloudViewer::t::geometry::MINIMAL_JYLANKI, cloudViewer::utility::nullopt, OrientedBoundingBox(), cloudViewer::t::geometry::PCA, points, and cloudViewer::core::eigen_converter::TensorToEigenVector3dVector().

Referenced by cloudViewer::t::geometry::LineSet::GetOrientedBoundingBox(), cloudViewer::t::geometry::PointCloud::GetOrientedBoundingBox(), and cloudViewer::t::geometry::TriangleMesh::GetOrientedBoundingBox().

◆ FromLegacy()

OrientedBoundingBox cloudViewer::t::geometry::OrientedBoundingBox::FromLegacy ( const cloudViewer::geometry::OrientedBoundingBox &  box,
const core::Dtype &  dtype = core::Float32,
const core::Device &  device = core::Device("CPU:0") 
)
static

◆ GetAxisAlignedBoundingBox()

AxisAlignedBoundingBox cloudViewer::t::geometry::OrientedBoundingBox::GetAxisAlignedBoundingBox ( ) const

◆ GetBoxPoints()

core::Tensor cloudViewer::t::geometry::OrientedBoundingBox::GetBoxPoints ( ) const

Returns the eight points that define the bounding box.

The Return tensor has shape {8, 3} and data type same as the box.

///      ------- x
///     /|
///    / |
///   /  | z
///  y
///      0 ------------------- 1
///       /|                /|
///      / |               / |
///     /  |              /  |
///    /   |             /   |
/// 2 ------------------- 7  |
///   |    |____________|____| 6
///   |   /3            |   /
///   |  /              |  /
///   | /               | /
///   |/                |/
/// 5 ------------------- 4
/// 

References cloudViewer::core::Tensor::Add(), cloudViewer::t::geometry::AxisAlignedBoundingBox::GetBoxPoints(), GetCenter(), GetExtent(), GetRotation(), and cloudViewer::core::Tensor::Matmul().

Referenced by GetAxisAlignedBoundingBox(), GetMaxBound(), and GetMinBound().

◆ GetCenter()

core::Tensor cloudViewer::t::geometry::OrientedBoundingBox::GetCenter ( ) const
inline

◆ GetColor()

core::Tensor cloudViewer::t::geometry::OrientedBoundingBox::GetColor ( ) const
inline

References color_.

Referenced by ToLegacy().

◆ GetDevice()

core::Device cloudViewer::t::geometry::OrientedBoundingBox::GetDevice ( ) const
inlineoverridevirtual

◆ GetDtype()

core::Dtype cloudViewer::t::geometry::OrientedBoundingBox::GetDtype ( ) const
inline

Returns the data type attribute of this OrientedBoundingBox.

References dtype_.

Referenced by Clear(), Rotate(), Scale(), SetCenter(), SetColor(), SetExtent(), SetRotation(), ToString(), Transform(), and Translate().

◆ GetExtent()

core::Tensor cloudViewer::t::geometry::OrientedBoundingBox::GetExtent ( ) const
inline

◆ GetMaxBound()

core::Tensor cloudViewer::t::geometry::OrientedBoundingBox::GetMaxBound ( ) const

◆ GetMinBound()

core::Tensor cloudViewer::t::geometry::OrientedBoundingBox::GetMinBound ( ) const

◆ GetPointIndicesWithinBoundingBox()

core::Tensor cloudViewer::t::geometry::OrientedBoundingBox::GetPointIndicesWithinBoundingBox ( const core::Tensor &  points) const

◆ GetRotation()

core::Tensor cloudViewer::t::geometry::OrientedBoundingBox::GetRotation ( ) const
inline

◆ IsEmpty()

bool cloudViewer::t::geometry::OrientedBoundingBox::IsEmpty ( ) const
inlineoverridevirtual

Returns true iff the geometry is empty.

Implements cloudViewer::t::geometry::Geometry.

References Volume().

Referenced by cloudViewer::t::geometry::PointCloud::Crop().

◆ Rotate()

OrientedBoundingBox & cloudViewer::t::geometry::OrientedBoundingBox::Rotate ( const core::Tensor &  rotation,
const utility::optional< core::Tensor > &  center = utility::nullopt 
)

Rotate the oriented box by the given rotation matrix. If the rotation matrix is not orthogonal, the rotation will no be applied. The rotation center will be the box center if it is not specified.

Parameters
rotationRotation matrix of shape {3, 3}, type float32 or float64, device same as the box.
centerCenter of the rotation, default is null, which means use center of the box as rotation center.

References AssertTensorDevice, AssertTensorDtypes, AssertTensorShape, center_, e, cloudViewer::core::Tensor::Flatten(), cloudViewer::core::Float32, cloudViewer::core::Float64, GetDevice(), GetDtype(), cloudViewer::utility::optional< T >::has_value(), LogWarning, cloudViewer::core::Tensor::Matmul(), rotation, rotation_, and cloudViewer::utility::optional< T >::value().

Referenced by cloudViewer::t::geometry::kernel::minimum_obb::ComputeMinimumOBBApprox(), and Transform().

◆ Scale()

OrientedBoundingBox & cloudViewer::t::geometry::OrientedBoundingBox::Scale ( double  scale,
const utility::optional< core::Tensor > &  center = utility::nullopt 
)

Scale the axis-aligned box. If $mi$ is the min_bound and $ma$ is the max_bound of the axis aligned bounding box, and $s$ and $c$ are the provided scaling factor and center respectively, then the new min_bound and max_bound are given by $mi = c + s (mi - c)$ and $ma = c + s (ma - c)$. The scaling center will be the box center if it is not specified.

Parameters
scaleThe scale parameter.
centerCenter used for the scaling operation. Tensor of shape {3,}, type float32 or float64, device same as the box.

References AssertTensorDevice, AssertTensorDtypes, AssertTensorShape, center_, extent_, cloudViewer::core::Float32, cloudViewer::core::Float64, GetDevice(), GetDtype(), cloudViewer::utility::optional< T >::has_value(), cloudViewer::core::Tensor::To(), and cloudViewer::utility::optional< T >::value().

◆ SetCenter()

void cloudViewer::t::geometry::OrientedBoundingBox::SetCenter ( const core::Tensor &  center)

Set the center of the box. If the data type of the given tensor differs from the data type of the box, an exception will be thrown.

Parameters
centerTensor with {3,} shape, and type float32 or float64.

References AssertTensorDevice, AssertTensorDtypes, AssertTensorShape, center_, cloudViewer::core::Float32, cloudViewer::core::Float64, GetDevice(), GetDtype(), and cloudViewer::core::Tensor::To().

Referenced by To().

◆ SetColor()

void cloudViewer::t::geometry::OrientedBoundingBox::SetColor ( const core::Tensor &  color)

Set the color of the box.

Parameters
colorTensor with {3,} shape, and type float32 or float64, with values in range [0.0, 1.0].

References AssertTensorDevice, AssertTensorShape, color, color_, cloudViewer::core::Float64, GetDevice(), GetDtype(), and LogError.

Referenced by FromLegacy(), and To().

◆ SetExtent()

void cloudViewer::t::geometry::OrientedBoundingBox::SetExtent ( const core::Tensor &  extent)

Set the extent of the box. If the data type of the given tensor differs from the data type of the box, an exception will be thrown.

Parameters
extentTensor with {3,} shape, and type float32 or float64.

References AssertTensorDevice, AssertTensorDtypes, AssertTensorShape, extent_, cloudViewer::core::Float32, cloudViewer::core::Float64, GetDevice(), GetDtype(), cloudViewer::core::Tensor::Item(), LogError, cloudViewer::core::Tensor::Min(), and cloudViewer::core::Tensor::To().

Referenced by To().

◆ SetRotation()

void cloudViewer::t::geometry::OrientedBoundingBox::SetRotation ( const core::Tensor &  rotation)

Set the rotation matrix of the box. If the data type of the given tensor differs from the data type of the box, an exception will be thrown.

Parameters
rotationTensor with {3, 3} shape, and type float32 or float64.

References AssertTensorDevice, AssertTensorDtypes, AssertTensorShape, e, cloudViewer::core::Float32, cloudViewer::core::Float64, GetDevice(), GetDtype(), LogWarning, rotation, and rotation_.

Referenced by To().

◆ To()

OrientedBoundingBox cloudViewer::t::geometry::OrientedBoundingBox::To ( const core::Device &  device,
bool  copy = false 
) const

Transfer the OrientedBoundingBox to a specified device.

Parameters
deviceThe targeted device to convert to.
copyIf true, a new OrientedBoundingBox is always created; if false, the copy is avoided when the original OrientedBoundingBox is already on the targeted device.

References center_, color_, copy, extent_, GetDevice(), rotation_, SetCenter(), SetColor(), SetExtent(), SetRotation(), and cloudViewer::core::Tensor::To().

Referenced by Clone(), and Volume().

◆ ToLegacy()

◆ ToString()

std::string cloudViewer::t::geometry::OrientedBoundingBox::ToString ( ) const

Text description.

References format, GetDevice(), and GetDtype().

◆ Transform()

OrientedBoundingBox & cloudViewer::t::geometry::OrientedBoundingBox::Transform ( const core::Tensor &  transformation)

Transform the oriented box by the given transformation matrix.

Parameters
transformationTransformation matrix of shape {4, 4}, type float32 or float64, device same as the box.

References AssertTensorDevice, AssertTensorDtypes, AssertTensorShape, cloudViewer::core::Float32, cloudViewer::core::Float64, GetDevice(), GetDtype(), cloudViewer::core::TensorKey::Index(), Rotate(), cloudViewer::core::TensorKey::Slice(), cloudViewer::core::Tensor::To(), and Translate().

◆ Translate()

OrientedBoundingBox & cloudViewer::t::geometry::OrientedBoundingBox::Translate ( const core::Tensor &  translation,
bool  relative = true 
)

Translate the oriented box by the given translation. If relative is true, the translation is added to the center of the box. If false, the center will be assigned to the translation.

Parameters
translationTranslation tensor of shape {3,}, type float32 or float64, device same as the box.
relativeWhether to perform relative translation.

References AssertTensorDevice, AssertTensorDtypes, AssertTensorShape, center_, cloudViewer::core::Float32, cloudViewer::core::Float64, GetDevice(), GetDtype(), and cloudViewer::core::Tensor::To().

Referenced by Transform().

◆ Volume()

double cloudViewer::t::geometry::OrientedBoundingBox::Volume ( ) const
inline

Member Data Documentation

◆ center_

core::Tensor cloudViewer::t::geometry::OrientedBoundingBox::center_
protected

◆ color_

core::Tensor cloudViewer::t::geometry::OrientedBoundingBox::color_
protected

Referenced by Clear(), GetColor(), SetColor(), and To().

◆ device_

core::Device cloudViewer::t::geometry::OrientedBoundingBox::device_ = core::Device("CPU:0")
protected

Referenced by GetDevice().

◆ dtype_

core::Dtype cloudViewer::t::geometry::OrientedBoundingBox::dtype_ = core::Float32
protected

Referenced by GetDtype().

◆ extent_

core::Tensor cloudViewer::t::geometry::OrientedBoundingBox::extent_
protected

◆ rotation_

core::Tensor cloudViewer::t::geometry::OrientedBoundingBox::rotation_
protected

The documentation for this class was generated from the following files: