TriangleNormalGenerator.h
Go to the documentation of this file.
// This file is a part of the OpenSurgSim project.
// Copyright 2013, SimQuest Solutions Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef SURGSIM_GRAPHICS_TRIANGLENORMALGENERATOR_H
#define SURGSIM_GRAPHICS_TRIANGLENORMALGENERATOR_H
#include <osg/NodeVisitor>
#include <osg/Geode>
#include <osg/Geometry>
#include <osg/TriangleIndexFunctor>
namespace SurgSim
{
namespace Graphics
{
class TriangleNormalGenerator
{
public:
void set(osg::Vec3Array* vertexArray,
osg::Vec3Array* normalArray);
void normalize();
void reset();
void operator() (size_t vertexIndex1, size_t vertexIndex2, size_t vertexIndex3);
protected:
TriangleNormalGenerator();
private:
osg::ref_ptr<osg::Vec3Array> m_vertexArray;
osg::ref_ptr<osg::Vec3Array> m_normalArray;
size_t m_size;
};
osg::TriangleIndexFunctor<TriangleNormalGenerator> createNormalGenerator(
osg::Vec3Array* vertexArray,
osg::Vec3Array* normalArray);
}; // Graphics
}; // SurgSim
#endif
SurgSim
Definition: CompoundShapeToGraphics.cpp:29
SurgSim::Graphics::TriangleNormalGenerator::reset
void reset()
Resets all calculated normals to 0.
Definition: TriangleNormalGenerator.cpp:57
SurgSim::Graphics::TriangleNormalGenerator::operator()
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
SurgSim::Graphics::TriangleNormalGenerator::m_vertexArray
osg::ref_ptr< osg::Vec3Array > m_vertexArray
Array containing vertex positions.
Definition: TriangleNormalGenerator.h:63
SurgSim::Graphics::TriangleNormalGenerator::m_size
size_t m_size
Size of vertex and normal array.
Definition: TriangleNormalGenerator.h:69
SurgSim::Graphics::TriangleNormalGenerator::normalize
void normalize()
Normalizes the calculated normals, this needs to be called after the pass to normalize all the normal...
Definition: TriangleNormalGenerator.cpp:49
SurgSim::Graphics::TriangleNormalGenerator
Triangle index functor which calculates normals for the vertices of a geometry, use createNormalGener...
Definition: TriangleNormalGenerator.h:32
SurgSim::Graphics::TriangleNormalGenerator::m_normalArray
osg::ref_ptr< osg::Vec3Array > m_normalArray
Array storing calculated normals.
Definition: TriangleNormalGenerator.h:66
SurgSim::Graphics::TriangleNormalGenerator::TriangleNormalGenerator
TriangleNormalGenerator()
Constructor.
Definition: TriangleNormalGenerator.cpp:29
SurgSim::Graphics::createNormalGenerator
osg::TriangleIndexFunctor< TriangleNormalGenerator > createNormalGenerator(osg::Vec3Array *vertexArray, osg::Vec3Array *normalArray)
Definition: TriangleNormalGenerator.cpp:86