Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > DoxygengridWrap.cc
Go to the documentation of this file.
00001 /* 00002 ** License Applicability. Except to the extent portions of this file are 00003 ** made subject to an alternative license as permitted in the SGI Free 00004 ** Software License B, Version 1.1 (the "License"), the contents of this 00005 ** file are subject only to the provisions of the License. You may not use 00006 ** this file except in compliance with the License. You may obtain a copy 00007 ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 00008 ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: 00009 ** 00010 ** http://oss.sgi.com/projects/FreeB 00011 ** 00012 ** Note that, as provided in the License, the Software is distributed on an 00013 ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS 00014 ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND 00015 ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A 00016 ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. 00017 ** 00018 ** Original Code. The Original Code is: OpenGL Sample Implementation, 00019 ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, 00020 ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. 00021 ** Copyright in any portions created by third parties is as indicated 00022 ** elsewhere herein. All Rights Reserved. 00023 ** 00024 ** Additional Notice Provisions: The application programming interfaces 00025 ** established by SGI in conjunction with the Original Code are The 00026 ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released 00027 ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version 00028 ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X 00029 ** Window System(R) (Version 1.3), released October 19, 1998. This software 00030 ** was created using the OpenGL(R) version 1.2.1 Sample Implementation 00031 ** published by SGI, but has not been independently verified as being 00032 ** compliant with the OpenGL(R) version 1.2.1 Specification. 00033 ** 00034 ** $Date: 2006-03-12 00:07:02 +0000 (Sun, 12 Mar 2006) $ $Revision: 1.1 $ 00035 */ 00036 /* 00037 ** $Header: /cygdrive/c/RCVS/CVS/ReactOS/reactos/lib/glu32/libnurbs/nurbtess/gridWrap.cc,v 1.1 2004/02/02 16:39:13 navaraf Exp $ 00038 */ 00039 00040 #include "gluos.h" 00041 #include <stdlib.h> 00042 #include <stdio.h> 00043 #include <GL/gl.h> 00044 #include "zlassert.h" 00045 #include "gridWrap.h" 00046 00047 00048 /*******************grid structure****************************/ 00049 void gridWrap::print() 00050 { 00051 printf("n_ulines = %i\n", n_ulines); 00052 printf("n_vlines = %i\n", n_vlines); 00053 printf("u_min=%f, umax=%f, vmin=%f, vmax=%f\n", u_min, u_max, v_min, v_max); 00054 } 00055 00056 gridWrap::gridWrap(Int nUlines, Real* uvals, 00057 Int nVlines, Real* vvals) 00058 { 00059 assert(nUlines>=2); 00060 assert(nVlines>=2); 00061 00062 is_uniform = 0; 00063 n_ulines = nUlines; 00064 n_vlines = nVlines; 00065 u_min = uvals[0]; 00066 u_max = uvals[nUlines-1]; 00067 v_min = vvals[0]; 00068 v_max = vvals[nVlines-1]; 00069 u_values = (Real*) malloc(sizeof(Real) * n_ulines); 00070 assert(u_values); 00071 v_values = (Real*) malloc(sizeof(Real) * n_vlines); 00072 assert(v_values); 00073 00074 Int i; 00075 for(i=0; i<n_ulines; i++) 00076 u_values[i] = uvals[i]; 00077 for(i=0; i<n_vlines; i++) 00078 v_values[i] = vvals[i]; 00079 } 00080 00081 gridWrap::gridWrap(Int nUlines, Int nVlines, 00082 Real uMin, Real uMax, 00083 Real vMin, Real vMax 00084 ) 00085 { 00086 is_uniform = 1; 00087 n_ulines = nUlines; 00088 n_vlines = nVlines; 00089 u_min = uMin; 00090 u_max = uMax; 00091 v_min = vMin; 00092 v_max = vMax; 00093 u_values = (Real*) malloc(sizeof(Real) * n_ulines); 00094 assert(u_values); 00095 v_values = (Real*) malloc(sizeof(Real) * n_vlines); 00096 assert(v_values); 00097 00098 Int i; 00099 assert(nUlines>=2); 00100 assert(nVlines>=2); 00101 Real du = (uMax-uMin)/(nUlines-1); 00102 Real dv = (vMax-vMin)/(nVlines-1); 00103 00104 float tempu=uMin; 00105 u_values[0] = tempu; 00106 for(i=1; i<nUlines; i++) 00107 { 00108 tempu += du; 00109 u_values[i] = tempu; 00110 } 00111 u_values[nUlines-1] = uMax; 00112 00113 float tempv=vMin; 00114 v_values[0] = tempv; 00115 for(i=1; i<nVlines; i++) 00116 { 00117 tempv += dv; 00118 v_values[i] = tempv; 00119 } 00120 v_values[nVlines-1] = vMax; 00121 } 00122 00123 gridWrap::~gridWrap() 00124 { 00125 free(u_values); 00126 free(v_values); 00127 } 00128 00129 void gridWrap::draw() 00130 { 00131 int i,j; 00132 glBegin(GL_POINTS); 00133 for(i=0; i<n_ulines; i++) 00134 for(j=0; j<n_vlines; j++) 00135 glVertex2f(get_u_value(i), get_v_value(j)); 00136 glEnd(); 00137 } 00138 00139 void gridWrap::outputFanWithPoint(Int v, Int uleft, Int uright, Real vert[2], primStream* pStream) 00140 { 00141 Int i; 00142 if(uleft >= uright) 00143 return; //no triangles to output. 00144 00145 pStream->begin(); 00146 pStream->insert(vert); 00147 00148 assert(vert[1] != v_values[v]); //don't output degenerate triangles 00149 00150 if(vert[1] > v_values[v]) //vertex is above this grid line: notice the orientation 00151 { 00152 for(i=uleft; i<=uright; i++) 00153 pStream->insert(u_values[i], v_values[v]); 00154 } 00155 else //vertex is below the grid line 00156 { 00157 for(i=uright; i>= uleft; i--) 00158 pStream->insert(u_values[i], v_values[v]); 00159 } 00160 00161 pStream->end(PRIMITIVE_STREAM_FAN); 00162 } 00163 00164 00165 00166 /*each chain stores a number of consecutive 00167 *V-lines within a grid. 00168 *There is one grid vertex on each V-line. 00169 * The total number of V-lines is: 00170 * nVlines. 00171 * with respect to the grid, the index of the first V-line is 00172 * firstVlineIndex. 00173 * So with respect to the grid, the index of the ith V-line is 00174 * firstVlineIndex-i. 00175 * the grid-index of the uline at the ith vline (recall that each vline has one grid point) 00176 * is ulineIndices[i]. The u_value is cached in ulineValues[i], that is, 00177 * ulineValues[i] = grid->get_u_value(ulineIndices[i]) 00178 */ 00179 gridBoundaryChain::gridBoundaryChain( 00180 gridWrap* gr, 00181 Int first_vline_index, 00182 Int n_vlines, 00183 Int* uline_indices, 00184 Int* inner_indices 00185 ) 00186 : grid(gr), firstVlineIndex(first_vline_index), nVlines(n_vlines) 00187 { 00188 ulineIndices = (Int*) malloc(sizeof(Int) * n_vlines); 00189 assert(ulineIndices); 00190 00191 innerIndices = (Int*) malloc(sizeof(Int) * n_vlines); 00192 assert(innerIndices); 00193 00194 vertices = (Real2*) malloc(sizeof(Real2) * n_vlines); 00195 assert(vertices); 00196 00197 00198 00199 Int i; 00200 for(i=0; i<n_vlines; i++){ 00201 ulineIndices[i] = uline_indices[i]; 00202 innerIndices[i] = inner_indices[i]; 00203 } 00204 00205 for(i=0; i<n_vlines; i++){ 00206 vertices[i][0] = gr->get_u_value(ulineIndices[i]); 00207 vertices[i][1] = gr->get_v_value(first_vline_index-i); 00208 } 00209 } 00210 00211 void gridBoundaryChain::draw() 00212 { 00213 Int i; 00214 glBegin(GL_LINE_STRIP); 00215 for(i=0; i<nVlines; i++) 00216 { 00217 glVertex2fv(vertices[i]); 00218 } 00219 glEnd(); 00220 } 00221 00222 void gridBoundaryChain::drawInner() 00223 { 00224 Int i; 00225 for(i=1; i<nVlines; i++) 00226 { 00227 glBegin(GL_LINE_STRIP); 00228 glVertex2f(grid->get_u_value(innerIndices[i]), get_v_value(i-1) ); 00229 glVertex2f(grid->get_u_value(innerIndices[i]), get_v_value(i) ); 00230 glEnd(); 00231 } 00232 } 00233 00234 Int gridBoundaryChain::lookfor(Real v, Int i1, Int i2) 00235 { 00236 Int mid; 00237 while(i1 < i2-1) 00238 { 00239 mid = (i1+i2)/2; 00240 if(v > vertices[mid][1]) 00241 { 00242 i2 = mid; 00243 } 00244 else 00245 i1 = mid; 00246 } 00247 return i1; 00248 } 00249 00250 /*output the fan of the right end between grid line i-1 and grid line i*/ 00251 void gridBoundaryChain::rightEndFan(Int i, primStream* pStream) 00252 { 00253 Int j; 00254 if(getUlineIndex(i) > getUlineIndex(i-1)) 00255 { 00256 pStream->begin(); 00257 pStream->insert(get_vertex(i-1)); 00258 for(j=getUlineIndex(i-1); j<= getUlineIndex(i); j++) 00259 pStream->insert(grid->get_u_value(j), get_v_value(i)); 00260 pStream->end(PRIMITIVE_STREAM_FAN); 00261 } 00262 else if(getUlineIndex(i) < getUlineIndex(i-1)) 00263 { 00264 pStream->begin(); 00265 pStream->insert(get_vertex(i)); 00266 for(j=getUlineIndex(i-1); j>= getUlineIndex(i); j--) 00267 pStream->insert(grid->get_u_value(j), get_v_value(i-1)); 00268 pStream->end(PRIMITIVE_STREAM_FAN); 00269 } 00270 //otherside, the two are equal, so there is no fan to output 00271 } 00272 00273 00274 /*output the fan of the left end between grid line i-1 and grid line i*/ 00275 void gridBoundaryChain::leftEndFan(Int i, primStream* pStream) 00276 { 00277 Int j; 00278 if(getUlineIndex(i) < getUlineIndex(i-1)) 00279 { 00280 pStream->begin(); 00281 pStream->insert(get_vertex(i-1)); 00282 for(j=getUlineIndex(i); j<= getUlineIndex(i-1); j++) 00283 pStream->insert(grid->get_u_value(j), get_v_value(i)); 00284 pStream->end(PRIMITIVE_STREAM_FAN); 00285 } 00286 else if(getUlineIndex(i) > getUlineIndex(i-1)) 00287 { 00288 pStream->begin(); 00289 pStream->insert(get_vertex(i)); 00290 for(j=getUlineIndex(i); j>= getUlineIndex(i-1); j--) 00291 pStream->insert(grid->get_u_value(j), get_v_value(i-1)); 00292 pStream->end(PRIMITIVE_STREAM_FAN); 00293 } 00294 /*otherwisem, the two are equal, so there is no fan to outout*/ 00295 } Generated on Sat May 26 2012 04:22:19 for ReactOS by
1.7.6.1
|