27#ifndef EASY3D_ALGO_TESSELLATOR_H
28#define EASY3D_ALGO_TESSELLATOR_H
31#include <easy3d/core/types.h>
60 struct Vertex : std::vector<double> {
78 Vertex(
const FT *data, std::size_t size,
int idx = 0) : std::vector<double>(data, data + size),
index(idx) {}
86 explicit Vertex(std::size_t size = 0,
int idx = 0) : std::vector<double>(size),
index(idx) {}
94 Vertex(
const Vertex &v,
int idx = 0) : std::vector<double>(v.begin(), v.end()),
index(idx) {}
102 template<
typename Vec>
104 for (
int i = 0; i < v.
size(); ++i)
124 WINDING_ODD = 100130,
125 WINDING_NONZERO = 100131,
126 WINDING_POSITIVE = 100132,
127 WINDING_NEGATIVE = 100133,
128 WINDING_ABS_GEQ_TWO = 100134
199 void add_vertex(
const float *data,
unsigned int size,
int idx = 0);
268 const std::vector<Vertex *> &
vertices()
const;
275 const std::vector<std::vector<unsigned int> > &
elements()
const {
return elements_; }
296 void _add_element(
const std::vector<unsigned int> &element);
299 static void beginCallback(
unsigned int w,
void *cbdata);
300 static void endCallback(
void *cbdata);
301 static void vertexCallback(
void *vertex,
void *cbdata);
302 static void combineCallback(
const double coords[3],
void *vertex_data[4],
const float weight[4],
void **dataOut,
void *cbdata);
306 void *vertex_manager_;
309 unsigned int primitive_type_;
313 std::vector<std::vector<unsigned int> > elements_;
316 unsigned int num_elements_in_polygon_;
319 std::vector<unsigned int> vertex_ids_;
322 unsigned int vertex_data_size_;
342 void union_of(std::vector<Polygon2> &polygons);
350 void intersection_of(
const Polygon2& polygon_a,
const Polygon2& polygon_b, std::vector<Polygon2> &result);
358 void difference_of(
const Polygon2& polygon_a,
const Polygon2& polygon_b, std::vector<Polygon2> &result);
void add_vertex(const Vertex &data)
Add a vertex of a contour to the tessellator.
Definition tessellator.cpp:163
void end_polygon()
Finish the current polygon.
Definition tessellator.cpp:233
void begin_polygon()
Begin the tessellation of a complex polygon.
Definition tessellator.cpp:152
WindingRule
The winding rule (default rule is ODD, modify if needed)
Definition tessellator.h:123
Tessellator()
Constructor.
Definition tessellator.cpp:105
void begin_contour()
Begin a contour of a complex polygon (a polygon may have multiple contours).
Definition tessellator.cpp:158
~Tessellator()
Destructor.
Definition tessellator.cpp:129
unsigned int num_elements_in_polygon() const
The number of elements (triangle or contour) in the last polygon.
Definition tessellator.h:282
const std::vector< Vertex * > & vertices() const
The list of vertices in the result.
Definition tessellator.cpp:238
void reset()
Clear all recorded data (triangle list and vertices) and restart index counter.
Definition tessellator.cpp:382
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 it...
Definition tessellator.h:275
void set_winding_rule(WindingRule rule)
Set the winding rule. The new rule will be effective until being changed by calling this function aga...
Definition tessellator.cpp:140
void end_contour()
Finish the current contour of a polygon.
Definition tessellator.cpp:228
void set_boundary_only(bool b)
Set the working mode of the tessellator.
Definition tessellator.cpp:135
Base class for vector types. It provides generic functionality for N dimensional vectors.
Definition vec.h:30
static size_t size()
Returns the dimension/size of this vector.
Definition vec.h:79
Definition collider.cpp:182
Vec< 3, float > vec3
A 3D point/vector of float type.
Definition types.h:44
GenericPolygon< float > Polygon2
A 2D polygon of float type.
Definition types.h:116
Vec< 2, float > vec2
A 2D point/vector of float type.
Definition types.h:42
Vertex(std::size_t size=0, int idx=0)
Initialize with a known size but memory is allocated without data initialization.
Definition tessellator.h:86
void append(const Vec &v)
Append a property (e.g., color, texture coordinates) to this vertex.
Definition tessellator.h:103
Vertex(const vec3 &xyz, int idx=0)
Initialize with xyz coordinates and an optional index.
Definition tessellator.h:67
int index
The index of this vertex. This can be used to carry and map to the original vertex index.
Definition tessellator.h:109
Vertex(const Vertex &v, int idx=0)
Copy constructor.
Definition tessellator.h:94
Vertex(const FT *data, std::size_t size, int idx=0)
Initialize from a C-style array.
Definition tessellator.h:78