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 |
|
|
|
36 |
|
|
/** \author Jia Pan */ |
37 |
|
|
|
38 |
|
|
#ifndef HPP_FCL_BV_FITTER_H |
39 |
|
|
#define HPP_FCL_BV_FITTER_H |
40 |
|
|
|
41 |
|
|
#include <hpp/fcl/BVH/BVH_internal.h> |
42 |
|
|
#include <hpp/fcl/BV/kIOS.h> |
43 |
|
|
#include <hpp/fcl/BV/OBBRSS.h> |
44 |
|
|
#include <hpp/fcl/BV/AABB.h> |
45 |
|
|
#include <iostream> |
46 |
|
|
|
47 |
|
|
namespace hpp { |
48 |
|
|
namespace fcl { |
49 |
|
|
|
50 |
|
|
/// @brief Compute a bounding volume that fits a set of n points. |
51 |
|
|
template <typename BV> |
52 |
|
39240 |
void fit(Vec3f* ps, unsigned int n, BV& bv) { |
53 |
✓✓ |
156960 |
for (unsigned int i = 0; i < n; ++i) // TODO(jcarpent): vectorize |
54 |
|
|
{ |
55 |
|
117720 |
bv += ps[i]; |
56 |
|
|
} |
57 |
|
39240 |
} |
58 |
|
|
|
59 |
|
|
template <> |
60 |
|
|
void fit<OBB>(Vec3f* ps, unsigned int n, OBB& bv); |
61 |
|
|
|
62 |
|
|
template <> |
63 |
|
|
void fit<RSS>(Vec3f* ps, unsigned int n, RSS& bv); |
64 |
|
|
|
65 |
|
|
template <> |
66 |
|
|
void fit<kIOS>(Vec3f* ps, unsigned int n, kIOS& bv); |
67 |
|
|
|
68 |
|
|
template <> |
69 |
|
|
void fit<OBBRSS>(Vec3f* ps, unsigned int n, OBBRSS& bv); |
70 |
|
|
|
71 |
|
|
template <> |
72 |
|
|
void fit<AABB>(Vec3f* ps, unsigned int n, AABB& bv); |
73 |
|
|
|
74 |
|
|
/// @brief The class for the default algorithm fitting a bounding volume to a |
75 |
|
|
/// set of points |
76 |
|
|
template <typename BV> |
77 |
|
|
class HPP_FCL_DLLAPI BVFitterTpl { |
78 |
|
|
public: |
79 |
|
|
/// @brief default deconstructor |
80 |
|
6070 |
virtual ~BVFitterTpl() {} |
81 |
|
|
|
82 |
|
|
/// @brief Prepare the geometry primitive data for fitting |
83 |
|
6338 |
void set(Vec3f* vertices_, Triangle* tri_indices_, BVHModelType type_) { |
84 |
|
6338 |
vertices = vertices_; |
85 |
|
6338 |
prev_vertices = NULL; |
86 |
|
6338 |
tri_indices = tri_indices_; |
87 |
|
6338 |
type = type_; |
88 |
|
6338 |
} |
89 |
|
|
|
90 |
|
|
/// @brief Prepare the geometry primitive data for fitting, for deformable |
91 |
|
|
/// mesh |
92 |
|
136 |
void set(Vec3f* vertices_, Vec3f* prev_vertices_, Triangle* tri_indices_, |
93 |
|
|
BVHModelType type_) { |
94 |
|
136 |
vertices = vertices_; |
95 |
|
136 |
prev_vertices = prev_vertices_; |
96 |
|
136 |
tri_indices = tri_indices_; |
97 |
|
136 |
type = type_; |
98 |
|
|
} |
99 |
|
|
|
100 |
|
|
/// @brief Compute the fitting BV |
101 |
|
|
virtual BV fit(unsigned int* primitive_indices, |
102 |
|
|
unsigned int num_primitives) = 0; |
103 |
|
|
|
104 |
|
|
/// @brief Clear the geometry primitive data |
105 |
|
6474 |
void clear() { |
106 |
|
6474 |
vertices = NULL; |
107 |
|
6474 |
prev_vertices = NULL; |
108 |
|
6474 |
tri_indices = NULL; |
109 |
|
6474 |
type = BVH_MODEL_UNKNOWN; |
110 |
|
6474 |
} |
111 |
|
|
|
112 |
|
|
protected: |
113 |
|
|
Vec3f* vertices; |
114 |
|
|
Vec3f* prev_vertices; |
115 |
|
|
Triangle* tri_indices; |
116 |
|
|
BVHModelType type; |
117 |
|
|
}; |
118 |
|
|
|
119 |
|
|
/// @brief The class for the default algorithm fitting a bounding volume to a |
120 |
|
|
/// set of points |
121 |
|
|
template <typename BV> |
122 |
|
|
class HPP_FCL_DLLAPI BVFitter : public BVFitterTpl<BV> { |
123 |
|
|
typedef BVFitterTpl<BV> Base; |
124 |
|
|
|
125 |
|
|
public: |
126 |
|
|
/// @brief Compute a bounding volume that fits a set of primitives (points or |
127 |
|
|
/// triangles). The primitive data was set by set function and |
128 |
|
|
/// primitive_indices is the primitive index relative to the data |
129 |
|
493014 |
BV fit(unsigned int* primitive_indices, unsigned int num_primitives) { |
130 |
|
493014 |
BV bv; |
131 |
|
|
|
132 |
|
493014 |
if (type == BVH_MODEL_TRIANGLES) /// The primitive is triangle |
133 |
|
|
{ |
134 |
|
3599952 |
for (unsigned int i = 0; i < num_primitives; ++i) { |
135 |
|
3107028 |
Triangle t = tri_indices[primitive_indices[i]]; |
136 |
|
3107028 |
bv += vertices[t[0]]; |
137 |
|
3107028 |
bv += vertices[t[1]]; |
138 |
|
3107028 |
bv += vertices[t[2]]; |
139 |
|
|
|
140 |
|
3107028 |
if (prev_vertices) /// can fitting both current and previous frame |
141 |
|
|
{ |
142 |
|
|
bv += prev_vertices[t[0]]; |
143 |
|
|
bv += prev_vertices[t[1]]; |
144 |
|
|
bv += prev_vertices[t[2]]; |
145 |
|
|
} |
146 |
|
|
} |
147 |
|
90 |
} else if (type == BVH_MODEL_POINTCLOUD) /// The primitive is point |
148 |
|
|
{ |
149 |
|
282 |
for (unsigned int i = 0; i < num_primitives; ++i) { |
150 |
|
192 |
bv += vertices[primitive_indices[i]]; |
151 |
|
|
|
152 |
|
192 |
if (prev_vertices) /// can fitting both current and previous frame |
153 |
|
|
{ |
154 |
|
|
bv += prev_vertices[primitive_indices[i]]; |
155 |
|
|
} |
156 |
|
|
} |
157 |
|
|
} |
158 |
|
|
|
159 |
|
493014 |
return bv; |
160 |
|
|
} |
161 |
|
|
|
162 |
|
|
protected: |
163 |
|
|
using Base::prev_vertices; |
164 |
|
|
using Base::tri_indices; |
165 |
|
|
using Base::type; |
166 |
|
|
using Base::vertices; |
167 |
|
|
}; |
168 |
|
|
|
169 |
|
|
/// @brief Specification of BVFitter for OBB bounding volume |
170 |
|
|
template <> |
171 |
|
|
class HPP_FCL_DLLAPI BVFitter<OBB> : public BVFitterTpl<OBB> { |
172 |
|
|
public: |
173 |
|
|
/// @brief Compute a bounding volume that fits a set of primitives (points or |
174 |
|
|
/// triangles). The primitive data was set by set function and |
175 |
|
|
/// primitive_indices is the primitive index relative to the data. |
176 |
|
|
OBB fit(unsigned int* primitive_indices, unsigned int num_primitives); |
177 |
|
|
}; |
178 |
|
|
|
179 |
|
|
/// @brief Specification of BVFitter for RSS bounding volume |
180 |
|
|
template <> |
181 |
|
|
class HPP_FCL_DLLAPI BVFitter<RSS> : public BVFitterTpl<RSS> { |
182 |
|
|
public: |
183 |
|
|
/// @brief Compute a bounding volume that fits a set of primitives (points or |
184 |
|
|
/// triangles). The primitive data was set by set function and |
185 |
|
|
/// primitive_indices is the primitive index relative to the data. |
186 |
|
|
RSS fit(unsigned int* primitive_indices, unsigned int num_primitives); |
187 |
|
|
}; |
188 |
|
|
|
189 |
|
|
/// @brief Specification of BVFitter for kIOS bounding volume |
190 |
|
|
template <> |
191 |
|
|
class HPP_FCL_DLLAPI BVFitter<kIOS> : public BVFitterTpl<kIOS> { |
192 |
|
|
public: |
193 |
|
|
/// @brief Compute a bounding volume that fits a set of primitives (points or |
194 |
|
|
/// triangles). The primitive data was set by set function and |
195 |
|
|
/// primitive_indices is the primitive index relative to the data. |
196 |
|
|
kIOS fit(unsigned int* primitive_indices, unsigned int num_primitives); |
197 |
|
|
}; |
198 |
|
|
|
199 |
|
|
/// @brief Specification of BVFitter for OBBRSS bounding volume |
200 |
|
|
template <> |
201 |
|
|
class HPP_FCL_DLLAPI BVFitter<OBBRSS> : public BVFitterTpl<OBBRSS> { |
202 |
|
|
public: |
203 |
|
|
/// @brief Compute a bounding volume that fits a set of primitives (points or |
204 |
|
|
/// triangles). The primitive data was set by set function and |
205 |
|
|
/// primitive_indices is the primitive index relative to the data. |
206 |
|
|
OBBRSS fit(unsigned int* primitive_indices, unsigned int num_primitives); |
207 |
|
|
}; |
208 |
|
|
|
209 |
|
|
/// @brief Specification of BVFitter for AABB bounding volume |
210 |
|
|
template <> |
211 |
|
|
class HPP_FCL_DLLAPI BVFitter<AABB> : public BVFitterTpl<AABB> { |
212 |
|
|
public: |
213 |
|
|
/// @brief Compute a bounding volume that fits a set of primitives (points or |
214 |
|
|
/// triangles). The primitive data was set by set function and |
215 |
|
|
/// primitive_indices is the primitive index relative to the data. |
216 |
|
|
AABB fit(unsigned int* primitive_indices, unsigned int num_primitives); |
217 |
|
|
}; |
218 |
|
|
|
219 |
|
|
} // namespace fcl |
220 |
|
|
|
221 |
|
|
} // namespace hpp |
222 |
|
|
|
223 |
|
|
#endif |