Medusa  1.1
Coordinate Free Mehless Method implementation
PolyhedronShape.hpp
1 #ifndef MEDUSA_BITS_DOMAINS_POLYHEDRONSHAPE_HPP_
2 #define MEDUSA_BITS_DOMAINS_POLYHEDRONSHAPE_HPP_
3 
7 
8 namespace mm {
9 
10 template <typename vec_t>
12  const std::function<scalar_t(vec_t)>& dr, int type) const {
13  bool vexists, fexists, cexists;
14  Mesh::Property_map<VI, Vector> vnormals;
15  Mesh::Property_map<FI, Vector> fnormals;
16  Mesh::Property_map<FI, CGAL::Color> fcolors;
17  std::tie(vnormals, vexists) = surface.property_map<VI, Vector>("v:normals");
18  assert_msg(vexists, "Vertex normals were not computed.");
19  std::tie(fnormals, fexists) = surface.property_map<FI, Vector>("f:normals");
20  assert_msg(fexists, "Face normals were not computed.");
21  std::tie(fcolors, cexists) = surface.property_map<FI, CGAL::Color>("f:color");
22  auto get_face_type = [&](FI face) {
23  return (cexists && type == 0) ?
24  rgb2type(fcolors[face].r(), fcolors[face].g(), fcolors[face].b()) :
25  -1;
26  };
28  auto d = mm::DomainDiscretization<vec_t>(*this);
29  auto add_point = [&](const vec_t& p, int type, const vec_t& n) {
30  if (tree.existsPointInSphere(p, dr(p))) return;
31  tree.insert(p);
32  d.addBoundaryNode(p, type, n);
33  };
34 
35  // Discretize vertices.
36  for (VI idx : surface.vertices()) {
37  int face_type = get_face_type(surface.face(surface.halfedge(idx)));
38  auto n = vnormals[idx];
39  add_point(getPoint(idx), face_type, {n.x(), n.y(), n.z()});
40  }
41  // Discretize edges.
42  for (Mesh::edge_index idx : surface.edges()) {
43  FI face1 = surface.face(idx.halfedge());
44  FI face2 = surface.face(surface.opposite(idx.halfedge()));
45  Vector normal1 = fnormals[face1];
46  Vector normal2 = fnormals[face2];
47  vec_t n1 = {normal1.x(), normal1.y(), normal1.z()};
48  vec_t n2 = {normal2.x(), normal2.y(), normal2.z()};
49  vec_t n = (n1 + n2).normalized();
50  int face_type = get_face_type(face1);
51 
52  vec_t p1 = getPoint(surface.vertex(idx, 0));
53  vec_t p2 = getPoint(surface.vertex(idx, 1));
54  for (const vec_t& p : discretization_helpers::discretizeLineWithDensity(p1, p2, dr)) {
55  add_point(p, face_type, n);
56  }
57  }
58  // Discretize faces.
59  for (FI face : surface.faces()) {
60  auto range = surface.vertices_around_face(surface.halfedge(face));
61  assert_msg(range.size() == 3, "All faces must be triangles.");
62  auto it = range.begin();
63  VI p1 = *it;
64  ++it;
65  VI p2 = *it;
66  ++it;
67  VI p3 = *it;
68 
69  int face_type = get_face_type(face);
70  Vector normal = fnormals[face];
71  vec_t n = {normal.x(), normal.y(), normal.z()};
72  std::vector<vec_t> points_on_surface =
74  getPoint(p1), getPoint(p2), getPoint(p3), n, dr);
75  for (const auto& p : points_on_surface) {
76  add_point(p, face_type, n);
77  }
78  }
79  return d;
80 }
81 
82 } // namespace mm
83 
84 #endif // MEDUSA_BITS_DOMAINS_POLYHEDRONSHAPE_HPP_
mm::KDTreeMutable::insert
void insert(const vec_t &point)
Insert a point into the tree.
Definition: KDTreeMutable.hpp:24
mm
Root namespace for the whole library.
Definition: Gaussian.hpp:14
scalar_t
Scalar scalar_t
Type of the elements, alias of Scalar.
Definition: MatrixBaseAddons.hpp:16
mm::DomainDiscretization
Class representing domain discretization along with an associated shape.
Definition: DomainDiscretization_fwd.hpp:46
DomainDiscretization.hpp
mm::KDTreeMutable
A k-d tree data structure that supports dynamic insertions and lazy-removal.
Definition: HalfLinksRefine_fwd.hpp:18
mm::PolyhedronShape::discretizeBoundaryWithDensity
DomainDiscretization< vec_t > discretizeBoundaryWithDensity(const std::function< scalar_t(vec_t)> &dr, int type) const override
Discretizes boundary with given density and fill engine.
Definition: PolyhedronShape.hpp:11
mm::discretization_helpers::discretizeTriangleWithDensity
Range< vec_t > discretizeTriangleWithDensity(const vec_t &p1, const vec_t &p2, const vec_t &p3, const vec_t &normal, const func_t &h, bool only_interior=true)
Discretize a triangle in 3D space with given density.
Definition: discretization_helpers_advanced.hpp:45
assert_msg
#define assert_msg(cond,...)
Assert with better error reporting.
Definition: assert.hpp:75
KDTreeMutable.hpp
mm::KDTreeMutable::existsPointInSphere
bool existsPointInSphere(const vec_t &p, scalar_t r)
Check if any point exists in sphere centered at p with radius r.
Definition: KDTreeMutable_fwd.hpp:88
mm::discretization_helpers::discretizeLineWithDensity
Range< vec_t > discretizeLineWithDensity(const vec_t &p, const vec_t &q, const func_t &delta_r)
Returns nodes lying on the line segment pq with approximate distances delta_r.
Definition: discretization_helpers.hpp:35
mm::PolyhedronShape::Vector
K::Vector_3 Vector
CGAL vector type.
Definition: PolyhedronShape_fwd.hpp:53
mm::PolyhedronShape::FI
Mesh::Face_index FI
CGAL index type for a face on a surface mesh.
Definition: PolyhedronShape_fwd.hpp:56
mm::PolyhedronShape::VI
Mesh::Vertex_index VI
CGAL index type for a point on a surface mesh.
Definition: PolyhedronShape_fwd.hpp:55
PolyhedronShape_fwd.hpp