aimstil  5.0.5
mesh_conversion.tpp
Go to the documentation of this file.
1 #ifndef TIL_MESH_CONVERSION_TPP_
2 #define TIL_MESH_CONVERSION_TPP_
3 
4 namespace til
5 {
6 
7  //---------------------------------------------------------------------------
8 
9  template < typename TVertexCollection, typename TFaceCollection, typename TGraphVertices, typename TGraphFaces >
10  //template < typename TVertexCollection, typename TFaceCollection >
11  //template < typename TGraphVertices, typename TGraphFaces >
12  //void Graph2ListMeshConvertor2<TVertexCollection, TFaceCollection>
13  void Graph2ListMeshConvertor2 < TVertexCollection, TFaceCollection, TGraphVertices, TGraphFaces >
14  ::operator()
15  (
16  const TGraphVertices & graph_vertices,
17  const TGraphFaces & graph_faces,
18  TVertexCollection & vertices,
19  TFaceCollection & faces
20  )
21  {
22  // TODO: use accessors instead
23  {
24  vertices.resize(graph_vertices.size());
25  std::size_t c = 0;
26  for (typename TGraphVertices::const_iterator i = graph_vertices.begin(); i != graph_vertices.end(); ++i)
27  {
28  vertices[c] = i->pos();
29  m_index_vertex.insert(std::make_pair(static_cast<const void*>(&*i),c));
30  ++c;
31  }
32  }
33  {
34  int c = 0;
35  faces.resize(graph_faces.size());
36  for (typename TGraphFaces::const_iterator i = graph_faces.begin(); i != graph_faces.end(); ++i)
37  {
38  for (int j = 0; j < 3; ++j)
39  faces[c][j] = m_index_vertex[static_cast<const void*>(&*(i->face[j]))];
40  ++c;
41  }
42  }
43  }
44 
45  //---------------------------------------------------------------------------
46 
47  template < typename TVertexNode, typename TFaceNode, typename TVertexCollection, typename TFaceCollection, typename TNeighborCollection >
48  //template < typename TVertexNode, typename TFaceNode >
49  //template < typename TVertexCollection, typename TFaceCollection, typename TNeighborCollection >
50  //void List2GraphMeshConvertor<TVertexNode, TFaceNode>::
51  void List2GraphMeshConvertor<TVertexNode, TFaceNode, TVertexCollection, TFaceCollection, TNeighborCollection>::
52  operator()
53  (
54  TVertexCollection const & vertices, ///< [input] mesh vertices
55  TFaceCollection const & faceIndices, ///< [input] mesh faces
56  std::vector<std::list<std::size_t> > const & invertedFaceIndices, ///< [input] inverted face indices
57  TNeighborCollection const & neighbors, ///< [input] vertex neighborhoods
58  std::list<TVertexNode> & graph_vertices,
59  std::list<TFaceNode> & graph_faces
60  )
61  {
62  assert(vertices.size() == invertedFaceIndices.size());
63  assert(vertices.size() == neighbors.size());
64 
65  m_index_vertex.resize(vertices.size());
66  m_index_face.resize(faceIndices.size());
67  {
68  // push all vertices into the vertex list and get an index2iterator translation
69  for (std::size_t i = 0; i < vertices.size(); ++i)
70  {
71  // create a node with current position
72  TVertexNode m;
73  m.pos() = vertices[i];
74  // push this node at the end of the vertex list
75  m_index_vertex[i] = graph_vertices.insert(graph_vertices.end(), m);
76  }
77 
78  // now push all faces into the face list
79  for (std::size_t i = 0; i < til::size(faceIndices); ++i)
80  {
81  // create a face with current face indices
82  TFaceNode f;
83  for (int j = 0; j < 3; ++j)
84  {
85  assert(vertices.size() > faceIndices[i][j]);
86  f.face[j] = m_index_vertex[faceIndices[i][j]];
87  }
88  // push this face at the end of the face list
89  m_index_face[i] = graph_faces.insert(graph_faces.end(), f);
90  }
91 
92  // now we need a second pass on the vertices to fill in the neighbor
93  // and the faces structure.
94  for (std::size_t i = 0; i < vertices.size(); ++i)
95  {
96  for (std::list<std::size_t>::const_iterator j = invertedFaceIndices[i].begin(); j != invertedFaceIndices[i].end(); ++j)
97  {
98  assert(faceIndices.size() > *j);
99  m_index_vertex[i]->faces().push_back(m_index_face[*j]);
100  }
101  for (typename TNeighborCollection::value_type::const_iterator iN = neighbors[i].begin();
102  iN != neighbors[i].end(); ++iN)
103  {
104  assert(vertices.size() > *iN);
105  m_index_vertex[i]->neighbors().push_back(m_index_vertex[*iN]);
106  }
107  }
108  }
109  }
110 }
111 
112 #endif /*MESH_CONVERSION_TPP_*/