kDOP.h 6.42 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/data_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
53
  /// @addtogroup Bounding_Volume
  /// @{

54
55
/// @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. 
56
57
58
59
60
61
62
63
64
/// 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
65
66
67
68
69
70
71
72
73
74
/// 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
75
76
77
78
79
80
81
82
83
84
85
86
87
/// 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
88
89
90
template<size_t N>
class KDOP
{
91
92
93
94
private:
  /// @brief Origin's distances to N KDOP planes
  FCL_REAL dist_[N];

sachinc's avatar
sachinc committed
95
96
public:

97
98
  /// @brief Creating kDOP containing nothing
  KDOP();
sachinc's avatar
sachinc committed
99

100
101
  /// @brief Creating kDOP containing only one point
  KDOP(const Vec3f& v);
sachinc's avatar
sachinc committed
102

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

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

117
118
    /// @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
119

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

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

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

129
130
131
132
133
134
135
136
137
138
139
140
141
   /// @brief Size of the kDOP (used in BV_Splitter to order two kDOPs)
  inline FCL_REAL size() const
  {
    return width() * width() + height() * height() + depth() * depth();
  }

  /// @brief The (AABB) center
  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;
  }


142
  /// @brief The (AABB) width
143
  inline FCL_REAL width() const
sachinc's avatar
sachinc committed
144
145
146
147
  {
    return dist_[N / 2] - dist_[0];
  }

148
  /// @brief The (AABB) height
149
  inline FCL_REAL height() const
sachinc's avatar
sachinc committed
150
151
152
153
  {
    return dist_[N / 2 + 1] - dist_[1];
  }

154
  /// @brief The (AABB) depth
155
  inline FCL_REAL depth() const
sachinc's avatar
sachinc committed
156
157
158
159
  {
    return dist_[N / 2 + 2] - dist_[2];
  }

160
  /// @brief The (AABB) volume
161
  inline FCL_REAL volume() const
sachinc's avatar
sachinc committed
162
163
164
165
  {
    return width() * height() * depth();
  }

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

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

176
177
  //// @brief Check whether one point is inside the KDOP
  bool inside(const Vec3f& p) const;
sachinc's avatar
sachinc committed
178
179
180

};

Joseph Mirabel's avatar
Joseph Mirabel committed
181
182
183
184
185
186
187
188
189
190
191
192
193
194
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
195
196
197
198
199

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

sachinc's avatar
sachinc committed
200
201
}

202
203
} // namespace hpp

sachinc's avatar
sachinc committed
204
#endif