1 #include <CGAL/Linear_cell_complex_for_combinatorial_map.h>
2 #include <CGAL/Linear_cell_complex_constructors.h>
3 #include <CGAL/Timer.h>
4 #include <iostream>
5 #include <fstream>
6
7 typedef CGAL::Linear_cell_complex_for_combinatorial_map<2,3> LCC_3;
8 typedef LCC_3::Dart_handle Dart_handle;
9 typedef LCC_3::Point Point;
10 typedef LCC_3::FT FT;
11
load_and_simplify_off(LCC_3 & lcc,const std::string & filename,bool updateattribs,int percent)12 void load_and_simplify_off(LCC_3& lcc, const std::string& filename,
13 bool updateattribs, int percent)
14 {
15 std::ifstream ifile(filename.c_str());
16 if (ifile)
17 {
18 CGAL::load_off(lcc, ifile);
19 CGAL::Timer timer;
20 Dart_handle dh;
21 std::size_t nb=(lcc.number_of_darts()*percent)/200;
22 timer.start();
23
24 if (!updateattribs) lcc.set_automatic_attributes_management(false);
25 for (LCC_3::Dart_range::iterator it=lcc.darts().begin(),
26 itend=lcc.darts().end(); it!=itend && nb>0; )
27 {
28 dh=it++;
29 if ( it!=itend && it==lcc.beta<2>(dh) ) ++it;
30 lcc.remove_cell<1>(dh);
31 --nb;
32 }
33 if ( !updateattribs ) lcc.set_automatic_attributes_management(true);
34
35 timer.stop();
36 lcc.display_characteristics(std::cout);
37 std::cout<<", valid="<< lcc.is_valid()
38 <<" time: "<<timer.time()<<" seconds." << std::endl;
39 }
40 }
41
main(int narg,char ** argv)42 int main(int narg, char** argv)
43 {
44 if (narg>1 && (!strcmp(argv[1],"-h") || !strcmp(argv[1],"-?")) )
45 {
46 std::cout<<"Usage: a.out file.off [percentage]"<<std::endl;
47 return EXIT_FAILURE;
48 }
49
50 std::string filename;
51 if ( narg==1 )
52 {
53 filename=std::string("data/armadillo.off");
54 std::cout<<"No filename given: use data/armadillo.off by default."<<std::endl;
55 }
56 else filename=std::string(argv[1]);
57
58 int percent = 30; // remove 30 percent of edges
59 if ( narg>2 ) { percent = atoi(argv[2]); }
60 std::cout<<percent<<"% edges to remove."<<std::endl;
61
62 LCC_3 lcc;
63 std::cout<<"Update attribute DURING operations: ";
64 load_and_simplify_off(lcc, filename, true, percent);
65
66 LCC_3 lcc2;
67 std::cout<<"Update attribute AFTER operations: ";
68 load_and_simplify_off(lcc2, filename, false, percent);
69
70 return EXIT_SUCCESS;
71 }
72