cherish
Public Member Functions | Protected Member Functions | List of all members
entity::Stroke Class Reference

Geometry class that defined strokes entered by a user. The creation and usage of this class must be followed after certain steps. Here's an example of how to create a new stroke when user is drawing right away: More...

#include <Stroke.h>

Inheritance diagram for entity::Stroke:
entity::ShaderedEntity2D entity::Entity2D

Public Member Functions

 Stroke ()
 
 Stroke (const Stroke &copy, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
 
 META_Node (entity, Stroke) void setIsCurved(bool curved)
 
bool getIsCurved () const
 
virtual bool copyFrom (const entity::ShaderedEntity2D *copy)
 
virtual bool redefineToShape (osg::MatrixTransform *t=0)
 
osg::Node * getMeshRepresentation () const
 
float getLength () const
 
bool isLengthy () const
 
cher::ENTITY_TYPE getEntityType () const
 
virtual ProgramStrokegetProgram () const
 
virtual void appendPoint (const float u, const float v)
 
- Public Member Functions inherited from entity::ShaderedEntity2D
 ShaderedEntity2D (unsigned int drawing, osg::Geometry::AttributeBinding binding, const std::string &name, const osg::Vec4f &color)
 
 ShaderedEntity2D (const entity::ShaderedEntity2D &copy, const osg::CopyOp &copyop)
 
virtual void initializeProgram (ProgramEntity2D *p, unsigned int mode=GL_LINE_STRIP)
 
virtual void appendPoint (const float u, const float v, osg::Vec4f color)
 
virtual osg::Vec2f getPoint (unsigned int i) const
 
virtual osg::Vec3f getPoint3 (unsigned int i) const
 
int getNumPoints () const
 
virtual void moveDelta (double du, double dv)
 
virtual void scale (double scaleX, double scaleY, osg::Vec3f center)
 
virtual void scale (double scale, osg::Vec3f center)
 
virtual void rotate (double theta, osg::Vec3f center)
 
void setLines (osg::DrawArrays *lines)
 
const osg::DrawArrays * getLines () const
 
void setColor (const osg::Vec4f &color)
 
const osg::Vec4f & getColor () const
 
void setSelected (float alpha)
 
void setUnselected (float alpha)
 
void setIsShadered (bool shadered)
 
bool getIsShadered () const
 
virtual void setProgram (ProgramEntity2D *p)
 
- Public Member Functions inherited from entity::Entity2D
 Entity2D (const Entity2D &copy, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
 

Protected Member Functions

virtual bool redefineToShader (osg::MatrixTransform *t)
 
osg::Vec3Array * getCurvePoints (const osg::Vec3Array *bezierPts) const
 
double normalize (osg::Vec3Array *path, const osg::Vec3f &center)
 
void denormalize (osg::Vec3Array *path, const osg::Vec3f &center, double scale)
 

Additional Inherited Members

- Protected Attributes inherited from entity::ShaderedEntity2D
osg::ref_ptr< osg::DrawArrays > m_lines
 
osg::observer_ptr< ProgramEntity2Dm_program
 
bool m_isShadered
 
osg::Vec4f m_colorNormal
 
osg::Vec4f m_colorSelected
 

Detailed Description

Geometry class that defined strokes entered by a user. The creation and usage of this class must be followed after certain steps. Here's an example of how to create a new stroke when user is drawing right away:

// create an empty stroke
// initialize the shader program
original->initializeProgram(p); // e.g. Canvas::getProgramStroke()
// as user draws, add mouse coordinates, in an event loop:
original->addPoint(u,v);
\\ after user is finished drawing, re-define the look (shaderize as well)
original->redefineToShape();

The below example provides details on how to copy/clone a stroke that is already present on the scene graph:

// create an empty stroke
// copy data points from the stroke that is already on the scene (which means it is shadered)
// it also copies shader data
copy->copyFrom(original);
// as before, we re-define the stroke to be shadered

Constructor & Destructor Documentation

§ Stroke() [1/2]

entity::Stroke::Stroke ( )

Constructor that creates an empty stroke.

§ Stroke() [2/2]

entity::Stroke::Stroke ( const Stroke copy,
const osg::CopyOp &  copyop = osg::CopyOp::SHALLOW_COPY 
)

Copy constructor, only used for serialization; not to be used otherwise.

Member Function Documentation

§ appendPoint()

void entity::Stroke::appendPoint ( const float  u,
const float  v 
)
virtual

A method to add a point to the end of the entity. It is normally used when constructing an emtity in-motion while sketching.

Parameters
uis local U coordinate,
vis local V coordinate.

§ copyFrom()

bool entity::Stroke::copyFrom ( const entity::ShaderedEntity2D copy)
virtual

A method to be used to copy the input geometry data. It is assumed *this is empty.

Parameters
copyis the source geometry to copy from.

Reimplemented from entity::ShaderedEntity2D.

§ denormalize()

void entity::Stroke::denormalize ( osg::Vec3Array *  path,
const osg::Vec3f &  center,
double  scale 
)
protected

A method to denormalize the curve coordinates. Should be used after the curve fitting algorithm.

See also
normalize().

§ getCurvePoints()

osg::Vec3Array * entity::Stroke::getCurvePoints ( const osg::Vec3Array *  bezierPts) const
protected
Returns
Sampled points from provided set of bezier control points.

§ getEntityType()

cher::ENTITY_TYPE entity::Stroke::getEntityType ( ) const
virtual

A re-defined method of entity::Entity2D to obtain entity type.

Returns
entity type

Implements entity::ShaderedEntity2D.

§ getLength()

float entity::Stroke::getLength ( ) const
Returns
length of the stroke, which is measured as a largest dimention of the bounding box around the stroke.

§ getMeshRepresentation()

osg::Node * entity::Stroke::getMeshRepresentation ( ) const

A method that generates mesh representation of the stroke using Parallel Transport Algorithm.

Returns
pointer on the cretated mesh structure. The structure is not attached to the scene graph.

§ isLengthy()

bool entity::Stroke::isLengthy ( ) const
Returns
true if the stroke is longer than allowed threshold, false otherwise.

§ normalize()

double entity::Stroke::normalize ( osg::Vec3Array *  path,
const osg::Vec3f &  center 
)
protected

A method to make sure the curve is not too small, neither too large for a fitter tolerance level. Nomalization should be applied before the fitting algorithm, and then the result coordinates must get denrmalized back to their true size. The nornalization algorithm is as follows:

  1. Find center of the points.
  2. For each curve coordinate, substract a center coordinate from it.
  3. The scale factor equals to all the squared point deviations devided by total number of the points.
  4. Scale each coordinate by scale factor.
    Parameters
    pathis the point array to normalize,
    centeris local 2d center (e.g., bounding box center).
    Returns
    scaling factor.

§ redefineToShader()

bool entity::Stroke::redefineToShader ( osg::MatrixTransform *  t)
protectedvirtual

A method to tune the look of the stroke with smoother connections and thicker linewidth. So that to avoid broken and thin look of the default OpenGL functionality when using GL_LINE_STRIP_ADJACENCY and such.

Implements entity::ShaderedEntity2D.

§ redefineToShape()

bool entity::Stroke::redefineToShape ( osg::MatrixTransform *  t = 0)
virtual

A method that fits the stroke's points to a set of curve using Schneider's algorithm.

Parameters
tis the Canvas matrix transform. If none is provided, the transform of the current canvas is taken.
toleranceis the threshold fitting.
Returns
true upon success.

Implements entity::ShaderedEntity2D.


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