use clipper and add missing vertices to avoid missing triangles

This commit is contained in:
Konstantin Käfer
2014-02-27 16:00:49 +01:00
parent ea80daa129
commit eadafede08
4 changed files with 5097 additions and 145 deletions

398
include/clipper/clipper.hpp Executable file
View File

@@ -0,0 +1,398 @@
/*******************************************************************************
* *
* Author : Angus Johnson *
* Version : 6.1.3a *
* Date : 22 January 2014 *
* Website : http://www.angusj.com *
* Copyright : Angus Johnson 2010-2014 *
* *
* License: *
* Use, modification & distribution is subject to Boost Software License Ver 1. *
* http://www.boost.org/LICENSE_1_0.txt *
* *
* Attributions: *
* The code in this library is an extension of Bala Vatti's clipping algorithm: *
* "A generic solution to polygon clipping" *
* Communications of the ACM, Vol 35, Issue 7 (July 1992) pp 56-63. *
* http://portal.acm.org/citation.cfm?id=129906 *
* *
* Computer graphics and geometric modeling: implementation and algorithms *
* By Max K. Agoston *
* Springer; 1 edition (January 4, 2005) *
* http://books.google.com/books?q=vatti+clipping+agoston *
* *
* See also: *
* "Polygon Offsetting by Computing Winding Numbers" *
* Paper no. DETC2005-85513 pp. 565-575 *
* ASME 2005 International Design Engineering Technical Conferences *
* and Computers and Information in Engineering Conference (IDETC/CIE2005) *
* September 24-28, 2005 , Long Beach, California, USA *
* http://www.me.berkeley.edu/~mcmains/pubs/DAC05OffsetPolygon.pdf *
* *
*******************************************************************************/
#ifndef clipper_hpp
#define clipper_hpp
#define CLIPPER_VERSION "6.1.3"
//use_int32: When enabled 32bit ints are used instead of 64bit ints. This
//improve performance but coordinate values are limited to the range +/- 46340
//#define use_int32
//use_xyz: adds a Z member to IntPoint. Adds a minor cost to perfomance.
//#define use_xyz
//use_lines: Enables line clipping. Adds a very minor cost to performance.
//#define use_lines
//use_deprecated: Enables support for the obsolete OffsetPaths() function
//which has been replace with the ClipperOffset class.
#define use_deprecated
#include <vector>
#include <set>
#include <stdexcept>
#include <cstring>
#include <cstdlib>
#include <ostream>
#include <functional>
namespace ClipperLib {
enum ClipType { ctIntersection, ctUnion, ctDifference, ctXor };
enum PolyType { ptSubject, ptClip };
//By far the most widely used winding rules for polygon filling are
//EvenOdd & NonZero (GDI, GDI+, XLib, OpenGL, Cairo, AGG, Quartz, SVG, Gr32)
//Others rules include Positive, Negative and ABS_GTR_EQ_TWO (only in OpenGL)
//see http://glprogramming.com/red/chapter11.html
enum PolyFillType { pftEvenOdd, pftNonZero, pftPositive, pftNegative };
#ifdef use_int32
typedef int cInt;
typedef unsigned int cUInt;
#else
typedef signed long long cInt;
typedef unsigned long long cUInt;
#endif
struct IntPoint {
cInt X;
cInt Y;
#ifdef use_xyz
cInt Z;
IntPoint(cInt x = 0, cInt y = 0, cInt z = 0): X(x), Y(y), Z(z) {};
#else
IntPoint(cInt x = 0, cInt y = 0): X(x), Y(y) {};
#endif
friend inline bool operator== (const IntPoint& a, const IntPoint& b)
{
return a.X == b.X && a.Y == b.Y;
}
friend inline bool operator!= (const IntPoint& a, const IntPoint& b)
{
return a.X != b.X || a.Y != b.Y;
}
};
//------------------------------------------------------------------------------
typedef std::vector< IntPoint > Path;
typedef std::vector< Path > Paths;
inline Path& operator <<(Path& poly, const IntPoint& p) {poly.push_back(p); return poly;}
inline Paths& operator <<(Paths& polys, const Path& p) {polys.push_back(p); return polys;}
std::ostream& operator <<(std::ostream &s, const IntPoint &p);
std::ostream& operator <<(std::ostream &s, const Path &p);
std::ostream& operator <<(std::ostream &s, const Paths &p);
struct DoublePoint
{
double X;
double Y;
DoublePoint(double x = 0, double y = 0) : X(x), Y(y) {}
DoublePoint(IntPoint ip) : X((double)ip.X), Y((double)ip.Y) {}
};
//------------------------------------------------------------------------------
#ifdef use_xyz
typedef void (*TZFillCallback)(IntPoint& z1, IntPoint& z2, IntPoint& pt);
#endif
enum InitOptions {ioReverseSolution = 1, ioStrictlySimple = 2, ioPreserveCollinear = 4};
enum JoinType {jtSquare, jtRound, jtMiter};
enum EndType {etClosedPolygon, etClosedLine, etOpenButt, etOpenSquare, etOpenRound};
#ifdef use_deprecated
enum EndType_ {etClosed, etButt = 2, etSquare, etRound};
#endif
class PolyNode;
typedef std::vector< PolyNode* > PolyNodes;
class PolyNode
{
public:
PolyNode();
Path Contour;
PolyNodes Childs;
PolyNode* Parent;
PolyNode* GetNext() const;
bool IsHole() const;
bool IsOpen() const;
int ChildCount() const;
private:
unsigned Index; //node index in Parent.Childs
bool m_IsOpen;
JoinType m_jointype;
EndType m_endtype;
PolyNode* GetNextSiblingUp() const;
void AddChild(PolyNode& child);
friend class Clipper; //to access Index
friend class ClipperOffset;
};
class PolyTree: public PolyNode
{
public:
~PolyTree(){Clear();};
PolyNode* GetFirst() const;
void Clear();
int Total() const;
private:
PolyNodes AllNodes;
friend class Clipper; //to access AllNodes
};
bool Orientation(const Path &poly);
double Area(const Path &poly);
int PointInPolygon(const IntPoint &pt, const Path &path);
#ifdef use_deprecated
void OffsetPaths(const Paths &in_polys, Paths &out_polys,
double delta, JoinType jointype, EndType_ endtype, double limit = 0);
#endif
void SimplifyPolygon(const Path &in_poly, Paths &out_polys, PolyFillType fillType = pftEvenOdd);
void SimplifyPolygons(const Paths &in_polys, Paths &out_polys, PolyFillType fillType = pftEvenOdd);
void SimplifyPolygons(Paths &polys, PolyFillType fillType = pftEvenOdd);
void CleanPolygon(const Path& in_poly, Path& out_poly, double distance = 1.415);
void CleanPolygon(Path& poly, double distance = 1.415);
void CleanPolygons(const Paths& in_polys, Paths& out_polys, double distance = 1.415);
void CleanPolygons(Paths& polys, double distance = 1.415);
void MinkowskiSum(const Path& pattern, const Path& path, Paths& solution, bool pathIsClosed);
void MinkowskiSum(const Path& pattern, const Paths& paths,
Paths& solution, PolyFillType pathFillType, bool pathIsClosed);
void MinkowskiDiff(const Path& poly1, const Path& poly2, Paths& solution);
void PolyTreeToPaths(const PolyTree& polytree, Paths& paths);
void ClosedPathsFromPolyTree(const PolyTree& polytree, Paths& paths);
void OpenPathsFromPolyTree(PolyTree& polytree, Paths& paths);
void ReversePath(Path& p);
void ReversePaths(Paths& p);
struct IntRect { cInt left; cInt top; cInt right; cInt bottom; };
//enums that are used internally ...
enum EdgeSide { esLeft = 1, esRight = 2};
//forward declarations (for stuff used internally) ...
struct TEdge;
struct IntersectNode;
struct LocalMinima;
struct Scanbeam;
struct OutPt;
struct OutRec;
struct Join;
typedef std::vector < OutRec* > PolyOutList;
typedef std::vector < TEdge* > EdgeList;
typedef std::vector < Join* > JoinList;
typedef std::vector < IntersectNode* > IntersectList;
//------------------------------------------------------------------------------
//ClipperBase is the ancestor to the Clipper class. It should not be
//instantiated directly. This class simply abstracts the conversion of sets of
//polygon coordinates into edge objects that are stored in a LocalMinima list.
class ClipperBase
{
public:
ClipperBase();
virtual ~ClipperBase();
bool AddPath(const Path &pg, PolyType PolyTyp, bool Closed);
bool AddPaths(const Paths &ppg, PolyType PolyTyp, bool Closed);
virtual void Clear();
IntRect GetBounds();
bool PreserveCollinear() {return m_PreserveCollinear;};
void PreserveCollinear(bool value) {m_PreserveCollinear = value;};
protected:
void DisposeLocalMinimaList();
TEdge* AddBoundsToLML(TEdge *e, bool IsClosed);
void PopLocalMinima();
virtual void Reset();
TEdge* ProcessBound(TEdge* E, bool IsClockwise);
void InsertLocalMinima(LocalMinima *newLm);
void DoMinimaLML(TEdge* E1, TEdge* E2, bool IsClosed);
TEdge* DescendToMin(TEdge *&E);
void AscendToMax(TEdge *&E, bool Appending, bool IsClosed);
LocalMinima *m_CurrentLM;
LocalMinima *m_MinimaList;
bool m_UseFullRange;
EdgeList m_edges;
bool m_PreserveCollinear;
bool m_HasOpenPaths;
};
//------------------------------------------------------------------------------
class Clipper : public virtual ClipperBase
{
public:
Clipper(int initOptions = 0);
~Clipper();
bool Execute(ClipType clipType,
Paths &solution,
PolyFillType subjFillType = pftEvenOdd,
PolyFillType clipFillType = pftEvenOdd);
bool Execute(ClipType clipType,
PolyTree &polytree,
PolyFillType subjFillType = pftEvenOdd,
PolyFillType clipFillType = pftEvenOdd);
bool ReverseSolution() {return m_ReverseOutput;};
void ReverseSolution(bool value) {m_ReverseOutput = value;};
bool StrictlySimple() {return m_StrictSimple;};
void StrictlySimple(bool value) {m_StrictSimple = value;};
//set the callback function for z value filling on intersections (otherwise Z is 0)
#ifdef use_xyz
void ZFillFunction(TZFillCallback zFillFunc);
#endif
protected:
void Reset();
virtual bool ExecuteInternal();
private:
PolyOutList m_PolyOuts;
JoinList m_Joins;
JoinList m_GhostJoins;
IntersectList m_IntersectList;
ClipType m_ClipType;
std::set< cInt, std::greater<cInt> > m_Scanbeam;
TEdge *m_ActiveEdges;
TEdge *m_SortedEdges;
bool m_ExecuteLocked;
PolyFillType m_ClipFillType;
PolyFillType m_SubjFillType;
bool m_ReverseOutput;
bool m_UsingPolyTree;
bool m_StrictSimple;
#ifdef use_xyz
TZFillCallback m_ZFill; //custom callback
#endif
void SetWindingCount(TEdge& edge);
bool IsEvenOddFillType(const TEdge& edge) const;
bool IsEvenOddAltFillType(const TEdge& edge) const;
void InsertScanbeam(const cInt Y);
cInt PopScanbeam();
void InsertLocalMinimaIntoAEL(const cInt botY);
void InsertEdgeIntoAEL(TEdge *edge, TEdge* startEdge);
void AddEdgeToSEL(TEdge *edge);
void CopyAELToSEL();
void DeleteFromSEL(TEdge *e);
void DeleteFromAEL(TEdge *e);
void UpdateEdgeIntoAEL(TEdge *&e);
void SwapPositionsInSEL(TEdge *edge1, TEdge *edge2);
bool IsContributing(const TEdge& edge) const;
bool IsTopHorz(const cInt XPos);
void SwapPositionsInAEL(TEdge *edge1, TEdge *edge2);
void DoMaxima(TEdge *e);
void PrepareHorzJoins(TEdge* horzEdge, bool isTopOfScanbeam);
void ProcessHorizontals(bool IsTopOfScanbeam);
void ProcessHorizontal(TEdge *horzEdge, bool isTopOfScanbeam);
void AddLocalMaxPoly(TEdge *e1, TEdge *e2, const IntPoint &pt);
OutPt* AddLocalMinPoly(TEdge *e1, TEdge *e2, const IntPoint &pt);
OutRec* GetOutRec(int idx);
void AppendPolygon(TEdge *e1, TEdge *e2);
void IntersectEdges(TEdge *e1, TEdge *e2,
const IntPoint &pt, bool protect = false);
OutRec* CreateOutRec();
OutPt* AddOutPt(TEdge *e, const IntPoint &pt);
void DisposeAllOutRecs();
void DisposeOutRec(PolyOutList::size_type index);
bool ProcessIntersections(const cInt botY, const cInt topY);
void BuildIntersectList(const cInt botY, const cInt topY);
void ProcessIntersectList();
void ProcessEdgesAtTopOfScanbeam(const cInt topY);
void BuildResult(Paths& polys);
void BuildResult2(PolyTree& polytree);
void SetHoleState(TEdge *e, OutRec *outrec);
void DisposeIntersectNodes();
bool FixupIntersectionOrder();
void FixupOutPolygon(OutRec &outrec);
bool IsHole(TEdge *e);
bool FindOwnerFromSplitRecs(OutRec &outRec, OutRec *&currOrfl);
void FixHoleLinkage(OutRec &outrec);
void AddJoin(OutPt *op1, OutPt *op2, const IntPoint offPt);
void ClearJoins();
void ClearGhostJoins();
void AddGhostJoin(OutPt *op, const IntPoint offPt);
bool JoinPoints(Join *j, OutRec* outRec1, OutRec* outRec2);
void JoinCommonEdges();
void DoSimplePolygons();
void FixupFirstLefts1(OutRec* OldOutRec, OutRec* NewOutRec);
void FixupFirstLefts2(OutRec* OldOutRec, OutRec* NewOutRec);
#ifdef use_xyz
void SetZ(IntPoint& pt, TEdge& e);
#endif
};
//------------------------------------------------------------------------------
class ClipperOffset
{
public:
ClipperOffset(double miterLimit = 2.0, double roundPrecision = 0.25);
~ClipperOffset();
void AddPath(const Path& path, JoinType joinType, EndType endType);
void AddPaths(const Paths& paths, JoinType joinType, EndType endType);
void Execute(Paths& solution, double delta);
void Execute(PolyTree& solution, double delta);
void Clear();
double MiterLimit;
double ArcTolerance;
private:
Paths m_destPolys;
Path m_srcPoly;
Path m_destPoly;
std::vector<DoublePoint> m_normals;
double m_delta, m_sinA, m_sin, m_cos;
double m_miterLim, m_StepsPerRad;
IntPoint m_lowest;
PolyNode m_polyNodes;
void FixOrientations();
void DoOffset(double delta);
void OffsetPoint(int j, int& k, JoinType jointype);
void DoSquare(int j, int k);
void DoMiter(int j, int k, double r);
void DoRound(int j, int k);
};
//------------------------------------------------------------------------------
class clipperException : public std::exception
{
public:
clipperException(const char* description): m_descr(description) {}
virtual ~clipperException() throw() {}
virtual const char* what() const throw() {return m_descr.c_str();}
private:
std::string m_descr;
};
//------------------------------------------------------------------------------
} //ClipperLib namespace
#endif //clipper_hpp

View File

@@ -6,6 +6,7 @@
#include <llmr/geometry/elements_buffer.hpp>
#include <llmr/geometry/fill_buffer.hpp>
#include <clipper/clipper.hpp>
#include <libtess2/tesselator.h>
#include <vector>
@@ -47,8 +48,6 @@ public:
virtual void render(Painter& painter, const std::string& layer_name, const Tile::ID& id);
void addGeometry(pbf& data);
void addGeometry(const std::vector<Coordinate>& line);
void addGeometry(const std::vector<std::vector<TESSreal>>& lines);
bool empty() const;
void tessellate();
@@ -62,6 +61,7 @@ public:
private:
TESSalloc *allocator;
TESStesselator *tesselator;
ClipperLib::Clipper clipper;
std::shared_ptr<FillVertexBuffer> vertexBuffer;
std::shared_ptr<TriangleElementsBuffer> triangleElementsBuffer;
@@ -75,11 +75,11 @@ private:
std::vector<triangle_group_type> triangleGroups;
std::vector<line_group_type> lineGroups;
std::vector<TESSreal> line;
std::vector<ClipperLib::IntPoint> line;
bool hasVertices = false;
static const int vertexSize = 2;
static const int stride = sizeof(TESSreal) *vertexSize;
static const int stride = sizeof(TESSreal) * vertexSize;
static const int vertices_per_group = 3;
};

4610
src/clipper/clipper.cpp Executable file

File diff suppressed because it is too large Load Diff

View File

@@ -75,17 +75,16 @@ void FillBucket::addGeometry(pbf& geom) {
while ((cmd = geometry.next(x, y)) != Geometry::end) {
if (cmd == Geometry::move_to) {
if (line.size()) {
tessAddContour(tesselator, vertexSize, line.data(), stride, line.size() / vertexSize);
clipper.AddPath(line, ClipperLib::ptSubject, true);
line.clear();
hasVertices = true;
}
}
line.push_back(x);
line.push_back(y);
line.emplace_back(x, y);
}
if (line.size()) {
tessAddContour(tesselator, vertexSize, line.data(), stride, line.size() / vertexSize);
clipper.AddPath(line, ClipperLib::ptSubject, true);
line.clear();
hasVertices = true;
}
@@ -95,162 +94,107 @@ void FillBucket::tessellate() {
if (!hasVertices) {
return;
}
hasVertices = false;
// First combine contours and then triangulate, this removes unnecessary inner vertices.
if (tessTesselate(tesselator, TESS_WINDING_POSITIVE, TESS_BOUNDARY_CONTOURS, 0, 0, 0)) {
const TESSreal *vertices = tessGetVertices(tesselator);
const int vertex_count = tessGetVertexCount(tesselator);
const int element_count = tessGetElementCount(tesselator);
const TESSindex *elements = tessGetElements(tesselator);
if (vertex_count > 65536) {
throw geometry_too_long_exception();
}
std::vector<std::vector<ClipperLib::IntPoint>> polygons;
clipper.Execute(ClipperLib::ctUnion, polygons, ClipperLib::pftPositive);
clipper.Clear();
for (int i = 0; i < vertex_count; ++i) {
vertexBuffer->add(vertices[i * 2], vertices[i * 2 + 1]);
}
if (!lineGroups.size() || (lineGroups.back().vertex_length + vertex_count > 65535)) {
// Move to a new group because the old one can't hold the geometry.
lineGroups.emplace_back();
}
// We're generating triangle fans, so we always start with the first
// coordinate in this polygon.
line_group_type& group = lineGroups.back();
uint32_t index = group.vertex_length;
for (int i = 0; i < element_count; ++i) {
const TESSindex group_start = elements[i * 2];
const TESSindex group_end = group_start + elements[i * 2 + 1];
for (int i = group_start; i < group_end; ++i) {
const TESSindex prevI = (i == group_start ? group_end : i) - 1;
lineElementsBuffer->add(index + prevI, index + i);
}
}
// Add a line from the last vertex to the first vertex.
// lineElementsBuffer->add(index + vertex_count - 1, index);
group.vertex_length += vertex_count;
group.elements_length += vertex_count;
for (int i = 0; i < element_count; ++i) {
const TESSindex group_start = elements[i * 2];
const TESSindex group_count = elements[i * 2 + 1];
const TESSreal *group_vertices = &vertices[group_start * 2];
tessAddContour(tesselator, 2, group_vertices, stride, group_count);
}
if (tessTesselate(tesselator, TESS_WINDING_POSITIVE, TESS_POLYGONS, vertices_per_group, 2, 0)) {
const TESSindex *vertex_indices = tessGetVertexIndices(tesselator);
const TESSindex *elements = tessGetElements(tesselator);
const int element_count = tessGetElementCount(tesselator);
if (!triangleGroups.size() || (triangleGroups.back().vertex_length + vertex_count > 65535)) {
// Move to a new group because the old one can't hold the geometry.
triangleGroups.emplace_back();
}
// We're generating triangle fans, so we always start with the first
// coordinate in this polygon.
triangle_group_type& group = triangleGroups.back();
uint32_t index = group.vertex_length;
for (int i = 0; i < element_count; ++i) {
const TESSindex *element_group = &elements[i * vertices_per_group];
if (element_group[0] != TESS_UNDEF && element_group[1] != TESS_UNDEF && element_group[2] != TESS_UNDEF) {
const TESSindex a = vertex_indices[element_group[0]];
const TESSindex b = vertex_indices[element_group[1]];
const TESSindex c = vertex_indices[element_group[2]];
if (a != TESS_UNDEF && b != TESS_UNDEF && c != TESS_UNDEF) {
triangleElementsBuffer->add(index + a, index + b, index + c);
} else {
// TODO: We're missing a vertex that was not part of the line.
fprintf(stderr, "undefined element buffer\n");
}
} else {
fprintf(stderr, "undefined element buffer\n");
}
}
group.vertex_length += vertex_count;
group.elements_length += element_count;
} else {
assert(false && "tesselation failed");
}
} else {
assert(false && "tesselation failed");
}
}
void FillBucket::addGeometry(const std::vector<Coordinate>& line) {
uint32_t vertex_start = vertexBuffer->index();
size_t length = line.size();
// Don't add the first vertex twice.
if (line.front() == line.back()) --length;
for (size_t i = 0; i < length; i++) {
const Coordinate& coord = line[i];
vertexBuffer->add(coord.x, coord.y);
if (polygons.size() == 0) {
return;
}
size_t vertex_end = vertexBuffer->index();
size_t total_vertex_count = 0;
for (const std::vector<ClipperLib::IntPoint>& polygon : polygons) {
total_vertex_count += polygon.size();
}
size_t vertex_count = vertex_end - vertex_start;
if (vertex_count > 65536) {
if (total_vertex_count > 65536) {
throw geometry_too_long_exception();
}
{
if (!triangleGroups.size() || (triangleGroups.back().vertex_length + vertex_count > 65535)) {
if (!lineGroups.size() || (lineGroups.back().vertex_length + total_vertex_count > 65535)) {
// Move to a new group because the old one can't hold the geometry.
lineGroups.emplace_back();
}
line_group_type& lineGroup = lineGroups.back();
uint32_t lineIndex = lineGroup.vertex_length;
for (const std::vector<ClipperLib::IntPoint>& polygon : polygons) {
const size_t group_count = polygon.size();
assert(group_count >= 3);
std::vector<TESSreal> line;
for (const ClipperLib::IntPoint& pt : polygon) {
line.push_back(pt.X);
line.push_back(pt.Y);
vertexBuffer->add(pt.X, pt.Y);
}
for (size_t i = 0; i < group_count; i++) {
const size_t prev_i = (i == 0 ? group_count : i) - 1;
lineElementsBuffer->add(lineIndex + prev_i, lineIndex + i);
}
lineIndex += group_count;
tessAddContour(tesselator, vertexSize, line.data(), stride, line.size() / vertexSize);
}
if (tessTesselate(tesselator, TESS_WINDING_POSITIVE, TESS_POLYGONS, vertices_per_group, vertexSize, 0)) {
const TESSreal *vertices = tessGetVertices(tesselator);
const size_t vertex_count = tessGetVertexCount(tesselator);
TESSindex *vertex_indices = const_cast<TESSindex *>(tessGetVertexIndices(tesselator));
const TESSindex *elements = tessGetElements(tesselator);
const int triangle_count = tessGetElementCount(tesselator);
for (size_t i = 0; i < vertex_count; ++i) {
if (vertex_indices[i] == TESS_UNDEF) {
vertexBuffer->add(round(vertices[i * 2]), round(vertices[i * 2 + 1]));
vertex_indices[i] = total_vertex_count;
total_vertex_count++;
}
}
if (!triangleGroups.size() || (triangleGroups.back().vertex_length + total_vertex_count > 65535)) {
// Move to a new group because the old one can't hold the geometry.
triangleGroups.emplace_back();
}
// We're generating triangle fans, so we always start with the first
// coordinate in this polygon.
triangle_group_type& group = triangleGroups.back();
uint32_t index = group.vertex_length;
for (size_t i = 2; i < vertex_count; ++i) {
triangleElementsBuffer->add(index, index + i - 1, index + i);
triangle_group_type& triangleGroup = triangleGroups.back();
uint32_t triangleIndex = triangleGroup.vertex_length;
for (int i = 0; i < triangle_count; ++i) {
const TESSindex *element_group = &elements[i * vertices_per_group];
if (element_group[0] != TESS_UNDEF && element_group[1] != TESS_UNDEF && element_group[2] != TESS_UNDEF) {
const TESSindex a = vertex_indices[element_group[0]];
const TESSindex b = vertex_indices[element_group[1]];
const TESSindex c = vertex_indices[element_group[2]];
if (a != TESS_UNDEF && b != TESS_UNDEF && c != TESS_UNDEF) {
triangleElementsBuffer->add(triangleIndex + a, triangleIndex + b, triangleIndex + c);
} else {
// TODO: We're missing a vertex that was not part of the line.
fprintf(stderr, "undefined element buffer\n");
}
} else {
fprintf(stderr, "undefined element buffer\n");
}
}
group.vertex_length += vertex_count;
group.elements_length += (vertex_count - 2);
triangleGroup.vertex_length += total_vertex_count;
triangleGroup.elements_length += triangle_count;
} else {
fprintf(stderr, "tessellation failed\n");
}
{
if (!lineGroups.size() || (lineGroups.back().vertex_length + vertex_count > 65535)) {
// Move to a new group because the old one can't hold the geometry.
lineGroups.emplace_back();
}
// We're generating triangle fans, so we always start with the first
// coordinate in this polygon.
line_group_type& group = lineGroups.back();
uint32_t index = group.vertex_length;
for (size_t i = 1; i < vertex_count; ++i) {
lineElementsBuffer->add(index + i - 1, index + i);
}
// Add a line from the last vertex to the first vertex.
lineElementsBuffer->add(index + vertex_count - 1, index);
group.vertex_length += vertex_count;
group.elements_length += vertex_count;
}
lineGroup.vertex_length += total_vertex_count;
lineGroup.elements_length += total_vertex_count;
}
void FillBucket::render(Painter& painter, const std::string& layer_name, const Tile::ID& id) {
@@ -258,7 +202,7 @@ void FillBucket::render(Painter& painter, const std::string& layer_name, const T
}
bool FillBucket::empty() const {
return triangleGroups.empty();
return triangleGroups.empty() && lineGroups.empty();
}
void FillBucket::drawElements(PlainShader& shader) {