41 #include "sampleCompBot.h"
42 #include "sampleCompRight.h"
44 #define max(a,b) ((a>b)? a:b)
61 assert(leftCorner <= leftEnd);
62 for(i=leftCorner; i<= leftEnd; i++)
63 if(leftChain->getVertex(i)[0] >= u)
66 if(ret_index_pass <= leftEnd)
68 for(i=ret_index_pass; i< leftEnd; i++)
70 if(leftChain->getVertex(i+1)[0] <= leftChain->getVertex(i)[0])
86 assert(rightCorner <= rightEnd);
87 for(i=rightCorner; i<= rightEnd; i++)
88 if(rightChain->getVertex(i)[0] <= u)
95 if(ret_index_pass <= rightEnd)
97 for(i=ret_index_pass; i< rightEnd; i++)
99 if(rightChain->getVertex(i+1)[0] >= rightChain->getVertex(i)[0])
107 void sampleBotRightWithGridLinePost(Real* botVertex,
120 if(segIndexPass > rightCorner)
123 if(segIndexPass <= rightEnd)
124 tempBot = rightChain->getVertex(segIndexPass);
128 tempTop[0] = grid->get_u_value(rightU);
129 tempTop[1] = grid->get_v_value(gridV);
131 monoTriangulation2(tempTop, tempBot,
140 if(segIndexPass <= rightEnd)
146 if(botVertex[0] <= grid->get_u_value(leftU))
152 for(i=segIndexMono; i<=rightEnd; i++)
153 if(rightChain->getVertex(i)[0] <= botVertex[0])
165 while(grid->get_u_value(midU) <= botVertex[0])
173 grid->outputFanWithPoint(gridV, leftU, midU, botVertex, pStream);
174 stripOfFanRight(rightChain, segIndexMono, segIndexPass, grid, gridV, midU, rightU, pStream, 1);
176 tempTop[0] = grid->get_u_value(midU);
177 tempTop[1] = grid->get_v_value(gridV);
178 monoTriangulation2(tempTop, botVertex, rightChain, segIndexMono, rightEnd, 0, pStream);
182 stripOfFanRight(rightChain, segIndexMono, segIndexPass, grid, gridV, leftU, rightU, pStream, 1);
184 tempTop[0] = grid->get_u_value(leftU);
185 tempTop[1] = grid->get_v_value(gridV);
186 monoTriangulation2(tempTop, botVertex, rightChain, segIndexMono, rightEnd, 0, pStream);
190 grid->outputFanWithPoint(gridV, leftU, rightU, botVertex, pStream);
193 void sampleBotRightWithGridLine(Real* botVertex,
205 if(rightEnd<rightCorner){
206 grid->outputFanWithPoint(gridV, leftU, rightU, botVertex, pStream);
210 Int segIndexMono, segIndexPass;
211 findBotRightSegment(rightChain,
214 grid->get_u_value(rightU),
218 sampleBotRightWithGridLinePost(botVertex,
232 void sampleBotLeftWithGridLinePost(Real* botVertex,
246 if(segIndexPass > leftCorner)
249 if(segIndexPass <= leftEnd)
250 tempBot = leftChain->getVertex(segIndexPass);
254 tempTop[0] = grid->get_u_value(leftU);
255 tempTop[1] = grid->get_v_value(gridV);
256 monoTriangulation2(tempTop, tempBot, leftChain, leftCorner, segIndexPass-1,
261 if(segIndexPass <= leftEnd)
263 stripOfFanLeft(leftChain, segIndexMono, segIndexPass, grid, gridV, leftU, rightU, pStream, 1);
265 tempTop[0] = grid->get_u_value(rightU);
266 tempTop[1] = grid->get_v_value(gridV);
268 monoTriangulation2(tempTop, botVertex, leftChain, segIndexMono, leftEnd,
274 grid->outputFanWithPoint(gridV, leftU, rightU, botVertex, pStream);
279 void sampleBotLeftWithGridLine(Real* botVertex,
291 if(leftEnd< leftCorner){
292 grid->outputFanWithPoint(gridV, leftU, rightU, botVertex, pStream);
296 Int segIndexPass, segIndexMono;
297 findBotLeftSegment(leftChain, leftEnd, leftCorner, grid->get_u_value(leftU), segIndexMono, segIndexPass);
299 sampleBotLeftWithGridLinePost(botVertex,
307 leftU, rightU, pStream);
320 Int oldLeftI, oldRightI, newLeftI, newRightI;
324 if(leftChain->getVertex(leftCorner)[1] < rightChain->getVertex(rightCorner)[1])
326 oldLeftI = leftCorner-1;
327 oldRightI = rightCorner;
328 leftMax = leftChain->getVertex(leftCorner)[0] - Real(1.0) ;
329 rightMin = rightChain->getVertex(rightCorner)[0];
333 oldLeftI = leftCorner;
334 oldRightI = rightCorner-1;
335 leftMax = leftChain->getVertex(leftCorner)[0];
336 rightMin = rightChain->getVertex(rightCorner)[0] + Real(1.0);
348 newRightI = oldRightI;
351 for(k=j+1; k<= rightEnd; k++)
353 if(rightChain->getVertex(k)[0] > leftMax)
356 if(rightChain->getVertex(k)[0] < rightMin)
358 rightMin = rightChain->getVertex(k)[0];
367 else if(j > rightEnd)
369 for(k=i+1; k<= leftEnd; k++)
371 if(leftChain->getVertex(k)[0] < rightMin)
374 if(leftChain->getVertex(k)[0] > leftMax)
376 leftMax = leftChain->getVertex(k)[0];
385 else if(leftChain->getVertex(i)[1] < rightChain->getVertex(j)[1])
388 if(leftChain->getVertex(i)[0] > leftMax)
390 leftMax = leftChain->getVertex(i)[0];
393 for(k=j+1; k<= rightEnd; k++)
395 if(rightChain->getVertex(k)[1] < leftChain->getVertex(i)[1])
397 if(rightChain->getVertex(k)[0] < rightMin)
399 rightMin = rightChain->getVertex(k)[0];
404 if(leftMax >= rightMin)
409 oldRightI = newRightI;
415 if(rightChain->getVertex(j)[0] < rightMin)
417 rightMin = rightChain->getVertex(j)[0];
420 for(k=i+1; k<= leftEnd; k++)
422 if(leftChain->getVertex(k)[1] < rightChain->getVertex(j)[1])
424 if(leftChain->getVertex(k)[0] > leftMax)
426 leftMax = leftChain->getVertex(k)[0];
431 if(leftMax >= rightMin)
436 oldRightI = newRightI;
442 if(oldLeftI < leftCorner || oldRightI < rightCorner)
446 ret_sep_left = oldLeftI;
447 ret_sep_right = oldRightI;
452 void sampleCompBot(Real* botVertex,
460 Int down_leftCornerWhere,
461 Int down_leftCornerIndex,
462 Int down_rightCornerWhere,
463 Int down_rightCornerIndex,
467 if(down_leftCornerWhere == 1 && down_rightCornerWhere == 1)
470 leftGridChain->getGrid()->outputFanWithPoint(leftGridChain->getVlineIndex(gridIndex),
471 leftGridChain->getUlineIndex(gridIndex),
472 rightGridChain->getUlineIndex(gridIndex),
477 else if(down_leftCornerWhere != 0)
482 if(down_leftCornerWhere == 1){
483 tempRightEnd = rightEnd;
488 tempRightEnd = down_leftCornerIndex-1;
489 tempBot = rightChain->getVertex(down_leftCornerIndex);
492 sampleBotRightWithGridLine(tempBot,
495 down_rightCornerIndex,
496 rightGridChain->getGrid(),
497 leftGridChain->getVlineIndex(gridIndex),
498 leftGridChain->getUlineIndex(gridIndex),
499 rightGridChain->getUlineIndex(gridIndex),
502 else if(down_rightCornerWhere != 2)
507 if(down_rightCornerWhere == 1){
508 tempLeftEnd = leftEnd;
513 tempLeftEnd = down_rightCornerIndex-1;
514 tempBot = leftChain->getVertex(down_rightCornerIndex);
518 sampleBotLeftWithGridLine(tempBot, leftChain, tempLeftEnd, down_leftCornerIndex,
519 leftGridChain->getGrid(),
520 leftGridChain->getVlineIndex(gridIndex),
521 leftGridChain->getUlineIndex(gridIndex),
522 rightGridChain->getUlineIndex(gridIndex),
528 sampleCompBotSimple(botVertex,
536 down_leftCornerWhere,
537 down_leftCornerIndex,
538 down_rightCornerWhere,
539 down_rightCornerIndex,
546 Int sep_left, sep_right;
547 if(findBotSeparator(leftChain, leftEnd, down_leftCornerIndex,
548 rightChain, rightEnd, down_rightCornerIndex,
553 if(leftChain->getVertex(sep_left)[0] >= leftGridChain->get_u_value(gridIndex) &&
554 rightChain->getVertex(sep_right)[0] <= rightGridChain->get_u_value(gridIndex))
557 Int segLeftMono, segLeftPass, segRightMono, segRightPass;
558 findBotLeftSegment(leftChain,
560 down_leftCornerIndex,
561 leftGridChain->get_u_value(gridIndex),
564 findBotRightSegment(rightChain,
566 down_rightCornerIndex,
567 rightGridChain->get_u_value(gridIndex),
570 if(leftChain->getVertex(segLeftMono)[1] <= rightChain->getVertex(segRightMono)[1])
572 gridSep = rightGridChain->getUlineIndex(gridIndex);
573 while(leftGridChain->getGrid()->get_u_value(gridSep) > leftChain->getVertex(segLeftMono)[0])
578 gridSep = leftGridChain->getUlineIndex(gridIndex);
579 while(leftGridChain->getGrid()->get_u_value(gridSep) < rightChain->getVertex(segRightMono)[0])
583 sampleBotLeftWithGridLinePost(leftChain->getVertex(segLeftMono),
588 down_leftCornerIndex,
589 leftGridChain->getGrid(),
590 leftGridChain->getVlineIndex(gridIndex),
591 leftGridChain->getUlineIndex(gridIndex),
594 sampleBotRightWithGridLinePost(rightChain->getVertex(segRightMono),
599 down_rightCornerIndex,
600 rightGridChain->getGrid(),
601 rightGridChain->getVlineIndex(gridIndex),
603 rightGridChain->getUlineIndex(gridIndex),
606 tempTop[0] = leftGridChain->getGrid()->get_u_value(gridSep);
607 tempTop[1] = leftGridChain->get_v_value(gridIndex);
608 monoTriangulationRecGen(tempTop, botVertex,
609 leftChain, segLeftMono, leftEnd,
610 rightChain, segRightMono, rightEnd,
613 else if(leftChain->getVertex(sep_left)[0] >= leftGridChain->get_u_value(gridIndex))
616 Int segLeftMono, segLeftPass;
617 findBotLeftSegment(leftChain,
619 down_leftCornerIndex,
620 leftGridChain->get_u_value(gridIndex),
623 assert(segLeftPass <= sep_left);
624 monoTriangulation2(leftGridChain->get_vertex(gridIndex),
625 leftChain->getVertex(segLeftPass),
627 down_leftCornerIndex,
631 stripOfFanLeft(leftChain, segLeftMono, segLeftPass,
632 leftGridChain->getGrid(),
633 leftGridChain->getVlineIndex(gridIndex),
634 leftGridChain->getUlineIndex(gridIndex),
635 rightGridChain->getUlineIndex(gridIndex),
651 monoTriangulationRecGen(rightGridChain->get_vertex(gridIndex),
653 leftChain, segLeftMono, leftEnd,
654 rightChain, down_rightCornerIndex, rightEnd,
657 else if(rightChain->getVertex(sep_right)[0] <= rightGridChain->get_u_value(gridIndex))
659 Int segRightMono, segRightPass;
660 findBotRightSegment(rightChain, sep_right, down_rightCornerIndex,
661 rightGridChain->get_u_value(gridIndex),
665 assert(segRightPass <= sep_right);
666 monoTriangulation2(rightGridChain->get_vertex(gridIndex),
667 rightChain->getVertex(segRightPass),
669 down_rightCornerIndex,
674 stripOfFanRight(rightChain, segRightMono, segRightPass,
675 rightGridChain->getGrid(),
676 rightGridChain->getVlineIndex(gridIndex),
677 leftGridChain->getUlineIndex(gridIndex),
678 rightGridChain->getUlineIndex(gridIndex),
682 monoTriangulationRecGen(leftGridChain->get_vertex(gridIndex),
684 leftChain, down_leftCornerIndex, leftEnd,
685 rightChain, segRightMono, rightEnd,
691 sampleCompBotSimple(botVertex,
699 down_leftCornerWhere,
700 down_leftCornerIndex,
701 down_rightCornerWhere,
702 down_rightCornerIndex,
710 sampleCompBotSimple(botVertex,
718 down_leftCornerWhere,
719 down_leftCornerIndex,
720 down_rightCornerWhere,
721 down_rightCornerIndex,
729 void sampleCompBotSimple(Real* botVertex,
737 Int down_leftCornerWhere,
738 Int down_leftCornerIndex,
739 Int down_rightCornerWhere,
740 Int down_rightCornerIndex,
747 Int ActualLeftStart, ActualLeftEnd;
748 Int ActualRightStart, ActualRightEnd;
751 gridWrap* grid = leftGridChain->getGrid();
752 Int gridV = leftGridChain->getVlineIndex(gridIndex);
753 Int gridLeftU = leftGridChain->getUlineIndex(gridIndex);
754 Int gridRightU = rightGridChain->getUlineIndex(gridIndex);
755 Real2* gridPoints = (Real2*) malloc(
sizeof(Real2) * (gridRightU - gridLeftU +1));
758 for(k=0, i=gridRightU; i>= gridLeftU; i--, k++)
760 gridPoints[k][0] = grid->get_u_value(i);
761 gridPoints[k][1] = grid->get_v_value(gridV);
764 if(down_rightCornerWhere != 0)
765 ActualLeftEnd = leftEnd;
767 ActualLeftEnd = down_rightCornerIndex-1;
769 if(down_leftCornerWhere != 0)
770 ActualLeftStart = leftEnd+1;
772 ActualLeftStart = down_leftCornerIndex;
774 vertexArray ActualLeftChain(max(0, ActualLeftEnd - ActualLeftStart +1) + gridRightU - gridLeftU +1);
776 for(i=0; i<gridRightU - gridLeftU +1 ; i++)
777 ActualLeftChain.appendVertex(gridPoints[i]);
778 for(i=ActualLeftStart; i<= ActualLeftEnd; i++)
779 ActualLeftChain.appendVertex(leftChain->getVertex(i));
782 if(down_rightCornerWhere != 2)
783 ActualRightStart = rightEnd +1;
785 ActualRightStart = down_rightCornerIndex;
788 if(down_leftCornerWhere != 2)
791 ActualRightEnd = rightEnd;
795 ActualRightEnd = down_leftCornerIndex-1;
800 if(down_rightCornerWhere == 2)
802 if(down_leftCornerWhere == 2)
803 ActualBot = rightChain->getVertex(down_leftCornerIndex);
805 ActualBot = botVertex;
807 else if(down_rightCornerWhere == 1)
808 ActualBot = botVertex;
810 ActualBot = leftChain->getVertex(down_rightCornerIndex);
812 ActualTop = gridPoints[0];
820 if(rightChain->getVertex(ActualRightStart)[1] == ActualTop[1])
821 monoTriangulationRecGenOpt(rightChain->getVertex(ActualRightStart),
825 ActualLeftChain.getNumElements()-1,
831 monoTriangulationRecGenOpt(ActualTop, ActualBot,
834 ActualLeftChain.getNumElements()-1,