BV_splitter.cpp
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 
39 
40 namespace coal {
41 
42 template <typename BV>
43 void computeSplitVector(const BV& bv, Vec3s& split_vector) {
44  split_vector = bv.axes.col(0);
45 }
46 
47 template <>
48 void computeSplitVector<kIOS>(const kIOS& bv, Vec3s& split_vector) {
49  /*
50  switch(bv.num_spheres)
51  {
52  case 1:
53  split_vector = Vec3s(1, 0, 0);
54  break;
55  case 3:
56  {
57  Vec3s v[3];
58  v[0] = bv.spheres[1].o - bv.spheres[0].o;
59  v[0].normalize();
60  generateCoordinateSystem(v[0], v[1], v[2]);
61  split_vector = v[1];
62  }
63  break;
64  case 5:
65  {
66  Vec3s v[2];
67  v[0] = bv.spheres[1].o - bv.spheres[0].o;
68  v[1] = bv.spheres[3].o - bv.spheres[0].o;
69  split_vector = v[0].cross(v[1]);
70  split_vector.normalize();
71  }
72  break;
73  default:
74  ;
75  }
76  */
77  split_vector = bv.obb.axes.col(0);
78 }
79 
80 template <>
81 void computeSplitVector<OBBRSS>(const OBBRSS& bv, Vec3s& split_vector) {
82  split_vector = bv.obb.axes.col(0);
83 }
84 
85 template <typename BV>
86 void computeSplitValue_bvcenter(const BV& bv, CoalScalar& split_value) {
87  Vec3s center = bv.center();
88  split_value = center[0];
89 }
90 
91 template <typename BV>
92 void computeSplitValue_mean(const BV&, Vec3s* vertices, Triangle* triangles,
93  unsigned int* primitive_indices,
94  unsigned int num_primitives, BVHModelType type,
95  const Vec3s& split_vector,
96  CoalScalar& split_value) {
97  if (type == BVH_MODEL_TRIANGLES) {
98  Vec3s c(Vec3s::Zero());
99 
100  for (unsigned int i = 0; i < num_primitives; ++i) {
101  const Triangle& t = triangles[primitive_indices[i]];
102  const Vec3s& p1 = vertices[t[0]];
103  const Vec3s& p2 = vertices[t[1]];
104  const Vec3s& p3 = vertices[t[2]];
105 
106  c += p1 + p2 + p3;
107  }
108  split_value = c.dot(split_vector) / (3 * num_primitives);
109  } else if (type == BVH_MODEL_POINTCLOUD) {
110  CoalScalar sum = 0;
111  for (unsigned int i = 0; i < num_primitives; ++i) {
112  const Vec3s& p = vertices[primitive_indices[i]];
113  sum += p.dot(split_vector);
114  }
115 
116  split_value = sum / num_primitives;
117  }
118 }
119 
120 template <typename BV>
121 void computeSplitValue_median(const BV&, Vec3s* vertices, Triangle* triangles,
122  unsigned int* primitive_indices,
123  unsigned int num_primitives, BVHModelType type,
124  const Vec3s& split_vector,
125  CoalScalar& split_value) {
126  std::vector<CoalScalar> proj(num_primitives);
127 
128  if (type == BVH_MODEL_TRIANGLES) {
129  for (unsigned int i = 0; i < num_primitives; ++i) {
130  const Triangle& t = triangles[primitive_indices[i]];
131  const Vec3s& p1 = vertices[t[0]];
132  const Vec3s& p2 = vertices[t[1]];
133  const Vec3s& p3 = vertices[t[2]];
134  Vec3s centroid3(p1[0] + p2[0] + p3[0], p1[1] + p2[1] + p3[1],
135  p1[2] + p2[2] + p3[2]);
136 
137  proj[i] = centroid3.dot(split_vector) / 3;
138  }
139  } else if (type == BVH_MODEL_POINTCLOUD) {
140  for (unsigned int i = 0; i < num_primitives; ++i) {
141  const Vec3s& p = vertices[primitive_indices[i]];
142  Vec3s v(p[0], p[1], p[2]);
143  proj[i] = v.dot(split_vector);
144  }
145  }
146 
147  std::sort(proj.begin(), proj.end());
148 
149  if (num_primitives % 2 == 1) {
150  split_value = proj[(num_primitives - 1) / 2];
151  } else {
152  split_value = (proj[num_primitives / 2] + proj[num_primitives / 2 - 1]) / 2;
153  }
154 }
155 
156 template <>
157 void BVSplitter<OBB>::computeRule_bvcenter(const OBB& bv, unsigned int*,
158  unsigned int) {
159  computeSplitVector<OBB>(bv, split_vector);
160  computeSplitValue_bvcenter<OBB>(bv, split_value);
161 }
162 
163 template <>
165  unsigned int* primitive_indices,
166  unsigned int num_primitives) {
167  computeSplitVector<OBB>(bv, split_vector);
168  computeSplitValue_mean<OBB>(bv, vertices, tri_indices, primitive_indices,
169  num_primitives, type, split_vector, split_value);
170 }
171 
172 template <>
174  unsigned int* primitive_indices,
175  unsigned int num_primitives) {
176  computeSplitVector<OBB>(bv, split_vector);
177  computeSplitValue_median<OBB>(bv, vertices, tri_indices, primitive_indices,
178  num_primitives, type, split_vector,
179  split_value);
180 }
181 
182 template <>
183 void BVSplitter<RSS>::computeRule_bvcenter(const RSS& bv, unsigned int*,
184  unsigned int) {
185  computeSplitVector<RSS>(bv, split_vector);
186  computeSplitValue_bvcenter<RSS>(bv, split_value);
187 }
188 
189 template <>
191  unsigned int* primitive_indices,
192  unsigned int num_primitives) {
193  computeSplitVector<RSS>(bv, split_vector);
194  computeSplitValue_mean<RSS>(bv, vertices, tri_indices, primitive_indices,
195  num_primitives, type, split_vector, split_value);
196 }
197 
198 template <>
200  unsigned int* primitive_indices,
201  unsigned int num_primitives) {
202  computeSplitVector<RSS>(bv, split_vector);
203  computeSplitValue_median<RSS>(bv, vertices, tri_indices, primitive_indices,
204  num_primitives, type, split_vector,
205  split_value);
206 }
207 
208 template <>
209 void BVSplitter<kIOS>::computeRule_bvcenter(const kIOS& bv, unsigned int*,
210  unsigned int) {
211  computeSplitVector<kIOS>(bv, split_vector);
212  computeSplitValue_bvcenter<kIOS>(bv, split_value);
213 }
214 
215 template <>
217  unsigned int* primitive_indices,
218  unsigned int num_primitives) {
219  computeSplitVector<kIOS>(bv, split_vector);
220  computeSplitValue_mean<kIOS>(bv, vertices, tri_indices, primitive_indices,
221  num_primitives, type, split_vector, split_value);
222 }
223 
224 template <>
226  unsigned int* primitive_indices,
227  unsigned int num_primitives) {
228  computeSplitVector<kIOS>(bv, split_vector);
229  computeSplitValue_median<kIOS>(bv, vertices, tri_indices, primitive_indices,
230  num_primitives, type, split_vector,
231  split_value);
232 }
233 
234 template <>
235 void BVSplitter<OBBRSS>::computeRule_bvcenter(const OBBRSS& bv, unsigned int*,
236  unsigned int) {
237  computeSplitVector<OBBRSS>(bv, split_vector);
238  computeSplitValue_bvcenter<OBBRSS>(bv, split_value);
239 }
240 
241 template <>
243  unsigned int* primitive_indices,
244  unsigned int num_primitives) {
245  computeSplitVector<OBBRSS>(bv, split_vector);
246  computeSplitValue_mean<OBBRSS>(bv, vertices, tri_indices, primitive_indices,
247  num_primitives, type, split_vector,
248  split_value);
249 }
250 
251 template <>
253  unsigned int* primitive_indices,
254  unsigned int num_primitives) {
255  computeSplitVector<OBBRSS>(bv, split_vector);
256  computeSplitValue_median<OBBRSS>(bv, vertices, tri_indices, primitive_indices,
257  num_primitives, type, split_vector,
258  split_value);
259 }
260 
261 template <>
262 bool BVSplitter<OBB>::apply(const Vec3s& q) const {
263  return split_vector.dot(Vec3s(q[0], q[1], q[2])) > split_value;
264 }
265 
266 template <>
267 bool BVSplitter<RSS>::apply(const Vec3s& q) const {
268  return split_vector.dot(Vec3s(q[0], q[1], q[2])) > split_value;
269 }
270 
271 template <>
272 bool BVSplitter<kIOS>::apply(const Vec3s& q) const {
273  return split_vector.dot(Vec3s(q[0], q[1], q[2])) > split_value;
274 }
275 
276 template <>
277 bool BVSplitter<OBBRSS>::apply(const Vec3s& q) const {
278  return split_vector.dot(Vec3s(q[0], q[1], q[2])) > split_value;
279 }
280 
281 template class BVSplitter<RSS>;
282 template class BVSplitter<OBBRSS>;
283 template class BVSplitter<OBB>;
284 template class BVSplitter<kIOS>;
285 
286 } // namespace coal
coal::computeSplitValue_median
void computeSplitValue_median(const BV &, Vec3s *vertices, Triangle *triangles, unsigned int *primitive_indices, unsigned int num_primitives, BVHModelType type, const Vec3s &split_vector, CoalScalar &split_value)
Definition: BV_splitter.cpp:121
coal::Vec3s
Eigen::Matrix< CoalScalar, 3, 1 > Vec3s
Definition: coal/data_types.h:77
doxygen_xml_parser.type
type
Definition: doxygen_xml_parser.py:885
coal::computeSplitVector
void computeSplitVector(const BV &bv, Vec3s &split_vector)
Definition: BV_splitter.cpp:43
coal::BVHModelType
BVHModelType
BVH model type.
Definition: coal/BVH/BVH_internal.h:79
coal::BVSplitter::computeRule_bvcenter
void computeRule_bvcenter(const BV &bv, unsigned int *, unsigned int)
Split algorithm 1: Split the node from center.
Definition: coal/internal/BV_splitter.h:128
coal::OBB::axes
EIGEN_MAKE_ALIGNED_OPERATOR_NEW Matrix3s axes
Orientation of OBB. axis[i] is the ith column of the orientation matrix for the box; it is also the i...
Definition: include/coal/BV/OBB.h:59
coal
Main namespace.
Definition: coal/broadphase/broadphase_bruteforce.h:44
coal::OBBRSS::obb
EIGEN_MAKE_ALIGNED_OPERATOR_NEW OBB obb
OBB member, for rotation.
Definition: coal/BV/OBBRSS.h:57
coal::computeSplitVector< kIOS >
void computeSplitVector< kIOS >(const kIOS &bv, Vec3s &split_vector)
Definition: BV_splitter.cpp:48
coal::kIOS
A class describing the kIOS collision structure, which is a set of spheres.
Definition: coal/BV/kIOS.h:52
coal::BVSplitter
A class describing the split rule that splits each BV node.
Definition: coal/BVH/BVH_model.h:61
coal::computeSplitValue_mean
void computeSplitValue_mean(const BV &, Vec3s *vertices, Triangle *triangles, unsigned int *primitive_indices, unsigned int num_primitives, BVHModelType type, const Vec3s &split_vector, CoalScalar &split_value)
Definition: BV_splitter.cpp:92
coal::BVH_MODEL_POINTCLOUD
@ BVH_MODEL_POINTCLOUD
triangle model
Definition: coal/BVH/BVH_internal.h:82
coal::BVH_MODEL_TRIANGLES
@ BVH_MODEL_TRIANGLES
unknown model type
Definition: coal/BVH/BVH_internal.h:81
coal::OBBRSS
Class merging the OBB and RSS, can handle collision and distance simultaneously.
Definition: coal/BV/OBBRSS.h:53
c
c
coal::computeSplitValue_bvcenter
void computeSplitValue_bvcenter(const BV &bv, CoalScalar &split_value)
Definition: BV_splitter.cpp:86
q
q
BV_splitter.h
octree.p1
tuple p1
Definition: octree.py:54
coal::BVSplitter::computeRule_mean
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: coal/internal/BV_splitter.h:143
coal::BVSplitter::apply
bool apply(const Vec3s &q) const
Apply the split rule on a given point.
Definition: coal/internal/BV_splitter.h:93
coal::kIOS::obb
OBB obb
@ OBB related with kIOS
Definition: coal/BV/kIOS.h:122
coal::OBB
Oriented bounding box class.
Definition: include/coal/BV/OBB.h:51
coal::Triangle
Triangle with 3 indices for points.
Definition: coal/data_types.h:111
t
dictionary t
coal::RSS
A class for rectangle sphere-swept bounding volume.
Definition: coal/BV/RSS.h:53
coal::CoalScalar
double CoalScalar
Definition: coal/data_types.h:76
coal::computeSplitVector< OBBRSS >
void computeSplitVector< OBBRSS >(const OBBRSS &bv, Vec3s &split_vector)
Definition: BV_splitter.cpp:81
obb.v
list v
Definition: obb.py:48
coal::BVSplitter::computeRule_median
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: coal/internal/BV_splitter.h:174


hpp-fcl
Author(s):
autogenerated on Sat Nov 23 2024 03:44:57