Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GenerateBVHSubModel variants #308

Merged
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
143 changes: 84 additions & 59 deletions include/fcl/geometry/geometric_shape_to_BVH_model-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace fcl

//==============================================================================
template<typename BV>
void generateBVHModel(BVHModel<BV>& model, const Box<typename BV::S>& shape, const Transform3<typename BV::S>& pose)
void generateBVHModel(BVHModel<BV>& model, const Box<typename BV::S>& shape, const Transform3<typename BV::S>& pose, FinalizeModel finalize_model)
{
using S = typename BV::S;

Expand Down Expand Up @@ -81,15 +81,21 @@ void generateBVHModel(BVHModel<BV>& model, const Box<typename BV::S>& shape, con
points[i] = pose * points[i];
}

model.beginModel();
if(model.build_state == BVH_BUILD_STATE_EMPTY){
model.beginModel();
}

model.addSubModel(points, tri_indices);
model.endModel();
model.computeLocalAABB();
if(finalize_model == FinalizeModel::DO_FINALIZE){
model.endModel();
model.computeLocalAABB();
}
}


//==============================================================================
template<typename BV>
void generateBVHModel(BVHModel<BV>& model, const Sphere<typename BV::S>& shape, const Transform3<typename BV::S>& pose, unsigned int seg, unsigned int ring)
void generateBVHModel(BVHModel<BV>& model, const Sphere<typename BV::S>& shape, const Transform3<typename BV::S>& pose, unsigned int seg, unsigned int ring, FinalizeModel finalize_model)
{
using S = typename BV::S;

Expand Down Expand Up @@ -148,15 +154,20 @@ void generateBVHModel(BVHModel<BV>& model, const Sphere<typename BV::S>& shape,
points[i] = pose * points[i];
}

model.beginModel();
if(model.build_state == BVH_BUILD_STATE_EMPTY){
model.beginModel();
}

model.addSubModel(points, tri_indices);
model.endModel();
model.computeLocalAABB();
if(finalize_model == FinalizeModel::DO_FINALIZE){
model.endModel();
model.computeLocalAABB();
}
}

//==============================================================================
template<typename BV>
void generateBVHModel(BVHModel<BV>& model, const Sphere<typename BV::S>& shape, const Transform3<typename BV::S>& pose, unsigned int n_faces_for_unit_sphere)
void generateBVHModel(BVHModel<BV>& model, const Sphere<typename BV::S>& shape, const Transform3<typename BV::S>& pose, unsigned int n_faces_for_unit_sphere, FinalizeModel finalize_model)
{
using S = typename BV::S;

Expand All @@ -165,12 +176,12 @@ void generateBVHModel(BVHModel<BV>& model, const Sphere<typename BV::S>& shape,
unsigned int ring = ceil(n_low_bound);
unsigned int seg = ceil(n_low_bound);

generateBVHModel(model, shape, pose, seg, ring);
generateBVHModel(model, shape, pose, seg, ring, finalize_model);
}

//==============================================================================
template<typename BV>
void generateBVHModel(BVHModel<BV>& model, const Ellipsoid<typename BV::S>& shape, const Transform3<typename BV::S>& pose, unsigned int seg, unsigned int ring)
void generateBVHModel(BVHModel<BV>& model, const Ellipsoid<typename BV::S>& shape, const Transform3<typename BV::S>& pose, unsigned int seg, unsigned int ring, FinalizeModel finalize_model)
{
using S = typename BV::S;

Expand Down Expand Up @@ -232,15 +243,20 @@ void generateBVHModel(BVHModel<BV>& model, const Ellipsoid<typename BV::S>& shap
points[i] = pose * points[i];
}

model.beginModel();
if(model.build_state == BVH_BUILD_STATE_EMPTY){
model.beginModel();
}

model.addSubModel(points, tri_indices);
model.endModel();
model.computeLocalAABB();
if(finalize_model == FinalizeModel::DO_FINALIZE){
model.endModel();
model.computeLocalAABB();
}
}

//==============================================================================
template<typename BV>
void generateBVHModel(BVHModel<BV>& model, const Ellipsoid<typename BV::S>& shape, const Transform3<typename BV::S>& pose, unsigned int n_faces_for_unit_ellipsoid)
void generateBVHModel(BVHModel<BV>& model, const Ellipsoid<typename BV::S>& shape, const Transform3<typename BV::S>& pose, unsigned int n_faces_for_unit_ellipsoid, FinalizeModel finalize_model)
{
using S = typename BV::S;

Expand All @@ -256,12 +272,12 @@ void generateBVHModel(BVHModel<BV>& model, const Ellipsoid<typename BV::S>& shap
const unsigned int ring = std::ceil(n_low_bound);
const unsigned int seg = std::ceil(n_low_bound);

generateBVHModel(model, shape, pose, seg, ring);
generateBVHModel(model, shape, pose, seg, ring, finalize_model);
}

//==============================================================================
template<typename BV>
void generateBVHModel(BVHModel<BV>& model, const Cylinder<typename BV::S>& shape, const Transform3<typename BV::S>& pose, unsigned int tot, unsigned int h_num)
void generateBVHModel(BVHModel<BV>& model, const Cylinder<typename BV::S>& shape, const Transform3<typename BV::S>& pose, unsigned int circle_split_tot, unsigned int h_num, FinalizeModel finalize_model)
{
using S = typename BV::S;

Expand All @@ -272,45 +288,45 @@ void generateBVHModel(BVHModel<BV>& model, const Cylinder<typename BV::S>& shape
S h = shape.lz;
S phi, phid;
const S pi = constants<S>::pi();
phid = pi * 2 / tot;
phid = pi * 2 / circle_split_tot;
phi = 0;

S hd = h / h_num;

for(unsigned int i = 0; i < tot; ++i)
for(unsigned int i = 0; i < circle_split_tot; ++i)
points.emplace_back(r * cos(phi + phid * i), r * sin(phi + phid * i), h / 2);

for(unsigned int i = 0; i < h_num - 1; ++i)
{
for(unsigned int j = 0; j < tot; ++j)
for(unsigned int j = 0; j < circle_split_tot; ++j)
{
points.emplace_back(r * cos(phi + phid * j), r * sin(phi + phid * j), h / 2 - (i + 1) * hd);
}
}

for(unsigned int i = 0; i < tot; ++i)
for(unsigned int i = 0; i < circle_split_tot; ++i)
points.emplace_back(r * cos(phi + phid * i), r * sin(phi + phid * i), - h / 2);

points.emplace_back(0, 0, h / 2);
points.emplace_back(0, 0, -h / 2);

for(unsigned int i = 0; i < tot; ++i)
tri_indices.emplace_back((h_num + 1) * tot, i, ((i == tot - 1) ? 0 : (i + 1)));
for(unsigned int i = 0; i < circle_split_tot; ++i)
tri_indices.emplace_back((h_num + 1) * circle_split_tot, i, ((i == circle_split_tot - 1) ? 0 : (i + 1)));

for(unsigned int i = 0; i < tot; ++i)
tri_indices.emplace_back((h_num + 1) * tot + 1, h_num * tot + ((i == tot - 1) ? 0 : (i + 1)), h_num * tot + i);
for(unsigned int i = 0; i < circle_split_tot; ++i)
tri_indices.emplace_back((h_num + 1) * circle_split_tot + 1, h_num * circle_split_tot + ((i == circle_split_tot - 1) ? 0 : (i + 1)), h_num * circle_split_tot + i);

for(unsigned int i = 0; i < h_num; ++i)
{
for(unsigned int j = 0; j < tot; ++j)
for(unsigned int j = 0; j < circle_split_tot; ++j)
{
int a, b, c, d;
a = j;
b = (j == tot - 1) ? 0 : (j + 1);
c = j + tot;
d = (j == tot - 1) ? tot : (j + 1 + tot);
b = (j == circle_split_tot - 1) ? 0 : (j + 1);
c = j + circle_split_tot;
d = (j == circle_split_tot - 1) ? circle_split_tot : (j + 1 + circle_split_tot);

int start = i * tot;
int start = i * circle_split_tot;
tri_indices.emplace_back(start + b, start + a, start + c);
tri_indices.emplace_back(start + b, start + c, start + d);
}
Expand All @@ -321,35 +337,39 @@ void generateBVHModel(BVHModel<BV>& model, const Cylinder<typename BV::S>& shape
points[i] = pose * points[i];
}

model.beginModel();
if(model.build_state == BVH_BUILD_STATE_EMPTY){
model.beginModel();
}

model.addSubModel(points, tri_indices);
model.endModel();
model.computeLocalAABB();
if(finalize_model == FinalizeModel::DO_FINALIZE){
model.endModel();
model.computeLocalAABB();
}
}

//==============================================================================
template<typename BV>
void generateBVHModel(BVHModel<BV>& model, const Cylinder<typename BV::S>& shape, const Transform3<typename BV::S>& pose, unsigned int tot_for_unit_cylinder)
void generateBVHModel(BVHModel<BV>& model, const Cylinder<typename BV::S>& shape, const Transform3<typename BV::S>& pose, unsigned int circle_split_tot_for_unit_cylinder, FinalizeModel finalize_model)
{
using S = typename BV::S;

S r = shape.radius;
S h = shape.lz;

const S pi = constants<S>::pi();
unsigned int tot = tot_for_unit_cylinder * r;
S phid = pi * 2 / tot;
unsigned int circle_split_tot = circle_split_tot_for_unit_cylinder * r;
S phid = pi * 2 / circle_split_tot;

S circle_edge = phid * r;
unsigned int h_num = ceil(h / circle_edge);

generateBVHModel(model, shape, pose, tot, h_num);
generateBVHModel(model, shape, pose, circle_split_tot, h_num, finalize_model);
}


//==============================================================================
template<typename BV>
void generateBVHModel(BVHModel<BV>& model, const Cone<typename BV::S>& shape, const Transform3<typename BV::S>& pose, unsigned int tot, unsigned int h_num)
void generateBVHModel(BVHModel<BV>& model, const Cone<typename BV::S>& shape, const Transform3<typename BV::S>& pose, unsigned int circle_split_tot, unsigned int h_num, FinalizeModel finalize_model)
{
using S = typename BV::S;

Expand All @@ -361,7 +381,7 @@ void generateBVHModel(BVHModel<BV>& model, const Cone<typename BV::S>& shape, co

S phi, phid;
const S pi = constants<S>::pi();
phid = pi * 2 / tot;
phid = pi * 2 / circle_split_tot;
phi = 0;

S hd = h / h_num;
Expand All @@ -370,35 +390,35 @@ void generateBVHModel(BVHModel<BV>& model, const Cone<typename BV::S>& shape, co
{
S h_i = h / 2 - (i + 1) * hd;
S rh = r * (0.5 - h_i / h);
for(unsigned int j = 0; j < tot; ++j)
for(unsigned int j = 0; j < circle_split_tot; ++j)
{
points.emplace_back(rh * cos(phi + phid * j), rh * sin(phi + phid * j), h_i);
}
}

for(unsigned int i = 0; i < tot; ++i)
for(unsigned int i = 0; i < circle_split_tot; ++i)
points.emplace_back(r * cos(phi + phid * i), r * sin(phi + phid * i), - h / 2);

points.emplace_back(0, 0, h / 2);
points.emplace_back(0, 0, -h / 2);

for(unsigned int i = 0; i < tot; ++i)
tri_indices.emplace_back(h_num * tot, i, (i == tot - 1) ? 0 : (i + 1));
for(unsigned int i = 0; i < circle_split_tot; ++i)
tri_indices.emplace_back(h_num * circle_split_tot, i, (i == circle_split_tot - 1) ? 0 : (i + 1));

for(unsigned int i = 0; i < tot; ++i)
tri_indices.emplace_back(h_num * tot + 1, (h_num - 1) * tot + ((i == tot - 1) ? 0 : (i + 1)), (h_num - 1) * tot + i);
for(unsigned int i = 0; i < circle_split_tot; ++i)
tri_indices.emplace_back(h_num * circle_split_tot + 1, (h_num - 1) * circle_split_tot + ((i == circle_split_tot - 1) ? 0 : (i + 1)), (h_num - 1) * circle_split_tot + i);

for(unsigned int i = 0; i < h_num - 1; ++i)
{
for(unsigned int j = 0; j < tot; ++j)
for(unsigned int j = 0; j < circle_split_tot; ++j)
{
int a, b, c, d;
a = j;
b = (j == tot - 1) ? 0 : (j + 1);
c = j + tot;
d = (j == tot - 1) ? tot : (j + 1 + tot);
b = (j == circle_split_tot - 1) ? 0 : (j + 1);
c = j + circle_split_tot;
d = (j == circle_split_tot - 1) ? circle_split_tot : (j + 1 + circle_split_tot);

int start = i * tot;
int start = i * circle_split_tot;
tri_indices.emplace_back(start + b, start + a, start + c);
tri_indices.emplace_back(start + b, start + c, start + d);
}
Expand All @@ -409,31 +429,36 @@ void generateBVHModel(BVHModel<BV>& model, const Cone<typename BV::S>& shape, co
points[i] = pose * points[i];
}

model.beginModel();
if(model.build_state == BVH_BUILD_STATE_EMPTY){
model.beginModel();
}

model.addSubModel(points, tri_indices);
model.endModel();
model.computeLocalAABB();
if(finalize_model == FinalizeModel::DO_FINALIZE){
model.endModel();
model.computeLocalAABB();
}
}

//==============================================================================
template<typename BV>
void generateBVHModel(BVHModel<BV>& model, const Cone<typename BV::S>& shape, const Transform3<typename BV::S>& pose, unsigned int tot_for_unit_cone)
void generateBVHModel(BVHModel<BV>& model, const Cone<typename BV::S>& shape, const Transform3<typename BV::S>& pose, unsigned int circle_split_tot_for_unit_cone, FinalizeModel finalize_model)
{
using S = typename BV::S;

S r = shape.radius;
S h = shape.lz;

const S pi = constants<S>::pi();
unsigned int tot = tot_for_unit_cone * r;
S phid = pi * 2 / tot;
unsigned int circle_split_tot = circle_split_tot_for_unit_cone * r;
S phid = pi * 2 / circle_split_tot;

S circle_edge = phid * r;
unsigned int h_num = ceil(h / circle_edge);

generateBVHModel(model, shape, pose, tot, h_num);
generateBVHModel(model, shape, pose, circle_split_tot, h_num, finalize_model);
}

} // namespace fcl

#endif
#endif
Loading