gjk_asserts.cpp
Go to the documentation of this file.
1 #define BOOST_TEST_MODULE COAL_GJK_ASSERTS
2 
3 #include <boost/test/included/unit_test.hpp>
4 #include <boost/math/constants/constants.hpp>
5 #include "coal/BVH/BVH_model.h"
6 #include "coal/collision.h"
7 
8 using namespace coal;
9 
10 constexpr CoalScalar pi = boost::math::constants::pi<CoalScalar>();
11 
12 double DegToRad(const double& deg) {
13  static double degToRad = pi / 180.;
14  return deg * degToRad;
15 }
16 std::vector<Vec3s> dirs{Vec3s::UnitZ(), -Vec3s::UnitZ(), Vec3s::UnitY(),
18 
19 void CreateSphereMesh(BVHModel<OBBRSS>& model, const double& radius) {
20  size_t polarSteps{32};
21  size_t azimuthSteps{32};
22 
23  const float PI = static_cast<float>(pi);
24 
25  const float polarStep = PI / (float)(polarSteps - 1);
26  const float azimuthStep = 2.0f * PI / (float)(azimuthSteps - 1);
27  std::vector<Vec3s> vertices;
28  std::vector<Triangle> triangles;
29 
30  for (size_t p = 0; p < polarSteps; ++p) {
31  for (size_t a = 0; a < azimuthSteps; ++a) {
32  const float x =
33  std::sin((float)p * polarStep) * std::cos((float)a * azimuthStep);
34  const float y =
35  std::sin((float)p * polarStep) * std::sin((float)a * azimuthStep);
36  const float z = std::cos((float)p * polarStep);
37  vertices.emplace_back(radius * x, radius * y, radius * z);
38  }
39  }
40 
41  for (size_t p = 0; p < polarSteps - 1; ++p) {
42  for (size_t a = 0; a < azimuthSteps - 1; ++a) {
43  size_t p0 = p * azimuthSteps + a;
44  size_t p1 = p * azimuthSteps + (a + 1);
45  size_t p2 = (p + 1) * azimuthSteps + (a + 1);
46  size_t p3 = (p + 1) * azimuthSteps + a;
47  triangles.emplace_back(p0, p2, p1);
48  triangles.emplace_back(p0, p3, p2);
49  }
50  }
51  model.beginModel();
52  model.addSubModel(vertices, triangles);
53  model.endModel();
54 }
55 
56 BOOST_AUTO_TEST_CASE(TestSpheres) {
57  BVHModel<OBBRSS> sphere1{};
58  BVHModel<OBBRSS> sphere2{};
59 
60  CreateSphereMesh(sphere1, 1.);
61  CreateSphereMesh(sphere2, 2.);
62 
64 
65  ComputeCollision compute(&sphere2, &sphere1);
66 
67  Transform3s sphere1Tf = Transform3s::Identity();
68  Transform3s sphere2Tf = Transform3s::Identity();
69 
70  for (int i = 0; i < 360; ++i) {
71  for (int j = 0; j < 180; ++j) {
72  if (
74  (i == 5 && j == 48) || (i == 64 && j == 151) ||
75  (i == 98 && j == 47) || (i == 355 && j == 48) ||
77  (i == 86 && j == 52) || (i == 89 && j == 17) ||
78  (i == 89 && j == 58) || (i == 89 && j == 145)) {
79  sphere2Tf.setQuatRotation(
80  Eigen::AngleAxis<double>(DegToRad(i), Vec3s::UnitZ()) *
81  Eigen::AngleAxis<double>(DegToRad(j), Vec3s::UnitY()));
82  for (const Vec3s& dir : dirs) {
83  sphere2Tf.setTranslation(dir);
84  CollisionResult result;
85 
86  BOOST_CHECK_NO_THROW(compute(sphere2Tf, sphere1Tf, request, result));
87  }
88  }
89  }
90  }
91 }
collision.h
coal::BVHModelBase::beginModel
int beginModel(unsigned int num_tris=0, unsigned int num_vertices=0)
Begin a new BVH model.
Definition: BVH_model.cpp:179
coal::CONTACT
@ CONTACT
Definition: coal/collision_data.h:305
coal::Vec3s
Eigen::Matrix< CoalScalar, 3, 1 > Vec3s
Definition: coal/data_types.h:77
coal::BVHModelBase::endModel
int endModel()
End BVH model construction, will build the bounding volume hierarchy.
Definition: BVH_model.cpp:507
y
y
DegToRad
double DegToRad(const double &deg)
Definition: gjk_asserts.cpp:12
coal
Main namespace.
Definition: coal/broadphase/broadphase_bruteforce.h:44
coal::BVHModelBase::addSubModel
int addSubModel(const std::vector< Vec3s > &ps, const std::vector< Triangle > &ts)
Add a set of triangles in the new BVH model.
Definition: BVH_model.cpp:439
a
list a
dirs
std::vector< Vec3s > dirs
Definition: gjk_asserts.cpp:16
coal::DISTANCE_LOWER_BOUND
@ DISTANCE_LOWER_BOUND
Definition: coal/collision_data.h:306
coal::Transform3s
Simple transform class used locally by InterpMotion.
Definition: coal/math/transform.h:55
coal::Transform3s::setQuatRotation
void setQuatRotation(const Quatf &q_)
set transform from rotation
Definition: coal/math/transform.h:148
coal::Transform3s::setTranslation
void setTranslation(const Eigen::MatrixBase< Derived > &T_)
set transform from translation
Definition: coal/math/transform.h:143
coal::UnitZ
const Vec3s UnitZ
Definition: utility.cpp:90
BVH_model.h
coal::CollisionResult
collision result
Definition: coal/collision_data.h:390
coal::CollisionRequest
request to the collision algorithm
Definition: coal/collision_data.h:311
coal::Transform3s::Identity
static Transform3s Identity()
Definition: coal/math/transform.h:68
x
x
coal::UnitX
const Vec3s UnitX
Definition: utility.cpp:88
octree.p1
tuple p1
Definition: octree.py:54
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(TestSpheres)
Definition: gjk_asserts.cpp:56
coal::BVHModel
A class describing the bounding hierarchy of a mesh model or a point cloud model (which is viewed as ...
Definition: coal/BVH/BVH_model.h:314
PI
#define PI
Definition: rboxlib.c:33
coal::UnitY
const Vec3s UnitY
Definition: utility.cpp:89
CreateSphereMesh
void CreateSphereMesh(BVHModel< OBBRSS > &model, const double &radius)
Definition: gjk_asserts.cpp:19
pi
constexpr CoalScalar pi
Definition: gjk_asserts.cpp:10
coal::CoalScalar
double CoalScalar
Definition: coal/data_types.h:76
coal::ComputeCollision
This class reduces the cost of identifying the geometry pair. This is mostly useful for repeated shap...
Definition: coal/collision.h:78


hpp-fcl
Author(s):
autogenerated on Sat Nov 23 2024 03:44:58