OMToolkit  1.0
The polygonal mesh processing tool.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
OMDirectionsGeo.hxx
Go to the documentation of this file.
1 //#include <osg/MatrixTransform>
2 //#include <osg/Projection>
3 
4 //==============================================================================
17 #ifndef _OM_DIRECTIONS_GEO_HXX_
18 #define _OM_DIRECTIONS_GEO_HXX_
19 
21 // Constructor
22 // Creates an instance of this class by drawing vectors specified by handle from each vertex
23 // @param mesh Mesh to work with
24 // @param handle Handle to vector vertex property
25 // @param norm Lenght of showed distances
26 // @param defaultColor Default color of visualised normal
28 template <class Mesh, class Vector>
29 OMDirectionsGeometry<Mesh, Vector>::OMDirectionsGeometry(Mesh &mesh, OpenMesh::VPropHandleT<Vector> handle, ScalarT norm, Vec4f defaultColor)
30 {
31  ref_ptr<Vec3Array> vertices = new Vec3Array();
32  DrawElementsUInt *indices =new DrawElementsUInt(PrimitiveSet::LINES, 0);
33  ref_ptr<Vec4Array> colors = new Vec4Array();
34 
35  Mesh::Normal normal;
36  Mesh::VertexIter end = mesh.vertices_end();
37  Mesh::Point point;
38  unsigned int i = 0;
39  // pass each vertex and add two points and line
40  for (Mesh::VertexIter it = mesh.vertices_begin(); it != end; ++it)
41  {
42  point = mesh.point(it);
43  normal = mesh.property(handle, it);
44  normal *= norm;
45  vertices->push_back(Vec3(point[0], point[1], point[2]));
46  vertices->push_back(Vec3(normal[0]+point[0], normal[1]+point[1], normal[2]+point[2]));
47 
48  indices->push_back(i);
49  indices->push_back(i+1);
50 
51  i+=2;
52  }
53 
54  colors->push_back(defaultColor);
55  setColorArray(colors);
56  setColorBinding(Geometry::BIND_PER_PRIMITIVE_SET);
57  getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
58  setVertexArray(vertices);
59  addPrimitiveSet(indices);
60 }
61 
63 // Constructor
64 // Creates an instance of this class by drawing vectors specified by handle from each face
65 // @param mesh Mesh to work with
66 // @param handle Handle to vector vertex property
67 // @param norm Lenght of showed distances
68 // @param defaultColor Default color of visualised normal
70 template <class Mesh, class Vector>
71 OMDirectionsGeometry<Mesh, Vector>::OMDirectionsGeometry(Mesh &mesh, OpenMesh::FPropHandleT<Vector> handle, ScalarT norm, Vec4f defaultColor)
72 {
73  ref_ptr<Vec3Array> vertices = new Vec3Array();
74  DrawElementsUInt *indices =new DrawElementsUInt(PrimitiveSet::LINES, 0);
75  ref_ptr<Vec4Array> colors = new Vec4Array();
76 
77  Mesh::Normal normal;
78  Mesh::FaceIter end = mesh.faces_end();
79  Mesh::Point point;
80  unsigned int i = 0;
81 
82  // pass each face and add two points and line
83  for (Mesh::FaceIter it = mesh.faces_begin(); it != end; ++it)
84  {
85  mesh.calc_face_centroid(it, point);
86  normal = mesh.property(handle, it);
87  normal *= norm;
88  vertices->push_back(Vec3(point[0], point[1], point[2]));
89  vertices->push_back(Vec3(normal[0]+point[0], normal[1]+point[1], normal[2]+point[2]));
90 
91  indices->push_back(i);
92  indices->push_back(i+1);
93 
94  i+=2;
95  }
96 
97  colors->push_back(defaultColor);
98  setColorArray(colors);
99  setColorBinding(Geometry::BIND_PER_PRIMITIVE_SET);
100  getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
101  setVertexArray(vertices);
102  addPrimitiveSet(indices);
103 }
104 
105 #endif