|
BWAPI
|
00001 // Copyright (c) 2006 GeometryFactory (France). All rights reserved. 00002 // 00003 // This file is part of CGAL (www.cgal.org); you may redistribute it under 00004 // the terms of the Q Public License version 1.0. 00005 // See the file LICENSE.QPL distributed with CGAL. 00006 // 00007 // Licensees holding a valid commercial license may use this file in 00008 // accordance with the commercial license agreement provided with the software. 00009 // 00010 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 00011 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00012 // 00013 // $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/CGAL-3.5-branch/Surface_mesh_simplification/include/CGAL/Surface_mesh_simplification/halfedge_collapse_Polyhedron_3.h $ 00014 // $Id: halfedge_collapse_Polyhedron_3.h 50078 2009-06-25 15:12:52Z fcacciola $ 00015 // 00016 // Author(s) : Fernando Cacciola <fernando.cacciola@geometryfactory.com> 00017 // 00018 #ifndef CGAL_SURFACE_MESH_SIMPLIFICATION_COLLAPSE_TRIANGULATION_EDGE_POLYHEDRON_3_H 00019 #define CGAL_SURFACE_MESH_SIMPLIFICATION_COLLAPSE_TRIANGULATION_EDGE_POLYHEDRON_3_H 00020 00021 #include <CGAL/Surface_mesh_simplification/Detail/Common.h> 00022 #include <CGAL/Polyhedron_3.h> 00023 00024 #ifndef CGAL_CFG_NO_TMPL_IN_TMPL_PARAM 00025 # define CGAL_HDS_PARAM_ template < class Traits, class Items, class Alloc> class HDS 00026 #else 00027 # define CGAL_HDS_PARAM_ class HDS 00028 #endif 00029 00030 CGAL_BEGIN_NAMESPACE 00031 00032 namespace Surface_mesh_simplification 00033 { 00034 00035 template<class Gt, class I, CGAL_HDS_PARAM_, class A> 00036 typename boost::graph_traits< Polyhedron_3<Gt,I,HDS,A> >::vertex_descriptor 00037 halfedge_collapse( typename boost::graph_traits< Polyhedron_3<Gt,I,HDS,A> >::edge_descriptor const& pq 00038 , Polyhedron_3<Gt,I,HDS,A>& aSurface 00039 ) 00040 { 00041 typedef Polyhedron_3<Gt,I,HDS,A> Surface ; 00042 00043 typedef typename boost::graph_traits<Surface>::vertex_descriptor vertex_descriptor ; 00044 typedef typename boost::graph_traits<Surface>::edge_descriptor edge_descriptor ; 00045 00046 edge_descriptor qp = opposite_edge(pq,aSurface); 00047 edge_descriptor pt = opposite_edge(prev_edge(pq,aSurface),aSurface); 00048 edge_descriptor qb = opposite_edge(prev_edge(qp,aSurface),aSurface); 00049 00050 bool lTopFaceExists = !pq->is_border() ; 00051 bool lBottomFaceExists = !qp->is_border() ; 00052 bool lTopLeftFaceExists = lTopFaceExists && !pt->is_border() ; 00053 bool lBottomRightFaceExists = lBottomFaceExists && !qb->is_border() ; 00054 00055 CGAL_precondition( !lTopFaceExists || (lTopFaceExists && ( pt->vertex()->vertex_degree() > 2 ) ) ) ; 00056 CGAL_precondition( !lBottomFaceExists || (lBottomFaceExists && ( qb->vertex()->vertex_degree() > 2 ) ) ) ; 00057 00058 vertex_descriptor q = pq->vertex(); 00059 vertex_descriptor p = pq->opposite()->vertex(); 00060 00061 CGAL_ECMS_TRACE(3, "Collapsing p-q E" << pq->id() << " (V" << p->id() << "->V" << q->id() << ")" ) ; 00062 00063 bool lP_Erased = false, lQ_Erased = false ; 00064 00065 if ( lTopFaceExists ) 00066 { 00067 CGAL_precondition( !pt->opposite()->is_border() ) ; // p-q-t is a face of the mesh 00068 if ( lTopLeftFaceExists ) 00069 { 00070 CGAL_ECMS_TRACE(3, "Removing p-t E" << pt->id() << " (V" << p->id() << "->V" << pt->vertex()->id() << ") by joining top-left face" ) ; 00071 00072 aSurface.join_facet (pt); 00073 } 00074 else 00075 { 00076 CGAL_ECMS_TRACE(3, "Removing p-t E" << pt->id() << " (V" << p->id() << "->V" << pt->vertex()->id() << ") by erasing top face" ) ; 00077 00078 aSurface.erase_facet(pt->opposite()); 00079 00080 if ( !lBottomFaceExists ) 00081 { 00082 CGAL_ECMS_TRACE(3, "Bottom face doesn't exist so vertex P already removed" ) ; 00083 lP_Erased = true ; 00084 } 00085 } 00086 } 00087 00088 if ( lBottomFaceExists ) 00089 { 00090 CGAL_precondition( !qb->opposite()->is_border() ) ; // p-q-b is a face of the mesh 00091 if ( lBottomRightFaceExists ) 00092 { 00093 CGAL_ECMS_TRACE(3, "Removing q-b E" << qb->id() << " (V" << q->id() << "->V" << qb->vertex()->id() << ") by joining bottom-right face" ) ; 00094 aSurface.join_facet (qb); 00095 } 00096 else 00097 { 00098 CGAL_ECMS_TRACE(3, "Removing q-b E" << qb->id() << " (V" << q->id() << "->V" << qb->vertex()->id() << ") by erasing bottom face" ) ; 00099 00100 aSurface.erase_facet(qb->opposite()); 00101 00102 if ( !lTopFaceExists ) 00103 { 00104 CGAL_ECMS_TRACE(3, "Top face doesn't exist so vertex Q already removed" ) ; 00105 lQ_Erased = true ; 00106 } 00107 } 00108 } 00109 00110 CGAL_assertion( !lP_Erased || !lQ_Erased ) ; 00111 00112 if ( !lP_Erased && !lQ_Erased ) 00113 { 00114 CGAL_ECMS_TRACE(3, "Removing vertex P by joining pQ" ) ; 00115 aSurface.join_vertex(pq); 00116 lP_Erased = true ; 00117 } 00118 00119 return lP_Erased ? q : p ; 00120 } 00121 00122 } // namespace Surface_mesh_simplification 00123 00124 CGAL_END_NAMESPACE 00125 00126 #undef CGAL_HDS_ 00127 00128 #endif // CGAL_SURFACE_MESH_SIMPLIFICATION_COLLAPSE_TRIANGULATION_EDGE_POLYHEDRON_3_H 00129 // EOF // 00130
1.7.6.1