ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
OrientedBoundingBox.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 
8 #include "OrientedBoundingBox.h"
9 
10 #include "CVLog.h"
11 
12 // EIGEN
13 #include <Eigen/Eigenvalues>
14 
15 // STL
16 #include <algorithm>
17 #include <cstdint>
18 #include <numeric>
19 
20 using namespace cloudViewer;
21 
23  center_.setZero();
24  extent_.setZero();
25  R_ = Eigen::Matrix3d::Identity();
26  color_.setZero();
27  return *this;
28 }
29 
31  return extent_(0) * extent_(1) * extent_(2);
32 }
33 
34 std::vector<Eigen::Vector3d> OrientedBoundingBox::GetBoxPoints() const {
35  Eigen::Vector3d x_axis = R_ * Eigen::Vector3d(extent_(0) / 2, 0, 0);
36  Eigen::Vector3d y_axis = R_ * Eigen::Vector3d(0, extent_(1) / 2, 0);
37  Eigen::Vector3d z_axis = R_ * Eigen::Vector3d(0, 0, extent_(2) / 2);
38  std::vector<Eigen::Vector3d> points(8);
39  points[0] = center_ - x_axis - y_axis - z_axis;
40  points[1] = center_ + x_axis - y_axis - z_axis;
41  points[2] = center_ - x_axis + y_axis - z_axis;
42  points[3] = center_ - x_axis - y_axis + z_axis;
43  points[4] = center_ + x_axis + y_axis + z_axis;
44  points[5] = center_ - x_axis + y_axis + z_axis;
45  points[6] = center_ + x_axis - y_axis + z_axis;
46  points[7] = center_ + x_axis + y_axis - z_axis;
47  return points;
48 }
49 
51  const std::vector<Eigen::Vector3d>& points) const {
54 }
55 
57  const std::vector<CCVector3>& points) const {
58  std::vector<size_t> indices;
59  Eigen::Vector3d dx = R_ * Eigen::Vector3d(1, 0, 0);
60  Eigen::Vector3d dy = R_ * Eigen::Vector3d(0, 1, 0);
61  Eigen::Vector3d dz = R_ * Eigen::Vector3d(0, 0, 1);
62  Eigen::Vector3d halfExtent = GetHalfExtent();
63  for (size_t idx = 0; idx < points.size(); idx++) {
64  Eigen::Vector3d d = CCVector3d::fromArray(points[idx]) - center_;
65  if (std::abs(d.dot(dx)) <= halfExtent(0) &&
66  std::abs(d.dot(dy)) <= halfExtent(1) &&
67  std::abs(d.dot(dz)) <= halfExtent(2)) {
68  indices.push_back(idx);
69  }
70  }
71  return indices;
72 }
73 
75  const BoundingBox& aabox) {
77  obox.center_ = CCVector3d::fromArray(aabox.getCenter());
79  obox.R_ = Eigen::Matrix3d::Identity();
80  return obox;
81 }
int points
static Vector3Tpl fromArray(const int a[3])
Constructor from an int array.
Definition: CVGeom.h:268
static std::vector< Eigen::Matrix< double, 3, 1 > > fromArrayContainer(const std::vector< Vector3Tpl< PointCoordinateType >> &container)
Definition: CVGeom.h:301
Vector3Tpl< T > getDiagVec() const
Returns diagonal vector.
Definition: BoundingBox.h:169
Vector3Tpl< T > getCenter() const
Returns center.
Definition: BoundingBox.h:164
A bounding box oriented along an arbitrary frame of reference.
Eigen::Vector3d color_
The color of the bounding box in RGB.
Eigen::Vector3d GetHalfExtent() const
Returns the half extent of the bounding box in its frame of reference.
Eigen::Vector3d extent_
The extent of the bounding box in its frame of reference.
std::vector< Eigen::Vector3d > GetBoxPoints() const
static OrientedBoundingBox CreateFromAxisAlignedBoundingBox(const BoundingBox &aabox)
double volume() const
Returns the volume of the bounding box.
Eigen::Vector3d center_
The center point of the bounding box.
std::vector< size_t > GetPointIndicesWithinBoundingBox(const std::vector< Eigen::Vector3d > &points) const
Return indices to points that are within the bounding box.
__host__ __device__ int2 abs(int2 v)
Definition: cutil_math.h:1267
Generic file read and write utility for python interface.