Go to the documentation of this file.00001 #ifndef OPENTISSUE_DYNAMICS_PSYS_PSYS_GEOMETRY_HOLDER_H
00002 #define OPENTISSUE_DYNAMICS_PSYS_PSYS_GEOMETRY_HOLDER_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/dynamics/psys/collision/collision_psys_plane.h>
00013 #include <OpenTissue/dynamics/psys/collision/collision_psys_sphere.h>
00014 #include <OpenTissue/dynamics/psys/collision/collision_psys_sdf.h>
00015
00016
00017 #include <OpenTissue/collision/collision_points_aabb_tree.h>
00018 #include <OpenTissue/collision/collision_aabb_tree.h>
00019
00020
00021 #include <cassert>
00022
00023 namespace OpenTissue
00024 {
00025 namespace psys
00026 {
00027
00028
00048 template<typename types>
00049 class GeometryHolder
00050 : public types::connector_type
00051 {
00052 public:
00053
00054 typedef enum {UNDEFINED, SPHERE, PLANE, SDF, AABB_TREE} type_index;
00055
00056 typedef typename types::math_types math_types;
00057 typedef typename math_types::real_type real_type;
00058 typedef typename types::sphere_type sphere_type;
00059 typedef typename types::plane_type plane_type;
00060 typedef typename types::sdf_geometry_type sdf_geometry_type;
00061 typedef typename types::aabb_tree_type aabb_tree_type;
00062
00063 protected:
00064
00065 type_index m_type;
00066 void * m_geometry;
00067
00068 public:
00069
00070 void* geometry() { return m_geometry; }
00071 type_index const & type() { return m_type; }
00072
00073 public:
00074
00075 GeometryHolder()
00076 : m_type(UNDEFINED)
00077 , m_geometry(0)
00078 {}
00079
00080 public:
00081
00082 bool operator==(GeometryHolder const & geometry)
00083 {
00084 return (this->m_geometry == geometry.m_geometry);
00085 }
00086
00087 public:
00088
00089 void set(sphere_type * sphere)
00090 {
00091 m_type = SPHERE;
00092 m_geometry = static_cast<void*>(sphere);
00093 }
00094
00095 void set(plane_type * plane)
00096 {
00097 m_type = PLANE;
00098 m_geometry = static_cast<void*>(plane);
00099 }
00100
00101 void set(sdf_geometry_type * sdf)
00102 {
00103 m_type = SDF;
00104 m_geometry = static_cast<void*>(sdf);
00105 }
00106
00107
00108 void set(aabb_tree_type * aabb_tree)
00109 {
00110 m_type = AABB_TREE;
00111 m_geometry = static_cast<void*>(aabb_tree);
00112 }
00113
00114
00115 void clear()
00116 {
00117 m_type = UNDEFINED;
00118 m_geometry = 0;
00119 }
00120
00121 public:
00122
00123 template<typename particle_system, typename contact_point_container>
00124 void dispatch(particle_system & psys, contact_point_container & contacts)
00125 {
00126 if(m_type == SPHERE)
00127 {
00128 sphere_type * sphere = static_cast<sphere_type*>( m_geometry );
00129 collision_psys_sphere(psys,*sphere,contacts);
00130 }
00131 else if(m_type == PLANE)
00132 {
00133 plane_type * plane = static_cast<plane_type*>( m_geometry );
00134 collision_psys_plane(psys,*plane,contacts);
00135 }
00136 else if(m_type == SDF)
00137 {
00138 sdf_geometry_type * sdf = static_cast<sdf_geometry_type*>( m_geometry );
00139 collision_psys_sdf(psys,*sdf,contacts);
00140 }
00141
00142 else if(m_type == AABB_TREE)
00143 {
00144
00145
00146 aabb_tree_type * aabb_tree = static_cast<aabb_tree_type*>( m_geometry );
00147
00148
00149 OpenTissue::aabb_tree::refit(*aabb_tree);
00150
00151 if( this->owner() == (&psys) )
00152 OpenTissue::collision::aabb_tree_against_itself( *aabb_tree, contacts );
00153 else
00154 OpenTissue::collision::points_aabb_tree( psys.particle_begin(), psys.particle_end(), *aabb_tree, contacts );
00155 }
00156
00157 else
00158 {
00159 std::cerr << "GeometryHolder::dispatch(...): unrecognized geometry type?" << std::endl;
00160 }
00161 }
00162
00163 };
00164
00165
00166 }
00167
00168 }
00169
00170
00171 #endif