Computational Geometry Algorithms Library  1.0
Computational Geometry Algorithms Library Documentation
Functions
triangulate.h File Reference
#include "monotone.h"
Include dependency graph for triangulate.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void triangulate ()
 

Function Documentation

void triangulate ( )
4  {
5  DCELFace* walker = Faces.head;
6  vector<pair<DCELVertex *, DCELVertex *> > pendingDiagonals;
7  while (walker) {
8  if (walker->boundaryLength() > 3 && walker->bordered) {
9  vector<pair<DCELVertex *, int> >::iterator it;
10  vector<pair<DCELVertex *, int> > list = walker->sortedVertices();
11  (*(list.end() - 1)).second = -1;
12  stack<pair<DCELVertex *, int> > stck;
13  it = list.begin();
14  stck.push((*it));
15  it++;
16  stck.push((*it));
17  it++;
18  for (; it != list.end(); it++)
19  {
20  if ((*it).second != stck.top().second) {
21  while (stck.size() > 1) {
22  pendingDiagonals.push_back(make_pair(stck.top().first, (*it).first));
23  stck.pop();
24  }
25  stck.pop();
26  stck.push((*(it - 1)));
27  stck.push((*it));
28  }
29  else {
30  pair<DCELVertex *, int> lastPoint;
31  lastPoint = stck.top();
32  stck.pop();
33  while (!stck.empty()) {
34  if ((*it).second == 1) {
35  DCELHalfEdge *edgeWalker = (*it).first->edge;
36  while (edgeWalker->face != walker) edgeWalker = edgeWalker->twin->next;
37  if (orientation(edgeWalker->next->origin, (*it).first, stck.top().first) == CLOCKWISE) {
38  pendingDiagonals.push_back(make_pair(stck.top().first, (*it).first));
39  lastPoint = stck.top();
40  stck.pop();
41  }
42  else break;
43  }
44  else if ((*it).second == -1) {
45  DCELHalfEdge *edgeWalker = (*it).first->getEdgeOnFace(walker);
46  if (orientation(edgeWalker->getPrev()->origin, (*it).first, stck.top().first) == ANTICLOCKWISE) {
47  pendingDiagonals.push_back(make_pair(stck.top().first, (*it).first));
48  lastPoint = stck.top();
49  stck.pop();
50  }
51  else break;
52  }
53  }
54  stck.push(lastPoint);
55  stck.push((*it));
56  }
57  }
58  }
59  walker = walker->next;
60  }
61  for (int i = 0; i < pendingDiagonals.size(); i++) {
62  insertDiagonal(pendingDiagonals[i].first, pendingDiagonals[i].second);
63  }
64 }
DCELHalfEdge * twin
Definition: DCELHalfEdge.h:14
DCELHalfEdge * next
Definition: DCELHalfEdge.h:15
FaceList Faces
Definition: origin.h:15
Definition: DCELFace.h:1
DCELVertex * origin
Definition: DCELHalfEdge.h:17
DCELFace * head
Definition: FaceList.h:9
void insertDiagonal(DCELVertex *v1, DCELVertex *v2)
Definition: origin.h:105
int boundaryLength()
Definition: DCELFace.h:22
int orientation(pair< double, double > a, pair< double, double > b, pair< double, double > c)
Orientation.
Definition: origin.h:33
DCELFace * face
Definition: DCELHalfEdge.h:16
DCELFace * next
Definition: DCELFace.h:9
DCELHalfEdge * getPrev()
Half Edges.
Definition: DCELHalfEdge.h:36
#define ANTICLOCKWISE
Definition: origin.h:17
#define CLOCKWISE
Definition: origin.h:16
Definition: DCELHalfEdge.h:8
vector< pair< DCELVertex *, int > > sortedVertices()
Definition: DCELFace.h:32
bool bordered
Definition: DCELFace.h:8