File: extrude.cpp

package info (click to toggle)
cgal 6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 144,912 kB
  • sloc: cpp: 810,858; ansic: 208,477; sh: 493; python: 411; makefile: 286; javascript: 174
file content (75 lines) | stat: -rw-r--r-- 2,294 bytes parent folder | download | duplicates (2)
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
73
74
75
#include <CGAL/Surface_mesh.h>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Polygon_mesh_processing/compute_normal.h>
#include <CGAL/Polygon_mesh_processing/extrude.h>
#include <CGAL/IO/polygon_mesh_io.h>

#include <iostream>
#include <fstream>
#include <string>

typedef CGAL::Exact_predicates_inexact_constructions_kernel    Kernel;
typedef CGAL::Surface_mesh<Kernel::Point_3>                    Mesh;
typedef boost::graph_traits<Mesh>::vertex_descriptor           vertex_descriptor;

typedef Kernel::Vector_3                                       Vector;
typedef boost::property_map<Mesh, CGAL::vertex_point_t>::type  VPMap;
typedef Mesh::template Property_map<vertex_descriptor, Vector> VNMap;

struct Bottom
{
  Bottom(VPMap pmap, VNMap nmap, double vlen)
    : pmap(pmap), nmap(nmap), vlen(vlen)
  {}


  void operator()(const vertex_descriptor& vin, const vertex_descriptor vout) const
  {
    put(pmap, vout, get(pmap, vout) - vlen* get(nmap, vin));
  }

  VPMap pmap;
  VNMap nmap;
  double vlen;
};

struct Top
{
  Top(VPMap pmap, VNMap nmap, double vlen)
    : pmap(pmap), nmap(nmap), vlen(vlen)
  {}


  void operator()(const vertex_descriptor& vin, const vertex_descriptor vout) const
  {
    put(pmap, vout, get(pmap, vout) + vlen* get(nmap, vin));
  }

  VPMap pmap;
  VNMap nmap;
  double vlen;
};

int main(int argc, char* argv[])
{
  Mesh in, out;

  std::string filename = (argc > 1) ? std::string(argv[1]) : CGAL::data_file_path("meshes/cube-ouvert.off");
  double vlen = (argc > 2) ? std::stod(argv[2]) : 0.1;

  CGAL::IO::read_polygon_mesh(filename, in);

  VNMap vnormals = in.template add_property_map<vertex_descriptor, Vector>("v:normal", CGAL::NULL_VECTOR).first;

  CGAL::Polygon_mesh_processing::compute_vertex_normals(in, vnormals);
  Bottom bottom(get(CGAL::vertex_point,out), vnormals, vlen);
  Top top(get(CGAL::vertex_point,out), vnormals, vlen);
  CGAL::Polygon_mesh_processing::extrude_mesh(in, out, bottom, top);


  filename = filename.substr(filename.find_last_of("/") + 1, filename.length() - 1);
  filename = filename.substr(0, filename.find_last_of("."));
  filename = filename + "_" + std::to_string(vlen) + ".off";
  CGAL::IO::write_polygon_mesh(filename, out, CGAL::parameters::stream_precision(17));
  return 0;
}