MeshCGALExtensions.h
Go to the documentation of this file.
1 #pragma once
2 
3 #pragma GCC diagnostic push
4 #pragma GCC diagnostic ignored "-Wpedantic"
5 #include <CGAL/Polyhedron_3.h>
6 #include <CGAL/Surface_mesh/Surface_mesh.h>
7 #include <CGAL/boost/graph/iterator.h>
8 #pragma GCC diagnostic pop
9 
10 #include "Mesh.h"
11 
12 namespace armarx::viz
13 {
14  template<class T>
16  {
17  using sm_t = CGAL::Surface_mesh<T>;
18  using vidx_t = typename sm_t::Vertex_index;
19 
20  auto& vertices = data_->vertices;
21  auto& faces = data_->faces;
22  vertices.clear();
23  faces.clear();
24  vertices.reserve(sm.number_of_vertices());
25  faces.reserve(sm.number_of_faces());
26  std::map<vidx_t, std::size_t> index;
27  for (const auto& vidx : sm.vertices())
28  {
29  index[vidx] = vertices.size();
30  const auto& p = sm.point(vidx);
31  armarx::Vector3f visp;
32  visp.e0 = p.x();
33  visp.e1 = p.y();
34  visp.e2 = p.z();
35  vertices.emplace_back(visp);
36  }
37  for (const auto& fidx : sm.faces())
38  {
39  data::Face f;
40  const auto hf = sm.halfedge(fidx);
41  std::size_t i = 0;
42  for (auto hi : CGAL::halfedges_around_face(hf, sm))
43  {
44  const auto vidx = CGAL::target(hi, sm);
45  switch (i++)
46  {
47  case 0:
48  f.v0 = index.at(vidx);
49  break;
50  case 1:
51  f.v1 = index.at(vidx);
52  break;
53  case 2:
54  f.v2 = index.at(vidx);
55  break;
56  default:
57  break; // error handling below
58  }
59  }
60  ARMARX_CHECK_EQUAL(3, i) << "One face is no triangle!";
61  faces.emplace_back(f);
62  }
63  return *this;
64  }
65 
66  template < class PolyhedronTraits_3,
67  class PolyhedronItems_3,
68  template < class T, class I, class A>
69  class T_HDS,
70  class Alloc>
72  PolyhedronTraits_3,
73  PolyhedronItems_3,
74  T_HDS,
75  Alloc
76  > & p3)
77  {
78  auto& vertices = data_->vertices;
79  auto& faces = data_->faces;
80  vertices.clear();
81  faces.clear();
82  vertices.reserve(p3.size_of_vertices());
83  faces.reserve(p3.size_of_facets());
84  auto vbeg = p3.vertices_begin();
85  for (const auto& v : CGAL::Iterator_range{vbeg, p3.vertices_end()})
86  {
87  const auto& p = v.point();
88  armarx::Vector3f visp;
89  visp.e0 = p.x();
90  visp.e1 = p.y();
91  visp.e2 = p.z();
92  vertices.emplace_back(visp);
93  }
94  for (const auto& fidx : CGAL::Iterator_range{p3.facets_begin(), p3.facets_end()})
95  {
96  auto circ = fidx.facet_begin();
97  ARMARX_CHECK_EQUAL(3, CGAL::circulator_size(circ))
98  << "One face is no triangle!";
99  data::Face f;
100  f.v0 = std::distance(vbeg, circ->vertex());
101  ++circ;
102  f.v1 = std::distance(vbeg, circ->vertex());
103  ++circ;
104  f.v2 = std::distance(vbeg, circ->vertex());
105  ++circ;
106  ARMARX_CHECK_EXPRESSION(circ == fidx.facet_begin())
107  << "Internal error while circulating a facet";
108  faces.emplace_back(f);
109  }
110  return *this;
111  }
112 }
CGAL::Surface_mesh
Definition: Mesh.h:22
index
uint8_t index
Definition: EtherCATFrame.h:59
armarx::viz::Mesh
Definition: Mesh.h:28
boost::target
Vertex target(const detail::edge_base< Directed, Vertex > &e, const PCG &)
Definition: point_cloud_graph.h:688
armarx::viz::ElementOps< Mesh, data::ElementMesh >::data_
IceInternal::Handle< data::ElementMesh > data_
Definition: ElementOps.h:281
armarx::viz::Mesh::faces
Mesh & faces(const data::Face *fs, std::size_t size)
Definition: Mesh.h:73
Mesh.h
CGAL::Polyhedron_3
Definition: Mesh.h:21
armarx::ctrlutil::v
double v(double t, double v0, double a0, double j)
Definition: CtrlUtil.h:39
ARMARX_CHECK_EXPRESSION
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
Definition: ExpressionException.h:73
armarx::viz::Mesh::vertices
Mesh & vertices(const Eigen::Vector3f *vs, std::size_t size)
Definition: Mesh.h:33
armarx::viz::Mesh::mesh
Mesh & mesh(const CGAL::Surface_mesh< T > &sm)
Definition: MeshCGALExtensions.h:15
hi
#define hi(x)
Definition: AbstractInterface.h:42
distance
double distance(const Point &a, const Point &b)
Definition: point.hpp:88
ARMARX_CHECK_EQUAL
#define ARMARX_CHECK_EQUAL(lhs, rhs)
This macro evaluates whether lhs is equal (==) rhs and if it turns out to be false it will throw an E...
Definition: ExpressionException.h:130
armarx::viz
This file is part of ArmarX.
Definition: ArVizStorage.cpp:416