CUGL 2.1
Cornell University Game Library
Public Member Functions | List of all members
cugl::ComplexExtruder Class Reference

#include <CUComplexExtruder.h>

Public Member Functions

 ComplexExtruder ()
 
 ComplexExtruder (const std::vector< Vec2 > &points, bool closed)
 
 ComplexExtruder (const Path2 &path)
 
 ~ComplexExtruder ()
 
void setJoint (poly2::Joint joint)
 
poly2::Joint getJoint () const
 
void setEndCap (poly2::EndCap endcap)
 
poly2::EndCap getEndCap () const
 
void setMitreLimit (float limit)
 
float getMitreLimit () const
 
void setResolution (Uint32 resolution)
 
Uint32 getResolution () const
 
void set (const std::vector< Vec2 > &points, bool closed)
 
void set (const Vec2 *points, size_t size, bool closed)
 
void set (const Path2 &path)
 
void reset ()
 
void clear ()
 
void calculate (float stroke)
 
Poly2 getPolygon () const
 
Poly2getPolygon (Poly2 *buffer) const
 
std::vector< Path2getBorder () const
 
size_t getBorder (std::vector< Path2 > &buffer) const
 

Detailed Description

This class is a factory for extruding wireframe paths into a solid path.

An extrusion of a path is a polygon that follows the path but gives it width. Hence it takes a path and turns it into a solid shape. This is more complicated than simply triangulating the original path. The new polygon has more vertices, depending on the choice of joint (shape at the corners) and cap (shape at the end).

This class is significantly more accurate than SimpleExtruder. The extruded shape has no overlapping triangles and is safe to use with transparency. However, this comes at massive cost in speed. Even a simple line can take a full millisecond to compute, and more complicated paths will significantly affect frame rate. If you need to extrude a path at framerate, you should use SimpleExtruder instead, and pre-render to a texture if you need transparency.

As with all factories, the methods are broken up into three phases: initialization, calculation, and materialization. To use the factory, you first set the data (in this case a set of vertices or Path2 object) with the initialization methods. You then call the calculation method. Finally, you use the materialization methods to access the data in several different ways.

This division allows us to support multithreaded calculation if the data generation takes too long. However, note that this factory is not thread safe in that you cannot access data while it is still in mid-calculation.

Constructor & Destructor Documentation

◆ ComplexExtruder() [1/3]

cugl::ComplexExtruder::ComplexExtruder ( )

Creates an extruder with no vertex data.

◆ ComplexExtruder() [2/3]

cugl::ComplexExtruder::ComplexExtruder ( const std::vector< Vec2 > &  points,
bool  closed 
)

Creates an extruder with the given vertex data.

The vertex data is copied. The extruder does not retain any references to the original data.

Parameters
pointsThe vertices to extrude
closedWhether the path is closed

◆ ComplexExtruder() [3/3]

cugl::ComplexExtruder::ComplexExtruder ( const Path2 path)

Creates an extruder with the given vertex data.

The path data is copied. The extruder does not retain any references to the original data.

Parameters
pathThe vertices to extrude

◆ ~ComplexExtruder()

cugl::ComplexExtruder::~ComplexExtruder ( )
inline

Deletes this extruder, releasing all resources.

Member Function Documentation

◆ calculate()

void cugl::ComplexExtruder::calculate ( float  stroke)

Performs a extrusion of the current vertex data.

An extrusion of a polygon is a second polygon that follows the path of the first one, but gives it width. Hence it takes a path and turns it into a solid shape. This is more complicated than simply triangulating the original polygon. The new polygon has more vertices, depending on the choice of joint (shape at the corners) and cap (shape at the end).

This method uses the Clipper library to perform the extrusion. While accurate and the preferred for static shapes, it is not ideal to call this method at framerate. Furthermore, while Clipper produces the boundary path of the extrusion, it does not triangulate it. This class uses a DelaunayTriangulator to complete the calculation, as that triangulator produces the best triangles for geometric purposes.

Parameters
strokeThe stroke width of the extrusion

◆ clear()

void cugl::ComplexExtruder::clear ( )

Clears all internal data, including initial vertex data.

When this method is called, you will need to set a new vertices before calling calculate. However, the joint, cap, and precision settings are preserved.

◆ getBorder() [1/2]

std::vector<Path2> cugl::ComplexExtruder::getBorder ( ) const

Returns a (closed) path representing the extrusion border(s)

So long as the calculation is complete, the vector is guaranteed to contain at least one path. Counter-clockwise paths correspond to the exterior boundary of the stroke. Clockwise paths are potential holes in the extrusion. There is no guarantee on the order of the returned paths.

If the calculation is not yet performed, this method will return the empty path.

Returns
a (closed) path representing the extrusion border

◆ getBorder() [2/2]

size_t cugl::ComplexExtruder::getBorder ( std::vector< Path2 > &  buffer) const

Stores a (closed) path representing the extrusion border in the buffer

So long as the calculation is complete, the vector is guaranteed to contain at least one path. Counter-clockwise paths correspond to the exterior boundary of the stroke. Clockwise paths are potential holes in the extrusion. There is no guarantee on the order of the returned paths.

This method will append append its results to the provided buffer. It will not erase any existing data. You should clear the buffer first if you do not want to preserve the original data.

If the calculation is not yet performed, this method will do nothing.

Parameters
bufferThe buffer to store the path around the extrusion
Returns
the number of elements added to the buffer

◆ getEndCap()

poly2::EndCap cugl::ComplexExtruder::getEndCap ( ) const

Returns the end cap value for the extrusion.

The end cap type determines how the extrusion draws the ends of the line segments at the start and end of the path. See poly2::EndCap for the description of the types.

Returns
the end cap value for the extrusion.

◆ getJoint()

poly2::Joint cugl::ComplexExtruder::getJoint ( ) const

Returns the joint value for the extrusion.

The joint type determines how the extrusion joins the extruded line segments together. See poly2::Joint for the description of the types.

Returns
the joint value for the extrusion.

◆ getMitreLimit()

float cugl::ComplexExtruder::getMitreLimit ( ) const
inline

Returns the mitre limit of the extrusion.

The mitre limit sets how "pointy" a mitre joint is allowed to be before the algorithm switches it back to a bevel/square joint. Small angles can have very large mitre offsets that go way off-screen.

In the case of Clipper, the mitre limit is the maximum distance in multiples of delta that vertices can be offset from their original positions before squaring is applied. By default this value is 2 (e.g. twice delta). That is also the smallest value allowed.

Returns
the mitre limit for joint calculations

◆ getPolygon() [1/2]

Poly2 cugl::ComplexExtruder::getPolygon ( ) const

Returns a polygon representing the path extrusion.

The polygon contains the a completely new set of vertices together with the indices defining the extrusion path. The extruder does not maintain references to this polygon and it is safe to modify it.

If the calculation is not yet performed, this method will return the empty polygon.

Returns
a polygon representing the path extrusion.

◆ getPolygon() [2/2]

Poly2* cugl::ComplexExtruder::getPolygon ( Poly2 buffer) const

Stores the path extrusion in the given buffer.

This method will add both the new vertices, and the corresponding indices to the new buffer. If the buffer is not empty, the indices will be adjusted accordingly. You should clear the buffer first if you do not want to preserve the original data.

If the calculation is not yet performed, this method will do nothing.

Parameters
bufferThe buffer to store the extruded polygon
Returns
a reference to the buffer for chaining.

◆ getResolution()

Uint32 cugl::ComplexExtruder::getResolution ( ) const
inline

Returns the subdivision resolution for the Clipper library.

Clipper is not only accurate, it is also computationally stable. However, it achieves this stable by only using integer coordinates. This class supports float coordinates, but it does it by scaling the points to fit on an integer grid.

The resolution is the scaling factor before rounding the points to the nearest integer. It is effectively the same as specifying the number of integer subdivisions supported. For example, if the resolution is 8 (the default), then every point will be rounded to the nearest 1/8 value.

Returns
the subdivision resolution for the Clipper library.

◆ reset()

void cugl::ComplexExtruder::reset ( )

Clears all computed data, but still maintains the settings.

This method preserves all initial vertex data, as well as the joint, cap, and precision settings.

◆ set() [1/3]

void cugl::ComplexExtruder::set ( const Path2 path)

Sets the path for this extruder.

The path data is copied. The extruder does not retain any references to the original data.

This method resets all interal data. You will need to reperform the calculation before accessing data.

Parameters
pathThe path to extrude

◆ set() [2/3]

void cugl::ComplexExtruder::set ( const std::vector< Vec2 > &  points,
bool  closed 
)

Sets the vertex data for this extruder.

The vertex data is copied. The extruder does not retain any references to the original data.

This method resets all interal data. You will need to reperform the calculation before accessing data.

Parameters
pointsThe vertices to extruder
closedWhether the path is closed

◆ set() [3/3]

void cugl::ComplexExtruder::set ( const Vec2 points,
size_t  size,
bool  closed 
)

Sets the path for this extruder.

The path data is copied. The extruder does not retain any references to the original data. All points will be considered to be corner points.

This method resets all interal data. You will need to reperform the calculation before accessing data.

Parameters
pointsThe path to extrude
sizeThe number of points
closedWhether the path is closed

◆ setEndCap()

void cugl::ComplexExtruder::setEndCap ( poly2::EndCap  endcap)

Sets the end cap value for the extrusion.

The end cap type determines how the extrusion draws the ends of the line segments at the start and end of the path. See poly2::EndCap for the description of the types.

Parameters
endcapThe extrusion end cap type

◆ setJoint()

void cugl::ComplexExtruder::setJoint ( poly2::Joint  joint)

Sets the joint value for the extrusion.

The joint type determines how the extrusion joins the extruded line segments together. See poly2::Joint for the description of the types.

Parameters
jointThe extrusion joint type

◆ setMitreLimit()

void cugl::ComplexExtruder::setMitreLimit ( float  limit)
inline

Sets the mitre limit of the extrusion.

The mitre limit sets how "pointy" a mitre joint is allowed to be before the algorithm switches it back to a bevel/square joint. Small angles can have very large mitre offsets that go way off-screen.

In the case of Clipper, the mitre limit is the maximum distance in multiples of delta that vertices can be offset from their original positions before squaring is applied. By default this value is 2 (e.g. twice delta). That is also the smallest value allowed.

Parameters
limitThe mitre limit for joint calculations

◆ setResolution()

void cugl::ComplexExtruder::setResolution ( Uint32  resolution)
inline

Sets the subdivision resolution for the Clipper library.

Clipper is not only accurate, it is also computationally stable. However, it achieves this stable by only using integer coordinates. This class supports float coordinates, but it does it by scaling the points to fit on an integer grid.

The resolution is the scaling factor before rounding the points to the nearest integer. It is effectively the same as specifying the number of integer subdivisions supported. For example, if the resolution is 8 (the default), then every point will be rounded to the nearest 1/8 value.

Parameters
resolutionThe subdivision resolution

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