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.
34 ** $Date$ $Revision: 1.1 $
37 ** $Header: /cygdrive/c/RCVS/CVS/ReactOS/reactos/lib/glu32/libnurbs/nurbtess/gridWrap.cc,v 1.1 2004/02/02 16:39:13 navaraf Exp $
48 /*******************grid structure****************************/
49 void gridWrap::print()
51 printf("n_ulines = %i\n", n_ulines
);
52 printf("n_vlines = %i\n", n_vlines
);
53 printf("u_min=%f, umax=%f, vmin=%f, vmax=%f\n", u_min
, u_max
, v_min
, v_max
);
56 gridWrap::gridWrap(Int nUlines
, Real
* uvals
,
57 Int nVlines
, Real
* vvals
)
66 u_max
= uvals
[nUlines
-1];
68 v_max
= vvals
[nVlines
-1];
69 u_values
= (Real
*) malloc(sizeof(Real
) * n_ulines
);
71 v_values
= (Real
*) malloc(sizeof(Real
) * n_vlines
);
75 for(i
=0; i
<n_ulines
; i
++)
76 u_values
[i
] = uvals
[i
];
77 for(i
=0; i
<n_vlines
; i
++)
78 v_values
[i
] = vvals
[i
];
81 gridWrap::gridWrap(Int nUlines
, Int nVlines
,
93 u_values
= (Real
*) malloc(sizeof(Real
) * n_ulines
);
95 v_values
= (Real
*) malloc(sizeof(Real
) * n_vlines
);
101 Real du
= (uMax
-uMin
)/(nUlines
-1);
102 Real dv
= (vMax
-vMin
)/(nVlines
-1);
106 for(i
=1; i
<nUlines
; i
++)
111 u_values
[nUlines
-1] = uMax
;
115 for(i
=1; i
<nVlines
; i
++)
120 v_values
[nVlines
-1] = vMax
;
123 gridWrap::~gridWrap()
129 void gridWrap::draw()
133 for(i
=0; i
<n_ulines
; i
++)
134 for(j
=0; j
<n_vlines
; j
++)
135 glVertex2f(get_u_value(i
), get_v_value(j
));
139 void gridWrap::outputFanWithPoint(Int v
, Int uleft
, Int uright
, Real vert
[2], primStream
* pStream
)
143 return; //no triangles to output.
146 pStream
->insert(vert
);
148 assert(vert
[1] != v_values
[v
]); //don't output degenerate triangles
150 if(vert
[1] > v_values
[v
]) //vertex is above this grid line: notice the orientation
152 for(i
=uleft
; i
<=uright
; i
++)
153 pStream
->insert(u_values
[i
], v_values
[v
]);
155 else //vertex is below the grid line
157 for(i
=uright
; i
>= uleft
; i
--)
158 pStream
->insert(u_values
[i
], v_values
[v
]);
161 pStream
->end(PRIMITIVE_STREAM_FAN
);
166 /*each chain stores a number of consecutive
167 *V-lines within a grid.
168 *There is one grid vertex on each V-line.
169 * The total number of V-lines is:
171 * with respect to the grid, the index of the first V-line is
173 * So with respect to the grid, the index of the ith V-line is
175 * the grid-index of the uline at the ith vline (recall that each vline has one grid point)
176 * is ulineIndices[i]. The u_value is cached in ulineValues[i], that is,
177 * ulineValues[i] = grid->get_u_value(ulineIndices[i])
179 gridBoundaryChain::gridBoundaryChain(
181 Int first_vline_index
,
186 : grid(gr
), firstVlineIndex(first_vline_index
), nVlines(n_vlines
)
188 ulineIndices
= (Int
*) malloc(sizeof(Int
) * n_vlines
);
189 assert(ulineIndices
);
191 innerIndices
= (Int
*) malloc(sizeof(Int
) * n_vlines
);
192 assert(innerIndices
);
194 vertices
= (Real2
*) malloc(sizeof(Real2
) * n_vlines
);
200 for(i
=0; i
<n_vlines
; i
++){
201 ulineIndices
[i
] = uline_indices
[i
];
202 innerIndices
[i
] = inner_indices
[i
];
205 for(i
=0; i
<n_vlines
; i
++){
206 vertices
[i
][0] = gr
->get_u_value(ulineIndices
[i
]);
207 vertices
[i
][1] = gr
->get_v_value(first_vline_index
-i
);
211 void gridBoundaryChain::draw()
214 glBegin(GL_LINE_STRIP
);
215 for(i
=0; i
<nVlines
; i
++)
217 glVertex2fv(vertices
[i
]);
222 void gridBoundaryChain::drawInner()
225 for(i
=1; i
<nVlines
; i
++)
227 glBegin(GL_LINE_STRIP
);
228 glVertex2f(grid
->get_u_value(innerIndices
[i
]), get_v_value(i
-1) );
229 glVertex2f(grid
->get_u_value(innerIndices
[i
]), get_v_value(i
) );
234 Int
gridBoundaryChain::lookfor(Real v
, Int i1
, Int i2
)
240 if(v
> vertices
[mid
][1])
250 /*output the fan of the right end between grid line i-1 and grid line i*/
251 void gridBoundaryChain::rightEndFan(Int i
, primStream
* pStream
)
254 if(getUlineIndex(i
) > getUlineIndex(i
-1))
257 pStream
->insert(get_vertex(i
-1));
258 for(j
=getUlineIndex(i
-1); j
<= getUlineIndex(i
); j
++)
259 pStream
->insert(grid
->get_u_value(j
), get_v_value(i
));
260 pStream
->end(PRIMITIVE_STREAM_FAN
);
262 else if(getUlineIndex(i
) < getUlineIndex(i
-1))
265 pStream
->insert(get_vertex(i
));
266 for(j
=getUlineIndex(i
-1); j
>= getUlineIndex(i
); j
--)
267 pStream
->insert(grid
->get_u_value(j
), get_v_value(i
-1));
268 pStream
->end(PRIMITIVE_STREAM_FAN
);
270 //otherside, the two are equal, so there is no fan to output
274 /*output the fan of the left end between grid line i-1 and grid line i*/
275 void gridBoundaryChain::leftEndFan(Int i
, primStream
* pStream
)
278 if(getUlineIndex(i
) < getUlineIndex(i
-1))
281 pStream
->insert(get_vertex(i
-1));
282 for(j
=getUlineIndex(i
); j
<= getUlineIndex(i
-1); j
++)
283 pStream
->insert(grid
->get_u_value(j
), get_v_value(i
));
284 pStream
->end(PRIMITIVE_STREAM_FAN
);
286 else if(getUlineIndex(i
) > getUlineIndex(i
-1))
289 pStream
->insert(get_vertex(i
));
290 for(j
=getUlineIndex(i
); j
>= getUlineIndex(i
-1); j
--)
291 pStream
->insert(grid
->get_u_value(j
), get_v_value(i
-1));
292 pStream
->end(PRIMITIVE_STREAM_FAN
);
294 /*otherwisem, the two are equal, so there is no fan to outout*/