1
+ #include < Eigen/Eigenvalues>
2
+ #include < numeric>
3
+
1
4
#include " cupoch/geometry/boundingvolume.h"
2
5
#include " cupoch/geometry/pointcloud.h"
3
6
#include " cupoch/geometry/trianglemesh.h"
4
- #include " cupoch/utility/platform.h"
5
7
#include " cupoch/utility/console.h"
6
-
7
- #include < numeric>
8
-
9
- #include < Eigen/Eigenvalues>
8
+ #include " cupoch/utility/platform.h"
10
9
11
10
using namespace cupoch ;
12
11
using namespace cupoch ::geometry;
13
12
14
13
namespace {
15
14
16
15
struct check_within_oriented_bounding_box_functor {
17
- check_within_oriented_bounding_box_functor (const Eigen::Vector3f* points,
18
- const std::array<Eigen::Vector3f, 8 >& box_points)
19
- : points_(points), box_points_(box_points) {};
20
- const Eigen::Vector3f* points_;
16
+ check_within_oriented_bounding_box_functor (
17
+ const Eigen::Vector3f *points,
18
+ const std::array<Eigen::Vector3f, 8 > &box_points)
19
+ : points_(points), box_points_(box_points){};
20
+ const Eigen::Vector3f *points_;
21
21
const std::array<Eigen::Vector3f, 8 > box_points_;
22
- __device__
23
- float test_plane (const Eigen::Vector3f& a, const Eigen::Vector3f& b,
24
- const Eigen::Vector3f c, const Eigen::Vector3f& x) const {
22
+ __device__ float test_plane (const Eigen::Vector3f &a,
23
+ const Eigen::Vector3f &b,
24
+ const Eigen::Vector3f c,
25
+ const Eigen::Vector3f &x) const {
25
26
Eigen::Matrix3f design;
26
27
design << (b - a), (c - a), (x - a);
27
28
return design.determinant ();
28
29
};
29
- __device__
30
- bool operator ()(size_t idx) const {
31
- const Eigen::Vector3f& point = points_[idx];
32
- return (test_plane (box_points_[0 ], box_points_[1 ], box_points_[3 ], point) <=
33
- 0 &&
34
- test_plane (box_points_[0 ], box_points_[5 ], box_points_[3 ], point) >=
35
- 0 &&
36
- test_plane (box_points_[2 ], box_points_[5 ], box_points_[7 ], point) <=
37
- 0 &&
38
- test_plane (box_points_[1 ], box_points_[4 ], box_points_[7 ], point) >=
39
- 0 &&
40
- test_plane (box_points_[3 ], box_points_[4 ], box_points_[5 ], point) <=
41
- 0 &&
42
- test_plane (box_points_[0 ], box_points_[1 ], box_points_[7 ], point) >=
43
- 0 );
30
+ __device__ bool operator ()(size_t idx) const {
31
+ const Eigen::Vector3f &point = points_[idx];
32
+ return (test_plane (box_points_[0 ], box_points_[1 ], box_points_[3 ],
33
+ point) <= 0 &&
34
+ test_plane (box_points_[0 ], box_points_[5 ], box_points_[3 ],
35
+ point) >= 0 &&
36
+ test_plane (box_points_[2 ], box_points_[5 ], box_points_[7 ],
37
+ point) <= 0 &&
38
+ test_plane (box_points_[1 ], box_points_[4 ], box_points_[7 ],
39
+ point) >= 0 &&
40
+ test_plane (box_points_[3 ], box_points_[4 ], box_points_[5 ],
41
+ point) <= 0 &&
42
+ test_plane (box_points_[0 ], box_points_[1 ], box_points_[7 ],
43
+ point) >= 0 );
44
44
}
45
45
};
46
46
47
47
struct check_within_axis_aligned_bounding_box_functor {
48
- check_within_axis_aligned_bounding_box_functor (const Eigen::Vector3f* points,
49
- const Eigen::Vector3f& min_bound,
50
- const Eigen::Vector3f& max_bound)
51
- : points_(points), min_bound_(min_bound), max_bound_(max_bound) {};
52
- const Eigen::Vector3f* points_;
48
+ check_within_axis_aligned_bounding_box_functor (
49
+ const Eigen::Vector3f *points,
50
+ const Eigen::Vector3f &min_bound,
51
+ const Eigen::Vector3f &max_bound)
52
+ : points_(points), min_bound_(min_bound), max_bound_(max_bound){};
53
+ const Eigen::Vector3f *points_;
53
54
const Eigen::Vector3f min_bound_;
54
55
const Eigen::Vector3f max_bound_;
55
- __device__
56
- bool operator () (size_t idx) const {
57
- const Eigen::Vector3f& point = points_[idx];
56
+ __device__ bool operator ()(size_t idx) const {
57
+ const Eigen::Vector3f &point = points_[idx];
58
58
return (point (0 ) >= min_bound_ (0 ) && point (0 ) <= max_bound_ (0 ) &&
59
59
point (1 ) >= min_bound_ (1 ) && point (1 ) <= max_bound_ (1 ) &&
60
60
point (2 ) >= min_bound_ (2 ) && point (2 ) <= max_bound_ (2 ));
61
61
}
62
62
};
63
63
64
- }
64
+ } // namespace
65
65
66
- OrientedBoundingBox& OrientedBoundingBox::Clear () {
66
+ OrientedBoundingBox & OrientedBoundingBox::Clear () {
67
67
center_.setZero ();
68
68
extent_.setZero ();
69
69
R_ = Eigen::Matrix3f::Identity ();
@@ -93,16 +93,16 @@ OrientedBoundingBox OrientedBoundingBox::GetOrientedBoundingBox() const {
93
93
return *this ;
94
94
}
95
95
96
- OrientedBoundingBox& OrientedBoundingBox::Transform (
97
- const Eigen::Matrix4f& transformation) {
96
+ OrientedBoundingBox & OrientedBoundingBox::Transform (
97
+ const Eigen::Matrix4f & transformation) {
98
98
utility::LogError (
99
99
" A general transform of an OrientedBoundingBox is not implemented. "
100
100
" Call Translate, Scale, and Rotate." );
101
101
return *this ;
102
102
}
103
103
104
- OrientedBoundingBox& OrientedBoundingBox::Translate (
105
- const Eigen::Vector3f& translation, bool relative) {
104
+ OrientedBoundingBox & OrientedBoundingBox::Translate (
105
+ const Eigen::Vector3f & translation, bool relative) {
106
106
if (relative) {
107
107
center_ += translation;
108
108
} else {
@@ -111,7 +111,7 @@ OrientedBoundingBox& OrientedBoundingBox::Translate(
111
111
return *this ;
112
112
}
113
113
114
- OrientedBoundingBox& OrientedBoundingBox::Scale (const float scale,
114
+ OrientedBoundingBox & OrientedBoundingBox::Scale (const float scale,
115
115
bool center) {
116
116
if (center) {
117
117
extent_ *= scale;
@@ -122,7 +122,7 @@ OrientedBoundingBox& OrientedBoundingBox::Scale(const float scale,
122
122
return *this ;
123
123
}
124
124
125
- OrientedBoundingBox& OrientedBoundingBox::Rotate (const Eigen::Matrix3f& R,
125
+ OrientedBoundingBox & OrientedBoundingBox::Rotate (const Eigen::Matrix3f & R,
126
126
bool center) {
127
127
if (center) {
128
128
R_ *= R;
@@ -153,27 +153,30 @@ std::array<Eigen::Vector3f, 8> OrientedBoundingBox::GetBoxPoints() const {
153
153
return points;
154
154
}
155
155
156
- utility::device_vector<size_t > OrientedBoundingBox::GetPointIndicesWithinBoundingBox (
157
- const utility::device_vector<Eigen::Vector3f>& points) const {
156
+ utility::device_vector<size_t >
157
+ OrientedBoundingBox::GetPointIndicesWithinBoundingBox (
158
+ const utility::device_vector<Eigen::Vector3f> &points) const {
158
159
auto box_points = GetBoxPoints ();
159
- check_within_oriented_bounding_box_functor func (thrust::raw_pointer_cast (points.data ()), box_points);
160
+ check_within_oriented_bounding_box_functor func (
161
+ thrust::raw_pointer_cast (points.data ()), box_points);
160
162
utility::device_vector<size_t > indices (points.size ());
161
- auto end = thrust::copy_if (thrust::make_counting_iterator<size_t >(0 ), thrust::make_counting_iterator (points.size ()),
163
+ auto end = thrust::copy_if (thrust::make_counting_iterator<size_t >(0 ),
164
+ thrust::make_counting_iterator (points.size ()),
162
165
indices.begin (), func);
163
166
indices.resize (thrust::distance (indices.begin (), end));
164
167
return indices;
165
168
}
166
169
167
170
OrientedBoundingBox OrientedBoundingBox::CreateFromAxisAlignedBoundingBox (
168
- const AxisAlignedBoundingBox& aabox) {
171
+ const AxisAlignedBoundingBox & aabox) {
169
172
OrientedBoundingBox obox;
170
173
obox.center_ = aabox.GetCenter ();
171
174
obox.extent_ = aabox.GetExtent ();
172
175
obox.R_ = Eigen::Matrix3f::Identity ();
173
176
return obox;
174
177
}
175
178
176
- AxisAlignedBoundingBox& AxisAlignedBoundingBox::Clear () {
179
+ AxisAlignedBoundingBox & AxisAlignedBoundingBox::Clear () {
177
180
min_bound_.setZero ();
178
181
max_bound_.setZero ();
179
182
return *this ;
@@ -201,16 +204,16 @@ OrientedBoundingBox AxisAlignedBoundingBox::GetOrientedBoundingBox() const {
201
204
return OrientedBoundingBox::CreateFromAxisAlignedBoundingBox (*this );
202
205
}
203
206
204
- AxisAlignedBoundingBox& AxisAlignedBoundingBox::Transform (
205
- const Eigen::Matrix4f& transformation) {
207
+ AxisAlignedBoundingBox & AxisAlignedBoundingBox::Transform (
208
+ const Eigen::Matrix4f & transformation) {
206
209
utility::LogError (
207
210
" A general transform of a AxisAlignedBoundingBox would not be axis "
208
211
" aligned anymore, convert it to a OrientedBoundingBox first" );
209
212
return *this ;
210
213
}
211
214
212
- AxisAlignedBoundingBox& AxisAlignedBoundingBox::Translate (
213
- const Eigen::Vector3f& translation, bool relative) {
215
+ AxisAlignedBoundingBox & AxisAlignedBoundingBox::Translate (
216
+ const Eigen::Vector3f & translation, bool relative) {
214
217
if (relative) {
215
218
min_bound_ += translation;
216
219
max_bound_ += translation;
@@ -222,7 +225,7 @@ AxisAlignedBoundingBox& AxisAlignedBoundingBox::Translate(
222
225
return *this ;
223
226
}
224
227
225
- AxisAlignedBoundingBox& AxisAlignedBoundingBox::Scale (const float scale,
228
+ AxisAlignedBoundingBox & AxisAlignedBoundingBox::Scale (const float scale,
226
229
bool center) {
227
230
if (center) {
228
231
Eigen::Vector3f center = GetCenter ();
@@ -235,8 +238,8 @@ AxisAlignedBoundingBox& AxisAlignedBoundingBox::Scale(const float scale,
235
238
return *this ;
236
239
}
237
240
238
- AxisAlignedBoundingBox& AxisAlignedBoundingBox::Rotate (
239
- const Eigen::Matrix3f& rotation, bool center) {
241
+ AxisAlignedBoundingBox & AxisAlignedBoundingBox::Rotate (
242
+ const Eigen::Matrix3f & rotation, bool center) {
240
243
utility::LogError (
241
244
" A rotation of a AxisAlignedBoundingBox would not be axis aligned "
242
245
" anymore, convert it to an OrientedBoundingBox first" );
@@ -249,8 +252,8 @@ std::string AxisAlignedBoundingBox::GetPrintInfo() const {
249
252
max_bound_ (0 ), max_bound_ (1 ), max_bound_ (2 ));
250
253
}
251
254
252
- AxisAlignedBoundingBox& AxisAlignedBoundingBox::operator +=(
253
- const AxisAlignedBoundingBox& other) {
255
+ AxisAlignedBoundingBox & AxisAlignedBoundingBox::operator +=(
256
+ const AxisAlignedBoundingBox & other) {
254
257
if (IsEmpty ()) {
255
258
min_bound_ = other.min_bound_ ;
256
259
max_bound_ = other.max_bound_ ;
@@ -262,7 +265,7 @@ AxisAlignedBoundingBox& AxisAlignedBoundingBox::operator+=(
262
265
}
263
266
264
267
AxisAlignedBoundingBox AxisAlignedBoundingBox::CreateFromPoints (
265
- const utility::device_vector<Eigen::Vector3f>& points) {
268
+ const utility::device_vector<Eigen::Vector3f> & points) {
266
269
AxisAlignedBoundingBox box;
267
270
if (points.empty ()) {
268
271
box.min_bound_ = Eigen::Vector3f (0.0 , 0.0 , 0.0 );
@@ -290,12 +293,14 @@ std::array<Eigen::Vector3f, 8> AxisAlignedBoundingBox::GetBoxPoints() const {
290
293
return points;
291
294
}
292
295
293
- utility::device_vector<size_t > AxisAlignedBoundingBox::GetPointIndicesWithinBoundingBox (
294
- const utility::device_vector<Eigen::Vector3f>& points) const {
296
+ utility::device_vector<size_t >
297
+ AxisAlignedBoundingBox::GetPointIndicesWithinBoundingBox (
298
+ const utility::device_vector<Eigen::Vector3f> &points) const {
295
299
utility::device_vector<size_t > indices (points.size ());
296
- check_within_axis_aligned_bounding_box_functor func (thrust::raw_pointer_cast (points.data ()),
297
- min_bound_, max_bound_);
298
- auto end = thrust::copy_if (thrust::make_counting_iterator<size_t >(0 ), thrust::make_counting_iterator (points.size ()),
300
+ check_within_axis_aligned_bounding_box_functor func (
301
+ thrust::raw_pointer_cast (points.data ()), min_bound_, max_bound_);
302
+ auto end = thrust::copy_if (thrust::make_counting_iterator<size_t >(0 ),
303
+ thrust::make_counting_iterator (points.size ()),
299
304
indices.begin (), func);
300
305
indices.resize (thrust::distance (indices.begin (), end));
301
306
return indices;
0 commit comments