TriangleNormalGenerator.h
Go to the documentation of this file.
1 // This file is a part of the OpenSurgSim project.
2 // Copyright 2013, SimQuest Solutions Inc.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 
16 #ifndef SURGSIM_GRAPHICS_TRIANGLENORMALGENERATOR_H
17 #define SURGSIM_GRAPHICS_TRIANGLENORMALGENERATOR_H
18 
19 #include <osg/NodeVisitor>
20 #include <osg/Geode>
21 #include <osg/Geometry>
22 #include <osg/TriangleIndexFunctor>
23 
24 namespace SurgSim
25 {
26 namespace Graphics
27 {
28 
29 
33 {
34 public:
35 
40  void set(osg::Vec3Array* vertexArray,
41  osg::Vec3Array* normalArray);
42 
45  void normalize();
46 
48  void reset();
49 
54  void operator() (size_t vertexIndex1, size_t vertexIndex2, size_t vertexIndex3);
55 
56 protected:
59 
60 private:
61 
63  osg::ref_ptr<osg::Vec3Array> m_vertexArray;
64 
66  osg::ref_ptr<osg::Vec3Array> m_normalArray;
67 
69  size_t m_size;
70 };
71 
72 osg::TriangleIndexFunctor<TriangleNormalGenerator> createNormalGenerator(
73  osg::Vec3Array* vertexArray,
74  osg::Vec3Array* normalArray);
75 
76 
77 }; // Graphics
78 }; // SurgSim
79 
80 #endif
Definition: DriveElementFromInputBehavior.cpp:27
void reset()
Resets all calculated normals to 0.
Definition: TriangleNormalGenerator.cpp:57
void operator()(size_t vertexIndex1, size_t vertexIndex2, size_t vertexIndex3)
Calculates the triangle normal and adds it to each adjacent vertex normal.
Definition: TriangleNormalGenerator.cpp:66
osg::ref_ptr< osg::Vec3Array > m_vertexArray
Array containing vertex positions.
Definition: TriangleNormalGenerator.h:63
size_t m_size
Size of vertex and normal array.
Definition: TriangleNormalGenerator.h:69
void normalize()
Normalizes the calculated normals, this needs to be called after the pass to normalize all the normal...
Definition: TriangleNormalGenerator.cpp:49
Triangle index functor which calculates normals for the vertices of a geometry, use createNormalGener...
Definition: TriangleNormalGenerator.h:32
osg::ref_ptr< osg::Vec3Array > m_normalArray
Array storing calculated normals.
Definition: TriangleNormalGenerator.h:66
TriangleNormalGenerator()
Constructor.
Definition: TriangleNormalGenerator.cpp:29
osg::TriangleIndexFunctor< TriangleNormalGenerator > createNormalGenerator(osg::Vec3Array *vertexArray, osg::Vec3Array *normalArray)
Definition: TriangleNormalGenerator.cpp:86