| 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_OBBRSS_H | ||
| 39 | #define COAL_OBBRSS_H | ||
| 40 | |||
| 41 | #include "coal/BV/OBB.h" | ||
| 42 | #include "coal/BV/RSS.h" | ||
| 43 | |||
| 44 | namespace coal { | ||
| 45 | |||
| 46 | struct CollisionRequest; | ||
| 47 | |||
| 48 | /// @addtogroup Bounding_Volume | ||
| 49 | /// @{ | ||
| 50 | |||
| 51 | /// @brief Class merging the OBB and RSS, can handle collision and distance | ||
| 52 | /// simultaneously | ||
| 53 | struct COAL_DLLAPI OBBRSS { | ||
| 54 | EIGEN_MAKE_ALIGNED_OPERATOR_NEW | ||
| 55 | |||
| 56 | /// @brief OBB member, for rotation | ||
| 57 | OBB obb; | ||
| 58 | |||
| 59 | /// @brief RSS member, for distance | ||
| 60 | RSS rss; | ||
| 61 | |||
| 62 | /// @brief Equality operator | ||
| 63 | 812109 | bool operator==(const OBBRSS& other) const { | |
| 64 |
2/4✓ Branch 1 taken 812109 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 812109 times.
✗ Branch 5 not taken.
|
812109 | return obb == other.obb && rss == other.rss; |
| 65 | } | ||
| 66 | |||
| 67 | /// @brief Difference operator | ||
| 68 | bool operator!=(const OBBRSS& other) const { return !(*this == other); } | ||
| 69 | |||
| 70 | /// @brief Check whether the OBBRSS contains a point | ||
| 71 | inline bool contain(const Vec3s& p) const { return obb.contain(p); } | ||
| 72 | |||
| 73 | /// @brief Check collision between two OBBRSS | ||
| 74 | bool overlap(const OBBRSS& other) const { return obb.overlap(other.obb); } | ||
| 75 | |||
| 76 | /// Check collision between two OBBRSS | ||
| 77 | /// @retval sqrDistLowerBound squared lower bound on distance between | ||
| 78 | /// objects if they do not overlap. | ||
| 79 | 1330 | bool overlap(const OBBRSS& other, const CollisionRequest& request, | |
| 80 | Scalar& sqrDistLowerBound) const { | ||
| 81 | 1330 | return obb.overlap(other.obb, request, sqrDistLowerBound); | |
| 82 | } | ||
| 83 | |||
| 84 | /// @brief Distance between two OBBRSS; P and Q , is not NULL, returns the | ||
| 85 | /// nearest points | ||
| 86 | 514 | Scalar distance(const OBBRSS& other, Vec3s* P = NULL, Vec3s* Q = NULL) const { | |
| 87 | 514 | return rss.distance(other.rss, P, Q); | |
| 88 | } | ||
| 89 | |||
| 90 | /// @brief Merge the OBBRSS and a point | ||
| 91 | OBBRSS& operator+=(const Vec3s& p) { | ||
| 92 | obb += p; | ||
| 93 | rss += p; | ||
| 94 | return *this; | ||
| 95 | } | ||
| 96 | |||
| 97 | /// @brief Merge two OBBRSS | ||
| 98 | OBBRSS& operator+=(const OBBRSS& other) { | ||
| 99 | *this = *this + other; | ||
| 100 | return *this; | ||
| 101 | } | ||
| 102 | |||
| 103 | /// @brief Merge two OBBRSS | ||
| 104 | 6537 | OBBRSS operator+(const OBBRSS& other) const { | |
| 105 | 6537 | OBBRSS result; | |
| 106 |
1/2✓ Branch 1 taken 6537 times.
✗ Branch 2 not taken.
|
6537 | result.obb = obb + other.obb; |
| 107 |
1/2✓ Branch 1 taken 6537 times.
✗ Branch 2 not taken.
|
6537 | result.rss = rss + other.rss; |
| 108 | 6537 | return result; | |
| 109 | } | ||
| 110 | |||
| 111 | /// @brief Size of the OBBRSS (used in BV_Splitter to order two OBBRSS) | ||
| 112 | 1645546 | inline Scalar size() const { return obb.size(); } | |
| 113 | |||
| 114 | /// @brief Center of the OBBRSS | ||
| 115 | 42248 | inline const Vec3s& center() const { return obb.center(); } | |
| 116 | |||
| 117 | /// @brief Width of the OBRSS | ||
| 118 | ✗ | inline Scalar width() const { return obb.width(); } | |
| 119 | |||
| 120 | /// @brief Height of the OBBRSS | ||
| 121 | ✗ | inline Scalar height() const { return obb.height(); } | |
| 122 | |||
| 123 | /// @brief Depth of the OBBRSS | ||
| 124 | ✗ | inline Scalar depth() const { return obb.depth(); } | |
| 125 | |||
| 126 | /// @brief Volume of the OBBRSS | ||
| 127 | inline Scalar volume() const { return obb.volume(); } | ||
| 128 | }; | ||
| 129 | |||
| 130 | /** @} */ // end of Bounding_Volume | ||
| 131 | |||
| 132 | /// @brief Check collision between two OBBRSS, b1 is in configuration (R0, T0) | ||
| 133 | /// and b2 is in indentity | ||
| 134 | inline bool overlap(const Matrix3s& R0, const Vec3s& T0, const OBBRSS& b1, | ||
| 135 | const OBBRSS& b2) { | ||
| 136 | return overlap(R0, T0, b1.obb, b2.obb); | ||
| 137 | } | ||
| 138 | |||
| 139 | /// Check collision between two OBBRSS | ||
| 140 | /// @param R0, T0 configuration of b1 | ||
| 141 | /// @param b1 first OBBRSS in configuration (R0, T0) | ||
| 142 | /// @param b2 second OBBRSS in identity position | ||
| 143 | /// @retval sqrDistLowerBound squared lower bound on the distance if OBBRSS do | ||
| 144 | /// not overlap. | ||
| 145 | 63209 | inline bool overlap(const Matrix3s& R0, const Vec3s& T0, const OBBRSS& b1, | |
| 146 | const OBBRSS& b2, const CollisionRequest& request, | ||
| 147 | Scalar& sqrDistLowerBound) { | ||
| 148 | 63209 | return overlap(R0, T0, b1.obb, b2.obb, request, sqrDistLowerBound); | |
| 149 | } | ||
| 150 | |||
| 151 | /// @brief Computate distance between two OBBRSS, b1 is in configuation (R0, T0) | ||
| 152 | /// and b2 is in indentity; P and Q, is not NULL, returns the nearest points | ||
| 153 | 1589368 | inline Scalar distance(const Matrix3s& R0, const Vec3s& T0, const OBBRSS& b1, | |
| 154 | const OBBRSS& b2, Vec3s* P = NULL, Vec3s* Q = NULL) { | ||
| 155 | 1589368 | return distance(R0, T0, b1.rss, b2.rss, P, Q); | |
| 156 | } | ||
| 157 | |||
| 158 | } // namespace coal | ||
| 159 | |||
| 160 | #endif | ||
| 161 |