Easy3D 2.5.3
|
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 |
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 | |
void | set_boundary_only (bool b) |
Set the working mode of the tessellator. More... | |
void | set_winding_rule (WindingRule rule) |
Set the wining rule. The new rule will be effective until being changed by calling this function again. With the winding rules, complex CSG operations can be implemented: More... | |
void | begin_polygon (const vec3 &normal) |
Begin the tessellation of a complex polygon. More... | |
void | begin_polygon () |
Begin the tessellation of a complex polygon. More... | |
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. More... | |
void | add_vertex (const float *data, unsigned int size, int idx=0) |
void | add_vertex (const vec3 &xyz, int idx=0) |
void | add_vertex (const vec3 &xyz, const vec2 &t, int idx=0) |
void | add_vertex (const vec3 &xyz, const vec3 &v1, int idx=0) |
void | add_vertex (const vec3 &xyz, const vec3 &v1, const vec2 &t, int idx=0) |
void | add_vertex (const vec3 &xyz, const vec3 &v1, const vec3 &v2, int idx=0) |
void | add_vertex (const vec3 &xyz, const vec3 &v1, const vec3 &v2, const vec2 &t, int idx=0) |
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. More... | |
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. More... | |
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. More... | |
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).
void add_vertex | ( | const float * | data, |
unsigned int | size, | ||
int | idx = 0 |
||
) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
void add_vertex | ( | const vec3 & | xyz, |
int | idx = 0 |
||
) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
void add_vertex | ( | const Vertex & | data | ) |
Add a vertex of a contour to the tessellator.
data | The vertex data. |
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 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 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 wining rule. The new rule will be effective until being changed by calling this function again. With the winding rules, complex CSG operations can be implemented:
const std::vector< Tessellator::Vertex * > & vertices | ( | ) | const |
The list of vertices in the result.