30 bool writeMesh(Mesh &mesh, mds::mod::CChannel& channel,
Options opt)
32 using namespace OpenMesh::IO;
33 opt += Options::Default;
34 opt += Options::Binary;
35 opt += Options::ColorAlpha;
37 if (mesh.has_edge_colors())
38 opt += Options::EdgeColor;
39 if (mesh.has_face_colors())
40 opt += Options::FaceColor;
41 if (mesh.has_face_normals())
42 opt += Options::FaceNormal;
43 if (mesh.has_vertex_colors())
44 opt += Options::VertexColor;
45 if (mesh.has_vertex_normals())
46 opt += Options::VertexNormal;
62 bool writeMesh( Mesh &mesh, std::string filename,
Options opt)
64 using namespace OpenMesh::IO;
65 opt += Options::Default;
66 opt += Options::Binary;
67 opt += Options::ColorAlpha;
69 if (mesh.has_edge_colors())
70 opt += Options::EdgeColor;
71 if (mesh.has_face_colors())
72 opt += Options::FaceColor;
73 if (mesh.has_face_normals())
74 opt += Options::FaceNormal;
75 if (mesh.has_vertex_colors())
76 opt += Options::VertexColor;
77 if (mesh.has_vertex_normals())
78 opt += Options::VertexNormal;
80 return write_mesh(mesh, filename, opt);
95 bool writeMesh (Mesh &mesh, std::ostream& stream, std::string format,
Options opt)
97 using namespace OpenMesh::IO;
98 opt += Options::Default;
99 opt += Options::Binary;
100 opt += Options::ColorAlpha;
102 if (mesh.has_edge_colors())
103 opt += Options::EdgeColor;
104 if (mesh.has_face_colors())
105 opt += Options::FaceColor;
106 if (mesh.has_face_normals())
107 opt += Options::FaceNormal;
108 if (mesh.has_vertex_colors())
109 opt += Options::VertexColor;
110 if (mesh.has_vertex_normals())
111 opt += Options::VertexNormal;
113 return write_mesh(mesh, stream, format, opt);
125 bool readMesh(Mesh &mesh, mds::mod::CChannel& channel,
Options& opt)
127 using namespace OpenMesh::IO;
128 opt += Options::Default;
129 opt += Options::Binary;
130 opt += Options::ColorAlpha;
131 opt += Options::EdgeColor;
132 opt += Options::FaceColor;
133 opt += Options::FaceNormal;
134 opt += Options::VertexColor;
135 opt += Options::VertexNormal;
136 opt += Options::VertexTexCoord;
150 bool readMesh(Mesh &mesh, std::string filename,
Options& opt)
152 opt += Options::Default;
153 opt += Options::Binary;
154 opt += Options::ColorAlpha;
156 if (mesh.has_edge_colors())
157 opt += Options::EdgeColor;
158 if (mesh.has_face_colors())
159 opt += Options::FaceColor;
160 if (mesh.has_face_normals())
161 opt += Options::FaceNormal;
162 if (mesh.has_vertex_colors())
163 opt += Options::VertexColor;
164 if (mesh.has_vertex_normals())
165 opt += Options::VertexNormal;
167 return read_mesh(mesh, filename, opt);
180 bool readMesh(Mesh &mesh, std::istream& stream, std::string format,
Options& opt)
182 opt += Options::Default;
183 opt += Options::Binary;
184 opt += Options::ColorAlpha;
186 if (mesh.has_edge_colors())
187 opt += Options::EdgeColor;
188 if (mesh.has_face_colors())
189 opt += Options::FaceColor;
190 if (mesh.has_face_normals())
191 opt += Options::FaceNormal;
192 if (mesh.has_vertex_colors())
193 opt += Options::VertexColor;
194 if (mesh.has_vertex_normals())
195 opt += Options::VertexNormal;
197 return read_mesh(mesh, stream, format, opt);
214 template <
class Mesh,
typename Scalar>
215 bool exportVertices(Mesh &mesh, Scalar *output_array,
bool normals)
217 if (output_array == NULL || (normals && !mesh.has_vertex_normals()))
return false;
219 Mesh::VertexIter end = mesh.vertices_end();
220 Scalar *current_pointer = output_array;
221 Mesh::Point pointCoords;
222 Mesh::Normal normalCoords;
223 for (Mesh::VertexIter vertex = mesh.vertices_begin(); vertex != end; ++vertex)
225 pointCoords = mesh.point(vertex);
226 *(current_pointer) = pointCoords[0];
227 *(current_pointer+1) = pointCoords[1];
228 *(current_pointer+2) = pointCoords[2];
232 normalCoords = mesh.normal(vertex);
233 *(current_pointer+4) = normalCoords[0];
234 *(current_pointer+5) = normalCoords[1];
235 *(current_pointer+6) = normalCoords[2];
236 current_pointer += 8;
240 current_pointer += 4;
258 template <
class Mesh>
259 static bool exportFaces(Mesh &mesh,
int *output_array)
261 if (output_array == NULL)
return false;
263 Mesh::FaceIter end = mesh.faces_end();
264 int *current_pointer = output_array;
266 for (Mesh::FaceIter face = mesh.faces_begin(); face != end; ++face)
268 for (Mesh::FVIter vertex = mesh.fv_begin(face); vertex; ++vertex)
270 *(current_pointer) = vertex.handle().idx();
292 template <
class Mesh,
typename Scalar>
293 static bool importVertices(Mesh &mesh, Scalar *input_array,
int size,
bool normals)
295 if (input_array == NULL)
return false;
296 if (!mesh.has_vertex_normals()) mesh.request_vertex_normals();
298 Scalar *current_pointer = input_array;
299 Mesh::VertexHandle aux;
300 for (
int i = 0; i < size; ++i)
302 aux = mesh.add_vertex(Mesh::Point( *(current_pointer),
303 *(current_pointer+1),
304 *(current_pointer+2)));
308 mesh.set_normal(aux, Mesh::Normal( *(current_pointer+3),
309 *(current_pointer+4),
310 *(current_pointer+5)));
311 current_pointer += 6;
315 current_pointer += 3;
332 template <
class Mesh>
333 static bool importFaces(Mesh &mesh,
int *input_array,
int size)
335 if (input_array == NULL)
return false;
337 int *current_pointer = input_array;
338 Mesh::VertexHandle vertex[3];
339 for (
int i = 0; i < size; ++i)
341 vertex[0] = mesh.vertex_handle(*(current_pointer));
342 vertex[1] = mesh.vertex_handle(*(current_pointer+1));
343 vertex[2] = mesh.vertex_handle(*(current_pointer+2));
345 mesh.add_face(vertex[0], vertex[1], vertex[2]);
346 current_pointer += 3;