1 |
|
|
/* |
2 |
|
|
* Software License Agreement (BSD License) |
3 |
|
|
* |
4 |
|
|
* Copyright (c) 2011-2014, Willow Garage, Inc. |
5 |
|
|
* Copyright (c) 2014-2015, Open Source Robotics Foundation |
6 |
|
|
* All rights reserved. |
7 |
|
|
* |
8 |
|
|
* Redistribution and use in source and binary forms, with or without |
9 |
|
|
* modification, are permitted provided that the following conditions |
10 |
|
|
* are met: |
11 |
|
|
* |
12 |
|
|
* * Redistributions of source code must retain the above copyright |
13 |
|
|
* notice, this list of conditions and the following disclaimer. |
14 |
|
|
* * Redistributions in binary form must reproduce the above |
15 |
|
|
* copyright notice, this list of conditions and the following |
16 |
|
|
* disclaimer in the documentation and/or other materials provided |
17 |
|
|
* with the distribution. |
18 |
|
|
* * Neither the name of Open Source Robotics Foundation nor the names of its |
19 |
|
|
* contributors may be used to endorse or promote products derived |
20 |
|
|
* from this software without specific prior written permission. |
21 |
|
|
* |
22 |
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
23 |
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
24 |
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
25 |
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
26 |
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
27 |
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
28 |
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
29 |
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
30 |
|
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
31 |
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
32 |
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
33 |
|
|
* POSSIBILITY OF SUCH DAMAGE. |
34 |
|
|
*/ |
35 |
|
|
|
36 |
|
|
/** \author Jia Pan */ |
37 |
|
|
|
38 |
|
|
#ifndef TEST_HPP_FCL_UTILITY_H |
39 |
|
|
#define TEST_HPP_FCL_UTILITY_H |
40 |
|
|
|
41 |
|
|
#include <hpp/fcl/math/transform.h> |
42 |
|
|
#include <hpp/fcl/collision_data.h> |
43 |
|
|
#include <hpp/fcl/collision_object.h> |
44 |
|
|
#include <hpp/fcl/broadphase/default_broadphase_callbacks.h> |
45 |
|
|
#include <hpp/fcl/shape/convex.h> |
46 |
|
|
|
47 |
|
|
#ifdef HPP_FCL_HAS_OCTOMAP |
48 |
|
|
#include <hpp/fcl/octree.h> |
49 |
|
|
#endif |
50 |
|
|
|
51 |
|
|
#ifdef _WIN32 |
52 |
|
|
#define NOMINMAX // required to avoid compilation errors with Visual Studio |
53 |
|
|
// 2010 |
54 |
|
|
#include <windows.h> |
55 |
|
|
#else |
56 |
|
|
#include <sys/time.h> |
57 |
|
|
#endif |
58 |
|
|
|
59 |
|
|
#define EIGEN_VECTOR_IS_APPROX(Va, Vb, precision) \ |
60 |
|
|
BOOST_CHECK_MESSAGE(((Va) - (Vb)).isZero(precision), \ |
61 |
|
|
"check " #Va ".isApprox(" #Vb \ |
62 |
|
|
") failed " \ |
63 |
|
|
"[\n" \ |
64 |
|
|
<< (Va).transpose() << "\n!=\n" \ |
65 |
|
|
<< (Vb).transpose() << "\n]") |
66 |
|
|
#define EIGEN_MATRIX_IS_APPROX(Va, Vb, precision) \ |
67 |
|
|
BOOST_CHECK_MESSAGE(((Va) - (Vb)).isZero(precision), "check " #Va \ |
68 |
|
|
".isApprox(" #Vb \ |
69 |
|
|
") failed " \ |
70 |
|
|
"[\n" \ |
71 |
|
|
<< (Va) << "\n!=\n" \ |
72 |
|
|
<< (Vb) << "\n]") |
73 |
|
|
|
74 |
|
|
namespace octomap { |
75 |
|
|
#ifdef HPP_FCL_HAS_OCTOMAP |
76 |
|
|
typedef hpp::fcl::shared_ptr<octomap::OcTree> OcTreePtr_t; |
77 |
|
|
#endif |
78 |
|
|
} // namespace octomap |
79 |
|
|
namespace hpp { |
80 |
|
|
namespace fcl { |
81 |
|
|
|
82 |
|
|
class BenchTimer { |
83 |
|
|
public: |
84 |
|
|
BenchTimer(); |
85 |
|
|
~BenchTimer(); |
86 |
|
|
|
87 |
|
|
void start(); ///< start timer |
88 |
|
|
void stop(); ///< stop the timer |
89 |
|
|
double getElapsedTime(); ///< get elapsed time in milli-second |
90 |
|
|
double getElapsedTimeInSec(); ///< get elapsed time in second (same as |
91 |
|
|
///< getElapsedTime) |
92 |
|
|
double getElapsedTimeInMilliSec(); ///< get elapsed time in milli-second |
93 |
|
|
double getElapsedTimeInMicroSec(); ///< get elapsed time in micro-second |
94 |
|
|
|
95 |
|
|
private: |
96 |
|
|
double startTimeInMicroSec; ///< starting time in micro-second |
97 |
|
|
double endTimeInMicroSec; ///< ending time in micro-second |
98 |
|
|
int stopped; ///< stop flag |
99 |
|
|
#ifdef _WIN32 |
100 |
|
|
LARGE_INTEGER frequency; ///< ticks per second |
101 |
|
|
LARGE_INTEGER startCount; |
102 |
|
|
LARGE_INTEGER endCount; |
103 |
|
|
#else |
104 |
|
|
timeval startCount; |
105 |
|
|
timeval endCount; |
106 |
|
|
#endif |
107 |
|
|
}; |
108 |
|
|
|
109 |
|
|
struct TStruct { |
110 |
|
|
std::vector<double> records; |
111 |
|
|
double overall_time; |
112 |
|
|
|
113 |
|
459 |
TStruct() { overall_time = 0; } |
114 |
|
|
|
115 |
|
36540 |
void push_back(double t) { |
116 |
|
36540 |
records.push_back(t); |
117 |
|
36540 |
overall_time += t; |
118 |
|
36540 |
} |
119 |
|
|
}; |
120 |
|
|
|
121 |
|
|
extern const Eigen::IOFormat vfmt; |
122 |
|
|
extern const Eigen::IOFormat pyfmt; |
123 |
|
|
typedef Eigen::AngleAxis<FCL_REAL> AngleAxis; |
124 |
|
|
extern const Vec3f UnitX; |
125 |
|
|
extern const Vec3f UnitY; |
126 |
|
|
extern const Vec3f UnitZ; |
127 |
|
|
|
128 |
|
|
/// @brief Load an obj mesh file |
129 |
|
|
void loadOBJFile(const char* filename, std::vector<Vec3f>& points, |
130 |
|
|
std::vector<Triangle>& triangles); |
131 |
|
|
|
132 |
|
|
void saveOBJFile(const char* filename, std::vector<Vec3f>& points, |
133 |
|
|
std::vector<Triangle>& triangles); |
134 |
|
|
|
135 |
|
|
#ifdef HPP_FCL_HAS_OCTOMAP |
136 |
|
|
fcl::OcTree loadOctreeFile(const std::string& filename, |
137 |
|
|
const FCL_REAL& resolution); |
138 |
|
|
#endif |
139 |
|
|
|
140 |
|
|
/// @brief Generate one random transform whose translation is constrained by |
141 |
|
|
/// extents and rotation without constraints. The translation is (x, y, z), and |
142 |
|
|
/// extents[0] <= x <= extents[3], extents[1] <= y <= extents[4], extents[2] <= |
143 |
|
|
/// z <= extents[5] |
144 |
|
|
void generateRandomTransform(FCL_REAL extents[6], Transform3f& transform); |
145 |
|
|
|
146 |
|
|
/// @brief Generate n random transforms whose translations are constrained by |
147 |
|
|
/// extents. |
148 |
|
|
void generateRandomTransforms(FCL_REAL extents[6], |
149 |
|
|
std::vector<Transform3f>& transforms, |
150 |
|
|
std::size_t n); |
151 |
|
|
|
152 |
|
|
/// @brief Generate n random transforms whose translations are constrained by |
153 |
|
|
/// extents. Also generate another transforms2 which have additional random |
154 |
|
|
/// translation & rotation to the transforms generated. |
155 |
|
|
void generateRandomTransforms(FCL_REAL extents[6], FCL_REAL delta_trans[3], |
156 |
|
|
FCL_REAL delta_rot, |
157 |
|
|
std::vector<Transform3f>& transforms, |
158 |
|
|
std::vector<Transform3f>& transforms2, |
159 |
|
|
std::size_t n); |
160 |
|
|
|
161 |
|
|
/// @ brief Structure for minimum distance between two meshes and the |
162 |
|
|
/// corresponding nearest point pair |
163 |
|
|
struct DistanceRes { |
164 |
|
|
double distance; |
165 |
|
|
Vec3f p1; |
166 |
|
|
Vec3f p2; |
167 |
|
|
}; |
168 |
|
|
|
169 |
|
|
/// @brief Default collision callback for two objects o1 and o2 in broad phase. |
170 |
|
|
/// return value means whether the broad phase can stop now. |
171 |
|
|
bool defaultCollisionFunction(CollisionObject* o1, CollisionObject* o2, |
172 |
|
|
void* cdata); |
173 |
|
|
|
174 |
|
|
/// @brief Default distance callback for two objects o1 and o2 in broad phase. |
175 |
|
|
/// return value means whether the broad phase can stop now. also return dist, |
176 |
|
|
/// i.e. the bmin distance till now |
177 |
|
|
bool defaultDistanceFunction(CollisionObject* o1, CollisionObject* o2, |
178 |
|
|
void* cdata, FCL_REAL& dist); |
179 |
|
|
|
180 |
|
|
std::string getNodeTypeName(NODE_TYPE node_type); |
181 |
|
|
|
182 |
|
|
Quaternion3f makeQuat(FCL_REAL w, FCL_REAL x, FCL_REAL y, FCL_REAL z); |
183 |
|
|
|
184 |
|
|
std::ostream& operator<<(std::ostream& os, const Transform3f& tf); |
185 |
|
|
|
186 |
|
|
/// Get the argument --nb-run from argv |
187 |
|
|
std::size_t getNbRun(const int& argc, char const* const* argv, |
188 |
|
|
std::size_t defaultValue); |
189 |
|
|
|
190 |
|
|
void generateEnvironments(std::vector<CollisionObject*>& env, |
191 |
|
|
FCL_REAL env_scale, std::size_t n); |
192 |
|
|
|
193 |
|
|
void generateEnvironmentsMesh(std::vector<CollisionObject*>& env, |
194 |
|
|
FCL_REAL env_scale, std::size_t n); |
195 |
|
|
|
196 |
|
|
/// @brief We give an ellipsoid as input. The output is a 20 faces polytope |
197 |
|
|
/// which vertices belong to the original ellipsoid surface. The procedure is |
198 |
|
|
/// simple: we construct a icosahedron, see |
199 |
|
|
/// https://sinestesia.co/blog/tutorials/python-icospheres/ . We then apply an |
200 |
|
|
/// ellipsoid tranformation to each vertex of the icosahedron. |
201 |
|
|
Convex<Triangle> constructPolytopeFromEllipsoid(const Ellipsoid& ellipsoid); |
202 |
|
|
|
203 |
|
|
} // namespace fcl |
204 |
|
|
|
205 |
|
|
} // namespace hpp |
206 |
|
|
|
207 |
|
|
#endif |