Go to the documentation of this file.00001 #ifndef OPENTISSUE_COLLISION_OBB_TREE_OBB_TREE_COLLISION_POLICY_H
00002 #define OPENTISSUE_COLLISION_OBB_TREE_OBB_TREE_COLLISION_POLICY_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/collision/intersect/intersect_obb_obb_sat.h>
00013 #include <OpenTissue/collision/intersect/intersect_triangle_triangle_sat.h>
00014
00015 #include <cassert>
00016
00017 namespace OpenTissue
00018 {
00019
00020 namespace obb_tree
00021 {
00022
00023 template<
00024 typename bvh_type_
00025 , typename obb_tree_types_
00026 >
00027 class CollisionPolicy
00028 {
00029 public:
00030
00031 typedef obb_tree_types_ obb_tree_types;
00032 typedef typename obb_tree_types::coordsys_type coordsys_type;
00033 typedef typename obb_tree_types::vector3_type vector3_type;
00034 typedef typename obb_tree_types::time_stamp_type time_stamp_type;
00035
00036 typedef bvh_type_ bvh_type;
00037 typedef typename bvh_type::volume_type volume_type;
00038 typedef typename bvh_type::bv_ptr bv_ptr;
00039 typedef typename bvh_type::annotated_bv_ptr annotated_bv_ptr;
00040 typedef typename bvh_type::annotated_bv_type annotated_bv_type;
00041 typedef typename bvh_type::geometry_type face_ptr_type;
00042
00043 public:
00044
00045 time_stamp_type m_query;
00046
00047 public:
00048
00057 static time_stamp_type get_next_time_stamp()
00058 {
00059 static time_stamp_type next_stamp = 0;
00060 ++next_stamp;
00061 return next_stamp;
00062 }
00063
00064 public:
00065 CollisionPolicy()
00066 : m_query()
00067 {}
00068
00069 public:
00070
00071 template<typename result_container>
00072 void reset(result_container & results)
00073 {
00074 results.clear();
00075 }
00076
00077 bool overlap(coordsys_type const & A2B, bv_ptr bvA, bv_ptr bvB)
00078 {
00079 if(bvA->m_query!=m_query)
00080 {
00081 bvA->m_cached_volume = bvA->volume();
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105 bvA->m_cached_volume.xform(A2B);
00106 bvA->m_query = m_query;
00107 }
00108 bool collision = !OpenTissue::intersect::obb_obb_sat(bvB->volume(),bvA->m_cached_volume);
00109 return collision;
00110 }
00111
00112 template<typename result_container>
00113 bool report(coordsys_type const & A2B, bv_ptr bvA, bv_ptr bvB, result_container & results)
00114 {
00115 annotated_bv_ptr nodeA = boost::static_pointer_cast<annotated_bv_type>(bvA);
00116 annotated_bv_ptr nodeB = boost::static_pointer_cast<annotated_bv_type>(bvB);
00117
00118 face_ptr_type A = *(nodeA->geometry_begin());
00119 face_ptr_type B = *(nodeB->geometry_begin());
00120
00121 vector3_type a0 = *(A->m_v0);
00122 A2B.xform_point(a0);
00123 vector3_type a1 = *(A->m_v1);
00124 A2B.xform_point(a1);
00125 vector3_type a2 = *(A->m_v2);
00126 A2B.xform_point(a2);
00127
00128 bool collision = OpenTissue::intersect::triangle_triangle_sat( a0, a1 ,a2 , *(B->m_v0), *(B->m_v1), *(B->m_v2) );
00129
00130 if(!collision)
00131 return false;
00132
00133 results.push_back( std::make_pair(A,B) );
00134
00135 return true;
00136 }
00137 };
00138
00139 }
00140
00141 }
00142
00143
00144 #endif