Commit 89f4ed30 authored by Alexander Dielen's avatar Alexander Dielen

replaced options class with parameters of the read/write functions

parent bce9a3af
...@@ -6,83 +6,179 @@ ...@@ -6,83 +6,179 @@
namespace OM = OpenMesh; namespace OM = OpenMesh;
/** template <class Mesh>
* Expose the input/output functions and options to Python. void def_read_mesh(py::module& m, const char *_name) {
*/ m.def(_name,
void expose_io(py::module& m) { [](
const std::string& _filename,
bool _binary,
bool _msb,
bool _lsb,
bool _swap,
bool _vertex_normal,
bool _vertex_color,
bool _vertex_tex_coord,
bool _edge_color,
bool _face_normal,
bool _face_color,
bool _face_tex_coord,
bool _color_alpha,
bool _color_float
)
{
Mesh mesh;
OM::IO::Options options;
if (_binary) options += OM::IO::Options::Binary;
if (_msb) options += OM::IO::Options::MSB;
if (_lsb) options += OM::IO::Options::LSB;
if (_swap) options += OM::IO::Options::Swap;
if (_vertex_normal) {
options += OM::IO::Options::VertexNormal;
mesh.request_vertex_normals();
}
if (_vertex_color) {
options += OM::IO::Options::VertexColor;
mesh.request_vertex_colors();
}
if (_vertex_tex_coord) {
options += OM::IO::Options::VertexTexCoord;
// TODO request only one property
mesh.request_vertex_texcoords1D();
mesh.request_vertex_texcoords2D();
mesh.request_vertex_texcoords3D();
}
if (_edge_color) {
options += OM::IO::Options::EdgeColor;
mesh.request_edge_colors();
}
if (_face_normal) {
options += OM::IO::Options::FaceNormal;
mesh.request_face_normals();
}
if (_face_color) {
options += OM::IO::Options::FaceColor;
mesh.request_face_colors();
}
if (_face_tex_coord) options += OM::IO::Options::FaceTexCoord;
if (_color_alpha) options += OM::IO::Options::ColorAlpha;
if (_color_float) options += OM::IO::Options::ColorFloat;
OM::IO::read_mesh(mesh,_filename, options);
if (_vertex_normal && !options.vertex_has_normal()) {
PyErr_SetString(PyExc_RuntimeError, "Vertex normals could not be read.");
throw py::error_already_set();
}
if (_vertex_color && !options.vertex_has_color()) {
PyErr_SetString(PyExc_RuntimeError, "Vertex colors could not be read.");
throw py::error_already_set();
}
if (_vertex_tex_coord && !options.vertex_has_texcoord()) {
PyErr_SetString(PyExc_RuntimeError, "Vertex texcoords could not be read.");
throw py::error_already_set();
}
if (_edge_color && !options.edge_has_color()) {
PyErr_SetString(PyExc_RuntimeError, "Edge colors could not be read.");
throw py::error_already_set();
}
if (_face_normal && !options.face_has_normal()) {
PyErr_SetString(PyExc_RuntimeError, "Face normals could not be read.");
throw py::error_already_set();
}
if (_face_color && !options.face_has_color()) {
PyErr_SetString(PyExc_RuntimeError, "Face colors could not be read.");
throw py::error_already_set();
}
if (_face_tex_coord && !options.face_has_texcoord()) {
PyErr_SetString(PyExc_RuntimeError, "Face texcoords could not be read.");
throw py::error_already_set();
}
return mesh;
},
py::arg("filename"),
py::arg("binary")=false,
py::arg("msb")=false,
py::arg("lsb")=false,
py::arg("swap")=false,
py::arg("vertex_normal")=false,
py::arg("vertex_color")=false,
py::arg("vertex_tex_coord")=false,
py::arg("edge_color")=false,
py::arg("face_normal")=false,
py::arg("face_color")=false,
py::arg("face_tex_coord")=false,
py::arg("color_alpha")=false,
py::arg("color_float")=false
);
}
//====================================================================== template <class Mesh>
// Options void def_write_mesh(py::module& m) {
//====================================================================== m.def("write_mesh",
[](
py::class_<OM::IO::Options> class_options(m, "Options"); const std::string& _filename,
const Mesh& _mesh,
class_options bool _binary,
.def(py::init<>()) bool _msb,
.def(py::init<OM::IO::Options::Flag>()) bool _lsb,
.def("cleanup", &OM::IO::Options::cleanup) bool _swap,
.def("clear", &OM::IO::Options::clear) bool _vertex_normal,
.def("is_empty", &OM::IO::Options::is_empty) bool _vertex_color,
.def("check", &OM::IO::Options::check) bool _vertex_tex_coord,
.def("is_binary", &OM::IO::Options::is_binary) bool _edge_color,
.def("vertex_has_normal", &OM::IO::Options::vertex_has_normal) bool _face_normal,
.def("vertex_has_color", &OM::IO::Options::vertex_has_color) bool _face_color,
.def("vertex_has_texcoord", &OM::IO::Options::vertex_has_texcoord) bool _face_tex_coord,
.def("edge_has_color", &OM::IO::Options::edge_has_color) bool _color_alpha,
.def("face_has_normal", &OM::IO::Options::face_has_normal) bool _color_float
.def("face_has_color", &OM::IO::Options::face_has_color) )
.def("face_has_texcoord", &OM::IO::Options::face_has_texcoord) {
.def("color_has_alpha", &OM::IO::Options::color_has_alpha) OM::IO::Options options;
.def("color_is_float", &OM::IO::Options::color_is_float)
if (_binary) options += OM::IO::Options::Binary;
.def(py::self == py::self) if (_msb) options += OM::IO::Options::MSB;
.def(py::self != py::self) if (_lsb) options += OM::IO::Options::LSB;
.def(py::self -= OM::IO::Options::Flag()) if (_swap) options += OM::IO::Options::Swap;
.def(py::self += OM::IO::Options::Flag())
; if (_vertex_normal) options += OM::IO::Options::VertexNormal;
if (_vertex_color) options += OM::IO::Options::VertexColor;
py::enum_<OM::IO::Options::Flag>(class_options, "Flag", py::arithmetic()) if (_vertex_tex_coord) options += OM::IO::Options::VertexTexCoord;
.value("Default", OM::IO::Options::Default) if (_edge_color) options += OM::IO::Options::EdgeColor;
.value("Binary", OM::IO::Options::Binary) if (_face_normal) options += OM::IO::Options::FaceNormal;
.value("MSB", OM::IO::Options::MSB) if (_face_color) options += OM::IO::Options::FaceColor;
.value("LSB", OM::IO::Options::LSB)
.value("Swap", OM::IO::Options::Swap) if (_face_tex_coord) options += OM::IO::Options::FaceTexCoord;
.value("VertexNormal", OM::IO::Options::VertexNormal) if (_color_alpha) options += OM::IO::Options::ColorAlpha;
.value("VertexColor", OM::IO::Options::VertexColor) if (_color_float) options += OM::IO::Options::ColorFloat;
.value("VertexTexCoord", OM::IO::Options::VertexTexCoord)
.value("EdgeColor", OM::IO::Options::EdgeColor) OM::IO::write_mesh(_mesh, _filename, options);
.value("FaceNormal", OM::IO::Options::FaceNormal) },
.value("FaceColor", OM::IO::Options::FaceColor) py::arg("filename"),
.value("FaceTexCoord", OM::IO::Options::FaceTexCoord) py::arg("mesh"),
.value("ColorAlpha", OM::IO::Options::ColorAlpha) py::arg("binary")=false,
.value("ColorFloat", OM::IO::Options::ColorFloat) py::arg("msb")=false,
.export_values() py::arg("lsb")=false,
; py::arg("swap")=false,
py::arg("vertex_normal")=false,
//====================================================================== py::arg("vertex_color")=false,
// Functions py::arg("vertex_tex_coord")=false,
//====================================================================== py::arg("edge_color")=false,
py::arg("face_normal")=false,
bool (*read_mesh_poly )(PolyMesh&, const std::string& ) = &OM::IO::read_mesh; py::arg("face_color")=false,
bool (*read_mesh_poly_options)(PolyMesh&, const std::string&, OM::IO::Options&, bool) = &OM::IO::read_mesh; py::arg("face_tex_coord")=false,
bool (*read_mesh_tri )(TriMesh&, const std::string& ) = &OM::IO::read_mesh; py::arg("color_alpha")=false,
bool (*read_mesh_tri_options )(TriMesh&, const std::string&, OM::IO::Options&, bool) = &OM::IO::read_mesh; py::arg("color_float")=false
);
bool (*write_mesh_poly)(const PolyMesh&, const std::string&, OM::IO::Options, std::streamsize) = &OM::IO::write_mesh; }
bool (*write_mesh_tri )(const TriMesh&, const std::string&, OM::IO::Options, std::streamsize) = &OM::IO::write_mesh;
void expose_io(py::module& m) {
m.def("read_mesh", read_mesh_poly); def_read_mesh<TriMesh>(m, "read_trimesh");
m.def("read_mesh", read_mesh_poly_options, def_read_mesh<PolyMesh>(m, "read_polymesh");
py::arg("mesh"), py::arg("filename"), py::arg("opt"), py::arg("clear")=true); def_write_mesh<TriMesh>(m);
m.def("read_mesh", read_mesh_tri); def_write_mesh<PolyMesh>(m);
m.def("read_mesh", read_mesh_tri_options,
py::arg("mesh"), py::arg("filename"), py::arg("opt"), py::arg("clear")=true);
m.def("write_mesh", write_mesh_poly,
py::arg("mesh"), py::arg("filename"),
py::arg("opt")=OM::IO::Options(), py::arg("precision")=6);
m.def("write_mesh", write_mesh_tri,
py::arg("mesh"), py::arg("filename"),
py::arg("opt")=OM::IO::Options(), py::arg("precision")=6);
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment