hpp-fcl  1.4.4
HPP fork of FCL -- The Flexible Collision Library
traversal_node_base.h
Go to the documentation of this file.
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 
38 #ifndef HPP_FCL_TRAVERSAL_NODE_BASE_H
39 #define HPP_FCL_TRAVERSAL_NODE_BASE_H
40 
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 {
49 namespace fcl
50 {
51 
53 
54 class TraversalNodeBase
55 {
56 public:
57  TraversalNodeBase () : enable_statistics(false) {}
58 
59  virtual ~TraversalNodeBase() {}
60 
61  virtual void preprocess() {}
62 
63  virtual void postprocess() {}
64 
66  virtual bool isFirstNodeLeaf(int /*b*/) const { return true; }
67 
69  virtual bool isSecondNodeLeaf(int /*b*/) const { return true; }
70 
72  virtual bool firstOverSecond(int /*b1*/, int /*b2*/) const { return true; }
73 
75  virtual int getFirstLeftChild(int b) const { return b; }
76 
78  virtual int getFirstRightChild(int b) const { return b; }
79 
81  virtual int getSecondLeftChild(int b) const { return b; }
82 
84  virtual int getSecondRightChild(int b) const { return b; }
85 
87  void enableStatistics(bool enable) { enable_statistics = enable; }
88 
90  Transform3f tf1;
91 
93  Transform3f tf2;
94 
96  bool enable_statistics;
97 };
98 
102 
104 class CollisionTraversalNodeBase : public TraversalNodeBase
105 {
106 public:
107  CollisionTraversalNodeBase (const CollisionRequest& request_) :
108  request (request_), result(NULL) {}
109 
110  virtual ~CollisionTraversalNodeBase() {}
111 
113  virtual bool BVDisjoints(int b1, int b2) const = 0;
114 
119  virtual bool BVDisjoints(int b1, int b2, FCL_REAL& sqrDistLowerBound) const = 0;
120 
122  virtual void leafCollides(int /*b1*/, int /*b2*/, FCL_REAL& /*sqrDistLowerBound*/) const
123  {
124  throw std::runtime_error ("Not implemented");
125  }
126 
128  bool canStop() const { return this->request.isSatisfied(*(this->result)); }
129 
131  const CollisionRequest& request;
132 
134  CollisionResult* result;
135 
137  bool enable_statistics;
138 };
139 
141 
145 
147 class DistanceTraversalNodeBase : public TraversalNodeBase
148 {
149 public:
150  DistanceTraversalNodeBase() : result(NULL) {}
151 
152  virtual ~DistanceTraversalNodeBase() {}
153 
157  virtual FCL_REAL BVDistanceLowerBound(int /*b1*/, int /*b2*/) const
158  {
159  return std::numeric_limits<FCL_REAL>::max();
160  }
161 
163  virtual void leafComputeDistance(int b1, int b2) const = 0;
164 
166  virtual bool canStop(FCL_REAL /*c*/) const
167  { return false; }
168 
170  DistanceRequest request;
171 
173  DistanceResult* result;
174 };
175 
177 
178 }
179 
180 } // namespace hpp
181 
183 
184 #endif
185 
Main namespace.
Definition: AABB.h:43
double FCL_REAL
Definition: data_types.h:68