coal 3.0.1
Coal, The Collision Detection Library. Previously known as HPP-FCL, fork of FCL -- The Flexible Collision Library
Loading...
Searching...
No Matches
BV_splitter.h
Go to the documentation of this file.
1/*
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2011-2014, Willow Garage, Inc.
5 * Copyright (c) 2014-2015, Open Source Robotics Foundation
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer in the documentation and/or other materials provided
17 * with the distribution.
18 * * Neither the name of Open Source Robotics Foundation nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
34 */
35
38#ifndef COAL_BV_SPLITTER_H
39#define COAL_BV_SPLITTER_H
40
42#include "coal/BV/kIOS.h"
43#include "coal/BV/OBBRSS.h"
44#include <vector>
45#include <iostream>
46
47namespace coal {
48
55
57template <typename BV>
59 public:
62
64 virtual ~BVSplitter() {}
65
68 vertices = vertices_;
70 type = type_;
71 }
72
75 void computeRule(const BV& bv, unsigned int* primitive_indices,
76 unsigned int num_primitives) {
77 switch (split_method) {
79 computeRule_mean(bv, primitive_indices, num_primitives);
80 break;
82 computeRule_median(bv, primitive_indices, num_primitives);
83 break;
85 computeRule_bvcenter(bv, primitive_indices, num_primitives);
86 break;
87 default:
88 std::cerr << "Split method not supported" << std::endl;
89 }
90 }
91
93 bool apply(const Vec3s& q) const { return q[split_axis] > split_value; }
94
96 void clear() {
97 vertices = NULL;
100 }
101
102 protected:
109
114
117
120
123
126
128 void computeRule_bvcenter(const BV& bv, unsigned int*, unsigned int) {
129 Vec3s center = bv.center();
130 int axis = 2;
131
132 if (bv.width() >= bv.height() && bv.width() >= bv.depth())
133 axis = 0;
134 else if (bv.height() >= bv.width() && bv.height() >= bv.depth())
135 axis = 1;
136
138 split_value = center[axis];
139 }
140
143 void computeRule_mean(const BV& bv, unsigned int* primitive_indices,
144 unsigned int num_primitives) {
145 int axis = 2;
146
147 if (bv.width() >= bv.height() && bv.width() >= bv.depth())
148 axis = 0;
149 else if (bv.height() >= bv.width() && bv.height() >= bv.depth())
150 axis = 1;
151
153 Scalar sum = 0;
154
155 if (type == BVH_MODEL_TRIANGLES) {
156 for (unsigned int i = 0; i < num_primitives; ++i) {
157 const Triangle32& t = tri_indices[primitive_indices[i]];
158 sum += (vertices[t[0]][split_axis] + vertices[t[1]][split_axis] +
159 vertices[t[2]][split_axis]);
160 }
161
162 sum /= 3;
163 } else if (type == BVH_MODEL_POINTCLOUD) {
164 for (unsigned int i = 0; i < num_primitives; ++i) {
165 sum += vertices[primitive_indices[i]][split_axis];
166 }
167 }
168
169 split_value = sum / Scalar(num_primitives);
170 }
171
174 void computeRule_median(const BV& bv, unsigned int* primitive_indices,
175 unsigned int num_primitives) {
176 int axis = 2;
177
178 if (bv.width() >= bv.height() && bv.width() >= bv.depth())
179 axis = 0;
180 else if (bv.height() >= bv.width() && bv.height() >= bv.depth())
181 axis = 1;
182
184 std::vector<Scalar> proj((size_t)num_primitives);
185
186 if (type == BVH_MODEL_TRIANGLES) {
187 for (unsigned int i = 0; i < num_primitives; ++i) {
188 const Triangle32& t = tri_indices[primitive_indices[i]];
189 proj[i] = (vertices[t[0]][split_axis] + vertices[t[1]][split_axis] +
190 vertices[t[2]][split_axis]) /
191 3;
192 }
193 } else if (type == BVH_MODEL_POINTCLOUD) {
194 for (unsigned int i = 0; i < num_primitives; ++i)
195 proj[i] = vertices[primitive_indices[i]][split_axis];
196 }
197
198 std::sort(proj.begin(), proj.end());
199
200 if (num_primitives % 2 == 1) {
201 split_value = proj[(num_primitives - 1) / 2];
202 } else {
204 (proj[num_primitives / 2] + proj[num_primitives / 2 - 1]) / 2;
205 }
206 }
207};
208
209template <>
211
212template <>
214
215template <>
217
218template <>
220
221template <>
223 const OBB& bv, unsigned int* primitive_indices,
224 unsigned int num_primitives);
225
226template <>
228 const OBB& bv, unsigned int* primitive_indices,
229 unsigned int num_primitives);
230
231template <>
233 const OBB& bv, unsigned int* primitive_indices,
234 unsigned int num_primitives);
235
236template <>
238 const RSS& bv, unsigned int* primitive_indices,
239 unsigned int num_primitives);
240
241template <>
243 const RSS& bv, unsigned int* primitive_indices,
244 unsigned int num_primitives);
245
246template <>
248 const RSS& bv, unsigned int* primitive_indices,
249 unsigned int num_primitives);
250
251template <>
253 const kIOS& bv, unsigned int* primitive_indices,
254 unsigned int num_primitives);
255
256template <>
258 const kIOS& bv, unsigned int* primitive_indices,
259 unsigned int num_primitives);
260
261template <>
263 const kIOS& bv, unsigned int* primitive_indices,
264 unsigned int num_primitives);
265
266template <>
268 const OBBRSS& bv, unsigned int* primitive_indices,
269 unsigned int num_primitives);
270
271template <>
273 const OBBRSS& bv, unsigned int* primitive_indices,
274 unsigned int num_primitives);
275
276template <>
278 const OBBRSS& bv, unsigned int* primitive_indices,
279 unsigned int num_primitives);
280
281} // namespace coal
282
283#endif
A class describing the split rule that splits each BV node.
Definition BV_splitter.h:58
virtual ~BVSplitter()
Default deconstructor.
Definition BV_splitter.h:64
BVSplitter(SplitMethodType method)
Definition BV_splitter.h:60
void computeRule(const BV &bv, unsigned int *primitive_indices, unsigned int num_primitives)
Compute the split rule according to a subset of geometry and the corresponding BV node.
Definition BV_splitter.h:75
void clear()
Clear the geometry data set before.
Definition BV_splitter.h:96
void set(Vec3s *vertices_, Triangle32 *tri_indices_, BVHModelType type_)
Set the geometry data needed by the split rule.
Definition BV_splitter.h:67
Vec3s * vertices
The mesh vertices or points handled by the splitter.
Definition BV_splitter.h:116
void computeRule_bvcenter(const BV &bv, unsigned int *, unsigned int)
Split algorithm 1: Split the node from center.
Definition BV_splitter.h:128
Triangle32 * tri_indices
The triangles handled by the splitter.
Definition BV_splitter.h:119
bool apply(const Vec3s &q) const
Apply the split rule on a given point.
Definition BV_splitter.h:93
Vec3s split_vector
Definition BV_splitter.h:108
void computeRule_median(const BV &bv, unsigned int *primitive_indices, unsigned int num_primitives)
Split algorithm 3: Split the node according to the median of the data contained.
Definition BV_splitter.h:174
int split_axis
The axis based on which the split decision is made. For most BV, the axis is aligned with one of the ...
Definition BV_splitter.h:107
Scalar split_value
The split threshold, different primitives are splitted according whether their projection on the spli...
Definition BV_splitter.h:113
BVHModelType type
Whether the geometry is mesh or point cloud.
Definition BV_splitter.h:122
SplitMethodType split_method
The split algorithm used.
Definition BV_splitter.h:125
void computeRule_mean(const BV &bv, unsigned int *primitive_indices, unsigned int num_primitives)
Split algorithm 2: Split the node according to the mean of the data contained.
Definition BV_splitter.h:143
Triangle with 3 indices for points.
Definition data_types.h:122
A class describing the kIOS collision structure, which is a set of spheres.
Definition kIOS.h:52
#define COAL_DLLAPI
Definition config.hh:88
Main namespace.
Definition broadphase_bruteforce.h:44
BVHModelType
BVH model type.
Definition BVH_internal.h:79
@ BVH_MODEL_POINTCLOUD
triangle model
Definition BVH_internal.h:82
@ BVH_MODEL_TRIANGLES
unknown model type
Definition BVH_internal.h:81
@ BVH_MODEL_UNKNOWN
Definition BVH_internal.h:80
SplitMethodType
Three types of split algorithms are provided in FCL as default.
Definition BV_splitter.h:50
@ SPLIT_METHOD_BV_CENTER
Definition BV_splitter.h:53
@ SPLIT_METHOD_MEAN
Definition BV_splitter.h:51
@ SPLIT_METHOD_MEDIAN
Definition BV_splitter.h:52
Eigen::Matrix< Scalar, 3, 1 > Vec3s
Definition data_types.h:70
double Scalar
Definition data_types.h:68
Class merging the OBB and RSS, can handle collision and distance simultaneously.
Definition OBBRSS.h:53
Oriented bounding box class.
Definition OBB.h:51
A class for rectangle sphere-swept bounding volume.
Definition RSS.h:53