GCC Code Coverage Report


Directory: ./
File: include/coal/BV/OBB.h
Date: 2025-04-01 09:23:31
Exec Total Coverage
Lines: 9 12 75.0%
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 COAL_OBB_H
39 #define COAL_OBB_H
40
41 #include "coal/data_types.h"
42
43 namespace coal {
44
45 struct CollisionRequest;
46
47 /// @addtogroup Bounding_Volume
48 /// @{
49
50 /// @brief Oriented bounding box class
51 struct COAL_DLLAPI OBB {
52 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
53
54 /// @brief Orientation of OBB. axis[i] is the ith column of the orientation
55 /// matrix for the box; it is also the i-th principle direction of the box. We
56 /// assume that axis[0] corresponds to the axis with the longest box edge,
57 /// axis[1] corresponds to the shorter one and axis[2] corresponds to the
58 /// shortest one.
59 Matrix3s axes;
60
61 /// @brief Center of OBB
62 Vec3s To;
63
64 /// @brief Half dimensions of OBB
65 Vec3s extent;
66
67
3/6
✓ Branch 2 taken 3289064 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 3289064 times.
✗ Branch 7 not taken.
✓ Branch 10 taken 3289064 times.
✗ Branch 11 not taken.
3289064 OBB() : axes(Matrix3s::Zero()), To(Vec3s::Zero()), extent(Vec3s::Zero()) {}
68
69 /// @brief Equality operator
70 812109 bool operator==(const OBB& other) const {
71
3/6
✓ Branch 1 taken 812109 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 812109 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 812109 times.
✗ Branch 8 not taken.
812109 return axes == other.axes && To == other.To && extent == other.extent;
72 }
73
74 /// @brief Difference operator
75 bool operator!=(const OBB& other) const { return !(*this == other); }
76
77 /// @brief Check whether the OBB contains a point.
78 bool contain(const Vec3s& p) const;
79
80 /// Check collision between two OBB
81 /// @return true if collision happens.
82 bool overlap(const OBB& other) const;
83
84 /// Check collision between two OBB
85 /// @return true if collision happens.
86 /// @retval sqrDistLowerBound squared lower bound on distance between boxes if
87 /// they do not overlap.
88 bool overlap(const OBB& other, const CollisionRequest& request,
89 Scalar& sqrDistLowerBound) const;
90
91 /// @brief Distance between two OBBs, not implemented.
92 Scalar distance(const OBB& other, Vec3s* P = NULL, Vec3s* Q = NULL) const;
93
94 /// @brief A simple way to merge the OBB and a point (the result is not
95 /// compact).
96 OBB& operator+=(const Vec3s& p);
97
98 /// @brief Merge the OBB and another OBB (the result is not compact).
99 OBB& operator+=(const OBB& other) {
100 *this = *this + other;
101 return *this;
102 }
103
104 /// @brief Return the merged OBB of current OBB and the other one (the result
105 /// is not compact).
106 OBB operator+(const OBB& other) const;
107
108 /// @brief Size of the OBB (used in BV_Splitter to order two OBBs)
109 1708258 inline Scalar size() const { return extent.squaredNorm(); }
110
111 /// @brief Center of the OBB
112 130672 inline const Vec3s& center() const { return To; }
113
114 /// @brief Width of the OBB.
115 7592 inline Scalar width() const { return 2 * extent[0]; }
116
117 /// @brief Height of the OBB.
118 7592 inline Scalar height() const { return 2 * extent[1]; }
119
120 /// @brief Depth of the OBB
121 7592 inline Scalar depth() const { return 2 * extent[2]; }
122
123 /// @brief Volume of the OBB
124 7592 inline Scalar volume() const { return width() * height() * depth(); }
125 };
126
127 /// @brief Translate the OBB bv
128 COAL_DLLAPI OBB translate(const OBB& bv, const Vec3s& t);
129
130 /// @brief Check collision between two obbs, b1 is in configuration (R0, T0) and
131 /// b2 is in identity.
132 COAL_DLLAPI bool overlap(const Matrix3s& R0, const Vec3s& T0, const OBB& b1,
133 const OBB& b2);
134
135 /// @brief Check collision between two obbs, b1 is in configuration (R0, T0) and
136 /// b2 is in identity.
137 COAL_DLLAPI bool overlap(const Matrix3s& R0, const Vec3s& T0, const OBB& b1,
138 const OBB& b2, const CollisionRequest& request,
139 Scalar& sqrDistLowerBound);
140
141 /// Check collision between two boxes
142 /// @param B, T orientation and position of first box,
143 /// @param a half dimensions of first box,
144 /// @param b half dimensions of second box.
145 /// The second box is in identity configuration.
146 COAL_DLLAPI bool obbDisjoint(const Matrix3s& B, const Vec3s& T, const Vec3s& a,
147 const Vec3s& b);
148 } // namespace coal
149
150 #endif
151