File: linear_cell_complex_3_attributes_management.cpp

package info (click to toggle)
cgal 4.9-1
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 85,584 kB
  • sloc: cpp: 640,841; ansic: 140,696; sh: 708; fortran: 131; makefile: 114; python: 92
file content (72 lines) | stat: -rw-r--r-- 2,132 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <CGAL/Linear_cell_complex.h>
#include <CGAL/Linear_cell_complex_operations.h>
#include <CGAL/Linear_cell_complex_constructors.h>
#include <CGAL/Timer.h>
#include <iostream>
#include <fstream>

typedef CGAL::Linear_cell_complex<2,3> LCC_3;
typedef LCC_3::Dart_handle             Dart_handle;
typedef LCC_3::Point                   Point;
typedef LCC_3::FT                      FT;

void load_and_simplify_off(LCC_3& lcc, const std::string& filename,
                           bool updateattribs, int percent)
{
  std::ifstream ifile(filename.c_str());
  if (ifile)
  {
    CGAL::load_off(lcc, ifile);
    CGAL::Timer timer;
    Dart_handle dh;
    std::size_t nb=(lcc.number_of_darts()*percent)/200;
    timer.start();

    if (!updateattribs) lcc.set_automatic_attributes_management(false);
    for (LCC_3::Dart_range::iterator it=lcc.darts().begin(),
           itend=lcc.darts().end(); it!=itend && nb>0; )
    {
      dh=it++;
      if ( it!=itend && it==lcc.beta<2>(dh) ) ++it;
      lcc.remove_cell<1>(dh);
      --nb;
    }
    if ( !updateattribs ) lcc.set_automatic_attributes_management(true);

    timer.stop();
    lcc.display_characteristics(std::cout);
    std::cout<<", valid="<< lcc.is_valid()
             <<" time: "<<timer.time()<<" seconds." << std::endl;
  }
}

int main(int narg, char** argv)
{
  if (narg>1 && (!strcmp(argv[1],"-h") || !strcmp(argv[1],"-?")) )
  {
    std::cout<<"Usage: a.out file.off [percentage]"<<std::endl;
    return EXIT_FAILURE;
  }

  std::string filename;
  if ( narg==1 )
  {
    filename=std::string("data/armadillo.off");
    std::cout<<"No filename given: use data/armadillo.off by default."<<std::endl;
  }
  else filename=std::string(argv[1]);

  int percent = 30; // remove 30 percent of edges
  if ( narg>2 ) { percent = atoi(argv[2]); }
  std::cout<<percent<<"% edges to remove."<<std::endl;

  LCC_3 lcc;
  std::cout<<"Update attribute DURING operations: ";
  load_and_simplify_off(lcc, filename, true, percent);

  LCC_3 lcc2;
  std::cout<<"Update attribute AFTER operations: ";
  load_and_simplify_off(lcc2, filename, false, percent);

  return EXIT_SUCCESS;
}