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
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!
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
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
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
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 }
void update_normals()
Compute normals for all primitives.
Definition: PolyMeshT.cc:241
Has (r) / store (w) vertex normals.
Definition: Options.hh:109
T::value_type value_type
Type of the scalar value.
bool read_mesh(Mesh &_mesh, const std::string &_filename)
Read a mesh from file _filename.
Definition: MeshIO.hh:104
Set options for reader/writer modules.
Definition: Options.hh:95