geometric_shapes_utility.h 7.95 KB
Newer Older
sachinc's avatar
sachinc committed
1
2
3
/*
 * Software License Agreement (BSD License)
 *
4
5
 *  Copyright (c) 2011-2014, Willow Garage, Inc.
 *  Copyright (c) 2014-2015, Open Source Robotics Foundation
sachinc's avatar
sachinc committed
6
7
8
9
10
11
12
13
14
15
16
17
 *  All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions
 *  are met:
 *
 *   * Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 *   * Redistributions in binary form must reproduce the above
 *     copyright notice, this list of conditions and the following
 *     disclaimer in the documentation and/or other materials provided
 *     with the distribution.
18
 *   * Neither the name of Open Source Robotics Foundation nor the names of its
sachinc's avatar
sachinc committed
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
 *     contributors may be used to endorse or promote products derived
 *     from this software without specific prior written permission.
 *
 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 *  POSSIBILITY OF SUCH DAMAGE.
 */

/** \author Jia Pan */


Joseph Mirabel's avatar
Joseph Mirabel committed
39
40
#ifndef HPP_FCL_GEOMETRIC_SHAPES_UTILITY_H
#define HPP_FCL_GEOMETRIC_SHAPES_UTILITY_H
sachinc's avatar
sachinc committed
41

jpan's avatar
   
jpan committed
42
#include <vector>
43
44
#include <hpp/fcl/shape/geometric_shapes.h>
#include <hpp/fcl/BV/BV.h>
45
#include <hpp/fcl/internal/BV_fitter.h>
46

47
48
namespace hpp
{
sachinc's avatar
sachinc committed
49
50
51
namespace fcl
{

52
/// @cond IGNORE
jpan's avatar
   
jpan committed
53
54
namespace details
{
55
/// @brief get the vertices of some convex shape which can bound the given shape in a specific configuration
Joseph Mirabel's avatar
Joseph Mirabel committed
56
57
58
59
60
61
62
std::vector<Vec3f> getBoundVertices(const Box& box, const Transform3f& tf) HPP_FCL_DLLAPI;
std::vector<Vec3f> getBoundVertices(const Sphere& sphere, const Transform3f& tf) HPP_FCL_DLLAPI;
std::vector<Vec3f> getBoundVertices(const Capsule& capsule, const Transform3f& tf) HPP_FCL_DLLAPI;
std::vector<Vec3f> getBoundVertices(const Cone& cone, const Transform3f& tf) HPP_FCL_DLLAPI;
std::vector<Vec3f> getBoundVertices(const Cylinder& cylinder, const Transform3f& tf) HPP_FCL_DLLAPI;
std::vector<Vec3f> getBoundVertices(const ConvexBase& convex, const Transform3f& tf) HPP_FCL_DLLAPI;
std::vector<Vec3f> getBoundVertices(const TriangleP& triangle, const Transform3f& tf) HPP_FCL_DLLAPI;
63
64
} 
/// @endcond
jpan's avatar
   
jpan committed
65
66


67
/// @brief calculate a bounding volume for a shape in a specific configuration
jpan's avatar
   
jpan committed
68
template<typename BV, typename S>
Joseph Mirabel's avatar
Joseph Mirabel committed
69
inline void computeBV(const S& s, const Transform3f& tf, BV& bv)
jpan's avatar
   
jpan committed
70
71
72
73
74
75
{
  std::vector<Vec3f> convex_bound_vertices = details::getBoundVertices(s, tf);
  fit(&convex_bound_vertices[0], (int)convex_bound_vertices.size(), bv);
}

template<>
Joseph Mirabel's avatar
Joseph Mirabel committed
76
void computeBV<AABB, Box>(const Box& s, const Transform3f& tf, AABB& bv) HPP_FCL_DLLAPI;
jpan's avatar
   
jpan committed
77
78

template<>
Joseph Mirabel's avatar
Joseph Mirabel committed
79
void computeBV<AABB, Sphere>(const Sphere& s, const Transform3f& tf, AABB& bv) HPP_FCL_DLLAPI;
jpan's avatar
   
jpan committed
80
81

template<>
Joseph Mirabel's avatar
Joseph Mirabel committed
82
void computeBV<AABB, Capsule>(const Capsule& s, const Transform3f& tf, AABB& bv) HPP_FCL_DLLAPI;
jpan's avatar
   
jpan committed
83
84

template<>
Joseph Mirabel's avatar
Joseph Mirabel committed
85
void computeBV<AABB, Cone>(const Cone& s, const Transform3f& tf, AABB& bv) HPP_FCL_DLLAPI;
sachinc's avatar
sachinc committed
86

jpan's avatar
   
jpan committed
87
template<>
Joseph Mirabel's avatar
Joseph Mirabel committed
88
void computeBV<AABB, Cylinder>(const Cylinder& s, const Transform3f& tf, AABB& bv) HPP_FCL_DLLAPI;
sachinc's avatar
sachinc committed
89

jpan's avatar
   
jpan committed
90
template<>
Joseph Mirabel's avatar
Joseph Mirabel committed
91
void computeBV<AABB, ConvexBase>(const ConvexBase& s, const Transform3f& tf, AABB& bv) HPP_FCL_DLLAPI;
sachinc's avatar
sachinc committed
92

93
template<>
Joseph Mirabel's avatar
Joseph Mirabel committed
94
void computeBV<AABB, TriangleP>(const TriangleP& s, const Transform3f& tf, AABB& bv) HPP_FCL_DLLAPI;
95

96
template<>
Joseph Mirabel's avatar
Joseph Mirabel committed
97
void computeBV<AABB, Halfspace>(const Halfspace& s, const Transform3f& tf, AABB& bv) HPP_FCL_DLLAPI;
sachinc's avatar
sachinc committed
98

jpan's avatar
   
jpan committed
99
template<>
Joseph Mirabel's avatar
Joseph Mirabel committed
100
void computeBV<AABB, Plane>(const Plane& s, const Transform3f& tf, AABB& bv) HPP_FCL_DLLAPI;
sachinc's avatar
sachinc committed
101
102
103



jpan's avatar
   
jpan committed
104
template<>
Joseph Mirabel's avatar
Joseph Mirabel committed
105
void computeBV<OBB, Box>(const Box& s, const Transform3f& tf, OBB& bv) HPP_FCL_DLLAPI;
sachinc's avatar
sachinc committed
106

jpan's avatar
   
jpan committed
107
template<>
Joseph Mirabel's avatar
Joseph Mirabel committed
108
void computeBV<OBB, Sphere>(const Sphere& s, const Transform3f& tf, OBB& bv) HPP_FCL_DLLAPI;
sachinc's avatar
sachinc committed
109

jpan's avatar
   
jpan committed
110
template<>
Joseph Mirabel's avatar
Joseph Mirabel committed
111
void computeBV<OBB, Capsule>(const Capsule& s, const Transform3f& tf, OBB& bv) HPP_FCL_DLLAPI;
sachinc's avatar
sachinc committed
112

jpan's avatar
   
jpan committed
113
template<>
Joseph Mirabel's avatar
Joseph Mirabel committed
114
void computeBV<OBB, Cone>(const Cone& s, const Transform3f& tf, OBB& bv) HPP_FCL_DLLAPI;
sachinc's avatar
sachinc committed
115

jpan's avatar
   
jpan committed
116
template<>
Joseph Mirabel's avatar
Joseph Mirabel committed
117
void computeBV<OBB, Cylinder>(const Cylinder& s, const Transform3f& tf, OBB& bv) HPP_FCL_DLLAPI;
sachinc's avatar
sachinc committed
118

jpan's avatar
   
jpan committed
119
template<>
Joseph Mirabel's avatar
Joseph Mirabel committed
120
void computeBV<OBB, ConvexBase>(const ConvexBase& s, const Transform3f& tf, OBB& bv) HPP_FCL_DLLAPI;
sachinc's avatar
sachinc committed
121

122
template<>
Joseph Mirabel's avatar
Joseph Mirabel committed
123
void computeBV<OBB, Halfspace>(const Halfspace& s, const Transform3f& tf, OBB& bv) HPP_FCL_DLLAPI;
124

jpan's avatar
   
jpan committed
125
template<>
Joseph Mirabel's avatar
Joseph Mirabel committed
126
void computeBV<RSS, Halfspace>(const Halfspace& s, const Transform3f& tf, RSS& bv) HPP_FCL_DLLAPI;
127
128

template<>
Joseph Mirabel's avatar
Joseph Mirabel committed
129
void computeBV<OBBRSS, Halfspace>(const Halfspace& s, const Transform3f& tf, OBBRSS& bv) HPP_FCL_DLLAPI;
130
131

template<>
Joseph Mirabel's avatar
Joseph Mirabel committed
132
void computeBV<kIOS, Halfspace>(const Halfspace& s, const Transform3f& tf, kIOS& bv) HPP_FCL_DLLAPI;
133
134

template<>
Joseph Mirabel's avatar
Joseph Mirabel committed
135
void computeBV<KDOP<16>, Halfspace>(const Halfspace& s, const Transform3f& tf, KDOP<16>& bv) HPP_FCL_DLLAPI;
sachinc's avatar
sachinc committed
136

137
template<>
Joseph Mirabel's avatar
Joseph Mirabel committed
138
void computeBV<KDOP<18>, Halfspace>(const Halfspace& s, const Transform3f& tf, KDOP<18>& bv) HPP_FCL_DLLAPI;
139
140

template<>
Joseph Mirabel's avatar
Joseph Mirabel committed
141
void computeBV<KDOP<24>, Halfspace>(const Halfspace& s, const Transform3f& tf, KDOP<24>& bv) HPP_FCL_DLLAPI;
142
143

template<>
Joseph Mirabel's avatar
Joseph Mirabel committed
144
void computeBV<OBB, Plane>(const Plane& s, const Transform3f& tf, OBB& bv) HPP_FCL_DLLAPI;
145

jpan's avatar
   
jpan committed
146
template<>
Joseph Mirabel's avatar
Joseph Mirabel committed
147
void computeBV<RSS, Plane>(const Plane& s, const Transform3f& tf, RSS& bv) HPP_FCL_DLLAPI;
sachinc's avatar
sachinc committed
148

jpan's avatar
   
jpan committed
149
template<>
Joseph Mirabel's avatar
Joseph Mirabel committed
150
void computeBV<OBBRSS, Plane>(const Plane& s, const Transform3f& tf, OBBRSS& bv) HPP_FCL_DLLAPI;
sachinc's avatar
sachinc committed
151

jpan's avatar
   
jpan committed
152
template<>
Joseph Mirabel's avatar
Joseph Mirabel committed
153
void computeBV<kIOS, Plane>(const Plane& s, const Transform3f& tf, kIOS& bv) HPP_FCL_DLLAPI;
sachinc's avatar
sachinc committed
154

jpan's avatar
   
jpan committed
155
template<>
Joseph Mirabel's avatar
Joseph Mirabel committed
156
void computeBV<KDOP<16>, Plane>(const Plane& s, const Transform3f& tf, KDOP<16>& bv) HPP_FCL_DLLAPI;
sachinc's avatar
sachinc committed
157

jpan's avatar
   
jpan committed
158
template<>
Joseph Mirabel's avatar
Joseph Mirabel committed
159
void computeBV<KDOP<18>, Plane>(const Plane& s, const Transform3f& tf, KDOP<18>& bv) HPP_FCL_DLLAPI;
sachinc's avatar
sachinc committed
160

jpan's avatar
   
jpan committed
161
template<>
Joseph Mirabel's avatar
Joseph Mirabel committed
162
void computeBV<KDOP<24>, Plane>(const Plane& s, const Transform3f& tf, KDOP<24>& bv) HPP_FCL_DLLAPI;
163

jpan's avatar
jpan committed
164

165
/// @brief construct a box shape (with a configuration) from a given bounding volume
Joseph Mirabel's avatar
Joseph Mirabel committed
166
void constructBox(const AABB& bv, Box& box, Transform3f& tf) HPP_FCL_DLLAPI;
jpan's avatar
jpan committed
167

Joseph Mirabel's avatar
Joseph Mirabel committed
168
void constructBox(const OBB& bv, Box& box, Transform3f& tf) HPP_FCL_DLLAPI;
jpan's avatar
jpan committed
169

Joseph Mirabel's avatar
Joseph Mirabel committed
170
void constructBox(const OBBRSS& bv, Box& box, Transform3f& tf) HPP_FCL_DLLAPI;
jpan's avatar
jpan committed
171

Joseph Mirabel's avatar
Joseph Mirabel committed
172
void constructBox(const kIOS& bv, Box& box, Transform3f& tf) HPP_FCL_DLLAPI;
jpan's avatar
jpan committed
173

Joseph Mirabel's avatar
Joseph Mirabel committed
174
void constructBox(const RSS& bv, Box& box, Transform3f& tf) HPP_FCL_DLLAPI;
jpan's avatar
jpan committed
175

Joseph Mirabel's avatar
Joseph Mirabel committed
176
void constructBox(const KDOP<16>& bv, Box& box, Transform3f& tf) HPP_FCL_DLLAPI;
jpan's avatar
jpan committed
177

Joseph Mirabel's avatar
Joseph Mirabel committed
178
void constructBox(const KDOP<18>& bv, Box& box, Transform3f& tf) HPP_FCL_DLLAPI;
jpan's avatar
jpan committed
179

Joseph Mirabel's avatar
Joseph Mirabel committed
180
void constructBox(const KDOP<24>& bv, Box& box, Transform3f& tf) HPP_FCL_DLLAPI;
jpan's avatar
jpan committed
181

Joseph Mirabel's avatar
Joseph Mirabel committed
182
void constructBox(const AABB& bv, const Transform3f& tf_bv, Box& box, Transform3f& tf) HPP_FCL_DLLAPI;
jpan's avatar
jpan committed
183

Joseph Mirabel's avatar
Joseph Mirabel committed
184
void constructBox(const OBB& bv, const Transform3f& tf_bv, Box& box, Transform3f& tf) HPP_FCL_DLLAPI;
jpan's avatar
jpan committed
185

Joseph Mirabel's avatar
Joseph Mirabel committed
186
void constructBox(const OBBRSS& bv, const Transform3f& tf_bv, Box& box, Transform3f& tf) HPP_FCL_DLLAPI;
jpan's avatar
jpan committed
187

Joseph Mirabel's avatar
Joseph Mirabel committed
188
void constructBox(const kIOS& bv, const Transform3f& tf_bv, Box& box, Transform3f& tf) HPP_FCL_DLLAPI;
jpan's avatar
jpan committed
189

Joseph Mirabel's avatar
Joseph Mirabel committed
190
void constructBox(const RSS& bv, const Transform3f& tf_bv, Box& box, Transform3f& tf) HPP_FCL_DLLAPI;
jpan's avatar
jpan committed
191

Joseph Mirabel's avatar
Joseph Mirabel committed
192
void constructBox(const KDOP<16>& bv, const Transform3f& tf_bv, Box& box, Transform3f& tf) HPP_FCL_DLLAPI;
jpan's avatar
jpan committed
193

Joseph Mirabel's avatar
Joseph Mirabel committed
194
void constructBox(const KDOP<18>& bv, const Transform3f& tf_bv, Box& box, Transform3f& tf) HPP_FCL_DLLAPI;
jpan's avatar
jpan committed
195

Joseph Mirabel's avatar
Joseph Mirabel committed
196
void constructBox(const KDOP<24>& bv, const Transform3f& tf_bv, Box& box, Transform3f& tf) HPP_FCL_DLLAPI;
jpan's avatar
jpan committed
197

Joseph Mirabel's avatar
Joseph Mirabel committed
198
Halfspace transform(const Halfspace& a, const Transform3f& tf) HPP_FCL_DLLAPI;
199

Joseph Mirabel's avatar
Joseph Mirabel committed
200
Plane transform(const Plane& a, const Transform3f& tf) HPP_FCL_DLLAPI;
jpan's avatar
jpan committed
201

sachinc's avatar
sachinc committed
202
203
}

204
205
} // namespace hpp

sachinc's avatar
sachinc committed
206
#endif