diff --git a/Surface_mesh_simplification/demo/Surface_mesh_simplification/Surface_simplification.kdevelop b/Surface_mesh_simplification/demo/Surface_mesh_simplification/Surface_simplification.kdevelop index 6accb9e2138..b6b7eb8e99c 100644 --- a/Surface_mesh_simplification/demo/Surface_mesh_simplification/Surface_simplification.kdevelop +++ b/Surface_mesh_simplification/demo/Surface_mesh_simplification/Surface_simplification.kdevelop @@ -9,29 +9,29 @@ . false - + simplification_demo - executable + build / - + ./data/Sample0.off 1000 false true make - + false 1 0 false - - + + CGAL_MAKEFILE=/home/fcacciola/Programming/CGAL/make/makefile_i686_Linux-2.6_g++-4.0.2 DEBUGGING=yes default @@ -41,12 +41,12 @@ - - - - - - + + + + + + true false false @@ -126,7 +126,7 @@ 250 - + set m_,_ theValue @@ -152,8 +152,8 @@ VisualBoyAdvance - - + + false false -f0 diff --git a/Surface_mesh_simplification/demo/Surface_mesh_simplification/simplification_demo.C b/Surface_mesh_simplification/demo/Surface_mesh_simplification/simplification_demo.C index b920644423b..2eef16eb0aa 100644 --- a/Surface_mesh_simplification/demo/Surface_mesh_simplification/simplification_demo.C +++ b/Surface_mesh_simplification/demo/Surface_mesh_simplification/simplification_demo.C @@ -40,7 +40,7 @@ int main() { #include #include -//#define CGAL_SURFACE_SIMPLIFICATION_ENABLE_TRACE 1 +//#define CGAL_SURFACE_SIMPLIFICATION_ENABLE_TRACE 2 void Surface_simplification_external_trace( std::string s ) { @@ -52,7 +52,7 @@ void Surface_simplification_external_trace( std::string s ) #include #include #include -#include +#include #include #include @@ -200,7 +200,7 @@ void error_handler ( char const* what, char const* expr, char const* file, int l } -void Simplify ( Polyhedron& aP ) +void Simplify ( Polyhedron& aP, int aMax ) { std::cout << "Simplifying surface with " << (aP.size_of_halfedges()/2) << " edges..." << std::endl ; @@ -217,7 +217,7 @@ void Simplify ( Polyhedron& aP ) Lindstrom_Turk_selection selection_map ; Edge_length_cost_map cost_map ; Midpoint_vertex_placement vertex_placement ; - Count_ratio_stop_condition stop_condition(0.5); + Count_stop_condition stop_condition(aMax); std::cout << std::setprecision(19) ; @@ -234,8 +234,14 @@ void Simplify ( Polyhedron& aP ) fi->ID = lFacetID ++ ; int r = vertex_pair_collapse(aP,selection_map,cost_map,vertex_placement,stop_condition); - - std::cout << "Finished...\nEdges removed: " << r << std::endl ; + std::cout << "Finished...\n" + << r << " edges removed.\n" + << aP.size_of_vertices() << " vertices.\n" + << (aP.size_of_halfedges()/2) << " edges.\n" + << aP.size_of_facets() << " triangles.\n" + << ( aP.is_valid() ? " valid" : " INVALID!!" ) + << std::endl ; + ; #ifdef VISUALIZE gv << aP ; @@ -252,32 +258,35 @@ int main( int argc, char** argv ) Polyhedron lP; - char const* file = argc > 1 ? argv[1] : "./data/Eros_50000triangles_edited.off" ; - std::ifstream sample(file); - if ( sample ) + char const* infile = argc > 1 ? argv[1] : "./data/Sample0.off" ; + std::ifstream in(infile); + if ( in ) { - sample >> lP ; - Simplify(lP); + in >> lP ; + + int lMax = argc > 2 ? std::atoi(argv[2]) : 1000 ; //lP.size_of_halfedges() ; + + Simplify(lP,lMax); + + char const* of = argc > 3 ? argv[3] : 0 ; + std::string outfile = !of ? std::string(infile) + std::string(".out.off") : of ; + + std::ofstream out(outfile.c_str()); + if ( out ) + { + out << lP ; + } + else + { + std::cerr << "Unable to open out file: " << outfile << std::endl ; + } } else { - std::cerr << "Input file not found: " << file << std::endl ; + std::cerr << "Input file not found: " << infile << std::endl ; } - - /* - double lSize = 1e2 ; - - Point a(lSize,0,0) - , b(0,0,lSize) - , c(0,0,0) - , d(0,lSize,0) ; - - lP.make_tetrahedron(a,b,c,d) ; - - for ( int i = 0 ; i < 4 ; ++ i ) - subdiv(lP); - */ - + + return 0; } diff --git a/Surface_mesh_simplification/include/CGAL/Polyhedron_graph_traits_3.h b/Surface_mesh_simplification/include/CGAL/Polyhedron_graph_traits_3.h index 8d9a5692d8b..364e6cfb7f3 100644 --- a/Surface_mesh_simplification/include/CGAL/Polyhedron_graph_traits_3.h +++ b/Surface_mesh_simplification/include/CGAL/Polyhedron_graph_traits_3.h @@ -536,7 +536,7 @@ class T_HDS, class Alloc> typename graph_traits< CGAL::Polyhedron_3< PolyhedronTraits_3, PolyhedronItems_3, T_HDS, Alloc> >::edges_size_type num_edges(const CGAL::Polyhedron_3< PolyhedronTraits_3, PolyhedronItems_3, T_HDS, Alloc>& p) { - return p.size_of_halfedges(); + return p.size_of_halfedges() / 2 ; } template < class PolyhedronTraits_3, class PolyhedronItems_3, diff --git a/Surface_mesh_simplification/include/CGAL/Surface_mesh_simplification/Vertex_pair_collapse.C b/Surface_mesh_simplification/include/CGAL/Surface_mesh_simplification/Vertex_pair_collapse.C index b47654972ef..86eb6827202 100644 --- a/Surface_mesh_simplification/include/CGAL/Surface_mesh_simplification/Vertex_pair_collapse.C +++ b/Surface_mesh_simplification/include/CGAL/Surface_mesh_simplification/Vertex_pair_collapse.C @@ -115,7 +115,13 @@ void VertexPairCollapse::Loop() // Pairs in the queue might be "fixed", that is, marked as uncollapsable, or their cost might be undefined. if ( !lPair->is_fixed() && lPair->cost() != boost::none ) - { + { + if ( boost::num_vertices(mSurface) <= 4 ) + { + CGAL_TSMS_TRACE(0,"Thetrahedron reached."); + break ; + } + if ( stop_simplification(*lPair->cost(),lPair->p(),lPair->q(),lPair->is_edge(),mInitialPairCount,mCurrentPairCount,mSurface) ) { CGAL_TSMS_TRACE(0,"Stop condition reached with InitialCount=" << mInitialPairCount @@ -126,7 +132,7 @@ void VertexPairCollapse::Loop() } // Proceeds only if the pair is topolofically collapsable (collapsing it results in a non-degenerate triangulation) - if ( Is_collapsable(lPair) ) + if ( Is_collapsable(lPair) ) Collapse(lPair); } } @@ -145,17 +151,14 @@ bool VertexPairCollapse::Is_collapsable( vertex_pair_ptr const& edge_descriptor q_t = boost::next_edge_cw (q_p,mSurface); edge_descriptor q_b = boost::next_edge_ccw(q_p,mSurface); - // degree(p) and degree(q) > 3 + // degree(p) and degree(q) >= 3 if ( boost::target(p_t,mSurface) != aPair->q() && boost::target(p_b,mSurface) != aPair->q() && boost::target(q_t,mSurface) != aPair->p() && boost::target(q_b,mSurface) != aPair->p() - && boost::next_edge_ccw(p_t,mSurface) != p_b - && boost::next_edge_cw (q_t,mSurface) != q_b ) { // link('p') .intersection. link('q') == link('p_q') (that is, exactly {'t','b'}) - if ( boost::target(p_t,mSurface) == boost::target(q_t,mSurface) && boost::target(p_b,mSurface) == boost::target(q_b,mSurface) ) @@ -272,7 +275,7 @@ void VertexPairCollapse::Collapse( vertex_pair_ptr const& aPair // Updates the cost of all pairs in the PQ Update_neighbors(lQ); - -- mCurrentPairCount ; + mCurrentPairCount -= 3 ; } else { @@ -306,7 +309,7 @@ void VertexPairCollapse::Update_neighbors( vertex_descriptor co // This is required to satisfy the transitive link_condition. // That is, the edges around the replacement vertex 'v' cannot be collapsed again. - lPair1->is_fixed() = true ; + //lPair1->is_fixed() = true ; vertex_descriptor adj_v = boost::source(edge1,mSurface); @@ -338,7 +341,7 @@ void VertexPairCollapse::Update_neighbors( vertex_descriptor co for ( vertex_pair_vector_iterator it = lToUpdate.begin(), eit = lToUpdate.end() ; it != eit ; ++ it ) { vertex_pair_ptr lPair = *it ; - CGAL_TSMS_TRACE(2,"Updating cost of " << *lPair) ; + CGAL_TSMS_TRACE(3,"Updating cost of " << *lPair) ; // The cost of a pair can be recalculated by invalidating its cache and updating the PQ. // The PQ update will reposition the pair in the heap querying its cost(),