FCL  0.6.0
Flexible Collision Library
BV_splitter.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2011-2014, Willow Garage, Inc.
5  * Copyright (c) 2014-2016, 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 FCL_BV_SPLITTER_H
39 #define FCL_BV_SPLITTER_H
40 
41 #include <vector>
42 #include <iostream>
43 #include "fcl/math/triangle.h"
44 #include "fcl/math/bv/kIOS.h"
45 #include "fcl/math/bv/OBBRSS.h"
46 #include "fcl/geometry/bvh/BVH_internal.h"
47 #include "fcl/geometry/bvh/detail/BV_splitter_base.h"
48 
49 namespace fcl
50 {
51 
52 namespace detail
53 {
54 
56 enum SplitMethodType
57 {
58  SPLIT_METHOD_MEAN,
59  SPLIT_METHOD_MEDIAN,
60  SPLIT_METHOD_BV_CENTER
61 };
62 
64 template <typename BV>
65 class BVSplitter : public BVSplitterBase<BV>
66 {
67 public:
68 
69  using S = typename BV::S;
70 
71  BVSplitter(SplitMethodType method);
72 
74  virtual ~BVSplitter();
75 
77  void set(
78  Vector3<S>* vertices_, Triangle* tri_indices_, BVHModelType type_);
79 
82  void computeRule(
83  const BV& bv, unsigned int* primitive_indices, int num_primitives);
84 
86  bool apply(const Vector3<S>& q) const;
87 
89  void clear();
90 
91 private:
92 
97  int split_axis;
98  Vector3<S> split_vector;
99 
103  S split_value;
104 
106  Vector3<S>* vertices;
107 
109  Triangle* tri_indices;
110 
112  BVHModelType type;
113 
115  SplitMethodType split_method;
116 
118  void computeRule_bvcenter(
119  const BV& bv, unsigned int* primitive_indices, int num_primitives);
120 
123  void computeRule_mean(
124  const BV& bv, unsigned int* primitive_indices, int num_primitives);
125 
128  void computeRule_median(
129  const BV& bv, unsigned int* primitive_indices, int num_primitives);
130 
131  template <typename, typename>
132  friend struct ApplyImpl;
133 
134  template <typename, typename>
135  friend struct ComputeRuleCenterImpl;
136 
137  template <typename, typename>
138  friend struct ComputeRuleMeanImpl;
139 
140  template <typename, typename>
141  friend struct ComputeRuleMedianImpl;
142 };
143 
144 template <typename S, typename BV>
145 void computeSplitVector(const BV& bv, Vector3<S>& split_vector);
146 
147 template <typename S, typename BV>
148 void computeSplitValue_bvcenter(const BV& bv, S& split_value);
149 
150 template <typename S, typename BV>
151 void computeSplitValue_mean(
152  const BV& bv,
153  Vector3<S>* vertices,
154  Triangle* triangles,
155  unsigned int* primitive_indices,
156  int num_primitives,
157  BVHModelType type,
158  const Vector3<S>& split_vector,
159  S& split_value);
160 
161 template <typename S, typename BV>
162 void computeSplitValue_median(
163  const BV& bv,
164  Vector3<S>* vertices,
165  Triangle* triangles,
166  unsigned int* primitive_indices,
167  int num_primitives,
168  BVHModelType type,
169  const Vector3<S>& split_vector,
170  S& split_value);
171 
172 } // namespace detail
173 } // namespace fcl
174 
175 #include "fcl/geometry/bvh/detail/BV_splitter-inl.h"
176 
177 #endif
Base interface for BV splitting algorithm.
Definition: BV_splitter_base.h:56
Main namespace.
Definition: broadphase_bruteforce-inl.h:45
BVHModelType
BVH model type.
Definition: BVH_internal.h:75
virtual ~BVSplitter()
Default deconstructor.
Definition: BV_splitter-inl.h:59
void clear()
Clear the geometry data set before.
Definition: BV_splitter-inl.h:502
Definition: BV_splitter-inl.h:200
Triangle with 3 indices for points.
Definition: triangle.h:47
bool apply(const Vector3< S > &q) const
Apply the split rule on a given point.
Definition: BV_splitter-inl.h:108
void computeRule(const BV &bv, unsigned int *primitive_indices, int num_primitives)
Compute the split rule according to a subset of geometry and the corresponding BV node...
Definition: BV_splitter-inl.h:76
Definition: BV_splitter-inl.h:97
Definition: BV_splitter-inl.h:147
A class describing the split rule that splits each BV node.
Definition: BV_splitter.h:65
Definition: BV_splitter-inl.h:115