src/contact_patch.cpp
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2024, INRIA
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of INRIA nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  */
34 
37 #include "coal/contact_patch.h"
38 #include "coal/collision_utility.h"
39 
40 namespace coal {
41 
43  static ContactPatchFunctionMatrix table;
44  return table;
45 }
46 
48  const CollisionGeometry* o2, const Transform3s& tf2,
49  const CollisionResult& collision_result,
50  const ContactPatchRequest& request,
51  ContactPatchResult& result) {
52  if (!collision_result.isCollision() || request.max_num_patch == 0) {
53  // do nothing
54  return;
55  }
56 
57  // Before doing any computation, we initialize and clear the input result.
58  result.set(request);
59  ContactPatchSolver csolver(request);
60 
61  OBJECT_TYPE object_type1 = o1->getObjectType();
62  OBJECT_TYPE object_type2 = o2->getObjectType();
63  NODE_TYPE node_type1 = o1->getNodeType();
64  NODE_TYPE node_type2 = o2->getNodeType();
65 
66  const ContactPatchFunctionMatrix& looktable =
68 
69  if (object_type1 == OT_GEOM &&
70  (object_type2 == OT_BVH || object_type2 == OT_HFIELD)) {
71  if (!looktable.contact_patch_matrix[node_type2][node_type1]) {
72  COAL_THROW_PRETTY("Computing contact patches between node type "
73  << std::string(get_node_type_name(node_type1))
74  << " and node type "
75  << std::string(get_node_type_name(node_type2))
76  << " is not yet supported.",
77  std::invalid_argument);
78  }
79  looktable.contact_patch_matrix[node_type2][node_type1](
80  o2, tf2, o1, tf1, collision_result, &csolver, request, result);
81  result.swapObjects();
82  return;
83  }
84 
85  if (!looktable.contact_patch_matrix[node_type1][node_type2]) {
86  COAL_THROW_PRETTY("Contact patch computation between node type "
87  << std::string(get_node_type_name(node_type1))
88  << " and node type "
89  << std::string(get_node_type_name(node_type2))
90  << " is not yet supported.",
91  std::invalid_argument);
92  }
93 
94  return looktable.contact_patch_matrix[node_type1][node_type2](
95  o1, tf1, o2, tf2, collision_result, &csolver, request, result);
96 }
97 
99  const CollisionResult& collision_result,
100  const ContactPatchRequest& request,
101  ContactPatchResult& result) {
103  o2->collisionGeometryPtr(), o2->getTransform(),
104  collision_result, request, result);
105 }
106 
108  const CollisionGeometry* o2)
109  : o1(o1), o2(o2) {
110  const ContactPatchFunctionMatrix& looktable =
112 
113  OBJECT_TYPE object_type1 = this->o1->getObjectType();
114  NODE_TYPE node_type1 = this->o1->getNodeType();
115  OBJECT_TYPE object_type2 = this->o2->getObjectType();
116  NODE_TYPE node_type2 = this->o2->getNodeType();
117 
118  this->swap_geoms = object_type1 == OT_GEOM &&
119  (object_type2 == OT_BVH || object_type2 == OT_HFIELD);
120  if ((this->swap_geoms &&
121  !looktable.contact_patch_matrix[node_type2][node_type1]) ||
122  (!this->swap_geoms &&
123  !looktable.contact_patch_matrix[node_type1][node_type2])) {
124  COAL_THROW_PRETTY("Collision function between node type "
125  << std::string(get_node_type_name(node_type1))
126  << " and node type "
127  << std::string(get_node_type_name(node_type2))
128  << " is not yet supported.",
129  std::invalid_argument);
130  }
131 
132  if (this->swap_geoms) {
133  this->func = looktable.contact_patch_matrix[node_type2][node_type1];
134  } else {
135  this->func = looktable.contact_patch_matrix[node_type1][node_type2];
136  }
137 }
138 
140  const CollisionResult& collision_result,
141  const ContactPatchRequest& request,
142  ContactPatchResult& result) const {
143  if (!collision_result.isCollision() || request.max_num_patch == 0) {
144  // do nothing
145  return;
146  }
147 
148  // Before doing any computation, we initialize and clear the input result.
149  result.set(request);
150  if (this->swap_geoms) {
151  this->func(this->o2, tf2, this->o1, tf1, collision_result, &(this->csolver),
152  request, result);
153  result.swapObjects();
154  } else {
155  this->func(this->o1, tf1, this->o2, tf2, collision_result, &(this->csolver),
156  request, result);
157  }
158 }
159 
161  const Transform3s& tf2,
162  const CollisionResult& collision_result,
163  const ContactPatchRequest& request,
164  ContactPatchResult& result) const
165 
166 {
167  this->csolver.set(request);
168  this->run(tf1, tf2, collision_result, request, result);
169 }
170 
171 } // namespace coal
coal::CollisionGeometry::getNodeType
virtual NODE_TYPE getNodeType() const
get the node type
Definition: coal/collision_object.h:130
coal::CollisionResult::isCollision
bool isCollision() const
return binary collision result
Definition: coal/collision_data.h:443
coal::CollisionObject::collisionGeometryPtr
const CollisionGeometry * collisionGeometryPtr() const
get raw pointer to collision geometry of the object instance
Definition: coal/collision_object.h:319
coal::OT_BVH
@ OT_BVH
Definition: coal/collision_object.h:54
coal::CollisionObject::getTransform
const Transform3s & getTransform() const
get object's transform
Definition: coal/collision_object.h:290
gjk.tf1
tuple tf1
Definition: test/scripts/gjk.py:27
coal::NODE_TYPE
NODE_TYPE
traversal node type: bounding volume (AABB, OBB, RSS, kIOS, OBBRSS, KDOP16, KDOP18,...
Definition: coal/collision_object.h:64
coal::ContactPatchRequest::max_num_patch
size_t max_num_patch
Maximum number of contact patches that will be computed.
Definition: coal/collision_data.h:726
coal
Main namespace.
Definition: coal/broadphase/broadphase_bruteforce.h:44
coal::ContactPatchFunctionMatrix
The contact patch matrix stores the functions for contact patches computation between different types...
Definition: coal/contact_patch_func_matrix.h:49
coal::CollisionGeometry
The geometry for the object for collision or distance computation.
Definition: coal/collision_object.h:94
coal::CollisionGeometry::getObjectType
virtual OBJECT_TYPE getObjectType() const
get the type of the object
Definition: coal/collision_object.h:127
coal::Transform3s
Simple transform class used locally by InterpMotion.
Definition: coal/math/transform.h:55
coal::ComputeContactPatch::ComputeContactPatch
ComputeContactPatch(const CollisionGeometry *o1, const CollisionGeometry *o2)
Default constructor from two Collision Geometries.
Definition: src/contact_patch.cpp:107
contact_patch.h
coal::ContactPatchSolver::set
void set(const ContactPatchRequest &request)
Set up the solver using a ContactPatchRequest.
COAL_THROW_PRETTY
#define COAL_THROW_PRETTY(message, exception)
Definition: include/coal/fwd.hh:64
coal::CollisionResult
collision result
Definition: coal/collision_data.h:390
coal::ComputeContactPatch::o2
const CollisionGeometry * o2
Definition: coal/contact_patch.h:104
coal::ComputeContactPatch::func
ContactPatchFunctionMatrix::ContactPatchFunc func
Definition: coal/contact_patch.h:108
coal::computeContactPatch
COAL_DLLAPI void computeContactPatch(const CollisionGeometry *o1, const Transform3s &tf1, const CollisionGeometry *o2, const Transform3s &tf2, const CollisionResult &collision_result, const ContactPatchRequest &request, ContactPatchResult &result)
Main contact patch computation interface.
Definition: src/contact_patch.cpp:47
coal::getContactPatchFunctionLookTable
ContactPatchFunctionMatrix & getContactPatchFunctionLookTable()
Definition: src/contact_patch.cpp:42
coal::ComputeContactPatch::operator()
void operator()(const Transform3s &tf1, const Transform3s &tf2, const CollisionResult &collision_result, const ContactPatchRequest &request, ContactPatchResult &result) const
Definition: src/contact_patch.cpp:160
coal::ContactPatchFunctionMatrix::contact_patch_matrix
ContactPatchFunc contact_patch_matrix[NODE_COUNT][NODE_COUNT]
Each item in the contact patch matrix is a function to handle contact patch computation between objec...
Definition: coal/contact_patch_func_matrix.h:78
coal::CollisionObject
the object for collision or distance computation, contains the geometry and the transform information
Definition: coal/collision_object.h:214
gjk.tf2
tuple tf2
Definition: test/scripts/gjk.py:36
coal::ComputeContactPatch::swap_geoms
bool swap_geoms
Definition: coal/contact_patch.h:109
coal::ContactPatchResult
Result for a contact patch computation.
Definition: coal/collision_data.h:822
coal::ContactPatchRequest
Request for a contact patch computation.
Definition: coal/collision_data.h:724
coal::OBJECT_TYPE
OBJECT_TYPE
object type: BVH (mesh, points), basic geometry, octree
Definition: coal/collision_object.h:52
coal::OT_GEOM
@ OT_GEOM
Definition: coal/collision_object.h:55
coal::ContactPatchResult::set
void set(const ContactPatchRequest &request)
Set up a ContactPatchResult from a ContactPatchRequest
Definition: coal/collision_data.h:919
coal::get_node_type_name
const char * get_node_type_name(NODE_TYPE node_type)
Returns the name associated to a NODE_TYPE.
Definition: coal/collision_utility.h:32
coal::ComputeContactPatch::csolver
ContactPatchSolver csolver
Definition: coal/contact_patch.h:106
coal::ComputeContactPatch::o1
const CollisionGeometry * o1
Definition: coal/contact_patch.h:103
coal::ComputeContactPatch::run
virtual void run(const Transform3s &tf1, const Transform3s &tf2, const CollisionResult &collision_result, const ContactPatchRequest &request, ContactPatchResult &result) const
Definition: src/contact_patch.cpp:139
collision_utility.h
coal::ContactPatchSolver
Solver to compute contact patches, i.e. the intersection between two contact surfaces projected onto ...
Definition: coal/contact_patch/contact_patch_solver.h:59
coal::OT_HFIELD
@ OT_HFIELD
Definition: coal/collision_object.h:57
coal::ContactPatchResult::swapObjects
void swapObjects()
Repositions the ContactPatch when they get inverted during their construction.
Definition: coal/collision_data.h:966


hpp-fcl
Author(s):
autogenerated on Sat Nov 23 2024 03:44:57