Skip to content

Commit

Permalink
Refactor unit tests for generateBVHModel
Browse files Browse the repository at this point in the history
Includes response to PR review, with minor comment fixes
as well as a major refactor in the unit test function.
  • Loading branch information
Nico van Duijn committed Jul 10, 2018
1 parent 7c11d0d commit e54d832
Show file tree
Hide file tree
Showing 5 changed files with 393 additions and 77 deletions.
42 changes: 21 additions & 21 deletions include/fcl/geometry/geometric_shape_to_BVH_model-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,27 @@
namespace fcl
{

//==============================================================================
// Local helper function to ease conditional adding of triangles to a BVHModel
template<typename BV>
int addTriangles(BVHModel<BV>& model, const std::vector<Vector3<typename BV::S>>& points, const std::vector<Triangle>& tri_indices, FinalizeModel finalize_model)
{
int retval = BVH_OK;
if(model.build_state == BVH_BUILD_STATE_EMPTY){
retval = model.beginModel();
}

if(retval == BVH_OK){
retval = model.addSubModel(points, tri_indices);
}

if(retval == BVH_OK && finalize_model == FinalizeModel::DO){
retval = model.endModel();
model.computeLocalAABB();
}
return retval;
}

//==============================================================================
template<typename BV>
int generateBVHModel(BVHModel<BV>& model, const Box<typename BV::S>& shape, const Transform3<typename BV::S>& pose, FinalizeModel finalize_model)
Expand Down Expand Up @@ -421,27 +442,6 @@ int generateBVHModel(BVHModel<BV>& model, const Cone<typename BV::S>& shape, con
return generateBVHModel(model, shape, pose, circle_split_tot, h_num, finalize_model);
}

//==============================================================================
template<typename BV>
int addTriangles(BVHModel<BV>& model, const std::vector<Vector3<typename BV::S>>& points, const std::vector<Triangle>& tri_indices, FinalizeModel finalize_model)
{
int retval = BVH_OK;
if(model.build_state == BVH_BUILD_STATE_EMPTY){
retval = model.beginModel();
}

if(retval == BVH_OK){
retval = model.addSubModel(points, tri_indices);
}

if(retval == BVH_OK && finalize_model == FinalizeModel::DO){
retval = model.endModel();
model.computeLocalAABB();
}
return retval;
}


} // namespace fcl

#endif
20 changes: 8 additions & 12 deletions include/fcl/geometry/geometric_shape_to_BVH_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,19 @@ enum class FinalizeModel{
/**
@defgroup generateBVHModel
@brief Create a BVHModel using geometric primitives
@details The functions in this group can be used to add geometric primitives (Box, Sphere, Ellipsoid, Cylinder, Cone)
@details The functions in this group can be used to add geometric primitives (Box, Sphere, Ellipsoid, Cylinder, Cone)
to a BVHModel. It can either close off the model or leave it unfinalized in order to add more primitives later.
@note All functions in this group have a common sub-set of parameters (listed below). In addition, each has unique
parameters related to the geometry type being added and how it should be tessellated. These additional parameters
are documented with their corresponding function
@warning If this function is used to create a BVHModel containing multiple geometric primitives, the BVHModel inherently
represents the *union* of those primitives. The BVHModel structure does not retain any notion of the original
geometric primitive.
@param[out] model The BVHModel to be generated or added to
@param[in] shape The geometric object to be added to the BVHModel
@param[in] pose The pose of the geometric object
@param[in] finalize_model an enum indicating whether the model is final or more submodels can be added later
@return BVHReturnCode indicating the success of the operation
@{
*/

Expand Down Expand Up @@ -149,16 +155,6 @@ int generateBVHModel(BVHModel<BV>& model, const Cone<typename BV::S>& shape, con
template<typename BV>
int 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 = FinalizeModel::DO);

/**
@brief AddTriangles to a BVHModel
@param[in, out] model The BVHModel
@param[in] points The points to add
@param[in] tri_indices The triangles to add
@param[in] finalize_model An enum indicating whether to close off the model afterwards
**/
template<typename BV>
int addTriangles(BVHModel<BV>& model, const std::vector<Vector3<typename BV::S>>& points, const std::vector<Triangle>& tri_indices, FinalizeModel finalize_model);

/**@} */ // end of doxygen group generateBVHModel

} // namespace fcl
Expand Down
3 changes: 2 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ set(tests
test_fcl_distance.cpp
test_fcl_frontlist.cpp
test_fcl_general.cpp
test_fcl_generate_bvh_model.cpp
test_fcl_generate_bvh_model_deferred_finalize.cpp
test_fcl_generate_bvh_model_primitives.cpp
test_fcl_geometric_shapes.cpp
test_fcl_math.cpp
test_fcl_profiler.cpp
Expand Down
Loading

0 comments on commit e54d832

Please sign in to comment.