Blender  V2.59
LOD_EdgeCollapser.h
Go to the documentation of this file.
00001 /*
00002  * $Id: LOD_EdgeCollapser.h 35147 2011-02-25 10:47:28Z jesterking $
00003  * ***** BEGIN GPL LICENSE BLOCK *****
00004  *
00005  * This program is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License
00007  * as published by the Free Software Foundation; either version 2
00008  * of the License, or (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software Foundation,
00017  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00018  *
00019  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
00020  * All rights reserved.
00021  *
00022  * The Original Code is: all of this file.
00023  *
00024  * Contributor(s): none yet.
00025  *
00026  * ***** END GPL LICENSE BLOCK *****
00027  */
00028 
00034 #ifndef NAN_INCLDUED_EgdeCollapser_h
00035 #define NAN_INCLDUED_EgdeCollapser_h
00036 
00037 // This is a helper class that collapses edges of a 2 - manifold mesh.
00038 
00039 #include "LOD_MeshPrimitives.h"
00040 #include "MEM_NonCopyable.h"
00041 #include <vector>
00042 #include <functional>
00043 
00044 class LOD_ManMesh2;
00045 
00046 class LOD_EdgeCollapser 
00047 : public  MEM_NonCopyable
00048 {
00049 
00050 public :
00051                         
00052         static
00053                 LOD_EdgeCollapser * 
00054         New(
00055         );
00056 
00057         // returns via arguments the set of modified
00058         // verts,edges and faces.
00059 
00060                 bool
00061         CollapseEdge(
00062                 LOD_EdgeInd ei,
00063                 LOD_ManMesh2 &mesh,
00064                 std::vector<LOD_EdgeInd> &      degenerate_edges,
00065                 std::vector<LOD_FaceInd> &      degenerate_faces,
00066                 std::vector<LOD_VertexInd> & degenerate_vertices,
00067                 std::vector<LOD_EdgeInd> &      new_edges,
00068                 std::vector<LOD_FaceInd> &      update_faces,
00069                 std::vector<LOD_VertexInd> & update_vertices
00070         );
00071 
00072 private :
00073 
00074         LOD_EdgeCollapser(
00075         );
00076 
00077         // Test to see if the result of collapsing the
00078         // edge produces 2 junctions in the mesh i.e. where
00079         // an edge is shared by more than 2 polygons
00080 
00081         // We count the number of coincedent edge pairs that
00082         // result from the collapse of collapse_edge.
00083 
00084         // If collapse edge is a boundary edge then the number of
00085         // coincedent pairs should be 1
00086         // else it should be 2.
00087 
00088                 bool
00089         TJunctionTest(
00090                 LOD_ManMesh2 &mesh,
00091                 std::vector<LOD_EdgeInd> &e_v0v1,
00092                 LOD_EdgeInd collapse_edge
00093         );
00094 
00095         // here's the definition of the sort function
00096         // we use to determine coincedent edges
00097 
00098         // assumes the edges are normalized i.e. m_verts[0] <= m_verts[1]
00099 
00100         struct less : std::binary_function<LOD_Edge, LOD_Edge, bool> {
00101                         bool 
00102                 operator()(
00103                         const LOD_Edge& a,
00104                         const LOD_Edge& b
00105                 ) const {
00106                                 
00107                         if (int(a.m_verts[0]) == int(b.m_verts[0])) {
00108                                 return (int(a.m_verts[1]) < int(b.m_verts[1]));
00109                         } else {
00110                                 return (int(a.m_verts[0]) < int(b.m_verts[0]));
00111                         }
00112                 }
00113         };
00114 
00115 };
00116 
00117 #endif
00118