Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00037 #include "fcl/ccd/conservative_advancement.h"
00038 #include "fcl/ccd/motion.h"
00039 #include "fcl/collision_node.h"
00040 #include "fcl/traversal/traversal_node_bvhs.h"
00041 #include "fcl/traversal/traversal_node_setup.h"
00042 #include "fcl/traversal/traversal_recurse.h"
00043 #include "fcl/collision.h"
00044
00045
00046 namespace fcl
00047
00048 {
00049
00050 template<typename BV>
00051 int conservativeAdvancement(const CollisionGeometry* o1,
00052 MotionBase<BV>* motion1,
00053 const CollisionGeometry* o2,
00054 MotionBase<BV>* motion2,
00055 const CollisionRequest& request,
00056 CollisionResult& result,
00057 FCL_REAL& toc)
00058 {
00059 if(request.num_max_contacts == 0)
00060 {
00061 std::cerr << "Warning: should stop early as num_max_contact is " << request.num_max_contacts << " !" << std::endl;
00062 return 0;
00063 }
00064
00065 const OBJECT_TYPE object_type1 = o1->getObjectType();
00066 const NODE_TYPE node_type1 = o1->getNodeType();
00067
00068 const OBJECT_TYPE object_type2 = o2->getObjectType();
00069 const NODE_TYPE node_type2 = o2->getNodeType();
00070
00071 if(object_type1 != OT_BVH || object_type2 != OT_BVH)
00072 return 0;
00073
00074 if(node_type1 != BV_RSS || node_type2 != BV_RSS)
00075 return 0;
00076
00077
00078 const BVHModel<RSS>* model1 = (const BVHModel<RSS>*)o1;
00079 const BVHModel<RSS>* model2 = (const BVHModel<RSS>*)o2;
00080
00081 Transform3f tf1, tf2;
00082 motion1->getCurrentTransform(tf1);
00083 motion2->getCurrentTransform(tf2);
00084
00085
00086 MeshCollisionTraversalNodeRSS cnode;
00087 if(!initialize(cnode, *model1, tf1, *model2, tf2, request, result))
00088 std::cout << "initialize error" << std::endl;
00089
00090 relativeTransform(tf1.getRotation(), tf1.getTranslation(), tf2.getRotation(), tf2.getTranslation(), cnode.R, cnode.T);
00091
00092 cnode.enable_statistics = false;
00093 cnode.request = request;
00094
00095 collide(&cnode);
00096
00097 int b = result.numContacts();
00098
00099 if(b > 0)
00100 {
00101 toc = 0;
00102
00103 return b;
00104 }
00105
00106
00107 MeshConservativeAdvancementTraversalNodeRSS node;
00108
00109 initialize(node, *model1, *model2, tf1.getRotation(), tf1.getTranslation(), tf2.getRotation(), tf2.getTranslation());
00110
00111 node.motion1 = motion1;
00112 node.motion2 = motion2;
00113
00114
00115 do
00116 {
00117 Matrix3f R1_t, R2_t;
00118 Vec3f T1_t, T2_t;
00119
00120 node.motion1->getCurrentTransform(R1_t, T1_t);
00121 node.motion2->getCurrentTransform(R2_t, T2_t);
00122
00123
00124 relativeTransform(R1_t, T1_t, R2_t, T2_t, node.R, node.T);
00125
00126 node.delta_t = 1;
00127 node.min_distance = std::numeric_limits<FCL_REAL>::max();
00128
00129 distanceRecurse(&node, 0, 0, NULL);
00130
00131 if(node.delta_t <= node.t_err)
00132 {
00133
00134 break;
00135 }
00136
00137 node.toc += node.delta_t;
00138 if(node.toc > 1)
00139 {
00140 node.toc = 1;
00141 break;
00142 }
00143
00144 node.motion1->integrate(node.toc);
00145 node.motion2->integrate(node.toc);
00146 }
00147 while(1);
00148
00149 toc = node.toc;
00150
00151 if(node.toc < 1)
00152 return 1;
00153
00154 return 0;
00155 }
00156
00157
00158 template int conservativeAdvancement<RSS>(const CollisionGeometry* o1,
00159 MotionBase<RSS>* motion1,
00160 const CollisionGeometry* o2,
00161 MotionBase<RSS>* motion2,
00162 const CollisionRequest& request,
00163 CollisionResult& result,
00164 FCL_REAL& toc);
00165
00166
00167 }