osg::TextVectorGlyph Class Reference

#include <OSGTextVectorGlyph.h>

Inheritance diagram for osg::TextVectorGlyph:
osg::TextGlyph

List of all members.

Classes

struct  Point
struct  PolygonOutline
struct  VertexNormal

Public Types

enum  Orientation { CW, CCW }
typedef std::vector< PointContour
typedef std::vector< ContourOutline
typedef std::vector< VertexNormalNormals
enum  { INVALID_INDEX = -1 }
typedef Int32 Index

Public Member Functions

virtual ~TextVectorGlyph ()
virtual Real32 getWidth () const
virtual Real32 getHeight () const
virtual Real32 getHoriBearingX () const
virtual Real32 getHoriBearingY () const
virtual Real32 getVertBearingX () const
virtual Real32 getVertBearingY () const
const OutlinegetOutline () const
const PolygonOutlinegetLines (UInt32 level=2) const
const NormalsgetNormals (UInt32 level=2) const
const std::vector< Orientation > & getContourOrientations () const
Index getGlyphIndex () const
Real32 getHoriAdvance () const
Real32 getVertAdvance () const

Protected Types

typedef std::map< UInt32,
PolygonOutline
PolygonOutlineMap
typedef std::map< UInt32, NormalsNormalMap

Protected Member Functions

 TextVectorGlyph ()

Protected Attributes

Real32 _width
Real32 _height
Real32 _horiBearingX
Real32 _horiBearingY
Real32 _vertBearingX
Real32 _vertBearingY
Outline _outline
std::vector< Orientation_contourOrientations
PolygonOutlineMap _polygonOutlineMap
NormalMap _normalMap
Index _glyphIndex
Real32 _horiAdvance
Real32 _vertAdvance

Private Member Functions

 TextVectorGlyph (const TextVectorGlyph &)
const TextVectorGlyphoperator= (const TextVectorGlyph &)
void computeContourOrientations () const

Friends

class TextVectorFace

Detailed Description

Defines a vector glyph.

Author:
Patrick Dähne

Definition at line 64 of file OSGTextVectorGlyph.h.


Member Typedef Documentation

typedef std::vector<Point> osg::TextVectorGlyph::Contour

Defines a contour

Definition at line 102 of file OSGTextVectorGlyph.h.

typedef std::vector<Contour> osg::TextVectorGlyph::Outline

Defines an outline

Definition at line 105 of file OSGTextVectorGlyph.h.

Defines a vector containing the edge normals along a polygon contour.

Definition at line 150 of file OSGTextVectorGlyph.h.

Defines the map of polygon outlines (level -> outline)

Definition at line 264 of file OSGTextVectorGlyph.h.

typedef std::map<UInt32, Normals> osg::TextVectorGlyph::NormalMap [protected]

Defines the map of normal outlines (level -> edge normal outline)

Definition at line 270 of file OSGTextVectorGlyph.h.

typedef Int32 osg::TextGlyph::Index [inherited]

Defines the glyph index

Definition at line 65 of file OSGTextGlyph.h.


Member Enumeration Documentation

Defines symbolic constants for the orientation of a contour.

Enumerator:
CW 
CCW 

Definition at line 222 of file OSGTextVectorGlyph.h.

00223     {
00224         CW, CCW
00225     };

anonymous enum [inherited]

Defines the invalid glyph index

Enumerator:
INVALID_INDEX 

Definition at line 68 of file OSGTextGlyph.h.

00068 { INVALID_INDEX = -1 };


Constructor & Destructor Documentation

osg::TextVectorGlyph::~TextVectorGlyph (  )  [virtual]

Destroys the VectorGlyph object.

Definition at line 66 of file OSGTextVectorGlyph.cpp.

00066 {}

osg::TextVectorGlyph::TextVectorGlyph (  )  [inline, protected]

Creates a new VectorGlyph object.

Definition at line 51 of file OSGTextVectorGlyph.inl.

00052 : TextGlyph(), _width(0.f), _height(0.f),
00053   _horiBearingX(0.f), _horiBearingY(0.f), _vertBearingX(0.f), _vertBearingY(0.f),
00054   _outline(), _polygonOutlineMap(), 
00055   _normalMap(), _contourOrientations()
00056 {}

osg::TextVectorGlyph::TextVectorGlyph ( const TextVectorGlyph  )  [private]

Copy constructor (not implemented!)


Member Function Documentation

Real32 osg::TextVectorGlyph::getWidth ( void   )  const [virtual]

Returns the width of the glyph.

Returns:
The width of the glyph

Implements osg::TextGlyph.

Definition at line 73 of file OSGTextVectorGlyph.cpp.

References _width.

00074 { return _width; }

Real32 osg::TextVectorGlyph::getHeight ( void   )  const [virtual]

Returns the height of the glyph.

Returns:
The height of the glyph

Implements osg::TextGlyph.

Definition at line 81 of file OSGTextVectorGlyph.cpp.

References _height.

00082 { return _height; }

Real32 osg::TextVectorGlyph::getHoriBearingX (  )  const [virtual]

Returns the x bearing of the glyph for horizontal layout. The x bearing is the distance from the origin to the left border of the glyph.

Returns:
The x bearing of the glyph for horizontal layout

Implements osg::TextGlyph.

Definition at line 89 of file OSGTextVectorGlyph.cpp.

References _horiBearingX.

00090 { return _horiBearingX; }

Real32 osg::TextVectorGlyph::getHoriBearingY (  )  const [virtual]

Returns the y bearing of the glyph for horizontal layout. The y bearing is the distance from the origin to the top border of the glyph.

Returns:
The y bearing of the glyph for horizontal layout

Implements osg::TextGlyph.

Definition at line 97 of file OSGTextVectorGlyph.cpp.

References _horiBearingY.

00098 { return _horiBearingY; }

Real32 osg::TextVectorGlyph::getVertBearingX (  )  const [virtual]

Returns the x bearing of the glyph for vertical layout. The x bearing is the distance from the origin to the left border of the glyph.

Returns:
The x bearing of the glyph for vertical layout

Implements osg::TextGlyph.

Definition at line 105 of file OSGTextVectorGlyph.cpp.

References _vertBearingX.

00106 { return _vertBearingX; }

Real32 osg::TextVectorGlyph::getVertBearingY (  )  const [virtual]

Returns the y bearing of the glyph for vertical layout. The y bearing is the distance from the origin to the top border of the glyph.

Returns:
The y bearing of the glyph for vertical layout

Implements osg::TextGlyph.

Definition at line 113 of file OSGTextVectorGlyph.cpp.

References _vertBearingY.

00114 { return _vertBearingY; }

const TextVectorGlyph::Outline & osg::TextVectorGlyph::getOutline (  )  const [inline]

Returns the contours that describe the outline of the glyph.

Returns:
The contours.

Definition at line 48 of file OSGTextVectorGlyph.inl.

References _outline.

00048 { return _outline; }

const TextVectorGlyph::PolygonOutline & osg::TextVectorGlyph::getLines ( UInt32  level = 2  )  const

Returns a polygon outline containing only on-curve points. The contours contained in this outline are not closed!

Parameters:
level The level of detail.
Returns:
An outline containing only on-curve points.

Definition at line 312 of file OSGTextVectorGlyph.cpp.

References _outline, _polygonOutlineMap, osg::evalBezierCurve(), GLdouble, osg::gluTessBeginDataCB(), osg::gluTessCombineDataCB(), osg::gluTessEndDataCB(), and osg::gluTessVertexDataCB().

Referenced by computeContourOrientations(), osg::TextVectorFace::fillGeo(), and getNormals().

00313 {
00314     // Try to find the polygon outline of the specified detail level in the
00315     // cache map
00316     PolygonOutlineMap::const_iterator it = _polygonOutlineMap.find(level);
00317     if (it != _polygonOutlineMap.end())
00318         // We already have that level - return the corresponding outline
00319         return it->second;
00320 
00321     // We did not find that level, so we have to create it
00322     PolygonOutline &newOutline = _polygonOutlineMap.insert(PolygonOutlineMap::value_type(level, PolygonOutline())).first->second;
00323 
00324     // Calculate the bezier curves for this level
00325     Outline::const_iterator oIt;
00326     for (oIt = _outline.begin(); oIt != _outline.end(); ++oIt)
00327     {
00328         UInt32 size = oIt->size();
00329         if (size > 0)
00330         {
00331             size -= 1;
00332             UInt32 index = 0;
00333             while (index < size)
00334                 evalBezierCurve(*oIt, index, level, newOutline.coords);
00335             newOutline.contours.push_back(newOutline.coords.size());
00336         }
00337     }
00338 
00339     // Calculate the faces
00340 
00341     // Create a new GLU tesselator object
00342     GLUtesselator *tess = gluNewTess();
00343     if (tess == 0)
00344         return newOutline;
00345 
00346     // hint to the GLU tesselator that all points lie in the xy-plane
00347     gluTessNormal(tess, 0.0, 0.0, 1.0);
00348     // set the winding rule
00349     gluTessProperty(tess, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_ODD);
00350 
00351     // register GLU Tesselator callback methods
00352     gluTessCallback(tess,
00353                     GLU_TESS_BEGIN_DATA,
00354                     reinterpret_cast<OSGGLUfuncptr>(gluTessBeginDataCB));
00355     gluTessCallback(tess,
00356                     GLU_TESS_END_DATA,
00357                     reinterpret_cast<OSGGLUfuncptr>(gluTessEndDataCB));
00358     gluTessCallback(tess,
00359                     GLU_TESS_COMBINE_DATA,
00360                     reinterpret_cast<OSGGLUfuncptr>(gluTessCombineDataCB));
00361     gluTessCallback(tess,
00362                     GLU_TESS_VERTEX_DATA,
00363                     reinterpret_cast<OSGGLUfuncptr>(gluTessVertexDataCB));
00364 
00365     // make shared data structure available to callbacks */
00366     gluTessBeginPolygon(tess, &newOutline);
00367 
00368     vector<UInt32>::const_iterator cIt;
00369     UInt32 coordIndex = 0;
00370     for (cIt = newOutline.contours.begin(); cIt != newOutline.contours.end(); ++cIt)
00371     {
00372         // begin new contour
00373         gluTessBeginContour(tess);
00374 
00375         while (coordIndex < *cIt)
00376         {
00377             GLdouble coords[3];
00378             assert(coordIndex < newOutline.coords.size());
00379             coords[0] = newOutline.coords[coordIndex].x();
00380             coords[1] = newOutline.coords[coordIndex].y();
00381             coords[2] = 0.f;
00382             gluTessVertex(tess, coords, reinterpret_cast<void*>(coordIndex++));
00383         }
00384 
00385         // end of contour
00386         gluTessEndContour(tess);
00387     }
00388 
00389     // trigger tesselator action
00390     gluTessEndPolygon(tess);
00391 
00392     // clean up
00393     gluDeleteTess(tess);
00394 
00395     return newOutline;
00396 }

const TextVectorGlyph::Normals & osg::TextVectorGlyph::getNormals ( UInt32  level = 2  )  const

Returns an edge normal outline of the specified detail level

Parameters:
level The level of detail.
Returns:
The normals at the edges of the outline.

Definition at line 420 of file OSGTextVectorGlyph.cpp.

References _contourOrientations, _normalMap, computeContourOrientations(), osg::computeEdgeNormal(), osg::TextVectorGlyph::PolygonOutline::contours, osg::TextVectorGlyph::PolygonOutline::coords, CW, getLines(), osg::Vector< ValueTypeT, SizeI >::normalize(), osg::osgabs(), and osg::osgacos().

Referenced by osg::TextVectorFace::fillGeo().

00421 {
00422     // Try to find the normal outline of the specified detail level in the
00423     // cache map
00424     NormalMap::const_iterator it = _normalMap.find(level);
00425     if (it != _normalMap.end())
00426         // We already have that level - return the corresponding outline
00427         return it->second;
00428 
00429     // We did not find that level, so we have to create it
00430     Normals &normals = _normalMap.insert(NormalMap::value_type(level, Normals())).first->second;
00431 
00432     // get the polygon outline of this glyph at the desired detail level
00433     // The contours of this outline are not closed!
00434     const PolygonOutline &outline = getLines(level);
00435 
00436     // compute the contour orientations when they are not available
00437     if (_contourOrientations.empty())
00438         computeContourOrientations();
00439 
00440     UInt32 start = 0, end, index = 0;
00441     vector<UInt32>::const_iterator iIt;
00442     vector<Orientation>::const_iterator oriIt = _contourOrientations.begin();
00443     for (iIt = outline.contours.begin(); iIt != outline.contours.end(); ++iIt, ++oriIt)
00444     {
00445         end = *iIt;
00446 
00447         assert(end - 1 < outline.coords.size());
00448         assert(start < outline.coords.size());
00449         assert(oriIt != _contourOrientations.end());
00450         Vec2f prevEdgeNormal = computeEdgeNormal(outline.coords[end - 1],
00451                                                  outline.coords[start],
00452                                                  (*oriIt) == CW);
00453         while (index < end)
00454         {
00455             UInt32 nextIndex = index + 1;
00456             if (nextIndex >= end)
00457                 nextIndex = start;
00458 
00459             assert(index < outline.coords.size());
00460             assert(nextIndex < outline.coords.size());
00461             Vec2f nextEdgeNormal = computeEdgeNormal(outline.coords[index], outline.coords[nextIndex], (*oriIt) == CW);
00462             Vec2f meanEdgeNormal = prevEdgeNormal + nextEdgeNormal;
00463             meanEdgeNormal.normalize();
00464             Real32 edgeAngle = osgacos(osgabs(prevEdgeNormal.dot(nextEdgeNormal)));
00465             normals.push_back(VertexNormal(nextEdgeNormal, meanEdgeNormal, edgeAngle));
00466 
00467             //the outgoing edge of this vertex is the incoming of the next vertex
00468             prevEdgeNormal = nextEdgeNormal;
00469 
00470             ++index;
00471         }
00472 
00473         start = end;
00474     }
00475 
00476     return normals;
00477 }

const vector< TextVectorGlyph::Orientation > & osg::TextVectorGlyph::getContourOrientations (  )  const

Returns the orientations of the outlines.

Returns:
The orientations of the outline.

Definition at line 484 of file OSGTextVectorGlyph.cpp.

References _contourOrientations, and computeContourOrientations().

Referenced by osg::TextVectorFace::fillGeo().

00485 {
00486     // compute the contour orientations when they are not available
00487     if (_contourOrientations.empty())
00488         computeContourOrientations();
00489     return _contourOrientations;
00490 }

const TextVectorGlyph& osg::TextVectorGlyph::operator= ( const TextVectorGlyph  )  [private]

Copy operator (not implemented!)

Reimplemented from osg::TextGlyph.

void osg::TextVectorGlyph::computeContourOrientations (  )  const [private]

Computes the orientation of each contour

Definition at line 581 of file OSGTextVectorGlyph.cpp.

References _contourOrientations, CCW, osg::computeEdgeNormal(), osg::TextVectorGlyph::PolygonOutline::contours, osg::TextVectorGlyph::PolygonOutline::coords, CW, osg::Eps, getLines(), osg::isInteriorPoint(), and osg::Vector< ValueTypeT, SizeI >::normalize().

Referenced by getContourOrientations(), and getNormals().

00582 {
00583     // get the simplest outline available as it should suffice for the
00584     // orientation check
00585     const PolygonOutline &outline = getLines(0);
00586     UInt32 start = 0, end;
00587     vector<UInt32>::const_iterator it;
00588     for (it = outline.contours.begin(); it != outline.contours.end(); ++it)
00589     {
00590         end = *it;
00591 
00592         // return value does not matter
00593         if (end - start < 3)
00594             _contourOrientations.push_back(CCW);
00595 
00596         assert(start + 2 < outline.coords.size());
00597         Vec2f en1 = computeEdgeNormal(outline.coords[start], outline.coords[start + 1], false);
00598         Vec2f en2 = computeEdgeNormal(outline.coords[start + 1], outline.coords[start + 2], false);
00599         // compute the mean of the edge normals at vertex 0.
00600         Vec2f testNormal = en1 + en2;
00601         testNormal.normalize();
00602         // calculate the displacement of vertex 0 along its mean edge normal
00603         Vec2f testPoint = outline.coords[start + 1] + testNormal * (1000.f * Eps);
00604 
00605         if (isInteriorPoint(testPoint, outline, GLU_TESS_WINDING_NONZERO))
00606             _contourOrientations.push_back(CW);
00607         else
00608             _contourOrientations.push_back(CCW);
00609 
00610         start = end;
00611     }
00612 }

TextGlyph::Index osg::TextGlyph::getGlyphIndex (  )  const [inline, inherited]

Returns the index of the glyph.

Returns:
The index of the glyph

Definition at line 43 of file OSGTextGlyph.inl.

References osg::TextGlyph::_glyphIndex.

00043 { return _glyphIndex; }

Real32 osg::TextGlyph::getHoriAdvance (  )  const [inline, inherited]

Returns the advance of the glyph for horizontal layout. The advance is the distance to the next character on the base line.

Returns:
The advance for horizontal layout

Definition at line 46 of file OSGTextGlyph.inl.

References osg::TextGlyph::_horiAdvance.

00046 { return _horiAdvance; }

Real32 osg::TextGlyph::getVertAdvance (  )  const [inline, inherited]

Returns the advance of the glyph for vertical layout. The advance is the distance to the next character on the base line. This value is usually negative!

Returns:
The advance for vertical layout

Definition at line 49 of file OSGTextGlyph.inl.

References osg::TextGlyph::_vertAdvance.

00049 { return _vertAdvance; }


Friends And Related Function Documentation

friend class TextVectorFace [friend]

Needs access to constructor

Definition at line 68 of file OSGTextVectorGlyph.h.


Member Data Documentation

The width of the glyph

Definition at line 240 of file OSGTextVectorGlyph.h.

Referenced by getWidth().

The height of the glyph

Definition at line 243 of file OSGTextVectorGlyph.h.

Referenced by getHeight().

The x bearing of the glyph for horizontal layout

Definition at line 246 of file OSGTextVectorGlyph.h.

Referenced by getHoriBearingX().

The y bearing of the glyph for horizontal layout

Definition at line 249 of file OSGTextVectorGlyph.h.

Referenced by getHoriBearingY().

The x bearing of the glyph for vertical layout

Definition at line 252 of file OSGTextVectorGlyph.h.

Referenced by getVertBearingX().

The y bearing of the glyph for vertical layout

Definition at line 255 of file OSGTextVectorGlyph.h.

Referenced by getVertBearingY().

The original outline information

Definition at line 258 of file OSGTextVectorGlyph.h.

Referenced by getLines(), and getOutline().

std::vector<Orientation> osg::TextVectorGlyph::_contourOrientations [mutable, protected]

The vector of contour orientations

Definition at line 261 of file OSGTextVectorGlyph.h.

Referenced by computeContourOrientations(), getContourOrientations(), and getNormals().

The map of polygon outlines (level -> outline)

Definition at line 267 of file OSGTextVectorGlyph.h.

Referenced by getLines().

The map of normal outlines (level -> edge normal outline)

Definition at line 273 of file OSGTextVectorGlyph.h.

Referenced by getNormals().

Index osg::TextGlyph::_glyphIndex [protected, inherited]

The index of the glyph

Definition at line 145 of file OSGTextGlyph.h.

Referenced by osg::TextGlyph::getGlyphIndex().

Real32 osg::TextGlyph::_horiAdvance [protected, inherited]

The advance of the glyph for horizontal layout

Definition at line 148 of file OSGTextGlyph.h.

Referenced by osg::TextGlyph::getHoriAdvance().

Real32 osg::TextGlyph::_vertAdvance [protected, inherited]

The advance of the glyph for vertical layout

Definition at line 151 of file OSGTextGlyph.h.

Referenced by osg::TextGlyph::getVertAdvance().


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

Generated on 8 Feb 2010 for OpenSG by  doxygen 1.6.1