13 #include <boost/graph/graph_traits.hpp>
14 #include <boost/graph/properties.hpp>
36 template<
typename FaceListGraph,
42 typename GeometryTraits >
51 const GeometryTraits &)
53 typedef boost::graph_traits< FaceListGraph > GraphTraits;
55 typedef typename GraphTraits::vertex_iterator vertex_iterator;
56 typedef boost::iterator_range< vertex_iterator > vertex_range;
58 typedef typename GraphTraits::halfedge_descriptor halfedge_descriptor;
60 typedef typename GraphTraits::face_iterator face_iterator;
61 typedef boost::iterator_range< face_iterator > face_range;
67 bool use_vertex_normal =
false;
68 bool use_vertex_color =
false;
69 bool use_vertex_texture_coord =
false;
70 bool use_halfedge_texture_coord =
false;
71 bool use_face_color =
false;
72 bool use_face_normal =
false;
73 bool use_face_material =
false;
74 bool use_mesh_materials =
false;
77 use_vertex_normal =
true;
79 use_face_normal =
true;
81 use_vertex_color =
true;
83 use_face_color =
true;
85 use_vertex_texture_coord =
true;
87 use_halfedge_texture_coord =
true;
89 use_face_material =
true;
91 use_mesh_materials =
true;
93 long vertex_index = 0;
94 std::map< vertex_descriptor, long >
101 auto point_pm =
get(boost::vertex_point, g);
104 for(vertex_iterator it_v = v_range.begin(); it_v != v_range.end(); ++it_v)
107 std::vector< coordP_type > point;
109 point.push_back(p[0]);
110 point.push_back(p[1]);
111 point.push_back(p[2]);
113 mvr.points_coords.push_back(point);
115 index_map[*it_v] = vertex_index;
120 if(use_vertex_normal)
124 auto vn =
get(vn_pm, *it_v);
125 std::vector< coordN_type > normal;
126 normal.push_back(vn[0]);
127 normal.push_back(vn[1]);
128 normal.push_back(vn[2]);
129 mvr.normals_coords.push_back(normal);
136 auto vc =
get(vc_pm, *it_v);
137 std::vector< coordC_type > color;
138 color.push_back(
static_cast< coordC_type
>(vc[0]));
139 color.push_back(
static_cast< coordC_type
>(vc[1]));
140 color.push_back(
static_cast< coordC_type
>(vc[2]));
141 mvr.vertex_color_coords.push_back(color);
144 if(use_vertex_texture_coord)
148 auto vt =
get(vt_pm, *it_v);
151 std::vector< coordT_type > uvi;
152 uvi.push_back(
static_cast< coordT_type
>(vt[0]));
153 uvi.push_back(
static_cast< coordT_type
>(vt[1]));
154 mvr.texture_coords.push_back(uvi);
161 face_range f_range =
faces(g);
162 for(face_iterator it_f = f_range.begin(); it_f != f_range.end(); ++it_f)
164 std::vector< index_type >
face;
165 std::vector< index_type > normal_indices;
166 std::vector< index_type > texture_indices;
169 halfedge_descriptor h =
halfedge(*it_f, g);
172 unsigned int face_vertices_nbr = 0;
181 if(use_vertex_normal)
182 normal_indices.push_back(index_map[v]);
183 if(use_vertex_texture_coord)
184 texture_indices.push_back(index_map[v]);
185 else if(use_halfedge_texture_coord)
189 auto ht =
get(ht_pm, h);
194 std::vector< coordT_type > uvi;
195 uvi.push_back(
static_cast< coordT_type
>(ht[0]));
196 uvi.push_back(
static_cast< coordT_type
>(ht[1]));
197 mvr.texture_coords.push_back(uvi);
200 texture_indices.push_back(
201 static_cast< index_type
>(mvr.texture_coords.size() - 1));
207 }
while(v != vbegin);
214 auto fn =
get(fn_pm, *it_f);
217 std::vector< coordN_type > normal;
218 normal.push_back(fn[0]);
219 normal.push_back(fn[1]);
220 normal.push_back(fn[2]);
221 mvr.normals_coords.push_back(normal);
224 for(
unsigned int i = 0; i < face_vertices_nbr; i++)
225 normal_indices.push_back(
226 static_cast< index_type
>(mvr.normals_coords.size() - 1));
229 mvr.faces_indices.push_back(
face);
230 if(use_vertex_normal || use_face_normal)
231 mvr.normal_face_indices.push_back(normal_indices);
232 if(use_vertex_texture_coord || use_halfedge_texture_coord)
233 mvr.texture_face_indices.push_back(texture_indices);
243 std::vector< coordC_type > color;
244 color.push_back(
static_cast< coordC_type
>(fc[0]));
245 color.push_back(
static_cast< coordC_type
>(fc[1]));
246 color.push_back(
static_cast< coordC_type
>(fc[2]));
247 mvr.face_color_coords.push_back(color);
251 if(use_face_material)
255 auto material_id =
get(fm_pm, *it_f);
258 mvr.face_material.push_back(material_id);
264 if(use_mesh_materials)
268 auto it = mm_pm.storage_begin();
269 auto it_end = mm_pm.storage_end();
270 for(; it != it_end; ++it)
271 mvr.materials.push_back(*it);
285 template<
typename FaceListGraph,
286 typename coordP_type,
287 typename coordN_type,
288 typename coordT_type,
289 typename coordC_type,
301 GeometryTraits gt(g);