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);
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);
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);