41 #include "glimports.h"
44 #include "monoTriangulation.h"
46 #include "partitionX.h"
47 #include "monoPolyPart.h"
58 Int n_edges = poly->numEdges();
61 findInteriorCuspsX(poly, n_cusps, cusps);
64 monoTriangulationFun(poly, compV2InX, pStream);
69 directedLine* other = findDiagonal_singleCuspX(new_polygon);
75 monoTriangulationFun(poly, compV2InX, pStream);
82 new_polygon->connectDiagonal_2slines(new_polygon, other,
87 monoTriangulationFun(ret_p1, compV2InX, pStream);
88 monoTriangulationFun(ret_p2, compV2InX, pStream);
90 ret_p1->deleteSinglePolygonWithSline();
91 ret_p2->deleteSinglePolygonWithSline();
98 monoTriangulationFun(poly, compV2InY, pStream);
104 void monoTriangulationRecOpt(Real* topVertex, Real* botVertex,
110 Int n_left = left_chain->getNumElements();
111 Int n_right = right_chain->getNumElements();
112 if(left_current>= n_left-1 ||
113 right_current>= n_right-1)
115 monoTriangulationRec(topVertex, botVertex, left_chain, left_current,
116 right_chain, right_current, pStream);
120 Real left_v = left_chain->getVertex(left_current)[1];
121 Real right_v = right_chain->getVertex(right_current)[1];
123 if(left_v <= right_v)
126 for(j=right_current; j<=n_right-1; j++)
128 if(right_chain->getVertex(j)[1] < left_v)
131 monoTriangulationRecGen(topVertex, left_chain->getVertex(left_current),
132 left_chain, left_current, left_current,
133 right_chain, right_current, j-1,
135 monoTriangulationRecOpt(right_chain->getVertex(j-1),
137 left_chain, left_current,
144 for(i=left_current; i<=n_left-1; i++)
146 if(left_chain->getVertex(i)[1] <= right_v)
149 monoTriangulationRecGen(topVertex, right_chain->getVertex(right_current),
150 left_chain, left_current, i-1,
151 right_chain, right_current, right_current,
153 monoTriangulationRecOpt(left_chain->getVertex(i-1),
156 right_chain, right_current,
162 void monoTriangulationRecGenTBOpt(Real* topVertex, Real* botVertex,
163 vertexArray* inc_chain, Int inc_current, Int inc_end,
164 vertexArray* dec_chain, Int dec_current, Int dec_end,
167 pStream->triangle(topVertex, inc_chain->getVertex(inc_current), dec_chain->getVertex(dec_current));
170 triangulateXYMonoTB(inc_end-inc_current+1, inc_chain->getArray()+inc_current, dec_end-dec_current+1, dec_chain->getArray()+dec_current, pStream);
172 pStream->triangle(botVertex, dec_chain->getVertex(dec_end), inc_chain->getVertex(inc_end));
181 void triangulateXYMonoTB(Int n_left, Real** leftVerts,
182 Int n_right, Real** rightVerts,
190 assert(n_left>=1 && n_right>=1);
191 if(leftVerts[0][1] >= rightVerts[0][1])
195 topMostV = leftVerts[0];
201 topMostV = rightVerts[0];
212 pStream->insert(topMostV);
213 for(k=n_right-1; k>=j; k--)
214 pStream->insert(rightVerts[j]);
216 pStream->end(PRIMITIVE_STREAM_FAN);
228 pStream->insert(topMostV);
230 for(k=i; k<n_left; k++)
231 pStream->insert(leftVerts[k]);
233 pStream->end(PRIMITIVE_STREAM_FAN);
241 if(leftVerts[i][1] >= rightVerts[j][1])
244 pStream->insert(rightVerts[j]);
246 pStream->insert(topMostV);
254 if(leftVerts[k][1] < rightVerts[j][1])
261 pStream->insert(leftVerts[l]);
264 pStream->end(PRIMITIVE_STREAM_FAN);
267 topMostV = leftVerts[k];
273 pStream->insert(leftVerts[i]);
280 if(rightVerts[k][1] <= leftVerts[i][1])
287 pStream->insert(rightVerts[l]);
289 pStream->insert(topMostV);
290 pStream->end(PRIMITIVE_STREAM_FAN);
292 topMostV = rightVerts[j-1];
298 static int chainConvex(
vertexArray* inc_chain, Int inc_current, Int inc_end)
302 if(inc_current >= inc_end-1)
return 1;
303 for(i=inc_current; i<= inc_end-2; i++)
305 if(area(inc_chain->getVertex(i), inc_chain->getVertex(i+1), inc_chain->getVertex(i+2)) <0)
311 static int chainConcave(
vertexArray* dec_chain, Int dec_current, Int dec_end)
315 if(dec_current >= dec_end -1)
return 1;
316 for(i=dec_current; i<=dec_end-2; i++)
318 if(area(dec_chain->getVertex(i), dec_chain->getVertex(i+1), dec_chain->getVertex(i+2)) >0)
324 void monoTriangulationRecGenInU(Real* topVertex, Real* botVertex,
325 vertexArray* inc_chain, Int inc_current, Int inc_end,
326 vertexArray* dec_chain, Int dec_current, Int dec_end,
332 void monoTriangulationRecGenOpt(Real* topVertex, Real* botVertex,
333 vertexArray* inc_chain, Int inc_current, Int inc_end,
334 vertexArray* dec_chain, Int dec_current, Int dec_end,
343 if(inc_current <= inc_end)
345 sline =
new sampledLine(topVertex, inc_chain->getVertex(inc_current));
347 for(i=inc_current; i<=inc_end-1; i++)
349 sline =
new sampledLine(inc_chain->getVertex(i), inc_chain->getVertex(i+1));
353 sline =
new sampledLine(inc_chain->getVertex(inc_end), botVertex);
364 assert(poly != NULL);
366 if(dec_current <= dec_end)
368 sline =
new sampledLine(botVertex, dec_chain->getVertex(dec_end));
371 for(i=dec_end; i>dec_current; i--)
373 sline =
new sampledLine(dec_chain->getVertex(i), dec_chain->getVertex(i-1));
377 sline =
new sampledLine(dec_chain->getVertex(dec_current), topVertex);
390 Int n_edges = poly->numEdges();
393 findInteriorCuspsX(poly, n_cusps, cusps);
397 monoTriangulationFun(poly, compV2InX, pStream);
399 else if(n_cusps == 1)
402 directedLine* other = findDiagonal_singleCuspX(new_polygon);
408 monoTriangulationFun(poly, compV2InX, pStream);
415 new_polygon->connectDiagonal_2slines(new_polygon, other,
420 monoTriangulationFun(ret_p1, compV2InX, pStream);
421 monoTriangulationFun(ret_p2, compV2InX, pStream);
423 ret_p1->deleteSinglePolygonWithSline();
424 ret_p2->deleteSinglePolygonWithSline();
435 for(
directedLine* temp = list; temp != NULL; temp = temp->getNextPolygon())
437 monoTriangulationFun(temp, compV2InX, pStream);
440 list->deletePolygonListWithSline();
452 poly->deleteSinglePolygonWithSline();
458 if(inc_current > inc_end || dec_current>dec_end)
460 monoTriangulationRecGen(topVertex, botVertex, inc_chain, inc_current, inc_end,
461 dec_chain, dec_current, dec_end,
468 area(dec_chain->getVertex(dec_current),
470 inc_chain->getVertex(inc_current)) >=0
471 && chainConvex(inc_chain, inc_current, inc_end)
472 && chainConcave(dec_chain, dec_current, dec_end)
473 && area(inc_chain->getVertex(inc_end), botVertex, dec_chain->getVertex(dec_end)) >=0
476 monoTriangulationRecFunGen(topVertex, botVertex,
477 inc_chain, inc_current, inc_end,
478 dec_chain, dec_current, dec_end,
483 monoTriangulationRecGen(topVertex, botVertex, inc_chain, inc_current, inc_end,
484 dec_chain, dec_current, dec_end,
492 void monoTriangulationRecGen(Real* topVertex, Real* botVertex,
493 vertexArray* inc_chain, Int inc_current, Int inc_end,
494 vertexArray* dec_chain, Int dec_current, Int dec_end,
501 if(inc_current > inc_end && dec_current>dec_end)
503 else if(inc_current>inc_end)
505 dec_array = dec_chain->getArray();
508 rChain.processNewVertex(topVertex, pStream);
510 for(i=dec_current; i<=dec_end; i++){
511 rChain.processNewVertex(dec_array[i], pStream);
514 rChain.processNewVertex(botVertex, pStream);
516 else if(dec_current> dec_end)
518 inc_array = inc_chain->getArray();
522 rChain.processNewVertex(topVertex, pStream);
524 for(i=inc_current; i<=inc_end; i++){
525 rChain.processNewVertex(inc_array[i], pStream);
528 rChain.processNewVertex(botVertex, pStream);
532 inc_array = inc_chain -> getArray();
533 dec_array = dec_chain -> getArray();
538 if(compV2InY(inc_array[inc_current], dec_array[dec_current]) <= 0)
542 rChain.processNewVertex(topVertex, pStream);
543 for(i=dec_current; i<=dec_end; i++)
545 if(compV2InY(inc_array[inc_current], dec_array[i]) <= 0)
546 rChain.processNewVertex(dec_array[i], pStream);
550 rChain.outputFan(inc_array[inc_current], pStream);
551 monoTriangulationRecGen(dec_array[i-1], botVertex,
552 inc_chain, inc_current, inc_end,
553 dec_chain, i, dec_end,
560 rChain.processNewVertex(topVertex, pStream);
561 for(i=inc_current; i<=inc_end; i++)
563 if(compV2InY(inc_array[i], dec_array[dec_current]) >0)
564 rChain.processNewVertex(inc_array[i], pStream);
568 rChain.outputFan(dec_array[dec_current], pStream);
569 monoTriangulationRecGen(inc_array[i-1], botVertex,
570 inc_chain, i, inc_end,
571 dec_chain, dec_current,dec_end,
586 topV = botV = monoPolygon;
587 for(tempV = monoPolygon->getNext(); tempV != monoPolygon; tempV = tempV->getNext())
589 if(compFun(topV->head(), tempV->head())<0) {
592 if(compFun(botV->head(), tempV->head())>0) {
599 for(i=1; i<=topV->get_npoints()-2; i++) {
600 inc_chain.appendVertex(topV->getVertex(i));
602 for(tempV = topV->getNext(); tempV != botV; tempV = tempV->getNext())
604 for(i=0; i<=tempV->get_npoints()-2; i++){
605 inc_chain.appendVertex(tempV->getVertex(i));
610 for(tempV = topV->getPrev(); tempV != botV; tempV = tempV->getPrev())
612 for(i=tempV->get_npoints()-2; i>=0; i--){
613 dec_chain.appendVertex(tempV->getVertex(i));
616 for(i=botV->get_npoints()-2; i>=1; i--){
617 dec_chain.appendVertex(tempV->getVertex(i));
620 if (!(0 == inc_chain.getNumElements() && 0 == dec_chain.getNumElements())) {
621 monoTriangulationRecFun(topV->head(), botV->head(), &inc_chain, 0,
622 &dec_chain, 0, compFun, pStream);
635 topV = botV = monoPolygon;
636 for(tempV = monoPolygon->getNext(); tempV != monoPolygon; tempV = tempV->getNext())
638 if(compV2InY(topV->head(), tempV->head())<0) {
641 if(compV2InY(botV->head(), tempV->head())>0) {
647 for(i=1; i<=topV->get_npoints()-2; i++) {
648 inc_chain.appendVertex(topV->getVertex(i));
650 for(tempV = topV->getNext(); tempV != botV; tempV = tempV->getNext())
652 for(i=0; i<=tempV->get_npoints()-2; i++){
653 inc_chain.appendVertex(tempV->getVertex(i));
658 for(tempV = topV->getPrev(); tempV != botV; tempV = tempV->getPrev())
660 for(i=tempV->get_npoints()-2; i>=0; i--){
661 dec_chain.appendVertex(tempV->getVertex(i));
664 for(i=botV->get_npoints()-2; i>=1; i--){
665 dec_chain.appendVertex(tempV->getVertex(i));
668 monoTriangulationRec(topV->head(), botV->head(), &inc_chain, 0, &dec_chain, 0, pStream);
678 void monoTriangulation2(Real* topVertex, Real* botVertex,
681 Int is_increase_chain,
684 assert( inc_chain != NULL);
687 if(inc_smallIndex > inc_largeIndex)
689 if(inc_smallIndex == inc_largeIndex)
691 if(is_increase_chain)
692 pStream->triangle(inc_chain->getVertex(inc_smallIndex), botVertex, topVertex);
694 pStream->triangle(inc_chain->getVertex(inc_smallIndex), topVertex, botVertex);
699 if(is_increase_chain && botVertex[1] == inc_chain->getVertex(inc_largeIndex)[1])
701 pStream->triangle(botVertex, inc_chain->getVertex(inc_largeIndex-1),
702 inc_chain->getVertex(inc_largeIndex));
703 monoTriangulation2(topVertex, botVertex, inc_chain, inc_smallIndex,
709 else if( (!is_increase_chain) && topVertex[1] == inc_chain->getVertex(inc_smallIndex)[1])
711 pStream->triangle(topVertex, inc_chain->getVertex(inc_smallIndex+1),
712 inc_chain->getVertex(inc_smallIndex));
713 monoTriangulation2(topVertex, botVertex, inc_chain, inc_smallIndex+1,
714 inc_largeIndex, is_increase_chain, pStream);
718 inc_array = inc_chain->getArray();
722 rChain.processNewVertex(topVertex, pStream);
724 for(i=inc_smallIndex; i<=inc_largeIndex; i++){
725 rChain.processNewVertex(inc_array[i], pStream);
727 rChain.processNewVertex(botVertex, pStream);
734 void monoTriangulationRecFunGen(Real* topVertex, Real* botVertex,
735 vertexArray* inc_chain, Int inc_current, Int inc_end,
736 vertexArray* dec_chain, Int dec_current, Int dec_end,
737 Int (*compFun)(Real*, Real*),
740 assert( inc_chain != NULL && dec_chain != NULL);
741 assert( ! (inc_current> inc_end &&
742 dec_current> dec_end));
750 assert( ! ( (inc_chain==NULL) && (dec_chain==NULL)));
752 if(inc_current> inc_end)
755 dec_array = dec_chain->getArray();
758 rChain.processNewVertex(topVertex, pStream);
760 for(i=dec_current; i<=dec_end; i++){
761 rChain.processNewVertex(dec_array[i], pStream);
764 rChain.processNewVertex(botVertex, pStream);
767 else if(dec_current> dec_end)
769 inc_array = inc_chain->getArray();
772 rChain.processNewVertex(topVertex, pStream);
774 for(i=inc_current; i<=inc_end; i++){
775 rChain.processNewVertex(inc_array[i], pStream);
778 rChain.processNewVertex(botVertex, pStream);
782 inc_array = inc_chain -> getArray();
783 dec_array = dec_chain -> getArray();
788 if(compFun(inc_array[inc_current], dec_array[dec_current]) <= 0)
792 rChain.processNewVertex(topVertex, pStream);
793 for(i=dec_current; i<=dec_end; i++)
795 if(compFun(inc_array[inc_current], dec_array[i]) <= 0)
796 rChain.processNewVertex(dec_array[i], pStream);
800 rChain.outputFan(inc_array[inc_current], pStream);
801 monoTriangulationRecFunGen(dec_array[i-1], botVertex,
802 inc_chain, inc_current, inc_end,
803 dec_chain, i, dec_end,
811 rChain.processNewVertex(topVertex, pStream);
812 for(i=inc_current; i<=inc_end; i++)
814 if(compFun(inc_array[i], dec_array[dec_current]) >0)
815 rChain.processNewVertex(inc_array[i], pStream);
819 rChain.outputFan(dec_array[dec_current], pStream);
820 monoTriangulationRecFunGen(inc_array[i-1], botVertex,
821 inc_chain, i,inc_end,
822 dec_chain, dec_current,dec_end,
832 void monoTriangulationRecFun(Real* topVertex, Real* botVertex,
835 Int (*compFun)(Real*, Real*),
838 assert( inc_chain != NULL && dec_chain != NULL);
839 assert( ! (inc_current>=inc_chain->getNumElements() &&
840 dec_current>=dec_chain->getNumElements()));
846 assert( ! ( (inc_chain==NULL) && (dec_chain==NULL)));
848 if(inc_current>=inc_chain->getNumElements())
851 dec_array = dec_chain->getArray();
852 dec_nVertices = dec_chain->getNumElements();
855 rChain.processNewVertex(topVertex, pStream);
857 for(i=dec_current; i<dec_nVertices; i++){
858 rChain.processNewVertex(dec_array[i], pStream);
861 rChain.processNewVertex(botVertex, pStream);
864 else if(dec_current>= dec_chain->getNumElements())
866 inc_array = inc_chain->getArray();
867 inc_nVertices= inc_chain->getNumElements();
870 rChain.processNewVertex(topVertex, pStream);
872 for(i=inc_current; i<inc_nVertices; i++){
873 rChain.processNewVertex(inc_array[i], pStream);
876 rChain.processNewVertex(botVertex, pStream);
880 inc_array = inc_chain -> getArray();
881 dec_array = dec_chain -> getArray();
882 inc_nVertices= inc_chain->getNumElements();
883 dec_nVertices= dec_chain->getNumElements();
887 if(compFun(inc_array[inc_current], dec_array[dec_current]) <= 0)
891 rChain.processNewVertex(topVertex, pStream);
892 for(i=dec_current; i<dec_nVertices; i++)
894 if(compFun(inc_array[inc_current], dec_array[i]) <= 0)
895 rChain.processNewVertex(dec_array[i], pStream);
899 rChain.outputFan(inc_array[inc_current], pStream);
900 monoTriangulationRecFun(dec_array[i-1], botVertex,
901 inc_chain, inc_current,
910 rChain.processNewVertex(topVertex, pStream);
911 for(i=inc_current; i<inc_nVertices; i++)
913 if(compFun(inc_array[i], dec_array[dec_current]) >0)
914 rChain.processNewVertex(inc_array[i], pStream);
918 rChain.outputFan(dec_array[dec_current], pStream);
919 monoTriangulationRecFun(inc_array[i-1], botVertex,
921 dec_chain, dec_current,
929 void monoTriangulationRec(Real* topVertex, Real* botVertex,
934 assert( inc_chain != NULL && dec_chain != NULL);
935 assert( ! (inc_current>=inc_chain->getNumElements() &&
936 dec_current>=dec_chain->getNumElements()));
942 assert( ! ( (inc_chain==NULL) && (dec_chain==NULL)));
944 if(inc_current>=inc_chain->getNumElements())
947 dec_array = dec_chain->getArray();
948 dec_nVertices = dec_chain->getNumElements();
951 rChain.processNewVertex(topVertex, pStream);
953 for(i=dec_current; i<dec_nVertices; i++){
954 rChain.processNewVertex(dec_array[i], pStream);
957 rChain.processNewVertex(botVertex, pStream);
960 else if(dec_current>= dec_chain->getNumElements())
962 inc_array = inc_chain->getArray();
963 inc_nVertices= inc_chain->getNumElements();
966 rChain.processNewVertex(topVertex, pStream);
968 for(i=inc_current; i<inc_nVertices; i++){
969 rChain.processNewVertex(inc_array[i], pStream);
972 rChain.processNewVertex(botVertex, pStream);
976 inc_array = inc_chain -> getArray();
977 dec_array = dec_chain -> getArray();
978 inc_nVertices= inc_chain->getNumElements();
979 dec_nVertices= dec_chain->getNumElements();
983 if(compV2InY(inc_array[inc_current], dec_array[dec_current]) <= 0)
987 rChain.processNewVertex(topVertex, pStream);
988 for(i=dec_current; i<dec_nVertices; i++)
990 if(compV2InY(inc_array[inc_current], dec_array[i]) <= 0)
991 rChain.processNewVertex(dec_array[i], pStream);
995 rChain.outputFan(inc_array[inc_current], pStream);
996 monoTriangulationRec(dec_array[i-1], botVertex,
997 inc_chain, inc_current,
1005 rChain.processNewVertex(topVertex, pStream);
1006 for(i=inc_current; i<inc_nVertices; i++)
1008 if(compV2InY(inc_array[i], dec_array[dec_current]) >0)
1009 rChain.processNewVertex(inc_array[i], pStream);
1013 rChain.outputFan(dec_array[dec_current], pStream);
1014 monoTriangulationRec(inc_array[i-1], botVertex,
1016 dec_chain, dec_current,
1033 void monoTriangulationRec(
directedLine* inc_chain, Int inc_index,
1041 Int tempIndex, oldtempIndex = 0;
1043 assert(inc_chain != NULL && dec_chain != NULL);
1045 if(inc_chain == botVertex) {
1047 rChain.processNewVertex(topVertex->getVertex(top_index), pStream);
1048 for(i=dec_index; i< dec_chain->get_npoints(); i++){
1049 rChain.processNewVertex(dec_chain->getVertex(i), pStream);
1051 for(temp = dec_chain->getPrev(); temp != botVertex; temp = temp->getPrev())
1053 for(i=0; i<temp->get_npoints(); i++){
1054 rChain.processNewVertex(temp->getVertex(i), pStream);
1058 else if(dec_chain==botVertex) {
1060 rChain.processNewVertex(topVertex->getVertex(top_index), pStream);
1061 for(i=inc_index; i< inc_chain->get_npoints(); i++){
1062 rChain.processNewVertex(inc_chain->getVertex(i), pStream);
1064 for(temp = inc_chain->getPrev(); temp != botVertex; temp = temp->getNext())
1066 for(i=0; i<temp->get_npoints(); i++){
1067 rChain.processNewVertex(temp->getVertex(i), pStream);
1072 if(compV2InY(inc_chain->getVertex(inc_index), dec_chain->getVertex(dec_index)) <=0) {
1074 rChain.processNewVertex(topVertex -> getVertex(top_index), pStream);
1076 tempIndex = dec_index;
1077 while( compV2InY(inc_chain->getVertex(inc_index), temp->getVertex(tempIndex))<=0) {
1079 oldtempIndex = tempIndex;
1080 rChain.processNewVertex(temp->getVertex(tempIndex), pStream);
1082 if(tempIndex == temp->get_npoints()-1){
1084 temp = temp->getPrev();
1090 rChain.outputFan(inc_chain->getVertex(inc_index), pStream);
1091 monoTriangulationRec(inc_chain, inc_index, temp, tempIndex, oldtemp, oldtempIndex, botVertex, pStream);
1095 rChain.processNewVertex(topVertex -> getVertex(top_index), pStream);
1097 tempIndex = inc_index;
1098 while( compV2InY(temp->getVertex(tempIndex), dec_chain->getVertex(dec_index))>0){
1100 oldtempIndex = tempIndex;
1101 rChain.processNewVertex(temp->getVertex(tempIndex), pStream);
1103 if(tempIndex == temp->get_npoints()-1){
1105 temp = temp->getNext();
1111 rChain.outputFan(dec_chain->getVertex(dec_index), pStream);
1112 monoTriangulationRec(temp, tempIndex, dec_chain, dec_index, oldtemp, oldtempIndex, botVertex, pStream);
1118 vertexArray::vertexArray(Real2* vertices, Int nVertices)
1121 size = index = nVertices;
1122 array = (Real**) malloc(
sizeof(Real*) * nVertices);
1124 for(i=0; i<nVertices; i++)
1126 array[i] = vertices[i];
1127 array[i] = vertices[i];
1131 vertexArray::vertexArray(Int s)
1134 array = (Real**) malloc(
sizeof(Real*) * s);
1139 vertexArray::~vertexArray()
1144 void vertexArray::appendVertex(Real* ptr)
1148 Real** temp = (Real**) malloc(
sizeof(Real*) * (2*size +1));
1150 for(i=0; i<index; i++)
1156 array[index++] = ptr;
1159 void vertexArray::print()
1161 printf(
"vertex Array:index=%i, size=%i\n", index, size);
1162 for(Int i=0; i<index; i++)
1164 printf(
"(%f,%f) ", array[i][0], array[i][1]);
1175 Int vertexArray::findIndexAbove(Real v)
1180 else if(array[0][1] < v)
1184 for(i=1; i<index; i++)
1201 Int vertexArray::findIndexBelowGen(Real v, Int startIndex, Int endIndex)
1204 if(startIndex > endIndex)
1206 else if(array[endIndex][1] > v)
1210 for(i=endIndex-1; i>=startIndex; i--)
1227 Int vertexArray::findIndexStrictBelowGen(Real v, Int startIndex, Int endIndex)
1230 if(startIndex > endIndex)
1232 else if(array[endIndex][1] >= v)
1236 for(i=endIndex-1; i>=startIndex; i--)
1238 if(array[i][1] >= v)
1253 Int vertexArray::findIndexFirstAboveEqualGen(Real v, Int startIndex, Int endIndex)
1257 if(startIndex > endIndex)
1258 return startIndex-1;
1259 else if(array[startIndex][1] < v)
1260 return startIndex-1;
1264 for(i=startIndex; i<=endIndex; i++)
1266 if(array[i][1] <= v)
1271 else if(array[i][1] == v)
1288 Int vertexArray::findIndexAboveGen(Real v, Int startIndex, Int endIndex)
1291 if(startIndex > endIndex)
1292 return startIndex-1;
1293 else if(array[startIndex][1] < v)
1294 return startIndex-1;
1297 for(i=startIndex+1; i<=endIndex; i++)
1306 Int vertexArray::findDecreaseChainFromEnd(Int begin, Int end)
1309 Real prevU = array[i][0];
1311 for(i=end-1; i>=begin; i--){
1312 thisU = array[i][0];
1323 Int vertexArray::skipEqualityFromStart(Real v, Int start, Int end)
1326 if(array[start][1] != v)
1329 for(i=start+1; i<= end; i++)
1330 if(array[i][1] != v)
1342 reflexChain::reflexChain(Int size, Int is_increasing)
1344 queue = (Real2*) malloc(
sizeof(Real2) * size);
1348 isIncreasing = is_increasing;
1351 reflexChain::~reflexChain()
1359 void reflexChain::insert(Real u, Real v)
1362 if(index_queue >= size_queue) {
1363 Real2 *temp = (Real2*) malloc(
sizeof(Real2) * (2*size_queue+1));
1367 for(i=0; i<index_queue; i++){
1368 temp[i][0] = queue[i][0];
1369 temp[i][1] = queue[i][1];
1374 size_queue = 2*size_queue + 1;
1377 queue[index_queue][0] = u;
1378 queue[index_queue][1] = v;
1382 void reflexChain::insert(Real v[2])
1404 void reflexChain::outputFan(Real v[2],
primStream* pStream)
1410 for(i=0; i<index_queue; i++)
1411 pStream->insert(queue[i]);
1414 for(i=index_queue-1; i>=0; i--)
1415 pStream->insert(queue[i]);
1417 pStream->end(PRIMITIVE_STREAM_FAN);
1420 void reflexChain::processNewVertex(Real v[2],
primStream* pStream)
1426 if(index_queue <=1){
1434 for(i=j; i>=1; i--) {
1436 isReflex = (area(queue[i-1], queue[i], v) <= 0.0);
1439 isReflex = (area(v, queue[i], queue[i-1]) <= 0.0);
1457 pStream->insert(queue[k]);
1461 pStream->insert(queue[k]);
1464 pStream->end(PRIMITIVE_STREAM_FAN);
1474 void reflexChain::print()
1477 printf(
"reflex chain: isIncreasing=%i\n", isIncreasing);
1478 for(i=0; i<index_queue; i++) {
1479 printf(
"(%f,%f) ", queue[i][0], queue[i][1]);