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 
lvr2::HalfEdgeMesh::numVertices
size_t numVertices() const final
Returns the number of vertices in the mesh.
lvr2::MeshGeometryIO::addVertices
virtual bool addVertices(const FloatChannel &channel_ptr)=0
Persistence layer interface, Writes the vertices of the mesh to the persistence layer.
lvr2::HalfEdgeMesh::numFaces
size_t numFaces() const final
Returns the number of faces in the mesh.
lvr2::MeshGeometryIO::addIndices
virtual bool addIndices(const IndexChannel &channel_ptr)=0
Persistence layer interface, Writes the face indices of the mesh to the persistence layer.
lvr2::HalfEdgeMesh::nextVertexIndex
Index nextVertexIndex() const
Returns the handle index which would be assigned to the next vertex that is created....
lvr2::HalfEdgeMesh::getVertexPosition
BaseVecT getVertexPosition(VertexHandle handle) const final
Get the position of the given vertex.
lvr2::VectorMap
A map with constant lookup overhead using small-ish integer-keys.
Definition: VectorMap.hpp:60
lvr2::HalfEdgeMesh::addVertex
VertexHandle addVertex(BaseVecT pos) final
Adds a vertex with the given position to the mesh.
lvr2::HalfEdgeMesh::getVerticesOfFace
array< VertexHandle, 3 > getVerticesOfFace(FaceHandle handle) const final
Get the three vertices surrounding the given face.
lvr2::VertexHandle
Handle to access vertices of the mesh.
Definition: Handles.hpp:146
lvr2::Channel< float >
lvr2::HalfEdgeMesh::addFace
FaceHandle addFace(VertexHandle v1H, VertexHandle v2H, VertexHandle v3H) final
Creates a face connecting the three given vertices.
lvr2::HalfEdgeMesh::containsVertex
bool containsVertex(VertexHandle vH) const
Checks if the given vertex is part of this mesh.
lvr2::AttributeMeshIOBase::addMesh
bool addMesh(const HalfEdgeMesh< BaseVec > &hem)
Adds a HalfEdgeMesh to the persistence layer.
Definition: AttributeMeshIOBase.cpp:40
lvr2::AttributeMeshIOBase::getMesh
boost::optional< HalfEdgeMesh< BaseVec > > getMesh()
Reads a HalfEdgeMesh from the persistence layer.
Definition: AttributeMeshIOBase.cpp:69
lvr2
Definition: BaseBufferManipulators.hpp:39
AttributeMeshIOBase.hpp
lvr2::VectorMap::insert
boost::optional< ValueT > insert(HandleT key, const ValueT &value) final
Inserts the given value at the given key position.
lvr2::BaseMesh::faces
virtual FaceIteratorProxy< BaseVecT > faces() const
Method for usage in range-based for-loops.
lvr2::Index
uint32_t Index
Datatype used as index for each vertex, face and edge.
Definition: Handles.hpp:96
lvr2::MeshGeometryIO::getIndices
virtual IndexChannelOptional getIndices()=0
Persistence layer interface, Accesses the face indices of the mesh in the persistence layer.
lvr2::VectorMap::reserve
void reserve(size_t newCap)
lvr2::MeshGeometryIO::getVertices
virtual FloatChannelOptional getVertices()=0
Persistence layer interface, Accesses the vertices of the mesh in the persistence layer.
lvr2::HalfEdgeMesh
Half-edge data structure implementing the BaseMesh interface.
Definition: HalfEdgeMesh.hpp:70


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 Wed Mar 2 2022 00:37:22