1*c2c66affSColin Finck /*
2*c2c66affSColin Finck ** License Applicability. Except to the extent portions of this file are
3*c2c66affSColin Finck ** made subject to an alternative license as permitted in the SGI Free
4*c2c66affSColin Finck ** Software License B, Version 1.1 (the "License"), the contents of this
5*c2c66affSColin Finck ** file are subject only to the provisions of the License. You may not use
6*c2c66affSColin Finck ** this file except in compliance with the License. You may obtain a copy
7*c2c66affSColin Finck ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
8*c2c66affSColin Finck ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
9*c2c66affSColin Finck **
10*c2c66affSColin Finck ** http://oss.sgi.com/projects/FreeB
11*c2c66affSColin Finck **
12*c2c66affSColin Finck ** Note that, as provided in the License, the Software is distributed on an
13*c2c66affSColin Finck ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
14*c2c66affSColin Finck ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
15*c2c66affSColin Finck ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
16*c2c66affSColin Finck ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
17*c2c66affSColin Finck **
18*c2c66affSColin Finck ** Original Code. The Original Code is: OpenGL Sample Implementation,
19*c2c66affSColin Finck ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
20*c2c66affSColin Finck ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
21*c2c66affSColin Finck ** Copyright in any portions created by third parties is as indicated
22*c2c66affSColin Finck ** elsewhere herein. All Rights Reserved.
23*c2c66affSColin Finck **
24*c2c66affSColin Finck ** Additional Notice Provisions: The application programming interfaces
25*c2c66affSColin Finck ** established by SGI in conjunction with the Original Code are The
26*c2c66affSColin Finck ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
27*c2c66affSColin Finck ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
28*c2c66affSColin Finck ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
29*c2c66affSColin Finck ** Window System(R) (Version 1.3), released October 19, 1998. This software
30*c2c66affSColin Finck ** was created using the OpenGL(R) version 1.2.1 Sample Implementation
31*c2c66affSColin Finck ** published by SGI, but has not been independently verified as being
32*c2c66affSColin Finck ** compliant with the OpenGL(R) version 1.2.1 Specification.
33*c2c66affSColin Finck **
34*c2c66affSColin Finck */
35*c2c66affSColin Finck /*
36*c2c66affSColin Finck */
37*c2c66affSColin Finck
38*c2c66affSColin Finck #include <stdlib.h>
39*c2c66affSColin Finck //#include <stdio.h>
40*c2c66affSColin Finck
41*c2c66affSColin Finck #include "partitionX.h"
42*c2c66affSColin Finck
43*c2c66affSColin Finck #define CONCAVITY_ZERO 1.0e-6 //this number is used to test whether a vertex is concave (refelx)
44*c2c66affSColin Finck //or not. The test needs to compute the area of the three adjacent
45*c2c66affSColin Finck //vertices to see if the are is positive or negative.
46*c2c66affSColin Finck
isCuspX(directedLine * v)47*c2c66affSColin Finck Int isCuspX(directedLine *v)
48*c2c66affSColin Finck {
49*c2c66affSColin Finck //if v->prev <= v && v->next <= v
50*c2c66affSColin Finck //|| v->prev >= v && v->next >= v
51*c2c66affSColin Finck Real* T = v->head();
52*c2c66affSColin Finck Real* P = v->getPrev()->head();
53*c2c66affSColin Finck Real* N = v->getNext()->head();
54*c2c66affSColin Finck if(
55*c2c66affSColin Finck (compV2InX(T,P) != -1 &&
56*c2c66affSColin Finck compV2InX(T,N) != -1
57*c2c66affSColin Finck ) ||
58*c2c66affSColin Finck (compV2InX(T,P) != 1 &&
59*c2c66affSColin Finck compV2InX(T,N) != 1
60*c2c66affSColin Finck )
61*c2c66affSColin Finck )
62*c2c66affSColin Finck return 1;
63*c2c66affSColin Finck else
64*c2c66affSColin Finck return 0;
65*c2c66affSColin Finck }
66*c2c66affSColin Finck
isReflexX(directedLine * v)67*c2c66affSColin Finck Int isReflexX(directedLine* v)
68*c2c66affSColin Finck {
69*c2c66affSColin Finck Real* A = v->getPrev()->head();
70*c2c66affSColin Finck Real* B = v->head();
71*c2c66affSColin Finck Real* C = v->tail();
72*c2c66affSColin Finck Real Bx,By, Cx, Cy;
73*c2c66affSColin Finck //scale them in case they are too small
74*c2c66affSColin Finck Bx = 10*(B[0] - A[0]);
75*c2c66affSColin Finck By = 10*(B[1] - A[1]);
76*c2c66affSColin Finck Cx = 10*(C[0] - A[0]);
77*c2c66affSColin Finck Cy = 10*(C[1] - A[1]);
78*c2c66affSColin Finck
79*c2c66affSColin Finck if(Bx*Cy - Cx*By < -CONCAVITY_ZERO) return 1;
80*c2c66affSColin Finck else return 0;
81*c2c66affSColin Finck }
82*c2c66affSColin Finck
83*c2c66affSColin Finck
84*c2c66affSColin Finck /*return
85*c2c66affSColin Finck *0: not-cusp
86*c2c66affSColin Finck *1: interior cusp
87*c2c66affSColin Finck *2: exterior cusp
88*c2c66affSColin Finck */
cuspTypeX(directedLine * v)89*c2c66affSColin Finck Int cuspTypeX(directedLine *v)
90*c2c66affSColin Finck {
91*c2c66affSColin Finck if(! isCuspX(v)) return 0;
92*c2c66affSColin Finck else
93*c2c66affSColin Finck {
94*c2c66affSColin Finck //printf("isCusp,%f,%f\n", v->head()[0], v->head()[1]);
95*c2c66affSColin Finck if(isReflexX(v))
96*c2c66affSColin Finck {
97*c2c66affSColin Finck // printf("isReflex\n");
98*c2c66affSColin Finck return 1;
99*c2c66affSColin Finck }
100*c2c66affSColin Finck else
101*c2c66affSColin Finck {
102*c2c66affSColin Finck // printf("not isReflex\n");
103*c2c66affSColin Finck return 2;
104*c2c66affSColin Finck }
105*c2c66affSColin Finck }
106*c2c66affSColin Finck }
107*c2c66affSColin Finck
numInteriorCuspsX(directedLine * polygon)108*c2c66affSColin Finck Int numInteriorCuspsX(directedLine *polygon)
109*c2c66affSColin Finck {
110*c2c66affSColin Finck directedLine *temp;
111*c2c66affSColin Finck int ret = 0;
112*c2c66affSColin Finck if(cuspTypeX(polygon) == 1)
113*c2c66affSColin Finck ret++;
114*c2c66affSColin Finck for(temp = polygon->getNext(); temp != polygon; temp = temp->getNext())
115*c2c66affSColin Finck if(cuspTypeX(temp) == 1)
116*c2c66affSColin Finck ret++;
117*c2c66affSColin Finck return ret;
118*c2c66affSColin Finck }
119*c2c66affSColin Finck
120*c2c66affSColin Finck
findInteriorCuspsX(directedLine * polygon,Int & ret_n_interior_cusps,directedLine ** ret_interior_cusps)121*c2c66affSColin Finck void findInteriorCuspsX(directedLine *polygon, Int& ret_n_interior_cusps,
122*c2c66affSColin Finck directedLine** ret_interior_cusps)
123*c2c66affSColin Finck {
124*c2c66affSColin Finck directedLine *temp;
125*c2c66affSColin Finck ret_n_interior_cusps = 0;
126*c2c66affSColin Finck if(cuspTypeX(polygon) == 1)
127*c2c66affSColin Finck {
128*c2c66affSColin Finck ret_interior_cusps[ret_n_interior_cusps++] = polygon;
129*c2c66affSColin Finck }
130*c2c66affSColin Finck for(temp = polygon->getNext(); temp != polygon; temp = temp->getNext())
131*c2c66affSColin Finck if(cuspTypeX(temp) == 1)
132*c2c66affSColin Finck {
133*c2c66affSColin Finck ret_interior_cusps[ret_n_interior_cusps++] = temp;
134*c2c66affSColin Finck }
135*c2c66affSColin Finck }
136*c2c66affSColin Finck
findDiagonal_singleCuspX(directedLine * cusp)137*c2c66affSColin Finck directedLine* findDiagonal_singleCuspX(directedLine* cusp)
138*c2c66affSColin Finck {
139*c2c66affSColin Finck directedLine* temp;
140*c2c66affSColin Finck Int is_minimal = ((compV2InX(cusp->head(), cusp->tail()) == -1)? 1:0);
141*c2c66affSColin Finck
142*c2c66affSColin Finck if(is_minimal)
143*c2c66affSColin Finck for(temp = cusp->getNext(); temp != cusp; temp = temp->getNext())
144*c2c66affSColin Finck {
145*c2c66affSColin Finck if(compV2InX(cusp->head(), temp->head()) == 1)
146*c2c66affSColin Finck {
147*c2c66affSColin Finck return temp;
148*c2c66affSColin Finck }
149*c2c66affSColin Finck }
150*c2c66affSColin Finck else //is maxmal
151*c2c66affSColin Finck for(temp = cusp->getNext(); temp != cusp; temp = temp->getNext())
152*c2c66affSColin Finck {
153*c2c66affSColin Finck if(compV2InX(cusp->head(), temp->head()) == -1)
154*c2c66affSColin Finck {
155*c2c66affSColin Finck return temp;
156*c2c66affSColin Finck }
157*c2c66affSColin Finck }
158*c2c66affSColin Finck return NULL;
159*c2c66affSColin Finck }
160*c2c66affSColin Finck
161*c2c66affSColin Finck
162*c2c66affSColin Finck
163