$search
00001 /* 00002 * Software License Agreement (BSD License) 00003 * 00004 * Copyright (c) 2011, Willow Garage, Inc. 00005 * All rights reserved. 00006 * 00007 * Redistribution and use in source and binary forms, with or without 00008 * modification, are permitted provided that the following conditions 00009 * are met: 00010 * 00011 * * Redistributions of source code must retain the above copyright 00012 * notice, this list of conditions and the following disclaimer. 00013 * * Redistributions in binary form must reproduce the above 00014 * copyright notice, this list of conditions and the following 00015 * disclaimer in the documentation and/or other materials provided 00016 * with the distribution. 00017 * * Neither the name of Willow Garage, Inc. nor the names of its 00018 * contributors may be used to endorse or promote products derived 00019 * from this software without specific prior written permission. 00020 * 00021 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00022 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00023 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00024 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00025 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00026 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00027 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00028 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00029 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00030 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00031 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00032 * POSSIBILITY OF SUCH DAMAGE. 00033 */ 00034 00038 #ifndef COLLISION_CHECKING_SELF_COLLISION_H 00039 #define COLLISION_CHECKING_SELF_COLLISION_H 00040 00041 00042 #include "collision_checking/collision_primitive.h" 00043 #include <iostream> 00044 00046 namespace collision_checking 00047 { 00048 00050 template<typename BV> 00051 int continuousCollide(BVHModel<BV>& model1, BVHModel<BV>& model2, BVH_CollideResult* res, BVHFrontList* front_list = NULL) 00052 { 00053 // currently support continuous collision for mesh-mesh, mesh-point cloud. 00054 if(model1.getModelType() == BVH_MODEL_POINTCLOUD && model2.getModelType() == BVH_MODEL_POINTCLOUD) 00055 { 00056 std::cerr << "BVH Error: Continuous collision only supported between two triangle models or one triangle model and one point cloud." << std::endl; 00057 return BVH_ERR_UNSUPPORTED_FUNCTION; 00058 } 00059 00060 00061 if(model1.build_state == BVH_BUILD_STATE_PROCESSED && model2.build_state == BVH_BUILD_STATE_PROCESSED) 00062 { 00063 std::cerr << "BVH Error: Continuous collision must have at least one object moving!" << std::endl; 00064 return BVH_ERR_UNSUPPORTED_FUNCTION; 00065 } 00066 else if(model1.build_state == BVH_BUILD_STATE_UPDATED && model2.build_state == BVH_BUILD_STATE_UPDATED) 00067 { 00068 // handle directly 00069 } 00070 else if(model1.build_state == BVH_BUILD_STATE_PROCESSED && model2.build_state == BVH_BUILD_STATE_UPDATED) 00071 { 00072 // model 1 static, model 2 moving 00073 model1.prev_vertices = model1.vertices; 00074 } 00075 else if(model1.build_state == BVH_BUILD_STATE_UPDATED && model2.build_state == BVH_BUILD_STATE_PROCESSED) 00076 { 00077 model2.prev_vertices = model2.vertices; 00078 } 00079 else 00080 { 00081 std::cerr << "BVH Error: Must finish BVH model construction before call collide()!" << std::endl; 00082 return BVH_ERR_BUILD_OUT_OF_SEQUENCE; 00083 } 00084 00085 res->resetRecord(); 00086 00087 if(front_list && front_list->size() > 0) 00088 continuousPropagateBVHFrontList(model1.bvs, model2.bvs, model1.vertices, model2.vertices, model1.prev_vertices, model2.prev_vertices, model1.tri_indices, model2.tri_indices, res, front_list); 00089 else 00090 continuousCollideRecurse(model1.bvs, model2.bvs, 0, 0, model1.vertices, model2.vertices, model1.prev_vertices, model2.prev_vertices, model1.tri_indices, model2.tri_indices, res, front_list); 00091 00092 if(model1.build_state == BVH_BUILD_STATE_PROCESSED && model2.build_state == BVH_BUILD_STATE_UPDATED) 00093 { 00094 // model 1 static, model 2 moving 00095 model1.prev_vertices = NULL; 00096 } 00097 else if(model1.build_state == BVH_BUILD_STATE_UPDATED && model2.build_state == BVH_BUILD_STATE_PROCESSED) 00098 { 00099 model2.prev_vertices = NULL; 00100 } 00101 00102 return BVH_OK; 00103 } 00104 00106 template<typename BV> 00107 int continuousSelfCollide(BVHModel<BV>& model, BVH_CollideResult* res, BVHFrontList* front_list = NULL) 00108 { 00109 // currently support continuous self collision for mesh-mesh. 00110 if(model.getModelType() != BVH_MODEL_TRIANGLES) 00111 { 00112 std::cerr << "BVH Error: Continuous self collision only supported for a triangle model." << std::endl; 00113 return BVH_ERR_UNSUPPORTED_FUNCTION; 00114 } 00115 00116 if(model.build_state != BVH_BUILD_STATE_UPDATED) 00117 { 00118 if(model.build_state == BVH_BUILD_STATE_PROCESSED) 00119 { 00120 std::cerr << "BVH Error: Continuous self collision only handles moving object!" << std::endl; 00121 return BVH_ERR_UNSUPPORTED_FUNCTION; 00122 } 00123 else 00124 { 00125 std::cerr << "BVH Error: Must finish BVH model construction before call collide()!" << std::endl; 00126 return BVH_ERR_BUILD_OUT_OF_SEQUENCE; 00127 } 00128 } 00129 00130 res->resetRecord(); 00131 00132 if(front_list && front_list->size() > 0) 00133 continuousPropagateBVHFrontList(model.bvs, model.bvs, model.vertices, model.vertices, model.prev_vertices, model.prev_vertices, model.tri_indices, model.tri_indices, res, front_list); 00134 else 00135 continuousSelfCollideRecurse(model.bvs, 0, model.vertices, model.prev_vertices, model.tri_indices, res, front_list); 00136 00137 return BVH_OK; 00138 } 00139 00140 00141 00142 } 00143 00144 #endif