Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > DoxygenmonoTriangulationBackend.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/internals/monoTriangulationBackend.cc,v 1.1 2004/02/02 16:39:12 navaraf Exp $ 00038 */ 00039 00040 #include "monoTriangulation.h" 00041 #include "polyUtil.h" 00042 #include "backend.h" 00043 #include "arc.h" 00044 00045 void reflexChain::outputFan(Real v[2], Backend* backend) 00046 { 00047 Int i; 00048 00049 backend->bgntfan(); 00050 backend->tmeshvert(v[0], v[1]); 00051 00052 if(isIncreasing) { 00053 for(i=0; i<index_queue; i++) 00054 { 00055 /* 00056 trimVert.param[0]=queue[i][0]; 00057 trimVert.param[1]=queue[i][1]; 00058 backend->tmeshvert(&trimVert); 00059 */ 00060 backend->tmeshvert(queue[i][0], queue[i][1]); 00061 } 00062 } 00063 else { 00064 for(i=index_queue-1; i>=0; i--) 00065 { 00066 /* 00067 trimVert.param[0]=queue[i][0]; 00068 trimVert.param[1]=queue[i][1]; 00069 backend->tmeshvert(&trimVert); 00070 */ 00071 backend->tmeshvert(queue[i][0], queue[i][1]); 00072 } 00073 } 00074 backend->endtfan(); 00075 } 00076 00077 void reflexChain::processNewVertex(Real v[2], Backend* backend) 00078 { 00079 Int i,j,k; 00080 Int isReflex; 00081 00082 /*if there are at most one vertex in the queue, then simply insert 00083 */ 00084 if(index_queue <=1){ 00085 insert(v); 00086 return; 00087 } 00088 00089 /*there are at least two vertices in the queue*/ 00090 j=index_queue-1; 00091 00092 for(i=j; i>=1; i--) { 00093 if(isIncreasing) { 00094 isReflex = (area(queue[i-1], queue[i], v) <= 0.0); 00095 } 00096 else /*decreasing*/{ 00097 isReflex = (area(v, queue[i], queue[i-1]) <= 0.0); 00098 } 00099 if(isReflex) { 00100 break; 00101 } 00102 } 00103 00104 /* 00105 *if i<j then vertices: i+1--j are convex 00106 * output triangle fan: 00107 * v, and queue[i], i+1, ..., j 00108 */ 00109 if(i<j) 00110 { 00111 backend->bgntfan(); 00112 /* 00113 trimVert.param[0]=v[0]; 00114 trimVert.param[1]=v[1]; 00115 backend->tmeshvert(& trimVert); 00116 */ 00117 backend->tmeshvert(v[0], v[1]); 00118 00119 if(isIncreasing) { 00120 for(k=i; k<=j; k++) 00121 { 00122 /* 00123 trimVert.param[0]=queue[k][0]; 00124 trimVert.param[1]=queue[k][1]; 00125 backend->tmeshvert(& trimVert); 00126 */ 00127 backend->tmeshvert(queue[k][0], queue[k][1]); 00128 } 00129 } 00130 else { 00131 for(k=j; k>=i; k--) 00132 { 00133 /* 00134 trimVert.param[0]=queue[k][0]; 00135 trimVert.param[1]=queue[k][1]; 00136 backend->tmeshvert(& trimVert); 00137 */ 00138 backend->tmeshvert(queue[k][0], queue[k][1]); 00139 } 00140 } 00141 00142 backend->endtfan(); 00143 } 00144 00145 /*delete vertices i+1--j from the queue*/ 00146 index_queue = i+1; 00147 /*finally insert v at the end of the queue*/ 00148 insert(v); 00149 00150 } 00151 00152 00153 void monoTriangulationRec(Real* topVertex, Real* botVertex, 00154 vertexArray* inc_chain, Int inc_current, 00155 vertexArray* dec_chain, Int dec_current, 00156 Backend* backend) 00157 { 00158 assert( inc_chain != NULL && dec_chain != NULL); 00159 assert( ! (inc_current>=inc_chain->getNumElements() && 00160 dec_current>=dec_chain->getNumElements())); 00161 Int inc_nVertices; 00162 Int dec_nVertices; 00163 Real** inc_array ; 00164 Real** dec_array ; 00165 Int i; 00166 assert( ! ( (inc_chain==NULL) && (dec_chain==NULL))); 00167 00168 if(inc_current>=inc_chain->getNumElements()) /*no more vertices on inc_chain*/ 00169 { 00170 00171 dec_array = dec_chain->getArray(); 00172 dec_nVertices = dec_chain->getNumElements(); 00173 reflexChain rChain(20,0); 00174 /*put the top vertex into the reflex chain*/ 00175 rChain.processNewVertex(topVertex, backend); 00176 /*process all the vertices on the dec_chain*/ 00177 for(i=dec_current; i<dec_nVertices; i++){ 00178 rChain.processNewVertex(dec_array[i], backend); 00179 } 00180 /*process the bottom vertex*/ 00181 rChain.processNewVertex(botVertex, backend); 00182 00183 } 00184 else if(dec_current>= dec_chain->getNumElements()) /*no more vertices on dec_chain*/ 00185 { 00186 inc_array = inc_chain->getArray(); 00187 inc_nVertices= inc_chain->getNumElements(); 00188 reflexChain rChain(20,1); 00189 /*put the top vertex into the reflex chain*/ 00190 rChain.processNewVertex(topVertex, backend); 00191 /*process all the vertices on the inc_chain*/ 00192 for(i=inc_current; i<inc_nVertices; i++){ 00193 rChain.processNewVertex(inc_array[i], backend); 00194 } 00195 /*process the bottom vertex*/ 00196 rChain.processNewVertex(botVertex, backend); 00197 } 00198 else /*neither chain is empty*/ 00199 { 00200 inc_array = inc_chain -> getArray(); 00201 dec_array = dec_chain -> getArray(); 00202 inc_nVertices= inc_chain->getNumElements(); 00203 dec_nVertices= dec_chain->getNumElements(); 00204 /*if top of inc_chain is 'lower' than top of dec_chain, process all the 00205 *vertices on the dec_chain which are higher than top of inc_chain 00206 */ 00207 if(compV2InY(inc_array[inc_current], dec_array[dec_current]) <= 0) 00208 { 00209 00210 reflexChain rChain(20, 0); 00211 rChain.processNewVertex(topVertex, backend); 00212 for(i=dec_current; i<dec_nVertices; i++) 00213 { 00214 if(compV2InY(inc_array[inc_current], dec_array[i]) <= 0) 00215 rChain.processNewVertex(dec_array[i], backend); 00216 else 00217 break; 00218 } 00219 rChain.outputFan(inc_array[inc_current], backend); 00220 monoTriangulationRec(dec_array[i-1], botVertex, 00221 inc_chain, inc_current, 00222 dec_chain, i, 00223 backend); 00224 } 00225 else /*compV2InY(inc_array[inc_current], dec_array[dec_current]) > 0*/ 00226 { 00227 00228 reflexChain rChain(20, 1); 00229 rChain.processNewVertex(topVertex, backend); 00230 for(i=inc_current; i<inc_nVertices; i++) 00231 { 00232 if(compV2InY(inc_array[i], dec_array[dec_current]) >0) 00233 rChain.processNewVertex(inc_array[i], backend); 00234 else 00235 break; 00236 } 00237 rChain.outputFan(dec_array[dec_current], backend); 00238 monoTriangulationRec(inc_array[i-1], botVertex, 00239 inc_chain, i, 00240 dec_chain, dec_current, 00241 backend); 00242 } 00243 }/*end case neither is empty*/ 00244 } 00245 00246 00247 void monoTriangulationFunBackend(Arc_ptr loop, Int (*compFun)(Real*, Real*), Backend* backend) 00248 { 00249 Int i; 00250 /*find the top vertex, bottom vertex, inccreasing chain, and decreasing chain, 00251 *then call monoTriangulationRec 00252 */ 00253 Arc_ptr tempV; 00254 Arc_ptr topV; 00255 Arc_ptr botV; 00256 topV = botV = loop; 00257 for(tempV = loop->next; tempV != loop; tempV = tempV->next) 00258 { 00259 if(compFun(topV->tail(), tempV->tail())<0) { 00260 topV = tempV; 00261 } 00262 if(compFun(botV->tail(), tempV->tail())>0) { 00263 botV = tempV; 00264 } 00265 } 00266 00267 /*creat increase and decrease chains*/ 00268 vertexArray inc_chain(20); /*this is a dynamic array*/ 00269 for(i=1; i<=topV->pwlArc->npts-2; i++) { /*the first vertex is the top vertex which doesn't belong to inc_chain*/ 00270 inc_chain.appendVertex(topV->pwlArc->pts[i].param); 00271 } 00272 for(tempV = topV->next; tempV != botV; tempV = tempV->next) 00273 { 00274 for(i=0; i<=tempV->pwlArc->npts-2; i++){ 00275 inc_chain.appendVertex(tempV->pwlArc->pts[i].param); 00276 } 00277 } 00278 00279 vertexArray dec_chain(20); 00280 for(tempV = topV->prev; tempV != botV; tempV = tempV->prev) 00281 { 00282 for(i=tempV->pwlArc->npts-2; i>=0; i--){ 00283 dec_chain.appendVertex(tempV->pwlArc->pts[i].param); 00284 } 00285 } 00286 for(i=botV->pwlArc->npts-2; i>=1; i--){ 00287 dec_chain.appendVertex(tempV->pwlArc->pts[i].param); 00288 } 00289 00290 monoTriangulationRecFunBackend(topV->tail(), botV->tail(), &inc_chain, 0, &dec_chain, 0, compFun, backend); 00291 00292 } 00293 00294 /*if compFun == compV2InY, top to bottom: V-monotone 00295 *if compFun == compV2InX, right to left: U-monotone 00296 */ 00297 void monoTriangulationRecFunBackend(Real* topVertex, Real* botVertex, 00298 vertexArray* inc_chain, Int inc_current, 00299 vertexArray* dec_chain, Int dec_current, 00300 Int (*compFun)(Real*, Real*), 00301 Backend* backend) 00302 { 00303 assert( inc_chain != NULL && dec_chain != NULL); 00304 assert( ! (inc_current>=inc_chain->getNumElements() && 00305 dec_current>=dec_chain->getNumElements())); 00306 Int inc_nVertices; 00307 Int dec_nVertices; 00308 Real** inc_array ; 00309 Real** dec_array ; 00310 Int i; 00311 assert( ! ( (inc_chain==NULL) && (dec_chain==NULL))); 00312 00313 if(inc_current>=inc_chain->getNumElements()) /*no more vertices on inc_chain*/ 00314 { 00315 00316 dec_array = dec_chain->getArray(); 00317 dec_nVertices = dec_chain->getNumElements(); 00318 reflexChain rChain(20,0); 00319 /*put the top vertex into the reflex chain*/ 00320 rChain.processNewVertex(topVertex, backend); 00321 /*process all the vertices on the dec_chain*/ 00322 for(i=dec_current; i<dec_nVertices; i++){ 00323 rChain.processNewVertex(dec_array[i], backend); 00324 } 00325 /*process the bottom vertex*/ 00326 rChain.processNewVertex(botVertex, backend); 00327 00328 } 00329 else if(dec_current>= dec_chain->getNumElements()) /*no more vertices on dec_chain*/ 00330 { 00331 inc_array = inc_chain->getArray(); 00332 inc_nVertices= inc_chain->getNumElements(); 00333 reflexChain rChain(20,1); 00334 /*put the top vertex into the reflex chain*/ 00335 rChain.processNewVertex(topVertex, backend); 00336 /*process all the vertices on the inc_chain*/ 00337 for(i=inc_current; i<inc_nVertices; i++){ 00338 rChain.processNewVertex(inc_array[i], backend); 00339 } 00340 /*process the bottom vertex*/ 00341 rChain.processNewVertex(botVertex, backend); 00342 } 00343 else /*neither chain is empty*/ 00344 { 00345 inc_array = inc_chain -> getArray(); 00346 dec_array = dec_chain -> getArray(); 00347 inc_nVertices= inc_chain->getNumElements(); 00348 dec_nVertices= dec_chain->getNumElements(); 00349 /*if top of inc_chain is 'lower' than top of dec_chain, process all the 00350 *vertices on the dec_chain which are higher than top of inc_chain 00351 */ 00352 if(compFun(inc_array[inc_current], dec_array[dec_current]) <= 0) 00353 { 00354 00355 reflexChain rChain(20, 0); 00356 rChain.processNewVertex(topVertex, backend); 00357 for(i=dec_current; i<dec_nVertices; i++) 00358 { 00359 if(compFun(inc_array[inc_current], dec_array[i]) <= 0) 00360 rChain.processNewVertex(dec_array[i], backend); 00361 else 00362 break; 00363 } 00364 rChain.outputFan(inc_array[inc_current], backend); 00365 monoTriangulationRecFunBackend(dec_array[i-1], botVertex, 00366 inc_chain, inc_current, 00367 dec_chain, i, 00368 compFun, 00369 backend); 00370 } 00371 else /*compFun(inc_array[inc_current], dec_array[dec_current]) > 0*/ 00372 { 00373 00374 reflexChain rChain(20, 1); 00375 rChain.processNewVertex(topVertex, backend); 00376 for(i=inc_current; i<inc_nVertices; i++) 00377 { 00378 if(compFun(inc_array[i], dec_array[dec_current]) >0) 00379 rChain.processNewVertex(inc_array[i], backend); 00380 else 00381 break; 00382 } 00383 rChain.outputFan(dec_array[dec_current], backend); 00384 monoTriangulationRecFunBackend(inc_array[i-1], botVertex, 00385 inc_chain, i, 00386 dec_chain, dec_current, 00387 compFun, 00388 backend); 00389 } 00390 }/*end case neither is empty*/ 00391 } Generated on Sun May 27 2012 04:23:40 for ReactOS by
1.7.6.1
|