geometric_shapes_utility.h 7.15 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
56
57
58
59
60
std::vector<Vec3f> getBoundVertices(const Box& box, const Transform3f& tf);
std::vector<Vec3f> getBoundVertices(const Sphere& sphere, const Transform3f& tf);
std::vector<Vec3f> getBoundVertices(const Capsule& capsule, const Transform3f& tf);
std::vector<Vec3f> getBoundVertices(const Cone& cone, const Transform3f& tf);
std::vector<Vec3f> getBoundVertices(const Cylinder& cylinder, const Transform3f& tf);
61
std::vector<Vec3f> getBoundVertices(const ConvexBase& convex, const Transform3f& tf);
62
std::vector<Vec3f> getBoundVertices(const TriangleP& triangle, const Transform3f& tf);
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>
69
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<>
76
void computeBV<AABB, Box>(const Box& s, const Transform3f& tf, AABB& bv);
jpan's avatar
   
jpan committed
77
78

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

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

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

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

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

93
template<>
94
void computeBV<AABB, TriangleP>(const TriangleP& s, const Transform3f& tf, AABB& bv);
95

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

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



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

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

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

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

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

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

122
123
124
template<>
void computeBV<OBB, Halfspace>(const Halfspace& s, const Transform3f& tf, OBB& bv);

jpan's avatar
   
jpan committed
125
template<>
126
127
128
129
130
131
132
133
134
135
void computeBV<RSS, Halfspace>(const Halfspace& s, const Transform3f& tf, RSS& bv);

template<>
void computeBV<OBBRSS, Halfspace>(const Halfspace& s, const Transform3f& tf, OBBRSS& bv);

template<>
void computeBV<kIOS, Halfspace>(const Halfspace& s, const Transform3f& tf, kIOS& bv);

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

137
138
139
140
141
142
143
144
template<>
void computeBV<KDOP<18>, Halfspace>(const Halfspace& s, const Transform3f& tf, KDOP<18>& bv);

template<>
void computeBV<KDOP<24>, Halfspace>(const Halfspace& s, const Transform3f& tf, KDOP<24>& bv);

template<>
void computeBV<OBB, Plane>(const Plane& s, const Transform3f& tf, OBB& bv);
145

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

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

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

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

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

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

jpan's avatar
jpan committed
164

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

198
199
200
Halfspace transform(const Halfspace& a, const Transform3f& tf);

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

sachinc's avatar
sachinc committed
202
203
}

204
205
} // namespace hpp

sachinc's avatar
sachinc committed
206
#endif