kDOP.h 6.37 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
 *     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
38
39
#ifndef HPP_FCL_KDOP_H
#define HPP_FCL_KDOP_H
sachinc's avatar
sachinc committed
40

41
#include <stdexcept>
42
#include <hpp/fcl/math/types.h>
sachinc's avatar
sachinc committed
43

44
45
namespace hpp
{
sachinc's avatar
sachinc committed
46
47
48
namespace fcl
{

49
  class CollisionRequest;
sachinc's avatar
sachinc committed
50

51
52
/// @brief KDOP class describes the KDOP collision structures. K is set as the template parameter, which should be 16, 18, or 24
///  The KDOP structure is defined by some pairs of parallel planes defined by some axes. 
53
54
55
56
57
58
59
60
61
/// For K = 16, the planes are 6 AABB planes and 10 diagonal planes that cut off some space of the edges:
/// (-1,0,0) and (1,0,0)  -> indices 0 and 8
/// (0,-1,0) and (0,1,0)  -> indices 1 and 9
/// (0,0,-1) and (0,0,1)  -> indices 2 and 10
/// (-1,-1,0) and (1,1,0) -> indices 3 and 11
/// (-1,0,-1) and (1,0,1) -> indices 4 and 12
/// (0,-1,-1) and (0,1,1) -> indices 5 and 13
/// (-1,1,0) and (1,-1,0) -> indices 6 and 14
/// (-1,0,1) and (1,0,-1) -> indices 7 and 15
62
63
64
65
66
67
68
69
70
71
/// For K = 18, the planes are 6 AABB planes and 12 diagonal planes that cut off some space of the edges:
/// (-1,0,0) and (1,0,0)  -> indices 0 and 9
/// (0,-1,0) and (0,1,0)  -> indices 1 and 10
/// (0,0,-1) and (0,0,1)  -> indices 2 and 11
/// (-1,-1,0) and (1,1,0) -> indices 3 and 12
/// (-1,0,-1) and (1,0,1) -> indices 4 and 13
/// (0,-1,-1) and (0,1,1) -> indices 5 and 14
/// (-1,1,0) and (1,-1,0) -> indices 6 and 15
/// (-1,0,1) and (1,0,-1) -> indices 7 and 16
/// (0,-1,1) and (0,1,-1) -> indices 8 and 17
72
73
74
75
76
77
78
79
80
81
82
83
84
/// For K = 18, the planes are 6 AABB planes and 18 diagonal planes that cut off some space of the edges:
/// (-1,0,0) and (1,0,0)  -> indices 0 and 12
/// (0,-1,0) and (0,1,0)  -> indices 1 and 13
/// (0,0,-1) and (0,0,1)  -> indices 2 and 14
/// (-1,-1,0) and (1,1,0) -> indices 3 and 15
/// (-1,0,-1) and (1,0,1) -> indices 4 and 16
/// (0,-1,-1) and (0,1,1) -> indices 5 and 17
/// (-1,1,0) and (1,-1,0) -> indices 6 and 18
/// (-1,0,1) and (1,0,-1) -> indices 7 and 19
/// (0,-1,1) and (0,1,-1) -> indices 8 and 20
/// (-1, -1, 1) and (1, 1, -1) --> indices 9 and 21
/// (-1, 1, -1) and (1, -1, 1) --> indices 10 and 22
/// (1, -1, -1) and (-1, 1, 1) --> indices 11 and 23
sachinc's avatar
sachinc committed
85
86
87
template<size_t N>
class KDOP
{
88
89
90
91
private:
  /// @brief Origin's distances to N KDOP planes
  FCL_REAL dist_[N];

sachinc's avatar
sachinc committed
92
93
public:

94
95
  /// @brief Creating kDOP containing nothing
  KDOP();
sachinc's avatar
sachinc committed
96

97
98
  /// @brief Creating kDOP containing only one point
  KDOP(const Vec3f& v);
sachinc's avatar
sachinc committed
99

100
101
  /// @brief Creating kDOP containing two points
  KDOP(const Vec3f& a, const Vec3f& b);
sachinc's avatar
sachinc committed
102
  
103
104
  /// @brief Check whether two KDOPs are overlapped
  bool overlap(const KDOP<N>& other) const;
sachinc's avatar
sachinc committed
105

106
  /// Not implemented
107
108
  bool overlap(const KDOP<N>& other, const CollisionRequest&,
               FCL_REAL& sqrDistLowerBound) const
109
  {
110
111
    sqrDistLowerBound = sqrt (-1);
    return overlap (other);
112
113
  }

114
115
  //// @brief Check whether one point is inside the KDOP
  bool inside(const Vec3f& p) const;
sachinc's avatar
sachinc committed
116

117
118
  /// @brief Merge the point and the KDOP
  KDOP<N>& operator += (const Vec3f& p);
sachinc's avatar
sachinc committed
119

120
121
  /// @brief Merge two KDOPs
  KDOP<N>& operator += (const KDOP<N>& other);
sachinc's avatar
sachinc committed
122

123
124
  /// @brief Create a KDOP by mergin two KDOPs
  KDOP<N> operator + (const KDOP<N>& other) const;
sachinc's avatar
sachinc committed
125

126
  /// @brief The (AABB) width
127
  inline FCL_REAL width() const
sachinc's avatar
sachinc committed
128
129
130
131
  {
    return dist_[N / 2] - dist_[0];
  }

132
  /// @brief The (AABB) height
133
  inline FCL_REAL height() const
sachinc's avatar
sachinc committed
134
135
136
137
  {
    return dist_[N / 2 + 1] - dist_[1];
  }

138
  /// @brief The (AABB) depth
139
  inline FCL_REAL depth() const
sachinc's avatar
sachinc committed
140
141
142
143
  {
    return dist_[N / 2 + 2] - dist_[2];
  }

144
  /// @brief The (AABB) volume
145
  inline FCL_REAL volume() const
sachinc's avatar
sachinc committed
146
147
148
149
  {
    return width() * height() * depth();
  }

150
  /// @brief Size of the kDOP (used in BV_Splitter to order two kDOPs)
151
  inline FCL_REAL size() const
sachinc's avatar
sachinc committed
152
153
154
155
  {
    return width() * width() + height() * height() + depth() * depth();
  }

156
  /// @brief The (AABB) center
sachinc's avatar
sachinc committed
157
158
159
160
161
  inline Vec3f center() const
  {
    return Vec3f(dist_[0] + dist_[N / 2], dist_[1] + dist_[N / 2 + 1], dist_[2] + dist_[N / 2 + 2]) * 0.5;
  }

162
163
  /// @brief The distance between two KDOP<N>. Not implemented.
  FCL_REAL distance(const KDOP<N>& other, Vec3f* P = NULL, Vec3f* Q = NULL) const;
sachinc's avatar
sachinc committed
164

jpan's avatar
jpan committed
165
166
167
168
169
170
171
172
173
174
  inline FCL_REAL dist(std::size_t i) const
  {
    return dist_[i];
  }

  inline FCL_REAL& dist(std::size_t i)
  {
    return dist_[i];
  }

sachinc's avatar
sachinc committed
175
176
177

};

Joseph Mirabel's avatar
Joseph Mirabel committed
178
179
180
181
182
183
184
185
186
187
188
189
190
191
template<size_t N>
bool overlap(const Matrix3f& /*R0*/, const Vec3f& /*T0*/,
             const KDOP<N>& /*b1*/, const KDOP<N>& /*b2*/)
{
  throw std::logic_error ("not implemented");
}

template<size_t N>
bool overlap(const Matrix3f& /*R0*/, const Vec3f& /*T0*/,
             const KDOP<N>& /*b1*/, const KDOP<N>& /*b2*/,
             const CollisionRequest& /*request*/, FCL_REAL& /*sqrDistLowerBound*/)
{
  throw std::logic_error ("not implemented");
}
jpan's avatar
jpan committed
192
193
194
195
196

/// @brief translate the KDOP BV
template<size_t N>
KDOP<N> translate(const KDOP<N>& bv, const Vec3f& t);

sachinc's avatar
sachinc committed
197
198
}

199
200
} // namespace hpp

sachinc's avatar
sachinc committed
201
#endif