Developer Documentation

properties.cc
1 #include <iostream>
2 // --------------------
3 #include <OpenMesh/Core/IO/MeshIO.hh>
4 #include <OpenMesh/Core/Mesh/TriMesh_ArrayKernelT.hh>
5
6
7 typedef OpenMesh::TriMesh_ArrayKernelT<> MyMesh;
8
9
10 int main(int argc, char **argv)
11 {
12 MyMesh mesh;
13
14 if (argc!=2)
15 {
16 std::cerr << "Usage: " << argv[0] << " <input>\n";
17 return 1;
18 }
19
20 // request vertex normals, so the mesh reader can use normal information
21 // if available
22 mesh.request_vertex_normals();
23
24 // assure we have vertex normals
25 if (!mesh.has_vertex_normals())
26 {
27 std::cerr << "ERROR: Standard vertex property 'Normals' not available!\n";
28 return 1;
29 }
30
31 OpenMesh::IO::Options opt;
32 if ( ! OpenMesh::IO::read_mesh(mesh,argv[1], opt))
33 {
34 std::cerr << "Error loading mesh from file " << argv[1] << std::endl;
35 return 1;
36 }
37
38 // If the file did not provide vertex normals, then calculate them
39 if ( !opt.check( OpenMesh::IO::Options::VertexNormal ) )
40 {
41 // we need face normals to update the vertex normals
42 mesh.request_face_normals();
43
44 // let the mesh update the normals
45 mesh.update_normals();
46
47 // dispose the face normals, as we don't need them anymore
48 mesh.release_face_normals();
49 }
50
51 // move all vertices one unit length along it's normal direction
52 for (MyMesh::VertexIter v_it = mesh.vertices_begin();
53 v_it != mesh.vertices_end(); ++v_it)
54 {
55 std::cout << "Vertex #" << *v_it << ": " << mesh.point( *v_it );
56 mesh.set_point( *v_it, mesh.point(*v_it)+mesh.normal(*v_it) );
57 std::cout << " moved to " << mesh.point( *v_it ) << std::endl;
58 }
59
60 // don't need the normals anymore? Remove them!
61 mesh.release_vertex_normals();
62
63 // just check if it really works
64 if (mesh.has_vertex_normals())
65 {
66 std::cerr << "Ouch! ERROR! Shouldn't have any vertex normals anymore!\n";
67 return 1;
68 }
69
70 return 0;
71 }
OpenMesh::TriMesh_ArrayKernelT
Definition: PolyMesh_ArrayKernelT.hh:73
OpenMesh::IO::Options
Set options for reader/writer modules.
Definition: Options.hh:90
OpenMesh::IO::Options::VertexNormal
Has (r) / store (w) vertex normals.
Definition: Options.hh:104
OpenMesh::IO::read_mesh
bool read_mesh(Mesh &_mesh, const std::string &_filename)
Read a mesh from file _filename.
Definition: MeshIO.hh:112
OpenMesh::PolyMeshT::update_normals
void update_normals()
Compute normals for all primitives.
Definition: PolyMeshT_impl.hh:259