GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: include/hpp/fcl/BV/OBB.h Lines: 9 12 75.0 %
Date: 2024-02-09 12:57:42 Branches: 6 12 50.0 %

Line Branch Exec Source
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
36
/** \author Jia Pan */
37
38
#ifndef HPP_FCL_OBB_H
39
#define HPP_FCL_OBB_H
40
41
#include <hpp/fcl/data_types.h>
42
43
namespace hpp {
44
namespace fcl {
45
46
struct CollisionRequest;
47
48
/// @addtogroup Bounding_Volume
49
/// @{
50
51
/// @brief Oriented bounding box class
52
struct HPP_FCL_DLLAPI OBB {
53
  /// @brief Orientation of OBB. axis[i] is the ith column of the orientation
54
  /// matrix for the box; it is also the i-th principle direction of the box. We
55
  /// assume that axis[0] corresponds to the axis with the longest box edge,
56
  /// axis[1] corresponds to the shorter one and axis[2] corresponds to the
57
  /// shortest one.
58
  Matrix3f axes;
59
60
  /// @brief Center of OBB
61
  Vec3f To;
62
63
  /// @brief Half dimensions of OBB
64
  Vec3f extent;
65
66

3078316
  OBB() : axes(Matrix3f::Zero()), To(Vec3f::Zero()), extent(Vec3f::Zero()) {}
67
68
  /// @brief Equality operator
69
374509
  bool operator==(const OBB& other) const {
70

374509
    return axes == other.axes && To == other.To && extent == other.extent;
71
  }
72
73
  /// @brief Difference operator
74
  bool operator!=(const OBB& other) const { return !(*this == other); }
75
76
  /// @brief Check whether the OBB contains a point.
77
  bool contain(const Vec3f& p) const;
78
79
  /// Check collision between two OBB
80
  /// @return true if collision happens.
81
  bool overlap(const OBB& other) const;
82
83
  /// Check collision between two OBB
84
  /// @return true if collision happens.
85
  /// @retval sqrDistLowerBound squared lower bound on distance between boxes if
86
  ///         they do not overlap.
87
  bool overlap(const OBB& other, const CollisionRequest& request,
88
               FCL_REAL& sqrDistLowerBound) const;
89
90
  /// @brief Distance between two OBBs, not implemented.
91
  FCL_REAL distance(const OBB& other, Vec3f* P = NULL, Vec3f* Q = NULL) const;
92
93
  /// @brief A simple way to merge the OBB and a point (the result is not
94
  /// compact).
95
  OBB& operator+=(const Vec3f& p);
96
97
  /// @brief Merge the OBB and another OBB (the result is not compact).
98
  OBB& operator+=(const OBB& other) {
99
    *this = *this + other;
100
    return *this;
101
  }
102
103
  /// @brief Return the merged OBB of current OBB and the other one (the result
104
  /// is not compact).
105
  OBB operator+(const OBB& other) const;
106
107
  /// @brief Size of the OBB (used in BV_Splitter to order two OBBs)
108
1581320
  inline FCL_REAL size() const { return extent.squaredNorm(); }
109
110
  /// @brief Center of the OBB
111
130672
  inline const Vec3f& center() const { return To; }
112
113
  /// @brief Width of the OBB.
114
7592
  inline FCL_REAL width() const { return 2 * extent[0]; }
115
116
  /// @brief Height of the OBB.
117
7592
  inline FCL_REAL height() const { return 2 * extent[1]; }
118
119
  /// @brief Depth of the OBB
120
7592
  inline FCL_REAL depth() const { return 2 * extent[2]; }
121
122
  /// @brief Volume of the OBB
123
7592
  inline FCL_REAL volume() const { return width() * height() * depth(); }
124
};
125
126
/// @brief Translate the OBB bv
127
HPP_FCL_DLLAPI OBB translate(const OBB& bv, const Vec3f& t);
128
129
/// @brief Check collision between two obbs, b1 is in configuration (R0, T0) and
130
/// b2 is in identity.
131
HPP_FCL_DLLAPI bool overlap(const Matrix3f& R0, const Vec3f& T0, const OBB& b1,
132
                            const OBB& b2);
133
134
/// @brief Check collision between two obbs, b1 is in configuration (R0, T0) and
135
/// b2 is in identity.
136
HPP_FCL_DLLAPI bool overlap(const Matrix3f& R0, const Vec3f& T0, const OBB& b1,
137
                            const OBB& b2, const CollisionRequest& request,
138
                            FCL_REAL& sqrDistLowerBound);
139
140
/// Check collision between two boxes
141
/// @param B, T orientation and position of first box,
142
/// @param a half dimensions of first box,
143
/// @param b half dimensions of second box.
144
/// The second box is in identity configuration.
145
HPP_FCL_DLLAPI bool obbDisjoint(const Matrix3f& B, const Vec3f& T,
146
                                const Vec3f& a, const Vec3f& b);
147
}  // namespace fcl
148
149
}  // namespace hpp
150
151
#endif