4 #include <OpenMesh/Core/IO/MeshIO.hh> 5 #include <OpenMesh/Core/Mesh/TriMesh_ArrayKernelT.hh> 6 #include <OpenMesh/Tools/Utils/getopt.h> 18 #define CHKROPT( Option ) \ 19 std::cout << " provides " << #Option \ 20 << (ropt.check(IO::Options:: Option)?": yes\n":": no\n") 22 #define CHKWOPT( Option ) \ 23 std::cout << " write " << #Option \ 24 << (wopt.check(IO::Options:: Option)?": yes\n":": no\n") 26 #define MESHOPT( msg, tf ) \ 27 std::cout << " " << msg << ": " << ((tf)?"yes\n":"no\n") 31 void parse_commandline(
int _argc,
char **_argv,
MyMesh& _mesh,
34 void usage_and_exit(
int xcode);
38 int main(
int argc,
char **argv)
45 parse_commandline( argc, argv, mesh, ropt, wopt );
51 std::cerr <<
"Error loading mesh from file " << argv[optind] << std::endl;
57 std::cout <<
"File " << argv[optind] << std::endl;
59 std::cout <<
" is binary: " 62 std::cout <<
" byte order: ";
64 std::cout <<
"swapped\n";
66 std::cout <<
"little endian\n";
68 std::cout <<
"big endian\n";
70 std::cout <<
"don't care\n";
72 std::cout <<
" provides VertexNormal" 75 ?
": yes\n":
": no\n");
76 CHKROPT( VertexColor );
77 CHKROPT( VertexTexCoord );
78 CHKROPT( FaceNormal );
84 std::cout <<
"# Vertices: " << mesh.n_vertices() << std::endl;
85 std::cout <<
"# Edges : " << mesh.n_faces() << std::endl;
86 std::cout <<
"# Faces : " << mesh.n_faces() << std::endl;
91 std::cout <<
"Selected write options:\n";
92 std::cout <<
" use binary: " 95 std::cout <<
" byte order: ";
97 std::cout <<
"swapped\n";
99 std::cout <<
"little endian\n";
101 std::cout <<
"big endian\n";
103 std::cout <<
"don't care\n";
105 std::cout <<
" write VertexNormal" 107 CHKWOPT( VertexColor );
108 CHKWOPT( VertexTexCoord );
109 CHKWOPT( FaceNormal );
110 CHKWOPT( FaceColor );
114 std::cout <<
"Mesh supports\n";
115 MESHOPT(
"vertex normals", mesh.has_vertex_normals());
116 MESHOPT(
"vertex colors", mesh.has_vertex_colors());
117 MESHOPT(
"texcoords", mesh.has_vertex_texcoords2D());
118 MESHOPT(
"face normals", mesh.has_face_normals());
119 MESHOPT(
"face colors", mesh.has_face_colors());
123 std::cout <<
"Write mesh to " << argv[optind+1] <<
"..";
126 std::cerr <<
"Error" << std::endl;
127 std::cerr <<
"Possible reasons:\n";
128 std::cerr <<
"1. Chosen format cannot handle an option!\n";
129 std::cerr <<
"2. Mesh does not provide necessary information!\n";
130 std::cerr <<
"3. Or simply cannot open file for writing!\n";
134 std::cout <<
"Ok.\n";
141 void parse_commandline(
int _argc,
char **_argv,
MyMesh& _mesh,
145 while ((c=getopt(_argc, _argv,
"bhsBF:LMSV:X:"))!=-1)
170 for(
size_t i=0; optarg[i]; ++i)
195 for(
size_t i=0; optarg[i]; ++i)
210 for(
size_t i=0; optarg[i]; ++i)
213 case 'f': entity = optarg[i];
break;
216 case 'v': _mesh.request_vertex_normals();
break;
217 case 'f': _mesh.request_face_normals();
break;
222 case 'v': _mesh.request_vertex_colors();
break;
223 case 'f': _mesh.request_face_colors();
break;
228 case 'v': _mesh.request_vertex_texcoords2D();
break;
243 if ( _argc-optind != 2)
250 void usage_and_exit(
int xcode)
252 std::ostream &os = xcode ? std::cerr : std::cout;
254 os <<
"Usage: io_options [Options] <input> <output>\n" 256 os <<
" Read and write a mesh, using OpenMesh::IO::Options\n" 260 os <<
"a) read options\n" 263 <<
"\tAssume input file is a binary file\n" 266 <<
"\tSwap byte order when reading a binary file!\n" 268 os <<
"b) write options\n" 271 <<
"\tWrite binary data\n" 274 <<
"\tSwap byte order, when writing binary data\n" 277 <<
"\tUse MSB/LSB byte ordering, when writing binary data\n" 280 <<
"\tWrite vertex normals, texcoords, and/or colors\n" 283 <<
"\tWrite face normals, and/or colors\n" 285 os <<
"c) Mesh properties\n" 288 <<
"\tRequest vertex property normals|colors|texcoords\n" 291 <<
"\tRequest face property normals|colors\n" Assume little endian byte ordering.
Has (r) / store (w) texture coordinates.
Has (r) / store (w) vertex normals.
Has (r) / store (w) face normals.
bool read_mesh(Mesh &_mesh, const std::string &_filename)
Read a mesh from file _filename.
Set options for reader/writer modules.
Swap byte order in binary mode.
Has (r) / store (w) face colors.
Has (r) / store (w) vertex colors.
Assume big endian byte ordering.
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.