38 #ifndef FCL_SHAPE_GEOMETRICSHAPETOBVHMODEL_INL_H 39 #define FCL_SHAPE_GEOMETRICSHAPETOBVHMODEL_INL_H 41 #include "fcl/geometry/geometric_shape_to_BVH_model.h" 50 using S =
typename BV::S;
55 std::vector<Vector3<S>> points(8);
56 std::vector<Triangle> tri_indices(12);
57 points[0] << 0.5 * a, -0.5 * b, 0.5 * c;
58 points[1] << 0.5 * a, 0.5 * b, 0.5 * c;
59 points[2] << -0.5 * a, 0.5 * b, 0.5 * c;
60 points[3] << -0.5 * a, -0.5 * b, 0.5 * c;
61 points[4] << 0.5 * a, -0.5 * b, -0.5 * c;
62 points[5] << 0.5 * a, 0.5 * b, -0.5 * c;
63 points[6] << -0.5 * a, 0.5 * b, -0.5 * c;
64 points[7] << -0.5 * a, -0.5 * b, -0.5 * c;
66 tri_indices[0].set(0, 4, 1);
67 tri_indices[1].set(1, 4, 5);
68 tri_indices[2].set(2, 6, 3);
69 tri_indices[3].set(3, 6, 7);
70 tri_indices[4].set(3, 0, 2);
71 tri_indices[5].set(2, 0, 1);
72 tri_indices[6].set(6, 5, 7);
73 tri_indices[7].set(7, 5, 4);
74 tri_indices[8].set(1, 5, 2);
75 tri_indices[9].set(2, 5, 6);
76 tri_indices[10].set(3, 7, 0);
77 tri_indices[11].set(0, 7, 4);
79 for(
unsigned int i = 0; i < points.size(); ++i)
81 points[i] = pose * points[i];
94 using S =
typename BV::S;
96 std::vector<Vector3<S>> points;
97 std::vector<Triangle> tri_indices;
106 thetad = pi / (ring + 1);
109 for(
unsigned int i = 0; i < ring; ++i)
111 S theta_ = theta + thetad * (i + 1);
112 for(
unsigned int j = 0; j < seg; ++j)
114 points.emplace_back(r * sin(theta_) * cos(phi + j * phid), r * sin(theta_) * sin(phi + j * phid), r * cos(theta_));
117 points.emplace_back(0, 0, r);
118 points.emplace_back(0, 0, -r);
120 for(
unsigned int i = 0; i < ring - 1; ++i)
122 for(
unsigned int j = 0; j < seg; ++j)
124 unsigned int a, b, c, d;
126 b = (j == seg - 1) ? (i * seg) : (i * seg + j + 1);
127 c = (i + 1) * seg + j;
128 d = (j == seg - 1) ? ((i + 1) * seg) : ((i + 1) * seg + j + 1);
129 tri_indices.emplace_back(a, c, b);
130 tri_indices.emplace_back(b, c, d);
134 for(
unsigned int j = 0; j < seg; ++j)
138 b = (j == seg - 1) ? 0 : (j + 1);
139 tri_indices.emplace_back(ring * seg, a, b);
141 a = (ring - 1) * seg + j;
142 b = (j == seg - 1) ? (ring - 1) * seg : ((ring - 1) * seg + j + 1);
143 tri_indices.emplace_back(a, ring * seg + 1, b);
146 for(
unsigned int i = 0; i < points.size(); ++i)
148 points[i] = pose * points[i];
158 template<
typename BV>
161 using S =
typename BV::S;
164 S n_low_bound = sqrtf(n_faces_for_unit_sphere / 2.0) * r * r;
165 unsigned int ring = ceil(n_low_bound);
166 unsigned int seg = ceil(n_low_bound);
172 template<
typename BV>
175 using S =
typename BV::S;
177 std::vector<Vector3<S>> points;
178 std::vector<Triangle> tri_indices;
180 const S& a = shape.
radii[0];
181 const S& b = shape.
radii[1];
182 const S& c = shape.
radii[2];
190 thetad = pi / (ring + 1);
193 for(
unsigned int i = 0; i < ring; ++i)
195 S theta_ = theta + thetad * (i + 1);
196 for(
unsigned int j = 0; j < seg; ++j)
198 points.emplace_back(a * sin(theta_) * cos(phi + j * phid), b * sin(theta_) * sin(phi + j * phid), c * cos(theta_));
201 points.emplace_back(0, 0, c);
202 points.emplace_back(0, 0, -c);
204 for(
unsigned int i = 0; i < ring - 1; ++i)
206 for(
unsigned int j = 0; j < seg; ++j)
208 unsigned int a, b, c, d;
210 b = (j == seg - 1) ? (i * seg) : (i * seg + j + 1);
211 c = (i + 1) * seg + j;
212 d = (j == seg - 1) ? ((i + 1) * seg) : ((i + 1) * seg + j + 1);
213 tri_indices.emplace_back(a, c, b);
214 tri_indices.emplace_back(b, c, d);
218 for(
unsigned int j = 0; j < seg; ++j)
222 b = (j == seg - 1) ? 0 : (j + 1);
223 tri_indices.emplace_back(ring * seg, a, b);
225 a = (ring - 1) * seg + j;
226 b = (j == seg - 1) ? (ring - 1) * seg : ((ring - 1) * seg + j + 1);
227 tri_indices.emplace_back(a, ring * seg + 1, b);
230 for(
unsigned int i = 0; i < points.size(); ++i)
232 points[i] = pose * points[i];
242 template<
typename BV>
245 using S =
typename BV::S;
249 const S& ap = std::pow(shape.
radii[0], p);
250 const S& bp = std::pow(shape.
radii[1], p);
251 const S& cp = std::pow(shape.
radii[2], p);
253 const S ratio = std::pow((ap * bp + bp * cp + cp * ap) / 3.0, 1.0 / p);
254 const S n_low_bound = std::sqrt(n_faces_for_unit_ellipsoid / 2.0) * ratio;
256 const unsigned int ring = std::ceil(n_low_bound);
257 const unsigned int seg = std::ceil(n_low_bound);
263 template<
typename BV>
266 using S =
typename BV::S;
268 std::vector<Vector3<S>> points;
269 std::vector<Triangle> tri_indices;
280 for(
unsigned int i = 0; i < tot; ++i)
281 points.emplace_back(r * cos(phi + phid * i), r * sin(phi + phid * i), h / 2);
283 for(
unsigned int i = 0; i < h_num - 1; ++i)
285 for(
unsigned int j = 0; j < tot; ++j)
287 points.emplace_back(r * cos(phi + phid * j), r * sin(phi + phid * j), h / 2 - (i + 1) * hd);
291 for(
unsigned int i = 0; i < tot; ++i)
292 points.emplace_back(r * cos(phi + phid * i), r * sin(phi + phid * i), - h / 2);
294 points.emplace_back(0, 0, h / 2);
295 points.emplace_back(0, 0, -h / 2);
297 for(
unsigned int i = 0; i < tot; ++i)
298 tri_indices.emplace_back((h_num + 1) * tot, i, ((i == tot - 1) ? 0 : (i + 1)));
300 for(
unsigned int i = 0; i < tot; ++i)
301 tri_indices.emplace_back((h_num + 1) * tot + 1, h_num * tot + ((i == tot - 1) ? 0 : (i + 1)), h_num * tot + i);
303 for(
unsigned int i = 0; i < h_num; ++i)
305 for(
unsigned int j = 0; j < tot; ++j)
309 b = (j == tot - 1) ? 0 : (j + 1);
311 d = (j == tot - 1) ? tot : (j + 1 + tot);
314 tri_indices.emplace_back(start + b, start + a, start + c);
315 tri_indices.emplace_back(start + b, start + c, start + d);
319 for(
unsigned int i = 0; i < points.size(); ++i)
321 points[i] = pose * points[i];
331 template<
typename BV>
334 using S =
typename BV::S;
340 unsigned int tot = tot_for_unit_cylinder * r;
341 S phid = pi * 2 / tot;
343 S circle_edge = phid * r;
344 unsigned int h_num = ceil(h / circle_edge);
351 template<
typename BV>
354 using S =
typename BV::S;
356 std::vector<Vector3<S>> points;
357 std::vector<Triangle> tri_indices;
369 for(
unsigned int i = 0; i < h_num - 1; ++i)
371 S h_i = h / 2 - (i + 1) * hd;
372 S rh = r * (0.5 - h_i / h);
373 for(
unsigned int j = 0; j < tot; ++j)
375 points.emplace_back(rh * cos(phi + phid * j), rh * sin(phi + phid * j), h_i);
379 for(
unsigned int i = 0; i < tot; ++i)
380 points.emplace_back(r * cos(phi + phid * i), r * sin(phi + phid * i), - h / 2);
382 points.emplace_back(0, 0, h / 2);
383 points.emplace_back(0, 0, -h / 2);
385 for(
unsigned int i = 0; i < tot; ++i)
386 tri_indices.emplace_back(h_num * tot, i, (i == tot - 1) ? 0 : (i + 1));
388 for(
unsigned int i = 0; i < tot; ++i)
389 tri_indices.emplace_back(h_num * tot + 1, (h_num - 1) * tot + ((i == tot - 1) ? 0 : (i + 1)), (h_num - 1) * tot + i);
391 for(
unsigned int i = 0; i < h_num - 1; ++i)
393 for(
unsigned int j = 0; j < tot; ++j)
397 b = (j == tot - 1) ? 0 : (j + 1);
399 d = (j == tot - 1) ? tot : (j + 1 + tot);
402 tri_indices.emplace_back(start + b, start + a, start + c);
403 tri_indices.emplace_back(start + b, start + c, start + d);
407 for(
unsigned int i = 0; i < points.size(); ++i)
409 points[i] = pose * points[i];
419 template<
typename BV>
422 using S =
typename BV::S;
428 unsigned int tot = tot_for_unit_cone * r;
429 S phid = pi * 2 / tot;
431 S circle_edge = phid * r;
432 unsigned int h_num = ceil(h / circle_edge);
void computeLocalAABB() override
Compute the AABB for the BVH, used for broad-phase collision.
Definition: BVH_model-inl.h:1063
int beginModel(int num_tris=0, int num_vertices=0)
Begin a new BVH model.
Definition: BVH_model-inl.h:205
Main namespace.
Definition: broadphase_bruteforce-inl.h:45
S radius
Radius of the cylinder.
Definition: cylinder.h:58
void generateBVHModel(BVHModel< BV > &model, const Box< typename BV::S > &shape, const Transform3< typename BV::S > &pose)
Generate BVH model from box.
Definition: geometric_shape_to_BVH_model-inl.h:48
Center at zero point ellipsoid.
Definition: ellipsoid.h:48
S lz
Length along z axis.
Definition: cylinder.h:61
int addSubModel(const std::vector< Vector3< S >> &ps, const std::vector< Triangle > &ts)
Add a set of triangles in the new BVH model.
Definition: BVH_model-inl.h:374
S lz
Length along z axis.
Definition: cone.h:60
Center at zero point, axis aligned box.
Definition: box.h:48
S radius
Radius of the cone.
Definition: cone.h:57
static constexpr S pi()
The mathematical constant pi.
Definition: constants.h:49
Vector3< S > side
box side length
Definition: box.h:64
A class describing the bounding hierarchy of a mesh model or a point cloud model (which is viewed as ...
Definition: BVH_model.h:57
Center at zero cylinder.
Definition: cylinder.h:48
Vector3< S > radii
Radii of the ellipsoid.
Definition: ellipsoid.h:61
Center at zero cone.
Definition: cone.h:48
int endModel()
End BVH model construction, will build the bounding volume hierarchy.
Definition: BVH_model-inl.h:437
S radius
Radius of the sphere.
Definition: sphere.h:57
Center at zero point sphere.
Definition: sphere.h:48