2 ** License Applicability. Except to the extent portions of this file are
3 ** made subject to an alternative license as permitted in the SGI Free
4 ** Software License B, Version 1.1 (the "License"), the contents of this
5 ** file are subject only to the provisions of the License. You may not use
6 ** this file except in compliance with the License. You may obtain a copy
7 ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
8 ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
10 ** http://oss.sgi.com/projects/FreeB
12 ** Note that, as provided in the License, the Software is distributed on an
13 ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
14 ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
15 ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
16 ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
18 ** Original Code. The Original Code is: OpenGL Sample Implementation,
19 ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
20 ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
21 ** Copyright in any portions created by third parties is as indicated
22 ** elsewhere herein. All Rights Reserved.
24 ** Additional Notice Provisions: The application programming interfaces
25 ** established by SGI in conjunction with the Original Code are The
26 ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
27 ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
28 ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
29 ** Window System(R) (Version 1.3), released October 19, 1998. This software
30 ** was created using the OpenGL(R) version 1.2.1 Sample Implementation
31 ** published by SGI, but has not been independently verified as being
32 ** compliant with the OpenGL(R) version 1.2.1 Specification.
38 * $Date$ $Revision: 1.1 $
39 * $Header: /cygdrive/c/RCVS/CVS/ReactOS/reactos/lib/glu32/libnurbs/internals/slicer.cc,v 1.1 2004/02/02 16:39:12 navaraf Exp $
45 #include "glimports.h"
52 #include "gridtrimvertex.h"
53 #include "simplemath.h"
54 #include "trimvertex.h"
57 #include "polyUtil.h" //for area()
61 /*USE_OPTTT is initiated in trimvertex.h*/
67 //#define USE_READ_FLAG //whether to use new or old tesselator
68 //if defined, it reads "flagFile",
69 // if the number is 1, then use new tess
70 // otherwise, use the old tess.
71 //if not defined, then use new tess.
73 static Int
read_flag(char* name
);
74 Int newtess_flag
= read_flag("flagFile");
77 //#define COUNT_TRIANGLES
78 #ifdef COUNT_TRIANGLES
79 Int num_triangles
= 0;
83 #define max(a,b) ((a>b)? a:b)
84 #define ZERO 0.00001 /*determing whether a loop is a rectngle or not*/
85 #define equalRect(a,b) ((glu_abs(a-b) <= ZERO)? 1:0) //only used in tessellating a rectangle
87 /******triangulate a monotone polygon**************/
88 #include "monoTriangulation.h"
90 inline int compInY(REAL a
[2], REAL b
[2])
101 void monoTriangulationLoop(Arc_ptr loop
, Backend
& backend
, primStream
* pStream
)
104 //find the top, bottom, increasing and decreasing chain
105 //then call monoTrianulation
110 if(compInY(loop
->tail(), loop
->prev
->tail()) < 0)
113 for(temp
= loop
->next
; temp
!= loop
; temp
= temp
->next
)
115 if(compInY(temp
->tail(), temp
->prev
->tail()) > 0)
120 for(temp
=loop
->prev
; temp
!= loop
; temp
= temp
->prev
)
122 if(compInY(temp
->tail(), temp
->prev
->tail()) > 0)
127 else //loop > loop->prev
129 for(temp
=loop
->next
; temp
!= loop
; temp
= temp
->next
)
131 if(compInY(temp
->tail(), temp
->prev
->tail()) < 0)
135 for(temp
=loop
->prev
; temp
!= loop
; temp
= temp
->prev
)
137 if(compInY(temp
->tail(), temp
->prev
->tail()) < 0)
142 //creat increase and decrease chains
143 vertexArray
inc_chain(50); //this is a dynamci array
144 for(i
=1; i
<=top
->pwlArc
->npts
-2; i
++)
146 //the first vertex is the top which doesn't below to inc_chain
147 inc_chain
.appendVertex(top
->pwlArc
->pts
[i
].param
);
149 for(jarc
=top
->next
; jarc
!= bot
; jarc
= jarc
->next
)
151 for(i
=0; i
<=jarc
->pwlArc
->npts
-2; i
++)
153 inc_chain
.appendVertex(jarc
->pwlArc
->pts
[i
].param
);
157 vertexArray
dec_chain(50);
158 for(jarc
= top
->prev
; jarc
!= bot
; jarc
= jarc
->prev
)
160 for(i
=jarc
->pwlArc
->npts
-2; i
>=0; i
--)
162 dec_chain
.appendVertex(jarc
->pwlArc
->pts
[i
].param
);
165 for(i
=bot
->pwlArc
->npts
-2; i
>=1; i
--)
167 dec_chain
.appendVertex(jarc
->pwlArc
->pts
[i
].param
);
170 monoTriangulationRec(top
->tail(), bot
->tail(), &inc_chain
, 0,
171 &dec_chain
, 0, &backend
);
175 /********tesselate a rectanlge (OPTIMIZATION**************/
176 static void triangulateRectGen(Arc_ptr loop
, int n_ulines
, int n_vlines
, Backend
& backend
);
178 static Int
is_rect(Arc_ptr loop
)
181 for(Arc_ptr jarc
= loop
->next
; jarc
!= loop
; jarc
= jarc
->next
)
193 printf("loop->tail=(%f,%f)\n", loop->tail()[0], loop->tail()[1]);
194 printf("loop->head=(%f,%f)\n", loop->head()[0], loop->head()[1]);
195 printf("loop->next->tail=(%f,%f)\n", loop->next->tail()[0], loop->next->tail()[1]);
196 printf("loop->next->head=(%f,%f)\n", loop->next->head()[0], loop->next->head()[1]);
197 if(fglu_abs(loop->tail()[0] - loop->head()[0])<0.000001)
199 if(loop->next->tail()[1] == loop->next->head()[1])
203 if( (glu_abs(loop
->tail()[0] - loop
->head()[0])<=ZERO
) &&
204 (glu_abs(loop
->next
->tail()[1] - loop
->next
->head()[1])<=ZERO
) &&
205 (glu_abs(loop
->prev
->tail()[1] - loop
->prev
->head()[1])<=ZERO
) &&
206 (glu_abs(loop
->prev
->prev
->tail()[0] - loop
->prev
->prev
->head()[0])<=ZERO
)
210 ( (glu_abs(loop
->tail()[1] - loop
->head()[1]) <= ZERO
) &&
211 (glu_abs(loop
->next
->tail()[0] - loop
->next
->head()[0]) <= ZERO
) &&
212 (glu_abs(loop
->prev
->tail()[0] - loop
->prev
->head()[0]) <= ZERO
) &&
213 (glu_abs(loop
->prev
->prev
->tail()[1] - loop
->prev
->prev
->head()[1]) <= ZERO
)
220 inline void OPT_OUTVERT(TrimVertex
& vv
, Backend
& backend
)
224 glNormal3fv(vv
.cache_normal
);
225 glVertex3fv(vv
.cache_point
);
228 backend
.tmeshvert(&vv
);
234 static void triangulateRectAux(PwlArc
* top
, PwlArc
* bot
, PwlArc
* left
, PwlArc
* right
, Backend
& backend
);
236 static void triangulateRect(Arc_ptr loop
, Backend
& backend
, int TB_or_LR
, int ulinear
, int vlinear
)
238 //we know the loop is a rectangle, but not sure which is top
239 Arc_ptr top
, bot
, left
, right
;
240 if(loop
->tail()[1] == loop
->head()[1])
242 if(loop
->tail()[1] > loop
->prev
->prev
->tail()[1])
249 top
= loop
->prev
->prev
;
254 if(loop
->tail()[0] > loop
->prev
->prev
->tail()[0])
256 //loop is the right arc
270 //if u, v are both nonlinear, then if the
271 //boundary is tessellated dense, we also
272 //sample the inside to get a better tesslletant.
273 if( (!ulinear
) && (!vlinear
))
275 int nu
= top
->pwlArc
->npts
;
276 if(nu
< bot
->pwlArc
->npts
)
277 nu
= bot
->pwlArc
->npts
;
278 int nv
= left
->pwlArc
->npts
;
279 if(nv
< right
->pwlArc
->npts
)
280 nv
= right
->pwlArc
->npts
;
284 triangulateRectGen(top, nu-2, nv-2, backend);
291 triangulateRectAux(top
->pwlArc
, bot
->pwlArc
, left
->pwlArc
, right
->pwlArc
, backend
);
292 else if(TB_or_LR
== -1)
293 triangulateRectAux(left
->pwlArc
, right
->pwlArc
, bot
->pwlArc
, top
->pwlArc
, backend
);
296 Int maxPointsTB
= top
->pwlArc
->npts
+ bot
->pwlArc
->npts
;
297 Int maxPointsLR
= left
->pwlArc
->npts
+ right
->pwlArc
->npts
;
299 if(maxPointsTB
< maxPointsLR
)
300 triangulateRectAux(left
->pwlArc
, right
->pwlArc
, bot
->pwlArc
, top
->pwlArc
, backend
);
302 triangulateRectAux(top
->pwlArc
, bot
->pwlArc
, left
->pwlArc
, right
->pwlArc
, backend
);
306 static void triangulateRectAux(PwlArc
* top
, PwlArc
* bot
, PwlArc
* left
, PwlArc
* right
, Backend
& backend
)
307 { //if(maxPointsTB >= maxPointsLR)
310 Int d
, topd_left
, topd_right
, botd_left
, botd_right
, i
,j
;
314 evalLineNOGE(top
->pts
, top
->npts
, backend
);
315 evalLineNOGE(bot
->pts
, bot
->npts
, backend
);
316 evalLineNOGE(left
->pts
, left
->npts
, backend
);
317 evalLineNOGE(right
->pts
, right
->npts
, backend
);
322 OPT_OUTVERT(top
->pts
[0], backend
);//the root
323 for(i
=0; i
<left
->npts
; i
++){
324 OPT_OUTVERT(left
->pts
[i
], backend
);
326 for(i
=1; i
<= bot
->npts
-2; i
++){
327 OPT_OUTVERT(bot
->pts
[i
], backend
);
332 OPT_OUTVERT(bot
->pts
[bot
->npts
-2], backend
);
333 for(i
=0; i
<right
->npts
; i
++){
334 OPT_OUTVERT(right
->pts
[i
], backend
);
338 else if(bot
->npts
== 2) {
340 OPT_OUTVERT(bot
->pts
[0], backend
);//the root
341 for(i
=0; i
<right
->npts
; i
++){
342 OPT_OUTVERT(right
->pts
[i
], backend
);
344 for(i
=1; i
<= top
->npts
-2; i
++){
345 OPT_OUTVERT(top
->pts
[i
], backend
);
350 OPT_OUTVERT(top
->pts
[top
->npts
-2], backend
);
351 for(i
=0; i
<left
->npts
; i
++){
352 OPT_OUTVERT(left
->pts
[i
], backend
);
356 else { //both top and bot have >=3 points
360 OPT_OUTVERT(top
->pts
[top
->npts
-2], backend
);
364 OPT_OUTVERT(left
->pts
[i
], backend
);
370 OPT_OUTVERT(bot
->pts
[1], backend
);
372 OPT_OUTVERT(top
->pts
[top
->npts
-2], backend
);
374 for(i
=d
; i
< left
->npts
; i
++)
376 OPT_OUTVERT(left
->pts
[i
], backend
);
381 //output only when d<right->npts-1 and
386 // backend.tmeshvert(& top->pts[1]);
387 OPT_OUTVERT(top
->pts
[1], backend
);
388 for(i
=d
; i
< right
->npts
; i
++)
390 // backend.tmeshvert(& right->pts[i]);
392 OPT_OUTVERT(right
->pts
[i
], backend
);
399 // backend.tmeshvert(& bot->pts[bot->npts-2]);
400 OPT_OUTVERT( bot
->pts
[bot
->npts
-2], backend
);
403 // backend.tmeshvert(& right->pts[i]);
404 OPT_OUTVERT(right
->pts
[i
], backend
);
408 // backend.tmeshvert(& top->pts[1]);
409 OPT_OUTVERT(top
->pts
[1], backend
);
414 topd_left
= top
->npts
-2;
415 topd_right
= 1; //topd_left>= topd_right
418 botd_right
= bot
->npts
-2; //botd_left<= bot_dright
421 if(top
->npts
< bot
->npts
)
423 int delta
=bot
->npts
- top
->npts
;
426 botd_right
= bot
->npts
-2-( delta
-u
);
431 // backend.tmeshvert(& top->pts[top->npts-2]);
432 OPT_OUTVERT(top
->pts
[top
->npts
-2], backend
);
433 for(i
=1; i
<= botd_left
; i
++)
435 // backend.tmeshvert(& bot->pts[i]);
436 OPT_OUTVERT(bot
->pts
[i
] , backend
);
440 if(botd_right
< bot
->npts
-2)
443 OPT_OUTVERT(top
->pts
[1], backend
);
444 for(i
=botd_right
; i
<= bot
->npts
-2; i
++)
445 OPT_OUTVERT(bot
->pts
[i
], backend
);
449 else if(top
->npts
> bot
->npts
)
451 int delta
=top
->npts
-bot
->npts
;
453 topd_left
= top
->npts
-2 - u
;
454 topd_right
= 1+delta
-u
;
456 if(topd_left
< top
->npts
-2)
459 // backend.tmeshvert(& bot->pts[1]);
460 OPT_OUTVERT(bot
->pts
[1], backend
);
461 for(i
=topd_left
; i
<= top
->npts
-2; i
++)
463 // backend.tmeshvert(& top->pts[i]);
464 OPT_OUTVERT(top
->pts
[i
], backend
);
471 OPT_OUTVERT(bot
->pts
[bot
->npts
-2], backend
);
472 for(i
=1; i
<= topd_right
; i
++)
473 OPT_OUTVERT(top
->pts
[i
], backend
);
478 if(topd_left
<= topd_right
)
482 for(j
=botd_left
, i
=topd_left
; i
>=topd_right
; i
--,j
++)
484 // backend.tmeshvert(& top->pts[i]);
485 // backend.tmeshvert(& bot->pts[j]);
486 OPT_OUTVERT(top
->pts
[i
], backend
);
487 OPT_OUTVERT(bot
->pts
[j
], backend
);
496 static void triangulateRectCenter(int n_ulines
, REAL
* u_val
,
497 int n_vlines
, REAL
* v_val
,
501 // XXX this code was patched by Diego Santa Cruz <Diego.SantaCruz@epfl.ch>
502 // to fix a problem in which glMapGrid2f() was called with bad parameters.
503 // This has beens submitted to SGI but not integrated as of May 1, 2001.
504 if(n_ulines
>1 && n_vlines
>1) {
505 backend
.surfgrid(u_val
[0], u_val
[n_ulines
-1], n_ulines
-1,
506 v_val
[n_vlines
-1], v_val
[0], n_vlines
-1);
507 backend
.surfmesh(0,0,n_ulines
-1,n_vlines
-1);
513 for(i=0; i<n_vlines-1; i++)
517 for(j=0; j<n_ulines; j++)
519 trimVert.param[0] = u_val[j];
520 trimVert.param[1] = v_val[i+1];
521 backend.tmeshvert(& trimVert);
523 trimVert.param[1] = v_val[i];
524 backend.tmeshvert(& trimVert);
532 //it works for top, bot, left ad right, you need ot select correct arguments
533 static void triangulateRectTopGen(Arc_ptr arc
, int n_ulines
, REAL
* u_val
, Real v
, int dir
, int is_u
, Backend
& backend
)
539 REAL
* upper_val
= (REAL
*) malloc(sizeof(REAL
) * arc
->pwlArc
->npts
);
543 for(k
=0,i
=arc
->pwlArc
->npts
-1; i
>=0; i
--,k
++)
545 upper_val
[k
] = arc
->pwlArc
->pts
[i
].param
[0];
547 backend
.evalUStrip(arc
->pwlArc
->npts
, arc
->pwlArc
->pts
[0].param
[1],
553 for(k
=0,i
=0; i
<arc
->pwlArc
->npts
; i
++,k
++)
555 upper_val
[k
] = arc
->pwlArc
->pts
[i
].param
[0];
561 arc
->pwlArc
->npts
, arc
->pwlArc
->pts
[0].param
[1], upper_val
571 REAL
* left_val
= (REAL
*) malloc(sizeof(REAL
) * arc
->pwlArc
->npts
);
575 for(k
=0,i
=arc
->pwlArc
->npts
-1; i
>=0; i
--,k
++)
577 left_val
[k
] = arc
->pwlArc
->pts
[i
].param
[1];
579 backend
.evalVStrip(arc
->pwlArc
->npts
, arc
->pwlArc
->pts
[0].param
[0],
585 for(k
=0,i
=0; i
<arc
->pwlArc
->npts
; i
++,k
++)
587 left_val
[k
] = arc
->pwlArc
->pts
[i
].param
[1];
591 arc
->pwlArc
->npts
, arc
->pwlArc
->pts
[0].param
[0], left_val
598 //the following is a different version of the above code. If you comment
599 //the above code, the following code will still work. The reason to leave
600 //the folliwng code here is purely for testing purpose.
603 PwlArc* parc = arc->pwlArc;
604 int d1 = parc->npts-1;
607 trimVert.nuid = 0;//????
608 REAL* temp_u_val = u_val;
609 if(dir ==0) //have to reverse u_val
611 temp_u_val = (REAL*) malloc(sizeof(REAL) * n_ulines);
613 for(i=0; i<n_ulines; i++)
614 temp_u_val[i] = u_val[n_ulines-1-i];
618 if(parc->npts > n_ulines)
624 trimVert.param[0] = u_val[0];
625 trimVert.param[1] = v;
629 trimVert.param[1] = u_val[0];
630 trimVert.param[0] = v;
633 backend.tmeshvert(& trimVert);
634 for(i=d1; i< parc->npts; i++)
635 backend.tmeshvert(& parc->pts[i]);
640 else if(parc->npts < n_ulines)
642 d2 = n_ulines-parc->npts;
646 backend.tmeshvert(& parc->pts[parc->npts-1]);
647 for(i=0; i<= d2; i++)
650 trimVert.param[0] = u_val[i];
651 trimVert.param[1] = v;
655 trimVert.param[1] = u_val[i];
656 trimVert.param[0] = v;
658 backend.tmeshvert(&trimVert);
667 for(i=d1, j=d2; i>=0; i--, j++)
669 backend.tmeshvert(& parc->pts[i]);
672 trimVert.param[0] = u_val[j];
673 trimVert.param[1] = v;
676 trimVert.param[1] = u_val[j];
677 trimVert.param[0] = v;
679 backend.tmeshvert(&trimVert);
688 if(dir == 0) //temp_u_val was mallocated
693 //n_ulines is the number of ulines inside, and n_vlines is the number of vlines
694 //inside, different from meanings elsewhere!!!
695 static void triangulateRectGen(Arc_ptr loop
, int n_ulines
, int n_vlines
, Backend
& backend
)
699 //we know the loop is a rectangle, but not sure which is top
700 Arc_ptr top
, bot
, left
, right
;
702 if(equalRect(loop
->tail()[1] , loop
->head()[1]))
705 if(loop
->tail()[1] > loop
->prev
->prev
->tail()[1])
712 top
= loop
->prev
->prev
;
717 if(loop
->tail()[0] > loop
->prev
->prev
->tail()[0])
719 //loop is the right arc
734 #ifdef COUNT_TRIANGLES
735 num_triangles
+= loop
->pwlArc
->npts
+
739 + 2*n_ulines
+ 2*n_vlines
741 num_quads
+= (n_ulines
-1)*(n_vlines
-1);
744 backend.surfgrid(left->tail()[0], right->tail()[0], n_ulines+1,
745 top->tail()[1], bot->tail()[1], n_vlines+1);
746 // if(n_ulines>1 && n_vlines>1)
747 backend.surfmesh(0,0,n_ulines+1,n_vlines+1);
750 REAL
* u_val
=(REAL
*) malloc(sizeof(REAL
)*n_ulines
);
752 REAL
* v_val
=(REAL
*)malloc(sizeof(REAL
) * n_vlines
);
754 REAL u_stepsize
= (right
->tail()[0] - left
->tail()[0])/( (REAL
) n_ulines
+1);
755 REAL v_stepsize
= (top
->tail()[1] - bot
->tail()[1])/( (REAL
) n_vlines
+1);
756 Real temp
=left
->tail()[0]+u_stepsize
;
757 for(i
=0; i
<n_ulines
; i
++)
762 temp
= bot
->tail()[1] + v_stepsize
;
763 for(i
=0; i
<n_vlines
; i
++)
769 triangulateRectTopGen(top
, n_ulines
, u_val
, v_val
[n_vlines
-1], 1,1, backend
);
770 triangulateRectTopGen(bot
, n_ulines
, u_val
, v_val
[0], 0, 1, backend
);
771 triangulateRectTopGen(left
, n_vlines
, v_val
, u_val
[0], 1, 0, backend
);
772 triangulateRectTopGen(right
, n_vlines
, v_val
, u_val
[n_ulines
-1], 0,0, backend
);
777 //triangulate the center
778 triangulateRectCenter(n_ulines
, u_val
, n_vlines
, v_val
, backend
);
785 /***********nextgen tess****************/
786 #include "sampleMonoPoly.h"
787 directedLine
* arcToDLine(Arc_ptr arc
)
792 sampledLine
* sline
= new sampledLine(arc
->pwlArc
->npts
);
793 for(i
=0; i
<arc
->pwlArc
->npts
; i
++)
795 vert
[0] = arc
->pwlArc
->pts
[i
].param
[0];
796 vert
[1] = arc
->pwlArc
->pts
[i
].param
[1];
797 sline
->setPoint(i
, vert
);
799 ret
= new directedLine(INCREASING
, sline
);
803 /*an pwlArc may not be a straight line*/
804 directedLine
* arcToMultDLines(directedLine
* original
, Arc_ptr arc
)
806 directedLine
* ret
= original
;
808 if(arc
->pwlArc
->npts
== 2 )
810 else if(area(arc
->pwlArc
->pts
[0].param
, arc
->pwlArc
->pts
[1].param
, arc
->pwlArc
->pts
[arc
->pwlArc
->npts
-1].param
) == 0.0)
815 directedLine
*dline
= arcToDLine(arc
);
824 for(Int i
=0; i
<arc
->pwlArc
->npts
-1; i
++)
827 vert
[0][0] = arc
->pwlArc
->pts
[i
].param
[0];
828 vert
[0][1] = arc
->pwlArc
->pts
[i
].param
[1];
829 vert
[1][0] = arc
->pwlArc
->pts
[i
+1].param
[0];
830 vert
[1][1] = arc
->pwlArc
->pts
[i
+1].param
[1];
832 sampledLine
*sline
= new sampledLine(2, vert
);
833 directedLine
*dline
= new directedLine(INCREASING
, sline
);
845 directedLine
* arcLoopToDLineLoop(Arc_ptr loop
)
851 ret
= arcToMultDLines(NULL
, loop
);
852 //ret->printSingle();
853 for(Arc_ptr temp
= loop
->next
; temp
!= loop
; temp
= temp
->next
){
854 ret
= arcToMultDLines(ret
, temp
);
855 //ret->printSingle();
862 void Slicer::evalRBArray(rectBlockArray* rbArray, gridWrap* grid)
864 TrimVertex *trimVert = (TrimVertex*)malloc(sizeof(TrimVertex));
865 trimVert -> nuid = 0;//????
867 Real* u_values = grid->get_u_values();
868 Real* v_values = grid->get_v_values();
872 for(l=0; l<rbArray->get_n_elements(); l++)
874 rectBlock* block = rbArray->get_element(l);
875 for(k=0, i=block->get_upGridLineIndex(); i>block->get_lowGridLineIndex(); i--, k++)
879 for(j=block->get_leftIndices()[k+1]; j<= block->get_rightIndices()[k+1]; j++)
881 trimVert->param[0] = u_values[j];
882 trimVert->param[1] = v_values[i];
883 backend.tmeshvert(trimVert);
885 trimVert->param[1] = v_values[i-1];
886 backend.tmeshvert(trimVert);
898 void Slicer::evalRBArray(rectBlockArray
* rbArray
, gridWrap
* grid
)
902 Int n_vlines
=grid
->get_n_vlines();
903 //the reason to switch the position of v_max and v_min is because of the
904 //the orientation problem. glEvalMesh generates quad_strip clockwise, but
905 //we need counter-clockwise.
906 backend
.surfgrid(grid
->get_u_min(), grid
->get_u_max(), grid
->get_n_ulines()-1,
907 grid
->get_v_max(), grid
->get_v_min(), n_vlines
-1);
910 for(j
=0; j
<rbArray
->get_n_elements(); j
++)
912 rectBlock
* block
= rbArray
->get_element(j
);
913 Int low
= block
->get_lowGridLineIndex();
914 Int high
= block
->get_upGridLineIndex();
916 for(k
=0, i
=high
; i
>low
; i
--, k
++)
918 backend
.surfmesh(block
->get_leftIndices()[k
+1], n_vlines
-1-i
, block
->get_rightIndices()[k
+1]-block
->get_leftIndices()[k
+1], 1);
924 void Slicer::evalStream(primStream
* pStream
)
929 TrimVertex
*trimVert
=/*&X*/ (TrimVertex
*)malloc(sizeof(TrimVertex
));
930 trimVert
-> nuid
= 0;//???
931 Real
* vertices
= pStream
->get_vertices(); //for efficiency
932 for(i
=0; i
<pStream
->get_n_prims(); i
++)
935 //ith primitive has #vertices = lengths[i], type=types[i]
936 switch(pStream
->get_type(i
)){
937 case PRIMITIVE_STREAM_FAN
:
941 for(j
=0; j
<pStream
->get_length(i
); j
++)
943 trimVert
->param
[0] = vertices
[k
];
944 trimVert
->param
[1] = vertices
[k
+1];
945 backend
.tmeshvert(trimVert
);
947 // backend.tmeshvert(vertices[k], vertices[k+1]);
954 fprintf(stderr
, "evalStream: not implemented yet\n");
965 void Slicer::slice_new(Arc_ptr loop
)
968 //if(count == 78) count=1;
969 //printf("count=%i\n", count);
970 //if( ! (4<= count && count <=4)) return;
975 Real uMin
, uMax
, vMin
, vMax
;
977 uMin
= uMax
= loop
->tail()[0];
978 vMin
= vMax
= loop
->tail()[1];
979 mydu
= (du
>0)? du
: -du
;
980 mydv
= (dv
>0)? dv
: -dv
;
982 for(Arc_ptr jarc
=loop
->next
; jarc
!= loop
; jarc
= jarc
->next
)
985 if(jarc
->tail()[0] < uMin
)
986 uMin
= jarc
->tail()[0];
987 if(jarc
->tail()[0] > uMax
)
988 uMax
= jarc
->tail()[0];
989 if(jarc
->tail()[1] < vMin
)
990 vMin
= jarc
->tail()[1];
991 if(jarc
->tail()[1] > vMax
)
992 vMax
= jarc
->tail()[1];
996 return; // prevent divide-by-zero. Jon Perry. 17 June 2002
998 if(mydu
> uMax
- uMin
)
1002 num_ulines
= 3 + (Int
) ((uMax
-uMin
)/mydu
);
1008 num_vlines
= 2+(Int
)((vMax
-vMin
)/mydv
);
1011 Int isRect
= is_rect(loop
);
1013 if(isRect
&& (num_ulines
<=2 || num_vlines
<=2))
1016 triangulateRect(loop
, backend
, 1, ulinear
, vlinear
);
1018 triangulateRect(loop
, backend
, -1, ulinear
, vlinear
);
1020 triangulateRect(loop
, backend
, 0, ulinear
, vlinear
);
1025 triangulateRectGen(loop
, num_ulines
-2, num_vlines
-2, backend
);
1027 else if( (num_ulines
<=2 || num_vlines
<=2) && ulinear
)
1029 monoTriangulationFunBackend(loop
, compV2InY
, &backend
);
1031 else if( (!ulinear
) && (!vlinear
) && (num_ulines
== 2) && (num_vlines
> 2))
1033 monoTriangulationFunBackend(loop
, compV2InY
, &backend
);
1037 directedLine
* poly
= arcLoopToDLineLoop(loop
);
1039 gridWrap
grid(num_ulines
, num_vlines
, uMin
, uMax
, vMin
, vMax
);
1040 primStream
pStream(20, 20);
1041 rectBlockArray
rbArray(20);
1043 sampleMonoPoly(poly
, &grid
, ulinear
, vlinear
, &pStream
, &rbArray
);
1045 evalStream(&pStream
);
1047 evalRBArray(&rbArray
, &grid
);
1049 #ifdef COUNT_TRIANGLES
1050 num_triangles
+= pStream
.num_triangles();
1051 num_quads
+= rbArray
.num_quads();
1053 poly
->deleteSinglePolygonWithSline();
1056 #ifdef COUNT_TRIANGLES
1057 printf("num_triangles=%i\n", num_triangles
);
1058 printf("num_quads = %i\n", num_quads
);
1062 void Slicer::slice(Arc_ptr loop
)
1064 #ifdef USE_READ_FLAG
1065 if(read_flag("flagFile"))
1078 Slicer::Slicer( Backend
&b
)
1079 : CoveAndTiler( b
), Mesher( b
), backend( b
)
1090 Slicer::setisolines( int x
)
1096 Slicer::setstriptessellation( REAL x
, REAL y
)
1098 assert(x
> 0 && y
> 0);
1105 Slicer::slice_old( Arc_ptr loop
)
1110 loop
->getextrema( extrema
);
1112 unsigned int npts
= loop
->numpts();
1113 TrimRegion::init( npts
, extrema
[0] );
1115 Mesher::init( npts
);
1117 long ulines
= uarray
.init( du
, extrema
[1], extrema
[3] );
1118 //printf("ulines = %i\n", ulines);
1120 long vlines
= varray
.init( dv
, extrema
[0], extrema
[2] );
1121 //printf("vlines = %i\n", vlines);
1124 TrimRegion::init( varray
.varray
[botv
] );
1125 getGridExtent( &extrema
[0]->pwlArc
->pts
[0], &extrema
[0]->pwlArc
->pts
[0] );
1127 for( long quad
=0; quad
<varray
.numquads
; quad
++ ) {
1128 backend
.surfgrid( uarray
.uarray
[0],
1129 uarray
.uarray
[ulines
-1],
1132 varray
.vval
[quad
+1],
1133 varray
.voffset
[quad
+1] - varray
.voffset
[quad
] );
1135 for( long i
=varray
.voffset
[quad
]+1; i
<= varray
.voffset
[quad
+1]; i
++ ) {
1137 advance( topv
- varray
.voffset
[quad
],
1138 botv
- varray
.voffset
[quad
],
1139 varray
.varray
[botv
] );
1141 getPts( extrema
[2] );
1159 Slicer::outline( void )
1161 GridTrimVertex upper
, lower
;
1164 backend
.bgnoutline();
1165 while( (nextupper( &upper
)) ) {
1166 if( upper
.isGridVert() )
1167 backend
.linevert( upper
.g
);
1169 backend
.linevert( upper
.t
);
1171 backend
.endoutline();
1173 backend
.bgnoutline();
1174 while( (nextlower( &lower
)) ) {
1175 if( lower
.isGridVert() )
1176 backend
.linevert( lower
.g
);
1178 backend
.linevert( lower
.t
);
1180 backend
.endoutline();
1185 Slicer::outline( Arc_ptr jarc
)
1189 if( jarc
->pwlArc
->npts
>= 2 ) {
1190 backend
.bgnoutline();
1191 for( int j
= jarc
->pwlArc
->npts
-1; j
>= 0; j
-- )
1192 backend
.linevert( &(jarc
->pwlArc
->pts
[j
]) );
1193 backend
.endoutline();