Open3D (C++ API)  0.17.0
BoundingVolume.h
Go to the documentation of this file.
1// ----------------------------------------------------------------------------
2// - Open3D: www.open3d.org -
3// ----------------------------------------------------------------------------
4// Copyright (c) 2018-2023 www.open3d.org
5// SPDX-License-Identifier: MIT
6// ----------------------------------------------------------------------------
7
8#pragma once
9
10#include "open3d/core/Tensor.h"
16
17namespace open3d {
18namespace t {
19namespace geometry {
20
21class OrientedBoundingBox;
22
47public:
49 AxisAlignedBoundingBox(const core::Device &device = core::Device("CPU:0"));
50
60 AxisAlignedBoundingBox(const core::Tensor &min_bound,
61 const core::Tensor &max_bound);
62
63 virtual ~AxisAlignedBoundingBox() override {}
64
66 core::Device GetDevice() const override { return device_; }
67
69 core::Dtype GetDtype() const { return dtype_; }
70
77 bool copy = false) const;
78
81 return To(GetDevice(), /*copy=*/true);
82 }
83
84 AxisAlignedBoundingBox &Clear() override;
85
86 bool IsEmpty() const override { return Volume() == 0; }
87
94 void SetMinBound(const core::Tensor &min_bound);
95
102 void SetMaxBound(const core::Tensor &max_bound);
103
110 void SetColor(const core::Tensor &color);
111
112public:
114
116
117 core::Tensor GetColor() const { return color_; }
118
119 core::Tensor GetCenter() const { return (min_bound_ + max_bound_) * 0.5; }
120
131 bool relative = true);
132
145 double scale,
147
152
155
157 core::Tensor GetHalfExtent() const { return GetExtent() / 2; }
158
161 double GetMaxExtent() const {
162 return GetExtent().Max({0}).To(core::Float64).Item<double>();
163 }
164
165 double GetXPercentage(double x) const;
166
167 double GetYPercentage(double y) const;
168
169 double GetZPercentage(double z) const;
170
172 double Volume() const {
173 return GetExtent().Prod({0}).To(core::Float64).Item<double>();
174 }
175
179
184 const core::Tensor &points) const;
185
187 std::string ToString() const;
188
191
194
204 const core::Dtype &dtype = core::Float32,
205 const core::Device &device = core::Device("CPU:0"));
206
213
214protected:
220};
221
246public:
248 OrientedBoundingBox(const core::Device &device = core::Device("CPU:0"));
249
262 OrientedBoundingBox(const core::Tensor &center,
263 const core::Tensor &rotation,
264 const core::Tensor &extent);
265
266 virtual ~OrientedBoundingBox() override {}
267
269 core::Device GetDevice() const override { return device_; }
270
272 core::Dtype GetDtype() const { return dtype_; }
273
279 OrientedBoundingBox To(const core::Device &device, bool copy = false) const;
280
282 OrientedBoundingBox Clone() const { return To(GetDevice(), /*copy=*/true); }
283
284 OrientedBoundingBox &Clear() override;
285
286 bool IsEmpty() const override { return Volume() == 0; }
287
293 void SetCenter(const core::Tensor &center);
294
300 void SetRotation(const core::Tensor &rotation);
301
307 void SetExtent(const core::Tensor &extent);
308
313 void SetColor(const core::Tensor &color);
314
315public:
317
319
320 core::Tensor GetColor() const { return color_; }
321
322 core::Tensor GetCenter() const { return center_; }
323
325
326 core::Tensor GetExtent() const { return extent_; }
327
335 OrientedBoundingBox &Translate(const core::Tensor &translation,
336 bool relative = true);
337
347 const core::Tensor &rotation,
349
354 OrientedBoundingBox &Transform(const core::Tensor &transformation);
355
368 double scale,
370
372 double Volume() const {
373 return GetExtent().Prod({0}).To(core::Float64).Item<double>();
374 }
375
399
404 const core::Tensor &points) const;
405
407 std::string ToString() const;
408
411
414
421 const AxisAlignedBoundingBox &aabb);
422
431 const core::Dtype &dtype = core::Float32,
432 const core::Device &device = core::Device("CPU:0"));
433
448 bool robust = false);
449
450protected:
457};
458
459} // namespace geometry
460} // namespace t
461} // namespace open3d
math::float4 color
Definition: LineSetBuffers.cpp:45
bool copy
Definition: VtkUtils.cpp:73
Definition: Device.h:18
Definition: Dtype.h:20
Definition: Tensor.h:32
Tensor Prod(const SizeVector &dims, bool keepdim=false) const
Definition: Tensor.cpp:1191
Tensor Max(const SizeVector &dims, bool keepdim=false) const
Definition: Tensor.cpp:1205
A bounding box that is aligned along the coordinate axes.
Definition: BoundingVolume.h:159
A bounding box oriented along an arbitrary frame of reference.
Definition: BoundingVolume.h:25
A bounding box that is aligned along the coordinate axes and defined by the min_bound and max_bound.
Definition: BoundingVolume.h:46
double GetZPercentage(double z) const
Definition: BoundingVolume.cpp:189
double Volume() const
Returns the volume of the bounding box.
Definition: BoundingVolume.h:172
core::Tensor GetMinBound() const
Definition: BoundingVolume.h:113
core::Dtype GetDtype() const
Returns the data type attribute of this AxisAlignedBoundingBox.
Definition: BoundingVolume.h:69
static AxisAlignedBoundingBox FromLegacy(const open3d::geometry::AxisAlignedBoundingBox &box, const core::Dtype &dtype=core::Float32, const core::Device &device=core::Device("CPU:0"))
Definition: BoundingVolume.cpp:258
void SetMinBound(const core::Tensor &min_bound)
Set the min bound of the box. If the data type of the given tensor differs from the data type of the ...
Definition: BoundingVolume.cpp:70
core::Tensor GetBoxPoints() const
Definition: BoundingVolume.cpp:195
OrientedBoundingBox GetOrientedBoundingBox() const
Convert to an oriented box.
Definition: BoundingVolume.cpp:254
void SetColor(const core::Tensor &color)
Set the color of the box. If the data type of the given tensor differs from the data type of the box,...
Definition: BoundingVolume.cpp:106
double GetYPercentage(double y) const
Definition: BoundingVolume.cpp:183
double GetMaxExtent() const
Definition: BoundingVolume.h:161
core::Dtype dtype_
Definition: BoundingVolume.h:216
virtual ~AxisAlignedBoundingBox() override
Definition: BoundingVolume.h:63
open3d::geometry::AxisAlignedBoundingBox ToLegacy() const
Convert to a legacy Open3D axis-aligned box.
Definition: BoundingVolume.cpp:241
AxisAlignedBoundingBox Clone() const
Returns copy of the AxisAlignedBoundingBox on the same device.
Definition: BoundingVolume.h:80
std::string ToString() const
Text description.
Definition: BoundingVolume.cpp:222
core::Tensor GetExtent() const
Get the extent/length of the bounding box in x, y, and z dimension.
Definition: BoundingVolume.h:154
AxisAlignedBoundingBox & operator+=(const AxisAlignedBoundingBox &other)
Add operation for axis-aligned bounding box. The device of ohter box must be the same as the device o...
Definition: BoundingVolume.cpp:158
core::Tensor max_bound_
Definition: BoundingVolume.h:218
AxisAlignedBoundingBox & Clear() override
Clear all elements in the geometry.
Definition: BoundingVolume.cpp:63
AxisAlignedBoundingBox & Scale(double scale, const utility::optional< core::Tensor > &center=utility::nullopt)
Scale the axis-aligned box. If is the min_bound and is the max_bound of the axis aligned bounding b...
Definition: BoundingVolume.cpp:140
core::Tensor GetColor() const
Definition: BoundingVolume.h:117
void SetMaxBound(const core::Tensor &max_bound)
Set the max boundof the box. If the data type of the given tensor differs from the data type of the b...
Definition: BoundingVolume.cpp:88
core::Tensor GetCenter() const
Definition: BoundingVolume.h:119
AxisAlignedBoundingBox(const core::Device &device=core::Device("CPU:0"))
Construct an empty AxisAlignedBoundingBox on the provided device.
Definition: BoundingVolume.cpp:18
core::Device device_
Definition: BoundingVolume.h:215
core::Tensor GetMaxBound() const
Definition: BoundingVolume.h:115
AxisAlignedBoundingBox & Translate(const core::Tensor &translation, bool relative=true)
Translate the axis-aligned box by the given translation.
Definition: BoundingVolume.cpp:122
core::Tensor min_bound_
Definition: BoundingVolume.h:217
core::Tensor color_
Definition: BoundingVolume.h:219
core::Tensor GetHalfExtent() const
Returns the half extent of the bounding box.
Definition: BoundingVolume.h:157
core::Device GetDevice() const override
Returns the device attribute of this AxisAlignedBoundingBox.
Definition: BoundingVolume.h:66
double GetXPercentage(double x) const
Definition: BoundingVolume.cpp:177
AxisAlignedBoundingBox To(const core::Device &device, bool copy=false) const
Transfer the AxisAlignedBoundingBox to a specified device.
Definition: BoundingVolume.cpp:51
core::Tensor GetPointIndicesWithinBoundingBox(const core::Tensor &points) const
Indices to points that are within the bounding box.
Definition: BoundingVolume.cpp:206
bool IsEmpty() const override
Returns true iff the geometry is empty.
Definition: BoundingVolume.h:86
static AxisAlignedBoundingBox CreateFromPoints(const core::Tensor &points)
Definition: BoundingVolume.cpp:227
Mix-in class for geometry types that can be visualized.
Definition: DrawableGeometry.h:19
The base geometry class.
Definition: Geometry.h:21
A bounding box oriented along an arbitrary frame of reference.
Definition: BoundingVolume.h:245
static OrientedBoundingBox CreateFromAxisAlignedBoundingBox(const AxisAlignedBoundingBox &aabb)
Definition: BoundingVolume.cpp:525
core::Dtype dtype_
Definition: BoundingVolume.h:452
double Volume() const
Returns the volume of the bounding box.
Definition: BoundingVolume.h:372
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 o...
Definition: BoundingVolume.cpp:368
core::Tensor center_
Definition: BoundingVolume.h:453
static OrientedBoundingBox CreateFromPoints(const core::Tensor &points, bool robust=false)
Definition: BoundingVolume.cpp:561
OrientedBoundingBox & Scale(double scale, const utility::optional< core::Tensor > &center=utility::nullopt)
Scale the axis-aligned box. If is the min_bound and is the max_bound of the axis aligned bounding b...
Definition: BoundingVolume.cpp:471
core::Dtype GetDtype() const
Returns the data type attribute of this OrientedBoundingBox.
Definition: BoundingVolume.h:272
static OrientedBoundingBox FromLegacy(const open3d::geometry::OrientedBoundingBox &box, const core::Dtype &dtype=core::Float32, const core::Device &device=core::Device("CPU:0"))
Definition: BoundingVolume.cpp:534
bool IsEmpty() const override
Returns true iff the geometry is empty.
Definition: BoundingVolume.h:286
core::Tensor extent_
Definition: BoundingVolume.h:455
core::Tensor GetColor() const
Definition: BoundingVolume.h:320
core::Tensor GetCenter() const
Definition: BoundingVolume.h:322
core::Tensor GetPointIndicesWithinBoundingBox(const core::Tensor &points) const
Indices to points that are within the bounding box.
Definition: BoundingVolume.cpp:486
core::Tensor rotation_
Definition: BoundingVolume.h:454
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...
Definition: BoundingVolume.cpp:346
OrientedBoundingBox & Clear() override
Clear all elements in the geometry.
Definition: BoundingVolume.cpp:338
core::Tensor GetRotation() const
Definition: BoundingVolume.h:324
OrientedBoundingBox & Transform(const core::Tensor &transformation)
Transform the oriented box by the given transformation matrix.
Definition: BoundingVolume.cpp:455
core::Tensor GetMaxBound() const
Definition: BoundingVolume.cpp:401
core::Device device_
Definition: BoundingVolume.h:451
void SetColor(const core::Tensor &color)
Set the color of the box.
Definition: BoundingVolume.cpp:382
std::string ToString() const
Text description.
Definition: BoundingVolume.cpp:503
open3d::geometry::OrientedBoundingBox ToLegacy() const
Convert to a legacy Open3D oriented box.
Definition: BoundingVolume.cpp:508
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,...
Definition: BoundingVolume.cpp:426
virtual ~OrientedBoundingBox() override
Definition: BoundingVolume.h:266
OrientedBoundingBox(const core::Device &device=core::Device("CPU:0"))
Construct an empty OrientedBoundingBox on the provided device.
Definition: BoundingVolume.cpp:283
core::Device GetDevice() const override
Returns the device attribute of this OrientedBoundingBox.
Definition: BoundingVolume.h:269
OrientedBoundingBox To(const core::Device &device, bool copy=false) const
Definition: BoundingVolume.cpp:325
AxisAlignedBoundingBox GetAxisAlignedBoundingBox() const
Convert to an axis-aligned box.
Definition: BoundingVolume.cpp:521
core::Tensor color_
Definition: BoundingVolume.h:456
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...
Definition: BoundingVolume.cpp:354
core::Tensor GetMinBound() const
Definition: BoundingVolume.cpp:397
core::Tensor GetBoxPoints() const
Definition: BoundingVolume.cpp:405
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...
Definition: BoundingVolume.cpp:411
core::Tensor GetExtent() const
Definition: BoundingVolume.h:326
OrientedBoundingBox Clone() const
Returns copy of the OrientedBoundingBox on the same device.
Definition: BoundingVolume.h:282
Definition: Optional.h:259
int points
Definition: FilePCD.cpp:54
const Dtype Float64
Definition: Dtype.cpp:43
const Dtype Float32
Definition: Dtype.cpp:42
constexpr nullopt_t nullopt
Definition: Optional.h:152
Definition: PinholeCameraIntrinsic.cpp:16