#include <stdlib.h>
#include <stdio.h>
#include "glimports.h"
#include "sampleComp.h"
#include "sampleCompTop.h"
#include "sampleCompBot.h"
#include "sampleCompRight.h"
#define max(a,b) ((a>b)? a:b)
#define min(a,b) ((a>b)? b:a)
void sampleConnectedComp(Real* topVertex, Real* botVertex,
vertexArray* leftChain,
Int leftStartIndex, Int leftEndIndex,
vertexArray* rightChain,
Int rightStartIndex, Int rightEndIndex,
gridBoundaryChain* leftGridChain,
gridBoundaryChain* rightGridChain,
Int gridIndex1, Int gridIndex2,
Int up_leftCornerWhere,
Int up_leftCornerIndex,
Int up_rightCornerWhere,
Int up_rightCornerIndex,
Int down_leftCornerWhere,
Int down_leftCornerIndex,
Int down_rightCornerWhere,
Int down_rightCornerIndex,
primStream* pStream,
rectBlockArray* rbArray
)
{
sampleCompLeft(topVertex, botVertex,
leftChain,
leftStartIndex, leftEndIndex,
rightChain,
rightStartIndex, rightEndIndex,
leftGridChain,
gridIndex1,
gridIndex2,
up_leftCornerWhere,
up_leftCornerIndex,
down_leftCornerWhere,
down_leftCornerIndex,
pStream);
sampleCompRight(topVertex, botVertex,
leftChain,
leftStartIndex, leftEndIndex,
rightChain,
rightStartIndex,
rightEndIndex,
rightGridChain,
gridIndex1, gridIndex2,
up_rightCornerWhere,
up_rightCornerIndex,
down_rightCornerWhere,
down_rightCornerIndex,
pStream);
sampleCompTop(topVertex,
leftChain,
leftStartIndex,
rightChain,
rightStartIndex,
leftGridChain,
rightGridChain,
gridIndex1,
up_leftCornerWhere,
up_leftCornerIndex,
up_rightCornerWhere,
up_rightCornerIndex,
pStream);
sampleCompBot(botVertex,
leftChain,
leftEndIndex,
rightChain,
rightEndIndex,
leftGridChain,
rightGridChain,
gridIndex2,
down_leftCornerWhere,
down_leftCornerIndex,
down_rightCornerWhere,
down_rightCornerIndex,
pStream);
rbArray->insert(new rectBlock(leftGridChain, rightGridChain, gridIndex1, gridIndex2));
}
void sampleCompLeft(Real* topVertex, Real* botVertex,
vertexArray* leftChain,
Int leftStartIndex, Int leftEndIndex,
vertexArray* rightChain,
Int rightStartIndex, Int rightEndIndex,
gridBoundaryChain* leftGridChain,
Int gridIndex1, Int gridIndex2,
Int up_leftCornerWhere,
Int up_leftCornerIndex,
Int down_leftCornerWhere,
Int down_leftCornerIndex,
primStream* pStream)
{
Int midIndex1;
Int midIndex2;
Int gridMidIndex1 = 0, gridMidIndex2 = 0;
midIndex1 = leftChain->findIndexBelowGen(
leftGridChain->get_v_value(gridIndex1),
leftStartIndex,
leftEndIndex);
midIndex2 = -1;
if(midIndex1<= leftEndIndex && gridIndex1<gridIndex2)
if(leftChain->getVertex(midIndex1)[1] >= leftGridChain->get_v_value(gridIndex2))
{
midIndex2 = leftChain->findIndexAboveGen(
leftGridChain->get_v_value(gridIndex2),
midIndex1, leftEndIndex);
gridMidIndex1 = leftGridChain->lookfor(leftChain->getVertex(midIndex1)[1],
gridIndex1, gridIndex2);
gridMidIndex2 = 1+leftGridChain->lookfor(leftChain->getVertex(midIndex2)[1],
gridMidIndex1, gridIndex2);
}
Real* cornerTop;
Real* cornerBot;
Int cornerLeftStart;
Int cornerLeftEnd;
Int cornerRightUpEnd;
Int cornerRightDownStart;
if(up_leftCornerWhere == 0)
{
cornerTop = leftChain->getVertex(up_leftCornerIndex);
cornerLeftStart = up_leftCornerIndex+1;
cornerRightUpEnd = -1;
}
else if(up_leftCornerWhere == 1)
{
cornerTop = topVertex;
cornerLeftStart = leftStartIndex;
cornerRightUpEnd = -1;
}
else
{
cornerTop = topVertex;
cornerLeftStart = leftStartIndex;
cornerRightUpEnd = up_leftCornerIndex;
}
if(down_leftCornerWhere == 0)
{
cornerBot = leftChain->getVertex(down_leftCornerIndex);
cornerLeftEnd = down_leftCornerIndex-1;
cornerRightDownStart = rightEndIndex+1;
}
else if(down_leftCornerWhere == 1)
{
cornerBot = botVertex;
cornerLeftEnd = leftEndIndex;
cornerRightDownStart = rightEndIndex+1;
}
else
{
cornerBot = botVertex;
cornerLeftEnd = leftEndIndex;
cornerRightDownStart = down_leftCornerIndex;
}
if(midIndex2 >= 0)
{
sampleLeftSingleTrimEdgeRegionGen(cornerTop, leftChain->getVertex(midIndex1),
leftChain,
cornerLeftStart,
midIndex1-1,
leftGridChain,
gridIndex1,
gridMidIndex1,
rightChain,
rightStartIndex,
cornerRightUpEnd,
0, -1,
pStream);
sampleLeftSingleTrimEdgeRegionGen(leftChain->getVertex(midIndex2),
cornerBot,
leftChain,
midIndex2+1,
cornerLeftEnd,
leftGridChain,
gridMidIndex2,
gridIndex2,
rightChain,
0, -1,
cornerRightDownStart,
rightEndIndex,
pStream);
sampleLeftStripRecF(leftChain,
midIndex1,
midIndex2,
leftGridChain,
gridMidIndex1,
gridMidIndex2,
pStream);
}
else
{
sampleLeftSingleTrimEdgeRegionGen(cornerTop, cornerBot,
leftChain,
cornerLeftStart,
cornerLeftEnd,
leftGridChain,
gridIndex1,
gridIndex2,
rightChain,
rightStartIndex,
cornerRightUpEnd,
cornerRightDownStart,
rightEndIndex,
pStream);
}
}
void sampleLeftSingleTrimEdgeRegionGen(Real topVert[2], Real botVert[2],
vertexArray* leftChain,
Int leftStart,
Int leftEnd,
gridBoundaryChain* gridChain,
Int gridBeginIndex,
Int gridEndIndex,
vertexArray* rightChain,
Int rightUpBegin,
Int rightUpEnd,
Int rightDownBegin,
Int rightDownEnd,
primStream* pStream)
{
Int i,j,k;
vertexArray vArray(gridEndIndex-gridBeginIndex+1 +
max(0,rightUpEnd - rightUpBegin+1)+
max(0,rightDownEnd - rightDownBegin+1));
for(i=rightUpBegin; i<= rightUpEnd; i++)
vArray.appendVertex(rightChain->getVertex(i));
vArray.appendVertex(gridChain->get_vertex(gridBeginIndex));
for(k=1, i=gridBeginIndex+1; i<=gridEndIndex; i++, k++)
{
vArray.appendVertex(gridChain->get_vertex(i));
if(gridChain->getUlineIndex(i) < gridChain->getUlineIndex(i-1))
{
pStream->begin();
pStream->insert(gridChain->get_vertex(i-1));
for(j=gridChain->getUlineIndex(i); j<= gridChain->getUlineIndex(i-1); j++)
pStream->insert(gridChain->getGrid()->get_u_value(j), gridChain->get_v_value(i));
pStream->end(PRIMITIVE_STREAM_FAN);
}
else if(gridChain->getUlineIndex(i) > gridChain->getUlineIndex(i-1))
{
pStream->begin();
pStream->insert(gridChain->get_vertex(i));
for(j=gridChain->getUlineIndex(i); j>= gridChain->getUlineIndex(i-1); j--)
pStream->insert(gridChain->getGrid()->get_u_value(j), gridChain->get_v_value(i-1));
pStream->end(PRIMITIVE_STREAM_FAN);
}
}
for(i=rightDownBegin; i<= rightDownEnd; i++)
vArray.appendVertex(rightChain->getVertex(i));
monoTriangulationRecGen(topVert, botVert,
leftChain, leftStart, leftEnd,
&vArray, 0, vArray.getNumElements()-1,
pStream);
}