GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: include/hpp/fcl/internal/traversal_node_base.h Lines: 14 21 66.7 %
Date: 2024-02-09 12:57:42 Branches: 1 2 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_TRAVERSAL_NODE_BASE_H
39
#define HPP_FCL_TRAVERSAL_NODE_BASE_H
40
41
/// @cond INTERNAL
42
43
#include <hpp/fcl/data_types.h>
44
#include <hpp/fcl/math/transform.h>
45
#include <hpp/fcl/collision_data.h>
46
47
namespace hpp {
48
namespace fcl {
49
50
/// @brief Node structure encoding the information required for traversal.
51
52
class TraversalNodeBase {
53
 public:
54
733249
  TraversalNodeBase() : enable_statistics(false) {}
55
56
1466498
  virtual ~TraversalNodeBase() {}
57
58
716096
  virtual void preprocess() {}
59
60
716096
  virtual void postprocess() {}
61
62
  /// @brief Whether b is a leaf node in the first BVH tree
63
716196
  virtual bool isFirstNodeLeaf(unsigned int /*b*/) const { return true; }
64
65
  /// @brief Whether b is a leaf node in the second BVH tree
66
784717
  virtual bool isSecondNodeLeaf(unsigned int /*b*/) const { return true; }
67
68
  /// @brief Traverse the subtree of the node in the first tree first
69
36257
  virtual bool firstOverSecond(unsigned int /*b1*/, unsigned int /*b2*/) const {
70
36257
    return true;
71
  }
72
73
  /// @brief Get the left child of the node b in the first tree
74
  virtual int getFirstLeftChild(unsigned int b) const { return (int)b; }
75
76
  /// @brief Get the right child of the node b in the first tree
77
  virtual int getFirstRightChild(unsigned int b) const { return (int)b; }
78
79
  /// @brief Get the left child of the node b in the second tree
80
  virtual int getSecondLeftChild(unsigned int b) const { return (int)b; }
81
82
  /// @brief Get the right child of the node b in the second tree
83
  virtual int getSecondRightChild(unsigned int b) const { return (int)b; }
84
85
  /// @brief Whether store some statistics information during traversal
86
  void enableStatistics(bool enable) { enable_statistics = enable; }
87
88
  /// @brief configuation of first object
89
  Transform3f tf1;
90
91
  /// @brief configuration of second object
92
  Transform3f tf2;
93
94
  /// @brief Whether stores statistics
95
  bool enable_statistics;
96
};
97
98
/// @defgroup Traversal_For_Collision
99
/// regroup class about traversal for distance.
100
/// @{
101
102
/// @brief Node structure encoding the information required for collision
103
/// traversal.
104
class CollisionTraversalNodeBase : public TraversalNodeBase {
105
 public:
106
10580
  CollisionTraversalNodeBase(const CollisionRequest& request_)
107
10580
      : request(request_), result(NULL) {}
108
109
21160
  virtual ~CollisionTraversalNodeBase() {}
110
111
  /// BV test between b1 and b2
112
  /// @param b1, b2 Bounding volumes to test,
113
  /// @retval sqrDistLowerBound square of a lower bound of the minimal
114
  ///         distance between bounding volumes.
115
  virtual bool BVDisjoints(unsigned int b1, unsigned int b2,
116
                           FCL_REAL& sqrDistLowerBound) const = 0;
117
118
  /// @brief Leaf test between node b1 and b2, if they are both leafs
119
  virtual void leafCollides(unsigned int /*b1*/, unsigned int /*b2*/,
120
                            FCL_REAL& /*sqrDistLowerBound*/) const = 0;
121
122
  /// @brief Check whether the traversal can stop
123
20810241
  bool canStop() const { return this->request.isSatisfied(*(this->result)); }
124
125
  /// @brief request setting for collision
126
  const CollisionRequest& request;
127
128
  /// @brief collision result kept during the traversal iteration
129
  CollisionResult* result;
130
};
131
132
/// @}
133
134
/// @defgroup Traversal_For_Distance
135
/// regroup class about traversal for distance.
136
/// @{
137
138
/// @brief Node structure encoding the information required for distance
139
/// traversal.
140
class DistanceTraversalNodeBase : public TraversalNodeBase {
141
 public:
142
722669
  DistanceTraversalNodeBase() : result(NULL) {}
143
144
1445338
  virtual ~DistanceTraversalNodeBase() {}
145
146
  /// @brief BV test between b1 and b2
147
  /// @return a lower bound of the distance between the two BV.
148
  /// @note except for OBB, this method returns the distance.
149
  virtual FCL_REAL BVDistanceLowerBound(unsigned int /*b1*/,
150
                                        unsigned int /*b2*/) const {
151
    return (std::numeric_limits<FCL_REAL>::max)();
152
  }
153
154
  /// @brief Leaf test between node b1 and b2, if they are both leafs
155
  virtual void leafComputeDistance(unsigned int b1, unsigned int b2) const = 0;
156
157
  /// @brief Check whether the traversal can stop
158
  virtual bool canStop(FCL_REAL /*c*/) const { return false; }
159
160
  /// @brief request setting for distance
161
  DistanceRequest request;
162
163
  /// @brief distance result kept during the traversal iteration
164
  DistanceResult* result;
165
};
166
167
///@}
168
169
}  // namespace fcl
170
171
}  // namespace hpp
172
173
/// @endcond
174
175
#endif