38 #ifndef COAL_GEOMETRIC_SHAPE_TO_BVH_MODEL_H
39 #define COAL_GEOMETRIC_SHAPE_TO_BVH_MODEL_H
43 #include <boost/math/constants/constants.hpp>
48 template <
typename BV>
54 std::vector<Vec3s> points(8);
55 std::vector<Triangle> tri_indices(12);
56 points[0] =
Vec3s(a, -b, c);
57 points[1] =
Vec3s(a, b, c);
58 points[2] =
Vec3s(-a, b, c);
59 points[3] =
Vec3s(-a, -b, c);
60 points[4] =
Vec3s(a, -b, -c);
61 points[5] =
Vec3s(a, b, -c);
62 points[6] =
Vec3s(-a, b, -c);
63 points[7] =
Vec3s(-a, -b, -c);
65 tri_indices[0].set(0, 4, 1);
66 tri_indices[1].set(1, 4, 5);
67 tri_indices[2].set(2, 6, 3);
68 tri_indices[3].set(3, 6, 7);
69 tri_indices[4].set(3, 0, 2);
70 tri_indices[5].set(2, 0, 1);
71 tri_indices[6].set(6, 5, 7);
72 tri_indices[7].set(7, 5, 4);
73 tri_indices[8].set(1, 5, 2);
74 tri_indices[9].set(2, 5, 6);
75 tri_indices[10].set(3, 7, 0);
76 tri_indices[11].set(0, 7, 4);
78 for (
unsigned int i = 0; i < points.size(); ++i) {
79 points[i] = pose.
transform(points[i]).eval();
90 template <
typename BV>
94 std::vector<Vec3s> points;
95 std::vector<Triangle> tri_indices;
99 const CoalScalar pi = boost::math::constants::pi<CoalScalar>();
104 thetad = pi / (ring + 1);
107 for (
unsigned int i = 0; i < ring; ++i) {
109 for (
unsigned int j = 0; j < seg; ++j) {
110 points.push_back(
Vec3s(r * sin(theta_) * cos(phi + j * phid),
111 r * sin(theta_) * sin(phi + j * phid),
115 points.push_back(
Vec3s(0, 0, r));
116 points.push_back(
Vec3s(0, 0, -r));
118 for (
unsigned int i = 0; i < ring - 1; ++i) {
119 for (
unsigned int j = 0; j < seg; ++j) {
120 unsigned int a, b, c, d;
122 b = (j == seg - 1) ? (i * seg) : (i * seg + j + 1);
123 c = (i + 1) * seg + j;
124 d = (j == seg - 1) ? ((i + 1) * seg) : ((i + 1) * seg + j + 1);
125 tri_indices.push_back(
Triangle(a, c, b));
126 tri_indices.push_back(
Triangle(b, c, d));
130 for (
unsigned int j = 0; j < seg; ++j) {
133 b = (j == seg - 1) ? 0 : (j + 1);
134 tri_indices.push_back(
Triangle(ring * seg, a, b));
136 a = (ring - 1) * seg + j;
137 b = (j == seg - 1) ? (ring - 1) * seg : ((ring - 1) * seg + j + 1);
138 tri_indices.push_back(
Triangle(a, ring * seg + 1, b));
141 for (
unsigned int i = 0; i < points.size(); ++i) {
156 template <
typename BV>
159 unsigned int n_faces_for_unit_sphere) {
163 unsigned int ring = (
unsigned int)ceil(n_low_bound);
164 unsigned int seg = (
unsigned int)ceil(n_low_bound);
171 template <
typename BV>
174 unsigned int h_num) {
175 std::vector<Vec3s> points;
176 std::vector<Triangle> tri_indices;
181 const CoalScalar pi = boost::math::constants::pi<CoalScalar>();
187 for (
unsigned int i = 0; i < tot; ++i)
189 Vec3s(r * cos(phi + phid * i), r * sin(phi + phid * i), h));
191 for (
unsigned int i = 0; i < h_num - 1; ++i) {
192 for (
unsigned int j = 0; j < tot; ++j) {
193 points.push_back(
Vec3s(r * cos(phi + phid * j), r * sin(phi + phid * j),
198 for (
unsigned int i = 0; i < tot; ++i)
200 Vec3s(r * cos(phi + phid * i), r * sin(phi + phid * i), -h));
202 points.push_back(
Vec3s(0, 0, h));
203 points.push_back(
Vec3s(0, 0, -h));
205 for (
unsigned int i = 0; i < tot; ++i) {
206 Triangle tmp((h_num + 1) * tot, i, ((i == tot - 1) ? 0 : (i + 1)));
207 tri_indices.push_back(tmp);
210 for (
unsigned int i = 0; i < tot; ++i) {
212 h_num * tot + ((i == tot - 1) ? 0 : (i + 1)), h_num * tot + i);
213 tri_indices.push_back(tmp);
216 for (
unsigned int i = 0; i < h_num; ++i) {
217 for (
unsigned int j = 0; j < tot; ++j) {
218 unsigned int a, b, c, d;
220 b = (j == tot - 1) ? 0 : (j + 1);
222 d = (j == tot - 1) ? tot : (j + 1 + tot);
224 unsigned int start = i * tot;
225 tri_indices.push_back(
Triangle(start + b, start + a, start + c));
226 tri_indices.push_back(
Triangle(start + b, start + c, start + d));
230 for (
unsigned int i = 0; i < points.size(); ++i) {
244 template <
typename BV>
247 unsigned int tot_for_unit_cylinder) {
251 const CoalScalar pi = boost::math::constants::pi<CoalScalar>();
252 unsigned int tot = (
unsigned int)(tot_for_unit_cylinder * r);
256 unsigned int h_num = (
unsigned int)ceil(h / circle_edge);
263 template <
typename BV>
266 unsigned int h_num) {
267 std::vector<Vec3s> points;
268 std::vector<Triangle> tri_indices;
274 const CoalScalar pi = boost::math::constants::pi<CoalScalar>();
280 for (
unsigned int i = 0; i < h_num - 1; ++i) {
283 for (
unsigned int j = 0; j < tot; ++j) {
285 Vec3s(rh * cos(phi + phid * j), rh * sin(phi + phid * j), h_i));
289 for (
unsigned int i = 0; i < tot; ++i)
291 Vec3s(r * cos(phi + phid * i), r * sin(phi + phid * i), -h));
293 points.push_back(
Vec3s(0, 0, h));
294 points.push_back(
Vec3s(0, 0, -h));
296 for (
unsigned int i = 0; i < tot; ++i) {
297 Triangle tmp(h_num * tot, i, (i == tot - 1) ? 0 : (i + 1));
298 tri_indices.push_back(tmp);
301 for (
unsigned int i = 0; i < tot; ++i) {
303 (h_num - 1) * tot + ((i == tot - 1) ? 0 : (i + 1)),
304 (h_num - 1) * tot + i);
305 tri_indices.push_back(tmp);
308 for (
unsigned int i = 0; i < h_num - 1; ++i) {
309 for (
unsigned int j = 0; j < tot; ++j) {
310 unsigned int a, b, c, d;
312 b = (j == tot - 1) ? 0 : (j + 1);
314 d = (j == tot - 1) ? tot : (j + 1 + tot);
316 unsigned int start = i * tot;
317 tri_indices.push_back(
Triangle(start + b, start + a, start + c));
318 tri_indices.push_back(
Triangle(start + b, start + c, start + d));
322 for (
unsigned int i = 0; i < points.size(); ++i) {
336 template <
typename BV>
338 const Transform3s& pose,
unsigned int tot_for_unit_cone) {
342 const CoalScalar pi = boost::math::constants::pi<CoalScalar>();
343 unsigned int tot = (
unsigned int)(tot_for_unit_cone * r);
347 unsigned int h_num = (
unsigned int)ceil(h / circle_edge);
void computeLocalAABB()
Compute the AABB for the BVH, used for broad-phase collision.
int addSubModel(const std::vector< Vec3s > &ps, const std::vector< Triangle > &ts)
Add a set of triangles in the new BVH model.
int beginModel(unsigned int num_tris=0, unsigned int num_vertices=0)
Begin a new BVH model.
int endModel()
End BVH model construction, will build the bounding volume hierarchy.
A class describing the bounding hierarchy of a mesh model or a point cloud model (which is viewed as ...
Definition: BVH_model.h:314
Center at zero point, axis aligned box.
Definition: geometric_shapes.h:166
Cone The base of the cone is at and the top is at .
Definition: geometric_shapes.h:467
Cylinder along Z axis. The cylinder is defined at its centroid.
Definition: geometric_shapes.h:560
Center at zero point sphere.
Definition: geometric_shapes.h:240
Triangle with 3 indices for points.
Definition: data_types.h:111
CoalScalar halfLength
Half Length along z axis.
Definition: geometric_shapes.h:486
CoalScalar radius
Radius of the sphere.
Definition: geometric_shapes.h:250
CoalScalar radius
Radius of the cone.
Definition: geometric_shapes.h:480
CoalScalar halfLength
Half Length along z axis.
Definition: geometric_shapes.h:587
Vec3s halfSide
box side half-length
Definition: geometric_shapes.h:189
CoalScalar radius
Radius of the cylinder.
Definition: geometric_shapes.h:581
Main namespace.
Definition: broadphase_bruteforce.h:44
void generateBVHModel(BVHModel< BV > &model, const Box &shape, const Transform3s &pose)
Generate BVH model from box.
Definition: geometric_shape_to_BVH_model.h:49
Eigen::Matrix< CoalScalar, 3, 1 > Vec3s
Definition: data_types.h:77
double CoalScalar
Definition: data_types.h:76