Commit 6884d050 authored by Lucile Remigy's avatar Lucile Remigy
Browse files

Merge branch 'devel' into refactoring

parents 083fdd4c cfdb3136
......@@ -126,16 +126,7 @@ SET(${PROJECT_NAME}_HEADERS
include/hpp/fcl/math/matrix_3f.h
include/hpp/fcl/math/vec_3f.h
include/hpp/fcl/math/types.h
include/hpp/fcl/math/tools.h
include/hpp/fcl/math/transform.h
include/hpp/fcl/traversal/details/traversal.h
include/hpp/fcl/traversal/traversal_node_shapes.h
include/hpp/fcl/traversal/traversal_node_setup.h
include/hpp/fcl/traversal/traversal_recurse.h
include/hpp/fcl/traversal/traversal_node_octree.h
include/hpp/fcl/traversal/traversal_node_bvhs.h
include/hpp/fcl/traversal/traversal_node_bvh_shape.h
include/hpp/fcl/traversal/traversal_node_base.h
include/hpp/fcl/data_types.h
include/hpp/fcl/BVH/BV_splitter.h
include/hpp/fcl/BVH/BVH_internal.h
......
......@@ -81,6 +81,30 @@ public:
{
}
//start API in common test
/// @name Bounding volume API
/// Common API to BVs.
/// @{
/// @brief Check whether the AABB contains a point
inline bool contain(const Vec3f& p) const
{
if(p[0] < min_[0] || p[0] > max_[0]) return false;
if(p[1] < min_[1] || p[1] > max_[1]) return false;
if(p[2] < min_[2] || p[2] > max_[2]) return false;
return true;
}
/// @brief Check whether two AABB are overlap
inline bool overlap(const AABB& other) const
{
......@@ -99,35 +123,11 @@ public:
bool overlap(const AABB& other, const CollisionRequest& request,
FCL_REAL& sqrDistLowerBound) const;
/// @brief Check whether the AABB contains another AABB
inline bool contain(const AABB& other) const
{
return (other.min_[0] >= min_[0]) && (other.max_[0] <= max_[0]) && (other.min_[1] >= min_[1]) && (other.max_[1] <= max_[1]) && (other.min_[2] >= min_[2]) && (other.max_[2] <= max_[2]);
}
/// @brief Check whether two AABB are overlap and return the overlap part
inline bool overlap(const AABB& other, AABB& overlap_part) const
{
if(!overlap(other))
{
return false;
}
overlap_part.min_ = min_.cwiseMax(other.min_);
overlap_part.max_ = max_.cwiseMin(other.max_);
return true;
}
/// @brief Check whether the AABB contains a point
inline bool contain(const Vec3f& p) const
{
if(p[0] < min_[0] || p[0] > max_[0]) return false;
if(p[1] < min_[1] || p[1] > max_[1]) return false;
if(p[2] < min_[2] || p[2] > max_[2]) return false;
/// @brief Distance between two AABBs
FCL_REAL distance(const AABB& other) const;
return true;
}
/// @brief Distance between two AABBs; P and Q, should not be NULL, return the nearest points
FCL_REAL distance(const AABB& other, Vec3f* P, Vec3f* Q) const;
/// @brief Merge the AABB and a point
inline AABB& operator += (const Vec3f& p)
......@@ -152,6 +152,18 @@ public:
return res += other;
}
/// @brief Size of the AABB (used in BV_Splitter to order two AABBs)
inline FCL_REAL size() const
{
return (max_ - min_).squaredNorm();
}
/// @brief Center of the AABB
inline Vec3f center() const
{
return (min_ + max_) * 0.5;
}
/// @brief Width of the AABB
inline FCL_REAL width() const
{
......@@ -174,26 +186,42 @@ public:
inline FCL_REAL volume() const
{
return width() * height() * depth();
}
}
/// @brief Size of the AABB (used in BV_Splitter to order two AABBs)
inline FCL_REAL size() const
/// @}
//End API in common test
/// @brief Check whether the AABB contains another AABB
inline bool contain(const AABB& other) const
{
return (max_ - min_).squaredNorm();
return (other.min_[0] >= min_[0]) && (other.max_[0] <= max_[0]) && (other.min_[1] >= min_[1]) && (other.max_[1] <= max_[1]) && (other.min_[2] >= min_[2]) && (other.max_[2] <= max_[2]);
}
/// @brief Center of the AABB
inline Vec3f center() const
/// @brief Check whether two AABB are overlap and return the overlap part
inline bool overlap(const AABB& other, AABB& overlap_part) const
{
return (min_ + max_) * 0.5;
if(!overlap(other))
{
return false;
}
overlap_part.min_ = min_.cwiseMax(other.min_);
overlap_part.max_ = max_.cwiseMin(other.max_);
return true;
}
/// @brief Distance between two AABBs; P and Q, should not be NULL, return the nearest points
FCL_REAL distance(const AABB& other, Vec3f* P, Vec3f* Q) const;
/// @brief Distance between two AABBs
FCL_REAL distance(const AABB& other) const;
/// @brief expand the half size of the AABB by delta, and keep the center unchanged.
inline AABB& expand(const Vec3f& delta)
{
......@@ -241,7 +269,6 @@ bool overlap(const Matrix3f& R0, const Vec3f& T0, const AABB& b1, const AABB& b2
bool overlap(const Matrix3f& R0, const Vec3f& T0, const AABB& b1,
const AABB& b2, const CollisionRequest& request,
FCL_REAL& sqrDistLowerBound);
}
} // namespace hpp
......
......@@ -60,6 +60,12 @@ public:
/// @brief Half dimensions of OBB
Vec3f extent;
/// @brief Check whether the OBB contains a point.
bool contain(const Vec3f& p) const;
/// Check collision between two OBB
/// \return true if collision happens.
bool overlap(const OBB& other) const;
......@@ -71,8 +77,8 @@ public:
bool overlap(const OBB& other, const CollisionRequest& request,
FCL_REAL& sqrDistLowerBound) const;
/// @brief Check whether the OBB contains a point.
bool contain(const Vec3f& p) const;
/// @brief Distance between two OBBs, not implemented.
FCL_REAL distance(const OBB& other, Vec3f* P = NULL, Vec3f* Q = NULL) const;
/// @brief A simple way to merge the OBB and a point (the result is not compact).
OBB& operator += (const Vec3f& p);
......@@ -87,6 +93,18 @@ public:
/// @brief Return the merged OBB of current OBB and the other one (the result is not compact).
OBB operator + (const OBB& other) const;
/// @brief Size of the OBB (used in BV_Splitter to order two OBBs)
inline FCL_REAL size() const
{
return extent.squaredNorm();
}
/// @brief Center of the OBB
inline const Vec3f& center() const
{
return To;
}
/// @brief Width of the OBB.
inline FCL_REAL width() const
{
......@@ -110,22 +128,6 @@ public:
{
return width() * height() * depth();
}
/// @brief Size of the OBB (used in BV_Splitter to order two OBBs)
inline FCL_REAL size() const
{
return extent.squaredNorm();
}
/// @brief Center of the OBB
inline const Vec3f& center() const
{
return To;
}
/// @brief Distance between two OBBs, not implemented.
FCL_REAL distance(const OBB& other, Vec3f* P = NULL, Vec3f* Q = NULL) const;
};
......
......@@ -59,6 +59,16 @@ public:
/// @brief RSS member, for distance
RSS rss;
/// @brief Check whether the OBBRSS contains a point
inline bool contain(const Vec3f& p) const
{
return obb.contain(p);
}
/// @brief Check collision between two OBBRSS
bool overlap(const OBBRSS& other) const
{
......@@ -74,10 +84,10 @@ public:
return obb.overlap(other.obb, request, sqrDistLowerBound);
}
/// @brief Check whether the OBBRSS contains a point
inline bool contain(const Vec3f& p) const
/// @brief Distance between two OBBRSS; P and Q , is not NULL, returns the nearest points
FCL_REAL distance(const OBBRSS& other, Vec3f* P = NULL, Vec3f* Q = NULL) const
{
return obb.contain(p);
return rss.distance(other.rss, P, Q);
}
/// @brief Merge the OBBRSS and a point
......@@ -104,6 +114,18 @@ public:
return result;
}
/// @brief Size of the OBBRSS (used in BV_Splitter to order two OBBRSS)
inline FCL_REAL size() const
{
return obb.size();
}
/// @brief Center of the OBBRSS
inline const Vec3f& center() const
{
return obb.center();
}
/// @brief Width of the OBRSS
inline FCL_REAL width() const
{
......@@ -127,25 +149,12 @@ public:
{
return obb.volume();
}
};
/// @brief Size of the OBBRSS (used in BV_Splitter to order two OBBRSS)
inline FCL_REAL size() const
{
return obb.size();
}
/// @brief Center of the OBBRSS
inline const Vec3f& center() const
{
return obb.center();
}
/// @brief Distance between two OBBRSS; P and Q , is not NULL, returns the nearest points
FCL_REAL distance(const OBBRSS& other, Vec3f* P = NULL, Vec3f* Q = NULL) const
{
return rss.distance(other.rss, P, Q);
}
};
/// @brief Check collision between two OBBRSS, b1 is in configuration (R0, T0) and b2 is in indentity
inline bool overlap(const Matrix3f& R0, const Vec3f& T0, const OBBRSS& b1, const OBBRSS& b2)
......
......@@ -65,6 +65,10 @@ public:
/// @brief Radius of sphere summed with rectangle to form RSS
FCL_REAL r;
/// @brief Check whether the RSS contains a point
inline bool contain(const Vec3f& p) const;
/// @brief Check collision between two RSS
bool overlap(const RSS& other) const;
......@@ -76,15 +80,8 @@ public:
return overlap (other);
}
/// @brief Check collision between two RSS and return the overlap part.
/// For RSS, we return nothing, as the overlap part of two RSSs usually is not a RSS.
bool overlap(const RSS& other, RSS& /*overlap_part*/) const
{
return overlap(other);
}
/// @brief Check whether the RSS contains a point
inline bool contain(const Vec3f& p) const;
/// @brief the distance between two RSS; P and Q, if not NULL, return the nearest points
FCL_REAL distance(const RSS& other, Vec3f* P = NULL, Vec3f* Q = NULL) const;
/// @brief A simple way to merge the RSS and a point, not compact.
/// @todo This function may have some bug.
......@@ -100,6 +97,19 @@ public:
/// @brief Return the merged RSS of current RSS and the other one
RSS operator + (const RSS& other) const;
/// @brief Size of the RSS (used in BV_Splitter to order two RSSs)
inline FCL_REAL size() const
{
return (std::sqrt(l[0] * l[0] + l[1] * l[1]) + 2 * r);
}
/// @brief The RSS center
inline const Vec3f& center() const
{
return Tr;
}
/// @brief Width of the RSS
inline FCL_REAL width() const
{
......@@ -124,21 +134,12 @@ public:
return (l[0] * l[1] * 2 * r + 4 * boost::math::constants::pi<FCL_REAL>() * r * r * r);
}
/// @brief Size of the RSS (used in BV_Splitter to order two RSSs)
inline FCL_REAL size() const
{
return (std::sqrt(l[0] * l[0] + l[1] * l[1]) + 2 * r);
}
/// @brief The RSS center
inline const Vec3f& center() const
/// @brief Check collision between two RSS and return the overlap part.
/// For RSS, we return nothing, as the overlap part of two RSSs usually is not a RSS.
bool overlap(const RSS& other, RSS& /*overlap_part*/) const
{
return Tr;
return overlap(other);
}
/// @brief the distance between two RSS; P and Q, if not NULL, return the nearest points
FCL_REAL distance(const RSS& other, Vec3f* P = NULL, Vec3f* Q = NULL) const;
};
/// @brief distance between two RSS bounding volumes
......
......@@ -111,8 +111,8 @@ public:
return overlap (other);
}
//// @brief Check whether one point is inside the KDOP
bool inside(const Vec3f& p) const;
/// @brief The distance between two KDOP<N>. Not implemented.
FCL_REAL distance(const KDOP<N>& other, Vec3f* P = NULL, Vec3f* Q = NULL) const;
/// @brief Merge the point and the KDOP
KDOP<N>& operator += (const Vec3f& p);
......@@ -123,6 +123,19 @@ public:
/// @brief Create a KDOP by mergin two KDOPs
KDOP<N> operator + (const KDOP<N>& other) const;
/// @brief Size of the kDOP (used in BV_Splitter to order two kDOPs)
inline FCL_REAL size() const
{
return width() * width() + height() * height() + depth() * depth();
}
/// @brief The (AABB) center
inline Vec3f center() const
{
return Vec3f(dist_[0] + dist_[N / 2], dist_[1] + dist_[N / 2 + 1], dist_[2] + dist_[N / 2 + 2]) * 0.5;
}
/// @brief The (AABB) width
inline FCL_REAL width() const
{
......@@ -147,21 +160,6 @@ public:
return width() * height() * depth();
}
/// @brief Size of the kDOP (used in BV_Splitter to order two kDOPs)
inline FCL_REAL size() const
{
return width() * width() + height() * height() + depth() * depth();
}
/// @brief The (AABB) center
inline Vec3f center() const
{
return Vec3f(dist_[0] + dist_[N / 2], dist_[1] + dist_[N / 2 + 1], dist_[2] + dist_[N / 2 + 2]) * 0.5;
}
/// @brief The distance between two KDOP<N>. Not implemented.
FCL_REAL distance(const KDOP<N>& other, Vec3f* P = NULL, Vec3f* Q = NULL) const;
inline FCL_REAL dist(std::size_t i) const
{
return dist_[i];
......@@ -172,6 +170,8 @@ public:
return dist_[i];
}
//// @brief Check whether one point is inside the KDOP
bool inside(const Vec3f& p) const;
};
......
......@@ -93,6 +93,9 @@ public:
/// @ OBB related with kIOS
OBB obb;
/// @brief Check whether the kIOS contains a point
inline bool contain(const Vec3f& p) const;
/// @brief Check collision between two kIOS
bool overlap(const kIOS& other) const;
......@@ -100,8 +103,8 @@ public:
bool overlap(const kIOS& other, const CollisionRequest&,
FCL_REAL& sqrDistLowerBound) const;
/// @brief Check whether the kIOS contains a point
inline bool contain(const Vec3f& p) const;
/// @brief The distance between two kIOS
FCL_REAL distance(const kIOS& other, Vec3f* P = NULL, Vec3f* Q = NULL) const;
/// @brief A simple way to merge the kIOS and a point
kIOS& operator += (const Vec3f& p);
......@@ -116,6 +119,9 @@ public:
/// @brief Return the merged kIOS of current kIOS and the other one
kIOS operator + (const kIOS& other) const;
/// @brief size of the kIOS (used in BV_Splitter to order two kIOSs)
FCL_REAL size() const;
/// @brief Center of the kIOS
const Vec3f& center() const
{
......@@ -133,12 +139,6 @@ public:
/// @brief Volume of the kIOS
FCL_REAL volume() const;
/// @brief size of the kIOS (used in BV_Splitter to order two kIOSs)
FCL_REAL size() const;
/// @brief The distance between two kIOS
FCL_REAL distance(const kIOS& other, Vec3f* P = NULL, Vec3f* Q = NULL) const;
};
......
......@@ -77,10 +77,10 @@ public:
BVHBuildState build_state;
/// @brief Split rule to split one BV node into two children
boost::shared_ptr<BVSplitterBase<BV> > bv_splitter;
boost::shared_ptr<BVSplitter<BV> > bv_splitter;
/// @brief Fitting rule to fit a BV node to a set of geometry primitives
boost::shared_ptr<BVFitterBase<BV> > bv_fitter;
boost::shared_ptr<BVFitterTpl<BV> > bv_fitter;
/// @brief Model type described by the instance
BVHModelType getModelType() const
......
......@@ -74,27 +74,9 @@ void fit<OBBRSS>(Vec3f* ps, int n, OBBRSS& bv);
template<>
void fit<AABB>(Vec3f* ps, int n, AABB& bv);
/// @brief Interface for fitting a bv given the triangles or points inside it.
template<typename BV>
class BVFitterBase
{
public:
/// @brief Set the primitives to be processed by the fitter
virtual void set(Vec3f* vertices_, Triangle* tri_indices_, BVHModelType type_) = 0;
/// @brief Set the primitives to be processed by the fitter, for deformable mesh.
virtual void set(Vec3f* vertices_, Vec3f* prev_vertices_, Triangle* tri_indices_, BVHModelType type_) = 0;
/// @brief Compute the fitting BV
virtual BV fit(unsigned int* primitive_indices, int num_primitives) = 0;
/// @brief clear the temporary data generated.
virtual void clear() = 0;
};
/// @brief The class for the default algorithm fitting a bounding volume to a set of points
template<typename BV>
class BVFitterTpl : public BVFitterBase<BV>
class BVFitterTpl
{
public:
/// @brief default deconstructor
......@@ -118,6 +100,9 @@ public:
type = type_;
}
/// @brief Compute the fitting BV
virtual BV fit(unsigned int* primitive_indices, int num_primitives) = 0;
/// @brief Clear the geometry primitive data
void clear()
{
......
......@@ -49,32 +49,13 @@ namespace hpp
namespace fcl
{
/// @brief Base interface for BV splitting algorithm
template<typename BV>
class BVSplitterBase
{
public:
/// @brief Set the geometry data needed by the split rule
virtual void set(Vec3f* vertices_, Triangle* tri_indices_, BVHModelType type_) = 0;
/// @brief Compute the split rule according to a subset of geometry and the corresponding BV node
virtual void computeRule(const BV& bv, unsigned int* primitive_indices, int num_primitives) = 0;
/// @brief Apply the split rule on a given point
virtual bool apply(const Vec3f& q) const = 0;
/// @brief Clear the geometry data set before
virtual void clear() = 0;
};
/// @brief Three types of split algorithms are provided in FCL as default
enum SplitMethodType {SPLIT_METHOD_MEAN, SPLIT_METHOD_MEDIAN, SPLIT_METHOD_BV_CENTER};
/// @brief A class describing the split rule that splits each BV node
template<typename BV>
class BVSplitter : public BVSplitterBase<BV>
class BVSplitter
{
public:
......
......@@ -39,7 +39,7 @@
#include <hpp/fcl/BVH/BVH_utility.h>
#include <hpp/fcl/math/transform.h>
#include <hpp/fcl/collision_data.h>
#include <hpp/fcl/math/tools.h>
#include "../math/tools.h"
#include <iostream>
#include <limits>
......
......@@ -38,7 +38,7 @@
#include <hpp/fcl/BV/RSS.h>
#include <hpp/fcl/BVH/BVH_utility.h>
#include <iostream>
#include <hpp/fcl/math/tools.h>
#include "../math/tools.h"
namespace hpp
{
namespace fcl
......
......@@ -38,7 +38,7 @@
#include <hpp/fcl/BVH/BV_fitter.h>
#include <hpp/fcl/BVH/BVH_utility.h>
#include <limits>
#include <hpp/fcl/math/tools.h>
#include "../math/tools.h"
namespace hpp
{
......
......@@ -54,9 +54,9 @@ CollisionFunctionMatrix<GJKSolver>& getCollisionFunctionLookTable()
return table;
}