Open3D (C++ API)  0.16.0
BoundingVolume.h
Go to the documentation of this file.
1// ----------------------------------------------------------------------------
2// - Open3D: www.open3d.org -
3// ----------------------------------------------------------------------------
4// The MIT License (MIT)
5//
6// Copyright (c) 2018-2021 www.open3d.org
7//
8// Permission is hereby granted, free of charge, to any person obtaining a copy
9// of this software and associated documentation files (the "Software"), to deal
10// in the Software without restriction, including without limitation the rights
11// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12// copies of the Software, and to permit persons to whom the Software is
13// furnished to do so, subject to the following conditions:
14//
15// The above copyright notice and this permission notice shall be included in
16// all copies or substantial portions of the Software.
17//
18// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24// IN THE SOFTWARE.
25// ----------------------------------------------------------------------------
26
27#pragma once
28
29#include <Eigen/Core>
30
32
33namespace open3d {
34namespace geometry {
35
36class AxisAlignedBoundingBox;
37
45public:
51 center_(0, 0, 0),
52 R_(Eigen::Matrix3d::Identity()),
53 extent_(0, 0, 0),
54 color_(1, 1, 1) {}
61 OrientedBoundingBox(const Eigen::Vector3d& center,
62 const Eigen::Matrix3d& R,
63 const Eigen::Vector3d& extent)
65 center_(center),
66 R_(R),
67 extent_(extent) {}
69
70public:
71 OrientedBoundingBox& Clear() override;
72 bool IsEmpty() const override;
73 virtual Eigen::Vector3d GetMinBound() const override;
74 virtual Eigen::Vector3d GetMaxBound() const override;
75 virtual Eigen::Vector3d GetCenter() const override;
78 bool robust) const override;
80 const Eigen::Matrix4d& transformation) override;
81 virtual OrientedBoundingBox& Translate(const Eigen::Vector3d& translation,
82 bool relative = true) override;
83 virtual OrientedBoundingBox& Scale(const double scale,
84 const Eigen::Vector3d& center) override;
85 virtual OrientedBoundingBox& Rotate(const Eigen::Matrix3d& R,
86 const Eigen::Vector3d& center) override;
87
89 double Volume() const;
90
111 std::vector<Eigen::Vector3d> GetBoxPoints() const;
112
114 std::vector<size_t> GetPointIndicesWithinBoundingBox(
115 const std::vector<Eigen::Vector3d>& points) const;
116
122 const AxisAlignedBoundingBox& aabox);
123
134 const std::vector<Eigen::Vector3d>& points, bool robust = false);
135
136public:
138 Eigen::Vector3d center_;
141 Eigen::Matrix3d R_;
143 Eigen::Vector3d extent_;
145 Eigen::Vector3d color_;
146};
147
156public:
162 min_bound_(0, 0, 0),
163 max_bound_(0, 0, 0),
164 color_(1, 1, 1) {}
169 AxisAlignedBoundingBox(const Eigen::Vector3d& min_bound,
170 const Eigen::Vector3d& max_bound)
172 min_bound_(min_bound),
173 max_bound_(max_bound),
174 color_(1, 1, 1) {}
176
177public:
178 AxisAlignedBoundingBox& Clear() override;
179 bool IsEmpty() const override;
180 virtual Eigen::Vector3d GetMinBound() const override;
181 virtual Eigen::Vector3d GetMaxBound() const override;
182 virtual Eigen::Vector3d GetCenter() const override;
183 virtual AxisAlignedBoundingBox GetAxisAlignedBoundingBox() const override;
185 bool robust = false) const override;
187 const Eigen::Matrix4d& transformation) override;
189 const Eigen::Vector3d& translation, bool relative = true) override;
190
201 const double scale, const Eigen::Vector3d& center) override;
202
206 const Eigen::Matrix3d& R, const Eigen::Vector3d& center) override;
207
209
211 Eigen::Vector3d GetExtent() const { return (max_bound_ - min_bound_); }
212
214 Eigen::Vector3d GetHalfExtent() const { return GetExtent() * 0.5; }
215
218 double GetMaxExtent() const { return (max_bound_ - min_bound_).maxCoeff(); }
219
220 double GetXPercentage(double x) const {
221 return (x - min_bound_(0)) / (max_bound_(0) - min_bound_(0));
222 }
223
224 double GetYPercentage(double y) const {
225 return (y - min_bound_(1)) / (max_bound_(1) - min_bound_(1));
226 }
227
228 double GetZPercentage(double z) const {
229 return (z - min_bound_(2)) / (max_bound_(2) - min_bound_(2));
230 }
231
233 double Volume() const;
235 std::vector<Eigen::Vector3d> GetBoxPoints() const;
236
240 std::vector<size_t> GetPointIndicesWithinBoundingBox(
241 const std::vector<Eigen::Vector3d>& points) const;
242
244 std::string GetPrintInfo() const;
245
250 const std::vector<Eigen::Vector3d>& points);
251
252public:
254 Eigen::Vector3d min_bound_;
256 Eigen::Vector3d max_bound_;
258 Eigen::Vector3d color_;
259};
260
261} // namespace geometry
262} // namespace open3d
A bounding box that is aligned along the coordinate axes.
Definition: BoundingVolume.h:155
Eigen::Vector3d GetHalfExtent() const
Returns the half extent of the bounding box.
Definition: BoundingVolume.h:214
double Volume() const
Returns the volume of the bounding box.
Definition: BoundingVolume.cpp:309
AxisAlignedBoundingBox()
Default constructor.
Definition: BoundingVolume.h:160
~AxisAlignedBoundingBox() override
Definition: BoundingVolume.h:175
virtual AxisAlignedBoundingBox & Rotate(const Eigen::Matrix3d &R, const Eigen::Vector3d &center) override
an AxisAlignedBoundingBox can not be rotated. This method will throw an error.
Definition: BoundingVolume.cpp:262
virtual Eigen::Vector3d GetCenter() const override
Returns the center of the geometry coordinates.
Definition: BoundingVolume.cpp:220
double GetXPercentage(double x) const
Definition: BoundingVolume.h:220
virtual AxisAlignedBoundingBox & Transform(const Eigen::Matrix4d &transformation) override
Apply transformation (4x4 matrix) to the geometry coordinates.
Definition: BoundingVolume.cpp:234
Eigen::Vector3d min_bound_
The lower x, y, z bounds of the bounding box.
Definition: BoundingVolume.h:254
virtual Eigen::Vector3d GetMinBound() const override
Returns min bounds for geometry coordinates.
Definition: BoundingVolume.cpp:212
bool IsEmpty() const override
Returns true iff the geometry is empty.
Definition: BoundingVolume.cpp:210
virtual AxisAlignedBoundingBox GetAxisAlignedBoundingBox() const override
Returns an axis-aligned bounding box of the geometry.
Definition: BoundingVolume.cpp:224
virtual AxisAlignedBoundingBox & Translate(const Eigen::Vector3d &translation, bool relative=true) override
Apply translation to the geometry coordinates.
Definition: BoundingVolume.cpp:242
AxisAlignedBoundingBox & operator+=(const AxisAlignedBoundingBox &other)
Definition: BoundingVolume.cpp:276
virtual OrientedBoundingBox GetOrientedBoundingBox(bool robust=false) const override
Definition: BoundingVolume.cpp:229
Eigen::Vector3d GetExtent() const
Get the extent/length of the bounding box in x, y, and z dimension.
Definition: BoundingVolume.h:211
std::string GetPrintInfo() const
Returns the 3D dimensions of the bounding box in string format.
Definition: BoundingVolume.cpp:270
AxisAlignedBoundingBox & Clear() override
Clear all elements in the geometry.
Definition: BoundingVolume.cpp:204
double GetZPercentage(double z) const
Definition: BoundingVolume.h:228
static AxisAlignedBoundingBox CreateFromPoints(const std::vector< Eigen::Vector3d > &points)
Definition: BoundingVolume.cpp:288
double GetMaxExtent() const
Definition: BoundingVolume.h:218
double GetYPercentage(double y) const
Definition: BoundingVolume.h:224
std::vector< Eigen::Vector3d > GetBoxPoints() const
Returns the eight points that define the bounding box.
Definition: BoundingVolume.cpp:311
std::vector< size_t > GetPointIndicesWithinBoundingBox(const std::vector< Eigen::Vector3d > &points) const
Definition: BoundingVolume.cpp:325
virtual AxisAlignedBoundingBox & Scale(const double scale, const Eigen::Vector3d &center) override
Scales the axis-aligned bounding boxes. If is the min_bound and is the max_bound of the axis aligne...
Definition: BoundingVolume.cpp:255
AxisAlignedBoundingBox(const Eigen::Vector3d &min_bound, const Eigen::Vector3d &max_bound)
Parameterized constructor.
Definition: BoundingVolume.h:169
Eigen::Vector3d color_
The color of the bounding box in RGB.
Definition: BoundingVolume.h:258
virtual Eigen::Vector3d GetMaxBound() const override
Returns max bounds for geometry coordinates.
Definition: BoundingVolume.cpp:216
Eigen::Vector3d max_bound_
The upper x, y, z bounds of the bounding box.
Definition: BoundingVolume.h:256
The base geometry class for 3D geometries.
Definition: Geometry3D.h:47
The base geometry class.
Definition: Geometry.h:37
GeometryType
Specifies possible geometry types.
Definition: Geometry.h:42
A bounding box oriented along an arbitrary frame of reference.
Definition: BoundingVolume.h:44
Eigen::Vector3d extent_
The extent of the bounding box in its frame of reference.
Definition: BoundingVolume.h:143
OrientedBoundingBox()
Default constructor.
Definition: BoundingVolume.h:49
OrientedBoundingBox & Clear() override
Clear all elements in the geometry.
Definition: BoundingVolume.cpp:40
Eigen::Vector3d color_
The color of the bounding box in RGB.
Definition: BoundingVolume.h:145
Eigen::Matrix3d R_
Definition: BoundingVolume.h:141
virtual Eigen::Vector3d GetMaxBound() const override
Returns max bounds for geometry coordinates.
Definition: BoundingVolume.cpp:55
~OrientedBoundingBox() override
Definition: BoundingVolume.h:68
virtual OrientedBoundingBox & Transform(const Eigen::Matrix4d &transformation) override
Apply transformation (4x4 matrix) to the geometry coordinates.
Definition: BoundingVolume.cpp:70
virtual Eigen::Vector3d GetCenter() const override
Returns the center of the geometry coordinates.
Definition: BoundingVolume.cpp:60
OrientedBoundingBox(const Eigen::Vector3d &center, const Eigen::Matrix3d &R, const Eigen::Vector3d &extent)
Parameterized constructor.
Definition: BoundingVolume.h:61
static OrientedBoundingBox CreateFromPoints(const std::vector< Eigen::Vector3d > &points, bool robust=false)
Definition: BoundingVolume.cpp:148
virtual OrientedBoundingBox & Rotate(const Eigen::Matrix3d &R, const Eigen::Vector3d &center) override
Apply rotation to the geometry coordinates and normals. Given a rotation matrix , and center ,...
Definition: BoundingVolume.cpp:95
std::vector< Eigen::Vector3d > GetBoxPoints() const
Definition: BoundingVolume.cpp:106
static OrientedBoundingBox CreateFromAxisAlignedBoundingBox(const AxisAlignedBoundingBox &aabox)
Definition: BoundingVolume.cpp:139
virtual OrientedBoundingBox & Scale(const double scale, const Eigen::Vector3d &center) override
Apply scaling to the geometry coordinates. Given a scaling factor , and center , a given point is tr...
Definition: BoundingVolume.cpp:88
double Volume() const
Returns the volume of the bounding box.
Definition: BoundingVolume.cpp:102
std::vector< size_t > GetPointIndicesWithinBoundingBox(const std::vector< Eigen::Vector3d > &points) const
Return indices to points that are within the bounding box.
Definition: BoundingVolume.cpp:122
virtual OrientedBoundingBox GetOrientedBoundingBox(bool robust) const override
Definition: BoundingVolume.cpp:66
virtual Eigen::Vector3d GetMinBound() const override
Returns min bounds for geometry coordinates.
Definition: BoundingVolume.cpp:50
virtual OrientedBoundingBox & Translate(const Eigen::Vector3d &translation, bool relative=true) override
Apply translation to the geometry coordinates.
Definition: BoundingVolume.cpp:78
virtual AxisAlignedBoundingBox GetAxisAlignedBoundingBox() const override
Returns an axis-aligned bounding box of the geometry.
Definition: BoundingVolume.cpp:62
bool IsEmpty() const override
Returns true iff the geometry is empty.
Definition: BoundingVolume.cpp:48
Eigen::Vector3d center_
The center point of the bounding box.
Definition: BoundingVolume.h:138
int points
Definition: FilePCD.cpp:73
Definition: NonRigidOptimizer.cpp:41
Definition: PinholeCameraIntrinsic.cpp:35