Xmipp  v3.23.11-Nereus
dcel.cpp
Go to the documentation of this file.
1 #include "dcel.h"
2 #include "defines.h"
3 #include <errno.h>
4 #include <float.h>
5 #ifdef LOGGING
6 #include "log.h"
7 #endif
8 #include <math.h>
9 #include "point.h"
10 #include "sorting.h"
11 #include <stdlib.h>
12 #include <string.h>
13 #include <time.h>
14 
15 #define DEFAULT_CONVEX_HULL_LEN 20
16 
17 /**************************************************************************
18 * Private functions declaration
19 **************************************************************************/
20 void print_Vertex(struct Dcel_Vertex_T *vertex);
21 void print_Edge(struct Dcel_Edge_T *edge);
22 void print_Face(struct Dcel_Face_T *face);
23 int get_Vertex_Index( struct DCEL_T *dcel, struct Point_T *point);
24 int in_Convex_Hull( struct DCEL_T *dcel, struct Dcel_Edge_T *edge);
25 void copy_Dcel(struct DCEL_T *in_Dcel, struct DCEL_T *out_Dcel);
26 
27 
28 //#define DEBUG_INITIALIZE_DCEL
29 /**************************************************************************
30 * Public functions bodies
31 **************************************************************************/
32 int initialize_DCEL( struct DCEL_T *dcel, int nPoints, int nEdges, int nFaces)
33 {
34  int ret=SUCCESS; // Return value.
35 
36  // Initialize vertex attributes.
37  dcel->nVertex = 0;
38  dcel->sizeVertex = nPoints;
39 
40  // Allocate array of vertex.
41  dcel->vertex = (struct Dcel_Vertex_T *) calloc(nPoints, sizeof(struct Dcel_Vertex_T));
42 
43  // Initialize edges attributes.
44  dcel->nEdges = 0;
45  if (nEdges != INVALID)
46  {
47  dcel->sizeEdges = nEdges;
48  }
49  // Max number of edges is = 3xnPoints - 6.
50  // NOTE: It is 6xnPoints because there are two directions per edge.
51  else
52  {
53  dcel->sizeEdges = 6*(nPoints+2) - 6;
54  }
55 
56  // Allocate array of edges.
57  dcel->edgeChecked = (int*) calloc( dcel->sizeEdges, sizeof(int));
58  dcel->edges = (struct Dcel_Edge_T *) malloc(sizeof(struct Dcel_Edge_T)*dcel->sizeEdges);
59 
60  // Initialize faces attributes. If # vertices and # edges are known then # faces = 2 - #v + #e
61  dcel->nFaces = 0;
62  if (nFaces == INVALID)
63  {
64  dcel->sizeFaces = 2 - dcel->sizeVertex + dcel->sizeEdges;
65  }
66  else
67  {
68  dcel->sizeFaces = nFaces;
69  }
70 
71  // Allocate array of vertex.
72  dcel->faces = (struct Dcel_Face_T *) calloc( dcel->sizeFaces, sizeof(struct Dcel_Face_T));
73 
74 #ifdef DEBUG_INITIALIZE_DCEL
75  printf("Allocating %d points, %d edges and %d faces\n", dcel->sizeVertex, dcel->sizeEdges, dcel->sizeFaces);
76 #endif
77 
78  // Check error allocating memory.
79  if ((dcel->vertex == NULL) ||
80  (dcel->edges == NULL) ||
81  (dcel->faces == NULL))
82  {
83 #ifdef LOGGING
84  sprintf( log_Text, "Error allocating memory in initialize_DCEL");
85  write_Log( log_Text);
86 #endif
87  ret = FAILURE;
88  printf("Function initialize_DCEL.\tError allocating memory in initialize_DCEL\n");
89  }
90 
91  return(ret);
92 }
93 
94 //#define DEBUG_READ_DCEL
95 int read_DCEL( struct DCEL_T *dcel, char *fileName)
96 {
97  int ret=SUCCESS; // Return value.
98  int i=0; // Loop counter.
99  FILE *fd=NULL; // File descriptor.
100  int origin=0;
101  int twin=0;
102  int prev=0;
103  int next=0;
104  int edgeFace=0;
105  int nVertex=0, nEdges=0, nFaces=0;
106  struct Dcel_Vertex_T vertex;
107  struct Dcel_Face_T face;
108 
109  // Open input file.
110  if ((fd = fopen( fileName, "r")) == NULL)
111  {
112 #ifdef LOGGING
113  sprintf( log_Text, "Error opening DCEL file: %s\n", fileName);
114  write_Log( log_Text);
115 #endif
116  printf("Error opening DCEL file: %s\n", fileName);
117  ret = FAILURE;
118  }
119  else
120  {
121  // Read number of vertex.
122  ret = fscanf( fd, "%d", &nVertex);
123 
124 #ifdef DEBUG_READ_DCEL
125  printf("# vertex %d\n", nVertex);
126 #endif
127  // Read vertex.
128  for (i=0; i<nVertex; i++)
129  {
130  // Read x and y coordinates and edge id.
131 #ifdef FLOAT_TYPE
132  ret = fscanf( fd, "%f", &vertex.vertex.x);
133  ret = fscanf( fd, "%f", &vertex.vertex.y);
134 #else
135  ret = fscanf( fd, "%lf", &vertex.vertex.x);
136  ret = fscanf( fd, "%lf", &vertex.vertex.y);
137 #endif
138  ret = fscanf( fd, "%d", &vertex.origin_Edge);
139  }
140 
141  // Read number of edges.
142  ret = fscanf( fd, "%d", &nEdges);
143 
144 #ifdef DEBUG_READ_DCEL
145  printf("# edges %d\n", nEdges);
146 #endif
147  // Read edges.
148  for (i=0; i<nEdges; i++)
149  {
150  // Read x and y coordinates and edge id.
151  ret = fscanf( fd, "%d", &origin);
152  ret = fscanf( fd, "%d", &twin);
153  ret = fscanf( fd, "%d", &prev);
154  ret = fscanf( fd, "%d", &next);
155  ret = fscanf( fd, "%d", &edgeFace);
156  }
157 
158  // Read number of faces.
159  ret = fscanf( fd, "%d", &nFaces);
160 
161 #ifdef DEBUG_READ_DCEL
162  printf("# faces %d\n", nFaces);
163 #endif
164 
165  // Move to first position of the file.
166  fclose( fd);
167  fd = fopen( fileName, "r");
168 
169  initialize_DCEL( dcel, nVertex, nEdges, nFaces);
170 
171  // Read number of vertex.
172  ret = fscanf( fd, "%d", &nVertex);
173 
174  // Read vertex.
175  for (i=0; i<nVertex; i++)
176  {
177  // Read x and y coordinates and edge id.
178 #ifdef FLOAT_TYPE
179  ret = fscanf( fd, "%f", &vertex.vertex.x);
180  ret = fscanf( fd, "%f", &vertex.vertex.y);
181 #else
182  ret = fscanf( fd, "%lf", &vertex.vertex.x);
183  ret = fscanf( fd, "%lf", &vertex.vertex.y);
184 #endif
185  ret = fscanf( fd, "%d", &vertex.origin_Edge);
186 
187 #ifdef DEBUG_READ_DCEL
188  printf("Vertex read (%f,%f) origin edge %d\n", vertex.vertex.x, vertex.vertex.y, vertex.origin_Edge);
189 #endif
190 
191  // Insert vertex.
192  insertVertex( dcel, vertex);
193  }
194 
195  // Read number of edges.
196  ret = fscanf( fd, "%d", &nEdges);
197 
198  // Read edges.
199  for (i=0; i<nEdges; i++)
200  {
201  // Read x and y coordinates and edge id.
202  ret = fscanf( fd, "%d", &origin);
203  ret = fscanf( fd, "%d", &twin);
204  ret = fscanf( fd, "%d", &prev);
205  ret = fscanf( fd, "%d", &next);
206  ret = fscanf( fd, "%d", &edgeFace);
207 
208  // Insert vertex.
209  insertEdge( dcel, origin, twin, prev, next, edgeFace);
210  }
211 
212  // Read number of faces.
213  ret = fscanf( fd, "%d", &nFaces);
214 
215  // Read faces.
216  for (i=0; i<nFaces; i++)
217  {
218  // Read x and y coordinates and edge id.
219  ret = fscanf( fd, "%d", &face.edge);
220 
221  // Insert vertex.
222  insertFace( dcel, face.edge);
223  }
224 
225 #ifdef DEBUG_READ_DCEL
226  printf("Read dcel with:\n%d vertex\n%d edges\n%d faces\n",
227  dcel->nVertex,
228  dcel->nEdges,
229  dcel->nFaces);
230 #endif
231 
232  fclose(fd);
233  }
234 
235  return(ret);
236 }
237 
238 //#define DEBUG_READ_FLAT_FILE
239 int read_Points_Flat_File( struct DCEL_T *dcel, const char *fileName)
240 {
241  int ret=SUCCESS; // Return value.
242  int number_Points=0; // Number of points of set.
243  FILE *fd=NULL; // File descriptor.
244 
245  // Open file.
246  if ((fd = fopen( fileName, "r")) == NULL)
247  {
248  // Set default number of points.
249 #ifdef LOGGING
250  sprintf( log_Text, "Error %d opening input file: %s\n", errno, fileName);
251  write_Log( log_Text);
252 #endif
253  printf("Error %d opening input file: %s\n", errno, fileName);
254  ret = FAILURE;
255  }
256  else
257  {
258  // Read number of points.
259  if (fscanf( fd, "%d", &number_Points) != 1)
260  {
261 #ifdef LOGGING
262  sprintf( log_Text, "Error %d reading number of points from file: %s.", errno, fileName);
263  write_Log( log_Text);
264 #endif
265  printf("Error %d reading number of points from file: %s.", errno, fileName);
266  ret = FAILURE;
267  }
268  else
269  {
270 #ifdef DEBUG_READ_FLAT_FILE
271  printf("# points %d\n", number_Points);
272 #endif
273  // Allocate DCEL structure.
274  if (initialize_DCEL( dcel, number_Points, INVALID, INVALID) == FAILURE)
275  {
276 #ifdef LOGGING
277  sprintf( log_Text, "Error allocating memory when calling initialize_DCEL\n");
278  write_Log( log_Text);
279 #endif
280  printf("Error allocating memory when calling initialize_DCEL");
281  ret = FAILURE;
282  }
283  else
284  {
285  // Read initial set of points and close input file.
286  if (read_Points_DCEL( fd, number_Points, dcel) == FAILURE)
287  {
288  ret = FAILURE;
289  }
290  }
291  }
292 
293  // Close input file.
294  fclose(fd);
295  }
296 
297  return(ret);
298 }
299 
300 //#define DEBUG_WRITE_DCEL
301 int write_DCEL( struct DCEL_T *dcel, int type, const char *fileName)
302 {
303  int i=0; // Loop counter.
304  int ret=SUCCESS; // Return value.
305  FILE *fd=NULL; // File descriptor.
306 
307  // Open file.
308  if ((fd = fopen( fileName, "w")) == NULL)
309  {
310  // Set default number of points.
311 #ifdef LOGGING
312  sprintf( log_Text, "Error %d opening input file: %s\n", errno, fileName);
313  write_Log( log_Text);
314 #endif
315  printf("Error %d opening output file: %s\n", errno, fileName);
316  ret = FAILURE;
317  }
318  else
319  {
320  if (type == DCEL_TYPE)
321  {
322 #ifdef DEBUG_WRITE_DCEL
323  printf("Writing DCEL data to %s file\n", fileName);
324 #endif
325 
326  // Write number of vertex.
327  fprintf( fd, "%d\n", dcel->nVertex);
328 
329  // Write vertex.
330  for (i=0; i<dcel->nVertex; i++)
331  {
332  // Read x and y coordinates and edge id.
333  fprintf( fd, "%f ", dcel->vertex[i].vertex.x);
334  fprintf( fd, "%f ", dcel->vertex[i].vertex.y);
335  fprintf( fd, "%d\n", dcel->vertex[i].origin_Edge);
336  }
337 
338  // Write number of edges.
339  fprintf( fd, "%d\n", dcel->nEdges);
340 
341  // Write edges.
342  for (i=0; i<dcel->nEdges; i++)
343  {
344  // Read x and y coordinates and edge id.
345  fprintf( fd, "%d ", dcel->edges[i].origin_Vertex);
346  fprintf( fd, "%d ", dcel->edges[i].twin_Edge);
347  fprintf( fd, "%d ", dcel->edges[i].previous_Edge);
348  fprintf( fd, "%d ", dcel->edges[i].next_Edge);
349  fprintf( fd, "%d\n", dcel->edges[i].face);
350  }
351 
352  // Write number of faces.
353  fprintf( fd, "%d\n", dcel->nFaces);
354 
355  // Read faces.
356  for (i=0; i<dcel->nFaces; i++)
357  {
358  // Read x and y coordinates and edge id.
359  fprintf( fd, "%d\n", dcel->faces[i].edge);
360  }
361  }
362  else
363  {
364 #ifdef DEBUG_WRITE_DCEL
365  printf("Writing only points to %s file\n", fileName);
366 #endif
367  // Write number of vertex.
368  fprintf( fd, "%d ", dcel->nVertex);
369 
370  // Write vertex.
371  for (i=0; i<dcel->nVertex; i++)
372  {
373  // Read x and y coordinates and edge id.
374  fprintf( fd, "%f ", dcel->vertex[i].vertex.x);
375  fprintf( fd, "%f ", dcel->vertex[i].vertex.y);
376  }
377  }
378 
379  // Close file.
380  fclose(fd);
381  }
382 
383  return(ret);
384 }
385 
386 void print_DCEL( struct DCEL_T *dcel)
387 {
388  int i=0; // Loop counter.
389 
390  // Print number of vertex.
391  printf("# vertices: %d\n", dcel->nVertex);
392 
393  // Print vertex.
394  for (i=0; i<dcel->nVertex; i++)
395  {
396  // Print x and y coordinates and edge id.
397  printf("%d\t%f ", i+1, dcel->vertex[i].vertex.x);
398  printf("%f ", dcel->vertex[i].vertex.y);
399  printf("%d\n", dcel->vertex[i].origin_Edge);
400  }
401 
402  // Print number of edges.
403  printf("# edges: %d\n", dcel->nEdges);
404 
405  // Print edges.
406  for (i=0; i<dcel->nEdges; i++)
407  {
408  // Print x and y coordinates and edge id.
409  printf("%d\t%d ", i+1, dcel->edges[i].origin_Vertex);
410  printf("%d ", dcel->edges[i].twin_Edge);
411  printf("%d ", dcel->edges[i].previous_Edge);
412  printf("%d ", dcel->edges[i].next_Edge);
413  printf("%d\n", dcel->edges[i].face);
414  }
415 
416  // Print number of faces.
417  printf("# faces: %d\n", dcel->nFaces);
418 
419  // Print faces.
420  for (i=0; i<dcel->nFaces; i++)
421  {
422  // Print x and y coordinates and edge id.
423  printf("%d\t%d\t%d\n", i, dcel->faces[i].edge, dcel->faces[i].imaginaryFace);
424  }
425 }
426 
427 void reset_DCEL(struct DCEL_T *dcel)
428 {
429  // Reset vertex.
430  dcel->nVertex = 0;
431  memset( dcel->vertex, 0, sizeof(struct Dcel_Vertex_T)*dcel->sizeVertex);
432 
433  // Reset edges.
434  dcel->nEdges = 0;
435  memset( dcel->edgeChecked, 0, dcel->sizeEdges*sizeof(int));
436  memset( dcel->edges, 0, dcel->sizeEdges*sizeof(struct Dcel_Edge_T));
437 
438  // Reset faces.
439  dcel->nFaces = 0;
440  memset( dcel->faces, 0, sizeof(struct Dcel_Face_T)*dcel->sizeFaces);
441 }
442 
443 void copy_Dcel(struct DCEL_T *in_Dcel, struct DCEL_T *out_dcel)
444 {
445  // Copy vertex.
446  out_dcel->nVertex = in_Dcel->nVertex;
447  out_dcel->sizeVertex = in_Dcel->sizeVertex;
448  memcpy( &out_dcel->vertex, in_Dcel->vertex, sizeof(struct Dcel_Vertex_T)*in_Dcel->nVertex);
449 
450  // Copy edges.
451  out_dcel->nEdges = in_Dcel->nEdges;
452  out_dcel->sizeEdges = in_Dcel->sizeEdges;
453  memcpy( &out_dcel->edgeChecked, in_Dcel->edgeChecked, sizeof(int)*in_Dcel->nEdges);
454  memcpy( &out_dcel->edges, in_Dcel->edges, sizeof(struct Dcel_Edge_T)*in_Dcel->nEdges);
455 
456  // Copy faces.
457  out_dcel->nFaces = in_Dcel->nFaces;
458  out_dcel->sizeFaces = in_Dcel->sizeFaces;
459  memcpy( &out_dcel->faces, in_Dcel->faces, sizeof(struct Dcel_Face_T)*in_Dcel->nFaces);
460 }
461 
462 
463 /***************************************************************************
464 * Name: resize_DCEL
465 * IN: resize_Type type of resize (vertex, edges or faces)
466 * OUT: N/A
467 * IN/OUT: dcel dcel data
468 * RETURN: SUCCESS if resize successfully. FAILURE i.o.c.
469 * Description: Resize the data defined by "resize_Type" to double its size.
470 ***************************************************************************/
471 int resize_DCEL( struct DCEL_T *dcel, enum Resize_DCEL_T resize_Type)
472 {
473  int ret=SUCCESS; // Return value.
474 
475  // Temporary pointers.
476  struct Dcel_Vertex_T *refVertex;
477  int *refEdgeChecked;
478  struct Dcel_Edge_T *refEdges;
479  struct Dcel_Face_T *refFaces;
480 
481  // Check resize type.
482  switch(resize_Type)
483  {
484  // Resize vertices.
485  case RESIZE_POINTS:
486  {
487  // Get reference to current data.
488  refVertex = dcel->vertex;
489 
490  // Allocate new array.
491  dcel->sizeVertex = dcel->sizeVertex*2;
492  dcel->vertex = (struct Dcel_Vertex_T *) calloc(dcel->sizeVertex, sizeof(struct Dcel_Vertex_T));
493  if (dcel->vertex != NULL)
494  {
495  // Copy vertices array.
496  memcpy( dcel->vertex, refVertex, sizeof(struct Dcel_Vertex_T)*dcel->nVertex);
497 
498  // Free previous array.
499  free(refVertex);
500  }
501  else
502  {
503 #ifdef LOGGING
504  sprintf( log_Text, "Error allocating vertex in resize_DCEL.\n");
505  write_Log( log_Text);
506 #endif
507  printf("Error allocating vertex in resize_DCEL.\n");
508  ret = FAILURE;
509  }
510  break;
511  }
512  // Resize edges.
513  case RESIZE_EDGES:
514  {
515  // Get reference to current data.
516  refEdgeChecked = dcel->edgeChecked;
517  refEdges = dcel->edges;
518 
519  // Allocate new arrays.
520  dcel->sizeEdges = dcel->sizeEdges*2;
521  dcel->edgeChecked = (int *) calloc(dcel->sizeVertex, sizeof(int));
522  dcel->edges = (struct Dcel_Edge_T *) calloc(dcel->sizeVertex, sizeof(struct Dcel_Edge_T));
523  if ((dcel->edgeChecked != NULL) &&
524  (dcel->edges != NULL))
525  {
526  // Copy edges arrays.
527  memcpy( dcel->edgeChecked, refEdgeChecked, sizeof(int)*dcel->nEdges);
528  memcpy( dcel->edges, refEdges, sizeof(struct Dcel_Edge_T)*dcel->nEdges);
529 
530  // Free previous arrays.
531  free(refEdgeChecked);
532  free(refEdges);
533  }
534  else
535  {
536 #ifdef LOGGING
537  sprintf( log_Text, "Error allocating edges in resize_DCEL.\n");
538  write_Log( log_Text);
539 #endif
540  printf("Error allocating edges in resize_DCEL.\n");
541  ret = FAILURE;
542  }
543  break;
544  }
545  // Resize faces.
546  default:
547  {
548  // Get reference to current data.
549  refFaces = dcel->faces;
550 
551  // Allocate new array.
552  dcel->sizeFaces = dcel->sizeFaces*2;
553  dcel->faces = (struct Dcel_Face_T *) calloc(dcel->sizeFaces, sizeof(struct Dcel_Face_T));
554  if (dcel->faces != NULL)
555  {
556  // Copy faces array.
557  memcpy( dcel->faces, refFaces, sizeof(struct Dcel_Face_T)*dcel->nFaces);
558 
559  // Free previous array.
560  free(refFaces);
561  }
562  else
563  {
564 #ifdef LOGGING
565  sprintf( log_Text, "Error allocating faces in resize_DCEL.\n");
566  write_Log( log_Text);
567 #endif
568  printf("Error allocating faces in resize_DCEL.\n");
569  ret = FAILURE;
570  }
571  break;
572  }
573  }
574 
575  return(ret);
576 }
577 
578 void check_DCEL_Data(struct DCEL_T *dcel)
579 {
580  struct DCEL_T check_Dcel;
581 
582  // Initialize copy of input DCEL data.
583  initialize_DCEL( &check_Dcel, dcel->nVertex, dcel->nEdges, dcel->nFaces);
584 
585  // Copy Dcel.
586  copy_Dcel( dcel, &check_Dcel);
587 
588  // Order in angular order from bottom most point.
589  sort( dcel);
590 
591  // Deallocate memory.
592  finalize_DCEL( &check_Dcel);
593 }
594 
595 void finalize_DCEL(struct DCEL_T *dcel)
596 {
597  if (dcel != NULL)
598  {
599  // Deallocate vertex memory.
600  if (dcel->vertex != NULL)
601  {
602  free(dcel->vertex);
603  }
604  dcel->vertex = NULL;
605 
606  // Deallocate edges memory.
607  if (dcel->edges != NULL)
608  {
609  free(dcel->edges);
610  }
611  dcel->edges = NULL;
612 
613  // Deallocate edgeChecked memory.
614  if (dcel->edgeChecked != NULL)
615  {
616  free(dcel->edgeChecked);
617  }
618  dcel->edgeChecked = NULL;
619 
620  // Deallocate faces memory.
621  if (dcel->faces != NULL)
622  {
623  free(dcel->faces);
624  }
625  dcel->faces = NULL;
626  }
627 }
628 
629 
630 /***************************************************************************
631 * Name: get_Number_Vertex
632 * IN: dcel DCEL data
633 * OUT: N/A
634 * IN/OUT: N/A
635 * RETURN: # vertex in DCEL
636 * Description: returns # vertex in DCEL
637 ***************************************************************************/
638 int get_Number_Vertex( struct DCEL_T *dcel)
639 {
640  // Return number of vertex in DCEL.
641  return(dcel->nVertex);
642 }
643 
644 
645 //#define DEBUG_INSERTPOINT
646 /***************************************************************************
647 * Name: insertPoint
648 * IN: point input point
649 * OUT: N/A
650 * IN/OUT: dcel DCEL data
651 * GLOBAL: N/A
652 * RETURN: SUCCESS if point inserted. FAILURE i.o.c.
653 * Description: Inserts a new point in the DCEL without setting the edge
654 * that departs from it.
655 ***************************************************************************/
656 int insertPoint( struct DCEL_T *dcel, struct Point_T *point)
657 {
658  int ret=SUCCESS; // Return value.
659 
660  // Check if DCEl vertex is full.
661  if (dcel->nVertex == dcel->sizeVertex)
662  {
663  printf("DCEL vertex is full. Size %d and # elements is %d.\n",
664  dcel->sizeVertex,
665  dcel->nVertex);
666  // Resize vertex array.
667  if (resize_DCEL( dcel, RESIZE_POINTS) == FAILURE)
668  {
669 #ifdef LOGGING
670  sprintf("Error resizing DCEL in insertPoint.\n");
671  write_Log( log_Text);
672 #endif
673  printf("Error resizing DCEL in insertPoint.\n");
674  ret = FAILURE;
675  }
676  }
677 
678  if (ret == SUCCESS)
679  {
680 #ifdef DEBUG_INSERTPOINT
681  printf("Insert point (%lf,%lf) at position %d. Size %d\n", point->x, point->y,
682  dcel->nVertex, dcel->sizeVertex);
683 #endif
684 
685  // Update next vertex.
686  dcel->vertex[dcel->nVertex].vertex.x = point->x;
687  dcel->vertex[dcel->nVertex].vertex.y = point->y;
688  dcel->vertex[dcel->nVertex].origin_Edge = INVALID;
689 
690  // Update number of vertex.
691  dcel->nVertex++;
692  }
693 
694  return(ret);
695 }
696 
697 //#define DEBUG_INSERTVERTEX
698 /***************************************************************************
699 * Name: insertVertex
700 * IN: vertex input vertex
701 * OUT: N/A
702 * IN/OUT: dcel DCEL data
703 * GLOBAL: N/A
704 * RETURN: SUCCESS if point inserted. FAILURE i.oc.
705 * Description: Inserts a new vertex in the DCEL
706 ***************************************************************************/
707 int insertVertex( struct DCEL_T *dcel, struct Dcel_Vertex_T vertex)
708 {
709  int ret=SUCCESS; // Return value.
710 
711  // Check if DCEl vertex is full.
712  if (dcel->nVertex == dcel->sizeVertex)
713  {
714  printf("DCEL vertex is full. Size %d and # elements is %d.\n", dcel->sizeVertex,
715  dcel->nVertex);
716  // Resize vertex array.
717  if (resize_DCEL( dcel, RESIZE_POINTS) == FAILURE)
718  {
719 #ifdef LOGGING
720  sprintf("Error resizing DCEL in insertPoint.\n");
721  write_Log( log_Text);
722 #endif
723  printf("Error resizing DCEL in insertPoint.\n");
724  ret = FAILURE;
725  }
726  }
727 
728  if (ret == SUCCESS)
729  {
730 #ifdef DEBUG_INSERTVERTEX
731  printf("Insert point (%lf,%lf) at position %d. Size %d\n", vertex.vertex.x,
732  vertex.vertex.y, dcel->nVertex, dcel->sizeVertex);
733 #endif
734 
735  // Update next vertex.
736  dcel->vertex[dcel->nVertex].vertex.x = vertex.vertex.x;
737  dcel->vertex[dcel->nVertex].vertex.y = vertex.vertex.y;
738  dcel->vertex[dcel->nVertex].origin_Edge = vertex.origin_Edge;
739 
740  // Update number of vertex.
741  dcel->nVertex++;
742  }
743 
744  return(ret);
745 }
746 
747 
748 /***************************************************************************
749 * Name: insert_Vertex_At
750 * IN: vertex vertex data to insert
751 * index position to insert vertex
752 * OUT: N/A
753 * IN/OUT: dcel DCEL data
754 * RETURN: SUCCESS if vertex inserted. FAILURE i.o.c.
755 * Description: Inserts "vertex" at "index" position.
756 ***************************************************************************/
757 int insert_Vertex_At( struct DCEL_T *dcel, struct Dcel_Vertex_T vertex, int index)
758 {
759  int ret=SUCCESS; // Return value.
760 
761  // Check if index is out of bounds.
762  if (index >= dcel->nVertex)
763  {
764  printf("Error inserting vertex in DCEL. Index %d out of bounds (0,%d).\n",
765  index,
766  dcel->nVertex-1);
767 #ifdef LOGGING
768  sprintf("Error inserting vertex in DCEL. Index %d out of bounds (0,%d).\n",
769  index,
770  dcel->nVertex-1);
771  write_Log( log_Text);
772 #endif
773  ret = FAILURE;
774  }
775  else
776  {
777  // Update next vertex.
778  dcel->vertex[index].vertex.x = vertex.vertex.x;
779  dcel->vertex[index].vertex.y = vertex.vertex.y;
780  dcel->vertex[index].origin_Edge = vertex.origin_Edge;
781 
782  // Update number of vertex.
783  dcel->nVertex++;
784  }
785 
786  return(ret);
787 }
788 
789 //#define DEBUG_UPDATE_VERTEX_EDGE_AT
790 /***************************************************************************
791 * Name: update_Vertex_Edge_At
792 * IN: vertex vertex data to insert
793 * index position to insert vertex
794 * OUT: N/A
795 * IN/OUT: dcel DCEL data
796 * RETURN: SUCCESS if vertex inserted. FAILURE i.o.c.
797 * Description: Inserts "vertex" at "index" position.
798 ***************************************************************************/
799 int update_Vertex_Edge_At( struct DCEL_T *dcel, int edge_ID, int index)
800 {
801  int ret=SUCCESS; // Return value.
802 
803  // Check if index is out of bounds.
804  if (index >= dcel->nVertex)
805  {
806  printf("Error updating vertex in DCEL. Index %d out of bounds (0,%d).\n",
807  index,
808  dcel->nVertex-1);
809 #ifdef LOGGING
810  sprintf("Error updating vertex in DCEL. Index %d out of bounds (0,%d).\n",
811  index,
812  dcel->nVertex-1);
813  write_Log( log_Text);
814 #endif
815  ret = FAILURE;
816  }
817  else
818  {
819 #ifdef DEBUG_UPDATE_VERTEX_EDGE_AT
820  printf("Updating vertex %d with edge %d\n", index, edge_ID);
821 #endif
822  // Update vertex edge.
823  dcel->vertex[index].origin_Edge = edge_ID;
824  }
825 
826  return(ret);
827 }
828 
829 /***************************************************************************
830 * Name: swap_Vertex
831 * IN: index1 first vertex position
832 * index2 second vertex position
833 * OUT: N/A
834 * IN/OUT: dcel DCEL data
835 * RETURN: SUCCESS if vertex inserted. FAILURE i.o.c.
836 * Description: Swap vertices at "index1" and "index2" positions.
837 ***************************************************************************/
838 int swap_Vertex( struct DCEL_T *dcel, int index1, int index2)
839 {
840  int ret=SUCCESS; // Return value.
841  struct Dcel_Vertex_T vertex; // Temporary variable.
842 
843  // Check if index is out of bounds.
844  if ((index1 >= dcel->nVertex) ||
845  (index2 >= dcel->nVertex))
846  {
847  printf("Error swapping vertices in DCEL. Index1 %d or Index2 %d out of bounds (0,%d).\n",
848  index1,
849  index2,
850  dcel->nVertex-1);
851 #ifdef LOGGING
852  sprintf("Error swapping vertices in DCEL. Index1 %d or Index2 out of bounds (0,%d).\n",
853  index1,
854  index2,
855  dcel->nVertex-1);
856  write_Log( log_Text);
857 #endif
858  ret = FAILURE;
859  }
860  else
861  {
862  // Swap vertices.
863  vertex = dcel->vertex[index1];
864  dcel->vertex[index1] = dcel->vertex[index2];
865  dcel->vertex[index2] = vertex;
866  }
867 
868  return(ret);
869 }
870 
871 
872 /***************************************************************************
873 * Name: get_Vertex
874 * IN: dcel DCEL data
875 * index vertex position
876 * OUT: N/A
877 * IN/OUT: N/A
878 * RETURN: Vertex at index position if "index" into array bounds.
879 * Vertex at 0 position if "index" out of bounds.
880 * Description: Returns the vertex at "index" position.
881 ***************************************************************************/
882 struct Dcel_Vertex_T *get_Vertex( struct DCEL_T *dcel, int index)
883 {
884  // Check if index is out of bounds.
885  if (index >= dcel->nVertex)
886  {
887  printf("Error in get_Vertex DCEL. Index %d out of bounds (0,%d).\n",
888  index,
889  dcel->nVertex-1);
890 #ifdef LOGGING
891  sprintf("Error in get_Vertex DCEL. Index %d out of bounds (0,%d).\n",
892  index,
893  dcel->nVertex-1);
894  write_Log( log_Text);
895 #endif
896  // Return vertex at 0 position.
897  return(&dcel->vertex[0]);
898  }
899  else
900  {
901  // Return vertex.
902  return(&dcel->vertex[index]);
903  }
904 }
905 
906 
907 /***************************************************************************
908 * Name: get_Vertex_Point
909 * IN: dcel DCEL data
910 * index vertex position
911 * OUT: N/A
912 * IN/OUT: N/A
913 * RETURN: point at index position if "index" into array bounds.
914 * point at 0 position if "index" out of bounds.
915 * Description: Returns the point at "index" position.
916 ***************************************************************************/
917 struct Point_T *get_Vertex_Point( struct DCEL_T *dcel, int index)
918 {
919  // Check if index is out of bounds.
920  if (index >= dcel->nVertex)
921  {
922  printf("Error in get_Vertex_Point DCEL. Index %d out of bounds (0,%d).\n",
923  index,
924  dcel->nVertex-1);
925 #ifdef LOGGING
926  sprintf("Error in get_Vertex_Point DCEL. Index %d out of bounds (0,%d).\n",
927  index,
928  dcel->nVertex-1);
929  write_Log( log_Text);
930 #endif
931  // Return point at 0 position.
932  return(&dcel->vertex[0].vertex);
933  }
934  else
935  {
936  // Return point.
937  return(&dcel->vertex[index].vertex);
938  }
939 }
940 
941 
942 /***************************************************************************
943 * Name: get_Number_Edges
944 * IN: dcel DCEL data
945 * OUT: N/A
946 * IN/OUT: N/A
947 * RETURN: # edges in DCEL
948 * Description: Returns # edges in DCEL
949 ***************************************************************************/
950 int get_Number_Edges( struct DCEL_T *dcel)
951 {
952  // Return number of edges.
953  return(dcel->nEdges);
954 }
955 
956 /***************************************************************************
957 * Name: get_Number_Real_Edges
958 * IN: dcel DCEL data
959 * OUT: N/A
960 * IN/OUT: N/A
961 * RETURN: # readl edges in DCEL
962 * Description: Returns # real edges in DCEL. Real edges has no imaginary
963 * vertex as origin nor destination.
964 ***************************************************************************/
965 int get_Number_Real_Edges( struct DCEL_T *dcel)
966 {
967  int i=0; // Loop counter.
968  int nEdges=0; // Return value.
969 
970  // Check all edges.
971  for (i=0; i<get_Number_Edges(dcel) ;i++)
972  {
973  // Check origin and destination has no imaginary vertex.
974  if ((dcel->edges[i].origin_Vertex >= 0) &&
975  (dcel->edges[dcel->edges[i].twin_Edge-1].origin_Vertex >= 0))
976  {
977  nEdges++;
978  }
979  }
980 
981  return(nEdges / 2);
982 }
983 
984 
985 //#define DEBUG_INSERTEDGE
986 /***************************************************************************
987 * Name: insertEdge
988 * IN: origin origin point of the edge
989 * twin twin edge
990 * prev previous edge
991 * next next edge
992 * face edge face
993 * OUT: N/A
994 * IN/OUT: dcel dcel DATA
995 * RETURN: SUCCESS if edge inserted. FAILURE i.o.c.
996 * Description: Inserts an edge in the next position of the edge array.
997 ***************************************************************************/
998 int insertEdge( struct DCEL_T *dcel, int origin, int twin, int prev, int next, int face)
999 {
1000  int ret=SUCCESS; // Return value.
1001 
1002  // Check if DCEl edges is full.
1003  if (dcel->nEdges == dcel->sizeEdges)
1004  {
1005  printf("DCEL edges is full. Size %d and # elements is %d.\n",
1006  dcel->sizeEdges,
1007  dcel->nEdges);
1008  // Resize edges array.
1009  if (resize_DCEL( dcel, RESIZE_EDGES) == FAILURE)
1010  {
1011 #ifdef LOGGING
1012  sprintf("Error resizing DCEL in insertEdge.\n");
1013  write_Log( log_Text);
1014 #endif
1015  printf("Error resizing DCEL in insertEdge.\n");
1016  ret = FAILURE;
1017  }
1018  }
1019 
1020  if (ret == SUCCESS)
1021  {
1022 #ifdef DEBUG_INSERTEDGE
1023  printf("Added edge %d. Origin %d Twin %d Prev %d Next %d Face %d.\n",
1024  dcel->nEdges + 1,
1025  origin,
1026  twin,
1027  prev,
1028  next,
1029  face);
1030 #endif
1031  // Update next edge.
1032  dcel->edges[dcel->nEdges].origin_Vertex = origin;
1033  dcel->edges[dcel->nEdges].twin_Edge = twin;
1034  dcel->edges[dcel->nEdges].previous_Edge = prev;
1035  dcel->edges[dcel->nEdges].next_Edge = next;
1036  dcel->edges[dcel->nEdges].face = face;
1037 
1038  // Update number of edges.
1039  dcel->nEdges++;
1040  }
1041 
1042  return(ret);
1043 }
1044 
1045 //#define DEBUG_UPDATE_EDGE
1046 /***************************************************************************
1047 * Name: update_Edge
1048 * IN: origin origin point of the edge
1049 * twin twin edge
1050 * next next edge
1051 * prev previous edge
1052 * face edge face
1053 * index edge position
1054 * OUT: N/A
1055 * IN/OUT: dcel dcel DATA
1056 * RETURN: SUCCESS if edge updated. FAILURE i.o.c.
1057 * Description: Updates the edge at "index" position. Fields with INVALID
1058 * value are not updated.
1059 ***************************************************************************/
1060 int update_Edge( struct DCEL_T *dcel, int origin, int twin, int prev, int next,
1061  int face,
1062  int index)
1063 {
1064  int ret=SUCCESS; // Return value.
1065 
1066  // Check index is not out of bounds.
1067  if (index >= dcel->nEdges)
1068  {
1069  printf("Trying to update index edge %d out of bounds %d\n",
1070  index,
1071  dcel->nEdges);
1072 #ifdef LOGGING
1073  sprintf("Trying to update index edge %d out of bounds %d\n",
1074  index,
1075  dcel->nEdges);
1076  write_Log( log_Text);
1077 #endif
1078  ret = FAILURE;
1079  }
1080  else
1081  {
1082  // Check if origin point field must be updated.
1083  if (origin != NO_UPDATE)
1084  {
1085  dcel->edges[index].origin_Vertex = origin;
1086  }
1087 
1088  // Check if twin edge field must be updated.
1089  if (twin != NO_UPDATE)
1090  {
1091  dcel->edges[index].twin_Edge = twin;
1092  }
1093 
1094  // Check if prev edge field must be updated.
1095  if (prev != NO_UPDATE)
1096  {
1097  dcel->edges[index].previous_Edge = prev;
1098  }
1099 
1100  // Check if next edge field must be updated.
1101  if (next != NO_UPDATE)
1102  {
1103  dcel->edges[index].next_Edge = next;
1104  }
1105 
1106  // Check if face field must be updated.
1107  if (face != NO_UPDATE)
1108  {
1109  dcel->edges[index].face = face ;
1110  }
1111 
1112 #ifdef DEBUG_UPDATE_EDGE
1113  printf("Updated edge %d. Origin %d Twin %d Prev %d Next %d Face %d.\n",
1114  index + 1,
1115  origin,
1116  twin,
1117  prev,
1118  next,
1119  face);
1120 #endif
1121  }
1122 
1123  return(ret);
1124 }
1125 
1126 
1127 /***************************************************************************
1128 * Name: are_Twins
1129 * IN: dcel dcel DATA
1130 * edge1 first edge
1131 * edge2 secomd edge
1132 * OUT: N/A
1133 * IN/OUT: N/A
1134 * RETURN: TRUE if edge are twins. FALSE i.o.c.
1135 * Description: Checks if "edge1" and "edge2" are twin in "dcel".
1136 ***************************************************************************/
1137 int are_Twins( struct DCEL_T *dcel, struct Dcel_Edge_T *edge1,
1138  struct Dcel_Edge_T *edge2)
1139 {
1140  int twins=0; // Return value.
1141  struct Dcel_Vertex_T *origin1=NULL; // Origin of edge 1.
1142  struct Dcel_Vertex_T *dest1=NULL; // Destination of edge 1.
1143  struct Dcel_Vertex_T *origin2=NULL; // Origin of edge 2.
1144  struct Dcel_Vertex_T *dest2=NULL; // Destination of edge 2.
1145 
1146  // Get origin and destination points of edge 1.
1147  origin1 = get_Vertex( dcel, edge1->origin_Vertex-1);
1148  dest1 = get_Vertex( dcel, dcel->edges[edge1->next_Edge-1].origin_Vertex-1);
1149 
1150  // Get origin and destination points of edge 2.
1151  origin2 = get_Vertex( dcel, edge2->origin_Vertex-1);
1152  dest2 = get_Vertex( dcel, dcel->edges[edge2->next_Edge-1].origin_Vertex-1);
1153 
1154  // Check if both edges share origin and destination.
1155  twins = 0;
1156  if (equal_Point( &origin1->vertex, &dest2->vertex) &&
1157  equal_Point( &origin2->vertex, &dest1->vertex))
1158  {
1159  twins = 1;
1160  }
1161 
1162  return(twins);
1163 }
1164 
1165 
1166 /***************************************************************************
1167 * Name: is_External_Edge
1168 * IN: dcel dcel DATA
1169 * index edge index.
1170 * OUT: N/A
1171 * IN/OUT: N/A
1172 * RETURN: TRUE if edge at "index" position is in external face. FALSE i.o.c.
1173 * Description: Checks if edge at "index" position is in external face.
1174 ***************************************************************************/
1175 int is_External_Edge( struct DCEL_T *dcel, int index)
1176 {
1177  int is_External=FALSE; // Return value.
1178 
1179  // Check index is not out of bounds.
1180  if (index >= dcel->nEdges)
1181  {
1182  printf("Trying to check an edge %d out of bounds %d in is_External_Edge\n",
1183  index,
1184  dcel->nEdges);
1185 #ifdef LOGGING
1186  sprintf("Trying to check an edge %d out of bounds %d in is_External_Edge\n",
1187  index,
1188  dcel->nEdges);
1189  write_Log( log_Text);
1190 #endif
1191  is_External = FALSE;
1192  }
1193  else
1194  {
1195  // Check if this edge or its twin belong face #0.
1196  if ((dcel->edges[index].face == EXTERNAL_FACE) ||
1197  (dcel->edges[dcel->edges[index].twin_Edge-1].face == EXTERNAL_FACE))
1198  {
1199  // Edge is external.
1200  is_External = TRUE;
1201  }
1202  }
1203 
1204  return(is_External);
1205 }
1206 
1207 
1208 /***************************************************************************
1209 * Name: get_Edge_Origin_Vertex
1210 * IN: dcel dcel DATA
1211 * edge_Index edge index.
1212 * OUT: N/A
1213 * IN/OUT: N/A
1214 * RETURN: origin vertex of edge at "edge_Index" position in the DCEL
1215 * Description: Returns the origin vertex of edge at "edge_Index" position
1216 * in the DCEL
1217 ***************************************************************************/
1218 int get_Edge_Origin_Vertex( struct DCEL_T *dcel, int edge_Index)
1219 {
1220  // Check index is not out of bounds.
1221  if (edge_Index >= dcel->nEdges)
1222  {
1223  printf("Trying to get edge %d out of bounds %d in get_Edge_Origin_Vertex\n",
1224  edge_Index,
1225  dcel->nEdges);
1226 #ifdef LOGGING
1227  sprintf("Trying to check an edge %d out of bounds %d in is_External_Edge\n",
1228  index,
1229  dcel->nEdges);
1230  write_Log( log_Text);
1231 #endif
1232  return(dcel->edges[0].origin_Vertex);
1233  }
1234  else
1235  {
1236  // Return origin of edge at position edge_Index.
1237  return(dcel->edges[edge_Index].origin_Vertex);
1238  }
1239 }
1240 
1241 //#define DEBUG_GET_EDGE_IN_CONVEX_HULL
1242 int get_Edge_In_Convex_Hull( struct DCEL_T *dcel, int firstEdge_Index)
1243 {
1244  int found=FALSE; // Loop control flag.
1245  int edge_Index=0; // Edge index.
1246 
1247  // Get first edge index.
1248  edge_Index = firstEdge_Index;
1249 
1250  // Check all edges in current face.
1251  while (!found)
1252  {
1253 #ifdef DEBUG_GET_EDGE_IN_CONVEX_HULL
1254  printf("Checking convex hull edge index %d. Points are %d and %d\n", edge_Index,
1255  dcel->edges[edge_Index].origin_Vertex,
1256  dcel->edges[dcel->edges[edge_Index].twin_Edge-1].origin_Vertex);
1257 #endif
1258  // Check origin and destination are positive.
1259  if ((dcel->edges[edge_Index].origin_Vertex >= 0) &&
1260  (dcel->edges[dcel->edges[edge_Index].twin_Edge-1].origin_Vertex >= 0))
1261  {
1262  found = TRUE;
1263  }
1264  // Next edge.
1265  else
1266  {
1267  edge_Index = dcel->edges[edge_Index].next_Edge - 1;
1268  }
1269  }
1270 
1271 #ifdef DEBUG_GET_EDGE_IN_CONVEX_HULL
1272  printf("Found edge %d.\n", edge_Index+1);
1273 #endif
1274 
1275  return(edge_Index+1);
1276 }
1277 
1278 /***************************************************************************
1279 * Name: get_Edge
1280 * IN: dcel dcel DATA
1281 * index edge index.
1282 * OUT: N/A
1283 * IN/OUT: N/A
1284 * RETURN: edge at "index" position in the DCEL
1285 * Description: Returns the edge at "index" position in the DCEL
1286 ***************************************************************************/
1287 struct Dcel_Edge_T *get_Edge( struct DCEL_T *dcel, int index)
1288 {
1289  // Check index is not out of bounds.
1290  if (index >= dcel->nEdges)
1291  {
1292  printf("Trying to get edge %d out of bounds %d in get_Edge\n",
1293  index,
1294  dcel->nEdges);
1295 #ifdef LOGGING
1296  sprintf("Trying to check an edge %d out of bounds %d in get_Edge\n",
1297  index,
1298  dcel->nEdges);
1299  write_Log( log_Text);
1300 #endif
1301  return(&dcel->edges[0]);
1302  }
1303  else
1304  {
1305  // Return edge.
1306  return(&dcel->edges[index]);
1307  }
1308 }
1309 
1310 
1311 /***************************************************************************
1312 * Name: copy_Edge
1313 * IN: dcel dcel DATA
1314 * index edge index.
1315 * OUT: edge copied edge
1316 * IN/OUT: N/A
1317 * RETURN: SUCCESS if edge copied. FAILURE i.o.c.
1318 * Description: copies edge at "index" position in "edge"
1319 ***************************************************************************/
1320 int copy_Edge( struct DCEL_T *dcel, int index, struct Dcel_Edge_T *edge)
1321 {
1322  int ret=SUCCESS; // Return value.
1323 
1324  // Check index is not out of bounds.
1325  if (index >= dcel->nEdges)
1326  {
1327  printf("Trying to get edge %d out of bounds %d in copy_Edge\n",
1328  index,
1329  dcel->nEdges);
1330 #ifdef LOGGING
1331  sprintf("Trying to check an edge %d out of bounds %d in copy_Edge\n",
1332  index,
1333  dcel->nEdges);
1334  write_Log( log_Text);
1335 #endif
1336  ret = FAILURE;
1337  }
1338  else
1339  {
1340  // Copy edge information.
1341  edge->face = dcel->edges[index].face;
1342  edge->next_Edge = dcel->edges[index].next_Edge;
1343  edge->origin_Vertex = dcel->edges[index].origin_Vertex;
1344  edge->previous_Edge = dcel->edges[index].previous_Edge;
1345  edge->twin_Edge = dcel->edges[index].twin_Edge;
1346  }
1347 
1348  return(ret);
1349 }
1350 
1351 
1352 /***************************************************************************
1353 * Name: get_Number_Faces
1354 * IN: dcel dcel DATA
1355 * OUT: N/A
1356 * IN/OUT: N/A
1357 * RETURN: # faces in the DCEL
1358 * Description: returns # faces in the DCEL
1359 ***************************************************************************/
1360 int get_Number_Faces(struct DCEL_T *dcel)
1361 {
1362  // Return the number of faces.
1363  return(dcel->nFaces);
1364 }
1365 
1366 
1367 //#define DEBUG_INSERTFACE
1368 /***************************************************************************
1369 * Name: insertFace
1370 * IN: edge_ID new edge assigned to face
1371 * OUT: N/A
1372 * IN/OUT: dcel dcel data
1373 * RETURN: N/A
1374 * Description: Inserts a new face in the dcel
1375 ***************************************************************************/
1376 int insertFace( struct DCEL_T *dcel, int edge_ID)
1377 {
1378  int ret=SUCCESS; // Return value.
1379 
1380  // Check if DCEL faces is full.
1381  if (dcel->nFaces == dcel->sizeFaces)
1382  {
1383  printf("DCEL faces array is full. Size %d # elements %d.\n",
1384  dcel->sizeFaces,
1385  dcel->nFaces);
1386 
1387  // Resize faces array.
1388  if (resize_DCEL( dcel, RESIZE_FACES) == FAILURE)
1389  {
1390 #ifdef LOGGING
1391  sprintf("Error resizing DCEL in insertFace.\n");
1392  write_Log( log_Text);
1393 #endif
1394  printf("Error resizing DCEL in insertFace.\n");
1395  ret = FAILURE;
1396  }
1397  }
1398 
1399  if (ret == SUCCESS)
1400  {
1401 #ifdef DEBUG_INSERTFACE
1402  printf("Insert face %d with edge %d\n", dcel->nFaces, edge_ID);
1403 #endif
1404  // Update face edge.
1405  dcel->faces[dcel->nFaces].edge = edge_ID;
1406 
1407  // Set face as real.
1408  dcel->faces[dcel->nFaces].imaginaryFace = VALID;
1409 
1410  // Update number of faces.
1411  dcel->nFaces++;
1412  }
1413 
1414  return(ret);
1415 }
1416 
1417 
1418 //#define DEBUG_UPDATE_FACE
1419 /***************************************************************************
1420 * Name: update_Face
1421 * IN: dcel dcel data
1422 * edge_ID new edge assigned to face
1423 * index face index
1424 * OUT: N/A
1425 * RETURN: N/A
1426 * Description: Updates the edge assigned to "index" face.
1427 ***************************************************************************/
1428 int update_Face(struct DCEL_T *dcel, int edge_ID, int index)
1429 {
1430  int ret=SUCCESS; // Return value.
1431 
1432  // Check if DCEL faces is full.
1433  if (dcel->nFaces == dcel->sizeFaces)
1434  {
1435  printf("DCEL faces array is full. Size %d # elements %d.\n",
1436  dcel->sizeFaces,
1437  dcel->nFaces);
1438 
1439  // Resize faces array.
1440  if (resize_DCEL( dcel, RESIZE_FACES) == FAILURE)
1441  {
1442 #ifdef LOGGING
1443  sprintf("Error resizing DCEL in update_Face.\n");
1444  write_Log( log_Text);
1445 #endif
1446  printf("Error resizing DCEL in update_Face.\n");
1447  ret = FAILURE;
1448  }
1449  }
1450 
1451  if (ret == SUCCESS)
1452  {
1453 #ifdef DEBUG_UPDATE_FACE
1454  printf("Updating face %d with edge %d\n", index, edge_ID);
1455 #endif
1456  // Update edge id of face at index-th position.
1457  if (edge_ID == INVALID)
1458  {
1459  dcel->faces[index].imaginaryFace = INVALID;
1460  }
1461  else
1462  {
1463  dcel->faces[index].edge = edge_ID;
1464  }
1465  }
1466 
1467  return(ret);
1468 }
1469 
1470 
1471 /***************************************************************************
1472 * Name: get_Face
1473 * IN: dcel dcel data
1474 * index face index
1475 * OUT: N/A
1476 * RETURN: returns the face stored at index position
1477 * Description: returns the face stored at index position
1478 ***************************************************************************/
1479 struct Dcel_Face_T *get_Face( struct DCEL_T *dcel, int index)
1480 {
1481  // Check if DCEL faces is full.
1482  if (index >= dcel->nFaces)
1483  {
1484  printf("Trying to get face %d out of bounds %d in get_Face\n",
1485  index,
1486  dcel->nFaces);
1487 #ifdef LOGGING
1488  sprintf("Trying to get an face %d out of bounds %d in get_Face\n",
1489  index,
1490  dcel->nFaces);
1491  write_Log( log_Text);
1492 #endif
1493  return(&dcel->faces[0]);
1494  }
1495  else
1496  {
1497  // Return face.
1498  return(&dcel->faces[index]);
1499  }
1500 }
1501 
1502 //#define DEBUG_GET_FACE_VERTEX
1503 /***************************************************************************
1504 * Name: get_Face_Vertex
1505 * IN: dcel DCEL data
1506 * face_ID face index
1507 * OUT: v1 first vertex
1508 * v2 third vertex
1509 * v3 second vertex
1510 * RETURN: SUCCESS if face into face array bounds. FAILURE i.o.c.
1511 * Description: returns the three vertices of the face at "face_ID" position.
1512 ***************************************************************************/
1513 int get_Face_Vertex( struct DCEL_T *dcel, int face_ID, struct Dcel_Vertex_T *v1,
1514  struct Dcel_Vertex_T *v2,
1515  struct Dcel_Vertex_T *v3)
1516 {
1517  int ret=SUCCESS; // Return value.
1518 
1519  // Check if DCEL faces is full.
1520  if (face_ID >= dcel->nFaces)
1521  {
1522  printf("Trying to get face %d out of bounds %d in get_Face\n",
1523  face_ID,
1524  dcel->nFaces);
1525 #ifdef LOGGING
1526  sprintf("Trying to get an face %d out of bounds %d in get_Face\n",
1527  face_ID,
1528  dcel->nFaces);
1529  write_Log( log_Text);
1530 #endif
1531  ret = FAILURE;
1532  }
1533  else
1534  {
1535 #ifdef DEBUG_GET_FACE_VERTEX
1536  printf("Three vertices points are %d %d %d\n", dcel->edges[dcel->faces[face_ID].edge-1].origin_Vertex,
1537  dcel->edges[dcel->edges[dcel->faces[face_ID].edge-1].next_Edge-1].origin_Vertex,
1538  dcel->edges[dcel->edges[dcel->faces[face_ID].edge-1].previous_Edge-1].origin_Vertex);
1539 #endif
1540  // Get first point.
1541  v1->vertex.x = dcel->vertex[dcel->edges[dcel->faces[face_ID].edge-1].origin_Vertex-1].vertex.x;
1542  v1->vertex.y = dcel->vertex[dcel->edges[dcel->faces[face_ID].edge-1].origin_Vertex-1].vertex.y;
1543 
1544  // Get second point.
1545  v2->vertex.x = dcel->vertex[dcel->edges[dcel->edges[dcel->faces[face_ID].edge-1].next_Edge-1].origin_Vertex-1].vertex.x;
1546  v2->vertex.y = dcel->vertex[dcel->edges[dcel->edges[dcel->faces[face_ID].edge-1].next_Edge-1].origin_Vertex-1].vertex.y;
1547 
1548  // Get third point.
1549  v3->vertex.x = dcel->vertex[dcel->edges[dcel->edges[dcel->faces[face_ID].edge-1].previous_Edge-1].origin_Vertex-1].vertex.x;
1550  v3->vertex.y = dcel->vertex[dcel->edges[dcel->edges[dcel->faces[face_ID].edge-1].previous_Edge-1].origin_Vertex-1].vertex.y;
1551  }
1552 
1553  return(ret);
1554 }
1555 
1556 
1557 /***************************************************************************
1558 * Name: get_Number_Real_Faces
1559 * IN: dcel dcel data
1560 * OUT: pointsSet array of three Point_T that are the vertex of the triangle
1561 * RETURN: # real faces in triangulation
1562 * Description: returns the number of real faces in a Delaunay triangulation.
1563 * Real faces are those triangles that belong to a Delaunay
1564 * triangulation that was built incrementally and so it can
1565 * contain imaginary faces due to imaginary points taken into
1566 * account while building the triangulation.
1567 ***************************************************************************/
1569 {
1570  int i=0; // Loop counter.
1571  struct Dcel_Face_T *face=NULL; // Current face.
1572  int nFaces=0; // Return value.
1573 
1574  // Loop all faces.
1575  for (i=1; i<dcel->nFaces ;i++)
1576  {
1577  // Get i-face.
1578  face = get_Face( dcel, i);
1579 
1580  // Check if it is a real face.
1581  if (face->imaginaryFace == VALID)
1582  {
1583  nFaces++;
1584  }
1585  }
1586 
1587  return(nFaces);
1588 }
1589 
1590 
1591 
1592 /***************************************************************************
1593 * Name: get_Vertex_Of_Face
1594 * IN: dcel DCEL data
1595 * face face id
1596 * OUT: index1 first vertex id
1597 * index2 second vertex id
1598 * index3 third vertex id
1599 * IN/OUT: N/A
1600 * RETURN: N/A
1601 * Description: returns the three vertex id of the "face" face.
1602 ***************************************************************************/
1603 void get_Vertex_Of_Face( struct DCEL_T *dcel, int face, int *index1,
1604  int *index2,
1605  int *index3)
1606 {
1607  int edgeIndex=0; // Edge index.
1608 
1609  // Get index in face.
1610  edgeIndex = dcel->faces[face].edge-1;
1611 
1612  // Get vertices from face.
1613  (*index1) = dcel->edges[edgeIndex].origin_Vertex;
1614  (*index2) = dcel->edges[dcel->edges[edgeIndex].twin_Edge-1].origin_Vertex;
1615  (*index3) = dcel->edges[dcel->edges[edgeIndex].previous_Edge-1].origin_Vertex;
1616 }
1617 
1618 
1619 /***************************************************************************
1620 * Name: is_Interior_To_Face
1621 * IN: dcel triangulation DCEL
1622 * p input point
1623 * face face id to check
1624 * OUT: N/A
1625 * RETURN: True TRUE if point is interior to face
1626 * Description: check if input point p is interior to "face" triangle.
1627 ***************************************************************************/
1628 bool is_Interior_To_Face( struct DCEL_T *dcel, struct Point_T *p, int face_ID)
1629 {
1630  int edge_Index=0; // Edge index.
1631  bool is_Interior=false; // Return value.
1632  struct Dcel_Vertex_T p1, p2, p3; // Temporary points.
1633 
1634  // Check face is not out of bounds.
1635  if (face_ID >= dcel->nFaces)
1636  {
1637  printf("Checking face %d out of bounds %d in is_Interior_To_Face\n",
1638  face_ID,
1639  dcel->nFaces);
1640 #ifdef LOGGING
1641  sprintf("Checking face %d out of bounds %d in is_Interior_To_Face\n",
1642  face_ID,
1643  dcel->nFaces);
1644  write_Log( log_Text);
1645 #endif
1646  is_Interior = false;
1647  }
1648  else
1649  {
1650  // Get edge index of edge departing from face_ID.
1651  edge_Index = dcel->faces[face_ID].edge-1;
1652 
1653  // Get points of current face.
1654  p1 = dcel->vertex[dcel->edges[dcel->edges[edge_Index].previous_Edge-1].origin_Vertex-1];
1655  p2 = dcel->vertex[dcel->edges[edge_Index].origin_Vertex-1];
1656  p3 = dcel->vertex[dcel->edges[dcel->edges[edge_Index].next_Edge-1].origin_Vertex-1];
1657 
1658  // Compute if point is interior.
1659  is_Interior = interior_Triangle( &p1.vertex, &p2.vertex, &p3.vertex, p);
1660  }
1661 
1662  return(is_Interior);
1663 }
1664 
1665 
1666 
1667 //#define DEBUG_IS_NEGATIVE_ANY_VERTEX
1668 /***************************************************************************
1669 * Name: is_Negative_Any_Vertex
1670 * IN: dcel DCEL data
1671 * edgeID edge identifier
1672 * OUT: N/A
1673 * RETURN: TRUE if any vertex in edge "edgeID" is negative. FALSE i.o.c.
1674 * Description: checks if any vertex in edge "edgeID" is negative
1675 ***************************************************************************/
1676 int is_Negative_Any_Vertex( struct DCEL_T *dcel, int edgeID)
1677 {
1678  int is_Negative=FALSE; // Return value.
1679 
1680  // Check face is not out of bounds.
1681  if (edgeID > dcel->nEdges)
1682  {
1683  printf("Checking edge %d out of bounds %d in is_Negative_Any_Vertex\n",
1684  edgeID,
1685  dcel->nEdges);
1686 #ifdef LOGGING
1687  sprintf("Checking edge %d out of bounds %d in is_Negative_Any_Vertex\n",
1688  edgeID,
1689  dcel->nEdges);
1690  write_Log( log_Text);
1691 #endif
1692  is_Negative = FALSE;
1693  }
1694  else
1695  {
1696 #ifdef DEBUG_IS_NEGATIVE_ANY_VERTEX
1697  printf("Origin %d Destination %d\n", dcel->edges[edgeID-1].origin_Vertex,
1698  dcel->edges[dcel->edges[edgeID-1].next_Edge-1].origin_Vertex);
1699 #endif
1700  // Check if any of the vertex of the triangle is negative.
1701  if ((dcel->edges[edgeID-1].origin_Vertex < 0) ||
1702  (dcel->edges[dcel->edges[edgeID-1].next_Edge-1].origin_Vertex < 0))
1703  {
1704  is_Negative = TRUE;
1705  }
1706  }
1707 
1708  return(is_Negative);
1709 }
1710 
1711 /***************************************************************************
1712 * Name: printFace
1713 * IN: dcel DCEL data
1714 * faceID face identifier
1715 * OUT: N/A
1716 * RETURN: N/A
1717 * Description: prints face information.
1718 ***************************************************************************/
1719 void printFace( struct DCEL_T *dcel, int faceID)
1720 {
1721  // Print face id.
1722  printf("Face %d.\n", faceID);
1723 
1724  // Print face edges.
1725  printf("\tEdges:\t%d\t\t%d\t\t%d.\n", dcel->faces[faceID].edge,
1726  dcel->edges[dcel->faces[faceID].edge-1].next_Edge,
1727  dcel->edges[dcel->faces[faceID].edge-1].previous_Edge);
1728 
1729  // Print face vertices.
1730  printf("\tVertices:\t%d\t\t%d\t\t%d.\n", dcel->edges[dcel->faces[faceID].edge-1].origin_Vertex,
1731  dcel->edges[dcel->edges[dcel->faces[faceID].edge-1].next_Edge-1].origin_Vertex,
1732  dcel->edges[dcel->edges[dcel->faces[faceID].edge-1].previous_Edge-1].origin_Vertex);
1733 }
1734 
1735 //#define DEBUG_RETURN_TURN
1736 enum Turn_T return_Turn( struct DCEL_T *dcel, struct Point_T *p, int source_ID, int dest_ID)
1737 {
1738  enum Turn_T turn=LEFT_TURN; // Return value.
1739 
1740  // Normal source point.
1741  if (source_ID > 0)
1742  {
1743  // Normal destination point.
1744  if (dest_ID > 0)
1745  {
1746  // If turn right then point is not in triangle.
1747  turn = check_Turn( &dcel->vertex[source_ID-1].vertex, &dcel->vertex[dest_ID-1].vertex, p);
1748  }
1749  // Destination point is P-2.
1750  else if (dest_ID == P_MINUS_2)
1751  {
1752  if (source_ID == 1)
1753  {
1754  turn = LEFT_TURN;
1755  }
1756  // Check if point is over line from source_Index point to P-2.
1757  else if (higher_Point( p, &dcel->vertex[source_ID-1].vertex, &lexicographic_Higher))
1758  {
1759  turn = RIGHT_TURN;
1760  }
1761  else
1762  {
1763  turn = LEFT_TURN;
1764  }
1765  }
1766  // Destination point is P-1.
1767  else
1768  {
1769  // Check if point is over line from source_Index point to P-1.
1770  if (higher_Point( p, &dcel->vertex[source_ID-1].vertex, &lexicographic_Higher))
1771  {
1772  turn = LEFT_TURN;
1773  }
1774  else
1775  {
1776  turn = RIGHT_TURN;
1777  }
1778  }
1779  }
1780  else
1781  {
1782  // Source point is P-1 and destination cannot be p-2.
1783  if (source_ID == P_MINUS_1)
1784  {
1785  if (dest_ID == 1)
1786  {
1787  turn = LEFT_TURN;
1788  }
1789  // Check if point is over line from P-1 point to dest_Index point.
1790  else if (higher_Point( p, &dcel->vertex[dest_ID-1].vertex, &lexicographic_Higher))
1791  {
1792  turn = RIGHT_TURN;
1793  }
1794  else
1795  {
1796  turn = LEFT_TURN;
1797  }
1798  }
1799  // Source point is P-2.
1800  else
1801  {
1802  // Check destination point.
1803  if (dest_ID != P_MINUS_1)
1804  {
1805  if (higher_Point( p, &dcel->vertex[dest_ID-1].vertex, &lexicographic_Higher))
1806  {
1807  turn = LEFT_TURN;
1808  }
1809  else
1810  {
1811  turn = RIGHT_TURN;
1812  }
1813  }
1814  else
1815  {
1816  // Points can only do a left turn.
1817  turn = LEFT_TURN;
1818  }
1819  }
1820  }
1821 
1822 #ifdef DEBUG_RETURN_TURN
1823  printf("Turn between segment %d %d and point \n", source_ID, dest_ID);
1824  print_Point( p);
1825  if (turn == LEFT_TURN)
1826  {
1827  printf(" is LEFT_TURN\n");
1828  }
1829  else if (turn == RIGHT)
1830  {
1831  printf(" is RIGHT\n");
1832  }
1833  else
1834  {
1835  printf(" is COLLINEAR\n");
1836  }
1837 #endif
1838 
1839  return(turn);
1840 }
1841 
1842 void shake_Dcel( struct DCEL_T *dcel)
1843 {
1844  int point_Index=0; // Loop counter.
1845 
1846  // Loop all points.
1847  for (point_Index=0; point_Index<dcel->nVertex ;point_Index++)
1848  {
1849  // Add a delta value to all points in dcel.
1850  dcel->vertex[point_Index].vertex.x = dcel->vertex[point_Index].vertex.x + 0.1;
1851  dcel->vertex[point_Index].vertex.y = dcel->vertex[point_Index].vertex.y + 0.1;
1852  }
1853 }
1854 
1855 void get_Extreme_Point( struct DCEL_T *dcel, int (*f)(struct Point_T *, struct Point_T *),
1856  struct Point_T *p)
1857 {
1858  int edge_Index=0; // Edge index.
1859  int point_Index=0, first=0; // Edge index.
1860  int finished=FALSE; // Loop control flag.
1861 
1862  // Initialize loop.
1863  edge_Index = dcel->faces[EXTERNAL_FACE].edge-1;
1864  point_Index = dcel->edges[edge_Index].origin_Vertex-1;
1865  first = point_Index;
1866 
1867  // Get first point.
1868  p->x = dcel->vertex[point_Index].vertex.x;
1869  p->y = dcel->vertex[point_Index].vertex.y;
1870 
1871  // Search in convex hull.
1872  finished = FALSE;
1873  while (!finished)
1874  {
1875  // Get next edge and next origin point.
1876  edge_Index = dcel->edges[edge_Index].next_Edge-1;
1877  point_Index = dcel->edges[edge_Index].origin_Vertex-1;
1878 
1879  // Check if all points in convex hull have been checked.
1880  if (point_Index == first)
1881  {
1882  finished = TRUE;
1883  }
1884  else
1885  {
1886  // Check if new point is better than current.
1887  if (f( &dcel->vertex[point_Index].vertex, p))
1888  {
1889  // Update most point.
1890  p->x = dcel->vertex[point_Index].vertex.x;
1891  p->y = dcel->vertex[point_Index].vertex.y;
1892  }
1893  }
1894  }
1895 }
1896 
1897 //#define DEBUG_GET_CONVEX_HULL
1898 /***************************************************************************
1899 * Name: get_Convex_Hull
1900 * IN: dcel dcel data
1901 * OUT: points vector where convex hull points are returned
1902 * IN/OUT: length contains vector length as input and contains
1903 * convex hull length as output.
1904 * RETURN: true if convex hull built. false i.o.c.
1905 * Description: returns in "points" the set of points of the convex hull of
1906 * the "dcel" and returns in "length" the number of points.
1907 * Returns true if the convex hull was stored in the "points"
1908 * vector and true if the vector had not enough space.
1909 ***************************************************************************/
1910 bool get_Convex_Hull( struct DCEL_T *dcel, int *length, int *points)
1911 {
1912  int nPoints=0; // # points in convex hull.
1913  bool finished=false; // Loop control flag.
1914  bool built=false; // Return value.
1915  int firstIndex=0; // First index in convex hull.
1916  int edgeIndex=0; // Current index.
1917 
1918  // Check if vector has been allocated.
1919  if (((*length) > 0) && (dcel->nFaces > 0))
1920  {
1921 #ifdef DEBUG_GET_CONVEX_HULL
1922  printf("Initial point %d\n", dcel->edges[0].origin_Vertex);
1923 #endif
1924  // Insert initial point.
1925  points[nPoints] = dcel->edges[0].origin_Vertex;
1926  nPoints++;
1927 
1928  // Get edge departing from 0 point.
1929  edgeIndex = dcel->vertex[0].origin_Edge - 1;
1930 
1931  // Get edge departing from 0 to MINUS_2.
1932  finished = false;
1933  while (!finished)
1934  {
1935  if ((dcel->edges[edgeIndex].origin_Vertex == 1) &&
1936  (dcel->edges[dcel->edges[edgeIndex].twin_Edge-1].origin_Vertex == P_MINUS_2))
1937  {
1938  finished = true;
1939 #ifdef DEBUG_GET_CONVEX_HULL
1940  printf("Found first edge %d. O %d D %d\n", edgeIndex,
1941  dcel->edges[edgeIndex].origin_Vertex,
1942  dcel->edges[dcel->edges[edgeIndex].twin_Edge-1].origin_Vertex);
1943 #endif
1944  }
1945  else
1946  {
1947  // Get next edge departing from 0 point.
1948  edgeIndex = dcel->edges[dcel->edges[edgeIndex].previous_Edge-1].twin_Edge - 1;
1949  }
1950  }
1951 
1952  // Get next edge as it is the first edge in the convex hull.
1953  edgeIndex = dcel->edges[edgeIndex].previous_Edge-1;
1954  firstIndex = edgeIndex;
1955 
1956  // Get all convex hull points.
1957  finished = false;
1958  while ((!built) && (!finished))
1959  {
1960  // Insert next point.
1961  if (nPoints < (*length))
1962  {
1963  points[nPoints] = dcel->edges[edgeIndex].origin_Vertex;
1964  nPoints++;
1965  }
1966 #ifdef DEBUG_GET_CONVEX_HULL
1967  printf("Next point %d\n", dcel->edges[edgeIndex].origin_Vertex);
1968 #endif
1969 
1970  // Get next edge.
1971  edgeIndex = dcel->edges[edgeIndex].previous_Edge-1;
1972  edgeIndex = dcel->edges[edgeIndex].twin_Edge-1;
1973  edgeIndex = dcel->edges[edgeIndex].previous_Edge-1;
1974 
1975  // If point is imaginary then skip edge.
1976  if (dcel->edges[edgeIndex].origin_Vertex < 0)
1977  {
1978  edgeIndex = dcel->edges[edgeIndex].twin_Edge-1;
1979  edgeIndex = dcel->edges[edgeIndex].previous_Edge-1;
1980  }
1981 
1982  // Check if first edge reached.
1983  if (edgeIndex == firstIndex)
1984  {
1985  // End loop and update vector length.
1986  if (nPoints < (*length))
1987  {
1988  built = true;
1989  }
1990  finished = true;
1991  (*length) = nPoints - 1;
1992 #ifdef DEBUG_GET_CONVEX_HULL
1993  printf("Finished\n");
1994 #endif
1995  }
1996  }
1997  }
1998  else
1999  {
2000  built = false;
2001  }
2002 
2003  return(built);
2004 }
2005 
2006 //#define DEBUG_INTERIOR_TO_CONVEX_HULL
2007 /***************************************************************************
2008 * Name: is_Interior_To_Convex_Hull
2009 * IN: dcel dcel data
2010 * p point to be checked
2011 * OUT: error error while executing function.
2012 * IN/OUT: N/A
2013 * RETURN: true if point is interior to convex hull. false i.o.c.
2014 * Description: checks if input point "p" is interior to triangulation in
2015 * "dcel" DCEL. To be interior the turn between all edges
2016 * and the point must not be a RIGHT turn.
2017 ***************************************************************************/
2018 bool is_Interior_To_Convex_Hull( struct DCEL_T *dcel, struct Point_T *p, bool *error)
2019 {
2020  bool isInterior=false; // Return value.
2021  int *convex=NULL; // Set of points in convex hull.
2022  int length=DEFAULT_CONVEX_HULL_LEN; // Convex hull length.
2023  bool built=false; // Convex hull built flag.
2024  int index=0; // Vector index.
2025  bool finished=false; // Loop control flag.
2026 
2027  // Initialize loop.
2028  built = false;
2029  (*error) = false;
2030 
2031  // Loop to get convex hull.
2032  while ((!built) && (!(*error)))
2033  {
2034  // Allocate vector.
2035  if ((convex = (int *)malloc(sizeof(int)*length)) == NULL)
2036  {
2037  (*error) = true;
2038 #ifdef LOGGING
2039  sprintf( log_Text, "Error allocating memory for convex hull vector");
2040  write_Log( log_Text, "interior_To_Convex_Hull", true);
2041 #else
2042  printf("Function interior_To_Convex_Hull:\n");
2043  printf("Error allocating memory for convex hull vector\n");
2044 #endif
2045  }
2046  // Check error getting convex hull.
2047  else if (!get_Convex_Hull( dcel, &length, convex))
2048  {
2049  // Deallocate vector.
2050  free(convex);
2051  }
2052  else
2053  {
2054  // Convex hull successfully built.
2055  built = true;
2056  }
2057  }
2058 
2059  // Check error while allocating vector.
2060  if (!(*error))
2061  {
2062  // Initialize loop variables.
2063  index = 0;
2064  isInterior = true;
2065  finished = false;
2066 
2067  // Loop to check all edges in convex hull.
2068  while ((isInterior) && (!finished))
2069  {
2070  // Check if all points checked.
2071  if (index == (length-1))
2072  {
2073  finished = true;
2074  }
2075  // Next edge.
2076  else
2077  {
2078  // Check if it is a right turn.
2079  if (return_Turn( dcel, p, convex[index], convex[index+1]) == RIGHT_TURN)
2080  {
2081  // It is not interior.
2082  isInterior = false;
2083  }
2084  else
2085  {
2086  // Next point in convex hull.
2087  index++;
2088  }
2089  }
2090  }
2091 
2092  // Deallocate vector.
2093  free(convex);
2094  }
2095 
2096  return(isInterior);
2097 }
2098 
2099 //#define DEBUG_READ_POINTS_DCEL
2100 int read_Points_DCEL( FILE *fd, int nPoints, struct DCEL_T *dcel)
2101 {
2102  int ret=SUCCESS; // Return value.
2103  int i=0; // Loop counter.
2104  struct Dcel_Vertex_T point; // Temp point.
2105  struct Dcel_Vertex_T bottom_Most;// Bottom most point.
2106 
2107  // Initialize bottom most.
2108  bottom_Most.vertex.x = MAX_X_COORD;
2109  bottom_Most.vertex.y = MAX_Y_COORD;
2110 
2111  // Add elements.
2112  i=0;
2113  while ((i<nPoints) && (ret==SUCCESS))
2114  {
2115 #ifdef DEBUG_READ_POINTS_DCEL
2116  printf("Reading point %d\n", i+1);
2117 #endif
2118  // Read point.
2119  if (fscanf( fd, "%f", &point.vertex.x) != 1)
2120  {
2121  ret = FAILURE;
2122 #ifdef LOGGING
2123  sprintf( log_Text, "Fail reading X coordinate of %dth point", i+1);
2124  write_Log( log_Text);
2125 #endif
2126  printf("Fail reading X coordinate of %dth point", i+1);
2127  }
2128  else if (fscanf( fd, "%f", &point.vertex.y) != 1)
2129  {
2130  ret = FAILURE;
2131 #ifdef LOGGING
2132  sprintf( log_Text, "Fail reading Y coordinate of %dth point", i+1);
2133  write_Log( log_Text);
2134 #endif
2135  printf("Fail reading Y coordinate of %dth point", i+1);
2136  }
2137  else
2138  {
2139 #ifdef DEBUG_READ_POINTS_DCEL
2140  printf("Point read (%lf,%lf)\n", point.vertex.x, point.vertex.y);
2141 #endif
2142  // Insert new point.
2143  point.origin_Edge = -1;
2144  insertVertex( dcel, point);
2145 
2146  // Update bottom most point.
2147  if (point.vertex.y < bottom_Most.vertex.y)
2148  {
2149  // Save bottom most.
2150  bottom_Most = point;
2151 
2152  // Swap it with previous vertex that was bottom most.
2153  swap_Vertex( dcel, 0, dcel->nVertex-1);
2154  }
2155  else if (point.vertex.y == bottom_Most.vertex.y)
2156  {
2157  if (point.vertex.x < bottom_Most.vertex.x)
2158  {
2159  // Save bottom most.
2160  bottom_Most = point;
2161 
2162  // Swap it with previous vertex that was bottom most.
2163  swap_Vertex( dcel, 0, dcel->nVertex-1);
2164  }
2165  }
2166 
2167  // Next point.
2168  i++;
2169  }
2170  }
2171 
2172  return(ret);
2173 }
2174 
2175 
2176 //#define DEBUG_GENERATE_RANDOM
2177 /***************************************************************************
2178 * Name: generate_Random_Points_DCEL
2179 * IN: nPoints # points to generate.
2180 * maxX max X coordinate
2181 * maxY max Y coordinate
2182 * OUT: N/A
2183 * IN/OUT: dcel structure to store points set.
2184 * RETURN: N/A
2185 * Description: generate a set of "nPoints" points and store it in "dcel".
2186 ***************************************************************************/
2187 void generate_Random_Points_DCEL( int nPoints, struct DCEL_T *dcel, TYPE maxX, TYPE maxY)
2188 {
2189  int i=0; // Loop counter.
2190  struct Dcel_Vertex_T point; // Temporary point.
2191  struct Dcel_Vertex_T bottom_Most;// Bottom most point.
2192 
2193  // Initialize bottom most.
2194  bottom_Most.vertex.x = maxX;
2195  bottom_Most.vertex.y = maxY;
2196 
2197  // Generate random set of points.
2198  // Create seed.
2199  srand48((int) time(NULL));
2200 
2201  // Add elements.
2202  for (i=0; i<nPoints ;i++)
2203  {
2204  // Generate new point.
2205  point.vertex.x = (drand48() * maxX);
2206  point.vertex.y = (drand48() * maxY);
2207 
2208  // Insert new point.
2209  point.origin_Edge = -1;
2210  insertVertex( dcel, point);
2211 
2212  // Update bottom most point.
2213  if (point.vertex.y < bottom_Most.vertex.y)
2214  {
2215  // Save bottom most.
2216  bottom_Most = point;
2217 
2218  // Swap it with previous vertex that was bottom most.
2219  swap_Vertex( dcel, 0, dcel->nVertex-1);
2220  }
2221  else if (point.vertex.y == bottom_Most.vertex.y)
2222  {
2223  if (point.vertex.x < bottom_Most.vertex.x)
2224  {
2225  // Save bottom most.
2226  bottom_Most = point;
2227 
2228  // Swap it with previous vertex that was bottom most.
2229  swap_Vertex( dcel, 0, dcel->nVertex-1);
2230  }
2231  }
2232  }
2233 }
2234 
2235 
2236 //#define DEBUG_GENERATE_CLUSTER
2237 /***************************************************************************
2238 * Name: generate_Cluster_Points_DCEL
2239 * IN: nPoints # points to generate
2240 * nClusters # clusters to generate
2241 * radius cluster radius.
2242 * maxX max X coordinate
2243 * maxY max Y coordinate
2244 * OUT: N/A
2245 * IN/OUT: dcel structure to store points set.
2246 * RETURN: N/A
2247 * Description: generate a set of "nPoints" points grouped in "nClusters"
2248 * clusters.
2249 ***************************************************************************/
2250 void generate_Cluster_Points_DCEL( int nPoints, struct DCEL_T *dcel,
2251  int nClusters, int radius, TYPE maxX, TYPE maxY)
2252 {
2253  int i=0, j=0; // Loop counters.
2254  int nElementsCluster=0; // # points per cluster.
2255  struct Dcel_Vertex_T seed; // Cluster seed point.
2256  struct Dcel_Vertex_T point; // Temporary point.
2257 
2258 #ifdef DEBUG_GENERATE_CLUSTER
2259  printf("Generating %d points in %d clusters with radius %d\n", nPoints, nClusters, radius);
2260 #endif
2261 
2262  // Create seed.
2263  srand48((int) time(NULL));
2264 
2265  // Get # elements per cluster.
2266  nElementsCluster = nPoints / nClusters;
2267 
2268  // Generate clusters centers.
2269  for (i=0; i<nClusters ;i++)
2270  {
2271  // Generate new point.
2272  seed.vertex.x = (drand48() * maxX);
2273  seed.vertex.y = (drand48() * maxY);
2274 
2275  // Insert new point.
2276  seed.origin_Edge = -1;
2277  insertVertex( dcel, seed);
2278 
2279 #ifdef DEBUG_GENERATE_CLUSTER
2280  printf("Generating %d cluster with seed (%f, %f)\n", i+1, seed.vertex.x, seed.vertex.y);
2281 #endif
2282 
2283  // Add points center in current seed.
2284  for (j=0; j<nElementsCluster-1 ;j++)
2285  {
2286  // Generate new point.
2287  if (drand48() > 0.5)
2288  {
2289  point.vertex.x = seed.vertex.x + (drand48() * radius);
2290  }
2291  else
2292  {
2293  point.vertex.x = seed.vertex.x - (drand48() * radius);
2294  }
2295  if (drand48() > 0.5)
2296  {
2297  point.vertex.y = seed.vertex.y + (drand48() * radius);
2298  }
2299  else
2300  {
2301  point.vertex.y = seed.vertex.y - (drand48() * radius);
2302  }
2303  while (distance( &point.vertex, &seed.vertex) > (float) radius)
2304  {
2305  // Generate new point.
2306  if (drand48() > 0.5)
2307  {
2308  point.vertex.x = seed.vertex.x + (drand48() * radius);
2309  }
2310  else
2311  {
2312  point.vertex.x = seed.vertex.x - (drand48() * radius);
2313  }
2314  if (drand48() > 0.5)
2315  {
2316  point.vertex.y = seed.vertex.y + (drand48() * radius);
2317  }
2318  else
2319  {
2320  point.vertex.y = seed.vertex.y - (drand48() * radius);
2321  }
2322  }
2323 
2324  // Correct points out of bounds.
2325  if (point.vertex.x < 0.0)
2326  {
2327  point.vertex.x = -point.vertex.x;
2328  }
2329  else if (point.vertex.x > maxX)
2330  {
2331  point.vertex.x = point.vertex.x - radius;
2332  }
2333  if (point.vertex.y < 0.0)
2334  {
2335  point.vertex.y = -point.vertex.y;
2336  }
2337  else if (point.vertex.y > maxY)
2338  {
2339  point.vertex.y = point.vertex.y - radius;
2340  }
2341 
2342  // Insert new point.
2343  point.origin_Edge = -1;
2344  insertVertex( dcel, point);
2345 
2346 #ifdef DEBUG_GENERATE_CLUSTER
2347  printf("Generated %d point (%f, %f)\n", j+1, point.vertex.x, point.vertex.y);
2348 #endif
2349  }
2350  }
2351 
2352  // Add elements randomly until nPoints reached.
2353  for (i=dcel->nVertex; i<nPoints ;i++)
2354  {
2355  // Generate new point.
2356  point.vertex.x = (drand48() * maxX);
2357  point.vertex.y = (drand48() * maxY);
2358 
2359  // Insert new point.
2360  point.origin_Edge = -1;
2361  insertVertex( dcel, point);
2362  }
2363 
2364  // Clutter set of points.
2365  clutter( dcel);
2366 }
2367 
2368 //#define DEBUG_PRINT_DCEL_STATISTICS
2369 /***************************************************************************
2370 * Name: print_Dcel_Statistics
2371 * IN: fileName output file.
2372 * dcel DCEL structure data.
2373 * OUT: N/A
2374 * IN/OUT: N/A
2375 * RETURN: N/A
2376 * Description: writes DCEL statistics data to an output file.
2377 ***************************************************************************/
2378 void print_Dcel_Statistics( char *fileName, struct DCEL_T *dcel)
2379 {
2380  FILE *fd=NULL; // File descriptor.
2381  int length=0; // Convex hull length.
2382  int *convex_Hull_Set=NULL; // Set of points in the convex hull.
2383  bool error=false;
2384  long long int memory=0; // Amount of memory use.
2385 
2386  if (dcel->nFaces > 0)
2387  {
2388 #ifdef DEBUG_PRINT_DCEL_STATISTICS
2389  printf("DCEL has %d faces\n", dcel->nFaces);
2390 #endif
2391  // Open input file.
2392  if ((fd = fopen( fileName, "w")) == NULL)
2393  {
2394  printf("Error opening output file: %s\n", fileName);
2395  }
2396  else
2397  {
2398  // Print # of vertices, edges and faces (also allocated #).
2399  fprintf( fd, "# vertex %d. Allocated %d\n", dcel->nVertex, dcel->sizeVertex);
2400  fprintf( fd, "# Real edges %d. Total edges %d. Allocated %d\n", get_Number_Real_Edges( dcel), dcel->nEdges, dcel->sizeEdges);
2401  fprintf( fd, "# Real faces %d. Total faces %d. Allocated %d\n", get_Number_Real_Faces( dcel), dcel->nFaces, dcel->sizeFaces);
2402 
2403  // Check if Delaunay was built using incremental algorithm.
2404  if (dcel->incremental)
2405  {
2406  // Allocate vector.
2407  length = dcel->nEdges / CONVEX_HULL_LEN_FACTOR;
2408  if ((convex_Hull_Set = (int *) calloc( length, sizeof(int))) != NULL)
2409  {
2410  // Get convex hull.
2411  error = false;
2412  while ((!get_Convex_Hull( dcel, &length, convex_Hull_Set)) && (!error))
2413  {
2414  // If error then resize vector.
2415  free(convex_Hull_Set);
2416  length = length*2;
2417  if ((convex_Hull_Set = (int *) calloc( length, sizeof(int))) == NULL)
2418  {
2419  error = true;
2420  }
2421  }
2422  }
2423 
2424  fprintf( fd, "Convex length %d\n", length);
2425  free(convex_Hull_Set);
2426  }
2427 
2428  // Print memory use.
2429  memory = sizeof(int) + sizeof(int) + sizeof(struct Dcel_Vertex_T)*dcel->sizeVertex;
2430  memory += sizeof(int) + sizeof(int) + sizeof(struct Dcel_Edge_T)*dcel->sizeEdges + sizeof(int)*dcel->sizeEdges;
2431  memory += sizeof(int) + sizeof(int) + sizeof(struct Dcel_Face_T)*dcel->sizeFaces;
2432  fprintf( fd,"Memory required:\n\t\t%f KB\n\t\t%f MB\n", memory / SIZE_OF_KB, memory / (SIZE_OF_KB*SIZE_OF_KB));
2433 
2434  fclose(fd);
2435  }
2436  }
2437  else
2438  {
2439  printf("DCEL has no triangles\n");
2440  }
2441 }
2442 
2443 
2444 
2445 void shake_Points_DCEL( struct DCEL_T *dcel)
2446 {
2447  int i=0; // Loop counter.
2448  int position=0; // Random value.
2449 
2450  // Create seed.
2451  srand((int) time(NULL));
2452 
2453  // Add elements.
2454  for (i=0; i<dcel->nVertex ;i++)
2455  {
2456  // Generate new point.
2457  position = rand();
2458  position = position % dcel->nVertex;
2459 
2460  // Swap elements.
2461  swap_Vertex( dcel, i, position);
2462  }
2463 }
2464 
2465 
2466 
2467 //*****************************************************************************
2468 // PRIVATE FUNCTION BODIES
2469 //*****************************************************************************
2470 void print_Vertex(struct Dcel_Vertex_T *vertex)
2471 {
2472  printf("Vertex info:\n");
2473  print_Point( &vertex->vertex);
2474  printf("Edge: %d\n\n", vertex->origin_Edge);
2475 }
2476 
2477 
2478 void print_Edge(struct Dcel_Edge_T *edge)
2479 {
2480  printf("Edge info:\n\tOrigin: %d\n\tTwin %d\n\tPrevious %d\n\tNext %d\n\tFace %d\n\n",
2481  edge->origin_Vertex,
2482  edge->twin_Edge,
2483  edge->previous_Edge,
2484  edge->next_Edge,
2485  edge->face);
2486 }
2487 
2488 
2490 {
2491  printf("Face info:\n\tEdge: %d\n\n", face->edge);
2492 }
2493 
2494 
2495 int get_Vertex_Index( struct DCEL_T *dcel, struct Point_T *point)
2496 {
2497  int i=0; // Loop counter.
2498  int found=0; // Loop control flag.
2499 
2500  // Search point in list.
2501  i=0;
2502  found = 0;
2503  while ((i<dcel->nVertex) && !found)
2504  {
2505  // Compare input point and i-point.
2506  if (equal_Point( point, &dcel->vertex[i].vertex))
2507  {
2508  found = 1;
2509  }
2510  // Next point.
2511  else
2512  {
2513  i++;
2514  }
2515  }
2516 
2517  return(i);
2518 }
2519 
2520 int in_Convex_Hull( struct DCEL_T *dcel, struct Dcel_Edge_T *edge)
2521 {
2522  int index=0;
2523  int in_Convex=0; // Return value.
2524  struct Dcel_Edge_T *prev_Edge=NULL; // Previous edge.
2525  struct Dcel_Vertex_T *v1=NULL;
2526  struct Dcel_Vertex_T *v2=NULL;
2527 
2528  // Get three points before.
2529  index = edge->twin_Edge-1;
2530  prev_Edge = get_Edge( dcel, index);
2531  index = prev_Edge->previous_Edge-1;
2532  prev_Edge = get_Edge( dcel, index);
2533  index = prev_Edge->previous_Edge-1;
2534  prev_Edge = get_Edge( dcel, index);
2535 
2536  // Get origin points.
2537  v1 = get_Vertex( dcel, edge->origin_Vertex-1);
2538  v2 = get_Vertex( dcel, prev_Edge->origin_Vertex-1);
2539 
2540  // Check if it is the same point -> not in convex hull.
2541  if (equal_Point( &v1->vertex, &v2->vertex))
2542  {
2543  in_Convex = 0;
2544  }
2545  else
2546  {
2547  in_Convex = 1;
2548  }
2549 
2550  return(in_Convex);
2551 }
2552 
2553 
2554 int set_Edge_Not_Checked( struct DCEL_T *dcel, int index, int *n)
2555 {
2556  int ret=SUCCESS; // Return value.
2557 
2558  // Check if index out of bounds.
2559  if (index >= dcel->nEdges)
2560  {
2561 #ifdef LOGGING
2562  sprintf("Trying to access index %d out of bounds (0,%d)\n.", index,
2563  dcel->nEdges-1);
2564  write_Log( log_Text);
2565 #endif
2566  printf("Trying to access index %d out of bounds (0,%d)\n.", index,
2567  dcel->nEdges-1);
2568  ret = FAILURE;
2569  }
2570  else
2571  {
2572  // If twin not checked set as checked.
2573  if (dcel->edges[index].face != 0)
2574  {
2575  if (dcel->edgeChecked[index])
2576  {
2577  (*n)++;
2578  dcel->edgeChecked[index] = 0;
2579  }
2580  }
2581  }
2582 
2583  return(ret);
2584 }
2585 
2586 
void get_Extreme_Point(struct DCEL_T *dcel, int(*f)(struct Point_T *, struct Point_T *), struct Point_T *p)
Definition: dcel.cpp:1855
#define FAILURE
Definition: defines.h:20
int twin_Edge
Definition: dcel.h:38
int update_Face(struct DCEL_T *dcel, int edge_ID, int index)
Definition: dcel.cpp:1428
int edge
Definition: dcel.h:46
int origin_Vertex
Definition: dcel.h:37
struct Dcel_Vertex_T * get_Vertex(struct DCEL_T *dcel, int index)
Definition: dcel.cpp:882
void generate_Cluster_Points_DCEL(int nPoints, struct DCEL_T *dcel, int nClusters, int radius, TYPE maxX, TYPE maxY)
Definition: dcel.cpp:2250
int initialize_DCEL(struct DCEL_T *dcel, int nPoints, int nEdges, int nFaces)
Definition: dcel.cpp:32
#define EXTERNAL_FACE
Definition: dcel.h:12
Definition: point.h:12
int get_Vertex_Index(struct DCEL_T *dcel, struct Point_T *point)
Definition: dcel.cpp:2495
int sizeVertex
Definition: dcel.h:56
int get_Face_Vertex(struct DCEL_T *dcel, int face_ID, struct Dcel_Vertex_T *v1, struct Dcel_Vertex_T *v2, struct Dcel_Vertex_T *v3)
Definition: dcel.cpp:1513
struct Point_T * get_Vertex_Point(struct DCEL_T *dcel, int index)
Definition: dcel.cpp:917
Turn_T
Definition: point.h:10
Definition: dcel.h:50
void copy_Dcel(struct DCEL_T *in_Dcel, struct DCEL_T *out_Dcel)
Definition: dcel.cpp:443
Resize_DCEL_T
Definition: dcel.h:24
void shake_Points_DCEL(struct DCEL_T *dcel)
Definition: dcel.cpp:2445
void shake_Dcel(struct DCEL_T *dcel)
Definition: dcel.cpp:1842
int insertVertex(struct DCEL_T *dcel, struct Dcel_Vertex_T vertex)
Definition: dcel.cpp:707
POINT_T x
Definition: point.h:14
void reset_DCEL(struct DCEL_T *dcel)
Definition: dcel.cpp:427
struct Dcel_Face_T * get_Face(struct DCEL_T *dcel, int index)
Definition: dcel.cpp:1479
int previous_Edge
Definition: dcel.h:39
int lexicographic_Higher(struct Point_T *p1, struct Point_T *p2)
Definition: point.cpp:211
#define i
int get_Number_Edges(struct DCEL_T *dcel)
Definition: dcel.cpp:950
#define NO_UPDATE
Definition: dcel.h:17
#define SIZE_OF_KB
Definition: defines.h:53
int get_Number_Vertex(struct DCEL_T *dcel)
Definition: dcel.cpp:638
void finalize_DCEL(struct DCEL_T *dcel)
Definition: dcel.cpp:595
void print_Edge(struct Dcel_Edge_T *edge)
Definition: dcel.cpp:2478
int is_External_Edge(struct DCEL_T *dcel, int index)
Definition: dcel.cpp:1175
#define SUCCESS
Definition: defines.h:21
glob_log first
int read_Points_DCEL(FILE *fd, int nPoints, struct DCEL_T *dcel)
Definition: dcel.cpp:2100
#define P_MINUS_1
Definition: defines.h:34
#define TYPE
Definition: defines.h:47
int read_Points_Flat_File(struct DCEL_T *dcel, const char *fileName)
Definition: dcel.cpp:239
enum Turn_T return_Turn(struct DCEL_T *dcel, struct Point_T *p, int source_ID, int dest_ID)
Definition: dcel.cpp:1736
double v1
int copy_Edge(struct DCEL_T *dcel, int index, struct Dcel_Edge_T *edge)
Definition: dcel.cpp:1320
void print_Point(struct Point_T *point)
Definition: point.cpp:67
int equal_Point(struct Point_T *p1, struct Point_T *p2)
Definition: point.cpp:39
void printFace(struct DCEL_T *dcel, int faceID)
Definition: dcel.cpp:1719
int higher_Point(struct Point_T *p1, struct Point_T *p2, int(*f)(struct Point_T *, struct Point_T *))
Definition: point.cpp:62
viol index
void print_Vertex(struct Dcel_Vertex_T *vertex)
Definition: dcel.cpp:2470
viol type
int nEdges
Definition: dcel.h:60
int next_Edge
Definition: dcel.h:40
struct Dcel_Edge_T * edges
Definition: dcel.h:63
double * f
#define INVALID
Definition: defines.h:29
#define P_MINUS_2
Definition: defines.h:35
int * edgeChecked
Definition: dcel.h:62
#define MAX_Y_COORD
Definition: defines.h:39
void print_Face(struct Dcel_Face_T *face)
Definition: dcel.cpp:2489
int read_DCEL(struct DCEL_T *dcel, char *fileName)
Definition: dcel.cpp:95
free((char *) ob)
int write_DCEL(struct DCEL_T *dcel, int type, const char *fileName)
Definition: dcel.cpp:301
__host__ __device__ float length(float2 v)
int sizeFaces
Definition: dcel.h:67
int get_Edge_In_Convex_Hull(struct DCEL_T *dcel, int firstEdge_Index)
Definition: dcel.cpp:1242
int get_Number_Faces(struct DCEL_T *dcel)
Definition: dcel.cpp:1360
#define VALID
Definition: defines.h:28
void sort(struct DCEL_T *dcel)
Definition: sorting.cpp:18
bool interior_Triangle(struct Point_T *p1, struct Point_T *p2, struct Point_T *p3, struct Point_T *q)
Definition: point.cpp:152
struct Dcel_Vertex_T * vertex
Definition: dcel.h:57
#define j
int is_Negative_Any_Vertex(struct DCEL_T *dcel, int edgeID)
Definition: dcel.cpp:1676
int insert_Vertex_At(struct DCEL_T *dcel, struct Dcel_Vertex_T vertex, int index)
Definition: dcel.cpp:757
void generate_Random_Points_DCEL(int nPoints, struct DCEL_T *dcel, TYPE maxX, TYPE maxY)
Definition: dcel.cpp:2187
POINT_T y
Definition: point.h:15
int get_Number_Real_Faces(struct DCEL_T *dcel)
Definition: dcel.cpp:1568
int in_Convex_Hull(struct DCEL_T *dcel, struct Dcel_Edge_T *edge)
Definition: dcel.cpp:2520
TYPE distance(struct Point_T *p, struct Point_T *q)
Definition: point.cpp:28
#define DEFAULT_CONVEX_HULL_LEN
Definition: dcel.cpp:15
bool is_Interior_To_Face(struct DCEL_T *dcel, struct Point_T *p, int face_ID)
Definition: dcel.cpp:1628
#define FALSE
Definition: defines.h:24
struct Point_T vertex
Definition: dcel.h:32
int origin_Edge
Definition: dcel.h:31
int nVertex
Definition: dcel.h:55
struct Dcel_Edge_T * get_Edge(struct DCEL_T *dcel, int index)
Definition: dcel.cpp:1287
int get_Edge_Origin_Vertex(struct DCEL_T *dcel, int edge_Index)
Definition: dcel.cpp:1218
int get_Number_Real_Edges(struct DCEL_T *dcel)
Definition: dcel.cpp:965
int are_Twins(struct DCEL_T *dcel, struct Dcel_Edge_T *edge1, struct Dcel_Edge_T *edge2)
Definition: dcel.cpp:1137
int swap_Vertex(struct DCEL_T *dcel, int index1, int index2)
Definition: dcel.cpp:838
int nFaces
Definition: dcel.h:66
void check_DCEL_Data(struct DCEL_T *dcel)
Definition: dcel.cpp:578
#define TRUE
Definition: defines.h:25
enum Turn_T check_Turn(struct Point_T *p1, struct Point_T *p2, struct Point_T *p3)
Definition: point.cpp:73
bool incremental
Definition: dcel.h:52
fprintf(glob_prnt.io, "\)
void print_DCEL(struct DCEL_T *dcel)
Definition: dcel.cpp:386
int resize_DCEL(struct DCEL_T *dcel, enum Resize_DCEL_T resize_Type)
Definition: dcel.cpp:471
int update_Vertex_Edge_At(struct DCEL_T *dcel, int edge_ID, int index)
Definition: dcel.cpp:799
bool is_Interior_To_Convex_Hull(struct DCEL_T *dcel, struct Point_T *p, bool *error)
Definition: dcel.cpp:2018
int sizeEdges
Definition: dcel.h:61
int imaginaryFace
Definition: dcel.h:47
#define CONVEX_HULL_LEN_FACTOR
Definition: dcel.h:19
#define MAX_X_COORD
Definition: defines.h:38
void clutter(struct DCEL_T *dcel)
Definition: sorting.cpp:32
struct Dcel_Face_T * faces
Definition: dcel.h:68
bool get_Convex_Hull(struct DCEL_T *dcel, int *length, int *points)
Definition: dcel.cpp:1910
int * n
int set_Edge_Not_Checked(struct DCEL_T *dcel, int index, int *n)
Definition: dcel.cpp:2554
void get_Vertex_Of_Face(struct DCEL_T *dcel, int face, int *index1, int *index2, int *index3)
Definition: dcel.cpp:1603
void print_Dcel_Statistics(char *fileName, struct DCEL_T *dcel)
Definition: dcel.cpp:2378
int insertFace(struct DCEL_T *dcel, int edge_ID)
Definition: dcel.cpp:1376
int insertPoint(struct DCEL_T *dcel, struct Point_T *point)
Definition: dcel.cpp:656
#define DCEL_TYPE
Definition: dcel.h:15
int insertEdge(struct DCEL_T *dcel, int origin, int twin, int prev, int next, int face)
Definition: dcel.cpp:998
int face
Definition: dcel.h:41
int update_Edge(struct DCEL_T *dcel, int origin, int twin, int prev, int next, int face, int index)
Definition: dcel.cpp:1060