ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
ecvBBox.h
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 
8 #pragma once
9 
10 // LOCAL
11 #include "CV_db.h"
12 #include "ecvColorTypes.h"
13 #include "ecvDrawableObject.h"
14 #include "ecvGLMatrix.h"
15 #include "ecvHObject.h"
16 
17 // CV_CORE_LIB
18 #include <BoundingBox.h>
19 #include <SquareMatrix.h>
20 
22 
26 public:
28  ccBBox() : ccHObject("ccBBox"), cloudViewer::BoundingBox() {}
29 
31  ccBBox(const CCVector3& bbMinCorner,
32  const CCVector3& bbMaxCorner,
33  const std::string& name = "ccBBox")
34  : ccHObject(name.c_str()),
35  cloudViewer::BoundingBox(bbMinCorner, bbMaxCorner) {}
36 
41  ccBBox(const Eigen::Vector3d& min_bound,
42  const Eigen::Vector3d& max_bound,
43  const std::string& name = "ccBBox")
44  : ccHObject(name.c_str()),
45  cloudViewer::BoundingBox(min_bound, max_bound) {}
46 
48  explicit ccBBox(const cloudViewer::BoundingBox& bbox,
49  const std::string& name = "ccBBox")
50  : ccHObject(name.c_str()), cloudViewer::BoundingBox(bbox) {}
51 
53  const ccBBox operator*(const ccGLMatrix& mat);
55  const ccBBox operator*(const ccGLMatrixd& mat);
56 
57  ~ccBBox() override = default;
58 
59  // inherited methods (ccHObject)
60  bool isSerializable() const override { return true; }
62  CV_CLASS_ENUM getClassID() const override { return CV_TYPES::BBOX; }
63  // Returns the entity's own bounding-box
64  virtual inline ccBBox getOwnBB(bool withGLFeatures = false) override {
65  return *this;
66  }
67 
68 public: // inherited methods (ccHObject)
69  // IsEmpty should check if bbox has zero size in all dimensions, not just
70  // volume For 2D objects (Z=0), volume=0 but bbox is still valid if X or Y
71  // dimension > 0
72  inline virtual bool IsEmpty() const override {
73  if (!isValid()) return true;
74  // Use getMaxBoxDim() which returns the maximum of X, Y, Z extents
75  // This correctly handles 2D objects where Z=0 but X or Y > 0
76  // A bbox is empty only if all dimensions are zero (or very close to
77  // zero)
78  return getMaxBoxDim() <= static_cast<PointCoordinateType>(0);
79  }
80 
81  virtual inline Eigen::Vector3d GetMinBound() const override {
82  return CCVector3d::fromArray(m_bbMin);
83  }
84  virtual inline Eigen::Vector3d GetMaxBound() const override {
85  return CCVector3d::fromArray(m_bbMax);
86  }
87  virtual inline Eigen::Vector3d GetCenter() const override {
89  }
90 
91  virtual inline ccBBox GetAxisAlignedBoundingBox() const override {
92  return *this;
93  }
94  virtual ecvOrientedBBox GetOrientedBoundingBox() const override;
95 
96  virtual ccBBox& Transform(const Eigen::Matrix4d& transformation) override;
97  virtual ccBBox& Translate(const Eigen::Vector3d& translation,
98  bool relative = true) override;
99  virtual ccBBox& Scale(const double s,
100  const Eigen::Vector3d& center) override;
101  virtual ccBBox& Rotate(const Eigen::Matrix3d& R,
102  const Eigen::Vector3d& center) override;
103 
104  const ccBBox& operator+=(const ccBBox& other);
105 
106  // CCVector3: must override to fix candidate template ignored:
107  // could not match 'QStringBuilder' against 'Vector3Tpl
108  const ccBBox& operator+=(const CCVector3& V) override;
109  const ccBBox& operator-=(const CCVector3& V) override;
110  const ccBBox& operator*=(float scaleFactor) override;
111  const ccBBox& operator*=(const cloudViewer::SquareMatrix& mat) override;
112 
113  // Eigen::Vector3d
114  const ccBBox& operator+=(const Eigen::Vector3d& V);
115  const ccBBox& operator-=(const Eigen::Vector3d& V);
116  const ccBBox& operator*=(double scaleFactor);
117  const ccBBox& operator*=(const Eigen::Matrix3d& mat);
118 
119 public:
120  // Inherited from ccHObject - override to avoid hiding base class method
121  void draw(CC_DRAW_CONTEXT& context) override;
122 
124 
128 
130  std::string GetPrintInfo() const;
131 
132  inline void SetMinBounds(const Eigen::Vector3d& minBound) {
133  m_bbMin = minBound;
134  }
135  inline void SetMaxBounds(const Eigen::Vector3d& maxBound) {
136  m_bbMax = maxBound;
137  }
138 
142  static ccBBox CreateFromPoints(const std::vector<CCVector3>& points);
143 
144  static ccBBox CreateFromPoints(const std::vector<Eigen::Vector3d>& points);
145 
147  inline Eigen::Vector3d GetExtent() const {
149  }
150 
152  Eigen::Vector3d GetHalfExtent() const { return GetExtent() * 0.5; }
153 
157  return (m_bbMax - m_bbMin).maxCoeff();
158  }
159 
161  std::vector<Eigen::Vector3d> GetBoxPoints() const;
162 };
float PointCoordinateType
Type of the coordinates of a (N-D) point.
Definition: CVTypes.h:16
int64_t CV_CLASS_ENUM
Type of object type flags (64 bits)
Definition: CVTypes.h:97
#define CV_DB_LIB_API
Definition: CV_db.h:15
std::string name
int points
static Vector3Tpl fromArray(const int a[3])
Constructor from an int array.
Definition: CVGeom.h:268
Bounding box structure.
Definition: ecvBBox.h:25
const ccBBox operator*(const ccGLMatrixd &mat)
Applies transformation to the bounding box.
const ccBBox operator*(const ccGLMatrix &mat)
Applies transformation to the bounding box.
void draw(CC_DRAW_CONTEXT &context) override
Draws entity and its children.
const ccBBox & operator*=(double scaleFactor)
virtual ccBBox & Translate(const Eigen::Vector3d &translation, bool relative=true) override
Apply translation to the geometry coordinates.
virtual ecvOrientedBBox GetOrientedBoundingBox() const override
PointCoordinateType GetMaxExtent() const
Definition: ecvBBox.h:156
const ccBBox & operator+=(const Eigen::Vector3d &V)
virtual ccBBox & Scale(const double s, const Eigen::Vector3d &center) override
Apply scaling to the geometry coordinates. Given a scaling factor , and center , a given point is tr...
ccBBox(const cloudViewer::BoundingBox &bbox, const std::string &name="ccBBox")
Constructor from two vectors (lower min. and upper max. corners)
Definition: ecvBBox.h:48
virtual Eigen::Vector3d GetMaxBound() const override
Returns max bounds for geometry coordinates.
Definition: ecvBBox.h:84
void SetMinBounds(const Eigen::Vector3d &minBound)
Definition: ecvBBox.h:132
void draw(CC_DRAW_CONTEXT &context, const ecvColor::Rgb &col)
Draws bounding box (OpenGL)
ccBBox(const CCVector3 &bbMinCorner, const CCVector3 &bbMaxCorner, const std::string &name="ccBBox")
Constructor from two vectors (lower min. and upper max. corners)
Definition: ecvBBox.h:31
Eigen::Vector3d GetExtent() const
Get the extent/length of the bounding box in x, y, and z dimension.
Definition: ecvBBox.h:147
const ccBBox & operator+=(const CCVector3 &V) override
ccBBox()
Default constructor.
Definition: ecvBBox.h:28
std::string GetPrintInfo() const
Returns the 3D dimensions of the bounding box in string format.
const ccBBox & operator*=(const cloudViewer::SquareMatrix &mat) override
const ccBBox & operator-=(const Eigen::Vector3d &V)
virtual ccBBox GetAxisAlignedBoundingBox() const override
Returns an axis-aligned bounding box of the geometry.
Definition: ecvBBox.h:91
CV_CLASS_ENUM getClassID() const override
Returns unique class ID.
Definition: ecvBBox.h:62
virtual ccBBox & Transform(const Eigen::Matrix4d &transformation) override
Apply transformation (4x4 matrix) to the geometry coordinates.
virtual ccBBox getOwnBB(bool withGLFeatures=false) override
Returns the entity's own bounding-box.
Definition: ecvBBox.h:64
virtual ccBBox & Rotate(const Eigen::Matrix3d &R, const Eigen::Vector3d &center) override
Apply rotation to the geometry coordinates and normals. Given a rotation matrix , and center ,...
const ccBBox & operator+=(const ccBBox &other)
~ccBBox() override=default
virtual Eigen::Vector3d GetMinBound() const override
Returns min bounds for geometry coordinates.
Definition: ecvBBox.h:81
const ccBBox & operator*=(float scaleFactor) override
Scales the bounding box.
Eigen::Vector3d GetHalfExtent() const
Returns the half extent of the bounding box.
Definition: ecvBBox.h:152
const ccBBox & operator-=(const CCVector3 &V) override
ccBBox(const Eigen::Vector3d &min_bound, const Eigen::Vector3d &max_bound, const std::string &name="ccBBox")
Parameterized constructor.
Definition: ecvBBox.h:41
static ccBBox CreateFromPoints(const std::vector< CCVector3 > &points)
const ccBBox & operator*=(const Eigen::Matrix3d &mat)
static ccBBox CreateFromPoints(const std::vector< Eigen::Vector3d > &points)
virtual Eigen::Vector3d GetCenter() const override
Returns the center of the geometry coordinates.
Definition: ecvBBox.h:87
bool isSerializable() const override
Returns whether object is serializable of not.
Definition: ecvBBox.h:60
void SetMaxBounds(const Eigen::Vector3d &maxBound)
Definition: ecvBBox.h:135
std::vector< Eigen::Vector3d > GetBoxPoints() const
Returns the eight points that define the bounding box.
virtual bool IsEmpty() const override
Definition: ecvBBox.h:72
Float version of ccGLMatrixTpl.
Definition: ecvGLMatrix.h:19
Double version of ccGLMatrixTpl.
Definition: ecvGLMatrix.h:56
Hierarchical CLOUDVIEWER Object.
Definition: ecvHObject.h:25
Vector3Tpl< PointCoordinateType > getDiagVec() const
Returns diagonal vector.
Definition: BoundingBox.h:169
Vector3Tpl< PointCoordinateType > getCenter() const
Returns center.
Definition: BoundingBox.h:164
PointCoordinateType getMaxBoxDim() const
Returns maximal box dimension.
Definition: BoundingBox.h:185
bool isValid() const
Returns whether bounding box is valid or not.
Definition: BoundingBox.h:203
RGB color structure.
Definition: ecvColorTypes.h:49
ImGuiContext * context
Definition: Window.cpp:76
@ BBOX
Definition: CVTypes.h:154
Generic file read and write utility for python interface.
BoundingBoxTpl< PointCoordinateType > BoundingBox
Default bounding-box type.
Definition: BoundingBox.h:304
Display context.