Easy3D 2.6.1
|
Tessellator subdivides concave planar polygons, polygons with holes, or polygons with intersecting edges into triangles or simple contours. More...
#include <easy3d/algo/tessellator.h>
Classes | |
struct | Vertex |
A vertex carries both xyz coordinates and its attributes (e.g., color, texcoord). More... | |
Public Types | |
enum | WindingRule { WINDING_ODD = 100130 , WINDING_NONZERO = 100131 , WINDING_POSITIVE = 100132 , WINDING_NEGATIVE = 100133 , WINDING_ABS_GEQ_TWO = 100134 } |
The winding rule (default rule is ODD, modify if needed) | |
Public Member Functions | |
Tessellator () | |
Constructor. | |
~Tessellator () | |
Destructor. | |
void | set_boundary_only (bool b) |
Set the working mode of the tessellator. | |
void | set_winding_rule (WindingRule rule) |
Set the winding rule. The new rule will be effective until being changed by calling this function again. | |
void | begin_polygon (const vec3 &normal) |
Begin the tessellation of a complex polygon. | |
void | begin_polygon () |
Begin the tessellation of a complex polygon. | |
void | begin_contour () |
Begin a contour of a complex polygon (a polygon may have multiple contours). | |
void | add_vertex (const Vertex &data) |
Add a vertex of a contour to the tessellator. | |
void | add_vertex (const float *data, unsigned int size, int idx=0) |
Add a vertex of a contour to the tessellator. | |
void | add_vertex (const vec3 &xyz, int idx=0) |
Add a vertex of a contour to the tessellator. | |
void | add_vertex (const vec3 &xyz, const vec2 &t, int idx=0) |
Add a vertex of a contour to the tessellator. | |
void | add_vertex (const vec3 &xyz, const vec3 &v1, int idx=0) |
Add a vertex of a contour to the tessellator. | |
void | add_vertex (const vec3 &xyz, const vec3 &v1, const vec2 &t, int idx=0) |
Add a vertex of a contour to the tessellator. | |
void | add_vertex (const vec3 &xyz, const vec3 &v1, const vec3 &v2, int idx=0) |
Add a vertex of a contour to the tessellator. | |
void | add_vertex (const vec3 &xyz, const vec3 &v1, const vec3 &v2, const vec2 &t, int idx=0) |
Add a vertex of a contour to the tessellator. | |
void | end_contour () |
Finish the current contour of a polygon. | |
void | end_polygon () |
Finish the current polygon. | |
const std::vector< Vertex * > & | vertices () const |
The list of vertices in the result. | |
const std::vector< std::vector< unsigned int > > & | elements () const |
The list of elements (triangle or contour) created over many calls. Each element is represented by its vertex indices. | |
unsigned int | num_elements_in_polygon () const |
The number of elements (triangle or contour) in the last polygon. | |
void | reset () |
Clear all recorded data (triangle list and vertices) and restart index counter. | |
Tessellator subdivides concave planar polygons, polygons with holes, or polygons with intersecting edges into triangles or simple contours.
This implementation is also able to keep track of the unique vertices and respective indices, which allows to take advantage of the element buffer for efficient rendering (i.e., avoid sending vertices with the same geometry to the GPU). Typical applications:
void add_vertex | ( | const float * | data, |
unsigned int | size, | ||
int | idx = 0 ) |
Add a vertex of a contour to the tessellator.
data | The vertex data. |
size | The size of the vertex data array. |
idx | The index of this vertex. Providing a non-negative index allows to map a resulting vertex to the original vertex. Any new vertex generated in the tessellation will have a negative index -1. |
Add a vertex of a contour to the tessellator.
xyz | The xyz coordinates of the vertex. |
t | The texture coordinates of the vertex. |
idx | The index of this vertex. Providing a non-negative index allows to map a resulting vertex to the original vertex. Any new vertex generated in the tessellation will have a negative index -1. |
Add a vertex of a contour to the tessellator.
xyz | The xyz coordinates of the vertex. |
v1 | The first vertex property. |
t | The texture coordinates of the vertex. |
idx | The index of this vertex. Providing a non-negative index allows to map a resulting vertex to the original vertex. Any new vertex generated in the tessellation will have a negative index -1. |
Add a vertex of a contour to the tessellator.
xyz | The xyz coordinates of the vertex. |
v1 | The first vertex property. |
v2 | The second vertex property. |
t | The texture coordinates of the vertex. |
idx | The index of this vertex. Providing a non-negative index allows to map a resulting vertex to the original vertex. Any new vertex generated in the tessellation will have a negative index -1. |
Add a vertex of a contour to the tessellator.
xyz | The xyz coordinates of the vertex. |
v1 | The first vertex property. |
v2 | The second vertex property. |
idx | The index of this vertex. Providing a non-negative index allows to map a resulting vertex to the original vertex. Any new vertex generated in the tessellation will have a negative index -1. |
Add a vertex of a contour to the tessellator.
xyz | The xyz coordinates of the vertex. |
v1 | The first vertex property. |
idx | The index of this vertex. Providing a non-negative index allows to map a resulting vertex to the original vertex. Any new vertex generated in the tessellation will have a negative index -1. |
void add_vertex | ( | const vec3 & | xyz, |
int | idx = 0 ) |
Add a vertex of a contour to the tessellator.
xyz | The xyz coordinates of the vertex. |
idx | The index of this vertex. Providing a non-negative index allows to map a resulting vertex to the original vertex. Any new vertex generated in the tessellation will have a negative index -1. |
void add_vertex | ( | const Vertex & | data | ) |
Add a vertex of a contour to the tessellator.
data | The vertex data. |
void begin_polygon | ( | ) |
Begin the tessellation of a complex polygon.
This function does not provide the polygon normal and let the tessellator decide.
void begin_polygon | ( | const vec3 & | normal | ) |
Begin the tessellation of a complex polygon.
This function lets the user supply the polygon normal if known (to improve robustness or to achieve a specific tessellation purpose like CSG). All input data is projected into a plane perpendicular to the normal before tesselation. All output triangles are oriented CCW with respect to the normal. If the supplied normal is (0,0,0) (the default value), the normal is determined as follows. The direction of the normal, up to its sign, is found by fitting a plane to the vertices, without regard to how the vertices are connected. It is expected that the input data lies approximately in plane; otherwise projection perpendicular to the computed normal may substantially change the geometry. The sign of the normal is chosen so that the sum of the signed areas of all input contours is non-negative (where a CCW contour has positive area).
|
inline |
The list of elements (triangle or contour) created over many calls. Each element is represented by its vertex indices.
|
inline |
The number of elements (triangle or contour) in the last polygon.
void reset | ( | ) |
Clear all recorded data (triangle list and vertices) and restart index counter.
This function is useful if you want to selectively stitch faces/components. In this case, call reset() before you process each set. Then for each set, you collect the vertices and vertex indices of the triangles.
void set_boundary_only | ( | bool | b | ) |
Set the working mode of the tessellator.
The tessellator has two working modes and this function sets its working mode. The two working modes:
b | True for the boundary only mode and false for the filled polygons mode. |
void set_winding_rule | ( | WindingRule | rule | ) |
Set the winding rule. The new rule will be effective until being changed by calling this function again.
rule | The winding rule to set. |
With the winding rules, complex CSG operations can be implemented:
const std::vector< Tessellator::Vertex * > & vertices | ( | ) | const |
The list of vertices in the result.