AttributeMeshIOBase.cpp
Go to the documentation of this file.
1 
29 namespace lvr2{
30 
31 const std::string attribute_type<EdgeHandle>::attr_group = "edge_attributes";
32 const std::string attribute_type<OptionalEdgeHandle>::attr_group = "edge_attributes";
33 const std::string attribute_type<VertexHandle>::attr_group = "vertex_attributes";
34 const std::string attribute_type<OptionalVertexHandle>::attr_group = "vertex_attributes";
35 const std::string attribute_type<FaceHandle>::attr_group = "face_attributes";
36 const std::string attribute_type<OptionalFaceHandle>::attr_group = "face_attributes";
37 const std::string attribute_type<ClusterHandle>::attr_group = "cluster_attributes";
38 const std::string attribute_type<OptionalClusterHandle>::attr_group = "cluster_attributes";
39 
41 {
42  FloatChannel vertices(hem.numVertices(), 3);
43  IndexChannel indices(hem.numFaces(), 3);
44 
45  DenseVertexMap<size_t > new_indices;
46  new_indices.reserve(hem.numVertices());
47 
48  size_t k = 0;
49  for(size_t i=0; i<hem.nextVertexIndex(); i++)
50  {
51  VertexHandle vH(i);
52  if(!hem.containsVertex(vH)) continue;
53  new_indices.insert(vH, k);
54  vertices[k++] = hem.getVertexPosition(vH);
55  }
56 
57  Index i = 0;
58  for(auto fH : hem.faces())
59  {
60  auto vHs = hem.getVerticesOfFace(fH);
61  indices[i][0] = new_indices[vHs[0]];
62  indices[i][1] = new_indices[vHs[1]];
63  indices[i][2] = new_indices[vHs[2]];
64  i++;
65  }
66  return addVertices(vertices) && addIndices(indices);
67 }
68 
69 boost::optional<HalfEdgeMesh<BaseVec>> AttributeMeshIOBase::getMesh()
70 {
71  auto vertices_opt = getVertices();
72  auto indices_opt = getIndices();
73 
74  if(vertices_opt && indices_opt)
75  {
76  auto& vertices = vertices_opt.get();
77  auto& indices = indices_opt.get();
78 
80  for (size_t i = 0; i < vertices.numElements(); i++)
81  {
82  hem.addVertex(vertices[i]);
83  }
84 
85  for (size_t i = 0; i < indices.numElements(); i++)
86  {
87  const std::array<VertexHandle, 3>& face = indices[i];
88  hem.addFace(face[0], face[1], face[2]);
89  }
90  return hem;
91  }
92  return boost::none;
93 }
94 
95 }
96 
size_t numVertices() const final
Returns the number of vertices in the mesh.
bool containsVertex(VertexHandle vH) const
Checks if the given vertex is part of this mesh.
Handle to access vertices of the mesh.
Definition: Handles.hpp:146
boost::optional< HalfEdgeMesh< BaseVec > > getMesh()
Reads a HalfEdgeMesh from the persistence layer.
uint32_t Index
Datatype used as index for each vertex, face and edge.
Definition: Handles.hpp:96
void reserve(size_t newCap)
virtual FloatChannelOptional getVertices()=0
Persistence layer interface, Accesses the vertices of the mesh in the persistence layer...
virtual bool addVertices(const FloatChannel &channel_ptr)=0
Persistence layer interface, Writes the vertices of the mesh to the persistence layer.
array< VertexHandle, 3 > getVerticesOfFace(FaceHandle handle) const final
Get the three vertices surrounding the given face.
virtual bool addIndices(const IndexChannel &channel_ptr)=0
Persistence layer interface, Writes the face indices of the mesh to the persistence layer...
virtual IndexChannelOptional getIndices()=0
Persistence layer interface, Accesses the face indices of the mesh in the persistence layer...
FaceHandle addFace(VertexHandle v1H, VertexHandle v2H, VertexHandle v3H) final
Creates a face connecting the three given vertices.
virtual FaceIteratorProxy< BaseVecT > faces() const
Method for usage in range-based for-loops.
Half-edge data structure implementing the BaseMesh interface.
size_t numFaces() const final
Returns the number of faces in the mesh.
A map with constant lookup overhead using small-ish integer-keys.
Definition: VectorMap.hpp:60
bool addMesh(const HalfEdgeMesh< BaseVec > &hem)
Adds a HalfEdgeMesh to the persistence layer.
Index nextVertexIndex() const
Returns the handle index which would be assigned to the next vertex that is created. This method is mainly useful for manually iterating over all possible handles. As handles are strictly increasing, all vertices currently in this mesh have a handle index smaller than what this method returns.
BaseVecT getVertexPosition(VertexHandle handle) const final
Get the position of the given vertex.
VertexHandle addVertex(BaseVecT pos) final
Adds a vertex with the given position to the mesh.


lvr2
Author(s): Thomas Wiemann , Sebastian Pütz , Alexander Mock , Lars Kiesow , Lukas Kalbertodt , Tristan Igelbrink , Johan M. von Behren , Dominik Feldschnieders , Alexander Löhr
autogenerated on Mon Feb 28 2022 22:46:06