ReactOS 0.4.15-dev-7961-gdcf9eb0
sweep.c File Reference
#include "gluos.h"
#include <assert.h>
#include "geom.h"
#include "tess.h"
#include "memalloc.h"
#include "sweep.h"
Include dependency graph for sweep.c:

Go to the source code of this file.

Macros

#define TRUE   1
 
#define FALSE   0
 
#define DebugEvent(tess)
 
#define MAX(x, y)   ((x) >= (y) ? (x) : (y))
 
#define MIN(x, y)   ((x) <= (y) ? (x) : (y))
 
#define AddWinding(eDst, eSrc)
 
#define TOLERANCE_NONZERO   FALSE
 
#define SENTINEL_COORD   (4 * GLU_TESS_MAX_COORD)
 

Functions

static void SweepEvent (GLUtesselator *tess, GLUvertex *vEvent)
 
static void WalkDirtyRegions (GLUtesselator *tess, ActiveRegion *regUp)
 
static int CheckForRightSplice (GLUtesselator *tess, ActiveRegion *regUp)
 
static int EdgeLeq (GLUtesselator *tess, ActiveRegion *reg1, ActiveRegion *reg2)
 
static void DeleteRegion (GLUtesselator *tess, ActiveRegion *reg)
 
static int FixUpperEdge (ActiveRegion *reg, GLUhalfEdge *newEdge)
 
static ActiveRegionTopLeftRegion (ActiveRegion *reg)
 
static ActiveRegionTopRightRegion (ActiveRegion *reg)
 
static ActiveRegionAddRegionBelow (GLUtesselator *tess, ActiveRegion *regAbove, GLUhalfEdge *eNewUp)
 
static GLboolean IsWindingInside (GLUtesselator *tess, int n)
 
static void ComputeWinding (GLUtesselator *tess, ActiveRegion *reg)
 
static void FinishRegion (GLUtesselator *tess, ActiveRegion *reg)
 
static GLUhalfEdgeFinishLeftRegions (GLUtesselator *tess, ActiveRegion *regFirst, ActiveRegion *regLast)
 
static void AddRightEdges (GLUtesselator *tess, ActiveRegion *regUp, GLUhalfEdge *eFirst, GLUhalfEdge *eLast, GLUhalfEdge *eTopLeft, GLboolean cleanUp)
 
static void CallCombine (GLUtesselator *tess, GLUvertex *isect, void *data[4], GLfloat weights[4], int needed)
 
static void SpliceMergeVertices (GLUtesselator *tess, GLUhalfEdge *e1, GLUhalfEdge *e2)
 
static void VertexWeights (GLUvertex *isect, GLUvertex *org, GLUvertex *dst, GLfloat *weights)
 
static void GetIntersectData (GLUtesselator *tess, GLUvertex *isect, GLUvertex *orgUp, GLUvertex *dstUp, GLUvertex *orgLo, GLUvertex *dstLo)
 
static int CheckForLeftSplice (GLUtesselator *tess, ActiveRegion *regUp)
 
static int CheckForIntersect (GLUtesselator *tess, ActiveRegion *regUp)
 
static void ConnectRightVertex (GLUtesselator *tess, ActiveRegion *regUp, GLUhalfEdge *eBottomLeft)
 
static void ConnectLeftDegenerate (GLUtesselator *tess, ActiveRegion *regUp, GLUvertex *vEvent)
 
static void ConnectLeftVertex (GLUtesselator *tess, GLUvertex *vEvent)
 
static void AddSentinel (GLUtesselator *tess, GLdouble t)
 
static void InitEdgeDict (GLUtesselator *tess)
 
static void DoneEdgeDict (GLUtesselator *tess)
 
static void RemoveDegenerateEdges (GLUtesselator *tess)
 
static int InitPriorityQ (GLUtesselator *tess)
 
static void DonePriorityQ (GLUtesselator *tess)
 
static int RemoveDegenerateFaces (GLUmesh *mesh)
 
int __gl_computeInterior (GLUtesselator *tess)
 

Macro Definition Documentation

◆ AddWinding

#define AddWinding (   eDst,
  eSrc 
)
Value:
(eDst->winding += eSrc->winding, \
eDst->Sym->winding += eSrc->Sym->winding)

Definition at line 100 of file sweep.c.

◆ DebugEvent

#define DebugEvent (   tess)

Definition at line 59 of file sweep.c.

◆ FALSE

#define FALSE   0

Definition at line 53 of file sweep.c.

◆ MAX

#define MAX (   x,
  y 
)    ((x) >= (y) ? (x) : (y))

Definition at line 94 of file sweep.c.

◆ MIN

#define MIN (   x,
  y 
)    ((x) <= (y) ? (x) : (y))

Definition at line 95 of file sweep.c.

◆ SENTINEL_COORD

#define SENTINEL_COORD   (4 * GLU_TESS_MAX_COORD)

Definition at line 1126 of file sweep.c.

◆ TOLERANCE_NONZERO

#define TOLERANCE_NONZERO   FALSE

Definition at line 939 of file sweep.c.

◆ TRUE

#define TRUE   1

Definition at line 50 of file sweep.c.

Function Documentation

◆ __gl_computeInterior()

int __gl_computeInterior ( GLUtesselator tess)

Definition at line 1301 of file sweep.c.

1309{
1310 GLUvertex *v, *vNext;
1311
1312 tess->fatalError = FALSE;
1313
1314 /* Each vertex defines an event for our sweep line. Start by inserting
1315 * all the vertices in a priority queue. Events are processed in
1316 * lexicographic order, ie.
1317 *
1318 * e1 < e2 iff e1.x < e2.x || (e1.x == e2.x && e1.y < e2.y)
1319 */
1320 RemoveDegenerateEdges( tess );
1321 if ( !InitPriorityQ( tess ) ) return 0; /* if error */
1322 InitEdgeDict( tess );
1323
1324 /* __gl_pqSortExtractMin */
1325 while( (v = (GLUvertex *)pqExtractMin( tess->pq )) != NULL ) {
1326 for( ;; ) {
1327 vNext = (GLUvertex *)pqMinimum( tess->pq ); /* __gl_pqSortMinimum */
1328 if( vNext == NULL || ! VertEq( vNext, v )) break;
1329
1330 /* Merge together all vertices at exactly the same location.
1331 * This is more efficient than processing them one at a time,
1332 * simplifies the code (see ConnectLeftDegenerate), and is also
1333 * important for correct handling of certain degenerate cases.
1334 * For example, suppose there are two identical edges A and B
1335 * that belong to different contours (so without this code they would
1336 * be processed by separate sweep events). Suppose another edge C
1337 * crosses A and B from above. When A is processed, we split it
1338 * at its intersection point with C. However this also splits C,
1339 * so when we insert B we may compute a slightly different
1340 * intersection point. This might leave two edges with a small
1341 * gap between them. This kind of error is especially obvious
1342 * when using boundary extraction (GLU_TESS_BOUNDARY_ONLY).
1343 */
1344 vNext = (GLUvertex *)pqExtractMin( tess->pq ); /* __gl_pqSortExtractMin*/
1345 SpliceMergeVertices( tess, v->anEdge, vNext->anEdge );
1346 }
1347 SweepEvent( tess, v );
1348 }
1349
1350 /* Set tess->event for debugging purposes */
1351 /* __GL_DICTLISTKEY */ /* __GL_DICTLISTMIN */
1352 tess->event = ((ActiveRegion *) dictKey( dictMin( tess->dict )))->eUp->Org;
1353 DebugEvent( tess );
1354 DoneEdgeDict( tess );
1355 DonePriorityQ( tess );
1356
1357 if ( !RemoveDegenerateFaces( tess->mesh ) ) return 0;
1358 __gl_meshCheckMesh( tess->mesh );
1359
1360 return 1;
1361}
#define dictMin(d)
Definition: dict-list.h:55
#define dictKey(n)
Definition: dict-list.h:52
#define NULL
Definition: types.h:112
void __gl_meshCheckMesh(GLUmesh *mesh)
Definition: mesh.c:742
#define VertEq(u, v)
Definition: geom.h:49
const GLdouble * v
Definition: gl.h:2040
#define pqExtractMin(pq)
#define pqMinimum(pq)
PriorityQ * pq
Definition: tess.h:84
GLUvertex * event
Definition: tess.h:85
GLboolean fatalError
Definition: tess.h:81
GLUmesh * mesh
Definition: tess.h:66
Dict * dict
Definition: tess.h:83
GLUhalfEdge * anEdge
Definition: mesh.h:117
static void InitEdgeDict(GLUtesselator *tess)
Definition: sweep.c:1158
static void RemoveDegenerateEdges(GLUtesselator *tess)
Definition: sweep.c:1199
static int RemoveDegenerateFaces(GLUmesh *mesh)
Definition: sweep.c:1267
static void SweepEvent(GLUtesselator *tess, GLUvertex *vEvent)
Definition: sweep.c:1068
#define DebugEvent(tess)
Definition: sweep.c:59
static int InitPriorityQ(GLUtesselator *tess)
Definition: sweep.c:1233
#define FALSE
Definition: sweep.c:53
static void DoneEdgeDict(GLUtesselator *tess)
Definition: sweep.c:1173
static void DonePriorityQ(GLUtesselator *tess)
Definition: sweep.c:1261
static void SpliceMergeVertices(GLUtesselator *tess, GLUhalfEdge *e1, GLUhalfEdge *e2)
Definition: sweep.c:438

Referenced by gluTessEndPolygon().

◆ AddRegionBelow()

static ActiveRegion * AddRegionBelow ( GLUtesselator tess,
ActiveRegion regAbove,
GLUhalfEdge eNewUp 
)
static

Definition at line 213 of file sweep.c.

222{
223 ActiveRegion *regNew = (ActiveRegion *)memAlloc( sizeof( ActiveRegion ));
224 if (regNew == NULL) longjmp(tess->env,1);
225
226 regNew->eUp = eNewUp;
227 /* __gl_dictListInsertBefore */
228 regNew->nodeUp = dictInsertBefore( tess->dict, regAbove->nodeUp, regNew );
229 if (regNew->nodeUp == NULL) longjmp(tess->env,1);
230 regNew->fixUpperEdge = FALSE;
231 regNew->sentinel = FALSE;
232 regNew->dirty = FALSE;
233
234 eNewUp->activeRegion = regNew;
235 return regNew;
236}
#define dictInsertBefore(dict, node, key)
Definition: dict-list.h:49
#define memAlloc
Definition: memalloc.h:48
GLboolean fixUpperEdge
Definition: sweep.h:69
DictNode * nodeUp
Definition: sweep.h:61
GLboolean dirty
Definition: sweep.h:66
GLUhalfEdge * eUp
Definition: sweep.h:60
GLboolean sentinel
Definition: sweep.h:65
ActiveRegion * activeRegion
Definition: mesh.h:147
jmp_buf env
Definition: tess.h:121

Referenced by AddRightEdges(), and ConnectLeftVertex().

◆ AddRightEdges()

static void AddRightEdges ( GLUtesselator tess,
ActiveRegion regUp,
GLUhalfEdge eFirst,
GLUhalfEdge eLast,
GLUhalfEdge eTopLeft,
GLboolean  cleanUp 
)
static

Definition at line 340 of file sweep.c.

353{
354 ActiveRegion *reg, *regPrev;
355 GLUhalfEdge *e, *ePrev;
356 int firstTime = TRUE;
357
358 /* Insert the new right-going edges in the dictionary */
359 e = eFirst;
360 do {
361 assert( VertLeq( e->Org, e->Dst ));
362 AddRegionBelow( tess, regUp, e->Sym );
363 e = e->Onext;
364 } while ( e != eLast );
365
366 /* Walk *all* right-going edges from e->Org, in the dictionary order,
367 * updating the winding numbers of each region, and re-linking the mesh
368 * edges to match the dictionary ordering (if necessary).
369 */
370 if( eTopLeft == NULL ) {
371 eTopLeft = RegionBelow( regUp )->eUp->Rprev;
372 }
373 regPrev = regUp;
374 ePrev = eTopLeft;
375 for( ;; ) {
376 reg = RegionBelow( regPrev );
377 e = reg->eUp->Sym;
378 if( e->Org != ePrev->Org ) break;
379
380 if( e->Onext != ePrev ) {
381 /* Unlink e from its current position, and relink below ePrev */
382 if ( !__gl_meshSplice( e->Oprev, e ) ) longjmp(tess->env,1);
383 if ( !__gl_meshSplice( ePrev->Oprev, e ) ) longjmp(tess->env,1);
384 }
385 /* Compute the winding number and "inside" flag for the new regions */
386 reg->windingNumber = regPrev->windingNumber - e->winding;
387 reg->inside = IsWindingInside( tess, reg->windingNumber );
388
389 /* Check for two outgoing edges with same slope -- process these
390 * before any intersection tests (see example in __gl_computeInterior).
391 */
392 regPrev->dirty = TRUE;
393 if( ! firstTime && CheckForRightSplice( tess, regPrev )) {
394 AddWinding( e, ePrev );
395 DeleteRegion( tess, regPrev );
396 if ( !__gl_meshDelete( ePrev ) ) longjmp(tess->env,1);
397 }
398 firstTime = FALSE;
399 regPrev = reg;
400 ePrev = e;
401 }
402 regPrev->dirty = TRUE;
403 assert( regPrev->windingNumber - e->winding == reg->windingNumber );
404
405 if( cleanUp ) {
406 /* Check for intersections between newly adjacent edges. */
407 WalkDirtyRegions( tess, regPrev );
408 }
409}
int __gl_meshDelete(GLUhalfEdge *eDel)
Definition: mesh.c:384
int __gl_meshSplice(GLUhalfEdge *eOrg, GLUhalfEdge *eDst)
Definition: mesh.c:328
#define assert(x)
Definition: debug.h:53
void cleanUp()
Definition: main.cpp:469
#define VertLeq(u, v)
Definition: geom.h:50
static int reg
Definition: i386-dis.c:1290
#define e
Definition: ke_i.h:82
int windingNumber
Definition: sweep.h:62
GLUvertex * Org
Definition: mesh.h:143
#define AddWinding(eDst, eSrc)
Definition: sweep.c:100
static GLboolean IsWindingInside(GLUtesselator *tess, int n)
Definition: sweep.c:238
static int CheckForRightSplice(GLUtesselator *tess, ActiveRegion *regUp)
Definition: sweep.c:499
static ActiveRegion * AddRegionBelow(GLUtesselator *tess, ActiveRegion *regAbove, GLUhalfEdge *eNewUp)
Definition: sweep.c:213
static void DeleteRegion(GLUtesselator *tess, ActiveRegion *reg)
Definition: sweep.c:151
static void WalkDirtyRegions(GLUtesselator *tess, ActiveRegion *regUp)
Definition: sweep.c:760
#define TRUE
Definition: sweep.c:50
#define RegionBelow(r)
Definition: sweep.h:74

Referenced by CheckForIntersect(), ConnectLeftDegenerate(), ConnectLeftVertex(), ConnectRightVertex(), and SweepEvent().

◆ AddSentinel()

static void AddSentinel ( GLUtesselator tess,
GLdouble  t 
)
static

Definition at line 1128 of file sweep.c.

1133{
1134 GLUhalfEdge *e;
1136 if (reg == NULL) longjmp(tess->env,1);
1137
1138 e = __gl_meshMakeEdge( tess->mesh );
1139 if (e == NULL) longjmp(tess->env,1);
1140
1141 e->Org->s = SENTINEL_COORD;
1142 e->Org->t = t;
1143 e->Dst->s = -SENTINEL_COORD;
1144 e->Dst->t = t;
1145 tess->event = e->Dst; /* initialize it */
1146
1147 reg->eUp = e;
1148 reg->windingNumber = 0;
1149 reg->inside = FALSE;
1150 reg->fixUpperEdge = FALSE;
1151 reg->sentinel = TRUE;
1152 reg->dirty = FALSE;
1153 reg->nodeUp = dictInsert( tess->dict, reg ); /* __gl_dictListInsertBefore */
1154 if (reg->nodeUp == NULL) longjmp(tess->env,1);
1155}
#define dictInsert(dict, key)
Definition: dict-list.h:48
GLUhalfEdge * __gl_meshMakeEdge(GLUmesh *mesh)
Definition: mesh.c:275
GLdouble GLdouble t
Definition: gl.h:2047
#define SENTINEL_COORD
Definition: sweep.c:1126

Referenced by InitEdgeDict().

◆ CallCombine()

static void CallCombine ( GLUtesselator tess,
GLUvertex isect,
void data[4],
GLfloat  weights[4],
int  needed 
)
static

Definition at line 412 of file sweep.c.

414{
415 GLdouble coords[3];
416
417 /* Copy coord data in case the callback changes it. */
418 coords[0] = isect->coords[0];
419 coords[1] = isect->coords[1];
420 coords[2] = isect->coords[2];
421
422 isect->data = NULL;
424 if( isect->data == NULL ) {
425 if( ! needed ) {
426 isect->data = data[0];
427 } else if( ! tess->fatalError ) {
428 /* The only way fatal error is when two edges are found to intersect,
429 * but the user has not provided the callback necessary to handle
430 * generated intersection points.
431 */
433 tess->fatalError = TRUE;
434 }
435 }
436}
#define GLU_TESS_NEED_COMBINE_CALLBACK
Definition: glu.h:257
double GLdouble
Definition: gl.h:163
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLuint coords
Definition: glext.h:7368
const GLbyte * weights
Definition: glext.h:6523
GLdouble coords[3]
Definition: mesh.h:121
void * data
Definition: mesh.h:118
#define CALL_ERROR_OR_ERROR_DATA(a)
Definition: tess.h:160
#define CALL_COMBINE_OR_COMBINE_DATA(a, b, c, d)
Definition: tess.h:155

Referenced by GetIntersectData(), and SpliceMergeVertices().

◆ CheckForIntersect()

static int CheckForIntersect ( GLUtesselator tess,
ActiveRegion regUp 
)
static

Definition at line 606 of file sweep.c.

616{
617 ActiveRegion *regLo = RegionBelow(regUp);
618 GLUhalfEdge *eUp = regUp->eUp;
619 GLUhalfEdge *eLo = regLo->eUp;
620 GLUvertex *orgUp = eUp->Org;
621 GLUvertex *orgLo = eLo->Org;
622 GLUvertex *dstUp = eUp->Dst;
623 GLUvertex *dstLo = eLo->Dst;
624 GLdouble tMinUp, tMaxLo;
625 GLUvertex isect, *orgMin;
626 GLUhalfEdge *e;
627
628 assert( ! VertEq( dstLo, dstUp ));
629 assert( EdgeSign( dstUp, tess->event, orgUp ) <= 0 );
630 assert( EdgeSign( dstLo, tess->event, orgLo ) >= 0 );
631 assert( orgUp != tess->event && orgLo != tess->event );
632 assert( ! regUp->fixUpperEdge && ! regLo->fixUpperEdge );
633
634 if( orgUp == orgLo ) return FALSE; /* right endpoints are the same */
635
636 tMinUp = MIN( orgUp->t, dstUp->t );
637 tMaxLo = MAX( orgLo->t, dstLo->t );
638 if( tMinUp > tMaxLo ) return FALSE; /* t ranges do not overlap */
639
640 if( VertLeq( orgUp, orgLo )) {
641 if( EdgeSign( dstLo, orgUp, orgLo ) > 0 ) return FALSE;
642 } else {
643 if( EdgeSign( dstUp, orgLo, orgUp ) < 0 ) return FALSE;
644 }
645
646 /* At this point the edges intersect, at least marginally */
647 DebugEvent( tess );
648
649 __gl_edgeIntersect( dstUp, orgUp, dstLo, orgLo, &isect );
650 /* The following properties are guaranteed: */
651 assert( MIN( orgUp->t, dstUp->t ) <= isect.t );
652 assert( isect.t <= MAX( orgLo->t, dstLo->t ));
653 assert( MIN( dstLo->s, dstUp->s ) <= isect.s );
654 assert( isect.s <= MAX( orgLo->s, orgUp->s ));
655
656 if( VertLeq( &isect, tess->event )) {
657 /* The intersection point lies slightly to the left of the sweep line,
658 * so move it until it''s slightly to the right of the sweep line.
659 * (If we had perfect numerical precision, this would never happen
660 * in the first place). The easiest and safest thing to do is
661 * replace the intersection by tess->event.
662 */
663 isect.s = tess->event->s;
664 isect.t = tess->event->t;
665 }
666 /* Similarly, if the computed intersection lies to the right of the
667 * rightmost origin (which should rarely happen), it can cause
668 * unbelievable inefficiency on sufficiently degenerate inputs.
669 * (If you have the test program, try running test54.d with the
670 * "X zoom" option turned on).
671 */
672 orgMin = VertLeq( orgUp, orgLo ) ? orgUp : orgLo;
673 if( VertLeq( orgMin, &isect )) {
674 isect.s = orgMin->s;
675 isect.t = orgMin->t;
676 }
677
678 if( VertEq( &isect, orgUp ) || VertEq( &isect, orgLo )) {
679 /* Easy case -- intersection at one of the right endpoints */
680 (void) CheckForRightSplice( tess, regUp );
681 return FALSE;
682 }
683
684 if( (! VertEq( dstUp, tess->event )
685 && EdgeSign( dstUp, tess->event, &isect ) >= 0)
686 || (! VertEq( dstLo, tess->event )
687 && EdgeSign( dstLo, tess->event, &isect ) <= 0 ))
688 {
689 /* Very unusual -- the new upper or lower edge would pass on the
690 * wrong side of the sweep event, or through it. This can happen
691 * due to very small numerical errors in the intersection calculation.
692 */
693 if( dstLo == tess->event ) {
694 /* Splice dstLo into eUp, and process the new region(s) */
695 if (__gl_meshSplitEdge( eUp->Sym ) == NULL) longjmp(tess->env,1);
696 if ( !__gl_meshSplice( eLo->Sym, eUp ) ) longjmp(tess->env,1);
697 regUp = TopLeftRegion( regUp );
698 if (regUp == NULL) longjmp(tess->env,1);
699 eUp = RegionBelow(regUp)->eUp;
700 FinishLeftRegions( tess, RegionBelow(regUp), regLo );
701 AddRightEdges( tess, regUp, eUp->Oprev, eUp, eUp, TRUE );
702 return TRUE;
703 }
704 if( dstUp == tess->event ) {
705 /* Splice dstUp into eLo, and process the new region(s) */
706 if (__gl_meshSplitEdge( eLo->Sym ) == NULL) longjmp(tess->env,1);
707 if ( !__gl_meshSplice( eUp->Lnext, eLo->Oprev ) ) longjmp(tess->env,1);
708 regLo = regUp;
709 regUp = TopRightRegion( regUp );
710 e = RegionBelow(regUp)->eUp->Rprev;
711 regLo->eUp = eLo->Oprev;
712 eLo = FinishLeftRegions( tess, regLo, NULL );
713 AddRightEdges( tess, regUp, eLo->Onext, eUp->Rprev, e, TRUE );
714 return TRUE;
715 }
716 /* Special case: called from ConnectRightVertex. If either
717 * edge passes on the wrong side of tess->event, split it
718 * (and wait for ConnectRightVertex to splice it appropriately).
719 */
720 if( EdgeSign( dstUp, tess->event, &isect ) >= 0 ) {
721 RegionAbove(regUp)->dirty = regUp->dirty = TRUE;
722 if (__gl_meshSplitEdge( eUp->Sym ) == NULL) longjmp(tess->env,1);
723 eUp->Org->s = tess->event->s;
724 eUp->Org->t = tess->event->t;
725 }
726 if( EdgeSign( dstLo, tess->event, &isect ) <= 0 ) {
727 regUp->dirty = regLo->dirty = TRUE;
728 if (__gl_meshSplitEdge( eLo->Sym ) == NULL) longjmp(tess->env,1);
729 eLo->Org->s = tess->event->s;
730 eLo->Org->t = tess->event->t;
731 }
732 /* leave the rest for ConnectRightVertex */
733 return FALSE;
734 }
735
736 /* General case -- split both edges, splice into new vertex.
737 * When we do the splice operation, the order of the arguments is
738 * arbitrary as far as correctness goes. However, when the operation
739 * creates a new face, the work done is proportional to the size of
740 * the new face. We expect the faces in the processed part of
741 * the mesh (ie. eUp->Lface) to be smaller than the faces in the
742 * unprocessed original contours (which will be eLo->Oprev->Lface).
743 */
744 if (__gl_meshSplitEdge( eUp->Sym ) == NULL) longjmp(tess->env,1);
745 if (__gl_meshSplitEdge( eLo->Sym ) == NULL) longjmp(tess->env,1);
746 if ( !__gl_meshSplice( eLo->Oprev, eUp ) ) longjmp(tess->env,1);
747 eUp->Org->s = isect.s;
748 eUp->Org->t = isect.t;
749 eUp->Org->pqHandle = pqInsert( tess->pq, eUp->Org ); /* __gl_pqSortInsert */
750 if (eUp->Org->pqHandle == LONG_MAX) {
751 pqDeletePriorityQ(tess->pq); /* __gl_pqSortDeletePriorityQ */
752 tess->pq = NULL;
753 longjmp(tess->env,1);
754 }
755 GetIntersectData( tess, eUp->Org, orgUp, dstUp, orgLo, dstLo );
756 RegionAbove(regUp)->dirty = regUp->dirty = regLo->dirty = TRUE;
757 return FALSE;
758}
GLUhalfEdge * __gl_meshSplitEdge(GLUhalfEdge *eOrg)
Definition: mesh.c:475
void __gl_edgeIntersect(GLUvertex *o1, GLUvertex *d1, GLUvertex *o2, GLUvertex *d2, GLUvertex *v)
Definition: geom.c:203
#define EdgeSign(u, v, w)
Definition: geom.h:55
#define LONG_MAX
Definition: limits.h:43
#define pqDeletePriorityQ(pq)
#define pqInsert(pq, key)
GLUhalfEdge * Lnext
Definition: mesh.h:142
GLUhalfEdge * Onext
Definition: mesh.h:141
GLUhalfEdge * Sym
Definition: mesh.h:140
GLdouble t
Definition: mesh.h:122
GLdouble s
Definition: mesh.h:122
long pqHandle
Definition: mesh.h:123
static GLUhalfEdge * FinishLeftRegions(GLUtesselator *tess, ActiveRegion *regFirst, ActiveRegion *regLast)
Definition: sweep.c:284
static ActiveRegion * TopLeftRegion(ActiveRegion *reg)
Definition: sweep.c:180
#define MIN(x, y)
Definition: sweep.c:95
static void AddRightEdges(GLUtesselator *tess, ActiveRegion *regUp, GLUhalfEdge *eFirst, GLUhalfEdge *eLast, GLUhalfEdge *eTopLeft, GLboolean cleanUp)
Definition: sweep.c:340
static void GetIntersectData(GLUtesselator *tess, GLUvertex *isect, GLUvertex *orgUp, GLUvertex *dstUp, GLUvertex *orgLo, GLUvertex *dstLo)
Definition: sweep.c:475
static ActiveRegion * TopRightRegion(ActiveRegion *reg)
Definition: sweep.c:202
#define MAX(x, y)
Definition: sweep.c:94
#define RegionAbove(r)
Definition: sweep.h:75

Referenced by ConnectRightVertex(), and WalkDirtyRegions().

◆ CheckForLeftSplice()

static int CheckForLeftSplice ( GLUtesselator tess,
ActiveRegion regUp 
)
static

Definition at line 556 of file sweep.c.

575{
576 ActiveRegion *regLo = RegionBelow(regUp);
577 GLUhalfEdge *eUp = regUp->eUp;
578 GLUhalfEdge *eLo = regLo->eUp;
579 GLUhalfEdge *e;
580
581 assert( ! VertEq( eUp->Dst, eLo->Dst ));
582
583 if( VertLeq( eUp->Dst, eLo->Dst )) {
584 if( EdgeSign( eUp->Dst, eLo->Dst, eUp->Org ) < 0 ) return FALSE;
585
586 /* eLo->Dst is above eUp, so splice eLo->Dst into eUp */
587 RegionAbove(regUp)->dirty = regUp->dirty = TRUE;
588 e = __gl_meshSplitEdge( eUp );
589 if (e == NULL) longjmp(tess->env,1);
590 if ( !__gl_meshSplice( eLo->Sym, e ) ) longjmp(tess->env,1);
591 e->Lface->inside = regUp->inside;
592 } else {
593 if( EdgeSign( eLo->Dst, eUp->Dst, eLo->Org ) > 0 ) return FALSE;
594
595 /* eUp->Dst is below eLo, so splice eUp->Dst into eLo */
596 regUp->dirty = regLo->dirty = TRUE;
597 e = __gl_meshSplitEdge( eLo );
598 if (e == NULL) longjmp(tess->env,1);
599 if ( !__gl_meshSplice( eUp->Lnext, eLo->Sym ) ) longjmp(tess->env,1);
600 e->Rface->inside = regUp->inside;
601 }
602 return TRUE;
603}
GLboolean inside
Definition: sweep.h:64

Referenced by WalkDirtyRegions().

◆ CheckForRightSplice()

static int CheckForRightSplice ( GLUtesselator tess,
ActiveRegion regUp 
)
static

Definition at line 499 of file sweep.c.

525{
526 ActiveRegion *regLo = RegionBelow(regUp);
527 GLUhalfEdge *eUp = regUp->eUp;
528 GLUhalfEdge *eLo = regLo->eUp;
529
530 if( VertLeq( eUp->Org, eLo->Org )) {
531 if( EdgeSign( eLo->Dst, eUp->Org, eLo->Org ) > 0 ) return FALSE;
532
533 /* eUp->Org appears to be below eLo */
534 if( ! VertEq( eUp->Org, eLo->Org )) {
535 /* Splice eUp->Org into eLo */
536 if ( __gl_meshSplitEdge( eLo->Sym ) == NULL) longjmp(tess->env,1);
537 if ( !__gl_meshSplice( eUp, eLo->Oprev ) ) longjmp(tess->env,1);
538 regUp->dirty = regLo->dirty = TRUE;
539
540 } else if( eUp->Org != eLo->Org ) {
541 /* merge the two vertices, discarding eUp->Org */
542 pqDelete( tess->pq, eUp->Org->pqHandle ); /* __gl_pqSortDelete */
543 SpliceMergeVertices( tess, eLo->Oprev, eUp );
544 }
545 } else {
546 if( EdgeSign( eUp->Dst, eLo->Org, eUp->Org ) < 0 ) return FALSE;
547
548 /* eLo->Org appears to be above eUp, so splice eLo->Org into eUp */
549 RegionAbove(regUp)->dirty = regUp->dirty = TRUE;
550 if (__gl_meshSplitEdge( eUp->Sym ) == NULL) longjmp(tess->env,1);
551 if ( !__gl_meshSplice( eLo->Oprev, eUp ) ) longjmp(tess->env,1);
552 }
553 return TRUE;
554}
#define pqDelete(pq, handle)

Referenced by AddRightEdges(), CheckForIntersect(), and WalkDirtyRegions().

◆ ComputeWinding()

static void ComputeWinding ( GLUtesselator tess,
ActiveRegion reg 
)
static

Definition at line 259 of file sweep.c.

260{
261 reg->windingNumber = RegionAbove(reg)->windingNumber + reg->eUp->winding;
262 reg->inside = IsWindingInside( tess, reg->windingNumber );
263}

Referenced by ConnectLeftVertex().

◆ ConnectLeftDegenerate()

static void ConnectLeftDegenerate ( GLUtesselator tess,
ActiveRegion regUp,
GLUvertex vEvent 
)
static

Definition at line 941 of file sweep.c.

948{
949 GLUhalfEdge *e, *eTopLeft, *eTopRight, *eLast;
951
952 e = regUp->eUp;
953 if( VertEq( e->Org, vEvent )) {
954 /* e->Org is an unprocessed vertex - just combine them, and wait
955 * for e->Org to be pulled from the queue
956 */
958 SpliceMergeVertices( tess, e, vEvent->anEdge );
959 return;
960 }
961
962 if( ! VertEq( e->Dst, vEvent )) {
963 /* General case -- splice vEvent into edge e which passes through it */
964 if (__gl_meshSplitEdge( e->Sym ) == NULL) longjmp(tess->env,1);
965 if( regUp->fixUpperEdge ) {
966 /* This edge was fixable -- delete unused portion of original edge */
967 if ( !__gl_meshDelete( e->Onext ) ) longjmp(tess->env,1);
968 regUp->fixUpperEdge = FALSE;
969 }
970 if ( !__gl_meshSplice( vEvent->anEdge, e ) ) longjmp(tess->env,1);
971 SweepEvent( tess, vEvent ); /* recurse */
972 return;
973 }
974
975 /* vEvent coincides with e->Dst, which has already been processed.
976 * Splice in the additional right-going edges.
977 */
979 regUp = TopRightRegion( regUp );
980 reg = RegionBelow( regUp );
981 eTopRight = reg->eUp->Sym;
982 eTopLeft = eLast = eTopRight->Onext;
983 if( reg->fixUpperEdge ) {
984 /* Here e->Dst has only a single fixable edge going right.
985 * We can delete it since now we have some real right-going edges.
986 */
987 assert( eTopLeft != eTopRight ); /* there are some left edges too */
988 DeleteRegion( tess, reg );
989 if ( !__gl_meshDelete( eTopRight ) ) longjmp(tess->env,1);
990 eTopRight = eTopLeft->Oprev;
991 }
992 if ( !__gl_meshSplice( vEvent->anEdge, eTopRight ) ) longjmp(tess->env,1);
993 if( ! EdgeGoesLeft( eTopLeft )) {
994 /* e->Dst had no left-going edges -- indicate this to AddRightEdges() */
995 eTopLeft = NULL;
996 }
997 AddRightEdges( tess, regUp, eTopRight->Onext, eLast, eTopLeft, TRUE );
998}
#define EdgeGoesLeft(e)
Definition: geom.h:65
#define TOLERANCE_NONZERO
Definition: sweep.c:939

Referenced by ConnectLeftVertex().

◆ ConnectLeftVertex()

static void ConnectLeftVertex ( GLUtesselator tess,
GLUvertex vEvent 
)
static

Definition at line 1001 of file sweep.c.

1017{
1018 ActiveRegion *regUp, *regLo, *reg;
1019 GLUhalfEdge *eUp, *eLo, *eNew;
1020 ActiveRegion tmp;
1021
1022 /* assert( vEvent->anEdge->Onext->Onext == vEvent->anEdge ); */
1023
1024 /* Get a pointer to the active region containing vEvent */
1025 tmp.eUp = vEvent->anEdge->Sym;
1026 /* __GL_DICTLISTKEY */ /* __gl_dictListSearch */
1027 regUp = (ActiveRegion *)dictKey( dictSearch( tess->dict, &tmp ));
1028 regLo = RegionBelow( regUp );
1029 eUp = regUp->eUp;
1030 eLo = regLo->eUp;
1031
1032 /* Try merging with U or L first */
1033 if( EdgeSign( eUp->Dst, vEvent, eUp->Org ) == 0 ) {
1034 ConnectLeftDegenerate( tess, regUp, vEvent );
1035 return;
1036 }
1037
1038 /* Connect vEvent to rightmost processed vertex of either chain.
1039 * e->Dst is the vertex that we will connect to vEvent.
1040 */
1041 reg = VertLeq( eLo->Dst, eUp->Dst ) ? regUp : regLo;
1042
1043 if( regUp->inside || reg->fixUpperEdge) {
1044 if( reg == regUp ) {
1045 eNew = __gl_meshConnect( vEvent->anEdge->Sym, eUp->Lnext );
1046 if (eNew == NULL) longjmp(tess->env,1);
1047 } else {
1048 GLUhalfEdge *tempHalfEdge= __gl_meshConnect( eLo->Dnext, vEvent->anEdge);
1049 if (tempHalfEdge == NULL) longjmp(tess->env,1);
1050
1051 eNew = tempHalfEdge->Sym;
1052 }
1053 if( reg->fixUpperEdge ) {
1054 if ( !FixUpperEdge( reg, eNew ) ) longjmp(tess->env,1);
1055 } else {
1056 ComputeWinding( tess, AddRegionBelow( tess, regUp, eNew ));
1057 }
1058 SweepEvent( tess, vEvent );
1059 } else {
1060 /* The new vertex is in a region which does not belong to the polygon.
1061 * We don''t need to connect this vertex to the rest of the mesh.
1062 */
1063 AddRightEdges( tess, regUp, vEvent->anEdge, vEvent->anEdge, NULL, TRUE );
1064 }
1065}
#define dictSearch(dict, key)
Definition: dict-list.h:47
GLUhalfEdge * __gl_meshConnect(GLUhalfEdge *eOrg, GLUhalfEdge *eDst)
Definition: mesh.c:508
static int FixUpperEdge(ActiveRegion *reg, GLUhalfEdge *newEdge)
Definition: sweep.c:166
static void ComputeWinding(GLUtesselator *tess, ActiveRegion *reg)
Definition: sweep.c:259
static void ConnectLeftDegenerate(GLUtesselator *tess, ActiveRegion *regUp, GLUvertex *vEvent)
Definition: sweep.c:941

Referenced by SweepEvent().

◆ ConnectRightVertex()

static void ConnectRightVertex ( GLUtesselator tess,
ActiveRegion regUp,
GLUhalfEdge eBottomLeft 
)
static

Definition at line 847 of file sweep.c.

880{
881 GLUhalfEdge *eNew;
882 GLUhalfEdge *eTopLeft = eBottomLeft->Onext;
883 ActiveRegion *regLo = RegionBelow(regUp);
884 GLUhalfEdge *eUp = regUp->eUp;
885 GLUhalfEdge *eLo = regLo->eUp;
886 int degenerate = FALSE;
887
888 if( eUp->Dst != eLo->Dst ) {
889 (void) CheckForIntersect( tess, regUp );
890 }
891
892 /* Possible new degeneracies: upper or lower edge of regUp may pass
893 * through vEvent, or may coincide with new intersection vertex
894 */
895 if( VertEq( eUp->Org, tess->event )) {
896 if ( !__gl_meshSplice( eTopLeft->Oprev, eUp ) ) longjmp(tess->env,1);
897 regUp = TopLeftRegion( regUp );
898 if (regUp == NULL) longjmp(tess->env,1);
899 eTopLeft = RegionBelow( regUp )->eUp;
900 FinishLeftRegions( tess, RegionBelow(regUp), regLo );
901 degenerate = TRUE;
902 }
903 if( VertEq( eLo->Org, tess->event )) {
904 if ( !__gl_meshSplice( eBottomLeft, eLo->Oprev ) ) longjmp(tess->env,1);
905 eBottomLeft = FinishLeftRegions( tess, regLo, NULL );
906 degenerate = TRUE;
907 }
908 if( degenerate ) {
909 AddRightEdges( tess, regUp, eBottomLeft->Onext, eTopLeft, eTopLeft, TRUE );
910 return;
911 }
912
913 /* Non-degenerate situation -- need to add a temporary, fixable edge.
914 * Connect to the closer of eLo->Org, eUp->Org.
915 */
916 if( VertLeq( eLo->Org, eUp->Org )) {
917 eNew = eLo->Oprev;
918 } else {
919 eNew = eUp;
920 }
921 eNew = __gl_meshConnect( eBottomLeft->Lprev, eNew );
922 if (eNew == NULL) longjmp(tess->env,1);
923
924 /* Prevent cleanup, otherwise eNew might disappear before we've even
925 * had a chance to mark it as a temporary edge.
926 */
927 AddRightEdges( tess, regUp, eNew, eNew->Onext, eNew->Onext, FALSE );
929 WalkDirtyRegions( tess, regUp );
930}
static int CheckForIntersect(GLUtesselator *tess, ActiveRegion *regUp)
Definition: sweep.c:606

Referenced by SweepEvent().

◆ DeleteRegion()

static void DeleteRegion ( GLUtesselator tess,
ActiveRegion reg 
)
static

Definition at line 151 of file sweep.c.

152{
153 if( reg->fixUpperEdge ) {
154 /* It was created with zero winding number, so it better be
155 * deleted with zero winding number (ie. it better not get merged
156 * with a real edge).
157 */
158 assert( reg->eUp->winding == 0 );
159 }
160 reg->eUp->activeRegion = NULL;
161 dictDelete( tess->dict, reg->nodeUp ); /* __gl_dictListDelete */
162 memFree( reg );
163}
#define dictDelete(dict, node)
Definition: dict-list.h:50
#define memFree
Definition: memalloc.h:41

Referenced by AddRightEdges(), ConnectLeftDegenerate(), DeleteObject(), DoneEdgeDict(), FinishRegion(), and WalkDirtyRegions().

◆ DoneEdgeDict()

static void DoneEdgeDict ( GLUtesselator tess)
static

Definition at line 1173 of file sweep.c.

1174{
1176#ifndef NDEBUG
1177 int fixedEdges = 0;
1178#endif
1179
1180 /* __GL_DICTLISTKEY */ /* __GL_DICTLISTMIN */
1181 while( (reg = (ActiveRegion *)dictKey( dictMin( tess->dict ))) != NULL ) {
1182 /*
1183 * At the end of all processing, the dictionary should contain
1184 * only the two sentinel edges, plus at most one "fixable" edge
1185 * created by ConnectRightVertex().
1186 */
1187 if( ! reg->sentinel ) {
1188 assert( reg->fixUpperEdge );
1189 assert( ++fixedEdges == 1 );
1190 }
1191 assert( reg->windingNumber == 0 );
1192 DeleteRegion( tess, reg );
1193/* __gl_meshDelete( reg->eUp );*/
1194 }
1195 dictDeleteDict( tess->dict ); /* __gl_dictListDeleteDict */
1196}
#define dictDeleteDict(dict)
Definition: dict-list.h:45

Referenced by __gl_computeInterior().

◆ DonePriorityQ()

static void DonePriorityQ ( GLUtesselator tess)
static

Definition at line 1261 of file sweep.c.

1262{
1263 pqDeletePriorityQ( tess->pq ); /* __gl_pqSortDeletePriorityQ */
1264}

Referenced by __gl_computeInterior().

◆ EdgeLeq()

static int EdgeLeq ( GLUtesselator tess,
ActiveRegion reg1,
ActiveRegion reg2 
)
static

Definition at line 107 of file sweep.c.

120{
121 GLUvertex *event = tess->event;
122 GLUhalfEdge *e1, *e2;
123 GLdouble t1, t2;
124
125 e1 = reg1->eUp;
126 e2 = reg2->eUp;
127
128 if( e1->Dst == event ) {
129 if( e2->Dst == event ) {
130 /* Two edges right of the sweep line which meet at the sweep event.
131 * Sort them by slope.
132 */
133 if( VertLeq( e1->Org, e2->Org )) {
134 return EdgeSign( e2->Dst, e1->Org, e2->Org ) <= 0;
135 }
136 return EdgeSign( e1->Dst, e2->Org, e1->Org ) >= 0;
137 }
138 return EdgeSign( e2->Dst, event, e2->Org ) <= 0;
139 }
140 if( e2->Dst == event ) {
141 return EdgeSign( e1->Dst, event, e1->Org ) >= 0;
142 }
143
144 /* General case - compute signed distance *from* e1, e2 to event */
145 t1 = EdgeEval( e1->Dst, event, e1->Org );
146 t2 = EdgeEval( e2->Dst, event, e2->Org );
147 return (t1 >= t2);
148}
#define EdgeEval(u, v, w)
Definition: geom.h:54
struct _cl_event * event
Definition: glext.h:7739

Referenced by InitEdgeDict().

◆ FinishLeftRegions()

static GLUhalfEdge * FinishLeftRegions ( GLUtesselator tess,
ActiveRegion regFirst,
ActiveRegion regLast 
)
static

Definition at line 284 of file sweep.c.

298{
299 ActiveRegion *reg, *regPrev;
300 GLUhalfEdge *e, *ePrev;
301
302 regPrev = regFirst;
303 ePrev = regFirst->eUp;
304 while( regPrev != regLast ) {
305 regPrev->fixUpperEdge = FALSE; /* placement was OK */
306 reg = RegionBelow( regPrev );
307 e = reg->eUp;
308 if( e->Org != ePrev->Org ) {
309 if( ! reg->fixUpperEdge ) {
310 /* Remove the last left-going edge. Even though there are no further
311 * edges in the dictionary with this origin, there may be further
312 * such edges in the mesh (if we are adding left edges to a vertex
313 * that has already been processed). Thus it is important to call
314 * FinishRegion rather than just DeleteRegion.
315 */
316 FinishRegion( tess, regPrev );
317 break;
318 }
319 /* If the edge below was a temporary edge introduced by
320 * ConnectRightVertex, now is the time to fix it.
321 */
322 e = __gl_meshConnect( ePrev->Lprev, e->Sym );
323 if (e == NULL) longjmp(tess->env,1);
324 if ( !FixUpperEdge( reg, e ) ) longjmp(tess->env,1);
325 }
326
327 /* Relink edges so that ePrev->Onext == e */
328 if( ePrev->Onext != e ) {
329 if ( !__gl_meshSplice( e->Oprev, e ) ) longjmp(tess->env,1);
330 if ( !__gl_meshSplice( ePrev, e ) ) longjmp(tess->env,1);
331 }
332 FinishRegion( tess, regPrev ); /* may change reg->eUp */
333 ePrev = reg->eUp;
334 regPrev = reg;
335 }
336 return ePrev;
337}
static void FinishRegion(GLUtesselator *tess, ActiveRegion *reg)
Definition: sweep.c:266

Referenced by CheckForIntersect(), ConnectRightVertex(), and SweepEvent().

◆ FinishRegion()

static void FinishRegion ( GLUtesselator tess,
ActiveRegion reg 
)
static

Definition at line 266 of file sweep.c.

274{
275 GLUhalfEdge *e = reg->eUp;
276 GLUface *f = e->Lface;
277
278 f->inside = reg->inside;
279 f->anEdge = e; /* optimization for __gl_meshTessellateMonoRegion() */
280 DeleteRegion( tess, reg );
281}
GLfloat f
Definition: glext.h:7540
Definition: mesh.h:126

Referenced by FinishLeftRegions().

◆ FixUpperEdge()

static int FixUpperEdge ( ActiveRegion reg,
GLUhalfEdge newEdge 
)
static

Definition at line 166 of file sweep.c.

170{
171 assert( reg->fixUpperEdge );
172 if ( !__gl_meshDelete( reg->eUp ) ) return 0;
173 reg->fixUpperEdge = FALSE;
174 reg->eUp = newEdge;
175 newEdge->activeRegion = reg;
176
177 return 1;
178}

Referenced by ConnectLeftVertex(), FinishLeftRegions(), and TopLeftRegion().

◆ GetIntersectData()

static void GetIntersectData ( GLUtesselator tess,
GLUvertex isect,
GLUvertex orgUp,
GLUvertex dstUp,
GLUvertex orgLo,
GLUvertex dstLo 
)
static

Definition at line 475 of file sweep.c.

483{
484 void *data[4];
485 GLfloat weights[4];
486
487 data[0] = orgUp->data;
488 data[1] = dstUp->data;
489 data[2] = orgLo->data;
490 data[3] = dstLo->data;
491
492 isect->coords[0] = isect->coords[1] = isect->coords[2] = 0;
493 VertexWeights( isect, orgUp, dstUp, &weights[0] );
494 VertexWeights( isect, orgLo, dstLo, &weights[2] );
495
496 CallCombine( tess, isect, data, weights, TRUE );
497}
float GLfloat
Definition: gl.h:161
static void CallCombine(GLUtesselator *tess, GLUvertex *isect, void *data[4], GLfloat weights[4], int needed)
Definition: sweep.c:412
static void VertexWeights(GLUvertex *isect, GLUvertex *org, GLUvertex *dst, GLfloat *weights)
Definition: sweep.c:454

Referenced by CheckForIntersect().

◆ InitEdgeDict()

static void InitEdgeDict ( GLUtesselator tess)
static

Definition at line 1158 of file sweep.c.

1163{
1164 /* __gl_dictListNewDict */
1165 tess->dict = dictNewDict( tess, (int (*)(void *, DictKey, DictKey)) EdgeLeq );
1166 if (tess->dict == NULL) longjmp(tess->env,1);
1167
1168 AddSentinel( tess, -SENTINEL_COORD );
1169 AddSentinel( tess, SENTINEL_COORD );
1170}
#define dictNewDict(frame, leq)
Definition: dict-list.h:44
static int EdgeLeq(GLUtesselator *tess, ActiveRegion *reg1, ActiveRegion *reg2)
Definition: sweep.c:107
static void AddSentinel(GLUtesselator *tess, GLdouble t)
Definition: sweep.c:1128

Referenced by __gl_computeInterior().

◆ InitPriorityQ()

static int InitPriorityQ ( GLUtesselator tess)
static

Definition at line 1233 of file sweep.c.

1238{
1239 PriorityQ *pq;
1240 GLUvertex *v, *vHead;
1241
1242 /* __gl_pqSortNewPriorityQ */
1243 pq = tess->pq = pqNewPriorityQ( (int (*)(PQkey, PQkey)) __gl_vertLeq );
1244 if (pq == NULL) return 0;
1245
1246 vHead = &tess->mesh->vHead;
1247 for( v = vHead->next; v != vHead; v = v->next ) {
1248 v->pqHandle = pqInsert( pq, v ); /* __gl_pqSortInsert */
1249 if (v->pqHandle == LONG_MAX) break;
1250 }
1251 if (v != vHead || !pqInit( pq ) ) { /* __gl_pqSortInit */
1252 pqDeletePriorityQ(tess->pq); /* __gl_pqSortDeletePriorityQ */
1253 tess->pq = NULL;
1254 return 0;
1255 }
1256
1257 return 1;
1258}
int __gl_vertLeq(GLUvertex *u, GLUvertex *v)
Definition: geom.c:40
#define pqNewPriorityQ(leq)
#define pqInit(pq)
GLUvertex vHead
Definition: mesh.h:164
GLUvertex * next
Definition: mesh.h:115

Referenced by __gl_computeInterior().

◆ IsWindingInside()

static GLboolean IsWindingInside ( GLUtesselator tess,
int  n 
)
static

Definition at line 238 of file sweep.c.

239{
240 switch( tess->windingRule ) {
242 return (n & 1);
244 return (n != 0);
246 return (n > 0);
248 return (n < 0);
250 return (n >= 2) || (n <= -2);
251 }
252 /*LINTED*/
253 assert( FALSE );
254 /*NOTREACHED*/
255 return GL_FALSE; /* avoid compiler complaints */
256}
#define GLU_TESS_WINDING_NONZERO
Definition: glu.h:261
#define GLU_TESS_WINDING_POSITIVE
Definition: glu.h:262
#define GLU_TESS_WINDING_NEGATIVE
Definition: glu.h:263
#define GLU_TESS_WINDING_ODD
Definition: glu.h:260
#define GLU_TESS_WINDING_ABS_GEQ_TWO
Definition: glu.h:264
#define GL_FALSE
Definition: gl.h:173
GLdouble n
Definition: glext.h:7729
GLenum windingRule
Definition: tess.h:80

Referenced by AddRightEdges(), and ComputeWinding().

◆ RemoveDegenerateEdges()

static void RemoveDegenerateEdges ( GLUtesselator tess)
static

Definition at line 1199 of file sweep.c.

1203{
1204 GLUhalfEdge *e, *eNext, *eLnext;
1205 GLUhalfEdge *eHead = &tess->mesh->eHead;
1206
1207 /*LINTED*/
1208 for( e = eHead->next; e != eHead; e = eNext ) {
1209 eNext = e->next;
1210 eLnext = e->Lnext;
1211
1212 if( VertEq( e->Org, e->Dst ) && e->Lnext->Lnext != e ) {
1213 /* Zero-length edge, contour has at least 3 edges */
1214
1215 SpliceMergeVertices( tess, eLnext, e ); /* deletes e->Org */
1216 if ( !__gl_meshDelete( e ) ) longjmp(tess->env,1); /* e is a self-loop */
1217 e = eLnext;
1218 eLnext = e->Lnext;
1219 }
1220 if( eLnext->Lnext == e ) {
1221 /* Degenerate contour (one or two edges) */
1222
1223 if( eLnext != e ) {
1224 if( eLnext == eNext || eLnext == eNext->Sym ) { eNext = eNext->next; }
1225 if ( !__gl_meshDelete( eLnext ) ) longjmp(tess->env,1);
1226 }
1227 if( e == eNext || e == eNext->Sym ) { eNext = eNext->next; }
1228 if ( !__gl_meshDelete( e ) ) longjmp(tess->env,1);
1229 }
1230 }
1231}
GLUhalfEdge * next
Definition: mesh.h:139
GLUhalfEdge eHead
Definition: mesh.h:166
struct define * next
Definition: compiler.c:65

Referenced by __gl_computeInterior().

◆ RemoveDegenerateFaces()

static int RemoveDegenerateFaces ( GLUmesh mesh)
static

Definition at line 1267 of file sweep.c.

1282{
1283 GLUface *f, *fNext;
1284 GLUhalfEdge *e;
1285
1286 /*LINTED*/
1287 for( f = mesh->fHead.next; f != &mesh->fHead; f = fNext ) {
1288 fNext = f->next;
1289 e = f->anEdge;
1290 assert( e->Lnext != e );
1291
1292 if( e->Lnext->Lnext == e ) {
1293 /* A face with only two edges */
1294 AddWinding( e->Onext, e );
1295 if ( !__gl_meshDelete( e ) ) return 0;
1296 }
1297 }
1298 return 1;
1299}
#define f
Definition: ke_i.h:83
GLUface * next
Definition: mesh.h:127
Definition: mesh.c:198

Referenced by __gl_computeInterior().

◆ SpliceMergeVertices()

static void SpliceMergeVertices ( GLUtesselator tess,
GLUhalfEdge e1,
GLUhalfEdge e2 
)
static

Definition at line 438 of file sweep.c.

444{
445 void *data[4] = { NULL, NULL, NULL, NULL };
446 GLfloat weights[4] = { 0.5, 0.5, 0.0, 0.0 };
447
448 data[0] = e1->Org->data;
449 data[1] = e2->Org->data;
450 CallCombine( tess, e1->Org, data, weights, FALSE );
451 if ( !__gl_meshSplice( e1, e2 ) ) longjmp(tess->env,1);
452}

Referenced by __gl_computeInterior(), CheckForRightSplice(), ConnectLeftDegenerate(), and RemoveDegenerateEdges().

◆ SweepEvent()

static void SweepEvent ( GLUtesselator tess,
GLUvertex vEvent 
)
static

Definition at line 1068 of file sweep.c.

1073{
1074 ActiveRegion *regUp, *reg;
1075 GLUhalfEdge *e, *eTopLeft, *eBottomLeft;
1076
1077 tess->event = vEvent; /* for access in EdgeLeq() */
1078 DebugEvent( tess );
1079
1080 /* Check if this vertex is the right endpoint of an edge that is
1081 * already in the dictionary. In this case we don't need to waste
1082 * time searching for the location to insert new edges.
1083 */
1084 e = vEvent->anEdge;
1085 while( e->activeRegion == NULL ) {
1086 e = e->Onext;
1087 if( e == vEvent->anEdge ) {
1088 /* All edges go right -- not incident to any processed edges */
1089 ConnectLeftVertex( tess, vEvent );
1090 return;
1091 }
1092 }
1093
1094 /* Processing consists of two phases: first we "finish" all the
1095 * active regions where both the upper and lower edges terminate
1096 * at vEvent (ie. vEvent is closing off these regions).
1097 * We mark these faces "inside" or "outside" the polygon according
1098 * to their winding number, and delete the edges from the dictionary.
1099 * This takes care of all the left-going edges from vEvent.
1100 */
1101 regUp = TopLeftRegion( e->activeRegion );
1102 if (regUp == NULL) longjmp(tess->env,1);
1103 reg = RegionBelow( regUp );
1104 eTopLeft = reg->eUp;
1105 eBottomLeft = FinishLeftRegions( tess, reg, NULL );
1106
1107 /* Next we process all the right-going edges from vEvent. This
1108 * involves adding the edges to the dictionary, and creating the
1109 * associated "active regions" which record information about the
1110 * regions between adjacent dictionary edges.
1111 */
1112 if( eBottomLeft->Onext == eTopLeft ) {
1113 /* No right-going edges -- add a temporary "fixable" edge */
1114 ConnectRightVertex( tess, regUp, eBottomLeft );
1115 } else {
1116 AddRightEdges( tess, regUp, eBottomLeft->Onext, eTopLeft, eTopLeft, TRUE );
1117 }
1118}
static void ConnectLeftVertex(GLUtesselator *tess, GLUvertex *vEvent)
Definition: sweep.c:1001
static void ConnectRightVertex(GLUtesselator *tess, ActiveRegion *regUp, GLUhalfEdge *eBottomLeft)
Definition: sweep.c:847

Referenced by __gl_computeInterior(), ConnectLeftDegenerate(), and ConnectLeftVertex().

◆ TopLeftRegion()

static ActiveRegion * TopLeftRegion ( ActiveRegion reg)
static

Definition at line 180 of file sweep.c.

181{
182 GLUvertex *org = reg->eUp->Org;
183 GLUhalfEdge *e;
184
185 /* Find the region above the uppermost edge with the same origin */
186 do {
187 reg = RegionAbove( reg );
188 } while( reg->eUp->Org == org );
189
190 /* If the edge above was a temporary edge introduced by ConnectRightVertex,
191 * now is the time to fix it.
192 */
193 if( reg->fixUpperEdge ) {
194 e = __gl_meshConnect( RegionBelow(reg)->eUp->Sym, reg->eUp->Lnext );
195 if (e == NULL) return NULL;
196 if ( !FixUpperEdge( reg, e ) ) return NULL;
197 reg = RegionAbove( reg );
198 }
199 return reg;
200}
static char org[]
Definition: encode.c:7456

Referenced by CheckForIntersect(), ConnectRightVertex(), and SweepEvent().

◆ TopRightRegion()

static ActiveRegion * TopRightRegion ( ActiveRegion reg)
static

Definition at line 202 of file sweep.c.

203{
204 GLUvertex *dst = reg->eUp->Dst;
205
206 /* Find the region above the uppermost edge with the same destination */
207 do {
208 reg = RegionAbove( reg );
209 } while( reg->eUp->Dst == dst );
210 return reg;
211}
GLenum GLenum dst
Definition: glext.h:6340

Referenced by CheckForIntersect(), and ConnectLeftDegenerate().

◆ VertexWeights()

static void VertexWeights ( GLUvertex isect,
GLUvertex org,
GLUvertex dst,
GLfloat weights 
)
static

Definition at line 454 of file sweep.c.

463{
464 GLdouble t1 = VertL1dist( org, isect );
465 GLdouble t2 = VertL1dist( dst, isect );
466
467 weights[0] = 0.5 * t2 / (t1 + t2);
468 weights[1] = 0.5 * t1 / (t1 + t2);
469 isect->coords[0] += weights[0]*org->coords[0] + weights[1]*dst->coords[0];
470 isect->coords[1] += weights[0]*org->coords[1] + weights[1]*dst->coords[1];
471 isect->coords[2] += weights[0]*org->coords[2] + weights[1]*dst->coords[2];
472}
#define VertL1dist(u, v)
Definition: geom.h:70

Referenced by GetIntersectData().

◆ WalkDirtyRegions()

static void WalkDirtyRegions ( GLUtesselator tess,
ActiveRegion regUp 
)
static

Definition at line 760 of file sweep.c.

769{
770 ActiveRegion *regLo = RegionBelow(regUp);
771 GLUhalfEdge *eUp, *eLo;
772
773 for( ;; ) {
774 /* Find the lowest dirty region (we walk from the bottom up). */
775 while( regLo->dirty ) {
776 regUp = regLo;
777 regLo = RegionBelow(regLo);
778 }
779 if( ! regUp->dirty ) {
780 regLo = regUp;
781 regUp = RegionAbove( regUp );
782 if( regUp == NULL || ! regUp->dirty ) {
783 /* We've walked all the dirty regions */
784 return;
785 }
786 }
787 regUp->dirty = FALSE;
788 eUp = regUp->eUp;
789 eLo = regLo->eUp;
790
791 if( eUp->Dst != eLo->Dst ) {
792 /* Check that the edge ordering is obeyed at the Dst vertices. */
793 if( CheckForLeftSplice( tess, regUp )) {
794
795 /* If the upper or lower edge was marked fixUpperEdge, then
796 * we no longer need it (since these edges are needed only for
797 * vertices which otherwise have no right-going edges).
798 */
799 if( regLo->fixUpperEdge ) {
800 DeleteRegion( tess, regLo );
801 if ( !__gl_meshDelete( eLo ) ) longjmp(tess->env,1);
802 regLo = RegionBelow( regUp );
803 eLo = regLo->eUp;
804 } else if( regUp->fixUpperEdge ) {
805 DeleteRegion( tess, regUp );
806 if ( !__gl_meshDelete( eUp ) ) longjmp(tess->env,1);
807 regUp = RegionAbove( regLo );
808 eUp = regUp->eUp;
809 }
810 }
811 }
812 if( eUp->Org != eLo->Org ) {
813 if( eUp->Dst != eLo->Dst
814 && ! regUp->fixUpperEdge && ! regLo->fixUpperEdge
815 && (eUp->Dst == tess->event || eLo->Dst == tess->event) )
816 {
817 /* When all else fails in CheckForIntersect(), it uses tess->event
818 * as the intersection location. To make this possible, it requires
819 * that tess->event lie between the upper and lower edges, and also
820 * that neither of these is marked fixUpperEdge (since in the worst
821 * case it might splice one of these edges into tess->event, and
822 * violate the invariant that fixable edges are the only right-going
823 * edge from their associated vertex).
824 */
825 if( CheckForIntersect( tess, regUp )) {
826 /* WalkDirtyRegions() was called recursively; we're done */
827 return;
828 }
829 } else {
830 /* Even though we can't use CheckForIntersect(), the Org vertices
831 * may violate the dictionary edge ordering. Check and correct this.
832 */
833 (void) CheckForRightSplice( tess, regUp );
834 }
835 }
836 if( eUp->Org == eLo->Org && eUp->Dst == eLo->Dst ) {
837 /* A degenerate loop consisting of only two edges -- delete it. */
838 AddWinding( eLo, eUp );
839 DeleteRegion( tess, regUp );
840 if ( !__gl_meshDelete( eUp ) ) longjmp(tess->env,1);
841 regUp = RegionAbove( regLo );
842 }
843 }
844}
static int CheckForLeftSplice(GLUtesselator *tess, ActiveRegion *regUp)
Definition: sweep.c:556

Referenced by AddRightEdges(), and ConnectRightVertex().