Minor bugs fixed.

Link-condition fixed
This commit is contained in:
Fernando Cacciola 2006-04-28 17:32:39 +00:00
parent a6bbefaad3
commit 0427412ef6
4 changed files with 64 additions and 52 deletions

View File

@ -9,29 +9,29 @@
<ignoreparts/>
<projectdirectory>.</projectdirectory>
<absoluteprojectpath>false</absoluteprojectpath>
<description/>
<description></description>
</general>
<kdevcustomproject>
<run>
<mainprogram>simplification_demo</mainprogram>
<directoryradio>executable</directoryradio>
<directoryradio>build</directoryradio>
<customdirectory>/</customdirectory>
<programargs/>
<programargs>./data/Sample0.off 1000</programargs>
<terminal>false</terminal>
<autocompile>true</autocompile>
<envvars/>
</run>
<build>
<buildtool>make</buildtool>
<builddir/>
<builddir></builddir>
</build>
<make>
<abortonerror>false</abortonerror>
<numberofjobs>1</numberofjobs>
<prio>0</prio>
<dontact>false</dontact>
<makebin/>
<defaulttarget/>
<makebin></makebin>
<defaulttarget></defaulttarget>
<makeoptions>CGAL_MAKEFILE=/home/fcacciola/Programming/CGAL/make/makefile_i686_Linux-2.6_g++-4.0.2 DEBUGGING=yes</makeoptions>
<selectedenvironment>default</selectedenvironment>
<environments>
@ -41,12 +41,12 @@
</kdevcustomproject>
<kdevdebugger>
<general>
<dbgshell/>
<programargs/>
<gdbpath/>
<configGdbScript/>
<runShellScript/>
<runGdbScript/>
<dbgshell></dbgshell>
<programargs></programargs>
<gdbpath></gdbpath>
<configGdbScript></configGdbScript>
<runShellScript></runShellScript>
<runGdbScript></runGdbScript>
<breakonloadinglibs>true</breakonloadinglibs>
<separatetty>false</separatetty>
<floatingtoolbar>false</floatingtoolbar>
@ -126,7 +126,7 @@
<headerCompletionDelay>250</headerCompletionDelay>
</codecompletion>
<creategettersetter>
<prefixGet/>
<prefixGet></prefixGet>
<prefixSet>set</prefixSet>
<prefixVariable>m_,_</prefixVariable>
<parameterName>theValue</parameterName>
@ -152,8 +152,8 @@
</cppsupportpart>
<kdevvisualadvance>
<emulator>VisualBoyAdvance</emulator>
<binary/>
<addOptions/>
<binary></binary>
<addOptions></addOptions>
<terminal>false</terminal>
<fullscreen>false</fullscreen>
<graphicFilter>-f0</graphicFilter>

View File

@ -40,7 +40,7 @@ int main() {
#include <CGAL/IO/Polyhedron_geomview_ostream.h>
#include <CGAL/IO/Polyhedron_iostream.h>
//#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 <CGAL/Surface_mesh_simplification/Policies/LindstromTurk_selection_map.h>
#include <CGAL/Surface_mesh_simplification/Policies/Edge_length_cost_map.h>
#include <CGAL/Surface_mesh_simplification/Policies/Midpoint_vertex_placement.h>
#include <CGAL/Surface_mesh_simplification/Policies/Count_ratio_stop_pred.h>
#include <CGAL/Surface_mesh_simplification/Policies/Count_stop_pred.h>
#include <iostream>
#include <fstream>
@ -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<Polyhedron> selection_map ;
Edge_length_cost_map<Polyhedron> cost_map ;
Midpoint_vertex_placement<Polyhedron> vertex_placement ;
Count_ratio_stop_condition<Polyhedron> stop_condition(0.5);
Count_stop_condition<Polyhedron> 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;
}

View File

@ -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,

View File

@ -115,7 +115,13 @@ void VertexPairCollapse<TSM,SM,CM,VP,SP>::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<TSM,SM,CM,VP,SP>::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<TSM,SM,CM,VP,SP>::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<TSM,SM,CM,VP,SP>::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<TSM,SM,CM,VP,SP>::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<TSM,SM,CM,VP,SP>::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(),