TangentSpaceGenerator.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_TANGENTSPACEGENERATOR_H
17 #define SURGSIM_GRAPHICS_TANGENTSPACEGENERATOR_H
18 
19 #include <osg/NodeVisitor>
20 #include <osg/Geode>
21 #include <osg/Geometry>
22 
23 namespace SurgSim
24 {
25 namespace Graphics
26 {
27 
31 {
32 public:
35 
39  void setBasisOrthonormality(bool orthonormal);
40 
44 
51  void set(const osg::Vec3Array* vertexArray,
52  const osg::Vec3Array* normalArray,
53  const osg::Vec2Array* textureCoordArray,
54  osg::Vec4Array* tangentArray,
55  osg::Vec4Array* bitangentArray);
56 
58  void orthogonalize();
59 
61  void reset();
62 
64  // space basis vectors.
68  void operator()(unsigned int vertexIndex1, unsigned int vertexIndex2, unsigned int vertexIndex3);
69 
70 private:
72  const osg::Vec3Array* m_vertexArray;
73 
75  const osg::Vec3Array* m_normalArray;
76 
78  const osg::Vec2Array* m_textureCoordArray;
79 
81  osg::Vec4Array* m_tangentArray;
82 
84  osg::Vec4Array* m_bitangentArray;
85 
89 };
90 
93 class TangentSpaceGenerator : public osg::NodeVisitor
94 {
95 public:
100  TangentSpaceGenerator(int textureCoordUnit, int tangentAttribIndex, int bitangentAttribIndex);
101 
103  virtual ~TangentSpaceGenerator();
104 
108  void setBasisOrthonormality(bool orthonormal);
109 
112  bool getBasisOrthonormality();
113 
116  void apply(osg::Geode& geode) override; // NOLINT
117 
125  static void generateTangentSpace(osg::Geometry* geometry,
126  int textureCoordUnit,
127  int tangentAttribIndex,
128  int bitangentAttribIndex,
129  bool orthonormal);
130 
131 private:
134 
137 
140 
144 };
145 
146 }
147 }
148 
149 #endif
SurgSim::Graphics::GenerateTangentSpaceTriangleIndexFunctor::m_textureCoordArray
const osg::Vec2Array * m_textureCoordArray
Array containing texture coordinates.
Definition: TangentSpaceGenerator.h:78
SurgSim::Graphics::TangentSpaceGenerator::m_textureCoordUnit
int m_textureCoordUnit
Texture unit of texture coordinates to use for calculating the tangent space.
Definition: TangentSpaceGenerator.h:133
SurgSim::Graphics::GenerateTangentSpaceTriangleIndexFunctor::m_createOrthonormalBasis
bool m_createOrthonormalBasis
Whether or not to create a fully orthonormal basis; otherwise, each tangent is separately orthonormal...
Definition: TangentSpaceGenerator.h:88
SurgSim::Graphics::GenerateTangentSpaceTriangleIndexFunctor::m_normalArray
const osg::Vec3Array * m_normalArray
Array containing normals.
Definition: TangentSpaceGenerator.h:75
SurgSim::Graphics::GenerateTangentSpaceTriangleIndexFunctor::m_vertexArray
const osg::Vec3Array * m_vertexArray
Array containing vertex positions.
Definition: TangentSpaceGenerator.h:72
SurgSim::Graphics::TangentSpaceGenerator
Node visitor which calculates the tangent space basis vectors from the texture coordinates of any geo...
Definition: TangentSpaceGenerator.h:93
SurgSim::Graphics::GenerateTangentSpaceTriangleIndexFunctor::GenerateTangentSpaceTriangleIndexFunctor
GenerateTangentSpaceTriangleIndexFunctor()
Constructor.
Definition: TangentSpaceGenerator.cpp:67
SurgSim::Graphics::TangentSpaceGenerator::TangentSpaceGenerator
TangentSpaceGenerator(int textureCoordUnit, int tangentAttribIndex, int bitangentAttribIndex)
Constructor.
Definition: TangentSpaceGenerator.cpp:182
SurgSim::Graphics::GenerateTangentSpaceTriangleIndexFunctor::orthogonalize
void orthogonalize()
Orthogonalize and normalize the calculated tangent space basis vectors.
Definition: TangentSpaceGenerator.cpp:116
SurgSim::Graphics::GenerateTangentSpaceTriangleIndexFunctor::operator()
void operator()(unsigned int vertexIndex1, unsigned int vertexIndex2, unsigned int vertexIndex3)
Calculates the triangle tangent space basis vectors and adds it to each adjacent vertex's tangent.
Definition: TangentSpaceGenerator.cpp:140
SurgSim::Graphics::GenerateTangentSpaceTriangleIndexFunctor::m_bitangentArray
osg::Vec4Array * m_bitangentArray
Array storing calculated bitangents.
Definition: TangentSpaceGenerator.h:84
SurgSim
Definition: CompoundShapeToGraphics.cpp:29
SurgSim::Graphics::GenerateTangentSpaceTriangleIndexFunctor::setBasisOrthonormality
void setBasisOrthonormality(bool orthonormal)
Sets whether the three tangent space basis vectors are made to be orthonormal; otherwise,...
Definition: TangentSpaceGenerator.cpp:77
SurgSim::Graphics::TangentSpaceGenerator::generateTangentSpace
static void generateTangentSpace(osg::Geometry *geometry, int textureCoordUnit, int tangentAttribIndex, int bitangentAttribIndex, bool orthonormal)
Generates tangent space basis vectors for the geometry.
Definition: TangentSpaceGenerator.cpp:217
SurgSim::Graphics::TangentSpaceGenerator::m_bitangentAttribIndex
int m_bitangentAttribIndex
Index of the vertex attribute array to store the calculated bitangents.
Definition: TangentSpaceGenerator.h:139
SurgSim::Graphics::TangentSpaceGenerator::m_createOrthonormalBasis
bool m_createOrthonormalBasis
Whether or not to create a fully orthonormal basis; otherwise, each tangent is separately orthonormal...
Definition: TangentSpaceGenerator.h:143
SurgSim::Graphics::GenerateTangentSpaceTriangleIndexFunctor::m_tangentArray
osg::Vec4Array * m_tangentArray
Array storing calculated tangents.
Definition: TangentSpaceGenerator.h:81
SurgSim::Graphics::TangentSpaceGenerator::setBasisOrthonormality
void setBasisOrthonormality(bool orthonormal)
Sets whether the three tangent space basis vectors are made to be orthonormal; otherwise,...
Definition: TangentSpaceGenerator.cpp:195
SurgSim::Graphics::GenerateTangentSpaceTriangleIndexFunctor::reset
void reset()
Resets all calculated tangent space basis vectors to 0.
Definition: TangentSpaceGenerator.cpp:129
SurgSim::Graphics::TangentSpaceGenerator::getBasisOrthonormality
bool getBasisOrthonormality()
Gets whether the three tangent space basis vectors are made to be orthonormal; otherwise,...
Definition: TangentSpaceGenerator.cpp:199
SurgSim::Graphics::GenerateTangentSpaceTriangleIndexFunctor::set
void set(const osg::Vec3Array *vertexArray, const osg::Vec3Array *normalArray, const osg::Vec2Array *textureCoordArray, osg::Vec4Array *tangentArray, osg::Vec4Array *bitangentArray)
Sets the arrays required to generate tangent space basis vectors.
Definition: TangentSpaceGenerator.cpp:86
SurgSim::Graphics::TangentSpaceGenerator::~TangentSpaceGenerator
virtual ~TangentSpaceGenerator()
Destructor.
Definition: TangentSpaceGenerator.cpp:191
SurgSim::Graphics::GenerateTangentSpaceTriangleIndexFunctor
Triangle index functor which calculates the tangent space basis vectors for the vertices of a geometr...
Definition: TangentSpaceGenerator.h:30
SurgSim::Graphics::TangentSpaceGenerator::m_tangentAttribIndex
int m_tangentAttribIndex
Index of the vertex attribute array to store the calculated tangents.
Definition: TangentSpaceGenerator.h:136
SurgSim::Graphics::GenerateTangentSpaceTriangleIndexFunctor::getBasisOrthonormality
bool getBasisOrthonormality()
Definition: TangentSpaceGenerator.cpp:81
SurgSim::Graphics::TangentSpaceGenerator::apply
void apply(osg::Geode &geode) override
Generates tangent space vectors for all geometry in the geode.
Definition: TangentSpaceGenerator.cpp:204