Open Inventor Reference
SoNormalGenerator Class Reference

This class can be used by polyhedral shape classes to generate surface normals when they do not have valid ones specified. More...

#include <Inventor/misc/SoNormalGenerator.h>

List of all members.

Public Member Functions

 SoNormalGenerator (SbBool isCCW)
 Constructors and destructor.
 SoNormalGenerator (SbBool isCCW, int approxNumVertices)
 ~SoNormalGenerator ()
void beginPolygon ()
 Send a polygon's worth of vertices.
void polygonVertex (const SbVec3f &point)
void endPolygon ()
void triangle (const SbVec3f &p1, const SbVec3f &p2, const SbVec3f &p3)
 Send a triangle.
void generate (float creaseAngle)
 Calculate the normals once all vertices have been sent.
int getNumNormals () const
 The rest of the methods may be called only AFTER generate() has been called:
void setNumNormals (int newNum)
 Truncate the array so there are only the given number of normals.
const SbVec3fgetNormals () const
 Returns a pointer to the array of normals.
const SbVec3fgetNormal (int32_t i) const
 Returns the i'th normal in the array.
void setNormal (int32_t index, const SbVec3f &newNormal)
 Some shapes may need to adjust or reorder normals after generation.

Detailed Description

To generate normals, create an instance of this class, then specify each polygon in the shape, then call generate(). After generate() is called, the normals can be accessed from the instance. There will be one normal generated for each vertex of each polygon, in the order passed in.

For convenience, there is a method to send down a triangle of vertices.

For efficiency, a constructor is provided that takes an approximate number of vertices that will be specified. Use this constructor if you know roughly how many vertices will be sent; this will cut down on allocation overhead.

The generate() method takes a crease angle that is used to determine whether to create normals that simulate a sharp crease at an edge between two polygons or to create normals that simulate smooth shading over the edge. The crease angle is the minimum angle (in radians) between the face normals on either side of an edge that will be used to consider the edge a crease. For example, a crease angle of pi/4 radians (45 degrees) means that adjacent face normals must be within 45 degrees of each other for the edge to be shaded smoothly.

Note that the SoNormalGenerator destructor DOES NOT delete the array of generated normals. The caller is responsible for doing so. This allows the normals to be cached elsewhere without having to copy them.

Definition at line 98 of file SoNormalGenerator.h.

Constructor & Destructor Documentation

SoNormalGenerator::SoNormalGenerator ( SbBool  isCCW)
SoNormalGenerator::SoNormalGenerator ( SbBool  isCCW,
int  approxNumVertices 
SoNormalGenerator::~SoNormalGenerator ( )

Member Function Documentation

void SoNormalGenerator::beginPolygon ( )

Begin a polygon, send as many vertices as you want, and then end the polygon.

void SoNormalGenerator::endPolygon ( )
void SoNormalGenerator::generate ( float  creaseAngle)
const SbVec3f& SoNormalGenerator::getNormal ( int32_t  i) const [inline]

Definition at line 136 of file SoNormalGenerator.h.

const SbVec3f* SoNormalGenerator::getNormals ( ) const [inline]

Definition at line 133 of file SoNormalGenerator.h.

int SoNormalGenerator::getNumNormals ( ) const [inline]

Returns number of normals generated. This will be equal to the number of points sent.

Definition at line 127 of file SoNormalGenerator.h.

void SoNormalGenerator::polygonVertex ( const SbVec3f point)
void SoNormalGenerator::setNormal ( int32_t  index,
const SbVec3f newNormal 

This method can be used to change a normal. It will insert room in the array if necessary to accommodate the new normal.

void SoNormalGenerator::setNumNormals ( int  newNum)
void SoNormalGenerator::triangle ( const SbVec3f p1,
const SbVec3f p2,
const SbVec3f p3 

The documentation for this class was generated from the following file: