Go to the documentation of this file.00001 #ifndef OPENTISSUE_CORE_CONTAINERS_MESH_POLYMESH_UTIL_POLYMESH_REFLEX_CONVEX_DECOMPOSITION_H
00002 #define OPENTISSUE_CORE_CONTAINERS_MESH_POLYMESH_UTIL_POLYMESH_REFLEX_CONVEX_DECOMPOSITION_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/core/containers/mesh/common/util/mesh_plane_clipper.h>
00013
00014 #include <OpenTissue/core/geometry/geometry_plane.h>
00015
00016 namespace OpenTissue
00017 {
00018 namespace polymesh
00019 {
00020
00021 template< typename mesh_type, typename mesh_container >
00022 bool reflex_convex_decomposition( mesh_type & mesh, mesh_container & pieces)
00023 {
00024 typedef typename mesh_type::halfedge_iterator halfedge_iterator;
00025 typedef typename mesh_type::halfedge_type halfedge_type;
00026 typedef typename mesh_type::vertex_iterator vertex_iterator;
00027 typedef typename mesh_type::vertex_handle vertex_handle;
00028 typedef typename mesh_type::face_iterator face_iterator;
00029 typedef typename mesh_type::index_type index_type;
00030
00031 typedef typename mesh_type::math_types math_types;
00032 typedef typename math_types::vector3_type vector3_type;
00033 typedef typename math_types::real_type real_type;
00034 typedef geometry::Plane<math_types> plane_type;
00035
00036 pieces.clear();
00037
00038 std::list<mesh_type *> processing;
00039 processing.push_back( &mesh );
00040
00041 while(!processing.empty())
00042 {
00043 mesh_type * piece = processing.back();processing.pop_back();
00044
00045 bool reflex_edge_found = false;
00046
00047 halfedge_iterator h = piece->halfedge_begin();
00048 halfedge_iterator hend = piece->halfedge_end();
00049 for(;h!=hend;++h)
00050 {
00051 if(is_boundary(*(h->get_edge_iterator())))
00052 continue;
00053
00054 if(is_concave(*h))
00055 {
00056 reflex_edge_found = true;
00057
00058 mesh_type * part1 = new mesh_type();
00059 mesh_type * part2 = new mesh_type();
00060
00061 plane_type Q;
00062
00063 face_iterator f0 = h->get_face_iterator();
00064 face_iterator f1 = h->get_twin_iterator()->get_face_iterator();
00065 vertex_iterator origin = h->get_origin_iterator();
00066 vertex_iterator destination = h->get_destination_iterator();
00067
00068 vector3_type n0,n1,u,n;
00069 compute_face_normal(*f0,n0);
00070 compute_face_normal(*f1,n1);
00071 u = destination->m_coord - origin->m_coord;
00072 n = (n0+n1) % u;
00073 Q.set(n,origin->m_coord);
00074
00075 mesh::plane_clipper(*piece,Q,*part1,*part2);
00076
00077 if(piece != &mesh)
00078 delete piece;
00079
00080 if(part1->size_faces()>0)
00081 {
00082
00083 processing.push_back(part1);
00084 }
00085 else
00086 {
00087 delete part1;
00088 }
00089 if(part2->size_faces()>0)
00090 {
00091
00092 processing.push_back(part2);
00093 }
00094 else
00095 {
00096 delete part2;
00097 }
00098 break;
00099 }
00100 }
00101
00102 if(!reflex_edge_found)
00103 {
00104 pieces.push_back( *piece);
00105 if(piece != &mesh)
00106 delete piece;
00107 }
00108 }
00109
00110 return true;
00111 }
00112
00113 }
00114 }
00115
00116
00117 #endif