coal/internal/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 
41 #include "coal/BVH/BVH_internal.h"
42 #include "coal/BV/kIOS.h"
43 #include "coal/BV/OBBRSS.h"
44 #include <vector>
45 #include <iostream>
46 
47 namespace coal {
48 
54 };
55 
57 template <typename BV>
58 class BVSplitter {
59  public:
61  : split_vector(0, 0, 0), split_method(method) {}
62 
64  virtual ~BVSplitter() {}
65 
67  void set(Vec3s* vertices_, Triangle* tri_indices_, BVHModelType type_) {
68  vertices = vertices_;
69  tri_indices = tri_indices_;
70  type = type_;
71  }
72 
75  void computeRule(const BV& bv, unsigned int* primitive_indices,
76  unsigned int num_primitives) {
77  switch (split_method) {
78  case SPLIT_METHOD_MEAN:
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;
98  tri_indices = 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 
137  split_axis = axis;
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 
152  split_axis = axis;
153  CoalScalar sum = 0;
154 
155  if (type == BVH_MODEL_TRIANGLES) {
156  for (unsigned int i = 0; i < num_primitives; ++i) {
157  const Triangle& 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 / 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 
183  split_axis = axis;
184  std::vector<CoalScalar> proj((size_t)num_primitives);
185 
186  if (type == BVH_MODEL_TRIANGLES) {
187  for (unsigned int i = 0; i < num_primitives; ++i) {
188  const Triangle& 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 {
203  split_value =
204  (proj[num_primitives / 2] + proj[num_primitives / 2 - 1]) / 2;
205  }
206  }
207 };
208 
209 template <>
210 bool COAL_DLLAPI BVSplitter<OBB>::apply(const Vec3s& q) const;
211 
212 template <>
213 bool COAL_DLLAPI BVSplitter<RSS>::apply(const Vec3s& q) const;
214 
215 template <>
216 bool COAL_DLLAPI BVSplitter<kIOS>::apply(const Vec3s& q) const;
217 
218 template <>
219 bool COAL_DLLAPI BVSplitter<OBBRSS>::apply(const Vec3s& q) const;
220 
221 template <>
223  const OBB& bv, unsigned int* primitive_indices,
224  unsigned int num_primitives);
225 
226 template <>
227 void COAL_DLLAPI BVSplitter<OBB>::computeRule_mean(
228  const OBB& bv, unsigned int* primitive_indices,
229  unsigned int num_primitives);
230 
231 template <>
232 void COAL_DLLAPI BVSplitter<OBB>::computeRule_median(
233  const OBB& bv, unsigned int* primitive_indices,
234  unsigned int num_primitives);
235 
236 template <>
238  const RSS& bv, unsigned int* primitive_indices,
239  unsigned int num_primitives);
240 
241 template <>
242 void COAL_DLLAPI BVSplitter<RSS>::computeRule_mean(
243  const RSS& bv, unsigned int* primitive_indices,
244  unsigned int num_primitives);
245 
246 template <>
247 void COAL_DLLAPI BVSplitter<RSS>::computeRule_median(
248  const RSS& bv, unsigned int* primitive_indices,
249  unsigned int num_primitives);
250 
251 template <>
253  const kIOS& bv, unsigned int* primitive_indices,
254  unsigned int num_primitives);
255 
256 template <>
257 void COAL_DLLAPI BVSplitter<kIOS>::computeRule_mean(
258  const kIOS& bv, unsigned int* primitive_indices,
259  unsigned int num_primitives);
260 
261 template <>
262 void COAL_DLLAPI BVSplitter<kIOS>::computeRule_median(
263  const kIOS& bv, unsigned int* primitive_indices,
264  unsigned int num_primitives);
265 
266 template <>
268  const OBBRSS& bv, unsigned int* primitive_indices,
269  unsigned int num_primitives);
270 
271 template <>
272 void COAL_DLLAPI BVSplitter<OBBRSS>::computeRule_mean(
273  const OBBRSS& bv, unsigned int* primitive_indices,
274  unsigned int num_primitives);
275 
276 template <>
278  const OBBRSS& bv, unsigned int* primitive_indices,
279  unsigned int num_primitives);
280 
281 } // namespace coal
282 
283 #endif
coal::BVH_MODEL_UNKNOWN
@ BVH_MODEL_UNKNOWN
Definition: coal/BVH/BVH_internal.h:80
coal::BVSplitter::split_method
SplitMethodType split_method
The split algorithm used.
Definition: coal/internal/BV_splitter.h:125
coal::Vec3s
Eigen::Matrix< CoalScalar, 3, 1 > Vec3s
Definition: coal/data_types.h:77
coal::BVHModelType
BVHModelType
BVH model type.
Definition: coal/BVH/BVH_internal.h:79
coal::SplitMethodType
SplitMethodType
Three types of split algorithms are provided in FCL as default.
Definition: coal/internal/BV_splitter.h:50
coal::BVSplitter::~BVSplitter
virtual ~BVSplitter()
Default deconstructor.
Definition: coal/internal/BV_splitter.h:64
coal::BVSplitter::BVSplitter
BVSplitter(SplitMethodType method)
Definition: coal/internal/BV_splitter.h:60
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::BVSplitter::split_vector
Vec3s split_vector
Definition: coal/internal/BV_splitter.h:108
coal
Main namespace.
Definition: coal/broadphase/broadphase_bruteforce.h:44
coal::BVSplitter::clear
void clear()
Clear the geometry data set before.
Definition: coal/internal/BV_splitter.h:96
coal::SPLIT_METHOD_MEAN
@ SPLIT_METHOD_MEAN
Definition: coal/internal/BV_splitter.h:51
coal::BVSplitter::split_value
CoalScalar split_value
The split threshold, different primitives are splitted according whether their projection on the spli...
Definition: coal/internal/BV_splitter.h:113
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::BVSplitter::vertices
Vec3s * vertices
The mesh vertices or points handled by the splitter.
Definition: coal/internal/BV_splitter.h:116
coal::SPLIT_METHOD_MEDIAN
@ SPLIT_METHOD_MEDIAN
Definition: coal/internal/BV_splitter.h:52
axis
axis
q
q
kIOS.h
BVH_internal.h
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::type
BVHModelType type
Whether the geometry is mesh or point cloud.
Definition: coal/internal/BV_splitter.h:122
coal::BVSplitter::apply
bool apply(const Vec3s &q) const
Apply the split rule on a given point.
Definition: coal/internal/BV_splitter.h:93
OBBRSS.h
coal::BVSplitter::tri_indices
Triangle * tri_indices
The triangles handled by the splitter.
Definition: coal/internal/BV_splitter.h:119
coal::BVSplitter::computeRule
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: coal/internal/BV_splitter.h:75
coal::Triangle
Triangle with 3 indices for points.
Definition: coal/data_types.h:111
t
dictionary t
coal::CoalScalar
double CoalScalar
Definition: coal/data_types.h:76
coal::BVSplitter::set
void set(Vec3s *vertices_, Triangle *tri_indices_, BVHModelType type_)
Set the geometry data needed by the split rule.
Definition: coal/internal/BV_splitter.h:67
coal::SPLIT_METHOD_BV_CENTER
@ SPLIT_METHOD_BV_CENTER
Definition: coal/internal/BV_splitter.h:53
coal::BVSplitter::split_axis
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: coal/internal/BV_splitter.h:107
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