ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/triangulate.h
Revision: 2.1
Committed: Thu Jan 23 23:51:41 2014 UTC (10 years, 3 months ago) by greg
Content type: text/plain
Branch: MAIN
Log Message:
Added routines to triangulate polygons

File Contents

# User Rev Content
1 greg 2.1 /* RCSid $Id$ */
2     /*
3     * triangulate.h
4     *
5     * Adapted by Greg Ward on 1/23/14.
6     * Copyright 2014 Anyhere Software. All rights reserved.
7     *
8     */
9    
10     /* COTD Entry submitted by John W. Ratcliff [[email protected]] */
11    
12     /**** THIS IS A CODE SNIPPET WHICH WILL EFFICIEINTLY TRIANGULATE ANY
13     // ** POLYGON/CONTOUR (without holes) AS A STATIC CLASS. THIS SNIPPET
14     // ** IS COMPRISED OF 3 FILES, TRIANGULATE.H, THE HEADER FILE FOR THE
15     // ** TRIANGULATE BASE CLASS, TRIANGULATE.CPP, THE IMPLEMENTATION OF
16     // ** THE TRIANGULATE BASE CLASS, AND TEST.CPP, A SMALL TEST PROGRAM
17     // ** DEMONSTRATING THE USAGE OF THE TRIANGULATOR. THE TRIANGULATE
18     // ** BASE CLASS ALSO PROVIDES TWO USEFUL HELPER METHODS, ONE WHICH
19     // ** COMPUTES THE AREA OF A POLYGON, AND ANOTHER WHICH DOES AN EFFICENT
20     // ** POINT IN A TRIANGLE TEST.
21     // ** SUBMITTED BY JOHN W. RATCLIFF ([email protected]) July 22, 2000
22     */
23    
24     /**********************************************************************/
25     /************ HEADER FILE FOR TRIANGULATE.C ***************************/
26     /**********************************************************************/
27    
28     #ifndef TRIANGULATE_H
29     #define TRIANGULATE_H
30    
31     #ifdef __cplusplus
32     extern "C" {
33     #endif
34    
35     typedef struct {
36     double mX, mY;
37     } Vert2;
38    
39     typedef struct {
40     int nv; /* number of vertices */
41     void *p; /* client data pointer */
42     Vert2 v[3]; /* extends struct */
43     } Vert2_list;
44    
45     /* allocate a polygon list */
46     extern Vert2_list *polyAlloc(int nv);
47    
48     #define polyFree free
49    
50     /* callback for output triangle */
51     typedef void tri_out_t(const Vert2_list *tp, int a, int b, int c);
52    
53     /* triangulate a contour/polygon, places results in STL vector
54     * as series of triangles. */
55     extern int polyTriangulate(const Vert2_list *contour, tri_out_t *cb);
56    
57     /* compute area of a contour/polygon */
58     extern double polyArea(const Vert2_list *contour);
59    
60     /* decide if point Px/Py is inside triangle defined by
61     * (Ax,Ay) (Bx,By) (Cx,Cy) */
62     extern int insideTriangle(double Ax, double Ay,
63     double Bx, double By,
64     double Cx, double Cy,
65     double Px, double Py);
66    
67     #ifdef __cplusplus
68     }
69     #endif
70    
71     #endif