utility.h
Go to the documentation of this file.
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 
38 #ifndef TEST_COAL_UTILITY_H
39 #define TEST_COAL_UTILITY_H
40 
41 #include "coal/math/transform.h"
42 #include "coal/collision_data.h"
43 #include "coal/collision_object.h"
45 #include "coal/shape/convex.h"
46 
47 #ifdef COAL_HAS_OCTOMAP
48 #include "coal/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 ") failed at precision " \
62  << precision << " [\n" \
63  << (Va).transpose() << "\n!=\n" \
64  << (Vb).transpose() << "\n]")
65 
66 #define EIGEN_MATRIX_IS_APPROX(Va, Vb, precision) \
67  BOOST_CHECK_MESSAGE(((Va) - (Vb)).isZero(precision), \
68  "check " #Va ".isApprox(" #Vb ") failed at precision " \
69  << precision << " [\n" \
70  << (Va) << "\n!=\n" \
71  << (Vb) << "\n]")
72 
73 #define CoalScalar_IS_APPROX(Va, Vb, precision) \
74  BOOST_CHECK_MESSAGE(std::abs((Va) - (Vb)) < precision, \
75  "check " #Va ".isApprox(" #Vb ") failed at precision " \
76  << precision << " [\n" \
77  << Va << "\n!=\n" \
78  << Vb << "\n]")
79 
80 namespace octomap {
81 #ifdef COAL_HAS_OCTOMAP
82 typedef coal::shared_ptr<octomap::OcTree> OcTreePtr_t;
83 #endif
84 } // namespace octomap
85 namespace coal {
86 
87 class BenchTimer {
88  public:
89  BenchTimer();
90  ~BenchTimer();
91 
92  void start();
93  void stop();
94  double getElapsedTime();
95  double getElapsedTimeInSec();
96  double getElapsedTimeInMilliSec();
98  double getElapsedTimeInMicroSec();
99 
100  private:
103  int stopped;
104 #ifdef _WIN32
105  LARGE_INTEGER frequency;
106  LARGE_INTEGER startCount;
107  LARGE_INTEGER endCount;
108 #else
109  timeval startCount;
110  timeval endCount;
111 #endif
112 };
113 
114 struct TStruct {
115  std::vector<double> records;
116  double overall_time;
117 
119 
120  void push_back(double t) {
121  records.push_back(t);
122  overall_time += t;
123  }
124 };
125 
126 extern const Eigen::IOFormat vfmt;
127 extern const Eigen::IOFormat pyfmt;
128 typedef Eigen::AngleAxis<CoalScalar> AngleAxis;
129 extern const Vec3s UnitX;
130 extern const Vec3s UnitY;
131 extern const Vec3s UnitZ;
132 
134 void loadOBJFile(const char* filename, std::vector<Vec3s>& points,
135  std::vector<Triangle>& triangles);
136 
137 void saveOBJFile(const char* filename, std::vector<Vec3s>& points,
138  std::vector<Triangle>& triangles);
139 
140 #ifdef COAL_HAS_OCTOMAP
141 coal::OcTree loadOctreeFile(const std::string& filename,
142  const CoalScalar& resolution);
143 #endif
144 
150 
154  std::vector<Transform3s>& transforms,
155  std::size_t n);
156 
160 void generateRandomTransforms(CoalScalar extents[6], CoalScalar delta_trans[3],
161  CoalScalar delta_rot,
162  std::vector<Transform3s>& transforms,
163  std::vector<Transform3s>& transforms2,
164  std::size_t n);
165 
168 struct DistanceRes {
169  double distance;
172 };
173 
177  void* cdata);
178 
183  void* cdata, CoalScalar& dist);
184 
185 std::string getNodeTypeName(NODE_TYPE node_type);
186 
188 
189 std::ostream& operator<<(std::ostream& os, const Transform3s& tf);
190 
192 std::size_t getNbRun(const int& argc, char const* const* argv,
193  std::size_t defaultValue);
194 
195 void generateEnvironments(std::vector<CollisionObject*>& env,
196  CoalScalar env_scale, std::size_t n);
197 
198 void generateEnvironmentsMesh(std::vector<CollisionObject*>& env,
199  CoalScalar env_scale, std::size_t n);
200 
205 
212 
213 Box makeRandomBox(CoalScalar min_size, CoalScalar max_size);
214 
215 Sphere makeRandomSphere(CoalScalar min_size, CoalScalar max_size);
216 
218 
219 Capsule makeRandomCapsule(std::array<CoalScalar, 2> min_size,
220  std::array<CoalScalar, 2> max_size);
221 
222 Cone makeRandomCone(std::array<CoalScalar, 2> min_size,
223  std::array<CoalScalar, 2> max_size);
224 
225 Cylinder makeRandomCylinder(std::array<CoalScalar, 2> min_size,
226  std::array<CoalScalar, 2> max_size);
227 
229 
230 Plane makeRandomPlane(CoalScalar min_size, CoalScalar max_size);
231 
233 
234 std::shared_ptr<ShapeBase> makeRandomGeometry(NODE_TYPE node_type);
235 
236 } // namespace coal
237 
238 #endif
coal::DistanceRes::distance
double distance
Definition: utility.h:169
coal::makeRandomGeometry
std::shared_ptr< ShapeBase > makeRandomGeometry(NODE_TYPE node_type)
Definition: utility.cpp:607
octree.h
coal::vfmt
const Eigen::IOFormat vfmt
Definition: utility.cpp:83
coal::BenchTimer
Definition: utility.h:87
coal::TStruct::records
std::vector< double > records
Definition: utility.h:115
coal::BenchTimer::getElapsedTime
double getElapsedTime()
get elapsed time in milli-second
Definition: utility.cpp:81
coal::Vec3s
Eigen::Matrix< CoalScalar, 3, 1 > Vec3s
Definition: coal/data_types.h:77
coal::DistanceRes
Definition: utility.h:168
coal::generateRandomTransform
void generateRandomTransform(CoalScalar extents[6], Transform3s &transform)
Generate one random transform whose translation is constrained by extents and rotation without constr...
Definition: utility.cpp:210
coal::TStruct
Definition: utility.h:114
coal::TStruct::push_back
void push_back(double t)
Definition: utility.h:120
coal::makeRandomCone
Cone makeRandomCone(std::array< CoalScalar, 2 > min_size, std::array< CoalScalar, 2 > max_size)
Definition: utility.cpp:581
coal::BenchTimer::startTimeInMicroSec
double startTimeInMicroSec
starting time in micro-second
Definition: utility.h:101
coal::BenchTimer::~BenchTimer
~BenchTimer()
Definition: utility.cpp:34
coal::BenchTimer::stop
void stop()
stop the timer
Definition: utility.cpp:45
coal::Halfspace
Half Space: this is equivalent to the Plane in ODE. A Half space has a priviledged direction: the dir...
Definition: coal/shape/geometric_shapes.h:892
coal::makeRandomConvex
Convex< Triangle > makeRandomConvex(CoalScalar min_size, CoalScalar max_size)
Definition: utility.cpp:593
coal::generateEnvironments
void generateEnvironments(std::vector< CollisionObject * > &env, CoalScalar env_scale, std::size_t n)
Definition: utility.cpp:392
coal::generateEnvironmentsMesh
void generateEnvironmentsMesh(std::vector< CollisionObject * > &env, CoalScalar env_scale, std::size_t n)
Definition: utility.cpp:423
coal::makeRandomHalfspace
Halfspace makeRandomHalfspace(CoalScalar min_size, CoalScalar max_size)
Definition: utility.cpp:602
coal::NODE_TYPE
NODE_TYPE
traversal node type: bounding volume (AABB, OBB, RSS, kIOS, OBBRSS, KDOP16, KDOP18,...
Definition: coal/collision_object.h:64
coal::Capsule
Capsule It is where is the distance between the point x and the capsule segment AB,...
Definition: coal/shape/geometric_shapes.h:383
collision_data.h
coal::getNodeTypeName
std::string getNodeTypeName(NODE_TYPE node_type)
Definition: utility.cpp:327
coal::AngleAxis
Eigen::AngleAxis< CoalScalar > AngleAxis
Definition: utility.h:128
coal
Main namespace.
Definition: coal/broadphase/broadphase_bruteforce.h:44
coal::Quatf
Eigen::Quaternion< CoalScalar > Quatf
Definition: coal/math/transform.h:47
coal::makeRandomSphere
Sphere makeRandomSphere(CoalScalar min_size, CoalScalar max_size)
Definition: utility.cpp:565
coal::makeRandomBox
Box makeRandomBox(CoalScalar min_size, CoalScalar max_size)
Definition: utility.cpp:559
coal::buildBox
Convex< Quadrilateral > buildBox(CoalScalar l, CoalScalar w, CoalScalar d)
Constructs a box with halfsides (l, w, d), centered around 0. The box is 2*l wide on the x-axis,...
Definition: utility.cpp:460
coal::BenchTimer::endCount
timeval endCount
Definition: utility.h:110
coal::Ellipsoid
Ellipsoid centered at point zero.
Definition: coal/shape/geometric_shapes.h:305
default_broadphase_callbacks.h
coal::DistanceRes::p1
Vec3s p1
Definition: utility.h:170
coal::DistanceRes::p2
Vec3s p2
Definition: utility.h:171
collision_object.h
coal::BenchTimer::getElapsedTimeInMilliSec
double getElapsedTimeInMilliSec()
get elapsed time in milli-second
Definition: utility.cpp:73
coal::BenchTimer::endTimeInMicroSec
double endTimeInMicroSec
ending time in micro-second
Definition: utility.h:102
coal::Plane
Infinite plane. A plane can be viewed as two half spaces; it has no priviledged direction....
Definition: coal/shape/geometric_shapes.h:983
convex.h
coal::Box
Center at zero point, axis aligned box.
Definition: coal/shape/geometric_shapes.h:166
coal::constructPolytopeFromEllipsoid
Convex< Triangle > constructPolytopeFromEllipsoid(const Ellipsoid &ellipsoid)
We give an ellipsoid as input. The output is a 20 faces polytope which vertices belong to the origina...
Definition: utility.cpp:501
coal::Sphere
Center at zero point sphere.
Definition: coal/shape/geometric_shapes.h:240
coal::Transform3s
Simple transform class used locally by InterpMotion.
Definition: coal/math/transform.h:55
coal::operator<<
static std::ostream & operator<<(std::ostream &o, const Quatf &q)
Definition: coal/math/transform.h:49
coal::BenchTimer::BenchTimer
BenchTimer()
Definition: utility.cpp:19
coal::UnitZ
const Vec3s UnitZ
Definition: utility.cpp:90
transform.h
coal::TStruct::overall_time
double overall_time
Definition: utility.h:116
coal::defaultCollisionFunction
bool defaultCollisionFunction(CollisionObject *o1, CollisionObject *o2, void *data)
Provides a simple callback for the collision query in the BroadPhaseCollisionManager....
Definition: default_broadphase_callbacks.cpp:42
collision-bench.filename
filename
Definition: collision-bench.py:6
coal::transform
COAL_DLLAPI Halfspace transform(const Halfspace &a, const Transform3s &tf)
Definition: geometric_shapes_utility.cpp:248
coal::BenchTimer::stopped
int stopped
stop flag
Definition: utility.h:103
coal::makeRandomPlane
Plane makeRandomPlane(CoalScalar min_size, CoalScalar max_size)
Definition: utility.cpp:598
coal::CollisionObject
the object for collision or distance computation, contains the geometry and the transform information
Definition: coal/collision_object.h:214
coal::Convex
Convex polytope.
Definition: coal/serialization/collision_object.h:51
coal::UnitX
const Vec3s UnitX
Definition: utility.cpp:88
coal::Cylinder
Cylinder along Z axis. The cylinder is defined at its centroid.
Definition: coal/shape/geometric_shapes.h:560
coal::generateRandomTransforms
void generateRandomTransforms(CoalScalar extents[6], std::vector< Transform3s > &transforms, std::size_t n)
Generate n random transforms whose translations are constrained by extents.
Definition: utility.cpp:226
extents
CoalScalar extents[6]
Definition: test/geometric_shapes.cpp:53
coal::OcTreePtr_t
shared_ptr< OcTree > OcTreePtr_t
Definition: include/coal/fwd.hh:144
coal::defaultDistanceFunction
bool defaultDistanceFunction(CollisionObject *o1, CollisionObject *o2, void *data, CoalScalar &dist)
Collision data for use with the DefaultContinuousCollisionFunction. It stores the collision request a...
Definition: default_broadphase_callbacks.cpp:66
coal::Cone
Cone The base of the cone is at and the top is at .
Definition: coal/shape/geometric_shapes.h:467
coal::pyfmt
const Eigen::IOFormat pyfmt
Definition: utility.cpp:85
coal::makeQuat
Quatf makeQuat(CoalScalar w, CoalScalar x, CoalScalar y, CoalScalar z)
Definition: utility.cpp:370
coal::OcTree
Octree is one type of collision geometry which can encode uncertainty information in the sensor data.
Definition: coal/octree.h:53
coal::saveOBJFile
void saveOBJFile(const char *filename, std::vector< Vec3s > &points, std::vector< Triangle > &triangles)
Definition: utility.cpp:163
coal::BenchTimer::start
void start()
start timer
Definition: utility.cpp:36
coal::TStruct::TStruct
TStruct()
Definition: utility.h:118
coal::BenchTimer::getElapsedTimeInSec
double getElapsedTimeInSec()
Definition: utility.cpp:77
octomap
Definition: utility.h:80
coal::UnitY
const Vec3s UnitY
Definition: utility.cpp:89
coal::makeRandomEllipsoid
Ellipsoid makeRandomEllipsoid(CoalScalar min_size, CoalScalar max_size)
Definition: utility.cpp:569
coal::BenchTimer::startCount
timeval startCount
Definition: utility.h:109
coal::getNbRun
std::size_t getNbRun(const int &argc, char const *const *argv, std::size_t defaultValue)
Get the argument –nb-run from argv.
Definition: utility.cpp:384
t
dictionary t
coal::BenchTimer::getElapsedTimeInMicroSec
double getElapsedTimeInMicroSec()
get elapsed time in micro-second
Definition: utility.cpp:55
coal::makeRandomCylinder
Cylinder makeRandomCylinder(std::array< CoalScalar, 2 > min_size, std::array< CoalScalar, 2 > max_size)
Definition: utility.cpp:587
coal::CoalScalar
double CoalScalar
Definition: coal/data_types.h:76
coal::makeRandomCapsule
Capsule makeRandomCapsule(std::array< CoalScalar, 2 > min_size, std::array< CoalScalar, 2 > max_size)
Definition: utility.cpp:575
coal::loadOBJFile
void loadOBJFile(const char *filename, std::vector< Vec3s > &points, std::vector< Triangle > &triangles)
Load an obj mesh file.
Definition: utility.cpp:97


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