~ubuntu-branches/debian/stretch/cgal/stretch

« back to all changes in this revision

Viewing changes to examples/Surface_mesh_simplification/edge_collapse_constrained_polyhedron.cpp

  • Committer: Package Import Robot
  • Author(s): Joachim Reichel
  • Date: 2014-04-05 10:56:43 UTC
  • mfrom: (1.2.4)
  • Revision ID: package-import@ubuntu.com-20140405105643-jgnrpu2thtx23zfs
Tags: 4.4-1
* New upstream release.
* Remove patches do-not-link-example-with-qt4-support-library.patch and
  fix_jet_fitting_3.patch (applied upstream).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#include <iostream>
2
 
#include <fstream>
3
 
 
4
 
#include <CGAL/Simple_cartesian.h>
5
 
#include <CGAL/Polyhedron_3.h>
6
 
#include <CGAL/IO/Polyhedron_iostream.h>
7
 
 
8
 
// Adaptor for Polyhedron_3
9
 
#include <CGAL/Surface_mesh_simplification/HalfedgeGraph_Polyhedron_3.h>
10
 
 
11
 
// Simplification function
12
 
#include <CGAL/Surface_mesh_simplification/edge_collapse.h>
13
 
 
14
 
// Stop-condition policy
15
 
#include <CGAL/Surface_mesh_simplification/Policies/Edge_collapse/Count_stop_predicate.h>
16
 
 
17
 
// Map used to mark edges as fixed
18
 
#include <CGAL/Unique_hash_map.h>
19
 
 
20
 
typedef CGAL::Simple_cartesian<double> Kernel;
21
 
typedef CGAL::Polyhedron_3<Kernel> Surface; 
22
 
 
23
 
namespace SMS = CGAL::Surface_mesh_simplification ;
24
 
 
25
 
//
26
 
// BGL property map which indicates whether an edge is border OR is marked as non-removable
27
 
//
28
 
class Constrains_map : public boost::put_get_helper<bool,Constrains_map>
29
 
{
30
 
public:
31
 
 
32
 
  typedef boost::readable_property_map_tag                    category;
33
 
  typedef bool                                                value_type;
34
 
  typedef bool                                                reference;
35
 
  typedef boost::graph_traits<Surface const>::edge_descriptor key_type;
36
 
 
37
 
  Constrains_map() : mConstrains(false) {}
38
 
 
39
 
  reference operator[](key_type const& e) const { return e->is_border() || is_constrained(e) ; }
40
 
  
41
 
  void set_is_constrained ( key_type const& e, bool is )  { mConstrains[e]=is; }
42
 
  
43
 
  bool is_constrained( key_type const& e ) const { return mConstrains.is_defined(e) ? mConstrains[e] : false ; }
44
 
  
45
 
private:
46
 
  
47
 
  CGAL::Unique_hash_map<key_type,bool> mConstrains ;
48
 
  
49
 
};
50
 
 
51
 
int main( int argc, char** argv ) 
52
 
{
53
 
  Surface surface; 
54
 
  
55
 
  std::ifstream is(argv[1]) ; is >> surface ;
56
 
 
57
 
  // This is a stop predicate (defines when the algorithm terminates).
58
 
  // In this example, the simplification stops when the number of undirected edges
59
 
  // left in the surface drops below the specified number (1000)
60
 
  SMS::Count_stop_predicate<Surface> stop(10);
61
 
     
62
 
  Constrains_map constrains_map ;
63
 
     
64
 
     
65
 
  // This example marks ALL edges as non-removable, but a real world application would mark only selected ones.   
66
 
  for( Surface::Halfedge_iterator eb = surface.halfedges_begin(), ee = surface.halfedges_end() ; eb != ee ; ++ eb ) 
67
 
    constrains_map.set_is_constrained(eb,true);
68
 
     
69
 
  // This the actual call to the simplification algorithm.
70
 
  // The surface and stop conditions are mandatory arguments.
71
 
  // The index maps are needed because the vertices and edges
72
 
  // of this surface lack an "id()" field.
73
 
  int r = SMS::edge_collapse
74
 
            (surface
75
 
            ,stop
76
 
            ,CGAL::vertex_index_map(boost::get(CGAL::vertex_external_index,surface)) 
77
 
                  .edge_index_map  (boost::get(CGAL::edge_external_index  ,surface)) 
78
 
                  .edge_is_border_map(constrains_map)
79
 
            );
80
 
  
81
 
  std::cout << "\nFinished...\n" << r << " edges removed.\n" 
82
 
            << (surface.size_of_halfedges()/2) << " final edges.\n" ;
83
 
        
84
 
  std::ofstream os( argc > 2 ? argv[2] : "out.off" ) ; os << surface ;
85
 
  
86
 
  return 0 ;      
87
 
}