1 #ifndef TIL_MESH_CONVERSION_TPP_
2 #define TIL_MESH_CONVERSION_TPP_
7 //---------------------------------------------------------------------------
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 >
16 const TGraphVertices & graph_vertices,
17 const TGraphFaces & graph_faces,
18 TVertexCollection & vertices,
19 TFaceCollection & faces
22 // TODO: use accessors instead
24 vertices.resize(graph_vertices.size());
26 for (typename TGraphVertices::const_iterator i = graph_vertices.begin(); i != graph_vertices.end(); ++i)
28 vertices[c] = i->pos();
29 m_index_vertex.insert(std::make_pair(static_cast<const void*>(&*i),c));
35 faces.resize(graph_faces.size());
36 for (typename TGraphFaces::const_iterator i = graph_faces.begin(); i != graph_faces.end(); ++i)
38 for (int j = 0; j < 3; ++j)
39 faces[c][j] = m_index_vertex[static_cast<const void*>(&*(i->face[j]))];
45 //---------------------------------------------------------------------------
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>::
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
62 assert(vertices.size() == invertedFaceIndices.size());
63 assert(vertices.size() == neighbors.size());
65 m_index_vertex.resize(vertices.size());
66 m_index_face.resize(faceIndices.size());
68 // push all vertices into the vertex list and get an index2iterator translation
69 for (std::size_t i = 0; i < vertices.size(); ++i)
71 // create a node with current position
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);
78 // now push all faces into the face list
79 for (std::size_t i = 0; i < til::size(faceIndices); ++i)
81 // create a face with current face indices
83 for (int j = 0; j < 3; ++j)
85 assert(vertices.size() > faceIndices[i][j]);
86 f.face[j] = m_index_vertex[faceIndices[i][j]];
88 // push this face at the end of the face list
89 m_index_face[i] = graph_faces.insert(graph_faces.end(), f);
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)
96 for (std::list<std::size_t>::const_iterator j = invertedFaceIndices[i].begin(); j != invertedFaceIndices[i].end(); ++j)
98 assert(faceIndices.size() > *j);
99 m_index_vertex[i]->faces().push_back(m_index_face[*j]);
101 for (typename TNeighborCollection::value_type::const_iterator iN = neighbors[i].begin();
102 iN != neighbors[i].end(); ++iN)
104 assert(vertices.size() > *iN);
105 m_index_vertex[i]->neighbors().push_back(m_index_vertex[*iN]);
112 #endif /*MESH_CONVERSION_TPP_*/