Examples added

This commit is contained in:
Fernando Cacciola 2006-08-31 17:49:03 +00:00
parent cb02182245
commit d2db851646
22 changed files with 876 additions and 147 deletions

6
.gitattributes vendored
View File

@ -1906,6 +1906,12 @@ Surface_mesh_parameterization/test/Surface_mesh_parameterization/data/cube.off -
Surface_mesh_parameterization/test/Surface_mesh_parameterization/data/high_genus.off -text svneol=unset#application/octet-stream
Surface_mesh_parameterization/test/Surface_mesh_parameterization/data/knot2.off -text svneol=unset#application/octet-stream
Surface_mesh_parameterization/test/Surface_mesh_parameterization/data/oni.off -text svneol=unset#application/octet-stream
Surface_mesh_simplification/examples/Surface_mesh_simplification/Edge_collapse_fully_cached_polyhedron_example.cpp -text
Surface_mesh_simplification/examples/Surface_mesh_simplification/LT_edge_collapse_enriched_polyhedron_example.cpp -text
Surface_mesh_simplification/examples/Surface_mesh_simplification/LT_edge_collapse_polyhedron_example.cpp -text
Surface_mesh_simplification/examples/Surface_mesh_simplification/LT_edge_collapse_visited_fully_enriched_polyhedron_example.cpp -text
Surface_mesh_simplification/examples/Surface_mesh_simplification/MP_edge_collapse_polyhedron_example.cpp -text
Surface_mesh_simplification/examples/Surface_mesh_simplification/makefile -text
Surface_mesh_simplification/include/CGAL/Surface_mesh_simplification/Edge_extra_pointer_map_stored.h -text
Surface_mesh_simplification/include/CGAL/Surface_mesh_simplification/Policies/Edge_collapse/Cached_cost.h -text
Surface_mesh_simplification/include/CGAL/Surface_mesh_simplification/Policies/Edge_collapse/Cached_placement.h -text

View File

@ -0,0 +1,106 @@
#include <iostream>
#include <iomanip>
#include <fstream>
#include <CGAL/Simple_cartesian.h>
// Target surface type. (this include Polyhedron_3.h itself)
#include <CGAL/Surface_mesh_simplification/Polyhedron.h>
// Policies
#include <CGAL/Surface_mesh_simplification/Policies/Edge_collapse/LindstromTurk.h>
#include <CGAL/Surface_mesh_simplification/Policies/Edge_collapse/Midpoint_and_length.h>
#include <CGAL/Surface_mesh_simplification/Policies/Edge_collapse/Count_stop_pred.h>
// Simplification method
#include <CGAL/Surface_mesh_simplification/Edge_collapse.h>
#include <CGAL/IO/Polyhedron_iostream.h>
#include <CGAL/Unique_hash_map.h>
using namespace std ;
using namespace boost ;
using namespace CGAL ;
typedef Simple_cartesian<double> Kernel;
typedef Kernel::Vector_3 Vector;
typedef Kernel::Point_3 Point;
typedef Polyhedron_3<Kernel> Surface;
typedef Surface::Halfedge_handle Halfedge_handle ;
using namespace CGAL::Triangulated_surface_mesh::Simplification::Edge_collapse ;
enum { LT, MP } ;
int main( int argc, char** argv )
{
Surface surface;
int strategy = atoi(argv[1]);
ifstream is(argv[2]) ;
is >> surface ;
//
// The simplification algorithm needs to associate some data to each edge.
// In this example we use an external map to do that, properly initialized with null pointers
// and passed to the edge_collapse function as a boost associative property map
//
Unique_hash_map<Halfedge_handle,void*> edge2ptr ;
for ( Surface::Halfedge_iterator hi = surface.halfedges_begin(); hi != surface.halfedges_end() ; ++ hi )
edge2ptr[hi] = 0 ;
//
// Simplify surface
// Down to 1000 edges
// Uing an external hasmap to store the per-edge extra pointer
// No fixed vertices
// Caching cost AND placement (full collapse data)
// Using LindstromTurk or Midpoint/Edge-length strategy from the cached collapse data.
//
// Implicit policies:
// Deffault parameters to the cost and placement functors
// No visitor.
if ( strategy == LT )
{
edge_collapse(surface
,Count_stop_condition<Surface>(1000)
,boost::make_assoc_property_map(edge2ptr)
,Vertex_is_fixed_map_always_false<Surface>()
,Set_full_collapse_data_LindstromTurk<Surface>()
,Cached_cost<Surface>()
,Cached_placement<Surface>()
);
}
else
{
typedef Edge_length_cost <Surface> Compute_cost ;
typedef Midpoint_placement<Surface> Compute_placement ;
typedef Set_full_collapse_data<Surface,Compute_cost,Compute_placement> Set_full_collapse_data ;
Compute_cost compute_cost ;
Compute_placement compute_placement ;
Set_full_collapse_data set_collapse_data(compute_cost,compute_placement);
edge_collapse(surface
,Count_stop_condition<Surface>(1000)
,boost::make_assoc_property_map(edge2ptr)
,Vertex_is_fixed_map_always_false<Surface>()
,set_collapse_data
,Cached_cost<Surface>()
,Cached_placement<Surface>()
);
}
cout << "\nFinished: " << (surface.size_of_halfedges()/2) << " final edges.\n" ;
ofstream os( argc > 3 ? argv[3] : "out.off" ) ;
os << surface ;
return 0 ;
}
// EOF //

View File

@ -0,0 +1,87 @@
#include <iostream>
#include <iomanip>
#include <fstream>
#include <CGAL/Simple_cartesian.h>
// Target surface type. (this include Polyhedron_3.h itself)
#include <CGAL/Surface_mesh_simplification/Polyhedron.h>
// Policies
#include <CGAL/Surface_mesh_simplification/Policies/Edge_collapse/Count_ratio_stop_pred.h>
// Simplification method
#include <CGAL/Surface_mesh_simplification/Edge_collapse.h>
#include <CGAL/IO/Polyhedron_iostream.h>
using namespace std ;
using namespace boost ;
using namespace CGAL ;
typedef Simple_cartesian<double> Kernel;
typedef Kernel::Vector_3 Vector;
typedef Kernel::Point_3 Point;
//
// Setup an enriched polyhedron type which stores in a halfedge each extra pointer needed by the algorithm
//
template <class Refs, class Traits>
struct My_halfedge : public HalfedgeDS_halfedge_base<Refs>
{
My_halfedge() : extra_ptr_(0) {}
void*& extra_pointer() { return extra_ptr_ ; }
void* extra_ptr_ ;
};
struct My_items : public Polyhedron_items_3
{
template < class Refs, class Traits>
struct Vertex_wrapper {
typedef CGAL::HalfedgeDS_vertex_base<Refs,Tag_true,Point> Vertex ;
};
template < class Refs, class Traits>
struct Halfedge_wrapper {
typedef My_halfedge<Refs,Traits> Halfedge;
};
template < class Refs, class Traits>
struct Face_wrapper {
typedef CGAL::HalfedgeDS_face_base<Refs,CGAL::Tag_true> Face;
};
};
typedef Polyhedron_3<Kernel,My_items> Surface;
using namespace CGAL::Triangulated_surface_mesh::Simplification::Edge_collapse ;
int main( int argc, char** argv )
{
Surface surface;
ifstream is(argv[1]) ;
is >> surface ;
//
// Simplify surface down to a 10% of the number of edges.
//
// Implicit policies:
// Per-edge extra pointer embeeded in each halfedge.
// No fixed vertices.
// LindstromTurk strategy, with default parameters.
// No visitor.
//
int r = edge_collapse(surface, Count_ratio_stop_condition<Surface>(0.10) );
cout << "\nFinished...\n" << r << " edges removed.\n" << (surface.size_of_halfedges()/2) << " final edges.\n" ;
ofstream os( argc > 2 ? argv[2] : "out.off" ) ;
os << surface ;
return 0 ;
}
// EOF //

View File

@ -0,0 +1,67 @@
#include <iostream>
#include <iomanip>
#include <fstream>
#include <CGAL/Simple_cartesian.h>
// Target surface type. (this include Polyhedron_3.h itself)
#include <CGAL/Surface_mesh_simplification/Polyhedron.h>
// Policies
#include <CGAL/Surface_mesh_simplification/Policies/Edge_collapse/Count_stop_pred.h>
// Simplification method
#include <CGAL/Surface_mesh_simplification/Edge_collapse.h>
#include <CGAL/IO/Polyhedron_iostream.h>
#include <CGAL/Unique_hash_map.h>
using namespace std ;
using namespace boost ;
using namespace CGAL ;
typedef Simple_cartesian<double> Kernel;
typedef Kernel::Vector_3 Vector;
typedef Kernel::Point_3 Point;
typedef Polyhedron_3<Kernel> Surface;
typedef Surface::Halfedge_handle Halfedge_handle ;
using namespace CGAL::Triangulated_surface_mesh::Simplification::Edge_collapse ;
int main( int argc, char** argv )
{
Surface surface;
ifstream is(argv[1]) ;
is >> surface ;
//
// The simplification algorithm needs to associate some data to each edge.
// In this example we use an external map to do that, properly initialized with null pointers
// and passed to the edge_collapse function as a boost associative property map
//
Unique_hash_map<Halfedge_handle,void*> edge2ptr ;
for ( Surface::Halfedge_iterator hi = surface.halfedges_begin(); hi != surface.halfedges_end() ; ++ hi )
edge2ptr[hi] = 0 ;
//
// Simplify surface down to 1000 edges using an external hasmap to store the per-edge extra pointer
//
// Implicit policies:
// No fixed vertices.
// LindstromTurk strategy, with default parameters.
// No visitor.
//
int r = edge_collapse(surface, Count_stop_condition<Surface>(1000), boost::make_assoc_property_map(edge2ptr) );
cout << "\nFinished...\n" << r << " edges removed.\n" << (surface.size_of_halfedges()/2) << " final edges.\n" ;
ofstream os( argc > 2 ? argv[2] : "out.off" ) ;
os << surface ;
return 0 ;
}
// EOF //

View File

@ -0,0 +1,178 @@
#include <iostream>
#include <iomanip>
#include <fstream>
#include <CGAL/Simple_cartesian.h>
// Target surface type. (this include Polyhedron_3.h itself)
#include <CGAL/Surface_mesh_simplification/Polyhedron.h>
// Policies
#include <CGAL/Surface_mesh_simplification/Vertex_is_fixed_map_stored.h>
#include <CGAL/Surface_mesh_simplification/Policies/Edge_collapse/Count_ratio_stop_pred.h>
// Simplification method
#include <CGAL/Surface_mesh_simplification/Edge_collapse.h>
#include <CGAL/IO/Polyhedron_iostream.h>
using namespace std ;
using namespace boost ;
using namespace CGAL ;
typedef Simple_cartesian<double> Kernel;
typedef Kernel::Vector_3 Vector;
typedef Kernel::Point_3 Point;
//
// Setup an enriched polyhedron type which stores in a halfedge each extra pointer needed by the algorithm
// and in each vertex whether it is fixed or not.
//
template <class Refs, class Traits>
struct My_vertex : public HalfedgeDS_vertex_base<Refs,Tag_true,Point>
{
typedef HalfedgeDS_vertex_base<Refs,Tag_true,Point> Base ;
My_vertex() : is_fixed_(false) {}
My_vertex( Point const& p ) : Base(p), is_fixed_(false) {}
bool is_fixed() const { return is_fixed_ ; }
bool is_fixed_ ;
};
template <class Refs, class Traits>
struct My_halfedge : public HalfedgeDS_halfedge_base<Refs>
{
My_halfedge() : extra_ptr_(0) {}
void*& extra_pointer() { return extra_ptr_ ; }
void* extra_ptr_ ;
};
struct My_items : public Polyhedron_items_3
{
template < class Refs, class Traits>
struct Vertex_wrapper {
typedef My_vertex<Refs,Traits> Vertex;
};
template < class Refs, class Traits>
struct Halfedge_wrapper {
typedef My_halfedge<Refs,Traits> Halfedge;
};
template < class Refs, class Traits>
struct Face_wrapper {
typedef CGAL::HalfedgeDS_face_base<Refs,CGAL::Tag_true> Face;
};
};
typedef Polyhedron_3<Kernel,My_items> Surface;
typedef Surface::Halfedge_handle Halfedge_handle ;
typedef Surface::Vertex_handle Vertex_handle ;
using namespace CGAL::Triangulated_surface_mesh::Simplification::Edge_collapse ;
struct Visitor
{
Visitor() : collected(0), processed(0), collapsed(0), non_collapsable(0), cost_uncomputable(0) {}
void OnStarted( Surface& aSurface ) {}
void OnFinished ( Surface& aSurface ) { cerr << "\n" << flush ; }
void OnStopConditionReached( Surface& aSurface ) {}
void OnCollected( Halfedge_handle const& aEdge
, bool aIsFixed
, Surface& aSurface
)
{
++ collected ;
cerr << "\rEdges collected: " << collected << flush ;
}
void OnProcessed(Halfedge_handle const& aEdge
,Surface& aSurface
,optional<double> aCost
,Vertex_handle const& aVertex
)
{
++ processed ;
if ( aVertex == Vertex_handle() )
{
if ( !aCost )
++ cost_uncomputable ;
else ++ non_collapsable ;
}
else
{
++ collapsed;
}
}
void OnStep(Halfedge_handle const& aEdge, Surface& aSurface, size_t aInitial, size_t aCurrent)
{
if ( aCurrent == aInitial )
cerr << "\n" << flush ;
cerr << "\r" << aCurrent << flush ;
}
size_t collected, processed, collapsed, non_collapsable, cost_uncomputable ;
} ;
int main( int argc, char** argv )
{
Surface surface;
ifstream is(argv[1]) ;
is >> surface ;
//
// Simplify surface
// Down to a 10% of the number of edges.
// Per-edge extra pointer embeeded in each halfedge.
// "is-fixed" flag embeeded in each vertex.
// Caching cost with not placement (partial collapse data)
// Using LindstromTurk cost strategy from the cached collapse data.
// Using LindstromTurk placement strategy computed on demand.
// Using default LindstromTurk params
// Using a visitor to track progress and collect stats.
//
Visitor visitor ;
LindstromTurk_params params ;
int r = edge_collapse(surface
,Count_ratio_stop_condition<Surface>(0.10)
,Edge_extra_pointer_map_stored<Surface>()
,Vertex_is_fixed_map_stored<Surface>()
,Set_partial_collapse_data_LindstromTurk<Surface>()
,Cached_cost<Surface>()
,LindstromTurk_placement<Surface>()
,&params
,&params
,&visitor
);
cout << "\nFinished...\n" << r << " edges removed.\n" << (surface.size_of_halfedges()/2) << " final edges." ;
cout << "\nEdges collected: " << visitor.collected
<< "\nEdges proccessed: " << visitor.processed
<< "\nEdges collapsed: " << visitor.collapsed
<< endl
<< "\nEdges not collapsed due to topological constrians: " << visitor.non_collapsable
<< "\nEdge not collapsed due to computational constrians: " << visitor.cost_uncomputable
<< endl ;
ofstream os( argc > 2 ? argv[2] : "out.off" ) ;
os << surface ;
return 0 ;
}
// EOF //

View File

@ -0,0 +1,82 @@
#include <iostream>
#include <iomanip>
#include <fstream>
#include <CGAL/Simple_cartesian.h>
// Target surface type. (this include Polyhedron_3.h itself)
#include <CGAL/Surface_mesh_simplification/Polyhedron.h>
// Policies
#include <CGAL/Surface_mesh_simplification/Policies/Edge_collapse/Midpoint_and_length.h>
#include <CGAL/Surface_mesh_simplification/Policies/Edge_collapse/Count_ratio_stop_pred.h>
// Simplification method
#include <CGAL/Surface_mesh_simplification/Edge_collapse.h>
#include <CGAL/IO/Polyhedron_iostream.h>
#include <boost/property_map.hpp>
#include <CGAL/Unique_hash_map.h>
using namespace std ;
using namespace boost ;
using namespace CGAL ;
typedef Simple_cartesian<double> Kernel;
typedef Kernel::Vector_3 Vector;
typedef Kernel::Point_3 Point;
typedef Polyhedron_3<Kernel> Surface;
typedef Surface::Halfedge_handle Halfedge_handle ;
using namespace CGAL::Triangulated_surface_mesh::Simplification::Edge_collapse ;
int main( int argc, char** argv )
{
Surface surface;
ifstream is(argv[1]) ;
is >> surface ;
//
// The simplification algorithm needs to associate some data to each edge.
// In this example we use an external map to do that, properly initialized with null pointers
// and passed to the edge_collapse function as a boost associative property map
//
Unique_hash_map<Halfedge_handle,void*> edge2ptr ;
for ( Surface::Halfedge_iterator hi = surface.halfedges_begin(); hi != surface.halfedges_end() ; ++ hi )
edge2ptr[hi] = 0 ;
//
// Simplify surface
// Down to a 10% of the number of edges.
// Uing an external hasmap to store the per-edge extra pointer
// With no fixed vertices
// Without caching cost and placement
// Using edge length cost
// Using midpoint vertex placement
//
// Implicit policies:
// No parameters to the cost and placement functors
// No visitor.
//
int r = edge_collapse(surface
,Count_ratio_stop_condition<Surface>(0.10)
,boost::make_assoc_property_map(edge2ptr)
,Vertex_is_fixed_map_always_false<Surface>()
,Set_empty_collapse_data <Surface>()
,Edge_length_cost <Surface>()
,Midpoint_placement <Surface>()
);
cout << "\nFinished...\n" << r << " edges removed.\n" << (surface.size_of_halfedges()/2) << " final edges.\n" ;
ofstream os( argc > 2 ? argv[2] : "out.off" ) ;
os << surface ;
return 0 ;
}
// EOF //

View File

@ -0,0 +1,76 @@
# Created by the script cgal_create_makefile
# This is the makefile for compiling a CGAL application.
#---------------------------------------------------------------------#
# include platform specific settings
#---------------------------------------------------------------------#
# Choose the right include file from the <cgalroot>/make directory.
# CGAL_MAKEFILE = ENTER_YOUR_INCLUDE_MAKEFILE_HERE
include $(CGAL_MAKEFILE)
#---------------------------------------------------------------------#
# compiler flags
#---------------------------------------------------------------------#
CXXFLAGS = -I../../include/ \
-I../../../BGL/include/ \
$(EXTRA_FLAGS) \
$(CGAL_CXXFLAGS)
#---------------------------------------------------------------------#
# linker flags
#---------------------------------------------------------------------#
LIBPATH = $(CGAL_LIBPATH)
LDFLAGS = $(CGAL_LDFLAGS)
#---------------------------------------------------------------------#
# target entries
#---------------------------------------------------------------------#
all: \
LT_edge_collapse_polyhedron_example \
LT_edge_collapse_enriched_polyhedron_example \
LT_edge_collapse_visited_fully_enriched_polyhedron_example \
MP_edge_collapse_polyhedron_example \
Edge_collapse_fully_cached_polyhedron_example
LT_edge_collapse_polyhedron_example$(EXE_EXT): LT_edge_collapse_polyhedron_example$(OBJ_EXT)
$(CGAL_CXX) $(LIBPATH) $(EXE_OPT)LT_edge_collapse_polyhedron_example \
LT_edge_collapse_polyhedron_example$(OBJ_EXT) $(LDFLAGS)
LT_edge_collapse_enriched_polyhedron_example$(EXE_EXT): LT_edge_collapse_enriched_polyhedron_example$(OBJ_EXT)
$(CGAL_CXX) $(LIBPATH) $(EXE_OPT)LT_edge_collapse_enriched_polyhedron_example \
LT_edge_collapse_enriched_polyhedron_example$(OBJ_EXT) $(LDFLAGS)
LT_edge_collapse_visited_fully_enriched_polyhedron_example$(EXE_EXT): LT_edge_collapse_visited_fully_enriched_polyhedron_example$(OBJ_EXT)
$(CGAL_CXX) $(LIBPATH) $(EXE_OPT)LT_edge_collapse_visited_fully_enriched_polyhedron_example \
LT_edge_collapse_visited_fully_enriched_polyhedron_example$(OBJ_EXT) $(LDFLAGS)
MP_edge_collapse_polyhedron_example$(EXE_EXT): MP_edge_collapse_polyhedron_example$(OBJ_EXT)
$(CGAL_CXX) $(LIBPATH) $(EXE_OPT)MP_edge_collapse_polyhedron_example \
MP_edge_collapse_polyhedron_example$(OBJ_EXT) $(LDFLAGS)
Edge_collapse_fully_cached_polyhedron_example$(EXE_EXT): Edge_collapse_fully_cached_polyhedron_example$(OBJ_EXT)
$(CGAL_CXX) $(LIBPATH) $(EXE_OPT)Edge_collapse_fully_cached_polyhedron_example \
Edge_collapse_fully_cached_polyhedron_example$(OBJ_EXT) $(LDFLAGS)
clean: \
LT_edge_collapse_polyhedron_example.clean \
LT_edge_collapse_enriched_polyhedron_example.clean \
LT_edge_collapse_visited_fully_enriched_polyhedron_example.clean \
MP_edge_collapse_polyhedron_example.clean \
Edge_collapse_fully_cached_polyhedron_example.clean
#---------------------------------------------------------------------#
# suffix rules
#---------------------------------------------------------------------#
.C$(OBJ_EXT):
$(CGAL_CXX) $(CXXFLAGS) $(OBJ_OPT) $<
.cpp$(OBJ_EXT):
$(CGAL_CXX) $(CXXFLAGS) $(OBJ_OPT) $<

View File

@ -39,13 +39,14 @@ namespace Triangulated_surface_mesh { namespace Simplification { namespace Edge_
// Implementation of the vertex-pair collapse triangulated surface mesh simplification algorithm
//
template<class TSM_
,class Params_
,class ShouldStop_
,class EdgeExtraPtrMap_
,class VertexIsFixedMap_
,class SetCollapseData_
,class GetCost_
,class GetPlacement_
,class ShouldStop_
,class EdgeCachedPtrMap_
,class VertexIsFixedMap_
,class CostParams_
,class PlacementParams_
,class VisitorT_
>
class EdgeCollapse
@ -53,13 +54,14 @@ class EdgeCollapse
public:
typedef TSM_ TSM ;
typedef Params_ Params ;
typedef ShouldStop_ ShouldStop ;
typedef EdgeExtraPtrMap_ EdgeExtraPtrMap ;
typedef VertexIsFixedMap_ VertexIsFixedMap ;
typedef SetCollapseData_ SetCollapseData ;
typedef GetCost_ GetCost ;
typedef GetPlacement_ GetPlacement ;
typedef ShouldStop_ ShouldStop ;
typedef EdgeCachedPtrMap_ EdgeExtraPtrMap ;
typedef VertexIsFixedMap_ VertexIsFixedMap ;
typedef CostParams_ CostParams ;
typedef PlacementParams_ PlacementParams ;
typedef VisitorT_ VisitorT ;
typedef EdgeCollapse Self ;
@ -171,14 +173,15 @@ public:
public:
EdgeCollapse( TSM& aSurface
, Params const* aParams // Can be NULL
, SetCollapseData const& aSetCollapseData
, GetCost const& aGetCost
, GetPlacement const& aGetPlacement
, ShouldStop const& aShouldStop
, EdgeExtraPtrMap const& aEdge_extra_ptr_map
, VertexIsFixedMap const& aVertex_is_fixed_map
, VisitorT* aVisitor
, SetCollapseData const& aSetCollapseData
, GetCost const& aGetCost
, GetPlacement const& aGetPlacement
, CostParams const* aCostParams // Can be NULL
, PlacementParams const* aPlacementParams // Can be NULL
, VisitorT* aVisitor // Can be NULL
) ;
int run() ;
@ -259,14 +262,14 @@ private:
{
Edge_data_ptr lData = get_data(aEdge);
CGAL_assertion(lData);
return Get_cost(aEdge,mSurface,lData->data(),mParams);
return Get_cost(aEdge,mSurface,lData->data(),mCostParams);
}
Optional_placement_type get_placement( edge_descriptor const& aEdge ) const
{
Edge_data_ptr lData = get_data(aEdge);
CGAL_assertion(lData);
return Get_placement(aEdge,mSurface,lData->data(),mParams);
return Get_placement(aEdge,mSurface,lData->data(),mPlacementParams);
}
bool compare_cost( edge_descriptor const& aEdgeA, edge_descriptor const& aEdgeB ) const
@ -313,16 +316,16 @@ private:
private:
TSM& mSurface ;
Params const* mParams ; // Can be NULL
SetCollapseData const& Set_collapse_data;
GetCost const& Get_cost ;
GetPlacement const& Get_placement ;
TSM& mSurface ;
ShouldStop const& Should_stop ;
EdgeExtraPtrMap const& Edge_extra_ptr_map ;
VertexIsFixedMap const& Vertex_is_fixed_map ;
VisitorT* Visitor ;
SetCollapseData const& Set_collapse_data;
GetCost const& Get_cost ;
GetPlacement const& Get_placement ;
CostParams const* mCostParams ; // Can be NULL
PlacementParams const* mPlacementParams ; // Can be NULL
VisitorT* Visitor ; // Can be NULL
private:

View File

@ -23,27 +23,28 @@ CGAL_BEGIN_NAMESPACE
namespace Triangulated_surface_mesh { namespace Simplification { namespace Edge_collapse
{
template<class M,class P,class D,class C,class V,class S, class X, class F, class R>
EdgeCollapse<M,P,D,C,V,S,X,F,R>::EdgeCollapse( TSM& aSurface
, Params const* aParams
, SetCollapseData const& aSet_collapse_data
, GetCost const& aGet_cost
, GetPlacement const& aGet_placement
, ShouldStop const& aShould_stop
, EdgeExtraPtrMap const& aEdge_extra_ptr_map
, VertexIsFixedMap const& aVertex_is_fixed_map
, VisitorT* aVisitor
)
template<class M,class S,class X, class F,class D,class CF,class PF,class CP, class PP,class V>
EdgeCollapse<M,S,X,F,D,CF,PF,CP,PP,V>::EdgeCollapse( TSM& aSurface
, ShouldStop const& aShould_stop
, EdgeExtraPtrMap const& aEdge_extra_ptr_map
, VertexIsFixedMap const& aVertex_is_fixed_map
, SetCollapseData const& aSet_collapse_data
, GetCost const& aGet_cost
, GetPlacement const& aGet_placement
, CostParams const* aCostParams
, PlacementParams const* aPlacementParams
, VisitorT* aVisitor
)
:
mSurface (aSurface)
,mParams(aParams)
,Set_collapse_data (aSet_collapse_data)
,Get_cost (aGet_cost)
,Get_placement (aGet_placement)
mSurface (aSurface)
,Should_stop (aShould_stop)
,Edge_extra_ptr_map (aEdge_extra_ptr_map)
,Vertex_is_fixed_map(aVertex_is_fixed_map)
,Set_collapse_data (aSet_collapse_data)
,Get_cost (aGet_cost)
,Get_placement (aGet_placement)
,mCostParams (aCostParams)
,mPlacementParams (aPlacementParams)
,Visitor (aVisitor)
{
@ -64,8 +65,8 @@ EdgeCollapse<M,P,D,C,V,S,X,F,R>::EdgeCollapse( TSM& aSurface
#endif
}
template<class M,class P,class D,class C,class V,class S, class X, class F, class R>
int EdgeCollapse<M,P,D,C,V,S,X,F,R>::run()
template<class M,class S,class X, class F,class D,class CF,class PF,class CP, class PP,class V>
int EdgeCollapse<M,S,X,F,D,CF,PF,CP,PP,V>::run()
{
if ( Visitor )
Visitor->OnStarted(mSurface);
@ -88,8 +89,8 @@ int EdgeCollapse<M,P,D,C,V,S,X,F,R>::run()
return r ;
}
template<class M,class P,class D,class C,class V,class S, class X, class F, class R>
void EdgeCollapse<M,P,D,C,V,S,X,F,R>::Collect()
template<class M,class S,class X, class F,class D,class CF,class PF,class CP, class PP,class V>
void EdgeCollapse<M,S,X,F,D,CF,PF,CP,PP,V>::Collect()
{
CGAL_TSMS_TRACE(0,"Collecting edges...");
@ -136,7 +137,7 @@ void EdgeCollapse<M,P,D,C,V,S,X,F,R>::Collect()
// But in the case of fixed edges the edge data is left default constructed
if ( !lIsFixed )
{
Set_collapse_data(lData->data(),lEdge,mSurface,mParams) ;
Set_collapse_data(lData->data(),lEdge,mSurface,mCostParams,mPlacementParams) ;
insert_in_PQ(lEdge,lData);
}
@ -151,8 +152,8 @@ void EdgeCollapse<M,P,D,C,V,S,X,F,R>::Collect()
CGAL_TSMS_TRACE(0,"Initial edge count: " << mInitialEdgeCount ) ;
}
template<class M,class P,class D,class C,class V,class S, class X, class F, class R>
void EdgeCollapse<M,P,D,C,V,S,X,F,R>::Loop()
template<class M,class S,class X, class F,class D,class CF,class PF,class CP, class PP,class V>
void EdgeCollapse<M,S,X,F,D,CF,PF,CP,PP,V>::Loop()
{
CGAL_TSMS_TRACE(0,"Collapsing edges...") ;
@ -212,8 +213,8 @@ void EdgeCollapse<M,P,D,C,V,S,X,F,R>::Loop()
//
// The link conidition is as follows: for every vertex 'k' adjacent to both 'p and 'q', "p,k,q" is a facet of the mesh.
//
template<class M,class P,class D,class C,class V,class S, class X, class F, class R>
bool EdgeCollapse<M,P,D,C,V,S,X,F,R>::Is_collapsable( edge_descriptor const& aEdgePQ )
template<class M,class S,class X, class F,class D,class CF,class PF,class CP, class PP,class V>
bool EdgeCollapse<M,S,X,F,D,CF,PF,CP,PP,V>::Is_collapsable( edge_descriptor const& aEdgePQ )
{
bool rR = true ;
@ -305,8 +306,8 @@ bool EdgeCollapse<M,P,D,C,V,S,X,F,R>::Is_collapsable( edge_descriptor const& aEd
return rR ;
}
template<class M,class P,class D,class C,class V,class S, class X, class F, class R>
typename EdgeCollapse<M,P,D,C,V,S,X,F,R>::vertex_descriptor EdgeCollapse<M,P,D,C,V,S,X,F,R>::Collapse( edge_descriptor const& aEdgePQ )
template<class M,class S,class X, class F,class D,class CF,class PF,class CP, class PP,class V>
typename EdgeCollapse<M,S,X,F,D,CF,PF,CP,PP,V>::vertex_descriptor EdgeCollapse<M,S,X,F,D,CF,PF,CP,PP,V>::Collapse( edge_descriptor const& aEdgePQ )
{
CGAL_TSMS_TRACE(1,"S" << mStep << ". Collapsig " << edge_to_string(aEdgePQ) ) ;
@ -433,8 +434,8 @@ typename EdgeCollapse<M,P,D,C,V,S,X,F,R>::vertex_descriptor EdgeCollapse<M,P,D,C
return rResult ;
}
template<class M,class P,class D,class C,class V,class S, class X, class F, class R>
void EdgeCollapse<M,P,D,C,V,S,X,F,R>::Update_neighbors( vertex_descriptor const& aKeptV )
template<class M,class S,class X, class F,class D,class CF,class PF,class CP, class PP,class V>
void EdgeCollapse<M,S,X,F,D,CF,PF,CP,PP,V>::Update_neighbors( vertex_descriptor const& aKeptV )
{
CGAL_TSMS_TRACE(3,"Updating cost of neighboring edges..." ) ;
@ -488,7 +489,7 @@ void EdgeCollapse<M,P,D,C,V,S,X,F,R>::Update_neighbors( vertex_descriptor const&
CGAL_assertion(lData);
Set_collapse_data(lData->data(),lEdge,mSurface,mParams) ;
Set_collapse_data(lData->data(),lEdge,mSurface,mCostParams,mPlacementParams) ;
CGAL_TSMS_TRACE(3, edge_to_string(lEdge) << " updated in the PQ") ;

View File

@ -85,6 +85,30 @@ struct Surface_geometric_traits
} ;
template<class T, class U> struct ChooseNotVoidType ;
template<class T> struct ChooseNotVoidType<T ,void> { typedef T type ; } ;
template<class U> struct ChooseNotVoidType<void,U > { typedef U type ; } ;
template<> struct ChooseNotVoidType<void,void> { typedef void type ; } ;
template<class GetCost, class SetCollapseData>
struct ExtractCostParamsType
{
typedef typename ChooseNotVoidType< typename GetCost::Params
, typename SetCollapseData::CostParams
>
::type type ;
} ;
template<class GetPlacement, class SetCollapseData>
struct ExtractPlacementParamsType
{
typedef typename ChooseNotVoidType< typename GetPlacement::Params
, typename SetCollapseData::PlacementParams
>
::type type ;
} ;
} } // namespace Triangulated_surface_mesh::Simplification
//

View File

@ -18,8 +18,14 @@
#ifndef CGAL_SURFACE_MESH_SIMPLIFICATION_EDGE_COLLAPSE_H
#define CGAL_SURFACE_MESH_SIMPLIFICATION_EDGE_COLLAPSE_H 1
#include <CGAL/boost/graph/BGL_properties.h>
#include <CGAL/Surface_mesh_simplification/Detail/Edge_collapse.h>
#include <CGAL/Surface_mesh_simplification/Edge_extra_pointer_map_stored.h>
#include <CGAL/Surface_mesh_simplification/Vertex_is_fixed_map_always_false.h>
#include <CGAL/Surface_mesh_simplification/Policies/Edge_collapse/LindstromTurk_params.h>
#include <CGAL/Surface_mesh_simplification/Policies/Edge_collapse/LindstromTurk_set_partial_collapse_data.h>
#include <CGAL/Surface_mesh_simplification/Policies/Edge_collapse/LindstromTurk_placement.h>
#include <CGAL/Surface_mesh_simplification/Policies/Edge_collapse/Cached_cost.h>
CGAL_BEGIN_NAMESPACE
@ -59,47 +65,56 @@ namespace Triangulated_surface_mesh { namespace Simplification { namespace Edge_
// This global function returns the number of edges collapsed.
//
template<class TSM
,class Params
,class SetCollapseData
,class GetCost
,class GetPlacement
,class ShouldStop
,class EdgeExtraPtrMap
,class VertexIsFixedMap
,class SetCollapseData
,class GetCost
,class GetPlacement
,class CostParams
,class PlacementParams
,class Visitor
>
int edge_collapse ( TSM& aSurface
, Params const* aParams // Can be NULL
, ShouldStop const& aShould_stop
// optional mesh information policies
, EdgeExtraPtrMap const& aEdge_extra_ptr_map // defaults to Edge_extra_pointer_map_stored<TSM>
, VertexIsFixedMap const& aVertex_is_fixed_map // defaults to Vertex_is_fixed_map_always_false<TSM>
// optional strategy policies - defaults to LindstomTurk
, SetCollapseData const& aSet_collapse_data
, GetCost const& aGet_cost
, GetPlacement const& aGet_placement
, ShouldStop const& aShould_stop
, EdgeExtraPtrMap const& aEdge_extra_ptr_map
, VertexIsFixedMap const& aVertex_is_fixed_map
, Visitor* aVisitor = ((void*)(0))
, CostParams const* aCostParams // Can be NULL
, PlacementParams const* aPlacementParams // Can be NULL
, Visitor* aVisitor // Can be NULL
)
{
typedef EdgeCollapse<TSM
,Params
,SetCollapseData
,GetCost
,GetPlacement
,ShouldStop
,EdgeExtraPtrMap
,VertexIsFixedMap
,SetCollapseData
,GetCost
,GetPlacement
,CostParams
,PlacementParams
,Visitor
>
Algorithm
;
Algorithm algorithm(aSurface
,aParams
,aSet_collapse_data
,aGet_cost
,aGet_placement
,aShould_stop
,aEdge_extra_ptr_map
,aVertex_is_fixed_map
,aSet_collapse_data
,aGet_cost
,aGet_placement
,aCostParams
,aPlacementParams
,aVisitor
) ;
@ -129,61 +144,126 @@ struct Dummy_visitor
} ;
template<class TSM
,class Params
,class SetCollapseData
,class GetCost
,class GetPlacement
,class ShouldStop
,class EdgeExtraPtrMap
,class VertexIsFixedMap
,class SetCollapseData
,class GetCost
,class GetPlacement
,class CostParams
,class PlacementParams
>
int edge_collapse ( TSM& aSurface
, Params const* aParams // Can be NULL
, ShouldStop const& aShould_stop
, EdgeExtraPtrMap const& aEdge_extra_ptr_map
, VertexIsFixedMap const& aVertex_is_fixed_map
, SetCollapseData const& aSet_collapse_data
, GetCost const& aGet_cost
, GetPlacement const& aGet_placement
, ShouldStop const& aShould_stop
, EdgeExtraPtrMap const& aEdge_extra_ptr_map
, VertexIsFixedMap const& aVertex_is_fixed_map = Vertex_is_fixed_map_always_false<TSM>()
, CostParams const* aCostParams
, PlacementParams const* aPlacementParams
)
{
return edge_collapse(aSurface
,aParams
,aSet_collapse_data
,aGet_cost
,aGet_placement
,aShould_stop
,aEdge_extra_ptr_map
,aVertex_is_fixed_map
,aSet_collapse_data
,aGet_cost
,aGet_placement
,aCostParams
,aPlacementParams
,((Dummy_visitor*)0)
);
}
template<class TSM
,class Params
,class ShouldStop
,class EdgeExtraPtrMap
,class VertexIsFixedMap
,class SetCollapseData
,class GetCost
,class GetPlacement
,class ShouldStop
,class EdgeExtraPtrMap
>
int edge_collapse ( TSM& aSurface
, Params const* aParams // Can be NULL
, ShouldStop const& aShould_stop
, EdgeExtraPtrMap const& aEdge_extra_ptr_map
, VertexIsFixedMap const& aVertex_is_fixed_map
, SetCollapseData const& aSet_collapse_data
, GetCost const& aGet_cost
, GetPlacement const& aGet_placement
, ShouldStop const& aShould_stop
, EdgeExtraPtrMap const& aEdge_extra_ptr_map
)
{
typename ExtractCostParamsType <GetCost ,SetCollapseData>::type cost_params ;
typename ExtractPlacementParamsType<GetPlacement,SetCollapseData>::type placement_params ;
return edge_collapse(aSurface
,aParams
,aShould_stop
,aEdge_extra_ptr_map
,aVertex_is_fixed_map
,aSet_collapse_data
,aGet_cost
,aGet_placement
,&cost_params
,&placement_params
,((Dummy_visitor*)0)
);
}
template<class TSM, class ShouldStop, class EdgeExtraPtrMap, class VertexIsFixedMap>
int edge_collapse ( TSM& aSurface
, ShouldStop const& aShould_stop
, EdgeExtraPtrMap const& aEdge_extra_ptr_map
, VertexIsFixedMap const& aVertex_is_fixed_map
)
{
LindstromTurk_params params ;
return edge_collapse(aSurface
,aShould_stop
,aEdge_extra_ptr_map
,aVertex_is_fixed_map
,Set_partial_collapse_data_LindstromTurk<TSM>()
,Cached_cost<TSM>()
,LindstromTurk_placement<TSM>()
,&params
,&params
,((Dummy_visitor*)0)
);
}
template<class TSM, class ShouldStop, class EdgeExtraPtrMap>
int edge_collapse ( TSM& aSurface, ShouldStop const& aShould_stop, EdgeExtraPtrMap const& aEdge_extra_ptr_map )
{
LindstromTurk_params params ;
return edge_collapse(aSurface
,aShould_stop
,aEdge_extra_ptr_map
,Vertex_is_fixed_map_always_false<TSM>()
,Set_partial_collapse_data_LindstromTurk<TSM>()
,Cached_cost<TSM>()
,LindstromTurk_placement<TSM>()
,&params
,&params
,((Dummy_visitor*)0)
);
}
template<class TSM, class ShouldStop>
int edge_collapse ( TSM& aSurface, ShouldStop const& aShould_stop )
{
LindstromTurk_params params ;
return edge_collapse(aSurface
,aShould_stop
,Edge_extra_pointer_map_stored<TSM>()
,Vertex_is_fixed_map_always_false<TSM>()
,Set_partial_collapse_data_LindstromTurk<TSM>()
,Cached_cost<TSM>()
,LindstromTurk_placement<TSM>()
,&params
,&params
,((Dummy_visitor*)0)
);
}

View File

@ -39,9 +39,11 @@ public:
typedef optional<FT> result_type ;
typedef void Params ;
public :
template<class Collapse_data, class Params>
template<class Collapse_data>
result_type operator()( edge_descriptor const& aEdge
, TSM& aSurface
, Collapse_data const& aData

View File

@ -39,10 +39,11 @@ public:
typedef optional<Point_3> result_type ;
typedef void Params ;
public :
template<class Collapse_data, class Params>
template<class Collapse_data>
result_type operator()( edge_descriptor const& aEdge
, TSM& aSurface
, Collapse_data const& aData

View File

@ -43,12 +43,13 @@ public:
typedef optional<FT> result_type ;
typedef char Params ;
public:
mutable int c ; Edge_length_cost() : c(0) {}
Edge_length_cost() {}
template<class Collapse_data, class Params>
template<class Collapse_data>
result_type operator()( edge_descriptor const& aEdge
, TSM& aSurface
, Collapse_data const& aData
@ -60,8 +61,6 @@ public:
Point_3 const& ps = this->get_point(vs,aSurface);
Point_3 const& pt = this->get_point(vt,aSurface);
++ c ;
return result_type(squared_distance(ps,pt));
}

View File

@ -44,9 +44,7 @@ public:
public:
mutable int c ;
LindstromTurk_cost() : c(0) {}
LindstromTurk_cost() {}
template<class Collapse_data>
result_type operator()( edge_descriptor const& aEdge
@ -64,7 +62,6 @@ public:
optional<Point_3> lPlacement ;
tie(lCost,lPlacement) = core.compute();
++ c ;
return lCost ;
}

View File

@ -44,9 +44,8 @@ public:
public:
mutable int p ;
LindstromTurk_placement() : p(0) {}
LindstromTurk_placement() {}
template<class Collapse_data>
result_type operator()( edge_descriptor const& aEdge
@ -64,7 +63,6 @@ public:
optional<Point_3> lPlacement ;
tie(lCost,lPlacement) = core.compute();
++ p ;
return lPlacement ;
}
};

View File

@ -48,28 +48,32 @@ public:
typedef optional<FT> Optional_cost_type ;
typedef optional<Point_3> Optional_placement_type ;
typedef LindstromTurk_params CostParams ;
typedef LindstromTurk_params PlacementParams ;
public :
mutable int c ;
mutable int p ;
Set_full_collapse_data_LindstromTurk() {}
Set_full_collapse_data_LindstromTurk() : c(0), p(0) {}
void operator() ( Collapse_data& rData, edge_descriptor const& aEdge, TSM& aSurface, Params const* aParams ) const
void operator() ( Collapse_data& rData
, edge_descriptor const& aEdge
, TSM& aSurface
, CostParams const* aCostParams
, PlacementParams const* aPlacementParams
) const
{
CGAL_assertion(aParams);
CGAL_assertion(aCostParams);
CGAL_assertion(aPlacementParams);
CGAL_assertion(aCostParams == aPlacementParams);
CGAL_assertion( handle_assigned(aEdge) );
LindstromTurkCore<TSM> core(*aParams,aEdge,aSurface,true);
LindstromTurkCore<TSM> core(*aCostParams,aEdge,aSurface,true);
Optional_cost_type lCost ;
Optional_placement_type lPlacement ;
tie(lCost,lPlacement) = core.compute();
rData = Collapse_data(lCost,lPlacement);
++ c ;
++ p ;
}
};

View File

@ -48,27 +48,29 @@ public:
typedef optional<FT> Optional_cost_type ;
typedef optional<Point_3> Optional_placement_type ;
typedef LindstromTurk_params CostParams ;
typedef void PlacementParams ;
public :
mutable int c ;
mutable int p ;
Set_partial_collapse_data_LindstromTurk() : c(0), p(0) {}
Set_partial_collapse_data_LindstromTurk() {}
void operator() ( Collapse_data& rData, edge_descriptor const& aEdge, TSM& aSurface, Params const* aParams ) const
void operator() ( Collapse_data& rData
, edge_descriptor const& aEdge
, TSM& aSurface
, CostParams const* aCostParams
, PlacementParams const*
) const
{
CGAL_assertion(aParams);
CGAL_assertion(aCostParams);
CGAL_assertion( handle_assigned(aEdge) );
LindstromTurkCore<TSM> core(*aParams,aEdge,aSurface,true);
LindstromTurkCore<TSM> core(*aCostParams,aEdge,aSurface,true);
Optional_cost_type lCost ;
Optional_placement_type lPlacement ;
tie(lCost,lPlacement) = core.compute();
rData = Collapse_data(lCost);
++ c ;
++ p ;
}
};

View File

@ -40,11 +40,13 @@ public:
typedef optional<Point_3> result_type ;
typedef char Params ;
public:
mutable int p ; Midpoint_placement() : p(0) {}
Midpoint_placement() {}
template<class Collapse_data, class Params>
template<class Collapse_data>
result_type operator()( edge_descriptor const& aEdge
, TSM& aSurface
, Collapse_data const& aData
@ -56,8 +58,6 @@ public:
Point_3 const& ps = this->get_point(vs,aSurface);
Point_3 const& pt = this->get_point(vt,aSurface);
++ p ;
return result_type(midpoint(ps,pt));
}

View File

@ -37,10 +37,18 @@ public:
typedef Empty_collapse_data Collapse_data ;
typedef void CostParams ;
typedef void PlacementParams ;
public :
template<class Params>
void operator() ( Collapse_data&, edge_descriptor const&, TSM&, Params const* ) const {}
void operator() ( Collapse_data&
, edge_descriptor const&
, TSM&
, CostParams const*
, PlacementParams const*
) const
{}
};

View File

@ -43,24 +43,28 @@ public:
typedef typename Collapse_data::Optional_cost_type Optional_cost_type ;
typedef typename Collapse_data::Optional_placement_type Optional_placement_type ;
typedef typename GetCost ::Params CostParams ;
typedef typename GetPlacement::Params PlacementParams ;
public :
mutable int c, p ;
Set_full_collapse_data ( GetCost const& aGetCost, GetPlacement const& aGetPlacement ) : get_cost(aGetCost), get_placement(aGetPlacement)
{ c = p = 0 ; }
{}
template<class Params>
void operator() ( Collapse_data& rData, edge_descriptor const& aEdge, TSM& aSurface, Params const* aParams ) const
void operator() ( Collapse_data& rData
, edge_descriptor const& aEdge
, TSM& aSurface
, CostParams const* aCostParams
, PlacementParams const* aPlacementParams
) const
{
CGAL_assertion(aParams);
CGAL_assertion(aCostParams);
CGAL_assertion(aPlacementParams);
CGAL_assertion( handle_assigned(aEdge) );
Optional_cost_type lCost = get_cost (aEdge,aSurface,rData,aParams);
Optional_placement_type lPlacement = get_placement(aEdge,aSurface,rData,aParams);
Optional_cost_type lCost = get_cost (aEdge,aSurface,rData,aCostParams);
Optional_placement_type lPlacement = get_placement(aEdge,aSurface,rData,aPlacementParams);
++ c;
++ p ;
rData = Collapse_data(lCost,lPlacement);
}

View File

@ -39,24 +39,28 @@ public:
typedef Partial_collapse_data<TSM> Collapse_data ;
typedef typename Collapse_data::Optional_cost_type Optional_cost_type ;
typedef typename GetCost::Params CostParams ;
typedef void PlacementParams ;
public :
mutable int c ;
Set_partial_collapse_data ( GetCost const& aGetCost ) : get_cost(aGetCost) { c = 0 ;}
Set_partial_collapse_data ( GetCost const& aGetCost ) : get_cost(aGetCost) {}
template<class Params>
void operator() ( Collapse_data& rData, edge_descriptor const& aEdge, TSM& aSurface, Params const* aParams ) const
void operator() ( Collapse_data& rData
, edge_descriptor const& aEdge
, TSM& aSurface
, CostParams const* aCostParams
, PlacementParams const*
) const
{
CGAL_assertion(aParams);
CGAL_assertion(aCostParams);
CGAL_assertion( handle_assigned(aEdge) );
Optional_cost_type lCost = get_cost(aEdge,aSurface,rData,aParams);
Optional_cost_type lCost = get_cost(aEdge,aSurface,rData,aCostParams);
rData = Collapse_data(lCost);
++ c ;
}
GetCost get_cost ;