Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

osg::TextVectorGlyph Class Reference

#include <OSGTextVectorGlyph.h>

Inheritance diagram for osg::TextVectorGlyph:

osg::TextGlyph List of all members.

Public Types

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

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,
Normals
NormalMap

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

Classes

struct  Point
struct  PolygonOutline
struct  VertexNormal

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.

typedef std::vector<VertexNormal> osg::TextVectorGlyph::Normals
 

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

Definition at line 150 of file OSGTextVectorGlyph.h.

typedef std::map<UInt32, PolygonOutline> osg::TextVectorGlyph::PolygonOutlineMap [protected]
 

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

enum osg::TextVectorGlyph::Orientation
 

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  )  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  )  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 317 of file OSGTextVectorGlyph.cpp.

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

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

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

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 425 of file OSGTextVectorGlyph.cpp.

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

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

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

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

Returns the orientations of the outlines.

Returns:
The orientations of the outline.

Definition at line 489 of file OSGTextVectorGlyph.cpp.

References _contourOrientations, and computeContourOrientations().

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

00490 {
00491     // compute the contour orientations when they are not available
00492     if (_contourOrientations.empty())
00493         computeContourOrientations();
00494     return _contourOrientations;
00495 }

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

Copy operator (not implemented!)

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

Computes the orientation of each contour

Definition at line 586 of file OSGTextVectorGlyph.cpp.

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

Referenced by getContourOrientations(), and getNormals().

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

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

Real32 osg::TextVectorGlyph::_width [protected]
 

The width of the glyph

Definition at line 240 of file OSGTextVectorGlyph.h.

Referenced by getWidth().

Real32 osg::TextVectorGlyph::_height [protected]
 

The height of the glyph

Definition at line 243 of file OSGTextVectorGlyph.h.

Referenced by getHeight().

Real32 osg::TextVectorGlyph::_horiBearingX [protected]
 

The x bearing of the glyph for horizontal layout

Definition at line 246 of file OSGTextVectorGlyph.h.

Referenced by getHoriBearingX().

Real32 osg::TextVectorGlyph::_horiBearingY [protected]
 

The y bearing of the glyph for horizontal layout

Definition at line 249 of file OSGTextVectorGlyph.h.

Referenced by getHoriBearingY().

Real32 osg::TextVectorGlyph::_vertBearingX [protected]
 

The x bearing of the glyph for vertical layout

Definition at line 252 of file OSGTextVectorGlyph.h.

Referenced by getVertBearingX().

Real32 osg::TextVectorGlyph::_vertBearingY [protected]
 

The y bearing of the glyph for vertical layout

Definition at line 255 of file OSGTextVectorGlyph.h.

Referenced by getVertBearingY().

Outline osg::TextVectorGlyph::_outline [protected]
 

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().

PolygonOutlineMap osg::TextVectorGlyph::_polygonOutlineMap [mutable, protected]
 

The map of polygon outlines (level -> outline)

Definition at line 267 of file OSGTextVectorGlyph.h.

Referenced by getLines().

NormalMap osg::TextVectorGlyph::_normalMap [mutable, protected]
 

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 Thu Aug 25 04:23:12 2005 for OpenSG by  doxygen 1.4.3