OpenMesh
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
InputOutput.hh
1 #ifndef OPENMESH_PYTHON_INPUTOUTPUT_HH
2 #define OPENMESH_PYTHON_INPUTOUTPUT_HH
3 
4 #include "Python/Bindings.hh"
5 
6 namespace OpenMesh {
7 namespace Python {
8 
9 const IO::Options::Flag FLAG_DEFAULT = IO::Options::Default;
10 const IO::Options::Flag FLAG_BINARY = IO::Options::Binary;
11 const IO::Options::Flag FLAG_MSB = IO::Options::MSB;
12 const IO::Options::Flag FLAG_LSB = IO::Options::LSB;
13 const IO::Options::Flag FLAG_SWAP = IO::Options::Swap;
14 const IO::Options::Flag FLAG_VERTEXNORMAL = IO::Options::VertexNormal;
15 const IO::Options::Flag FLAG_VERTEXCOLOR = IO::Options::VertexColor;
16 const IO::Options::Flag FLAG_VERTEXTEXCOORD = IO::Options::VertexTexCoord;
17 const IO::Options::Flag FLAG_EDGECOLOR = IO::Options::EdgeColor;
18 const IO::Options::Flag FLAG_FACENORMAL = IO::Options::FaceNormal;
19 const IO::Options::Flag FLAG_FACECOLOR = IO::Options::FaceColor;
20 const IO::Options::Flag FLAG_FACETEXCOORD = IO::Options::FaceTexCoord;
21 const IO::Options::Flag FLAG_COLORALPHA = IO::Options::ColorAlpha;
22 const IO::Options::Flag FLAG_COLORFLOAT = IO::Options::ColorFloat;
23 
24 BOOST_PYTHON_FUNCTION_OVERLOADS(read_mesh_overloads, IO::read_mesh, 3, 4)
25 BOOST_PYTHON_FUNCTION_OVERLOADS(write_mesh_overloads, IO::write_mesh, 2, 4)
26 
30 void expose_io() {
31 
32  //======================================================================
33  // Functions
34  //======================================================================
35 
36  bool (*read_mesh_poly )(PolyMesh&, const std::string& ) = &IO::read_mesh;
37  bool (*read_mesh_poly_options)(PolyMesh&, const std::string&, IO::Options&, bool) = &IO::read_mesh;
38  bool (*read_mesh_tri )(TriMesh&, const std::string& ) = &IO::read_mesh;
39  bool (*read_mesh_tri_options )(TriMesh&, const std::string&, IO::Options&, bool) = &IO::read_mesh;
40 
41  bool (*write_mesh_poly)(const PolyMesh&, const std::string&, IO::Options, std::streamsize) = &IO::write_mesh;
42  bool (*write_mesh_tri )(const TriMesh&, const std::string&, IO::Options, std::streamsize) = &IO::write_mesh;
43 
44  def("read_mesh", read_mesh_poly);
45  def("read_mesh", read_mesh_poly_options, read_mesh_overloads());
46  def("read_mesh", read_mesh_tri);
47  def("read_mesh", read_mesh_tri_options, read_mesh_overloads());
48 
49  def("write_mesh", write_mesh_poly, write_mesh_overloads());
50  def("write_mesh", write_mesh_tri, write_mesh_overloads());
51 
52  //======================================================================
53  // Options
54  //======================================================================
55 
56  scope scope_options = class_<IO::Options>("Options")
57  .def(init<IO::Options::Flag>())
58  .def("cleanup", &IO::Options::cleanup)
59  .def("clear", &IO::Options::clear)
60  .def("is_empty", &IO::Options::is_empty)
61  .def("check", &IO::Options::check)
62  .def("is_binary", &IO::Options::is_binary)
63  .def("vertex_has_normal", &IO::Options::vertex_has_normal)
64  .def("vertex_has_color", &IO::Options::vertex_has_color)
65  .def("vertex_has_texcoord", &IO::Options::vertex_has_texcoord)
66  .def("edge_has_color", &IO::Options::edge_has_color)
67  .def("face_has_normal", &IO::Options::face_has_normal)
68  .def("face_has_color", &IO::Options::face_has_color)
69  .def("face_has_texcoord", &IO::Options::face_has_texcoord)
70  .def("color_has_alpha", &IO::Options::color_has_alpha)
71  .def("color_is_float", &IO::Options::color_is_float)
72 
73  .def(self == self)
74  .def(self != self)
75  .def(self -= IO::Options::Flag())
76  .def(self += IO::Options::Flag())
77 
78  .def_readonly("Default", &FLAG_DEFAULT)
79  .def_readonly("Binary", &FLAG_BINARY)
80  .def_readonly("MSB", &FLAG_MSB)
81  .def_readonly("LSB", &FLAG_LSB)
82  .def_readonly("Swap", &FLAG_SWAP)
83  .def_readonly("VertexNormal", &FLAG_VERTEXNORMAL)
84  .def_readonly("VertexColor", &FLAG_VERTEXCOLOR)
85  .def_readonly("VertexTexCoord", &FLAG_VERTEXTEXCOORD)
86  .def_readonly("EdgeColor", &FLAG_EDGECOLOR)
87  .def_readonly("FaceNormal", &FLAG_FACENORMAL)
88  .def_readonly("FaceColor", &FLAG_FACECOLOR)
89  .def_readonly("FaceTexCoord", &FLAG_FACETEXCOORD)
90  .def_readonly("ColorAlpha", &FLAG_COLORALPHA)
91  .def_readonly("ColorFloat", &FLAG_COLORFLOAT)
92  ;
93 
94  enum_<IO::Options::Flag>("Flag")
95  .value("Default", IO::Options::Default)
96  .value("Binary", IO::Options::Binary)
97  .value("MSB", IO::Options::MSB)
98  .value("LSB", IO::Options::LSB)
99  .value("Swap", IO::Options::Swap)
100  .value("VertexNormal", IO::Options::VertexNormal)
101  .value("VertexColor", IO::Options::VertexColor)
102  .value("VertexTexCoord", IO::Options::VertexTexCoord)
103  .value("EdgeColor", IO::Options::EdgeColor)
104  .value("FaceNormal", IO::Options::FaceNormal)
105  .value("FaceColor", IO::Options::FaceColor)
106  .value("FaceTexCoord", IO::Options::FaceTexCoord)
107  .value("ColorAlpha", IO::Options::ColorAlpha)
108  .value("ColorFloat", IO::Options::ColorFloat)
109  ;
110 }
111 
112 } // namespace OpenMesh
113 } // namespace Python
114 
115 #endif
Has (r) / store (w) face colors.
Definition: Options.hh:114
Has (r) / store (w) edge colors.
Definition: Options.hh:112
Set options for reader/writer modules.
Definition: Options.hh:95
bool read_mesh(Mesh &_mesh, const std::string &_filename)
Read a mesh from file _filename.
Definition: MeshIO.hh:104
Has (r) / store (w) float values for colors (currently only implemented for PLY and OFF files) ...
Definition: Options.hh:117
bool is_empty(void) const
Returns true if all bits are zero.
Definition: Options.hh:155
Assume big endian byte ordering.
Definition: Options.hh:106
Has (r) / store (w) face normals.
Definition: Options.hh:113
Has (r) / store (w) vertex normals.
Definition: Options.hh:109
Has (r) / store (w) texture coordinates.
Definition: Options.hh:111
No options.
Definition: Options.hh:104
void clear(void)
Clear all bits.
Definition: Options.hh:151
Swap byte order in binary mode.
Definition: Options.hh:108
void expose_io()
Expose the input/output functions and options to Python.
Definition: InputOutput.hh:30
Triangle mesh based on the ArrayKernel.
Definition: TriMesh_ArrayKernelT.hh:98
Has (r) / store (w) face texture coordinates.
Definition: Options.hh:115
Polygonal mesh based on the ArrayKernel.
Definition: PolyMesh_ArrayKernelT.hh:98
void cleanup(void)
Restore state after default constructor.
Definition: Options.hh:147
Set binary mode for r/w.
Definition: Options.hh:105
Assume little endian byte ordering.
Definition: Options.hh:107
Flag
Definitions of Options for reading and writing.
Definition: Options.hh:103
Has (r) / store (w) alpha values for colors.
Definition: Options.hh:116
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:64
bool write_mesh(const Mesh &_mesh, const std::string &_filename, Options _opt=Options::Default, std::streamsize _precision=6)
Write a mesh to the file _filename.
Definition: MeshIO.hh:199
Has (r) / store (w) vertex colors.
Definition: Options.hh:110

Project OpenMesh, ©  Computer Graphics Group, RWTH Aachen. Documentation generated using doxygen .