aimstil  5.0.5
mesh_conversion.h
Go to the documentation of this file.
1 #ifndef TIL_MESH_CONVERSION_H_
2 #define TIL_MESH_CONVERSION_H_
3 
4 namespace til
5 {
6 
7  //---------------------------------------------------------------------------
8 
9  //----------------------------//
10  // Graph2ListMeshConvertor2 //
11  //----------------------------//
12 
13  template < typename TVertexCollection, typename TFaceCollection, typename TGraphVertices, typename TGraphFaces >
15  {
16  public: // typedefs
17 
18  //typedef std::map<typename std::list<TVertexNode>::const_iterator, std::size_t, ItComp<typename std::list<TVertexNode>::const_iterator> > VertexIndexMap;
19  typedef std::map<const void*, std::size_t> VertexIndexMap;
20 
21  public: // set & get
22 
23  VertexIndexMap & index_vertex() { return m_index_vertex; }
24  //shared_ptr<TVertexCollection> vertices() { return m_vertices; }
25  //shared_ptr<TFaceCollection> faces() { return m_faces; }
26 
27  public: // operators
28 
29  //template < typename TGraphVertices, typename TGraphFaces >
30  void operator()
31  (
32  const TGraphVertices & graph_vertices,
33  const TGraphFaces & graph_faces,
34  TVertexCollection & vertices,
35  TFaceCollection & faces
36  );
37 
38  private: // data, output
39 
40  //shared_ptr<TVertexCollection> m_vertices;
41  //shared_ptr<TFaceCollection> m_faces;
42  VertexIndexMap m_index_vertex;
43  };
44 
45 
46  //---------------------------------------------------------------------------
47 
48  //---------------------------//
49  // List2GraphMeshConvertor //
50  //---------------------------//
51 
54  template < typename TVertexNode, typename TFaceNode, typename TVertexCollection, typename TFaceCollection, typename TNeighborCollection >
56  {
57  public: // operators
58 
59  //template < typename TVertexCollection, typename TFaceCollection, typename TNeighborCollection >
60  void operator()
61  (
62  TVertexCollection const & vertices,
63  TFaceCollection const & faceIndices,
64  std::vector<std::list<std::size_t> > const & invertedFaceIndices,
65  TNeighborCollection const & neighbors,
66  std::list<TVertexNode> & graph_vertices,
67  std::list<TFaceNode> & graph_faces
68  );
69 
70  public: // set & get
71 
72  /*
73  std::list<TVertexNode> & graph_vertices() { return m_graph_vertices; }
74  std::list<TVertexNode> const & graph_vertices() const { return m_graph_vertices; }
75 
76  std::list<TFaceNode> & graph_faces() { return m_graph_faces; }
77  std::list<TFaceNode> const & graph_faces() const { return m_graph_faces; }
78  */
79  /*
80  std::vector<typename std::list<TVertexNode>::iterator> & index_vertex() { return m_index_vertex; }
81  std::vector<typename std::list<TVertexNode>::iterator> const & index_vertex() const { return m_index_vertex; }
82 
83  std::vector<typename std::list<TFaceNode>::iterator> & index_face() { return index_face; }
84  std::vector<typename std::list<TFaceNode>::iterator> const & index_face() const { return index_face; }
85  */
86 
87  private: // data, internal
88  //std::list<TVertexNode> m_graph_vertices;
89  //std::list<TFaceNode> m_graph_faces;
90  std::vector<typename std::list<TVertexNode>::iterator> m_index_vertex;
91  std::vector<typename std::list<TFaceNode>::iterator> m_index_face;
92  };
93 
94  //-- shortcuts --//
95 
96  // TODO: this is wrong, because l2g is destroyed. EIther use smart pointers, OR pass along the
97  // reference to vertexOut/facesOut to l2g.
98 
99  template < typename TVerticesIn, typename TFacesIn, typename TNeighbors, typename TVertexNode, typename TFaceNode >
101  (
102  const TVerticesIn & verticesIn,
103  const TFacesIn & facesIn,
104  const TNeighbors & neighc,
105  std::list<TVertexNode> & verticesOut,
106  std::list<TFaceNode> & facesOut
107  )
108  {
109  std::vector<std::list<std::size_t> > faceIndices = til::invertIndices(facesIn);
111  l2g(verticesIn, facesIn, faceIndices, neighc, verticesOut, facesOut);
112  }
113 
114  template < typename TVerticesIn, typename TFacesIn, typename TVertexNode, typename TFaceNode >
116  (
117  const TVerticesIn & verticesIn,
118  const TFacesIn & facesIn,
119  std::list<TVertexNode> & verticesOut,
120  std::list<TFaceNode> & facesOut
121  )
122  {
124  list2graph_mesh_conversion(verticesIn, facesIn, *neighc, verticesOut, facesOut);
125  }
126 
127  //---------------------------------------------------------------------------
128 
129  // TODO: remove this crap
130 
131  template < typename TMesh >
133  {
134  public: // typedefs
135 
136  //typedef std::map<typename std::list<TVertexNode>::const_iterator, std::size_t, ItComp<typename std::list<TVertexNode>::const_iterator> > VertexIndexMap;
137  typedef std::map<const void*, std::size_t> VertexIndexMap;
138 
139  public: // set & get
140 
141  VertexIndexMap & index_vertex() { return m_index_vertex; }
142  TMesh & mesh() { return m_mesh; }
143 
144  public: // operators
145 
146  template < typename TVertexNode, typename TFaceNode >
147  void operator()
148  (
149  const std::list<TVertexNode> & graph_vertices,
150  const std::list<TFaceNode> & graph_faces
151  )
152  {
153  {
154  {
155  getVertices(m_mesh).resize(graph_vertices.size());
156  std::size_t c = 0;
157  for (typename std::list<TVertexNode>::const_iterator i = graph_vertices.begin(); i != graph_vertices.end(); ++i)
158  {
159  getVertices(m_mesh)[c] = i->pos();
160  m_index_vertex.insert(std::make_pair(static_cast<const void*>(&*i),c));
161  ++c;
162  }
163  }
164  {
165  int c = 0;
166  getFaceIndices(m_mesh).resize(graph_faces.size());
167  for (typename std::list<TFaceNode>::const_iterator i = graph_faces.begin(); i != graph_faces.end(); ++i)
168  {
169  for (int j = 0; j < 3; ++j)
170  getFaceIndices(m_mesh)[c][j] = m_index_vertex[static_cast<const void*>(&*(i->face[j]))];
171  ++c;
172  }
173  }
174  }
175  }
176 
177  private: // data
178  TMesh m_mesh;
179  VertexIndexMap m_index_vertex;
180  };
181 
182 } // namespace til
183 
184 #include "mesh_conversion.tpp"
185 
186 
187 #endif /*MESH_CONVERSION_H_*/
std::map< const void *, std::size_t > VertexIndexMap
std::vector< std::list< std::size_t > > invertIndices(const std::vector< TIndexCollection > &c)
Invert an index array.
VertexIndexMap & index_vertex()
shared_ptr< std::vector< std::vector< typename TFaceCollection::value_type::value_type > > > circular_neighborhoods(TFaceCollection const &faces, std::size_t nVertices)
Get point neighbors so that they form a loop around points.
Belongs to package Box Do not include directly, include til/Box.h instead.
Definition: Accumulator.h:10
std::map< const void *, std::size_t > VertexIndexMap
VertexIndexMap & index_vertex()
const MeshTraits< AimsSurface< D, T > >::FaceIndexCollection & getFaceIndices(const AimsSurface< D, T > &mesh)
Definition: aims_wrap.h:505
Converts a (vertexCollection, faceCollection) mesh into a (vertexList, faceList) mesh graph...
void list2graph_mesh_conversion(const TVerticesIn &verticesIn, const TFacesIn &facesIn, const TNeighbors &neighc, std::list< TVertexNode > &verticesOut, std::list< TFaceNode > &facesOut)
const MeshTraits< AimsSurface< D, T > >::VertexCollection & getVertices(const AimsSurface< D, T > &mesh)
Definition: aims_wrap.h:474