ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
boundingvolume.cpp
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
9 
10 #include <string>
11 
13 
14 namespace cloudViewer {
15 namespace t {
16 namespace geometry {
17 
18 void pybind_boundingvolume(py::module& m) {
19  // AxisAlignedBoundingBox
20  py::class_<AxisAlignedBoundingBox, PyGeometry<AxisAlignedBoundingBox>,
21  std::shared_ptr<AxisAlignedBoundingBox>, Geometry,
23  aabb(m, "AxisAlignedBoundingBox",
24  "A bounding box aligned with coordinate axes.");
25 
26  aabb.def(py::init<const core::Device&>(),
27  "device"_a = core::Device("CPU:0"))
28  .def(py::init<const core::Tensor&, const core::Tensor&>(),
29  "min_bound"_a, "max_bound"_a)
30  .def("to", &AxisAlignedBoundingBox::To, "device"_a,
31  "copy"_a = false)
32  .def("clone", &AxisAlignedBoundingBox::Clone)
33  .def("cpu",
34  [](const AxisAlignedBoundingBox& self) {
35  return self.To(core::Device("CPU:0"));
36  })
37  .def(
38  "cuda",
39  [](const AxisAlignedBoundingBox& self, int device_id) {
40  return self.To(core::Device("CUDA", device_id));
41  },
42  "device_id"_a = 0)
43  .def("set_min_bound", &AxisAlignedBoundingBox::SetMinBound,
44  "min_bound"_a)
45  .def("set_max_bound", &AxisAlignedBoundingBox::SetMaxBound,
46  "max_bound"_a)
47  .def("set_color", &AxisAlignedBoundingBox::SetColor, "color"_a)
48  .def_property_readonly("min_bound",
50  .def_property_readonly("max_bound",
52  .def_property_readonly("color", &AxisAlignedBoundingBox::GetColor)
53  .def("get_center", &AxisAlignedBoundingBox::GetCenter)
54  .def("translate", &AxisAlignedBoundingBox::Translate,
55  "translation"_a, "relative"_a = true)
56  .def("scale", &AxisAlignedBoundingBox::Scale, "scale"_a,
57  "center"_a = utility::nullopt)
58  .def("get_extent", &AxisAlignedBoundingBox::GetExtent)
59  .def("get_half_extent", &AxisAlignedBoundingBox::GetHalfExtent)
60  .def("get_max_extent", &AxisAlignedBoundingBox::GetMaxExtent)
61  .def("volume", &AxisAlignedBoundingBox::Volume)
62  .def("get_box_points", &AxisAlignedBoundingBox::GetBoxPoints)
63  .def("get_point_indices_within_bounding_box",
65  "points"_a)
66  .def("to_legacy", &AxisAlignedBoundingBox::ToLegacy)
67  .def("get_oriented_bounding_box",
69  .def_static("from_legacy", &AxisAlignedBoundingBox::FromLegacy,
70  "box"_a, "dtype"_a = core::Float32,
71  "device"_a = core::Device("CPU:0"))
72  .def_static("create_from_points",
74 
75  // OrientedBoundingBox
76  py::class_<OrientedBoundingBox, PyGeometry<OrientedBoundingBox>,
77  std::shared_ptr<OrientedBoundingBox>, Geometry, DrawableGeometry>
78  obb(m, "OrientedBoundingBox",
79  "A bounding box oriented along an arbitrary frame.");
80 
81  obb.def(py::init<const core::Device&>(), "device"_a = core::Device("CPU:0"))
82  .def(py::init<const core::Tensor&, const core::Tensor&,
83  const core::Tensor&>(),
84  "center"_a, "rotation"_a, "extent"_a)
85  .def("to", &OrientedBoundingBox::To, "device"_a, "copy"_a = false)
86  .def("clone", &OrientedBoundingBox::Clone)
87  .def("cpu",
88  [](const OrientedBoundingBox& self) {
89  return self.To(core::Device("CPU:0"));
90  })
91  .def(
92  "cuda",
93  [](const OrientedBoundingBox& self, int device_id) {
94  return self.To(core::Device("CUDA", device_id));
95  },
96  "device_id"_a = 0)
97  .def("set_center", &OrientedBoundingBox::SetCenter, "center"_a)
98  .def("set_rotation", &OrientedBoundingBox::SetRotation,
99  "rotation"_a)
100  .def("set_extent", &OrientedBoundingBox::SetExtent, "extent"_a)
101  .def("set_color", &OrientedBoundingBox::SetColor, "color"_a)
102  .def_property_readonly("center", &OrientedBoundingBox::GetCenter)
103  .def_property_readonly("rotation",
105  .def_property_readonly("extent", &OrientedBoundingBox::GetExtent)
106  .def_property_readonly("color", &OrientedBoundingBox::GetColor)
107  .def("get_min_bound", &OrientedBoundingBox::GetMinBound)
108  .def("get_max_bound", &OrientedBoundingBox::GetMaxBound)
109  .def("translate", &OrientedBoundingBox::Translate, "translation"_a,
110  "relative"_a = true)
111  .def("rotate", &OrientedBoundingBox::Rotate, "rotation"_a,
112  "center"_a = utility::nullopt)
113  .def("transform", &OrientedBoundingBox::Transform,
114  "transformation"_a)
115  .def("scale", &OrientedBoundingBox::Scale, "scale"_a,
116  "center"_a = utility::nullopt)
117  .def("volume", &OrientedBoundingBox::Volume)
118  .def("get_box_points", &OrientedBoundingBox::GetBoxPoints)
119  .def("get_point_indices_within_bounding_box",
121  "points"_a)
122  .def("get_axis_aligned_bounding_box",
124  .def("to_legacy", &OrientedBoundingBox::ToLegacy)
125  .def_static("from_legacy", &OrientedBoundingBox::FromLegacy,
126  "box"_a, "dtype"_a = core::Float32,
127  "device"_a = core::Device("CPU:0"))
128  .def_static("create_from_axis_aligned_bounding_box",
130  "aabb"_a)
131  .def_static("create_from_points",
133  "robust"_a = false,
134  "method"_a = MethodOBBCreate::MINIMAL_APPROX);
135 }
136 
137 } // namespace geometry
138 } // namespace t
139 } // namespace cloudViewer
A bounding box that is aligned along the coordinate axes and defined by the min_bound and max_bound.
cloudViewer::geometry::AxisAlignedBoundingBox ToLegacy() const
Convert to a legacy CloudViewer axis-aligned box.
core::Tensor GetExtent() const
Get the extent/length of the bounding box in x, y, and z dimension.
core::Tensor GetPointIndicesWithinBoundingBox(const core::Tensor &points) const
Indices to points that are within the bounding box.
static AxisAlignedBoundingBox FromLegacy(const cloudViewer::geometry::AxisAlignedBoundingBox &box, const core::Dtype &dtype=core::Float32, const core::Device &device=core::Device("CPU:0"))
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,...
static AxisAlignedBoundingBox CreateFromPoints(const core::Tensor &points)
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 ...
AxisAlignedBoundingBox To(const core::Device &device, bool copy=false) const
Transfer the AxisAlignedBoundingBox to a specified device.
AxisAlignedBoundingBox Clone() const
Returns copy of the AxisAlignedBoundingBox on the same device.
double GetMaxExtent() const
Returns the maximum extent, i.e. the maximum of X, Y and Z axis' extents.
OrientedBoundingBox GetOrientedBoundingBox() const
Convert to an oriented box.
core::Tensor GetHalfExtent() const
Returns the half extent of the bounding box.
void SetMaxBound(const core::Tensor &max_bound)
Set the max bound of the box. If the data type of the given tensor differs from the data type of the ...
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...
core::Tensor GetBoxPoints() const
Returns the eight points that define the bounding box.
AxisAlignedBoundingBox & Translate(const core::Tensor &translation, bool relative=true)
Translate the axis-aligned box by the given translation.
double Volume() const
Returns the volume of the bounding box.
Mix-in class for geometry types that can be visualized.
The base geometry class.
Definition: Geometry.h:23
A bounding box oriented along an arbitrary frame of reference.
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,...
AxisAlignedBoundingBox GetAxisAlignedBoundingBox() const
Convert to an axis-aligned box.
OrientedBoundingBox To(const core::Device &device, bool copy=false) const
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...
OrientedBoundingBox Clone() const
Returns copy of the OrientedBoundingBox on the same device.
cloudViewer::geometry::OrientedBoundingBox ToLegacy() const
Convert to a legacy CloudViewer oriented box.
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...
static OrientedBoundingBox CreateFromPoints(const core::Tensor &points, bool robust=false, MethodOBBCreate method=MethodOBBCreate::MINIMAL_APPROX)
OrientedBoundingBox & Transform(const core::Tensor &transformation)
Transform the oriented box by the given transformation matrix.
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...
static OrientedBoundingBox CreateFromAxisAlignedBoundingBox(const AxisAlignedBoundingBox &aabb)
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...
core::Tensor GetBoxPoints() const
Returns the eight points that define the bounding box.
static OrientedBoundingBox FromLegacy(const cloudViewer::geometry::OrientedBoundingBox &box, const core::Dtype &dtype=core::Float32, const core::Device &device=core::Device("CPU:0"))
core::Tensor GetPointIndicesWithinBoundingBox(const core::Tensor &points) const
Indices to points that are within the bounding box.
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...
double Volume() const
Returns the volume of the bounding box.
void SetColor(const core::Tensor &color)
Set the color of the box.
const Dtype Float32
Definition: Dtype.cpp:42
void pybind_boundingvolume(py::module &m)
@ MINIMAL_APPROX
Minimal OBB approximation.
constexpr nullopt_t nullopt
Definition: Optional.h:136
Generic file read and write utility for python interface.