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 * slicer.c++
37*c2c66affSColin Finck *
38*c2c66affSColin Finck */
39*c2c66affSColin Finck
40*c2c66affSColin Finck //#include <stdlib.h>
41*c2c66affSColin Finck //#include <stdio.h>
42*c2c66affSColin Finck //#include <math.h>
43*c2c66affSColin Finck //#include "glimports.h"
44*c2c66affSColin Finck //#include "mystdio.h"
45*c2c66affSColin Finck //#include "myassert.h"
46*c2c66affSColin Finck //#include "bufpool.h"
47*c2c66affSColin Finck #include "slicer.h"
48*c2c66affSColin Finck #include "backend.h"
49*c2c66affSColin Finck //#include "arc.h"
50*c2c66affSColin Finck //#include "gridtrimvertex.h"
51*c2c66affSColin Finck #include "simplemath.h"
52*c2c66affSColin Finck //#include "trimvertex.h"
53*c2c66affSColin Finck #include "varray.h"
54*c2c66affSColin Finck
55*c2c66affSColin Finck #include "polyUtil.h" //for area()
56*c2c66affSColin Finck
57*c2c66affSColin Finck //static int count=0;
58*c2c66affSColin Finck
59*c2c66affSColin Finck /*USE_OPTTT is initiated in trimvertex.h*/
60*c2c66affSColin Finck
61*c2c66affSColin Finck #ifdef USE_OPTTT
62*c2c66affSColin Finck #include <GL/gl.h>
63*c2c66affSColin Finck #endif
64*c2c66affSColin Finck
65*c2c66affSColin Finck //#define USE_READ_FLAG //whether to use new or old tesselator
66*c2c66affSColin Finck //if defined, it reads "flagFile",
67*c2c66affSColin Finck // if the number is 1, then use new tess
68*c2c66affSColin Finck // otherwise, use the old tess.
69*c2c66affSColin Finck //if not defined, then use new tess.
70*c2c66affSColin Finck #ifdef USE_READ_FLAG
71*c2c66affSColin Finck static Int read_flag(char* name);
72*c2c66affSColin Finck Int newtess_flag = read_flag("flagFile");
73*c2c66affSColin Finck #endif
74*c2c66affSColin Finck
75*c2c66affSColin Finck //#define COUNT_TRIANGLES
76*c2c66affSColin Finck #ifdef COUNT_TRIANGLES
77*c2c66affSColin Finck Int num_triangles = 0;
78*c2c66affSColin Finck Int num_quads = 0;
79*c2c66affSColin Finck #endif
80*c2c66affSColin Finck
81*c2c66affSColin Finck #define max(a,b) ((a>b)? a:b)
82*c2c66affSColin Finck #define ZERO 0.00001 /*determing whether a loop is a rectngle or not*/
83*c2c66affSColin Finck #define equalRect(a,b) ((glu_abs(a-b) <= ZERO)? 1:0) //only used in tessellating a rectangle
84*c2c66affSColin Finck
85*c2c66affSColin Finck #if 0 // UNUSED
86*c2c66affSColin Finck static Int is_Convex(Arc_ptr loop)
87*c2c66affSColin Finck {
88*c2c66affSColin Finck if(area(loop->tail(), loop->head(), loop->next->head()) <0 )
89*c2c66affSColin Finck return 0;
90*c2c66affSColin Finck for(Arc_ptr jarc = loop->next; jarc != loop; jarc = jarc->next)
91*c2c66affSColin Finck {
92*c2c66affSColin Finck if(area(jarc->tail(), jarc->head(), jarc->next->head()) < 0)
93*c2c66affSColin Finck return 0;
94*c2c66affSColin Finck }
95*c2c66affSColin Finck return 1;
96*c2c66affSColin Finck }
97*c2c66affSColin Finck #endif
98*c2c66affSColin Finck
99*c2c66affSColin Finck /******triangulate a monotone polygon**************/
100*c2c66affSColin Finck #include "monoTriangulation.h"
101*c2c66affSColin Finck #if 0 // UNUSED
102*c2c66affSColin Finck static int is_U_monotone(Arc_ptr loop)
103*c2c66affSColin Finck {
104*c2c66affSColin Finck int n_changes=0;
105*c2c66affSColin Finck int prev_sign;
106*c2c66affSColin Finck int cur_sign;
107*c2c66affSColin Finck Arc_ptr temp;
108*c2c66affSColin Finck
109*c2c66affSColin Finck cur_sign = compV2InX(loop->head(), loop->tail());
110*c2c66affSColin Finck
111*c2c66affSColin Finck n_changes = (compV2InX(loop->prev->head(), loop->prev->tail())
112*c2c66affSColin Finck != cur_sign);
113*c2c66affSColin Finck
114*c2c66affSColin Finck for(temp=loop->next; temp != loop; temp = temp->next)
115*c2c66affSColin Finck {
116*c2c66affSColin Finck prev_sign = cur_sign;
117*c2c66affSColin Finck cur_sign = compV2InX(temp->head(), temp->tail());
118*c2c66affSColin Finck if(cur_sign != prev_sign)
119*c2c66affSColin Finck {
120*c2c66affSColin Finck #ifdef DEBUG
121*c2c66affSColin Finck printf("***change signe\n");
122*c2c66affSColin Finck #endif
123*c2c66affSColin Finck n_changes++;
124*c2c66affSColin Finck }
125*c2c66affSColin Finck }
126*c2c66affSColin Finck if(n_changes == 2) return 1;
127*c2c66affSColin Finck else
128*c2c66affSColin Finck return 0;
129*c2c66affSColin Finck }
130*c2c66affSColin Finck #endif
131*c2c66affSColin Finck
compInY(REAL a[2],REAL b[2])132*c2c66affSColin Finck inline int compInY(REAL a[2], REAL b[2])
133*c2c66affSColin Finck {
134*c2c66affSColin Finck if(a[1] < b[1])
135*c2c66affSColin Finck return -1;
136*c2c66affSColin Finck else if (a[1] > b[1])
137*c2c66affSColin Finck return 1;
138*c2c66affSColin Finck else if(a[0] > b[0])
139*c2c66affSColin Finck return 1;
140*c2c66affSColin Finck else return -1;
141*c2c66affSColin Finck }
142*c2c66affSColin Finck
monoTriangulationLoop(Arc_ptr loop,Backend & backend,primStream * pStream)143*c2c66affSColin Finck void monoTriangulationLoop(Arc_ptr loop, Backend& backend, primStream* pStream)
144*c2c66affSColin Finck {
145*c2c66affSColin Finck int i;
146*c2c66affSColin Finck //find the top, bottom, increasing and decreasing chain
147*c2c66affSColin Finck //then call monoTrianulation
148*c2c66affSColin Finck Arc_ptr jarc, temp;
149*c2c66affSColin Finck Arc_ptr top;
150*c2c66affSColin Finck Arc_ptr bot;
151*c2c66affSColin Finck top = bot = loop;
152*c2c66affSColin Finck if(compInY(loop->tail(), loop->prev->tail()) < 0)
153*c2c66affSColin Finck {
154*c2c66affSColin Finck //first find bot
155*c2c66affSColin Finck for(temp = loop->next; temp != loop; temp = temp->next)
156*c2c66affSColin Finck {
157*c2c66affSColin Finck if(compInY(temp->tail(), temp->prev->tail()) > 0)
158*c2c66affSColin Finck break;
159*c2c66affSColin Finck }
160*c2c66affSColin Finck bot = temp->prev;
161*c2c66affSColin Finck //then find top
162*c2c66affSColin Finck for(temp=loop->prev; temp != loop; temp = temp->prev)
163*c2c66affSColin Finck {
164*c2c66affSColin Finck if(compInY(temp->tail(), temp->prev->tail()) > 0)
165*c2c66affSColin Finck break;
166*c2c66affSColin Finck }
167*c2c66affSColin Finck top = temp;
168*c2c66affSColin Finck }
169*c2c66affSColin Finck else //loop > loop->prev
170*c2c66affSColin Finck {
171*c2c66affSColin Finck for(temp=loop->next; temp != loop; temp = temp->next)
172*c2c66affSColin Finck {
173*c2c66affSColin Finck if(compInY(temp->tail(), temp->prev->tail()) < 0)
174*c2c66affSColin Finck break;
175*c2c66affSColin Finck }
176*c2c66affSColin Finck top = temp->prev;
177*c2c66affSColin Finck for(temp=loop->prev; temp != loop; temp = temp->prev)
178*c2c66affSColin Finck {
179*c2c66affSColin Finck if(compInY(temp->tail(), temp->prev->tail()) < 0)
180*c2c66affSColin Finck break;
181*c2c66affSColin Finck }
182*c2c66affSColin Finck bot = temp;
183*c2c66affSColin Finck }
184*c2c66affSColin Finck //creat increase and decrease chains
185*c2c66affSColin Finck vertexArray inc_chain(50); //this is a dynamci array
186*c2c66affSColin Finck for(i=1; i<=top->pwlArc->npts-2; i++)
187*c2c66affSColin Finck {
188*c2c66affSColin Finck //the first vertex is the top which doesn't below to inc_chain
189*c2c66affSColin Finck inc_chain.appendVertex(top->pwlArc->pts[i].param);
190*c2c66affSColin Finck }
191*c2c66affSColin Finck for(jarc=top->next; jarc != bot; jarc = jarc->next)
192*c2c66affSColin Finck {
193*c2c66affSColin Finck for(i=0; i<=jarc->pwlArc->npts-2; i++)
194*c2c66affSColin Finck {
195*c2c66affSColin Finck inc_chain.appendVertex(jarc->pwlArc->pts[i].param);
196*c2c66affSColin Finck }
197*c2c66affSColin Finck
198*c2c66affSColin Finck }
199*c2c66affSColin Finck vertexArray dec_chain(50);
200*c2c66affSColin Finck for(jarc = top->prev; jarc != bot; jarc = jarc->prev)
201*c2c66affSColin Finck {
202*c2c66affSColin Finck for(i=jarc->pwlArc->npts-2; i>=0; i--)
203*c2c66affSColin Finck {
204*c2c66affSColin Finck dec_chain.appendVertex(jarc->pwlArc->pts[i].param);
205*c2c66affSColin Finck }
206*c2c66affSColin Finck }
207*c2c66affSColin Finck for(i=bot->pwlArc->npts-2; i>=1; i--)
208*c2c66affSColin Finck {
209*c2c66affSColin Finck dec_chain.appendVertex(jarc->pwlArc->pts[i].param);
210*c2c66affSColin Finck }
211*c2c66affSColin Finck
212*c2c66affSColin Finck monoTriangulationRec(top->tail(), bot->tail(), &inc_chain, 0,
213*c2c66affSColin Finck &dec_chain, 0, &backend);
214*c2c66affSColin Finck
215*c2c66affSColin Finck }
216*c2c66affSColin Finck
217*c2c66affSColin Finck /********tesselate a rectanlge (OPTIMIZATION**************/
218*c2c66affSColin Finck static void triangulateRectGen(Arc_ptr loop, int n_ulines, int n_vlines, Backend& backend);
219*c2c66affSColin Finck
is_rect(Arc_ptr loop)220*c2c66affSColin Finck static Int is_rect(Arc_ptr loop)
221*c2c66affSColin Finck {
222*c2c66affSColin Finck Int nlines =1;
223*c2c66affSColin Finck for(Arc_ptr jarc = loop->next; jarc != loop; jarc = jarc->next)
224*c2c66affSColin Finck {
225*c2c66affSColin Finck nlines++;
226*c2c66affSColin Finck if(nlines == 5)
227*c2c66affSColin Finck break;
228*c2c66affSColin Finck }
229*c2c66affSColin Finck if(nlines != 4)
230*c2c66affSColin Finck return 0;
231*c2c66affSColin Finck
232*c2c66affSColin Finck
233*c2c66affSColin Finck /*
234*c2c66affSColin Finck printf("here1\n");
235*c2c66affSColin Finck printf("loop->tail=(%f,%f)\n", loop->tail()[0], loop->tail()[1]);
236*c2c66affSColin Finck printf("loop->head=(%f,%f)\n", loop->head()[0], loop->head()[1]);
237*c2c66affSColin Finck printf("loop->next->tail=(%f,%f)\n", loop->next->tail()[0], loop->next->tail()[1]);
238*c2c66affSColin Finck printf("loop->next->head=(%f,%f)\n", loop->next->head()[0], loop->next->head()[1]);
239*c2c66affSColin Finck if(fglu_abs(loop->tail()[0] - loop->head()[0])<0.000001)
240*c2c66affSColin Finck printf("equal 1\n");
241*c2c66affSColin Finck if(loop->next->tail()[1] == loop->next->head()[1])
242*c2c66affSColin Finck printf("equal 2\n");
243*c2c66affSColin Finck */
244*c2c66affSColin Finck
245*c2c66affSColin Finck if( (glu_abs(loop->tail()[0] - loop->head()[0])<=ZERO) &&
246*c2c66affSColin Finck (glu_abs(loop->next->tail()[1] - loop->next->head()[1])<=ZERO) &&
247*c2c66affSColin Finck (glu_abs(loop->prev->tail()[1] - loop->prev->head()[1])<=ZERO) &&
248*c2c66affSColin Finck (glu_abs(loop->prev->prev->tail()[0] - loop->prev->prev->head()[0])<=ZERO)
249*c2c66affSColin Finck )
250*c2c66affSColin Finck return 1;
251*c2c66affSColin Finck else if
252*c2c66affSColin Finck ( (glu_abs(loop->tail()[1] - loop->head()[1]) <= ZERO) &&
253*c2c66affSColin Finck (glu_abs(loop->next->tail()[0] - loop->next->head()[0]) <= ZERO) &&
254*c2c66affSColin Finck (glu_abs(loop->prev->tail()[0] - loop->prev->head()[0]) <= ZERO) &&
255*c2c66affSColin Finck (glu_abs(loop->prev->prev->tail()[1] - loop->prev->prev->head()[1]) <= ZERO)
256*c2c66affSColin Finck )
257*c2c66affSColin Finck return 1;
258*c2c66affSColin Finck else
259*c2c66affSColin Finck return 0;
260*c2c66affSColin Finck }
261*c2c66affSColin Finck
262*c2c66affSColin Finck
263*c2c66affSColin Finck //a line with the same u for opt
264*c2c66affSColin Finck #ifdef USE_OPTTT
evalLineNOGE_BU(TrimVertex * verts,int n,Backend & backend)265*c2c66affSColin Finck static void evalLineNOGE_BU(TrimVertex *verts, int n, Backend& backend)
266*c2c66affSColin Finck {
267*c2c66affSColin Finck int i;
268*c2c66affSColin Finck backend.preEvaluateBU(verts[0].param[0]);
269*c2c66affSColin Finck for(i=0; i<n; i++)
270*c2c66affSColin Finck backend.tmeshvertNOGE_BU(&verts[i]);
271*c2c66affSColin Finck }
272*c2c66affSColin Finck #endif
273*c2c66affSColin Finck
274*c2c66affSColin Finck //a line with the same v for opt
275*c2c66affSColin Finck #ifdef USE_OPTTT
evalLineNOGE_BV(TrimVertex * verts,int n,Backend & backend)276*c2c66affSColin Finck static void evalLineNOGE_BV(TrimVertex *verts, int n, Backend& backend)
277*c2c66affSColin Finck {
278*c2c66affSColin Finck int i;
279*c2c66affSColin Finck backend.preEvaluateBV(verts[0].param[1]);
280*c2c66affSColin Finck
281*c2c66affSColin Finck for(i=0; i<n; i++)
282*c2c66affSColin Finck backend.tmeshvertNOGE_BV(&verts[i]);
283*c2c66affSColin Finck }
284*c2c66affSColin Finck #endif
285*c2c66affSColin Finck
286*c2c66affSColin Finck #ifdef USE_OPTTT
evalLineNOGE(TrimVertex * verts,int n,Backend & backend)287*c2c66affSColin Finck static void evalLineNOGE(TrimVertex *verts, int n, Backend& backend)
288*c2c66affSColin Finck {
289*c2c66affSColin Finck
290*c2c66affSColin Finck if(verts[0].param[0] == verts[n-1].param[0]) //all u;s are equal
291*c2c66affSColin Finck evalLineNOGE_BU(verts, n, backend);
292*c2c66affSColin Finck else if(verts[0].param[1] == verts[n-1].param[1]) //all v's are equal
293*c2c66affSColin Finck evalLineNOGE_BV(verts, n, backend);
294*c2c66affSColin Finck else
295*c2c66affSColin Finck {
296*c2c66affSColin Finck int i;
297*c2c66affSColin Finck for(i=0; i<n; i++)
298*c2c66affSColin Finck backend.tmeshvertNOGE(&verts[i]);
299*c2c66affSColin Finck }
300*c2c66affSColin Finck }
301*c2c66affSColin Finck #endif
302*c2c66affSColin Finck
OPT_OUTVERT(TrimVertex & vv,Backend & backend)303*c2c66affSColin Finck inline void OPT_OUTVERT(TrimVertex& vv, Backend& backend)
304*c2c66affSColin Finck {
305*c2c66affSColin Finck
306*c2c66affSColin Finck #ifdef USE_OPTTT
307*c2c66affSColin Finck glNormal3fv(vv.cache_normal);
308*c2c66affSColin Finck glVertex3fv(vv.cache_point);
309*c2c66affSColin Finck #else
310*c2c66affSColin Finck
311*c2c66affSColin Finck backend.tmeshvert(&vv);
312*c2c66affSColin Finck
313*c2c66affSColin Finck #endif
314*c2c66affSColin Finck
315*c2c66affSColin Finck }
316*c2c66affSColin Finck
317*c2c66affSColin Finck static void triangulateRectAux(PwlArc* top, PwlArc* bot, PwlArc* left, PwlArc* right, Backend& backend);
318*c2c66affSColin Finck
triangulateRect(Arc_ptr loop,Backend & backend,int TB_or_LR,int ulinear,int vlinear)319*c2c66affSColin Finck static void triangulateRect(Arc_ptr loop, Backend& backend, int TB_or_LR, int ulinear, int vlinear)
320*c2c66affSColin Finck {
321*c2c66affSColin Finck //we know the loop is a rectangle, but not sure which is top
322*c2c66affSColin Finck Arc_ptr top, bot, left, right;
323*c2c66affSColin Finck if(loop->tail()[1] == loop->head()[1])
324*c2c66affSColin Finck {
325*c2c66affSColin Finck if(loop->tail()[1] > loop->prev->prev->tail()[1])
326*c2c66affSColin Finck {
327*c2c66affSColin Finck
328*c2c66affSColin Finck top = loop;
329*c2c66affSColin Finck }
330*c2c66affSColin Finck else{
331*c2c66affSColin Finck
332*c2c66affSColin Finck top = loop->prev->prev;
333*c2c66affSColin Finck }
334*c2c66affSColin Finck }
335*c2c66affSColin Finck else
336*c2c66affSColin Finck {
337*c2c66affSColin Finck if(loop->tail()[0] > loop->prev->prev->tail()[0])
338*c2c66affSColin Finck {
339*c2c66affSColin Finck //loop is the right arc
340*c2c66affSColin Finck
341*c2c66affSColin Finck top = loop->next;
342*c2c66affSColin Finck }
343*c2c66affSColin Finck else
344*c2c66affSColin Finck {
345*c2c66affSColin Finck
346*c2c66affSColin Finck top = loop->prev;
347*c2c66affSColin Finck }
348*c2c66affSColin Finck }
349*c2c66affSColin Finck left = top->next;
350*c2c66affSColin Finck bot = left->next;
351*c2c66affSColin Finck right= bot->next;
352*c2c66affSColin Finck
353*c2c66affSColin Finck //if u, v are both nonlinear, then if the
354*c2c66affSColin Finck //boundary is tessellated dense, we also
355*c2c66affSColin Finck //sample the inside to get a better tesslletant.
356*c2c66affSColin Finck if( (!ulinear) && (!vlinear))
357*c2c66affSColin Finck {
358*c2c66affSColin Finck int nu = top->pwlArc->npts;
359*c2c66affSColin Finck if(nu < bot->pwlArc->npts)
360*c2c66affSColin Finck nu = bot->pwlArc->npts;
361*c2c66affSColin Finck int nv = left->pwlArc->npts;
362*c2c66affSColin Finck if(nv < right->pwlArc->npts)
363*c2c66affSColin Finck nv = right->pwlArc->npts;
364*c2c66affSColin Finck /*
365*c2c66affSColin Finck if(nu > 2 && nv > 2)
366*c2c66affSColin Finck {
367*c2c66affSColin Finck triangulateRectGen(top, nu-2, nv-2, backend);
368*c2c66affSColin Finck return;
369*c2c66affSColin Finck }
370*c2c66affSColin Finck */
371*c2c66affSColin Finck }
372*c2c66affSColin Finck
373*c2c66affSColin Finck if(TB_or_LR == 1)
374*c2c66affSColin Finck triangulateRectAux(top->pwlArc, bot->pwlArc, left->pwlArc, right->pwlArc, backend);
375*c2c66affSColin Finck else if(TB_or_LR == -1)
376*c2c66affSColin Finck triangulateRectAux(left->pwlArc, right->pwlArc, bot->pwlArc, top->pwlArc, backend);
377*c2c66affSColin Finck else
378*c2c66affSColin Finck {
379*c2c66affSColin Finck Int maxPointsTB = top->pwlArc->npts + bot->pwlArc->npts;
380*c2c66affSColin Finck Int maxPointsLR = left->pwlArc->npts + right->pwlArc->npts;
381*c2c66affSColin Finck
382*c2c66affSColin Finck if(maxPointsTB < maxPointsLR)
383*c2c66affSColin Finck triangulateRectAux(left->pwlArc, right->pwlArc, bot->pwlArc, top->pwlArc, backend);
384*c2c66affSColin Finck else
385*c2c66affSColin Finck triangulateRectAux(top->pwlArc, bot->pwlArc, left->pwlArc, right->pwlArc, backend);
386*c2c66affSColin Finck }
387*c2c66affSColin Finck }
388*c2c66affSColin Finck
triangulateRectAux(PwlArc * top,PwlArc * bot,PwlArc * left,PwlArc * right,Backend & backend)389*c2c66affSColin Finck static void triangulateRectAux(PwlArc* top, PwlArc* bot, PwlArc* left, PwlArc* right, Backend& backend)
390*c2c66affSColin Finck { //if(maxPointsTB >= maxPointsLR)
391*c2c66affSColin Finck {
392*c2c66affSColin Finck
393*c2c66affSColin Finck Int d, topd_left, topd_right, botd_left, botd_right, i,j;
394*c2c66affSColin Finck d = left->npts /2;
395*c2c66affSColin Finck
396*c2c66affSColin Finck #ifdef USE_OPTTT
397*c2c66affSColin Finck evalLineNOGE(top->pts, top->npts, backend);
398*c2c66affSColin Finck evalLineNOGE(bot->pts, bot->npts, backend);
399*c2c66affSColin Finck evalLineNOGE(left->pts, left->npts, backend);
400*c2c66affSColin Finck evalLineNOGE(right->pts, right->npts, backend);
401*c2c66affSColin Finck #endif
402*c2c66affSColin Finck
403*c2c66affSColin Finck if(top->npts == 2) {
404*c2c66affSColin Finck backend.bgntfan();
405*c2c66affSColin Finck OPT_OUTVERT(top->pts[0], backend);//the root
406*c2c66affSColin Finck for(i=0; i<left->npts; i++){
407*c2c66affSColin Finck OPT_OUTVERT(left->pts[i], backend);
408*c2c66affSColin Finck }
409*c2c66affSColin Finck for(i=1; i<= bot->npts-2; i++){
410*c2c66affSColin Finck OPT_OUTVERT(bot->pts[i], backend);
411*c2c66affSColin Finck }
412*c2c66affSColin Finck backend.endtfan();
413*c2c66affSColin Finck
414*c2c66affSColin Finck backend.bgntfan();
415*c2c66affSColin Finck OPT_OUTVERT(bot->pts[bot->npts-2], backend);
416*c2c66affSColin Finck for(i=0; i<right->npts; i++){
417*c2c66affSColin Finck OPT_OUTVERT(right->pts[i], backend);
418*c2c66affSColin Finck }
419*c2c66affSColin Finck backend.endtfan();
420*c2c66affSColin Finck }
421*c2c66affSColin Finck else if(bot->npts == 2) {
422*c2c66affSColin Finck backend.bgntfan();
423*c2c66affSColin Finck OPT_OUTVERT(bot->pts[0], backend);//the root
424*c2c66affSColin Finck for(i=0; i<right->npts; i++){
425*c2c66affSColin Finck OPT_OUTVERT(right->pts[i], backend);
426*c2c66affSColin Finck }
427*c2c66affSColin Finck for(i=1; i<= top->npts-2; i++){
428*c2c66affSColin Finck OPT_OUTVERT(top->pts[i], backend);
429*c2c66affSColin Finck }
430*c2c66affSColin Finck backend.endtfan();
431*c2c66affSColin Finck
432*c2c66affSColin Finck backend.bgntfan();
433*c2c66affSColin Finck OPT_OUTVERT(top->pts[top->npts-2], backend);
434*c2c66affSColin Finck for(i=0; i<left->npts; i++){
435*c2c66affSColin Finck OPT_OUTVERT(left->pts[i], backend);
436*c2c66affSColin Finck }
437*c2c66affSColin Finck backend.endtfan();
438*c2c66affSColin Finck }
439*c2c66affSColin Finck else { //both top and bot have >=3 points
440*c2c66affSColin Finck
441*c2c66affSColin Finck backend.bgntfan();
442*c2c66affSColin Finck
443*c2c66affSColin Finck OPT_OUTVERT(top->pts[top->npts-2], backend);
444*c2c66affSColin Finck
445*c2c66affSColin Finck for(i=0; i<=d; i++)
446*c2c66affSColin Finck {
447*c2c66affSColin Finck OPT_OUTVERT(left->pts[i], backend);
448*c2c66affSColin Finck }
449*c2c66affSColin Finck backend.endtfan();
450*c2c66affSColin Finck
451*c2c66affSColin Finck backend.bgntfan();
452*c2c66affSColin Finck
453*c2c66affSColin Finck OPT_OUTVERT(bot->pts[1], backend);
454*c2c66affSColin Finck
455*c2c66affSColin Finck OPT_OUTVERT(top->pts[top->npts-2], backend);
456*c2c66affSColin Finck
457*c2c66affSColin Finck for(i=d; i< left->npts; i++)
458*c2c66affSColin Finck {
459*c2c66affSColin Finck OPT_OUTVERT(left->pts[i], backend);
460*c2c66affSColin Finck }
461*c2c66affSColin Finck backend.endtfan();
462*c2c66affSColin Finck
463*c2c66affSColin Finck d = right->npts/2;
464*c2c66affSColin Finck //output only when d<right->npts-1 and
465*c2c66affSColin Finck //
466*c2c66affSColin Finck if(d<right->npts-1)
467*c2c66affSColin Finck {
468*c2c66affSColin Finck backend.bgntfan();
469*c2c66affSColin Finck // backend.tmeshvert(& top->pts[1]);
470*c2c66affSColin Finck OPT_OUTVERT(top->pts[1], backend);
471*c2c66affSColin Finck for(i=d; i< right->npts; i++)
472*c2c66affSColin Finck {
473*c2c66affSColin Finck // backend.tmeshvert(& right->pts[i]);
474*c2c66affSColin Finck
475*c2c66affSColin Finck OPT_OUTVERT(right->pts[i], backend);
476*c2c66affSColin Finck
477*c2c66affSColin Finck }
478*c2c66affSColin Finck backend.endtfan();
479*c2c66affSColin Finck }
480*c2c66affSColin Finck
481*c2c66affSColin Finck backend.bgntfan();
482*c2c66affSColin Finck // backend.tmeshvert(& bot->pts[bot->npts-2]);
483*c2c66affSColin Finck OPT_OUTVERT( bot->pts[bot->npts-2], backend);
484*c2c66affSColin Finck for(i=0; i<=d; i++)
485*c2c66affSColin Finck {
486*c2c66affSColin Finck // backend.tmeshvert(& right->pts[i]);
487*c2c66affSColin Finck OPT_OUTVERT(right->pts[i], backend);
488*c2c66affSColin Finck
489*c2c66affSColin Finck }
490*c2c66affSColin Finck
491*c2c66affSColin Finck // backend.tmeshvert(& top->pts[1]);
492*c2c66affSColin Finck OPT_OUTVERT(top->pts[1], backend);
493*c2c66affSColin Finck
494*c2c66affSColin Finck backend.endtfan();
495*c2c66affSColin Finck
496*c2c66affSColin Finck
497*c2c66affSColin Finck topd_left = top->npts-2;
498*c2c66affSColin Finck topd_right = 1; //topd_left>= topd_right
499*c2c66affSColin Finck
500*c2c66affSColin Finck botd_left = 1;
501*c2c66affSColin Finck botd_right = bot->npts-2; //botd_left<= bot_dright
502*c2c66affSColin Finck
503*c2c66affSColin Finck
504*c2c66affSColin Finck if(top->npts < bot->npts)
505*c2c66affSColin Finck {
506*c2c66affSColin Finck int delta=bot->npts - top->npts;
507*c2c66affSColin Finck int u = delta/2;
508*c2c66affSColin Finck botd_left = 1+ u;
509*c2c66affSColin Finck botd_right = bot->npts-2-( delta-u);
510*c2c66affSColin Finck
511*c2c66affSColin Finck if(botd_left >1)
512*c2c66affSColin Finck {
513*c2c66affSColin Finck backend.bgntfan();
514*c2c66affSColin Finck // backend.tmeshvert(& top->pts[top->npts-2]);
515*c2c66affSColin Finck OPT_OUTVERT(top->pts[top->npts-2], backend);
516*c2c66affSColin Finck for(i=1; i<= botd_left; i++)
517*c2c66affSColin Finck {
518*c2c66affSColin Finck // backend.tmeshvert(& bot->pts[i]);
519*c2c66affSColin Finck OPT_OUTVERT(bot->pts[i] , backend);
520*c2c66affSColin Finck }
521*c2c66affSColin Finck backend.endtfan();
522*c2c66affSColin Finck }
523*c2c66affSColin Finck if(botd_right < bot->npts-2)
524*c2c66affSColin Finck {
525*c2c66affSColin Finck backend.bgntfan();
526*c2c66affSColin Finck OPT_OUTVERT(top->pts[1], backend);
527*c2c66affSColin Finck for(i=botd_right; i<= bot->npts-2; i++)
528*c2c66affSColin Finck OPT_OUTVERT(bot->pts[i], backend);
529*c2c66affSColin Finck backend.endtfan();
530*c2c66affSColin Finck }
531*c2c66affSColin Finck }
532*c2c66affSColin Finck else if(top->npts> bot->npts)
533*c2c66affSColin Finck {
534*c2c66affSColin Finck int delta=top->npts-bot->npts;
535*c2c66affSColin Finck int u = delta/2;
536*c2c66affSColin Finck topd_left = top->npts-2 - u;
537*c2c66affSColin Finck topd_right = 1+delta-u;
538*c2c66affSColin Finck
539*c2c66affSColin Finck if(topd_left < top->npts-2)
540*c2c66affSColin Finck {
541*c2c66affSColin Finck backend.bgntfan();
542*c2c66affSColin Finck // backend.tmeshvert(& bot->pts[1]);
543*c2c66affSColin Finck OPT_OUTVERT(bot->pts[1], backend);
544*c2c66affSColin Finck for(i=topd_left; i<= top->npts-2; i++)
545*c2c66affSColin Finck {
546*c2c66affSColin Finck // backend.tmeshvert(& top->pts[i]);
547*c2c66affSColin Finck OPT_OUTVERT(top->pts[i], backend);
548*c2c66affSColin Finck }
549*c2c66affSColin Finck backend.endtfan();
550*c2c66affSColin Finck }
551*c2c66affSColin Finck if(topd_right > 1)
552*c2c66affSColin Finck {
553*c2c66affSColin Finck backend.bgntfan();
554*c2c66affSColin Finck OPT_OUTVERT(bot->pts[bot->npts-2], backend);
555*c2c66affSColin Finck for(i=1; i<= topd_right; i++)
556*c2c66affSColin Finck OPT_OUTVERT(top->pts[i], backend);
557*c2c66affSColin Finck backend.endtfan();
558*c2c66affSColin Finck }
559*c2c66affSColin Finck }
560*c2c66affSColin Finck
561*c2c66affSColin Finck if(topd_left <= topd_right)
562*c2c66affSColin Finck return;
563*c2c66affSColin Finck
564*c2c66affSColin Finck backend.bgnqstrip();
565*c2c66affSColin Finck for(j=botd_left, i=topd_left; i>=topd_right; i--,j++)
566*c2c66affSColin Finck {
567*c2c66affSColin Finck // backend.tmeshvert(& top->pts[i]);
568*c2c66affSColin Finck // backend.tmeshvert(& bot->pts[j]);
569*c2c66affSColin Finck OPT_OUTVERT(top->pts[i], backend);
570*c2c66affSColin Finck OPT_OUTVERT(bot->pts[j], backend);
571*c2c66affSColin Finck }
572*c2c66affSColin Finck backend.endqstrip();
573*c2c66affSColin Finck
574*c2c66affSColin Finck }
575*c2c66affSColin Finck }
576*c2c66affSColin Finck }
577*c2c66affSColin Finck
578*c2c66affSColin Finck
triangulateRectCenter(int n_ulines,REAL * u_val,int n_vlines,REAL * v_val,Backend & backend)579*c2c66affSColin Finck static void triangulateRectCenter(int n_ulines, REAL* u_val,
580*c2c66affSColin Finck int n_vlines, REAL* v_val,
581*c2c66affSColin Finck Backend& backend)
582*c2c66affSColin Finck {
583*c2c66affSColin Finck
584*c2c66affSColin Finck // XXX this code was patched by Diego Santa Cruz <Diego.SantaCruz@epfl.ch>
585*c2c66affSColin Finck // to fix a problem in which glMapGrid2f() was called with bad parameters.
586*c2c66affSColin Finck // This has beens submitted to SGI but not integrated as of May 1, 2001.
587*c2c66affSColin Finck if(n_ulines>1 && n_vlines>1) {
588*c2c66affSColin Finck backend.surfgrid(u_val[0], u_val[n_ulines-1], n_ulines-1,
589*c2c66affSColin Finck v_val[n_vlines-1], v_val[0], n_vlines-1);
590*c2c66affSColin Finck backend.surfmesh(0,0,n_ulines-1,n_vlines-1);
591*c2c66affSColin Finck }
592*c2c66affSColin Finck
593*c2c66affSColin Finck return;
594*c2c66affSColin Finck
595*c2c66affSColin Finck /*
596*c2c66affSColin Finck for(i=0; i<n_vlines-1; i++)
597*c2c66affSColin Finck {
598*c2c66affSColin Finck
599*c2c66affSColin Finck backend.bgnqstrip();
600*c2c66affSColin Finck for(j=0; j<n_ulines; j++)
601*c2c66affSColin Finck {
602*c2c66affSColin Finck trimVert.param[0] = u_val[j];
603*c2c66affSColin Finck trimVert.param[1] = v_val[i+1];
604*c2c66affSColin Finck backend.tmeshvert(& trimVert);
605*c2c66affSColin Finck
606*c2c66affSColin Finck trimVert.param[1] = v_val[i];
607*c2c66affSColin Finck backend.tmeshvert(& trimVert);
608*c2c66affSColin Finck }
609*c2c66affSColin Finck backend.endqstrip();
610*c2c66affSColin Finck
611*c2c66affSColin Finck }
612*c2c66affSColin Finck */
613*c2c66affSColin Finck }
614*c2c66affSColin Finck
615*c2c66affSColin Finck //it works for top, bot, left ad right, you need ot select correct arguments
triangulateRectTopGen(Arc_ptr arc,int n_ulines,REAL * u_val,Real v,int dir,int is_u,Backend & backend)616*c2c66affSColin Finck static void triangulateRectTopGen(Arc_ptr arc, int n_ulines, REAL* u_val, Real v, int dir, int is_u, Backend& backend)
617*c2c66affSColin Finck {
618*c2c66affSColin Finck
619*c2c66affSColin Finck if(is_u)
620*c2c66affSColin Finck {
621*c2c66affSColin Finck int i,k;
622*c2c66affSColin Finck REAL* upper_val = (REAL*) malloc(sizeof(REAL) * arc->pwlArc->npts);
623*c2c66affSColin Finck assert(upper_val);
624*c2c66affSColin Finck if(dir)
625*c2c66affSColin Finck {
626*c2c66affSColin Finck for(k=0,i=arc->pwlArc->npts-1; i>=0; i--,k++)
627*c2c66affSColin Finck {
628*c2c66affSColin Finck upper_val[k] = arc->pwlArc->pts[i].param[0];
629*c2c66affSColin Finck }
630*c2c66affSColin Finck backend.evalUStrip(arc->pwlArc->npts, arc->pwlArc->pts[0].param[1],
631*c2c66affSColin Finck upper_val,
632*c2c66affSColin Finck n_ulines, v, u_val);
633*c2c66affSColin Finck }
634*c2c66affSColin Finck else
635*c2c66affSColin Finck {
636*c2c66affSColin Finck for(k=0,i=0; i<arc->pwlArc->npts; i++,k++)
637*c2c66affSColin Finck {
638*c2c66affSColin Finck upper_val[k] = arc->pwlArc->pts[i].param[0];
639*c2c66affSColin Finck
640*c2c66affSColin Finck }
641*c2c66affSColin Finck
642*c2c66affSColin Finck backend.evalUStrip(
643*c2c66affSColin Finck n_ulines, v, u_val,
644*c2c66affSColin Finck arc->pwlArc->npts, arc->pwlArc->pts[0].param[1], upper_val
645*c2c66affSColin Finck );
646*c2c66affSColin Finck }
647*c2c66affSColin Finck
648*c2c66affSColin Finck free(upper_val);
649*c2c66affSColin Finck return;
650*c2c66affSColin Finck }
651*c2c66affSColin Finck else //is_v
652*c2c66affSColin Finck {
653*c2c66affSColin Finck int i,k;
654*c2c66affSColin Finck REAL* left_val = (REAL*) malloc(sizeof(REAL) * arc->pwlArc->npts);
655*c2c66affSColin Finck assert(left_val);
656*c2c66affSColin Finck if(dir)
657*c2c66affSColin Finck {
658*c2c66affSColin Finck for(k=0,i=arc->pwlArc->npts-1; i>=0; i--,k++)
659*c2c66affSColin Finck {
660*c2c66affSColin Finck left_val[k] = arc->pwlArc->pts[i].param[1];
661*c2c66affSColin Finck }
662*c2c66affSColin Finck backend.evalVStrip(arc->pwlArc->npts, arc->pwlArc->pts[0].param[0],
663*c2c66affSColin Finck left_val,
664*c2c66affSColin Finck n_ulines, v, u_val);
665*c2c66affSColin Finck }
666*c2c66affSColin Finck else
667*c2c66affSColin Finck {
668*c2c66affSColin Finck for(k=0,i=0; i<arc->pwlArc->npts; i++,k++)
669*c2c66affSColin Finck {
670*c2c66affSColin Finck left_val[k] = arc->pwlArc->pts[i].param[1];
671*c2c66affSColin Finck }
672*c2c66affSColin Finck backend.evalVStrip(
673*c2c66affSColin Finck n_ulines, v, u_val,
674*c2c66affSColin Finck arc->pwlArc->npts, arc->pwlArc->pts[0].param[0], left_val
675*c2c66affSColin Finck );
676*c2c66affSColin Finck }
677*c2c66affSColin Finck free(left_val);
678*c2c66affSColin Finck return;
679*c2c66affSColin Finck }
680*c2c66affSColin Finck
681*c2c66affSColin Finck //the following is a different version of the above code. If you comment
682*c2c66affSColin Finck //the above code, the following code will still work. The reason to leave
683*c2c66affSColin Finck //the folliwng code here is purely for testing purpose.
684*c2c66affSColin Finck /*
685*c2c66affSColin Finck int i,j;
686*c2c66affSColin Finck PwlArc* parc = arc->pwlArc;
687*c2c66affSColin Finck int d1 = parc->npts-1;
688*c2c66affSColin Finck int d2 = 0;
689*c2c66affSColin Finck TrimVertex trimVert;
690*c2c66affSColin Finck trimVert.nuid = 0;//????
691*c2c66affSColin Finck REAL* temp_u_val = u_val;
692*c2c66affSColin Finck if(dir ==0) //have to reverse u_val
693*c2c66affSColin Finck {
694*c2c66affSColin Finck temp_u_val = (REAL*) malloc(sizeof(REAL) * n_ulines);
695*c2c66affSColin Finck assert(temp_u_val);
696*c2c66affSColin Finck for(i=0; i<n_ulines; i++)
697*c2c66affSColin Finck temp_u_val[i] = u_val[n_ulines-1-i];
698*c2c66affSColin Finck }
699*c2c66affSColin Finck u_val = temp_u_val;
700*c2c66affSColin Finck
701*c2c66affSColin Finck if(parc->npts > n_ulines)
702*c2c66affSColin Finck {
703*c2c66affSColin Finck d1 = n_ulines-1;
704*c2c66affSColin Finck
705*c2c66affSColin Finck backend.bgntfan();
706*c2c66affSColin Finck if(is_u){
707*c2c66affSColin Finck trimVert.param[0] = u_val[0];
708*c2c66affSColin Finck trimVert.param[1] = v;
709*c2c66affSColin Finck }
710*c2c66affSColin Finck else
711*c2c66affSColin Finck {
712*c2c66affSColin Finck trimVert.param[1] = u_val[0];
713*c2c66affSColin Finck trimVert.param[0] = v;
714*c2c66affSColin Finck }
715*c2c66affSColin Finck
716*c2c66affSColin Finck backend.tmeshvert(& trimVert);
717*c2c66affSColin Finck for(i=d1; i< parc->npts; i++)
718*c2c66affSColin Finck backend.tmeshvert(& parc->pts[i]);
719*c2c66affSColin Finck backend.endtfan();
720*c2c66affSColin Finck
721*c2c66affSColin Finck
722*c2c66affSColin Finck }
723*c2c66affSColin Finck else if(parc->npts < n_ulines)
724*c2c66affSColin Finck {
725*c2c66affSColin Finck d2 = n_ulines-parc->npts;
726*c2c66affSColin Finck
727*c2c66affSColin Finck
728*c2c66affSColin Finck backend.bgntfan();
729*c2c66affSColin Finck backend.tmeshvert(& parc->pts[parc->npts-1]);
730*c2c66affSColin Finck for(i=0; i<= d2; i++)
731*c2c66affSColin Finck {
732*c2c66affSColin Finck if(is_u){
733*c2c66affSColin Finck trimVert.param[0] = u_val[i];
734*c2c66affSColin Finck trimVert.param[1] = v;
735*c2c66affSColin Finck }
736*c2c66affSColin Finck else
737*c2c66affSColin Finck {
738*c2c66affSColin Finck trimVert.param[1] = u_val[i];
739*c2c66affSColin Finck trimVert.param[0] = v;
740*c2c66affSColin Finck }
741*c2c66affSColin Finck backend.tmeshvert(&trimVert);
742*c2c66affSColin Finck }
743*c2c66affSColin Finck backend.endtfan();
744*c2c66affSColin Finck
745*c2c66affSColin Finck }
746*c2c66affSColin Finck if(d1>0){
747*c2c66affSColin Finck
748*c2c66affSColin Finck
749*c2c66affSColin Finck backend.bgnqstrip();
750*c2c66affSColin Finck for(i=d1, j=d2; i>=0; i--, j++)
751*c2c66affSColin Finck {
752*c2c66affSColin Finck backend.tmeshvert(& parc->pts[i]);
753*c2c66affSColin Finck
754*c2c66affSColin Finck if(is_u){
755*c2c66affSColin Finck trimVert.param[0] = u_val[j];
756*c2c66affSColin Finck trimVert.param[1] = v;
757*c2c66affSColin Finck }
758*c2c66affSColin Finck else{
759*c2c66affSColin Finck trimVert.param[1] = u_val[j];
760*c2c66affSColin Finck trimVert.param[0] = v;
761*c2c66affSColin Finck }
762*c2c66affSColin Finck backend.tmeshvert(&trimVert);
763*c2c66affSColin Finck
764*c2c66affSColin Finck
765*c2c66affSColin Finck
766*c2c66affSColin Finck }
767*c2c66affSColin Finck backend.endqstrip();
768*c2c66affSColin Finck
769*c2c66affSColin Finck
770*c2c66affSColin Finck }
771*c2c66affSColin Finck if(dir == 0) //temp_u_val was mallocated
772*c2c66affSColin Finck free(temp_u_val);
773*c2c66affSColin Finck */
774*c2c66affSColin Finck }
775*c2c66affSColin Finck
776*c2c66affSColin Finck //n_ulines is the number of ulines inside, and n_vlines is the number of vlines
777*c2c66affSColin Finck //inside, different from meanings elsewhere!!!
triangulateRectGen(Arc_ptr loop,int n_ulines,int n_vlines,Backend & backend)778*c2c66affSColin Finck static void triangulateRectGen(Arc_ptr loop, int n_ulines, int n_vlines, Backend& backend)
779*c2c66affSColin Finck {
780*c2c66affSColin Finck
781*c2c66affSColin Finck int i;
782*c2c66affSColin Finck //we know the loop is a rectangle, but not sure which is top
783*c2c66affSColin Finck Arc_ptr top, bot, left, right;
784*c2c66affSColin Finck
785*c2c66affSColin Finck if(equalRect(loop->tail()[1] , loop->head()[1]))
786*c2c66affSColin Finck {
787*c2c66affSColin Finck
788*c2c66affSColin Finck if(loop->tail()[1] > loop->prev->prev->tail()[1])
789*c2c66affSColin Finck {
790*c2c66affSColin Finck
791*c2c66affSColin Finck top = loop;
792*c2c66affSColin Finck }
793*c2c66affSColin Finck else{
794*c2c66affSColin Finck
795*c2c66affSColin Finck top = loop->prev->prev;
796*c2c66affSColin Finck }
797*c2c66affSColin Finck }
798*c2c66affSColin Finck else
799*c2c66affSColin Finck {
800*c2c66affSColin Finck if(loop->tail()[0] > loop->prev->prev->tail()[0])
801*c2c66affSColin Finck {
802*c2c66affSColin Finck //loop is the right arc
803*c2c66affSColin Finck
804*c2c66affSColin Finck top = loop->next;
805*c2c66affSColin Finck }
806*c2c66affSColin Finck else
807*c2c66affSColin Finck {
808*c2c66affSColin Finck
809*c2c66affSColin Finck top = loop->prev;
810*c2c66affSColin Finck }
811*c2c66affSColin Finck }
812*c2c66affSColin Finck
813*c2c66affSColin Finck left = top->next;
814*c2c66affSColin Finck bot = left->next;
815*c2c66affSColin Finck right= bot->next;
816*c2c66affSColin Finck
817*c2c66affSColin Finck #ifdef COUNT_TRIANGLES
818*c2c66affSColin Finck num_triangles += loop->pwlArc->npts +
819*c2c66affSColin Finck left->pwlArc->npts +
820*c2c66affSColin Finck bot->pwlArc->npts +
821*c2c66affSColin Finck right->pwlArc->npts
822*c2c66affSColin Finck + 2*n_ulines + 2*n_vlines
823*c2c66affSColin Finck -8;
824*c2c66affSColin Finck num_quads += (n_ulines-1)*(n_vlines-1);
825*c2c66affSColin Finck #endif
826*c2c66affSColin Finck /*
827*c2c66affSColin Finck backend.surfgrid(left->tail()[0], right->tail()[0], n_ulines+1,
828*c2c66affSColin Finck top->tail()[1], bot->tail()[1], n_vlines+1);
829*c2c66affSColin Finck // if(n_ulines>1 && n_vlines>1)
830*c2c66affSColin Finck backend.surfmesh(0,0,n_ulines+1,n_vlines+1);
831*c2c66affSColin Finck return;
832*c2c66affSColin Finck */
833*c2c66affSColin Finck REAL* u_val=(REAL*) malloc(sizeof(REAL)*n_ulines);
834*c2c66affSColin Finck assert(u_val);
835*c2c66affSColin Finck REAL* v_val=(REAL*)malloc(sizeof(REAL) * n_vlines);
836*c2c66affSColin Finck assert(v_val);
837*c2c66affSColin Finck REAL u_stepsize = (right->tail()[0] - left->tail()[0])/( (REAL) n_ulines+1);
838*c2c66affSColin Finck REAL v_stepsize = (top->tail()[1] - bot->tail()[1])/( (REAL) n_vlines+1);
839*c2c66affSColin Finck Real temp=left->tail()[0]+u_stepsize;
840*c2c66affSColin Finck for(i=0; i<n_ulines; i++)
841*c2c66affSColin Finck {
842*c2c66affSColin Finck u_val[i] = temp;
843*c2c66affSColin Finck temp += u_stepsize;
844*c2c66affSColin Finck }
845*c2c66affSColin Finck temp = bot->tail()[1] + v_stepsize;
846*c2c66affSColin Finck for(i=0; i<n_vlines; i++)
847*c2c66affSColin Finck {
848*c2c66affSColin Finck v_val[i] = temp;
849*c2c66affSColin Finck temp += v_stepsize;
850*c2c66affSColin Finck }
851*c2c66affSColin Finck
852*c2c66affSColin Finck triangulateRectTopGen(top, n_ulines, u_val, v_val[n_vlines-1], 1,1, backend);
853*c2c66affSColin Finck triangulateRectTopGen(bot, n_ulines, u_val, v_val[0], 0, 1, backend);
854*c2c66affSColin Finck triangulateRectTopGen(left, n_vlines, v_val, u_val[0], 1, 0, backend);
855*c2c66affSColin Finck triangulateRectTopGen(right, n_vlines, v_val, u_val[n_ulines-1], 0,0, backend);
856*c2c66affSColin Finck
857*c2c66affSColin Finck
858*c2c66affSColin Finck
859*c2c66affSColin Finck
860*c2c66affSColin Finck //triangulate the center
861*c2c66affSColin Finck triangulateRectCenter(n_ulines, u_val, n_vlines, v_val, backend);
862*c2c66affSColin Finck
863*c2c66affSColin Finck free(u_val);
864*c2c66affSColin Finck free(v_val);
865*c2c66affSColin Finck
866*c2c66affSColin Finck }
867*c2c66affSColin Finck
868*c2c66affSColin Finck
869*c2c66affSColin Finck
870*c2c66affSColin Finck
871*c2c66affSColin Finck /**********for reading newtess_flag from a file**********/
872*c2c66affSColin Finck #ifdef USE_READ_FLAG
read_flag(char * name)873*c2c66affSColin Finck static Int read_flag(char* name)
874*c2c66affSColin Finck {
875*c2c66affSColin Finck Int ret;
876*c2c66affSColin Finck FILE* fp = fopen(name, "r");
877*c2c66affSColin Finck if(fp == NULL)
878*c2c66affSColin Finck {
879*c2c66affSColin Finck fprintf(stderr, "can't open file %s\n", name);
880*c2c66affSColin Finck exit(1);
881*c2c66affSColin Finck }
882*c2c66affSColin Finck fscanf(fp, "%i", &ret);
883*c2c66affSColin Finck fclose(fp);
884*c2c66affSColin Finck return ret;
885*c2c66affSColin Finck }
886*c2c66affSColin Finck #endif
887*c2c66affSColin Finck
888*c2c66affSColin Finck /***********nextgen tess****************/
889*c2c66affSColin Finck #include "sampleMonoPoly.h"
arcToDLine(Arc_ptr arc)890*c2c66affSColin Finck directedLine* arcToDLine(Arc_ptr arc)
891*c2c66affSColin Finck {
892*c2c66affSColin Finck int i;
893*c2c66affSColin Finck Real vert[2];
894*c2c66affSColin Finck directedLine* ret;
895*c2c66affSColin Finck sampledLine* sline = new sampledLine(arc->pwlArc->npts);
896*c2c66affSColin Finck for(i=0; i<arc->pwlArc->npts; i++)
897*c2c66affSColin Finck {
898*c2c66affSColin Finck vert[0] = arc->pwlArc->pts[i].param[0];
899*c2c66affSColin Finck vert[1] = arc->pwlArc->pts[i].param[1];
900*c2c66affSColin Finck sline->setPoint(i, vert);
901*c2c66affSColin Finck }
902*c2c66affSColin Finck ret = new directedLine(INCREASING, sline);
903*c2c66affSColin Finck return ret;
904*c2c66affSColin Finck }
905*c2c66affSColin Finck
906*c2c66affSColin Finck /*an pwlArc may not be a straight line*/
arcToMultDLines(directedLine * original,Arc_ptr arc)907*c2c66affSColin Finck directedLine* arcToMultDLines(directedLine* original, Arc_ptr arc)
908*c2c66affSColin Finck {
909*c2c66affSColin Finck directedLine* ret = original;
910*c2c66affSColin Finck int is_linear = 0;
911*c2c66affSColin Finck if(arc->pwlArc->npts == 2 )
912*c2c66affSColin Finck is_linear = 1;
913*c2c66affSColin Finck else if(area(arc->pwlArc->pts[0].param, arc->pwlArc->pts[1].param, arc->pwlArc->pts[arc->pwlArc->npts-1].param) == 0.0)
914*c2c66affSColin Finck is_linear = 1;
915*c2c66affSColin Finck
916*c2c66affSColin Finck if(is_linear)
917*c2c66affSColin Finck {
918*c2c66affSColin Finck directedLine *dline = arcToDLine(arc);
919*c2c66affSColin Finck if(ret == NULL)
920*c2c66affSColin Finck ret = dline;
921*c2c66affSColin Finck else
922*c2c66affSColin Finck ret->insert(dline);
923*c2c66affSColin Finck return ret;
924*c2c66affSColin Finck }
925*c2c66affSColin Finck else /*not linear*/
926*c2c66affSColin Finck {
927*c2c66affSColin Finck for(Int i=0; i<arc->pwlArc->npts-1; i++)
928*c2c66affSColin Finck {
929*c2c66affSColin Finck Real vert[2][2];
930*c2c66affSColin Finck vert[0][0] = arc->pwlArc->pts[i].param[0];
931*c2c66affSColin Finck vert[0][1] = arc->pwlArc->pts[i].param[1];
932*c2c66affSColin Finck vert[1][0] = arc->pwlArc->pts[i+1].param[0];
933*c2c66affSColin Finck vert[1][1] = arc->pwlArc->pts[i+1].param[1];
934*c2c66affSColin Finck
935*c2c66affSColin Finck sampledLine *sline = new sampledLine(2, vert);
936*c2c66affSColin Finck directedLine *dline = new directedLine(INCREASING, sline);
937*c2c66affSColin Finck if(ret == NULL)
938*c2c66affSColin Finck ret = dline;
939*c2c66affSColin Finck else
940*c2c66affSColin Finck ret->insert(dline);
941*c2c66affSColin Finck }
942*c2c66affSColin Finck return ret;
943*c2c66affSColin Finck }
944*c2c66affSColin Finck }
945*c2c66affSColin Finck
946*c2c66affSColin Finck
947*c2c66affSColin Finck
arcLoopToDLineLoop(Arc_ptr loop)948*c2c66affSColin Finck directedLine* arcLoopToDLineLoop(Arc_ptr loop)
949*c2c66affSColin Finck {
950*c2c66affSColin Finck directedLine* ret;
951*c2c66affSColin Finck
952*c2c66affSColin Finck if(loop == NULL)
953*c2c66affSColin Finck return NULL;
954*c2c66affSColin Finck ret = arcToMultDLines(NULL, loop);
955*c2c66affSColin Finck //ret->printSingle();
956*c2c66affSColin Finck for(Arc_ptr temp = loop->next; temp != loop; temp = temp->next){
957*c2c66affSColin Finck ret = arcToMultDLines(ret, temp);
958*c2c66affSColin Finck //ret->printSingle();
959*c2c66affSColin Finck }
960*c2c66affSColin Finck
961*c2c66affSColin Finck return ret;
962*c2c66affSColin Finck }
963*c2c66affSColin Finck
964*c2c66affSColin Finck /*
965*c2c66affSColin Finck void Slicer::evalRBArray(rectBlockArray* rbArray, gridWrap* grid)
966*c2c66affSColin Finck {
967*c2c66affSColin Finck TrimVertex *trimVert = (TrimVertex*)malloc(sizeof(TrimVertex));
968*c2c66affSColin Finck trimVert -> nuid = 0;//????
969*c2c66affSColin Finck
970*c2c66affSColin Finck Real* u_values = grid->get_u_values();
971*c2c66affSColin Finck Real* v_values = grid->get_v_values();
972*c2c66affSColin Finck
973*c2c66affSColin Finck Int i,j,k,l;
974*c2c66affSColin Finck
975*c2c66affSColin Finck for(l=0; l<rbArray->get_n_elements(); l++)
976*c2c66affSColin Finck {
977*c2c66affSColin Finck rectBlock* block = rbArray->get_element(l);
978*c2c66affSColin Finck for(k=0, i=block->get_upGridLineIndex(); i>block->get_lowGridLineIndex(); i--, k++)
979*c2c66affSColin Finck {
980*c2c66affSColin Finck
981*c2c66affSColin Finck backend.bgnqstrip();
982*c2c66affSColin Finck for(j=block->get_leftIndices()[k+1]; j<= block->get_rightIndices()[k+1]; j++)
983*c2c66affSColin Finck {
984*c2c66affSColin Finck trimVert->param[0] = u_values[j];
985*c2c66affSColin Finck trimVert->param[1] = v_values[i];
986*c2c66affSColin Finck backend.tmeshvert(trimVert);
987*c2c66affSColin Finck
988*c2c66affSColin Finck trimVert->param[1] = v_values[i-1];
989*c2c66affSColin Finck backend.tmeshvert(trimVert);
990*c2c66affSColin Finck
991*c2c66affSColin Finck }
992*c2c66affSColin Finck backend.endqstrip();
993*c2c66affSColin Finck
994*c2c66affSColin Finck }
995*c2c66affSColin Finck }
996*c2c66affSColin Finck
997*c2c66affSColin Finck free(trimVert);
998*c2c66affSColin Finck }
999*c2c66affSColin Finck */
1000*c2c66affSColin Finck
evalRBArray(rectBlockArray * rbArray,gridWrap * grid)1001*c2c66affSColin Finck void Slicer::evalRBArray(rectBlockArray* rbArray, gridWrap* grid)
1002*c2c66affSColin Finck {
1003*c2c66affSColin Finck Int i,j,k;
1004*c2c66affSColin Finck
1005*c2c66affSColin Finck Int n_vlines=grid->get_n_vlines();
1006*c2c66affSColin Finck //the reason to switch the position of v_max and v_min is because of the
1007*c2c66affSColin Finck //the orientation problem. glEvalMesh generates quad_strip clockwise, but
1008*c2c66affSColin Finck //we need counter-clockwise.
1009*c2c66affSColin Finck backend.surfgrid(grid->get_u_min(), grid->get_u_max(), grid->get_n_ulines()-1,
1010*c2c66affSColin Finck grid->get_v_max(), grid->get_v_min(), n_vlines-1);
1011*c2c66affSColin Finck
1012*c2c66affSColin Finck
1013*c2c66affSColin Finck for(j=0; j<rbArray->get_n_elements(); j++)
1014*c2c66affSColin Finck {
1015*c2c66affSColin Finck rectBlock* block = rbArray->get_element(j);
1016*c2c66affSColin Finck Int low = block->get_lowGridLineIndex();
1017*c2c66affSColin Finck Int high = block->get_upGridLineIndex();
1018*c2c66affSColin Finck
1019*c2c66affSColin Finck for(k=0, i=high; i>low; i--, k++)
1020*c2c66affSColin Finck {
1021*c2c66affSColin Finck backend.surfmesh(block->get_leftIndices()[k+1], n_vlines-1-i, block->get_rightIndices()[k+1]-block->get_leftIndices()[k+1], 1);
1022*c2c66affSColin Finck }
1023*c2c66affSColin Finck }
1024*c2c66affSColin Finck }
1025*c2c66affSColin Finck
1026*c2c66affSColin Finck
evalStream(primStream * pStream)1027*c2c66affSColin Finck void Slicer::evalStream(primStream* pStream)
1028*c2c66affSColin Finck {
1029*c2c66affSColin Finck Int i,j,k;
1030*c2c66affSColin Finck k=0;
1031*c2c66affSColin Finck /* TrimVertex X;*/
1032*c2c66affSColin Finck TrimVertex *trimVert =/*&X*/ (TrimVertex*)malloc(sizeof(TrimVertex));
1033*c2c66affSColin Finck trimVert -> nuid = 0;//???
1034*c2c66affSColin Finck Real* vertices = pStream->get_vertices(); //for efficiency
1035*c2c66affSColin Finck for(i=0; i<pStream->get_n_prims(); i++)
1036*c2c66affSColin Finck {
1037*c2c66affSColin Finck
1038*c2c66affSColin Finck //ith primitive has #vertices = lengths[i], type=types[i]
1039*c2c66affSColin Finck switch(pStream->get_type(i)){
1040*c2c66affSColin Finck case PRIMITIVE_STREAM_FAN:
1041*c2c66affSColin Finck
1042*c2c66affSColin Finck backend.bgntfan();
1043*c2c66affSColin Finck
1044*c2c66affSColin Finck for(j=0; j<pStream->get_length(i); j++)
1045*c2c66affSColin Finck {
1046*c2c66affSColin Finck trimVert->param[0] = vertices[k];
1047*c2c66affSColin Finck trimVert->param[1] = vertices[k+1];
1048*c2c66affSColin Finck backend.tmeshvert(trimVert);
1049*c2c66affSColin Finck
1050*c2c66affSColin Finck // backend.tmeshvert(vertices[k], vertices[k+1]);
1051*c2c66affSColin Finck k += 2;
1052*c2c66affSColin Finck }
1053*c2c66affSColin Finck backend.endtfan();
1054*c2c66affSColin Finck break;
1055*c2c66affSColin Finck
1056*c2c66affSColin Finck default:
1057*c2c66affSColin Finck fprintf(stderr, "evalStream: not implemented yet\n");
1058*c2c66affSColin Finck exit(1);
1059*c2c66affSColin Finck
1060*c2c66affSColin Finck }
1061*c2c66affSColin Finck }
1062*c2c66affSColin Finck free(trimVert);
1063*c2c66affSColin Finck }
1064*c2c66affSColin Finck
1065*c2c66affSColin Finck
1066*c2c66affSColin Finck
1067*c2c66affSColin Finck
slice_new(Arc_ptr loop)1068*c2c66affSColin Finck void Slicer::slice_new(Arc_ptr loop)
1069*c2c66affSColin Finck {
1070*c2c66affSColin Finck //count++;
1071*c2c66affSColin Finck //if(count == 78) count=1;
1072*c2c66affSColin Finck //printf("count=%i\n", count);
1073*c2c66affSColin Finck //if( ! (4<= count && count <=4)) return;
1074*c2c66affSColin Finck
1075*c2c66affSColin Finck
1076*c2c66affSColin Finck Int num_ulines;
1077*c2c66affSColin Finck Int num_vlines;
1078*c2c66affSColin Finck Real uMin, uMax, vMin, vMax;
1079*c2c66affSColin Finck Real mydu, mydv;
1080*c2c66affSColin Finck uMin = uMax = loop->tail()[0];
1081*c2c66affSColin Finck vMin = vMax = loop->tail()[1];
1082*c2c66affSColin Finck mydu = (du>0)? du: -du;
1083*c2c66affSColin Finck mydv = (dv>0)? dv: -dv;
1084*c2c66affSColin Finck
1085*c2c66affSColin Finck for(Arc_ptr jarc=loop->next; jarc != loop; jarc = jarc->next)
1086*c2c66affSColin Finck {
1087*c2c66affSColin Finck
1088*c2c66affSColin Finck if(jarc->tail()[0] < uMin)
1089*c2c66affSColin Finck uMin = jarc->tail()[0];
1090*c2c66affSColin Finck if(jarc->tail()[0] > uMax)
1091*c2c66affSColin Finck uMax = jarc->tail()[0];
1092*c2c66affSColin Finck if(jarc->tail()[1] < vMin)
1093*c2c66affSColin Finck vMin = jarc->tail()[1];
1094*c2c66affSColin Finck if(jarc->tail()[1] > vMax)
1095*c2c66affSColin Finck vMax = jarc->tail()[1];
1096*c2c66affSColin Finck }
1097*c2c66affSColin Finck
1098*c2c66affSColin Finck if (uMax == uMin)
1099*c2c66affSColin Finck return; // prevent divide-by-zero. Jon Perry. 17 June 2002
1100*c2c66affSColin Finck
1101*c2c66affSColin Finck if(mydu > uMax - uMin)
1102*c2c66affSColin Finck num_ulines = 2;
1103*c2c66affSColin Finck else
1104*c2c66affSColin Finck {
1105*c2c66affSColin Finck num_ulines = 3 + (Int) ((uMax-uMin)/mydu);
1106*c2c66affSColin Finck }
1107*c2c66affSColin Finck if(mydv>=vMax-vMin)
1108*c2c66affSColin Finck num_vlines = 2;
1109*c2c66affSColin Finck else
1110*c2c66affSColin Finck {
1111*c2c66affSColin Finck num_vlines = 2+(Int)((vMax-vMin)/mydv);
1112*c2c66affSColin Finck }
1113*c2c66affSColin Finck
1114*c2c66affSColin Finck Int isRect = is_rect(loop);
1115*c2c66affSColin Finck
1116*c2c66affSColin Finck if(isRect && (num_ulines<=2 || num_vlines<=2))
1117*c2c66affSColin Finck {
1118*c2c66affSColin Finck if(vlinear)
1119*c2c66affSColin Finck triangulateRect(loop, backend, 1, ulinear, vlinear);
1120*c2c66affSColin Finck else if(ulinear)
1121*c2c66affSColin Finck triangulateRect(loop, backend, -1, ulinear, vlinear);
1122*c2c66affSColin Finck else
1123*c2c66affSColin Finck triangulateRect(loop, backend, 0, ulinear, vlinear);
1124*c2c66affSColin Finck }
1125*c2c66affSColin Finck
1126*c2c66affSColin Finck else if(isRect)
1127*c2c66affSColin Finck {
1128*c2c66affSColin Finck triangulateRectGen(loop, num_ulines-2, num_vlines-2, backend);
1129*c2c66affSColin Finck }
1130*c2c66affSColin Finck else if( (num_ulines<=2 || num_vlines <=2) && ulinear)
1131*c2c66affSColin Finck {
1132*c2c66affSColin Finck monoTriangulationFunBackend(loop, compV2InY, &backend);
1133*c2c66affSColin Finck }
1134*c2c66affSColin Finck else if( (!ulinear) && (!vlinear) && (num_ulines == 2) && (num_vlines > 2))
1135*c2c66affSColin Finck {
1136*c2c66affSColin Finck monoTriangulationFunBackend(loop, compV2InY, &backend);
1137*c2c66affSColin Finck }
1138*c2c66affSColin Finck else
1139*c2c66affSColin Finck {
1140*c2c66affSColin Finck directedLine* poly = arcLoopToDLineLoop(loop);
1141*c2c66affSColin Finck
1142*c2c66affSColin Finck gridWrap grid(num_ulines, num_vlines, uMin, uMax, vMin, vMax);
1143*c2c66affSColin Finck primStream pStream(20, 20);
1144*c2c66affSColin Finck rectBlockArray rbArray(20);
1145*c2c66affSColin Finck
1146*c2c66affSColin Finck sampleMonoPoly(poly, &grid, ulinear, vlinear, &pStream, &rbArray);
1147*c2c66affSColin Finck
1148*c2c66affSColin Finck evalStream(&pStream);
1149*c2c66affSColin Finck
1150*c2c66affSColin Finck evalRBArray(&rbArray, &grid);
1151*c2c66affSColin Finck
1152*c2c66affSColin Finck #ifdef COUNT_TRIANGLES
1153*c2c66affSColin Finck num_triangles += pStream.num_triangles();
1154*c2c66affSColin Finck num_quads += rbArray.num_quads();
1155*c2c66affSColin Finck #endif
1156*c2c66affSColin Finck poly->deleteSinglePolygonWithSline();
1157*c2c66affSColin Finck }
1158*c2c66affSColin Finck
1159*c2c66affSColin Finck #ifdef COUNT_TRIANGLES
1160*c2c66affSColin Finck printf("num_triangles=%i\n", num_triangles);
1161*c2c66affSColin Finck printf("num_quads = %i\n", num_quads);
1162*c2c66affSColin Finck #endif
1163*c2c66affSColin Finck }
1164*c2c66affSColin Finck
slice(Arc_ptr loop)1165*c2c66affSColin Finck void Slicer::slice(Arc_ptr loop)
1166*c2c66affSColin Finck {
1167*c2c66affSColin Finck #ifdef USE_READ_FLAG
1168*c2c66affSColin Finck if(read_flag("flagFile"))
1169*c2c66affSColin Finck slice_new(loop);
1170*c2c66affSColin Finck else
1171*c2c66affSColin Finck slice_old(loop);
1172*c2c66affSColin Finck
1173*c2c66affSColin Finck #else
1174*c2c66affSColin Finck slice_new(loop);
1175*c2c66affSColin Finck #endif
1176*c2c66affSColin Finck
1177*c2c66affSColin Finck }
1178*c2c66affSColin Finck
1179*c2c66affSColin Finck
1180*c2c66affSColin Finck
Slicer(Backend & b)1181*c2c66affSColin Finck Slicer::Slicer( Backend &b )
1182*c2c66affSColin Finck : CoveAndTiler( b ), Mesher( b ), backend( b )
1183*c2c66affSColin Finck {
1184*c2c66affSColin Finck oneOverDu = 0;
1185*c2c66affSColin Finck du = 0;
1186*c2c66affSColin Finck dv = 0;
1187*c2c66affSColin Finck isolines = 0;
1188*c2c66affSColin Finck ulinear = 0;
1189*c2c66affSColin Finck vlinear = 0;
1190*c2c66affSColin Finck }
1191*c2c66affSColin Finck
~Slicer()1192*c2c66affSColin Finck Slicer::~Slicer()
1193*c2c66affSColin Finck {
1194*c2c66affSColin Finck }
1195*c2c66affSColin Finck
1196*c2c66affSColin Finck void
setisolines(int x)1197*c2c66affSColin Finck Slicer::setisolines( int x )
1198*c2c66affSColin Finck {
1199*c2c66affSColin Finck isolines = x;
1200*c2c66affSColin Finck }
1201*c2c66affSColin Finck
1202*c2c66affSColin Finck void
setstriptessellation(REAL x,REAL y)1203*c2c66affSColin Finck Slicer::setstriptessellation( REAL x, REAL y )
1204*c2c66affSColin Finck {
1205*c2c66affSColin Finck assert(x > 0 && y > 0);
1206*c2c66affSColin Finck du = x;
1207*c2c66affSColin Finck dv = y;
1208*c2c66affSColin Finck setDu( du );
1209*c2c66affSColin Finck }
1210*c2c66affSColin Finck
1211*c2c66affSColin Finck void
slice_old(Arc_ptr loop)1212*c2c66affSColin Finck Slicer::slice_old( Arc_ptr loop )
1213*c2c66affSColin Finck {
1214*c2c66affSColin Finck loop->markverts();
1215*c2c66affSColin Finck
1216*c2c66affSColin Finck Arc_ptr extrema[4];
1217*c2c66affSColin Finck loop->getextrema( extrema );
1218*c2c66affSColin Finck
1219*c2c66affSColin Finck unsigned int npts = loop->numpts();
1220*c2c66affSColin Finck TrimRegion::init( npts, extrema[0] );
1221*c2c66affSColin Finck
1222*c2c66affSColin Finck Mesher::init( npts );
1223*c2c66affSColin Finck
1224*c2c66affSColin Finck long ulines = uarray.init( du, extrema[1], extrema[3] );
1225*c2c66affSColin Finck //printf("ulines = %i\n", ulines);
1226*c2c66affSColin Finck Varray varray;
1227*c2c66affSColin Finck long vlines = varray.init( dv, extrema[0], extrema[2] );
1228*c2c66affSColin Finck //printf("vlines = %i\n", vlines);
1229*c2c66affSColin Finck long botv = 0;
1230*c2c66affSColin Finck long topv;
1231*c2c66affSColin Finck TrimRegion::init( varray.varray[botv] );
1232*c2c66affSColin Finck getGridExtent( &extrema[0]->pwlArc->pts[0], &extrema[0]->pwlArc->pts[0] );
1233*c2c66affSColin Finck
1234*c2c66affSColin Finck for( long quad=0; quad<varray.numquads; quad++ ) {
1235*c2c66affSColin Finck backend.surfgrid( uarray.uarray[0],
1236*c2c66affSColin Finck uarray.uarray[ulines-1],
1237*c2c66affSColin Finck ulines-1,
1238*c2c66affSColin Finck varray.vval[quad],
1239*c2c66affSColin Finck varray.vval[quad+1],
1240*c2c66affSColin Finck varray.voffset[quad+1] - varray.voffset[quad] );
1241*c2c66affSColin Finck
1242*c2c66affSColin Finck for( long i=varray.voffset[quad]+1; i <= varray.voffset[quad+1]; i++ ) {
1243*c2c66affSColin Finck topv = botv++;
1244*c2c66affSColin Finck advance( topv - varray.voffset[quad],
1245*c2c66affSColin Finck botv - varray.voffset[quad],
1246*c2c66affSColin Finck varray.varray[botv] );
1247*c2c66affSColin Finck if( i == vlines )
1248*c2c66affSColin Finck getPts( extrema[2] );
1249*c2c66affSColin Finck else
1250*c2c66affSColin Finck getPts( backend );
1251*c2c66affSColin Finck getGridExtent();
1252*c2c66affSColin Finck if( isolines ) {
1253*c2c66affSColin Finck outline();
1254*c2c66affSColin Finck } else {
1255*c2c66affSColin Finck if( canTile() )
1256*c2c66affSColin Finck coveAndTile();
1257*c2c66affSColin Finck else
1258*c2c66affSColin Finck mesh();
1259*c2c66affSColin Finck }
1260*c2c66affSColin Finck }
1261*c2c66affSColin Finck }
1262*c2c66affSColin Finck }
1263*c2c66affSColin Finck
1264*c2c66affSColin Finck
1265*c2c66affSColin Finck void
outline(void)1266*c2c66affSColin Finck Slicer::outline( void )
1267*c2c66affSColin Finck {
1268*c2c66affSColin Finck GridTrimVertex upper, lower;
1269*c2c66affSColin Finck Hull::init( );
1270*c2c66affSColin Finck
1271*c2c66affSColin Finck backend.bgnoutline();
1272*c2c66affSColin Finck while( (nextupper( &upper )) ) {
1273*c2c66affSColin Finck if( upper.isGridVert() )
1274*c2c66affSColin Finck backend.linevert( upper.g );
1275*c2c66affSColin Finck else
1276*c2c66affSColin Finck backend.linevert( upper.t );
1277*c2c66affSColin Finck }
1278*c2c66affSColin Finck backend.endoutline();
1279*c2c66affSColin Finck
1280*c2c66affSColin Finck backend.bgnoutline();
1281*c2c66affSColin Finck while( (nextlower( &lower )) ) {
1282*c2c66affSColin Finck if( lower.isGridVert() )
1283*c2c66affSColin Finck backend.linevert( lower.g );
1284*c2c66affSColin Finck else
1285*c2c66affSColin Finck backend.linevert( lower.t );
1286*c2c66affSColin Finck }
1287*c2c66affSColin Finck backend.endoutline();
1288*c2c66affSColin Finck }
1289*c2c66affSColin Finck
1290*c2c66affSColin Finck
1291*c2c66affSColin Finck void
outline(Arc_ptr jarc)1292*c2c66affSColin Finck Slicer::outline( Arc_ptr jarc )
1293*c2c66affSColin Finck {
1294*c2c66affSColin Finck jarc->markverts();
1295*c2c66affSColin Finck
1296*c2c66affSColin Finck if( jarc->pwlArc->npts >= 2 ) {
1297*c2c66affSColin Finck backend.bgnoutline();
1298*c2c66affSColin Finck for( int j = jarc->pwlArc->npts-1; j >= 0; j-- )
1299*c2c66affSColin Finck backend.linevert( &(jarc->pwlArc->pts[j]) );
1300*c2c66affSColin Finck backend.endoutline();
1301*c2c66affSColin Finck }
1302*c2c66affSColin Finck }
1303*c2c66affSColin Finck
1304*c2c66affSColin Finck
1305