Open3D (C++ API)
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
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 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 
33 namespace open3d {
34 namespace geometry {
35 
36 class AxisAlignedBoundingBox;
37 
39 public:
42  center_(0, 0, 0),
43  x_axis_(0, 0, 0),
44  y_axis_(0, 0, 0),
45  z_axis_(0, 0, 0),
46  color_(0, 0, 0) {}
47  ~OrientedBoundingBox() override {}
48 
49 public:
50  OrientedBoundingBox& Clear() override;
51  bool IsEmpty() const override;
52  virtual Eigen::Vector3d GetMinBound() const override;
53  virtual Eigen::Vector3d GetMaxBound() const override;
54  virtual Eigen::Vector3d GetCenter() const override;
55  virtual AxisAlignedBoundingBox GetAxisAlignedBoundingBox() const override;
56  virtual OrientedBoundingBox GetOrientedBoundingBox() const override;
58  const Eigen::Matrix4d& transformation) override;
59  virtual OrientedBoundingBox& Translate(const Eigen::Vector3d& translation,
60  bool relative = true) override;
61  virtual OrientedBoundingBox& Scale(const double scale,
62  bool center = true) override;
63  virtual OrientedBoundingBox& Rotate(
64  const Eigen::Vector3d& rotation,
65  bool center = true,
67 
68  double Volume() const;
69  std::vector<Eigen::Vector3d> GetBoxPoints() const;
70 
72  const AxisAlignedBoundingBox& aabox);
73 
80  const std::vector<Eigen::Vector3d>& points);
81 
82 public:
83  Eigen::Vector3d center_;
84  Eigen::Vector3d x_axis_;
85  Eigen::Vector3d y_axis_;
86  Eigen::Vector3d z_axis_;
87  Eigen::Vector3d color_;
88 };
89 
91 public:
94  min_bound_(0, 0, 0),
95  max_bound_(0, 0, 0),
96  color_(0, 0, 0) {}
98 
99 public:
100  AxisAlignedBoundingBox& Clear() override;
101  bool IsEmpty() const override;
102  virtual Eigen::Vector3d GetMinBound() const override;
103  virtual Eigen::Vector3d GetMaxBound() const override;
104  virtual Eigen::Vector3d GetCenter() const override;
105  virtual AxisAlignedBoundingBox GetAxisAlignedBoundingBox() const override;
106  virtual OrientedBoundingBox GetOrientedBoundingBox() const override;
108  const Eigen::Matrix4d& transformation) override;
110  const Eigen::Vector3d& translation, bool relative = true) override;
111  virtual AxisAlignedBoundingBox& Scale(const double scale,
112  bool center = true) override;
114  const Eigen::Vector3d& rotation,
115  bool center = true,
116  RotationType type = RotationType::XYZ) override;
117 
119  min_bound_ = min_bound_.array().min(other.min_bound_.array()).matrix();
120  max_bound_ = max_bound_.array().max(other.max_bound_.array()).matrix();
121  return *this;
122  }
123 
124  double Volume() const;
125  std::vector<Eigen::Vector3d> GetBoxPoints() const;
126 
127  Eigen::Vector3d GetExtend() const { return (max_bound_ - min_bound_); }
128 
129  Eigen::Vector3d GetHalfExtend() const { return GetExtend() * 0.5; }
130 
131  double GetMaxExtend() const { return (max_bound_ - min_bound_).maxCoeff(); }
132 
133  double GetXPercentage(double x) const {
134  return (x - min_bound_(0)) / (max_bound_(0) - min_bound_(0));
135  }
136 
137  double GetYPercentage(double y) const {
138  return (y - min_bound_(1)) / (max_bound_(1) - min_bound_(1));
139  }
140 
141  double GetZPercentage(double z) const {
142  return (z - min_bound_(2)) / (max_bound_(2) - min_bound_(2));
143  }
144 
145  std::string GetPrintInfo() const;
146 
148  const std::vector<Eigen::Vector3d>& points);
149 
150 public:
151  Eigen::Vector3d min_bound_;
152  Eigen::Vector3d max_bound_;
153  Eigen::Vector3d color_;
154 };
155 
156 } // namespace geometry
157 } // namespace open3d
OrientedBoundingBox & Clear() override
Definition: BoundingVolume.cpp:40
Definition: Geometry.h:32
Eigen::Vector3d y_axis_
Definition: BoundingVolume.h:85
Eigen::Vector3d max_bound_
Definition: BoundingVolume.h:152
Definition: BoundingVolume.h:90
~AxisAlignedBoundingBox() override
Definition: BoundingVolume.h:97
double GetXPercentage(double x) const
Definition: BoundingVolume.h:133
double Volume() const
Definition: BoundingVolume.cpp:138
static OrientedBoundingBox CreateFromPoints(const std::vector< Eigen::Vector3d > &points)
Definition: BoundingVolume.cpp:166
Definition: BoundingVolume.h:38
Eigen::Vector3d min_bound_
Definition: BoundingVolume.h:151
virtual OrientedBoundingBox & Rotate(const Eigen::Vector3d &rotation, bool center=true, RotationType type=RotationType::XYZ) override
Definition: BoundingVolume.cpp:119
Eigen::Vector3d GetHalfExtend() const
Definition: BoundingVolume.h:129
Eigen::Vector3d GetExtend() const
Definition: BoundingVolume.h:127
bool IsEmpty() const override
Definition: BoundingVolume.cpp:48
RotationType
Definition: Geometry3D.h:43
virtual Eigen::Vector3d GetCenter() const override
Definition: BoundingVolume.cpp:60
virtual OrientedBoundingBox & Transform(const Eigen::Matrix4d &transformation) override
Definition: BoundingVolume.cpp:70
double GetZPercentage(double z) const
Definition: BoundingVolume.h:141
virtual OrientedBoundingBox & Translate(const Eigen::Vector3d &translation, bool relative=true) override
Definition: BoundingVolume.cpp:91
std::vector< Eigen::Vector3d > GetBoxPoints() const
Definition: BoundingVolume.cpp:142
Definition: Geometry3D.h:41
virtual AxisAlignedBoundingBox GetAxisAlignedBoundingBox() const override
Definition: BoundingVolume.cpp:62
virtual Eigen::Vector3d GetMinBound() const override
Definition: BoundingVolume.cpp:50
Eigen::Vector3d color_
Definition: BoundingVolume.h:153
OrientedBoundingBox()
Definition: BoundingVolume.h:40
~OrientedBoundingBox() override
Definition: BoundingVolume.h:47
double GetYPercentage(double y) const
Definition: BoundingVolume.h:137
char type
Definition: FilePCD.cpp:56
virtual OrientedBoundingBox GetOrientedBoundingBox() const override
Definition: BoundingVolume.cpp:66
int points
Definition: FilePCD.cpp:69
Definition: PinholeCameraIntrinsic.cpp:34
Eigen::Vector3d color_
Definition: BoundingVolume.h:87
GeometryType
Definition: Geometry.h:34
AxisAlignedBoundingBox & operator+=(const AxisAlignedBoundingBox &other)
Definition: BoundingVolume.h:118
virtual Eigen::Vector3d GetMaxBound() const override
Definition: BoundingVolume.cpp:55
AxisAlignedBoundingBox()
Definition: BoundingVolume.h:92
virtual OrientedBoundingBox & Scale(const double scale, bool center=true) override
Definition: BoundingVolume.cpp:101
Eigen::Vector3d x_axis_
Definition: BoundingVolume.h:84
static OrientedBoundingBox CreateFromAxisAlignedBoundingBox(const AxisAlignedBoundingBox &aabox)
Definition: BoundingVolume.cpp:155
double GetMaxExtend() const
Definition: BoundingVolume.h:131
Eigen::Vector3d z_axis_
Definition: BoundingVolume.h:86
Eigen::Vector3d center_
Definition: BoundingVolume.h:83