📄 samplecompbot.cc
字号:
break;
if(leftChain->getVertex(k)[0] > leftMax)
{
leftMax = leftChain->getVertex(k)[0];
newLeftI = k;
}
}
i=k; //nexct working i, since i will be lower than j next loop
if(leftMax >= rightMin) //there is conflict
break;
else //still no conflict
{
oldLeftI = newLeftI;
oldRightI = newRightI;
}
}
}//end of while loop
//now oldLeftI and oldRight I are the desired separator index notice that they are not
//necessarily valid
if(oldLeftI < leftCorner || oldRightI < rightCorner)
return 0; //no separator
else
{
ret_sep_left = oldLeftI;
ret_sep_right = oldRightI;
return 1;
}
}
void sampleCompBot(Real* botVertex,
vertexArray* leftChain,
Int leftEnd,
vertexArray* rightChain,
Int rightEnd,
gridBoundaryChain* leftGridChain,
gridBoundaryChain* rightGridChain,
Int gridIndex,
Int down_leftCornerWhere,
Int down_leftCornerIndex,
Int down_rightCornerWhere,
Int down_rightCornerIndex,
primStream* pStream)
{
if(down_leftCornerWhere == 1 && down_rightCornerWhere == 1) //the bot is botVertex with possible grid points
{
leftGridChain->getGrid()->outputFanWithPoint(leftGridChain->getVlineIndex(gridIndex),
leftGridChain->getUlineIndex(gridIndex),
rightGridChain->getUlineIndex(gridIndex),
botVertex,
pStream);
return;
}
else if(down_leftCornerWhere != 0)
{
Real* tempBot;
Int tempRightEnd;
if(down_leftCornerWhere == 1){
tempRightEnd = rightEnd;
tempBot = botVertex;
}
else
{
tempRightEnd = down_leftCornerIndex-1;
tempBot = rightChain->getVertex(down_leftCornerIndex);
}
sampleBotRightWithGridLine(tempBot,
rightChain,
tempRightEnd,
down_rightCornerIndex,
rightGridChain->getGrid(),
leftGridChain->getVlineIndex(gridIndex),
leftGridChain->getUlineIndex(gridIndex),
rightGridChain->getUlineIndex(gridIndex),
pStream);
}
else if(down_rightCornerWhere != 2)
{
Real* tempBot;
Int tempLeftEnd;
if(down_rightCornerWhere == 1){
tempLeftEnd = leftEnd;
tempBot = botVertex;
}
else //right corner is on left chain
{
tempLeftEnd = down_rightCornerIndex-1;
tempBot = leftChain->getVertex(down_rightCornerIndex);
}
sampleBotLeftWithGridLine(tempBot, leftChain, tempLeftEnd, down_leftCornerIndex,
leftGridChain->getGrid(),
leftGridChain->getVlineIndex(gridIndex),
leftGridChain->getUlineIndex(gridIndex),
rightGridChain->getUlineIndex(gridIndex),
pStream);
}
else //down_leftCornereWhere == 0, down_rightCornerwhere == 2
{
sampleCompBotSimple(botVertex,
leftChain,
leftEnd,
rightChain,
rightEnd,
leftGridChain,
rightGridChain,
gridIndex,
down_leftCornerWhere,
down_leftCornerIndex,
down_rightCornerWhere,
down_rightCornerIndex,
pStream);
return;
#ifdef NOT_REACHABLE
//the following code is trying to do some optimization, but not quite working. so it is not reachable, but leave it here for reference
Int sep_left, sep_right;
if(findBotSeparator(leftChain, leftEnd, down_leftCornerIndex,
rightChain, rightEnd, down_rightCornerIndex,
sep_left, sep_right)
)//separator exiosts
{
if(leftChain->getVertex(sep_left)[0] >= leftGridChain->get_u_value(gridIndex) &&
rightChain->getVertex(sep_right)[0] <= rightGridChain->get_u_value(gridIndex))
{
Int gridSep;
Int segLeftMono, segLeftPass, segRightMono, segRightPass;
findBotLeftSegment(leftChain,
sep_left,
down_leftCornerIndex,
leftGridChain->get_u_value(gridIndex),
segLeftMono,
segLeftPass);
findBotRightSegment(rightChain,
sep_right,
down_rightCornerIndex,
rightGridChain->get_u_value(gridIndex),
segRightMono,
segRightPass);
if(leftChain->getVertex(segLeftMono)[1] <= rightChain->getVertex(segRightMono)[1])
{
gridSep = rightGridChain->getUlineIndex(gridIndex);
while(leftGridChain->getGrid()->get_u_value(gridSep) > leftChain->getVertex(segLeftMono)[0])
gridSep--;
}
else
{
gridSep = leftGridChain->getUlineIndex(gridIndex);
while(leftGridChain->getGrid()->get_u_value(gridSep) < rightChain->getVertex(segRightMono)[0])
gridSep++;
}
sampleBotLeftWithGridLinePost(leftChain->getVertex(segLeftMono),
leftChain,
segLeftMono-1,
segLeftMono-1,
segLeftPass,
down_leftCornerIndex,
leftGridChain->getGrid(),
leftGridChain->getVlineIndex(gridIndex),
leftGridChain->getUlineIndex(gridIndex),
gridSep,
pStream);
sampleBotRightWithGridLinePost(rightChain->getVertex(segRightMono),
rightChain,
segRightMono-1,
segRightMono-1,
segRightPass,
down_rightCornerIndex,
rightGridChain->getGrid(),
rightGridChain->getVlineIndex(gridIndex),
gridSep,
rightGridChain->getUlineIndex(gridIndex),
pStream);
Real tempTop[2];
tempTop[0] = leftGridChain->getGrid()->get_u_value(gridSep);
tempTop[1] = leftGridChain->get_v_value(gridIndex);
monoTriangulationRecGen(tempTop, botVertex,
leftChain, segLeftMono, leftEnd,
rightChain, segRightMono, rightEnd,
pStream);
}//end if both sides have vertices inside the gridboundary points
else if(leftChain->getVertex(sep_left)[0] >= leftGridChain->get_u_value(gridIndex)) //left n right out
{
Int segLeftMono, segLeftPass;
findBotLeftSegment(leftChain,
sep_left,
down_leftCornerIndex,
leftGridChain->get_u_value(gridIndex),
segLeftMono,
segLeftPass);
assert(segLeftPass <= sep_left); //make sure there is a point to the right of u.
monoTriangulation2(leftGridChain->get_vertex(gridIndex),
leftChain->getVertex(segLeftPass),
leftChain,
down_leftCornerIndex,
segLeftPass-1,
1, //a increase chain
pStream);
stripOfFanLeft(leftChain, segLeftMono, segLeftPass,
leftGridChain->getGrid(),
leftGridChain->getVlineIndex(gridIndex),
leftGridChain->getUlineIndex(gridIndex),
rightGridChain->getUlineIndex(gridIndex),
pStream,1 );
/*
sampleBotLeftWithGridLinePost(leftChain->getVertex(segLeftMono),
leftChain,
segLeftMono-1,
segLeftMono-1,
segLeftPass,
down_leftCornerIndex,
leftGridChain->getGrid(),
leftGridChain->getVlineIndex(gridIndex),
leftGridChain->getUlineIndex(gridIndex),
rightGridChain->getUlineIndex(gridIndex),
pStream);
*/
monoTriangulationRecGen(rightGridChain->get_vertex(gridIndex),
botVertex,
leftChain, segLeftMono, leftEnd,
rightChain, down_rightCornerIndex, rightEnd,
pStream);
}//end left in right out
else if(rightChain->getVertex(sep_right)[0] <= rightGridChain->get_u_value(gridIndex))//left out right in
{
Int segRightMono, segRightPass;
findBotRightSegment(rightChain, sep_right, down_rightCornerIndex,
rightGridChain->get_u_value(gridIndex),
segRightMono,
segRightPass);
assert(segRightPass <= sep_right); //make sure there is a point to the left of u.
monoTriangulation2(rightGridChain->get_vertex(gridIndex),
rightChain->getVertex(segRightPass),
rightChain,
down_rightCornerIndex,
segRightPass-1,
0, // a decrease chain
pStream);
stripOfFanRight(rightChain, segRightMono, segRightPass,
rightGridChain->getGrid(),
rightGridChain->getVlineIndex(gridIndex),
leftGridChain->getUlineIndex(gridIndex),
rightGridChain->getUlineIndex(gridIndex),
pStream, 1);
monoTriangulationRecGen(leftGridChain->get_vertex(gridIndex),
botVertex,
leftChain, down_leftCornerIndex, leftEnd,
rightChain, segRightMono, rightEnd,
pStream);
}//end left out right in
else //left out, right out
{
sampleCompBotSimple(botVertex,
leftChain,
leftEnd,
rightChain,
rightEnd,
leftGridChain,
rightGridChain,
gridIndex,
down_leftCornerWhere,
down_leftCornerIndex,
down_rightCornerWhere,
down_rightCornerIndex,
pStream);
}//end leftout right out
}//end if separator exists
else //no separator
{
sampleCompBotSimple(botVertex,
leftChain,
leftEnd,
rightChain,
rightEnd,
leftGridChain,
rightGridChain,
gridIndex,
down_leftCornerWhere,
down_leftCornerIndex,
down_rightCornerWhere,
down_rightCornerIndex,
pStream);
}
#endif
}//end id 0 2
}//end if the functin
void sampleCompBotSimple(Real* botVertex,
vertexArray* leftChain,
Int leftEnd,
vertexArray* rightChain,
Int rightEnd,
gridBoundaryChain* leftGridChain,
gridBoundaryChain* rightGridChain,
Int gridIndex,
Int down_leftCornerWhere,
Int down_leftCornerIndex,
Int down_rightCornerWhere,
Int down_rightCornerIndex,
primStream* pStream)
{
//the plan is to use monotriangulation algorithm.
Int i,k;
Real* ActualTop;
Real* ActualBot;
Int ActualLeftStart, ActualLeftEnd;
Int ActualRightStart, ActualRightEnd;
//creat an array to store the points on the grid line
gridWrap* grid = leftGridChain->getGrid();
Int gridV = leftGridChain->getVlineIndex(gridIndex);
Int gridLeftU = leftGridChain->getUlineIndex(gridIndex);
Int gridRightU = rightGridChain->getUlineIndex(gridIndex);
Real2* gridPoints = (Real2*) malloc(sizeof(Real2) * (gridRightU - gridLeftU +1));
assert(gridPoints);
for(k=0, i=gridRightU; i>= gridLeftU; i--, k++)
{
gridPoints[k][0] = grid->get_u_value(i);
gridPoints[k][1] = grid->get_v_value(gridV);
}
if(down_rightCornerWhere != 0) //rightCorner is not on lef
ActualLeftEnd = leftEnd;
else
ActualLeftEnd = down_rightCornerIndex-1; //down_rightCornerIndex will be th actualBot
if(down_leftCornerWhere != 0) //left corner is not on let chian
ActualLeftStart = leftEnd+1; //meaning that there is no actual left section
else
ActualLeftStart = down_leftCornerIndex;
vertexArray ActualLeftChain(max(0, ActualLeftEnd - ActualLeftStart +1) + gridRightU - gridLeftU +1);
for(i=0; i<gridRightU - gridLeftU +1 ; i++)
ActualLeftChain.appendVertex(gridPoints[i]);
for(i=ActualLeftStart; i<= ActualLeftEnd; i++)
ActualLeftChain.appendVertex(leftChain->getVertex(i));
//determine ActualRightStart
if(down_rightCornerWhere != 2) //right is not on right
ActualRightStart = rightEnd +1; //meaning no section on right
else
ActualRightStart = down_rightCornerIndex;
//determine actualrightEnd
if(down_leftCornerWhere != 2) //left is not on right
{
ActualRightEnd = rightEnd;
}
else //left corner is on right
{
ActualRightEnd = down_leftCornerIndex-1; //down_leftCornerIndex will be the bot
}
//actual bot
if(down_rightCornerWhere == 2)
{
if(down_leftCornerWhere == 2)
ActualBot = rightChain->getVertex(down_leftCornerIndex);
else
ActualBot = botVertex;
}
else if(down_rightCornerWhere == 1) //right corner bot
ActualBot = botVertex;
else //down_rightCornerWhere == 0
ActualBot = leftChain->getVertex(down_rightCornerIndex);
ActualTop = gridPoints[0];
/*
printf("in bot simple, actual leftChain is \n");
ActualLeftChain.print();
printf("Actual Top = %f,%f\n", ActualTop[0],ActualTop[1]);
printf("Actual Bot = %f,%f\n", ActualBot[0],ActualBot[1]);
printf("Actual right start = %i, end=%i\n",ActualRightStart, ActualRightEnd);
*/
if(rightChain->getVertex(ActualRightStart)[1] == ActualTop[1])
monoTriangulationRecGenOpt(rightChain->getVertex(ActualRightStart),
ActualBot,
&ActualLeftChain,
0,
ActualLeftChain.getNumElements()-1,
rightChain,
ActualRightStart+1,
ActualRightEnd,
pStream);
else
monoTriangulationRecGenOpt(ActualTop, ActualBot,
&ActualLeftChain,
1, //the first one is the top vertex
ActualLeftChain.getNumElements()-1,
rightChain,
ActualRightStart,
ActualRightEnd,
pStream);
free(gridPoints);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -