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.
46 /*******************grid structure****************************/
47 void gridWrap::print()
49 printf("n_ulines = %i\n", n_ulines);
50 printf("n_vlines = %i\n", n_vlines);
51 printf("u_min=%f, umax=%f, vmin=%f, vmax=%f\n", u_min, u_max, v_min, v_max);
54 gridWrap::gridWrap(Int nUlines, Real* uvals,
55 Int nVlines, Real* vvals)
64 u_max = uvals[nUlines-1];
66 v_max = vvals[nVlines-1];
67 u_values = (Real*) malloc(sizeof(Real) * n_ulines);
69 v_values = (Real*) malloc(sizeof(Real) * n_vlines);
73 for(i=0; i<n_ulines; i++)
74 u_values[i] = uvals[i];
75 for(i=0; i<n_vlines; i++)
76 v_values[i] = vvals[i];
79 gridWrap::gridWrap(Int nUlines, Int nVlines,
91 u_values = (Real*) malloc(sizeof(Real) * n_ulines);
93 v_values = (Real*) malloc(sizeof(Real) * n_vlines);
99 Real du = (uMax-uMin)/(nUlines-1);
100 Real dv = (vMax-vMin)/(nVlines-1);
104 for(i=1; i<nUlines; i++)
109 u_values[nUlines-1] = uMax;
113 for(i=1; i<nVlines; i++)
118 v_values[nVlines-1] = vMax;
121 gridWrap::~gridWrap()
127 void gridWrap::draw()
131 for(i=0; i<n_ulines; i++)
132 for(j=0; j<n_vlines; j++)
133 glVertex2f(get_u_value(i), get_v_value(j));
137 void gridWrap::outputFanWithPoint(Int v, Int uleft, Int uright, Real vert[2], primStream* pStream)
141 return; //no triangles to output.
144 pStream->insert(vert);
146 assert(vert[1] != v_values[v]); //don't output degenerate triangles
148 if(vert[1] > v_values[v]) //vertex is above this grid line: notice the orientation
150 for(i=uleft; i<=uright; i++)
151 pStream->insert(u_values[i], v_values[v]);
153 else //vertex is below the grid line
155 for(i=uright; i>= uleft; i--)
156 pStream->insert(u_values[i], v_values[v]);
159 pStream->end(PRIMITIVE_STREAM_FAN);
164 /*each chain stores a number of consecutive
165 *V-lines within a grid.
166 *There is one grid vertex on each V-line.
167 * The total number of V-lines is:
169 * with respect to the grid, the index of the first V-line is
171 * So with respect to the grid, the index of the ith V-line is
173 * the grid-index of the uline at the ith vline (recall that each vline has one grid point)
174 * is ulineIndices[i]. The u_value is cached in ulineValues[i], that is,
175 * ulineValues[i] = grid->get_u_value(ulineIndices[i])
177 gridBoundaryChain::gridBoundaryChain(
179 Int first_vline_index,
184 : grid(gr), firstVlineIndex(first_vline_index), nVlines(n_vlines)
186 ulineIndices = (Int*) malloc(sizeof(Int) * n_vlines);
187 assert(ulineIndices);
189 innerIndices = (Int*) malloc(sizeof(Int) * n_vlines);
190 assert(innerIndices);
192 vertices = (Real2*) malloc(sizeof(Real2) * n_vlines);
198 for(i=0; i<n_vlines; i++){
199 ulineIndices[i] = uline_indices[i];
200 innerIndices[i] = inner_indices[i];
203 for(i=0; i<n_vlines; i++){
204 vertices[i][0] = gr->get_u_value(ulineIndices[i]);
205 vertices[i][1] = gr->get_v_value(first_vline_index-i);
209 void gridBoundaryChain::draw()
212 glBegin(GL_LINE_STRIP);
213 for(i=0; i<nVlines; i++)
215 glVertex2fv(vertices[i]);
220 void gridBoundaryChain::drawInner()
223 for(i=1; i<nVlines; i++)
225 glBegin(GL_LINE_STRIP);
226 glVertex2f(grid->get_u_value(innerIndices[i]), get_v_value(i-1) );
227 glVertex2f(grid->get_u_value(innerIndices[i]), get_v_value(i) );
232 Int gridBoundaryChain::lookfor(Real v, Int i1, Int i2)
238 if(v > vertices[mid][1])
248 /*output the fan of the right end between grid line i-1 and grid line i*/
249 void gridBoundaryChain::rightEndFan(Int i, primStream* pStream)
252 if(getUlineIndex(i) > getUlineIndex(i-1))
255 pStream->insert(get_vertex(i-1));
256 for(j=getUlineIndex(i-1); j<= getUlineIndex(i); j++)
257 pStream->insert(grid->get_u_value(j), get_v_value(i));
258 pStream->end(PRIMITIVE_STREAM_FAN);
260 else if(getUlineIndex(i) < getUlineIndex(i-1))
263 pStream->insert(get_vertex(i));
264 for(j=getUlineIndex(i-1); j>= getUlineIndex(i); j--)
265 pStream->insert(grid->get_u_value(j), get_v_value(i-1));
266 pStream->end(PRIMITIVE_STREAM_FAN);
268 //otherside, the two are equal, so there is no fan to output
272 /*output the fan of the left end between grid line i-1 and grid line i*/
273 void gridBoundaryChain::leftEndFan(Int i, primStream* pStream)
276 if(getUlineIndex(i) < getUlineIndex(i-1))
279 pStream->insert(get_vertex(i-1));
280 for(j=getUlineIndex(i); j<= getUlineIndex(i-1); j++)
281 pStream->insert(grid->get_u_value(j), get_v_value(i));
282 pStream->end(PRIMITIVE_STREAM_FAN);
284 else if(getUlineIndex(i) > getUlineIndex(i-1))
287 pStream->insert(get_vertex(i));
288 for(j=getUlineIndex(i); j>= getUlineIndex(i-1); j--)
289 pStream->insert(grid->get_u_value(j), get_v_value(i-1));
290 pStream->end(PRIMITIVE_STREAM_FAN);
292 /*otherwisem, the two are equal, so there is no fan to outout*/