Developer Documentation

attributes.cc
1 #include <iostream>
2 #include <typeinfo>
3 // --------------------
4 #include <OpenMesh/Core/IO/MeshIO.hh>
5
6 #include <OpenMesh/Core/Mesh/TriMesh_ArrayKernelT.hh>
7 #include <OpenMesh/Core/Geometry/VectorT.hh>
8
9 #ifndef DOXY_IGNORE_THIS
10
11 // Define my personal traits
12 struct MyTraits : OpenMesh::DefaultTraits
13 {
14 // Let Point and Normal be a vector of doubles
15 typedef OpenMesh::Vec3d Point;
16 typedef OpenMesh::Vec3d Normal;
17
18 // Already defined in OpenMesh::DefaultTraits
19 // HalfedgeAttributes( OpenMesh::Attributes::PrevHalfedge );
20
21 // Uncomment next line to disable attribute PrevHalfedge
22 // HalfedgeAttributes( OpenMesh::Attributes::None );
23 //
24 // or
25 //
26 // HalfedgeAttributes( 0 );
27 };
28
29 #endif
30
31 // Define my mesh with the new traits!
32 typedef OpenMesh::TriMesh_ArrayKernelT<MyTraits> MyMesh;
33
34 // ------------------------------------------------------------------ main ----
35
36 int main(int argc, char **argv)
37 {
38 MyMesh mesh;
39
40 if (argc!=2)
41 {
42 std::cerr << "Usage: " << argv[0] << " <input>\n";
43 return 1;
44 }
45
46 // Just make sure that point element type is double
47 if ( typeid( OpenMesh::vector_traits<MyMesh::Point>::value_type )
48 != typeid(double) )
49 {
50 std::cerr << "Ouch! ERROR! Data type is wrong!\n";
51 return 1;
52 }
53
54 // Make sure that normal element type is double
55 if ( typeid( OpenMesh::vector_traits<MyMesh::Normal>::value_type )
56 != typeid(double) )
57 {
58 std::cerr << "Ouch! ERROR! Data type is wrong!\n";
59 return 1;
60 }
61
62 // Add vertex normals as default property (ref. previous tutorial)
63 mesh.request_vertex_normals();
64
65 // Add face normals as default property
66 mesh.request_face_normals();
67
68 // load a mesh
69 OpenMesh::IO::Options opt;
70 if ( ! OpenMesh::IO::read_mesh(mesh,argv[1], opt))
71 {
72 std::cerr << "Error loading mesh from file " << argv[1] << std::endl;
73 return 1;
74 }
75
76 // If the file did not provide vertex normals, then calculate them
77 if ( !opt.check( OpenMesh::IO::Options::VertexNormal ) &&
78 mesh.has_face_normals() && mesh.has_vertex_normals() )
79 {
80 // let the mesh update the normals
81 mesh.update_normals();
82 }
83
84 // move all vertices one unit length along it's normal direction
85 for (MyMesh::VertexIter v_it = mesh.vertices_begin();
86 v_it != mesh.vertices_end(); ++v_it)
87 {
88 std::cout << "Vertex #" << *v_it << ": " << mesh.point( *v_it );
89 mesh.set_point( *v_it, mesh.point(*v_it)+mesh.normal(*v_it) );
90 std::cout << " moved to " << mesh.point( *v_it ) << std::endl;
91 }
92
93 return 0;
94 }
OpenMesh::TriMesh_ArrayKernelT
Definition: PolyMesh_ArrayKernelT.hh:73
OpenMesh::VectorT
Definition: Vector11T.hh:83
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:317
OpenMesh::IO::Options
Set options for reader/writer modules.
Definition: Options.hh:90
MyTraits
Definition: mymesh.cc:5
OpenMesh::IO::Options::VertexNormal
Has (r) / store (w) vertex normals.
Definition: Options.hh:104
OpenMesh::DefaultTraits
Definition: Traits.hh:121
OpenMesh::vector_traits::value_type
T::value_type value_type
Type of the scalar value.
Definition: vector_traits.hh:94