| 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_BV_NODE_H | ||
| 39 | #define COAL_BV_NODE_H | ||
| 40 | |||
| 41 | #include "coal/data_types.h" | ||
| 42 | #include "coal/BV/BV.h" | ||
| 43 | |||
| 44 | namespace coal { | ||
| 45 | |||
| 46 | /// @defgroup Construction_Of_BVH Construction of BVHModel | ||
| 47 | /// Classes which are used to build a BVHModel (Bounding Volume Hierarchy) | ||
| 48 | /// @{ | ||
| 49 | |||
| 50 | /// @brief BVNodeBase encodes the tree structure for BVH | ||
| 51 | struct COAL_DLLAPI BVNodeBase { | ||
| 52 | /// @brief An index for first child node or primitive | ||
| 53 | /// If the value is positive, it is the index of the first child bv node | ||
| 54 | /// If the value is negative, it is -(primitive index + 1) | ||
| 55 | /// Zero is not used. | ||
| 56 | int first_child; | ||
| 57 | |||
| 58 | /// @brief The start id the primitive belonging to the current node. The index | ||
| 59 | /// is referred to the primitive_indices in BVHModel and from that we can | ||
| 60 | /// obtain the primitive's index in original data indirectly. | ||
| 61 | unsigned int first_primitive; | ||
| 62 | |||
| 63 | /// @brief The number of primitives belonging to the current node | ||
| 64 | unsigned int num_primitives; | ||
| 65 | |||
| 66 | /// @brief Default constructor | ||
| 67 | 1968229 | BVNodeBase() | |
| 68 | 1968229 | : first_child(0), | |
| 69 | 1968229 | first_primitive( | |
| 70 | 1968229 | (std::numeric_limits<unsigned int>::max)()) // value we should help | |
| 71 | // to raise an issue | ||
| 72 | , | ||
| 73 | 1968229 | num_primitives(0) {} | |
| 74 | |||
| 75 | /// @brief Equality operator | ||
| 76 | 83252 | bool operator==(const BVNodeBase& other) const { | |
| 77 | 166504 | return first_child == other.first_child && | |
| 78 |
2/4✓ Branch 0 taken 83252 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 83252 times.
✗ Branch 3 not taken.
|
166504 | first_primitive == other.first_primitive && |
| 79 |
1/2✓ Branch 0 taken 83252 times.
✗ Branch 1 not taken.
|
166504 | num_primitives == other.num_primitives; |
| 80 | } | ||
| 81 | |||
| 82 | /// @brief Difference operator | ||
| 83 | bool operator!=(const BVNodeBase& other) const { return !(*this == other); } | ||
| 84 | |||
| 85 | /// @brief Whether current node is a leaf node (i.e. contains a primitive | ||
| 86 | /// index | ||
| 87 | 162559036 | inline bool isLeaf() const { return first_child < 0; } | |
| 88 | |||
| 89 | /// @brief Return the primitive index. The index is referred to the original | ||
| 90 | /// data (i.e. vertices or tri_indices) in BVHModel | ||
| 91 | 59025895 | inline int primitiveId() const { return -(first_child + 1); } | |
| 92 | |||
| 93 | /// @brief Return the index of the first child. The index is referred to the | ||
| 94 | /// bounding volume array (i.e. bvs) in BVHModel | ||
| 95 | 22821943 | inline int leftChild() const { return first_child; } | |
| 96 | |||
| 97 | /// @brief Return the index of the second child. The index is referred to the | ||
| 98 | /// bounding volume array (i.e. bvs) in BVHModel | ||
| 99 | 22821694 | inline int rightChild() const { return first_child + 1; } | |
| 100 | }; | ||
| 101 | |||
| 102 | /// @brief A class describing a bounding volume node. It includes the tree | ||
| 103 | /// structure providing in BVNodeBase and also the geometry data provided in BV | ||
| 104 | /// template parameter. | ||
| 105 | template <typename BV> | ||
| 106 | struct COAL_DLLAPI BVNode : public BVNodeBase { | ||
| 107 | typedef BVNodeBase Base; | ||
| 108 | |||
| 109 | /// @brief bounding volume storing the geometry | ||
| 110 | BV bv; | ||
| 111 | |||
| 112 | /// @brief Equality operator | ||
| 113 | 83252 | bool operator==(const BVNode& other) const { | |
| 114 |
2/4✓ Branch 1 taken 83252 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 83252 times.
✗ Branch 5 not taken.
|
83252 | return Base::operator==(other) && bv == other.bv; |
| 115 | } | ||
| 116 | |||
| 117 | /// @brief Difference operator | ||
| 118 | 83252 | bool operator!=(const BVNode& other) const { return !(*this == other); } | |
| 119 | |||
| 120 | /// @brief Check whether two BVNode collide | ||
| 121 | bool overlap(const BVNode& other) const { return bv.overlap(other.bv); } | ||
| 122 | /// @brief Check whether two BVNode collide | ||
| 123 | 37740092 | bool overlap(const BVNode& other, const CollisionRequest& request, | |
| 124 | Scalar& sqrDistLowerBound) const { | ||
| 125 | 37740092 | return bv.overlap(other.bv, request, sqrDistLowerBound); | |
| 126 | } | ||
| 127 | |||
| 128 | /// @brief Compute the distance between two BVNode. P1 and P2, if not NULL and | ||
| 129 | /// the underlying BV supports distance, return the nearest points. | ||
| 130 | 5556 | Scalar distance(const BVNode& other, Vec3s* P1 = NULL, | |
| 131 | Vec3s* P2 = NULL) const { | ||
| 132 | 5556 | return bv.distance(other.bv, P1, P2); | |
| 133 | } | ||
| 134 | |||
| 135 | /// @brief Access to the center of the BV | ||
| 136 | ✗ | Vec3s getCenter() const { return bv.center(); } | |
| 137 | |||
| 138 | /// @brief Access to the orientation of the BV | ||
| 139 | const Matrix3s& getOrientation() const { | ||
| 140 | static const Matrix3s id3 = Matrix3s::Identity(); | ||
| 141 | return id3; | ||
| 142 | } | ||
| 143 | |||
| 144 | /// \cond | ||
| 145 | EIGEN_MAKE_ALIGNED_OPERATOR_NEW | ||
| 146 | /// \endcond | ||
| 147 | }; | ||
| 148 | |||
| 149 | template <> | ||
| 150 | inline const Matrix3s& BVNode<OBB>::getOrientation() const { | ||
| 151 | return bv.axes; | ||
| 152 | } | ||
| 153 | |||
| 154 | template <> | ||
| 155 | inline const Matrix3s& BVNode<RSS>::getOrientation() const { | ||
| 156 | return bv.axes; | ||
| 157 | } | ||
| 158 | |||
| 159 | template <> | ||
| 160 | inline const Matrix3s& BVNode<OBBRSS>::getOrientation() const { | ||
| 161 | return bv.obb.axes; | ||
| 162 | } | ||
| 163 | |||
| 164 | } // namespace coal | ||
| 165 | |||
| 166 | #endif | ||
| 167 |