Computational Geometry Algorithms Library  1.0
Computational Geometry Algorithms Library Documentation
origin.h
Go to the documentation of this file.
1 #ifndef DCEL_ORIGIN_H
2 #define DCEL_ORIGIN_H
3 
4 #include <iostream>
5 #include <bits/stdc++.h>
6 #include <typeinfo>
7 #include "HalfEdgeList.h"
8 #include "VertexList.h"
9 
10 using namespace std;
11 
12 
13 VertexList Vertices; //Head of linked-list containing Vertex Collation
14 HalfEdgeList Edges; //Head of linked-list containing Edge Collation
15 FaceList Faces; //Head of linked-list containing Face Collation
16 
17 
19 
22 void getPolygon(char const *filename) {
23  double a, b, c ;
24  DCELVertex* firstVertex;
25  DCELVertex *walker = new DCELVertex();
26  DCELHalfEdge *LaggingTwin = NULL;
27  DCELFace *inner = new DCELFace();
28  DCELFace *outer = new DCELFace();
29  ifstream in_file;
30  in_file.open(filename);
31  while (in_file.is_open()) {
32  int n, i = 0;
33  in_file >> n;
34  while (in_file >> a >> b >> c) {
35  DCELVertex *next = new DCELVertex();
36  next->setCoords(a, b);
37  DCELHalfEdge *edge = new DCELHalfEdge();
38  edge->origin = next;
39  edge->face = inner;
40  inner->edge = edge;
41  Edges.addToList(edge);
42  LaggingTwin = Edges.addTwinTo(edge, LaggingTwin);
43  LaggingTwin->face = outer;
44  outer->edge = LaggingTwin;
45  outer->bordered = false;
46  next->edge = edge;
47  if (!Vertices.length) firstVertex = next;
48  Vertices.addToList(next);
49  }
50  Faces.addToList(outer);
51  Faces.addToList(inner);
52 
53  in_file.close();
54  }
55  Edges.tail->next = Edges.head;
56  Edges.head->twin->next = Edges.tail->twin;
57  Edges.tail->twin->origin = firstVertex;
58 }
59 
60 void printPolygon() {
61  cout << "OFF" << endl;
62  cout << Vertices.length << " " << Faces.length() << " 0" << endl;
63  Vertices.echo();
64  DCELFace *walker = Faces.head;
65  DCELHalfEdge *edgeWalker;
66  while (walker) {
67  if (walker->bordered) {
68  edgeWalker = walker->edge;
69  cout << walker->boundaryLength() << " ";
70  do {
71  cout << edgeWalker->origin->index << " ";
72  edgeWalker = edgeWalker->next;
73  } while (edgeWalker != walker->edge);
74  cout << (double)rand() / RAND_MAX << " " << (double)rand() / RAND_MAX << " " << (double)rand() / RAND_MAX;
75  cout << endl;
76  }
77  walker = walker->next;
78  }
79 }
80 
82  DCELFace* face = NULL;
83  DCELHalfEdge* walker = v1->edge;
84  DCELHalfEdge* twinWalker = v2->edge;
85  do {
86  do {
87  if (walker->face == twinWalker->face && walker->face->bordered)
88  {face = walker->face; break;}
89  twinWalker = twinWalker->twin->next;
90  } while (twinWalker != v2->edge);
91  walker = walker->twin->next;
92  } while (walker != v1->edge && !face);
93  return face;
94 }
96  DCELHalfEdge* walker = v1->edge;
97  do {
98  if (walker->next->origin == v2) {
99  return true;
100  }
101  walker = walker->twin->next;
102  } while (walker != v1->edge);
103  return false;
104 }
106  if (v1 == v2) return;
107  if (checkEdge(v1,v2)) return;
108 
109  DCELFace* face = getFaceCommonTo(v1, v2);
110  if(face) {
111  DCELFace* newSubdivision = Edges.addEdgeBetween(v1, v2, face);
112  Faces.addToList(newSubdivision);
113  Faces.removeFromList(face);
114  delete face;
115  }
116 }
117 #endif
DCELHalfEdge * edge
Definition: DCELVertex.h:10
DCELHalfEdge * twin
Definition: DCELHalfEdge.h:14
Definition: FaceList.h:4
void addToList(DCELHalfEdge *newEdge)
Definition: HalfEdgeList.h:33
DCELHalfEdge * next
Definition: DCELHalfEdge.h:15
void printPolygon()
Definition: origin.h:60
Definition: HalfEdgeList.h:7
void getPolygon(char const *filename)
Extract Data from Input File.
Definition: origin.h:22
void setCoords(double a, double b)
Definition: DCELVertex.h:30
FaceList Faces
Definition: origin.h:15
void removeFromList(DCELFace *face)
CREATE FACES.
Definition: FaceList.h:58
VertexList Vertices
Definition: origin.h:13
Definition: DCELFace.h:1
void addToList(DCELFace *newFace)
CREATE FACES.
Definition: FaceList.h:28
DCELVertex * origin
Definition: DCELHalfEdge.h:17
DCELFace * head
Definition: FaceList.h:9
void insertDiagonal(DCELVertex *v1, DCELVertex *v2)
Definition: origin.h:105
int length()
Definition: FaceList.h:42
int boundaryLength()
Definition: DCELFace.h:22
DCELHalfEdge * head
Definition: HalfEdgeList.h:13
DCELFace * face
Definition: DCELHalfEdge.h:16
DCELFace * next
Definition: DCELFace.h:9
void echo()
Definition: VertexList.h:26
Definition: DCELVertex.h:2
DCELFace * getFaceCommonTo(DCELVertex *v1, DCELVertex *v2)
Definition: origin.h:81
int index
Definition: DCELVertex.h:16
bool checkEdge(DCELVertex *v1, DCELVertex *v2)
Definition: origin.h:95
DCELHalfEdge * tail
Definition: HalfEdgeList.h:14
int length
Definition: VertexList.h:13
Definition: VertexList.h:3
HalfEdgeList Edges
Definition: origin.h:14
void addToList(DCELVertex *newVertex)
Definition: VertexList.h:38
DCELHalfEdge * addTwinTo(DCELHalfEdge *edge, DCELHalfEdge *LaggingTwin)
GETTTING THE HALF EDGE LIST.
Definition: HalfEdgeList.h:51
DCELFace * addEdgeBetween(DCELVertex *v1, DCELVertex *v2, DCELFace *face)
GETTTING THE HALF EDGE LIST.
Definition: HalfEdgeList.h:75
Definition: DCELHalfEdge.h:8
bool bordered
Definition: DCELFace.h:8
DCELHalfEdge * edge
Definition: DCELFace.h:7