$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 00037 #ifndef COLLISION_CHECKING_RSS_H 00038 #define COLLISION_CHECKING_RSS_H 00039 00040 #include "collision_checking/BVH_defs.h" 00041 #include "collision_checking/vec_3f.h" 00042 00043 namespace collision_checking 00044 { 00045 00046 class RSS 00047 { 00048 public: 00050 Vec3f axis[3]; 00051 00053 Vec3f Tr; 00054 00056 BVH_REAL l[2]; 00057 00059 BVH_REAL r; 00060 00061 RSS() {} 00062 00064 bool overlap(const RSS& other) const; 00065 00069 bool overlap(const RSS& other, RSS& overlap_part) const 00070 { 00071 return overlap(other); 00072 } 00073 00075 inline bool contain(const Vec3f& p) const; 00076 00078 RSS& operator += (const Vec3f& p); 00079 00081 inline RSS& operator += (const RSS& other) 00082 { 00083 *this = *this + other; 00084 return *this; 00085 } 00086 00088 RSS operator + (const RSS& other) const; 00089 00091 inline BVH_REAL width() const 00092 { 00093 return l[0] + 2 * r; 00094 } 00095 00097 inline BVH_REAL height() const 00098 { 00099 return l[1] + 2 * r; 00100 } 00101 00103 inline BVH_REAL depth() const 00104 { 00105 return 2 * r; 00106 } 00107 00109 inline BVH_REAL volume() const 00110 { 00111 return (l[0] * l[1] * 2 * r + 4 * 3.1415926 * r * r * r); 00112 } 00113 00115 inline BVH_REAL size() const 00116 { 00117 return (sqrt(l[0] * l[0] + l[1] * l[1]) + 2 * r); 00118 } 00119 00121 inline Vec3f center() const 00122 { 00123 return Tr; 00124 } 00125 00127 BVH_REAL distance(const RSS& other) const; 00128 00129 protected: 00130 00132 static void clipToRange(BVH_REAL& val, BVH_REAL a, BVH_REAL b); 00133 00143 static void segCoords(BVH_REAL& t, BVH_REAL& u, BVH_REAL a, BVH_REAL b, BVH_REAL A_dot_B, BVH_REAL A_dot_T, BVH_REAL B_dot_T); 00144 00153 static bool inVoronoi(BVH_REAL a, BVH_REAL b, BVH_REAL Anorm_dot_B, BVH_REAL Anorm_dot_T, BVH_REAL A_dot_B, BVH_REAL A_dot_T, BVH_REAL B_dot_T); 00154 00155 public: 00156 00160 static BVH_REAL rectDistance(const Vec3f Rab[3], Vec3f const& Tab, const BVH_REAL a[2], const BVH_REAL b[2], Vec3f* P = NULL, Vec3f* Q = NULL); 00161 00162 }; 00163 00168 BVH_REAL distance(const Vec3f R0[3], const Vec3f& T0, const RSS& b1, const RSS& b2, Vec3f* P = NULL, Vec3f* Q = NULL); 00169 00170 bool overlap(const Vec3f R0[3], const Vec3f& T0, const RSS& b1, const RSS& b2); 00171 00172 00173 } 00174 00175 00176 #endif