Go to the documentation of this file.00001 #ifndef OPENTISSUE_CORE_GEOMETRY_GEOMETRY_HYBRID_H
00002 #define OPENTISSUE_CORE_GEOMETRY_GEOMETRY_HYBRID_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/core/geometry/geometry_volume_shape.h>
00013 #include <OpenTissue/utility/utility_class_id.h>
00014 #include <OpenTissue/core/geometry/geometry_aabb.h>
00015 #include <OpenTissue/core/geometry/geometry_obb.h>
00016 #include <OpenTissue/core/geometry/geometry_sphere.h>
00017 #include <OpenTissue/core/geometry/geometry_cylinder.h>
00018 #include <OpenTissue/core/geometry/geometry_prism.h>
00019
00020 namespace OpenTissue
00021 {
00022
00023 namespace geometry
00024 {
00025
00029 template< typename math_types_ >
00030 class HybridVolume
00031 : public VolumeShape< math_types_ >
00032 , public OpenTissue::utility::ClassID< HybridVolume<math_types_> >
00033 {
00034 public:
00035
00036 typedef math_types_ math_types;
00037 typedef typename math_types::value_traits value_traits;
00038 typedef typename math_types::real_type real_type;
00039 typedef typename math_types::vector3_type vector3_type;
00040 typedef typename math_types::matrix3x3_type matrix3x3_type;
00041 typedef typename math_types::quaternion_type quaternion_type;
00042 typedef VolumeShape< math_types_ > volume_type;
00043
00044 typedef AABB<math_types> aabb_type;
00045 typedef OBB<math_types> obb_type;
00046 typedef Cylinder<math_types> cylinder_type;
00047 typedef Sphere<math_types> sphere_type;
00048 typedef Prism<math_types> prism_type;
00049
00050 typedef enum{
00051 selection_undefined
00052 , selection_sphere
00053 , selection_aabb
00054 , selection_obb
00055 , selection_cylinder
00056 , selection_prism
00057 , selection_tetrahedron
00058 } selection_type;
00059
00060 public:
00061
00062 aabb_type m_aabb;
00063 obb_type m_obb;
00064 cylinder_type m_cylinder;
00065 sphere_type m_sphere;
00066 prism_type m_prism;
00067 selection_type m_picked;
00068
00069 public:
00070
00071 size_t const class_id() const { return OpenTissue::utility::ClassID<OpenTissue::geometry::HybridVolume<math_types_> >::class_id(); }
00072
00073 virtual ~HybridVolume() {}
00074
00075 HybridVolume()
00076 : m_picked(selection_undefined)
00077 {}
00078
00079 void set(aabb_type const & other_aabb)
00080 {
00081 m_aabb = other_aabb;
00082 m_picked = selection_aabb;
00083 }
00084
00085 void set(obb_type const & other_obb)
00086 {
00087 m_obb = other_obb;
00088 m_picked = selection_obb;
00089 }
00090
00091 void set(sphere_type const & other_sphere)
00092 {
00093 m_sphere = other_sphere;
00094 m_picked = selection_sphere;
00095 }
00096
00097 void set(cylinder_type const & other_cylinder)
00098 {
00099 m_cylinder = other_cylinder;
00100 m_picked = selection_cylinder;
00101 }
00102
00103 void set(prism_type const & other_prism)
00104 {
00105 m_prism = other_prism;
00106 m_picked = selection_prism;
00107 }
00108
00109 real_type volume() const
00110 {
00111 switch(m_picked)
00112 {
00113 case selection_aabb:
00114 return m_aabb.volume();
00115 break;
00116 case selection_obb:
00117 return m_obb.volume();
00118 break;
00119 case selection_sphere:
00120 return m_sphere.volume();
00121 break;
00122 case selection_cylinder:
00123 return m_cylinder.volume();
00124 break;
00125 case selection_prism:
00126 return m_prism.volume();
00127 break;
00128 case selection_tetrahedron:
00129 case selection_undefined:
00130 assert(!"Hybrid::volume(): case not handled");
00131 break;
00132 };
00133 return value_traits::zero();
00134 }
00135
00136 real_type area() const
00137 {
00138 switch(m_picked)
00139 {
00140 case selection_aabb:
00141 return m_aabb.area();
00142 break;
00143 case selection_obb:
00144 return m_obb.area();
00145 break;
00146 case selection_sphere:
00147 return m_sphere.area();
00148 break;
00149 case selection_cylinder:
00150 return m_cylinder.area();
00151 break;
00152 case selection_prism:
00153 return m_prism.area();
00154 break;
00155 case selection_tetrahedron:
00156 case selection_undefined:
00157 assert(!"Hybrid::area(): case not handled");
00158 break;
00159 };
00160 return value_traits::zero();
00161 }
00162
00163 real_type diameter() const
00164 {
00165 switch(m_picked)
00166 {
00167 case selection_aabb:
00168 return m_aabb.diameter();
00169 break;
00170 case selection_obb:
00171 return m_obb.diameter();
00172 break;
00173 case selection_sphere:
00174 return m_sphere.diameter();
00175 break;
00176 case selection_cylinder:
00177 return m_cylinder.diameter();
00178 break;
00179 case selection_prism:
00180 return m_prism.diameter();
00181 break;
00182 case selection_tetrahedron:
00183 case selection_undefined:
00184 assert(!"Hybrid::diameter(): case not handled");
00185 break;
00186 };
00187 return value_traits::zero();
00188 }
00189
00190 vector3_type center() const
00191 {
00192 switch(m_picked)
00193 {
00194 case selection_aabb:
00195 return m_aabb.center();
00196 break;
00197 case selection_obb:
00198 return m_obb.center();
00199 break;
00200 case selection_sphere:
00201 return m_sphere.center();
00202 break;
00203 case selection_cylinder:
00204 return m_cylinder.center();
00205 break;
00206 case selection_prism:
00207 return m_prism.center();
00208 break;
00209 case selection_tetrahedron:
00210 case selection_undefined:
00211 assert(!"Hybrid::center(): case not handled");
00212 break;
00213 };
00214 return vector3_type(value_traits::zero(),value_traits::zero(),value_traits::zero());
00215 }
00216
00217
00218 selection_type selected_type() const
00219 {
00220 return m_picked;
00221 }
00222
00223 void compute_surface_points(std::vector<vector3_type> & points) const
00224 {
00225 switch(m_picked)
00226 {
00227 case selection_aabb:
00228 return m_aabb.compute_surface_points(points);
00229 break;
00230 case selection_obb:
00231 return m_obb.compute_surface_points(points);
00232 break;
00233 case selection_sphere:
00234 return m_sphere.compute_surface_points(points);
00235 break;
00236 case selection_cylinder:
00237 return m_cylinder.compute_surface_points(points);
00238 break;
00239 case selection_prism:
00240 return m_prism.compute_surface_points(points);
00241 break;
00242 case selection_tetrahedron:
00243 case selection_undefined:
00244 assert(!"Hybrid::compute_surface_points(): case not handled");
00245 break;
00246 };
00247 }
00248
00249 public:
00250
00251 void translate(vector3_type const & T)
00252 {
00253 switch(m_picked)
00254 {
00255 case selection_aabb:
00256 return m_aabb.translate(T);
00257 break;
00258 case selection_obb:
00259 return m_obb.translate(T);
00260 break;
00261 case selection_sphere:
00262 return m_sphere.translate(T);
00263 break;
00264 case selection_cylinder:
00265 return m_cylinder.translate(T);
00266 break;
00267 case selection_prism:
00268 return m_prism.translate(T);
00269 break;
00270 case selection_tetrahedron:
00271 case selection_undefined:
00272 assert(!"Hybrid::translate(): case not handled");
00273 break;
00274 };
00275 }
00276
00277 void rotate(matrix3x3_type const & R)
00278 {
00279 switch(m_picked)
00280 {
00281 case selection_aabb:
00282 return m_aabb.rotate(R);
00283 break;
00284 case selection_obb:
00285 return m_obb.rotate(R);
00286 break;
00287 case selection_sphere:
00288 return m_sphere.rotate(R);
00289 break;
00290 case selection_cylinder:
00291 return m_cylinder.rotate(R);
00292 break;
00293 case selection_prism:
00294 return m_prism.rotate(R);
00295 break;
00296 case selection_tetrahedron:
00297 case selection_undefined:
00298 assert(!"Hybrid::rotate(): case not handled");
00299 break;
00300 };
00301 }
00302
00303 void scale(real_type const & s)
00304 {
00305 switch(m_picked)
00306 {
00307 case selection_aabb:
00308 return m_aabb.scale(s);
00309 break;
00310 case selection_obb:
00311 return m_obb.scale(s);
00312 break;
00313 case selection_sphere:
00314 return m_sphere.scale(s);
00315 break;
00316 case selection_cylinder:
00317 return m_cylinder.scale(s);
00318 break;
00319 case selection_prism:
00320 return m_prism.scale(s);
00321 break;
00322 case selection_tetrahedron:
00323 case selection_undefined:
00324 assert(!"Hybrid::scale(): case not handled");
00325 break;
00326 };
00327 }
00328
00329 vector3_type get_support_point(vector3_type const & v) const
00330 {
00331 switch(m_picked)
00332 {
00333 case selection_aabb:
00334 return m_aabb.get_support_point(v);
00335 break;
00336 case selection_obb:
00337 return m_obb.get_support_point(v);
00338 break;
00339 case selection_sphere:
00340 return m_sphere.get_support_point(v);
00341 break;
00342 case selection_cylinder:
00343 return m_cylinder.get_support_point(v);
00344 break;
00345 case selection_prism:
00346 return m_prism.get_support_point(v);
00347 break;
00348 case selection_tetrahedron:
00349 case selection_undefined:
00350 assert(!"Hybrid::get_support_point(): case not handled");
00351 break;
00352 };
00353 return vector3_type(value_traits::zero(),value_traits::zero(),value_traits::zero());
00354 }
00355
00367 void compute_collision_aabb(
00368 vector3_type const & r
00369 , matrix3x3_type const & R
00370 , vector3_type & min_coord
00371 , vector3_type & max_coord
00372 ) const
00373 {
00374 assert(false || !"Sorry not implemented yet!");
00375 switch(m_picked)
00376 {
00377 case selection_aabb:
00378 return m_aabb.compute_collision_aabb(r,R,min_coord,max_coord);
00379 break;
00380 case selection_obb:
00381 return m_obb.compute_collision_aabb(r,R,min_coord,max_coord);
00382 break;
00383 case selection_sphere:
00384 return m_sphere.compute_collision_aabb(r,R,min_coord,max_coord);
00385 break;
00386 case selection_cylinder:
00387 return m_cylinder.compute_collision_aabb(r,R,min_coord,max_coord);
00388 break;
00389 case selection_prism:
00390 return m_prism.compute_collision_aabb(r,R,min_coord,max_coord);
00391 break;
00392 case selection_tetrahedron:
00393 case selection_undefined:
00394 assert(!"Hybrid::compute_collision_aabb(): case not handled");
00395 break;
00396 };
00397 }
00398
00399 };
00400
00401 }
00402
00403 }
00404
00405
00406 #endif