Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > DoxygensampleCompBot.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/sampleCompBot.cc,v 1.1 2004/02/02 16:39:13 navaraf Exp $ 00038 */ 00039 00040 #include <stdlib.h> 00041 #include <stdio.h> 00042 #include "zlassert.h" 00043 #include "sampleCompBot.h" 00044 #include "sampleCompRight.h" 00045 00046 #define max(a,b) ((a>b)? a:b) 00047 00048 //return: index_mono, index_pass 00049 //from [pass, mono] is strictly U-monotone 00050 //from [corner, pass] is <u 00051 // vertex[pass][0] >= u 00052 //if everybost is <u, then pass = end+1. 00053 //otherwise both mono and pass are meanng full and we have corner<=pass<=mono<=end 00054 void findBotLeftSegment(vertexArray* leftChain, 00055 Int leftEnd, 00056 Int leftCorner, 00057 Real u, 00058 Int& ret_index_mono, 00059 Int& ret_index_pass) 00060 { 00061 Int i; 00062 00063 assert(leftCorner <= leftEnd); 00064 for(i=leftCorner; i<= leftEnd; i++) 00065 if(leftChain->getVertex(i)[0] >= u) 00066 break; 00067 ret_index_pass = i; 00068 if(ret_index_pass <= leftEnd) 00069 { 00070 for(i=ret_index_pass; i< leftEnd; i++) 00071 { 00072 if(leftChain->getVertex(i+1)[0] <= leftChain->getVertex(i)[0]) 00073 break; 00074 } 00075 ret_index_mono = i; 00076 } 00077 00078 } 00079 00080 void findBotRightSegment(vertexArray* rightChain, 00081 Int rightEnd, 00082 Int rightCorner, 00083 Real u, 00084 Int& ret_index_mono, 00085 Int& ret_index_pass) 00086 { 00087 Int i; 00088 assert(rightCorner <= rightEnd); 00089 for(i=rightCorner; i<= rightEnd; i++) 00090 if(rightChain->getVertex(i)[0] <= u) 00091 break; 00092 00093 00094 00095 ret_index_pass = i; 00096 00097 if(ret_index_pass <= rightEnd) 00098 { 00099 for(i=ret_index_pass; i< rightEnd; i++) 00100 { 00101 if(rightChain->getVertex(i+1)[0] >= rightChain->getVertex(i)[0]) 00102 break; 00103 } 00104 ret_index_mono = i; 00105 } 00106 } 00107 00108 00109 void sampleBotRightWithGridLinePost(Real* botVertex, 00110 vertexArray* rightChain, 00111 Int rightEnd, 00112 Int segIndexMono, 00113 Int segIndexPass, 00114 Int rightCorner, 00115 gridWrap* grid, 00116 Int gridV, 00117 Int leftU, 00118 Int rightU, 00119 primStream* pStream) 00120 { 00121 //the possible section which is to the right of rightU 00122 if(segIndexPass > rightCorner) //from corner to pass-1 is > u. 00123 { 00124 Real *tempBot; 00125 if(segIndexPass <= rightEnd) //there is a point to the left of u 00126 tempBot = rightChain->getVertex(segIndexPass); 00127 else //nothing is to the left of u. 00128 tempBot = botVertex; 00129 Real tempTop[2]; 00130 tempTop[0] = grid->get_u_value(rightU); 00131 tempTop[1] = grid->get_v_value(gridV); 00132 00133 monoTriangulation2(tempTop, tempBot, 00134 rightChain, 00135 rightCorner, 00136 segIndexPass-1, 00137 0, // a decrease chain 00138 pStream); 00139 } 00140 00141 //the possible section which is strictly Umonotone 00142 if(segIndexPass <= rightEnd) //segIndex pass and mono exist 00143 { 00144 //if there are grid points which are to the left of botVertex 00145 //then we should use botVertex to form a fan with these points to 00146 //optimize the triangulation 00147 int do_optimize = 1; 00148 if(botVertex[0] <= grid->get_u_value(leftU)) 00149 do_optimize = 0; 00150 else 00151 { 00152 //we also have to make sure that botVertex is the left most vertex on the chain 00153 int i; 00154 for(i=segIndexMono; i<=rightEnd; i++) 00155 if(rightChain->getVertex(i)[0] <= botVertex[0]) 00156 { 00157 do_optimize = 0; 00158 break; 00159 } 00160 } 00161 00162 if(do_optimize) 00163 { 00164 //find midU so that grid->get_u_value(midU) <= botVertex[0] 00165 //and grid->get_u_value(midU) > botVertex[0] 00166 int midU = leftU; 00167 while(grid->get_u_value(midU) <= botVertex[0]) 00168 { 00169 midU++; 00170 if(midU > rightU) 00171 break; 00172 } 00173 midU--; 00174 00175 grid->outputFanWithPoint(gridV, leftU, midU, botVertex, pStream); 00176 stripOfFanRight(rightChain, segIndexMono, segIndexPass, grid, gridV, midU, rightU, pStream, 1); 00177 Real tempTop[2]; 00178 tempTop[0] = grid->get_u_value(midU); 00179 tempTop[1] = grid->get_v_value(gridV); 00180 monoTriangulation2(tempTop, botVertex, rightChain, segIndexMono, rightEnd, 0, pStream); 00181 } 00182 else //not optimize 00183 { 00184 stripOfFanRight(rightChain, segIndexMono, segIndexPass, grid, gridV, leftU, rightU, pStream, 1); 00185 Real tempTop[2]; 00186 tempTop[0] = grid->get_u_value(leftU); 00187 tempTop[1] = grid->get_v_value(gridV); 00188 monoTriangulation2(tempTop, botVertex, rightChain, segIndexMono, rightEnd, 0, pStream); 00189 } 00190 } 00191 else //the botVertex forms a fan witht eh grid points 00192 grid->outputFanWithPoint(gridV, leftU, rightU, botVertex, pStream); 00193 } 00194 00195 void sampleBotRightWithGridLine(Real* botVertex, 00196 vertexArray* rightChain, 00197 Int rightEnd, 00198 Int rightCorner, 00199 gridWrap* grid, 00200 Int gridV, 00201 Int leftU, 00202 Int rightU, 00203 primStream* pStream) 00204 { 00205 //if right chaain is empty, then there is only one bot vertex with 00206 //one grid line 00207 if(rightEnd<rightCorner){ 00208 grid->outputFanWithPoint(gridV, leftU, rightU, botVertex, pStream); 00209 return; 00210 } 00211 00212 Int segIndexMono, segIndexPass; 00213 findBotRightSegment(rightChain, 00214 rightEnd, 00215 rightCorner, 00216 grid->get_u_value(rightU), 00217 segIndexMono, 00218 segIndexPass); 00219 00220 sampleBotRightWithGridLinePost(botVertex, 00221 rightChain, 00222 rightEnd, 00223 segIndexMono, 00224 segIndexPass, 00225 rightCorner, 00226 grid, 00227 gridV, 00228 leftU, 00229 rightU, 00230 pStream); 00231 } 00232 00233 00234 void sampleBotLeftWithGridLinePost(Real* botVertex, 00235 vertexArray* leftChain, 00236 Int leftEnd, 00237 Int segIndexMono, 00238 Int segIndexPass, 00239 Int leftCorner, 00240 gridWrap* grid, 00241 Int gridV, 00242 Int leftU, 00243 Int rightU, 00244 primStream* pStream) 00245 { 00246 00247 //the possible section which is to the left of leftU 00248 if(segIndexPass > leftCorner) //at least leftCorner is to the left of leftU 00249 { 00250 Real *tempBot; 00251 if(segIndexPass <= leftEnd) //from corner to pass-1 is <u 00252 tempBot = leftChain->getVertex(segIndexPass); 00253 else //nothing is to the rigth of u 00254 tempBot = botVertex; 00255 Real tempTop[2]; 00256 tempTop[0] = grid->get_u_value(leftU); 00257 tempTop[1] = grid->get_v_value(gridV); 00258 monoTriangulation2(tempTop, tempBot, leftChain, leftCorner, segIndexPass-1, 00259 1, //a increase chain, 00260 pStream); 00261 } 00262 //the possible section which is strictly Umonotone 00263 if(segIndexPass <= leftEnd) //segIndexpass and mono exist 00264 { 00265 stripOfFanLeft(leftChain, segIndexMono, segIndexPass, grid, gridV, leftU, rightU, pStream, 1); 00266 Real tempTop[2]; 00267 tempTop[0] = grid->get_u_value(rightU); 00268 tempTop[1] = grid->get_v_value(gridV); 00269 00270 monoTriangulation2(tempTop, botVertex, leftChain, segIndexMono, leftEnd, 00271 1, //increase chain 00272 pStream); 00273 } 00274 else //the botVertex forms a fan with the grid points 00275 { 00276 grid->outputFanWithPoint(gridV, leftU, rightU, botVertex, pStream); 00277 } 00278 00279 } 00280 00281 void sampleBotLeftWithGridLine(Real* botVertex, 00282 vertexArray* leftChain, 00283 Int leftEnd, 00284 Int leftCorner, 00285 gridWrap* grid, 00286 Int gridV, 00287 Int leftU, 00288 Int rightU, 00289 primStream* pStream) 00290 { 00291 00292 //if leftChain is empty, then there is only one botVertex with one grid line 00293 if(leftEnd< leftCorner){ 00294 grid->outputFanWithPoint(gridV, leftU, rightU, botVertex, pStream); 00295 return; 00296 } 00297 00298 Int segIndexPass, segIndexMono; 00299 findBotLeftSegment(leftChain, leftEnd, leftCorner, grid->get_u_value(leftU), segIndexMono, segIndexPass); 00300 00301 sampleBotLeftWithGridLinePost(botVertex, 00302 leftChain, 00303 leftEnd, 00304 segIndexMono, 00305 segIndexPass, 00306 leftCorner, 00307 grid, 00308 gridV, 00309 leftU, rightU, pStream); 00310 } 00311 00312 //return 1 if separator exists, 0 otherwise 00313 Int findBotSeparator(vertexArray* leftChain, 00314 Int leftEnd, 00315 Int leftCorner, 00316 vertexArray* rightChain, 00317 Int rightEnd, 00318 Int rightCorner, 00319 Int& ret_sep_left, 00320 Int& ret_sep_right) 00321 { 00322 Int oldLeftI, oldRightI, newLeftI, newRightI; 00323 Int i,j,k; 00324 Real leftMax /*= leftChain->getVertex(leftCorner)[0]*/; 00325 Real rightMin /*= rightChain->getVertex(rightCorner)[0]*/; 00326 if(leftChain->getVertex(leftCorner)[1] < rightChain->getVertex(rightCorner)[1])//leftlower 00327 { 00328 oldLeftI = leftCorner-1; 00329 oldRightI = rightCorner; 00330 leftMax = leftChain->getVertex(leftCorner)[0] - Real(1.0) ; //initilize to be left of leftCorner 00331 rightMin = rightChain->getVertex(rightCorner)[0]; 00332 } 00333 else //rightlower 00334 { 00335 oldLeftI = leftCorner; 00336 oldRightI = rightCorner-1; 00337 leftMax = leftChain->getVertex(leftCorner)[0]; 00338 rightMin = rightChain->getVertex(rightCorner)[0] + Real(1.0); 00339 } 00340 00341 //i: the current working leftChain Index 00342 //j: the curent working right chian index 00343 //if(left(i) is lower than right(j), then the two chains above right(j) are separated. 00344 //else the two chains below left(i) are separated. 00345 i = leftCorner; 00346 j = rightCorner; 00347 while(1) 00348 { 00349 newLeftI = oldLeftI; 00350 newRightI = oldRightI; 00351 if(i> leftEnd) //left chain is doen , go through remaining right chain 00352 { 00353 for(k=j+1; k<= rightEnd; k++) 00354 { 00355 if(rightChain->getVertex(k)[0] > leftMax) //no conflict 00356 { 00357 //update oldRightI if necessary 00358 if(rightChain->getVertex(k)[0] < rightMin) 00359 { 00360 rightMin = rightChain->getVertex(k)[0]; 00361 oldRightI = k; 00362 } 00363 } 00364 else //there is a conflict 00365 break; //the for-loop, above right(k+1) is separated: oldLeftI, oldRightI 00366 } 00367 break; //the while loop 00368 } 00369 else if(j > rightEnd) //right Chain is doen 00370 { 00371 for(k=i+1; k<= leftEnd; k++) 00372 { 00373 if(leftChain->getVertex(k)[0] < rightMin) //no conflict 00374 { 00375 //update oldLeftI if necessary 00376 if(leftChain->getVertex(k)[0] > leftMax) 00377 { 00378 leftMax = leftChain->getVertex(k)[0]; 00379 oldLeftI = k; 00380 } 00381 } 00382 else //there is a conflict 00383 break; //the for-loop, above left(k+1) is separated: oldLeftI, oldRightI 00384 } 00385 break; //the while loop 00386 } 00387 else if(leftChain->getVertex(i)[1] < rightChain->getVertex(j)[1]) //left lower 00388 { 00389 00390 if(leftChain->getVertex(i)[0] > leftMax) //update leftMax amd newLeftI 00391 { 00392 leftMax = leftChain->getVertex(i)[0]; 00393 newLeftI = i; 00394 } 00395 for(k=j+1; k<= rightEnd; k++) //update rightMin and newRightI; 00396 { 00397 if(rightChain->getVertex(k)[1] < leftChain->getVertex(i)[1]) //right gets lower 00398 break; 00399 if(rightChain->getVertex(k)[0] < rightMin) 00400 { 00401 rightMin = rightChain->getVertex(k)[0]; 00402 newRightI = k; 00403 } 00404 } 00405 j = k; //next working j, since j will he lower than i in next loop 00406 if(leftMax >= rightMin) //there is a conflict 00407 break; 00408 else //still no conflict 00409 { 00410 oldLeftI = newLeftI; 00411 oldRightI = newRightI; 00412 00413 } 00414 } 00415 else //right lower 00416 { 00417 if(rightChain->getVertex(j)[0] < rightMin) 00418 { 00419 rightMin = rightChain->getVertex(j)[0]; 00420 newRightI = j; 00421 } 00422 for(k=i+1; k<= leftEnd; k++) 00423 { 00424 if(leftChain->getVertex(k)[1] < rightChain->getVertex(j)[1]) 00425 break; 00426 if(leftChain->getVertex(k)[0] > leftMax) 00427 { 00428 leftMax = leftChain->getVertex(k)[0]; 00429 newLeftI = k; 00430 } 00431 } 00432 i=k; //nexct working i, since i will be lower than j next loop 00433 if(leftMax >= rightMin) //there is conflict 00434 break; 00435 else //still no conflict 00436 { 00437 oldLeftI = newLeftI; 00438 oldRightI = newRightI; 00439 } 00440 } 00441 }//end of while loop 00442 //now oldLeftI and oldRight I are the desired separator index notice that they are not 00443 //necessarily valid 00444 if(oldLeftI < leftCorner || oldRightI < rightCorner) 00445 return 0; //no separator 00446 else 00447 { 00448 ret_sep_left = oldLeftI; 00449 ret_sep_right = oldRightI; 00450 return 1; 00451 } 00452 } 00453 00454 void sampleCompBot(Real* botVertex, 00455 vertexArray* leftChain, 00456 Int leftEnd, 00457 vertexArray* rightChain, 00458 Int rightEnd, 00459 gridBoundaryChain* leftGridChain, 00460 gridBoundaryChain* rightGridChain, 00461 Int gridIndex, 00462 Int down_leftCornerWhere, 00463 Int down_leftCornerIndex, 00464 Int down_rightCornerWhere, 00465 Int down_rightCornerIndex, 00466 primStream* pStream) 00467 { 00468 00469 if(down_leftCornerWhere == 1 && down_rightCornerWhere == 1) //the bot is botVertex with possible grid points 00470 { 00471 00472 leftGridChain->getGrid()->outputFanWithPoint(leftGridChain->getVlineIndex(gridIndex), 00473 leftGridChain->getUlineIndex(gridIndex), 00474 rightGridChain->getUlineIndex(gridIndex), 00475 botVertex, 00476 pStream); 00477 return; 00478 } 00479 else if(down_leftCornerWhere != 0) 00480 { 00481 00482 Real* tempBot; 00483 Int tempRightEnd; 00484 if(down_leftCornerWhere == 1){ 00485 tempRightEnd = rightEnd; 00486 tempBot = botVertex; 00487 } 00488 else 00489 { 00490 tempRightEnd = down_leftCornerIndex-1; 00491 tempBot = rightChain->getVertex(down_leftCornerIndex); 00492 } 00493 00494 sampleBotRightWithGridLine(tempBot, 00495 rightChain, 00496 tempRightEnd, 00497 down_rightCornerIndex, 00498 rightGridChain->getGrid(), 00499 leftGridChain->getVlineIndex(gridIndex), 00500 leftGridChain->getUlineIndex(gridIndex), 00501 rightGridChain->getUlineIndex(gridIndex), 00502 pStream); 00503 } 00504 else if(down_rightCornerWhere != 2) 00505 { 00506 00507 Real* tempBot; 00508 Int tempLeftEnd; 00509 if(down_rightCornerWhere == 1){ 00510 tempLeftEnd = leftEnd; 00511 tempBot = botVertex; 00512 } 00513 else //right corner is on left chain 00514 { 00515 tempLeftEnd = down_rightCornerIndex-1; 00516 tempBot = leftChain->getVertex(down_rightCornerIndex); 00517 } 00518 00519 00520 sampleBotLeftWithGridLine(tempBot, leftChain, tempLeftEnd, down_leftCornerIndex, 00521 leftGridChain->getGrid(), 00522 leftGridChain->getVlineIndex(gridIndex), 00523 leftGridChain->getUlineIndex(gridIndex), 00524 rightGridChain->getUlineIndex(gridIndex), 00525 pStream); 00526 00527 } 00528 else //down_leftCornereWhere == 0, down_rightCornerwhere == 2 00529 { 00530 sampleCompBotSimple(botVertex, 00531 leftChain, 00532 leftEnd, 00533 rightChain, 00534 rightEnd, 00535 leftGridChain, 00536 rightGridChain, 00537 gridIndex, 00538 down_leftCornerWhere, 00539 down_leftCornerIndex, 00540 down_rightCornerWhere, 00541 down_rightCornerIndex, 00542 pStream); 00543 00544 return; 00545 00546 #ifdef NOT_REACHABLE 00547 //the following code is trying to do some optimization, but not quite working. so it is not reachable, but leave it here for reference 00548 Int sep_left, sep_right; 00549 if(findBotSeparator(leftChain, leftEnd, down_leftCornerIndex, 00550 rightChain, rightEnd, down_rightCornerIndex, 00551 sep_left, sep_right) 00552 )//separator exiosts 00553 { 00554 00555 if(leftChain->getVertex(sep_left)[0] >= leftGridChain->get_u_value(gridIndex) && 00556 rightChain->getVertex(sep_right)[0] <= rightGridChain->get_u_value(gridIndex)) 00557 { 00558 Int gridSep; 00559 Int segLeftMono, segLeftPass, segRightMono, segRightPass; 00560 findBotLeftSegment(leftChain, 00561 sep_left, 00562 down_leftCornerIndex, 00563 leftGridChain->get_u_value(gridIndex), 00564 segLeftMono, 00565 segLeftPass); 00566 findBotRightSegment(rightChain, 00567 sep_right, 00568 down_rightCornerIndex, 00569 rightGridChain->get_u_value(gridIndex), 00570 segRightMono, 00571 segRightPass); 00572 if(leftChain->getVertex(segLeftMono)[1] <= rightChain->getVertex(segRightMono)[1]) 00573 { 00574 gridSep = rightGridChain->getUlineIndex(gridIndex); 00575 while(leftGridChain->getGrid()->get_u_value(gridSep) > leftChain->getVertex(segLeftMono)[0]) 00576 gridSep--; 00577 } 00578 else 00579 { 00580 gridSep = leftGridChain->getUlineIndex(gridIndex); 00581 while(leftGridChain->getGrid()->get_u_value(gridSep) < rightChain->getVertex(segRightMono)[0]) 00582 gridSep++; 00583 } 00584 00585 sampleBotLeftWithGridLinePost(leftChain->getVertex(segLeftMono), 00586 leftChain, 00587 segLeftMono-1, 00588 segLeftMono-1, 00589 segLeftPass, 00590 down_leftCornerIndex, 00591 leftGridChain->getGrid(), 00592 leftGridChain->getVlineIndex(gridIndex), 00593 leftGridChain->getUlineIndex(gridIndex), 00594 gridSep, 00595 pStream); 00596 sampleBotRightWithGridLinePost(rightChain->getVertex(segRightMono), 00597 rightChain, 00598 segRightMono-1, 00599 segRightMono-1, 00600 segRightPass, 00601 down_rightCornerIndex, 00602 rightGridChain->getGrid(), 00603 rightGridChain->getVlineIndex(gridIndex), 00604 gridSep, 00605 rightGridChain->getUlineIndex(gridIndex), 00606 pStream); 00607 Real tempTop[2]; 00608 tempTop[0] = leftGridChain->getGrid()->get_u_value(gridSep); 00609 tempTop[1] = leftGridChain->get_v_value(gridIndex); 00610 monoTriangulationRecGen(tempTop, botVertex, 00611 leftChain, segLeftMono, leftEnd, 00612 rightChain, segRightMono, rightEnd, 00613 pStream); 00614 }//end if both sides have vertices inside the gridboundary points 00615 else if(leftChain->getVertex(sep_left)[0] >= leftGridChain->get_u_value(gridIndex)) //left n right out 00616 00617 { 00618 Int segLeftMono, segLeftPass; 00619 findBotLeftSegment(leftChain, 00620 sep_left, 00621 down_leftCornerIndex, 00622 leftGridChain->get_u_value(gridIndex), 00623 segLeftMono, 00624 segLeftPass); 00625 assert(segLeftPass <= sep_left); //make sure there is a point to the right of u. 00626 monoTriangulation2(leftGridChain->get_vertex(gridIndex), 00627 leftChain->getVertex(segLeftPass), 00628 leftChain, 00629 down_leftCornerIndex, 00630 segLeftPass-1, 00631 1, //a increase chain 00632 pStream); 00633 stripOfFanLeft(leftChain, segLeftMono, segLeftPass, 00634 leftGridChain->getGrid(), 00635 leftGridChain->getVlineIndex(gridIndex), 00636 leftGridChain->getUlineIndex(gridIndex), 00637 rightGridChain->getUlineIndex(gridIndex), 00638 pStream,1 ); 00639 /* 00640 sampleBotLeftWithGridLinePost(leftChain->getVertex(segLeftMono), 00641 leftChain, 00642 segLeftMono-1, 00643 segLeftMono-1, 00644 segLeftPass, 00645 down_leftCornerIndex, 00646 leftGridChain->getGrid(), 00647 leftGridChain->getVlineIndex(gridIndex), 00648 leftGridChain->getUlineIndex(gridIndex), 00649 rightGridChain->getUlineIndex(gridIndex), 00650 pStream); 00651 */ 00652 00653 monoTriangulationRecGen(rightGridChain->get_vertex(gridIndex), 00654 botVertex, 00655 leftChain, segLeftMono, leftEnd, 00656 rightChain, down_rightCornerIndex, rightEnd, 00657 pStream); 00658 }//end left in right out 00659 else if(rightChain->getVertex(sep_right)[0] <= rightGridChain->get_u_value(gridIndex))//left out right in 00660 { 00661 Int segRightMono, segRightPass; 00662 findBotRightSegment(rightChain, sep_right, down_rightCornerIndex, 00663 rightGridChain->get_u_value(gridIndex), 00664 segRightMono, 00665 segRightPass); 00666 00667 assert(segRightPass <= sep_right); //make sure there is a point to the left of u. 00668 monoTriangulation2(rightGridChain->get_vertex(gridIndex), 00669 rightChain->getVertex(segRightPass), 00670 rightChain, 00671 down_rightCornerIndex, 00672 segRightPass-1, 00673 0, // a decrease chain 00674 pStream); 00675 00676 stripOfFanRight(rightChain, segRightMono, segRightPass, 00677 rightGridChain->getGrid(), 00678 rightGridChain->getVlineIndex(gridIndex), 00679 leftGridChain->getUlineIndex(gridIndex), 00680 rightGridChain->getUlineIndex(gridIndex), 00681 pStream, 1); 00682 00683 00684 monoTriangulationRecGen(leftGridChain->get_vertex(gridIndex), 00685 botVertex, 00686 leftChain, down_leftCornerIndex, leftEnd, 00687 rightChain, segRightMono, rightEnd, 00688 pStream); 00689 00690 }//end left out right in 00691 else //left out, right out 00692 { 00693 sampleCompBotSimple(botVertex, 00694 leftChain, 00695 leftEnd, 00696 rightChain, 00697 rightEnd, 00698 leftGridChain, 00699 rightGridChain, 00700 gridIndex, 00701 down_leftCornerWhere, 00702 down_leftCornerIndex, 00703 down_rightCornerWhere, 00704 down_rightCornerIndex, 00705 pStream); 00706 00707 }//end leftout right out 00708 }//end if separator exists 00709 else //no separator 00710 { 00711 00712 sampleCompBotSimple(botVertex, 00713 leftChain, 00714 leftEnd, 00715 rightChain, 00716 rightEnd, 00717 leftGridChain, 00718 rightGridChain, 00719 gridIndex, 00720 down_leftCornerWhere, 00721 down_leftCornerIndex, 00722 down_rightCornerWhere, 00723 down_rightCornerIndex, 00724 pStream); 00725 } 00726 #endif 00727 }//end id 0 2 00728 }//end if the functin 00729 00730 00731 void sampleCompBotSimple(Real* botVertex, 00732 vertexArray* leftChain, 00733 Int leftEnd, 00734 vertexArray* rightChain, 00735 Int rightEnd, 00736 gridBoundaryChain* leftGridChain, 00737 gridBoundaryChain* rightGridChain, 00738 Int gridIndex, 00739 Int down_leftCornerWhere, 00740 Int down_leftCornerIndex, 00741 Int down_rightCornerWhere, 00742 Int down_rightCornerIndex, 00743 primStream* pStream) 00744 { 00745 //the plan is to use monotriangulation algorithm. 00746 Int i,k; 00747 Real* ActualTop; 00748 Real* ActualBot; 00749 Int ActualLeftStart, ActualLeftEnd; 00750 Int ActualRightStart, ActualRightEnd; 00751 00752 //creat an array to store the points on the grid line 00753 gridWrap* grid = leftGridChain->getGrid(); 00754 Int gridV = leftGridChain->getVlineIndex(gridIndex); 00755 Int gridLeftU = leftGridChain->getUlineIndex(gridIndex); 00756 Int gridRightU = rightGridChain->getUlineIndex(gridIndex); 00757 Real2* gridPoints = (Real2*) malloc(sizeof(Real2) * (gridRightU - gridLeftU +1)); 00758 assert(gridPoints); 00759 00760 for(k=0, i=gridRightU; i>= gridLeftU; i--, k++) 00761 { 00762 gridPoints[k][0] = grid->get_u_value(i); 00763 gridPoints[k][1] = grid->get_v_value(gridV); 00764 } 00765 00766 if(down_rightCornerWhere != 0) //rightCorner is not on lef 00767 ActualLeftEnd = leftEnd; 00768 else 00769 ActualLeftEnd = down_rightCornerIndex-1; //down_rightCornerIndex will be th actualBot 00770 00771 if(down_leftCornerWhere != 0) //left corner is not on let chian 00772 ActualLeftStart = leftEnd+1; //meaning that there is no actual left section 00773 else 00774 ActualLeftStart = down_leftCornerIndex; 00775 00776 vertexArray ActualLeftChain(max(0, ActualLeftEnd - ActualLeftStart +1) + gridRightU - gridLeftU +1); 00777 00778 for(i=0; i<gridRightU - gridLeftU +1 ; i++) 00779 ActualLeftChain.appendVertex(gridPoints[i]); 00780 for(i=ActualLeftStart; i<= ActualLeftEnd; i++) 00781 ActualLeftChain.appendVertex(leftChain->getVertex(i)); 00782 00783 //determine ActualRightStart 00784 if(down_rightCornerWhere != 2) //right is not on right 00785 ActualRightStart = rightEnd +1; //meaning no section on right 00786 else 00787 ActualRightStart = down_rightCornerIndex; 00788 00789 //determine actualrightEnd 00790 if(down_leftCornerWhere != 2) //left is not on right 00791 { 00792 00793 ActualRightEnd = rightEnd; 00794 } 00795 else //left corner is on right 00796 { 00797 ActualRightEnd = down_leftCornerIndex-1; //down_leftCornerIndex will be the bot 00798 00799 } 00800 00801 //actual bot 00802 if(down_rightCornerWhere == 2) 00803 { 00804 if(down_leftCornerWhere == 2) 00805 ActualBot = rightChain->getVertex(down_leftCornerIndex); 00806 else 00807 ActualBot = botVertex; 00808 } 00809 else if(down_rightCornerWhere == 1) //right corner bot 00810 ActualBot = botVertex; 00811 else //down_rightCornerWhere == 0 00812 ActualBot = leftChain->getVertex(down_rightCornerIndex); 00813 00814 ActualTop = gridPoints[0]; 00815 /* 00816 printf("in bot simple, actual leftChain is \n"); 00817 ActualLeftChain.print(); 00818 printf("Actual Top = %f,%f\n", ActualTop[0],ActualTop[1]); 00819 printf("Actual Bot = %f,%f\n", ActualBot[0],ActualBot[1]); 00820 printf("Actual right start = %i, end=%i\n",ActualRightStart, ActualRightEnd); 00821 */ 00822 if(rightChain->getVertex(ActualRightStart)[1] == ActualTop[1]) 00823 monoTriangulationRecGenOpt(rightChain->getVertex(ActualRightStart), 00824 ActualBot, 00825 &ActualLeftChain, 00826 0, 00827 ActualLeftChain.getNumElements()-1, 00828 rightChain, 00829 ActualRightStart+1, 00830 ActualRightEnd, 00831 pStream); 00832 else 00833 monoTriangulationRecGenOpt(ActualTop, ActualBot, 00834 &ActualLeftChain, 00835 1, //the first one is the top vertex 00836 ActualLeftChain.getNumElements()-1, 00837 rightChain, 00838 ActualRightStart, 00839 ActualRightEnd, 00840 pStream); 00841 free(gridPoints); 00842 } 00843 00844 00845 00846 Generated on Fri May 25 2012 04:21:57 for ReactOS by
1.7.6.1
|