41 #include "glimports.h"
43 #include "sampleCompRight.h"
45 #define max(a,b) ((a>b)? a:b)
46 #define min(a,b) ((a>b)? b:a)
55 void sampleCompRight(Real* topVertex, Real* botVertex,
57 Int leftStartIndex, Int leftEndIndex,
59 Int rightStartIndex, Int rightEndIndex,
61 Int gridIndex1, Int gridIndex2,
62 Int up_rightCornerWhere,
63 Int up_rightCornerIndex,
64 Int down_rightCornerWhere,
65 Int down_rightCornerIndex,
73 Int gridMidIndex1 = 0, gridMidIndex2 = 0;
76 midIndex1 = rightChain->findIndexBelowGen(rightGridChain->get_v_value(gridIndex1),
80 if(midIndex1 <= rightEndIndex && gridIndex1 < gridIndex2)
81 if(rightChain->getVertex(midIndex1)[1] >= rightGridChain->get_v_value(gridIndex2))
84 midIndex2 = rightChain->findIndexAboveGen(rightGridChain->get_v_value(gridIndex2),
91 Real temp = rightChain->getVertex(midIndex1)[1];
92 if(rightGridChain->get_v_value(gridIndex1) == temp)
93 gridMidIndex1 = gridIndex1;
96 gridMidIndex1 = gridIndex1;
97 while(rightGridChain->get_v_value(gridMidIndex1) > temp)
105 Real temp = rightChain->getVertex(midIndex2)[1];
106 for(gridMidIndex2 = gridMidIndex1+1; gridMidIndex2 <= gridIndex2; gridMidIndex2++)
107 if(rightGridChain->get_v_value(gridMidIndex2) <= temp)
110 assert(gridMidIndex2 <= gridIndex2);
119 Int cornerRightStart;
122 Int cornerLeftDownStart;
123 if(up_rightCornerWhere == 2)
125 cornerTop = rightChain->getVertex(up_rightCornerIndex);
126 cornerRightStart = up_rightCornerIndex+1;
127 cornerLeftUpEnd = -1;
129 else if(up_rightCornerWhere == 1)
131 cornerTop = topVertex;
132 cornerRightStart = rightStartIndex;
133 cornerLeftUpEnd = -1;
137 cornerTop = topVertex;
138 cornerRightStart = rightStartIndex;
139 cornerLeftUpEnd = up_rightCornerIndex;
142 if(down_rightCornerWhere == 2)
144 cornerBot = rightChain->getVertex(down_rightCornerIndex);
145 cornerRightEnd = down_rightCornerIndex-1;
146 cornerLeftDownStart = leftEndIndex+1;
148 else if (down_rightCornerWhere == 1)
150 cornerBot = botVertex;
151 cornerRightEnd = rightEndIndex;
152 cornerLeftDownStart = leftEndIndex+1;
156 cornerBot = botVertex;
157 cornerRightEnd = rightEndIndex;
158 cornerLeftDownStart = down_rightCornerIndex;
165 sampleRightSingleTrimEdgeRegionGen(cornerTop, rightChain->getVertex(midIndex1),
179 sampleRightSingleTrimEdgeRegionGen(rightChain->getVertex(midIndex2),
194 sampleRightStripRecF(rightChain,
205 sampleRightSingleTrimEdgeRegionGen(cornerTop, cornerBot,
221 void sampleRightSingleTrimEdgeRegionGen(Real topVertex[2], Real botVertex[2],
243 max(0,leftUpEnd - leftUpBegin+1)+
244 max(0,leftDownEnd - leftDownBegin+1));
246 for(i=leftUpBegin; i<= leftUpEnd; i++)
247 vArray.appendVertex(leftChain->getVertex(i));
251 vArray.appendVertex(gridChain->get_vertex(gridBeginIndex));
253 for(k=1, i=gridBeginIndex+1; i<= gridEndIndex; i++, k++)
255 vArray.appendVertex(gridChain->get_vertex(i));
258 gridChain->rightEndFan(i, pStream);
262 for(i=leftDownBegin; i<= leftDownEnd; i++)
263 vArray.appendVertex(leftChain->getVertex(i));
264 monoTriangulationRecGen(topVertex, botVertex,
265 &vArray, 0, vArray.getNumElements()-1,
266 rightChain, rightStart, rightEnd,
270 void sampleRightSingleTrimEdgeRegion(Real upperVert[2], Real lowerVert[2],
278 vArray.appendVertex(gridChain->get_vertex(beginIndex));
279 for(k=1, i=beginIndex+1; i<= endIndex; i++, k++)
281 vArray.appendVertex(gridChain->get_vertex(i));
283 gridChain->rightEndFan(i, pStream);
285 monoTriangulation2(upperVert, lowerVert, &vArray, 0, endIndex-beginIndex,
309 Int rightGridChainStartIndex,
310 Int rightGridChainEndIndex,
316 if(topRightIndex > botRightIndex)
320 if(rightGridChainStartIndex >= rightGridChainEndIndex)
324 assert(rightChain->getVertex(topRightIndex)[1] <= rightGridChain->get_v_value(rightGridChainStartIndex) &&
325 rightChain->getVertex(botRightIndex)[1] >= rightGridChain->get_v_value(rightGridChainEndIndex));
329 Real secondGridChainV = rightGridChain->get_v_value(rightGridChainStartIndex+1);
330 Int index1 = topRightIndex;
331 while(rightChain->getVertex(index1)[1] >= secondGridChainV){
333 if(index1 > botRightIndex)
343 sampleRightOneGridStep(rightChain, topRightIndex, index1, rightGridChain, rightGridChainStartIndex, pStream);
347 if(rightChain->getVertex(index1)[1] == secondGridChainV)
351 sampleRightStripRecF(rightChain, index1, botRightIndex, rightGridChain, rightGridChainStartIndex+1, rightGridChainEndIndex, pStream);
353 else if(index1 < botRightIndex)
360 Real *uppervert, *lowervert;
361 uppervert = rightChain->getVertex(index1);
362 lowervert = rightChain->getVertex(index1+1);
363 Int index2 = rightGridChainStartIndex+1;
364 while(rightGridChain->get_v_value(index2) > lowervert[1])
367 if(index2 > rightGridChainEndIndex)
372 sampleRightSingleTrimEdgeRegion(uppervert, lowervert, rightGridChain, rightGridChainStartIndex+1, index2, pStream);
375 sampleRightStripRecF(rightChain, index1+1, botRightIndex, rightGridChain, index2, rightGridChainEndIndex, pStream);
380 void sampleRightOneGridStepNoMiddle(
vertexArray* rightChain,
384 Int rightGridChainStartIndex,
391 rightGridChain->rightEndFan(rightGridChainStartIndex+1, pStream);
392 monoTriangulation2(rightGridChain->get_vertex(rightGridChainStartIndex),
393 rightGridChain->get_vertex(rightGridChainStartIndex+1),
403 void sampleRightOneGridStep(
vertexArray* rightChain,
407 Int rightGridChainStartIndex,
410 if(checkMiddle(rightChain, beginRightIndex, endRightIndex,
411 rightGridChain->get_v_value(rightGridChainStartIndex),
412 rightGridChain->get_v_value(rightGridChainStartIndex+1))<0)
414 sampleRightOneGridStepNoMiddle(rightChain, beginRightIndex, endRightIndex, rightGridChain, rightGridChainStartIndex, pStream);
423 gridWrap* grid = rightGridChain->getGrid();
428 Int innerInd = rightGridChain->getInnerIndex(rightGridChainStartIndex+1);
429 Int upperInd = rightGridChain->getUlineIndex(rightGridChainStartIndex);
430 Int lowerInd = rightGridChain->getUlineIndex(rightGridChainStartIndex+1);
431 Real upperV = rightGridChain->get_v_value(rightGridChainStartIndex);
432 Real lowerV = rightGridChain->get_v_value(rightGridChainStartIndex+1);
435 vert1[1]=vert2[1]=upperV;
440 vert1[0]=grid->get_u_value(i);
441 vert2[0]=grid->get_u_value(i-1);
451 vert1[0]=vert2[0] = grid->get_u_value(innerInd);
462 vert1[1]=vert2[1]=lowerV;
463 for(i=innerInd; i<lowerInd; i++)
465 vert1[0] = grid->get_u_value(i);
466 vert2[0] = grid->get_u_value(i+1);
473 vert1[0]=grid->get_u_value(lowerInd);
474 sline =
new sampledLine(vert1, rightChain->getVertex(endRightIndex));
480 for(i=endRightIndex; i>beginRightIndex; i--)
482 sline =
new sampledLine(rightChain->getVertex(i), rightChain->getVertex(i-1));
489 vert2[0]=grid->get_u_value(upperInd);
490 sline =
new sampledLine(rightChain->getVertex(beginRightIndex), vert2);
493 monoTriangulationOpt(poly, pStream);
495 poly->deleteSinglePolygonWithSline();
504 Real prevU = rightChain->getVertex(i)[0];
505 for(i=beginRightIndex+1; i<= endRightIndex; i++){
506 Real thisU = rightChain->getVertex(i)[0];
516 if(i-1 == beginRightIndex && rightChain->getVertex(beginRightIndex)[1] == rightGridChain->get_v_value(rightGridChainStartIndex))
519 Int j = endRightIndex -1;
520 if(rightGridChain->getInnerIndex(rightGridChainStartIndex+1) < rightGridChain->getUlineIndex(rightGridChainStartIndex+1))
522 j = rightChain->findDecreaseChainFromEnd(i-1, endRightIndex);
523 Int temp = endRightIndex;
528 if(j+1 == endRightIndex)
530 while(rightChain->getVertex(j+1)[1] == rightGridChain->get_v_value(rightGridChainStartIndex+1))
533 monoTriangulation2(rightChain->getVertex(j+1),
534 rightGridChain->get_vertex(rightGridChainStartIndex+1),
544 stripOfFanRight(rightChain, temp, j+1, rightGridChain->getGrid(),
545 rightGridChain->getVlineIndex(rightGridChainStartIndex+1),
546 rightGridChain->getInnerIndex(rightGridChainStartIndex+1),
547 rightGridChain->getUlineIndex(rightGridChainStartIndex+1),
555 stripOfFanRight(rightChain, i-1, beginRightIndex, rightGridChain->getGrid(),
556 rightGridChain->getVlineIndex(rightGridChainStartIndex),
557 rightGridChain->getInnerIndex(rightGridChainStartIndex+1),
558 rightGridChain->getUlineIndex(rightGridChainStartIndex),
566 vert[0][0] = vert[1][0] = rightGridChain->getInner_u_value(rightGridChainStartIndex+1);
567 vert[0][1] = rightGridChain->get_v_value(rightGridChainStartIndex);
568 vert[1][1] = rightGridChain->get_v_value(rightGridChainStartIndex+1);
570 monoTriangulation2(&vert[0][0],
592 assert(largeIndex >= smallIndex);
595 grid_v_value = grid->get_v_value(vlineIndex);
597 Real2* trimVerts=(Real2*) malloc(
sizeof(Real2)* (largeIndex-smallIndex+1));
601 Real2* gridVerts=(Real2*) malloc(
sizeof(Real2)* (ulineLargeIndex-ulineSmallIndex+1));
606 for(k=0, i=smallIndex; i<=largeIndex; i++, k++)
608 trimVerts[k][0] = rightChain->getVertex(i)[0];
609 trimVerts[k][1] = rightChain->getVertex(i)[1];
612 for(k=0, i=largeIndex; i>=smallIndex; i--, k++)
614 trimVerts[k][0] = rightChain->getVertex(i)[0];
615 trimVerts[k][1] = rightChain->getVertex(i)[1];
618 for(k=0, i=ulineSmallIndex; i<= ulineLargeIndex; i++, k++)
620 gridVerts[k][0] = grid->get_u_value(i);
621 gridVerts[k][1] = grid_v_value;
626 ulineLargeIndex-ulineSmallIndex+1, gridVerts,
627 largeIndex-smallIndex+1, trimVerts,
630 triangulateXYMono(largeIndex-smallIndex+1, trimVerts,
631 ulineLargeIndex-ulineSmallIndex+1, gridVerts,