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