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 #include <windows.h>
53 #else
54 #include <sys/time.h>
55 #endif
56 
57 #define EIGEN_VECTOR_IS_APPROX(Va, Vb, precision) \
58  BOOST_CHECK_MESSAGE(((Va) - (Vb)).isZero(precision), \
59  "check " #Va ".isApprox(" #Vb ") failed at precision " \
60  << precision << " [\n" \
61  << (Va).transpose() << "\n!=\n" \
62  << (Vb).transpose() << "\n]")
63 
64 #define EIGEN_MATRIX_IS_APPROX(Va, Vb, precision) \
65  BOOST_CHECK_MESSAGE(((Va) - (Vb)).isZero(precision), \
66  "check " #Va ".isApprox(" #Vb ") failed at precision " \
67  << precision << " [\n" \
68  << (Va) << "\n!=\n" \
69  << (Vb) << "\n]")
70 
71 #define CoalScalar_IS_APPROX(Va, Vb, precision) \
72  BOOST_CHECK_MESSAGE(std::abs((Va) - (Vb)) < precision, \
73  "check " #Va ".isApprox(" #Vb ") failed at precision " \
74  << precision << " [\n" \
75  << Va << "\n!=\n" \
76  << Vb << "\n]")
77 
78 namespace octomap {
79 #ifdef COAL_HAS_OCTOMAP
80 typedef coal::shared_ptr<octomap::OcTree> OcTreePtr_t;
81 #endif
82 } // namespace octomap
83 namespace coal {
84 
85 class BenchTimer {
86  public:
87  BenchTimer();
88  ~BenchTimer();
89 
90  void start();
91  void stop();
92  double getElapsedTime();
93  double getElapsedTimeInSec();
94  double getElapsedTimeInMilliSec();
96  double getElapsedTimeInMicroSec();
97 
98  private:
101  int stopped;
102 #ifdef _WIN32
103  LARGE_INTEGER frequency;
104  LARGE_INTEGER startCount;
105  LARGE_INTEGER endCount;
106 #else
107  timeval startCount;
108  timeval endCount;
109 #endif
110 };
111 
112 struct TStruct {
113  std::vector<double> records;
114  double overall_time;
115 
117 
118  void push_back(double t) {
119  records.push_back(t);
120  overall_time += t;
121  }
122 };
123 
124 extern const Eigen::IOFormat vfmt;
125 extern const Eigen::IOFormat pyfmt;
126 typedef Eigen::AngleAxis<CoalScalar> AngleAxis;
127 extern const Vec3s UnitX;
128 extern const Vec3s UnitY;
129 extern const Vec3s UnitZ;
130 
132 void loadOBJFile(const char* filename, std::vector<Vec3s>& points,
133  std::vector<Triangle>& triangles);
134 
135 void saveOBJFile(const char* filename, std::vector<Vec3s>& points,
136  std::vector<Triangle>& triangles);
137 
138 #ifdef COAL_HAS_OCTOMAP
139 coal::OcTree loadOctreeFile(const std::string& filename,
140  const CoalScalar& resolution);
141 #endif
142 
148 
152  std::vector<Transform3s>& transforms,
153  std::size_t n);
154 
158 void generateRandomTransforms(CoalScalar extents[6], CoalScalar delta_trans[3],
159  CoalScalar delta_rot,
160  std::vector<Transform3s>& transforms,
161  std::vector<Transform3s>& transforms2,
162  std::size_t n);
163 
166 struct DistanceRes {
167  double distance;
170 };
171 
175  void* cdata);
176 
181  void* cdata, CoalScalar& dist);
182 
183 std::string getNodeTypeName(NODE_TYPE node_type);
184 
186 
187 std::ostream& operator<<(std::ostream& os, const Transform3s& tf);
188 
190 std::size_t getNbRun(const int& argc, char const* const* argv,
191  std::size_t defaultValue);
192 
193 void generateEnvironments(std::vector<CollisionObject*>& env,
194  CoalScalar env_scale, std::size_t n);
195 
196 void generateEnvironmentsMesh(std::vector<CollisionObject*>& env,
197  CoalScalar env_scale, std::size_t n);
198 
203 
210 
211 Box makeRandomBox(CoalScalar min_size, CoalScalar max_size);
212 
213 Sphere makeRandomSphere(CoalScalar min_size, CoalScalar max_size);
214 
216 
217 Capsule makeRandomCapsule(std::array<CoalScalar, 2> min_size,
218  std::array<CoalScalar, 2> max_size);
219 
220 Cone makeRandomCone(std::array<CoalScalar, 2> min_size,
221  std::array<CoalScalar, 2> max_size);
222 
223 Cylinder makeRandomCylinder(std::array<CoalScalar, 2> min_size,
224  std::array<CoalScalar, 2> max_size);
225 
227 
228 Plane makeRandomPlane(CoalScalar min_size, CoalScalar max_size);
229 
231 
232 std::shared_ptr<ShapeBase> makeRandomGeometry(NODE_TYPE node_type);
233 
234 } // namespace coal
235 
236 #endif
coal::DistanceRes::distance
double distance
Definition: utility.h:167
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:85
coal::TStruct::records
std::vector< double > records
Definition: utility.h:113
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:166
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:112
coal::TStruct::push_back
void push_back(double t)
Definition: utility.h:118
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:99
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:126
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:108
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:168
coal::DistanceRes::p2
Vec3s p2
Definition: utility.h:169
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:100
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:114
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:101
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:116
coal::BenchTimer::getElapsedTimeInSec
double getElapsedTimeInSec()
Definition: utility.cpp:77
octomap
Definition: utility.h:78
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:107
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 Fri Feb 14 2025 03:45:51