43#define GLCALLBACK(x) (( void (CALLBACK*)() )&(x))
48static void FormatDoublet(
double x,
double y,
int precision, std::string& strx, std::string& stry )
50 std::ostringstream ostr;
52 ostr << std::fixed << std::setprecision( precision );
61 while( *strx.rbegin() ==
'0' )
62 strx.erase( strx.size() - 1 );
64 while( *stry.rbegin() ==
'0' )
65 stry.erase( stry.size() - 1 );
71 std::ostringstream ostr;
73 ostr << std::fixed << std::setprecision( precision );
78 while( *strx.rbegin() ==
'0' )
79 strx.erase( strx.size() - 1 );
98 if( csides < 2 * maxSeg )
107 if( ( csides & 1 ) == 0 )
148 GLfloat weight[4],
void** outData,
void* user_data )
153 bool plated = vertex_data[0]->
pth;
155 if( !vertex_data[1]->pth )
158 if( vertex_data[2] && !vertex_data[2]->pth )
161 if( vertex_data[3] && !vertex_data[3]->pth )
199 gluTessProperty(
tess, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_POSITIVE );
201 gluTessNormal(
tess, 0, 0, 1 );
211 gluDeleteTess(
tess );
239 if( aMinLength <= 0 || aMaxLength <= aMinLength )
256 for( i =
contours.size(); i > 0; --i )
266 for( i =
vertices.size(); i > 0; --i )
289 for( i =
outline.size(); i > 0; --i )
308 for( i = 0; i <
vertices.size(); ++i )
320 std::list<int>* contour =
new std::list<int>;
323 areas.push_back( 0.0 );
325 pth.push_back( aPlatedHole );
335 error =
"AddVertex(): no more vertices may be added (Tesselate was previously executed)";
339 if( aContourID < 0 || (
unsigned int) aContourID >=
contours.size() )
341 error =
"AddVertex(): aContour is not within a valid range";
350 vertex->
pth =
pth[ aContourID ];
354 if(
contours[aContourID]->size() > 0 )
358 contours[aContourID]->push_back( vertex->
i );
361 areas[aContourID] += ( aXpos -
v2->x ) * ( aYpos +
v2->y );
369 if( aContourID < 0 || (
unsigned int) aContourID >=
contours.size() )
371 error =
"EnsureWinding(): aContour is outside the valid range";
375 std::list<int>* cp =
contours[aContourID];
379 error =
"EnsureWinding(): there are fewer than 3 vertices";
383 double dir =
areas[aContourID];
388 dir += ( vp1->
x - vp0->
x ) * ( vp1->
y + vp0->
y );
391 if( ( aHoleFlag && dir < 0 ) || ( !aHoleFlag && dir > 0 ) )
404 if( aContourID < 0 || (
unsigned int) aContourID >=
contours.size() )
406 error =
"AppendCircle(): invalid contour (out of range)";
432 double da =
M_PI * 2.0 / nsides;
438 fail |= !
AddVertex( aContourID, aXpos + aRadius, aYpos );
440 for(
double angle = da; angle <
M_PI * 2; angle += da )
442 fail |= !
AddVertex( aContourID, aXpos + aRadius * cos( angle ),
443 aYpos - aRadius * sin( angle ) );
448 fail |= !
AddVertex( aContourID, aXpos + aRadius, aYpos );
450 for(
double angle = da; angle <
M_PI * 2; angle += da )
452 fail |= !
AddVertex( aContourID, aXpos + aRadius * cos( angle ),
453 aYpos + aRadius * sin( angle ) );
466 if( aHoleFlag && aPlatedHole )
473 error =
"AddCircle(): failed to add a contour";
482 double aAngle,
bool aHoleFlag,
bool aPlatedHole )
484 aAngle *=
M_PI / 180.0;
486 if( aSlotWidth > aSlotLength )
489 std::swap( aSlotLength, aSlotWidth );
493 aSlotLength = aSlotLength / 2.0 - aSlotWidth;
499 capx = aCenterX + cos( aAngle ) * aSlotLength;
500 capy = aCenterY + sin( aAngle ) * aSlotLength;
506 if( aHoleFlag && aPlatedHole )
513 error =
"AddCircle(): failed to add a contour";
522 for( ang = aAngle +
M_PI2, i = 0; i < csides; ang -= da, ++i )
523 fail |= !
AddVertex(
pad, capx + aSlotWidth * cos( ang ),
524 capy + aSlotWidth * sin( ang ) );
526 ang = aAngle -
M_PI2;
527 fail |= !
AddVertex(
pad, capx + aSlotWidth * cos( ang ),
528 capy + aSlotWidth * sin( ang ) );
530 capx = aCenterX - cos( aAngle ) * aSlotLength;
531 capy = aCenterY - sin( aAngle ) * aSlotLength;
533 for( ang = aAngle -
M_PI2, i = 0; i < csides; ang -= da, ++i )
534 fail |= !
AddVertex(
pad, capx + aSlotWidth * cos( ang ),
535 capy + aSlotWidth * sin( ang ) );
537 ang = aAngle +
M_PI2;
538 fail |= !
AddVertex(
pad, capx + aSlotWidth * cos( ang ),
539 capy + aSlotWidth * sin( ang ) );
543 for( ang = aAngle -
M_PI2, i = 0; i < csides; ang += da, ++i )
544 fail |= !
AddVertex(
pad, capx + aSlotWidth * cos( ang ),
545 capy + aSlotWidth * sin( ang ) );
547 ang = aAngle +
M_PI2;
548 fail |= !
AddVertex(
pad, capx + aSlotWidth * cos( ang ),
549 capy + aSlotWidth * sin( ang ) );
551 capx = aCenterX - cos( aAngle ) * aSlotLength;
552 capy = aCenterY - sin( aAngle ) * aSlotLength;
554 for( ang = aAngle +
M_PI2, i = 0; i < csides; ang += da, ++i )
555 fail |= !
AddVertex(
pad, capx + aSlotWidth * cos( ang ),
556 capy + aSlotWidth * sin( ang ) );
558 ang = aAngle -
M_PI2;
559 fail |= !
AddVertex(
pad, capx + aSlotWidth * cos( ang ),
560 capy + aSlotWidth * sin( ang ) );
568 double aCenterY,
double aAngle )
574 error =
"AddPolygon(): failed to add a contour";
578 for(
auto corner : aPolySet )
582 AddVertex(
pad, aCenterX + corner.x, aCenterY + corner.y );
594 double aStartAngle,
double aAngle,
int aContourID )
596 if( aContourID < 0 || (
unsigned int) aContourID >=
contours.size() )
598 error =
"AppendArc(): invalid contour (out of range)";
602 aAngle = aAngle / 180.0 *
M_PI;
603 aStartAngle = aStartAngle / 180.0 *
M_PI;
607 double da = aAngle / nsides;
613 aAngle += aStartAngle;
615 for(
double ang = aStartAngle; ang < aAngle; ang += da )
617 fail |= !
AddVertex( aContourID, aCenterX + aRadius * cos( ang ),
618 aCenterY + aRadius * sin( ang ) );
623 aAngle += aStartAngle;
625 for(
double ang = aStartAngle; ang > aAngle; ang += da )
627 fail |= !
AddVertex( aContourID, aCenterX + aRadius * cos( ang ),
628 aCenterY + aRadius * sin( ang ) );
637 double aArcWidth,
double aAngle,
bool aHoleFlag,
bool aPlatedHole )
639 aAngle *=
M_PI / 180.0;
643 if( aAngle < 0.01745 && aAngle > -0.01745 )
645 error =
"AddArc(): angle is too small: abs( angle ) < 1 degree";
649 double rad = sqrt( (aStartX - aCenterX) * (aStartX - aCenterX)
650 + (aStartY - aCenterY) * (aStartY - aCenterY) );
657 if( aArcWidth >= ( rad * 1.01 ) )
659 error =
"AddArc(): width/2 exceeds radius*1.01";
664 double orad = rad + aArcWidth;
665 double irad = rad - aArcWidth;
671 double stAngle = atan2( aStartY - aCenterY, aStartX - aCenterX );
672 double endAngle = stAngle + aAngle;
675 double oendx = aCenterX + orad* cos( endAngle );
676 double oendy = aCenterY + orad* sin( endAngle );
677 double ostx = aCenterX + orad* cos( stAngle );
678 double osty = aCenterY + orad* sin( stAngle );
680 double iendx = aCenterX + irad* cos( endAngle );
681 double iendy = aCenterY + irad* sin( endAngle );
682 double istx = aCenterX + irad* cos( stAngle );
683 double isty = aCenterY + irad* sin( stAngle );
685 if( ( aAngle < 0 && !aHoleFlag ) || ( aAngle > 0 && aHoleFlag ) )
688 std::swap( stAngle, endAngle );
689 std::swap( oendx, ostx );
690 std::swap( oendy, osty );
691 std::swap( iendx, istx );
692 std::swap( iendy, isty );
697 if( aHoleFlag && aPlatedHole )
704 error =
"AddArc(): could not create a contour";
711 double da = aAngle / osides;
713 for( ang = stAngle, i = 0; i < osides; ang += da, ++i )
714 AddVertex( arc, aCenterX + orad * cos( ang ), aCenterY + orad * sin( ang ) );
717 double capx = ( iendx + oendx ) / 2.0;
718 double capy = ( iendy + oendy ) / 2.0;
725 for( ang = endAngle, i = 0; i < csides; ang += da, ++i )
726 AddVertex( arc, capx + aArcWidth * cos( ang ), capy + aArcWidth * sin( ang ) );
729 da = -aAngle / isides;
731 for( ang = endAngle, i = 0; i < isides; ang += da, ++i )
732 AddVertex( arc, aCenterX + irad * cos( ang ), aCenterY + irad * sin( ang ) );
735 capx = ( istx + ostx ) / 2.0;
736 capy = ( isty + osty ) / 2.0;
743 for( ang = stAngle +
M_PI, i = 0; i < csides; ang += da, ++i )
744 AddVertex( arc, capx + aArcWidth * cos( ang ), capy + aArcWidth * sin( ang ) );
754 error =
"Tesselate(): GLU tesselator was not initialized";
762 gluTessProperty(
tess, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_NEGATIVE );
764 gluTessProperty(
tess, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_POSITIVE );
769 error =
"Tesselate(): not enough vertices";
776 for(
unsigned int i = 0; i <
contours.size(); ++i )
783 areas[i] += ( vp1->
x - vp0->
x ) * ( vp1->
y + vp0->
y );
794 gluTessProperty(
tess, GLU_TESS_BOUNDARY_ONLY, GL_TRUE );
806 error =
"tesselate(): no hole contours";
811 error =
"tesselate(): no solid contours";
816 gluTessBeginPolygon(
tess,
this );
827 gluTessEndPolygon(
tess );
839 gluTessEndPolygon(
tess );
847 error =
"tesselate(): no points in result";
852 gluTessBeginPolygon(
tess,
this );
863 std::ostringstream ostr;
864 ostr <<
"Tesselate():FAILED: " << holes->
GetError();
884 for(
unsigned int i = 0; i <
vertices.size(); ++i )
889 for(
unsigned int i = 0; i <
extra_verts.size(); ++i )
897 gluTessEndPolygon(
tess );
901 gluTessProperty(
tess, GLU_TESS_BOUNDARY_ONLY, GL_FALSE );
903 gluTessBeginPolygon(
tess,
this );
908 gluTessEndPolygon(
tess );
922 error =
"pushOutline() failed: no vertices to push";
926 std::list<std::list<int>*>::const_iterator obeg =
outline.begin();
927 std::list<std::list<int>*>::const_iterator oend =
outline.end();
932 std::list<int>::const_iterator begin;
933 std::list<int>::const_iterator
end;
937 while( obeg != oend )
939 if( (*obeg)->size() < 3 )
945 gluTessBeginContour(
tess );
947 begin = (*obeg)->begin();
948 end = (*obeg)->end();
950 while( begin !=
end )
954 if( pi < 0 || (
unsigned int) pi >
ordmap.size() )
956 gluTessEndContour(
tess );
957 error =
"pushOutline():BUG: *outline.begin() is not a valid index to ordmap";
968 gluTessEndContour(
tess );
969 error =
"pushOutline():: BUG: ordmap[n] is not a valid index to vertices[]";
976 gluTessVertex(
tess, pt, vp );
980 gluTessEndContour(
tess );
987 error =
"pushOutline():: no valid contours available";
999 error =
"WriteVertices(): not enough vertices";
1003 if( aPrecision < 4 )
1013 std::string strx, stry, strz;
1017 aOutFile << strx <<
" " << stry <<
" " << strz;
1019 for( i = 1, j =
ordmap.size(); i < j; ++i )
1029 aOutFile <<
", " << strx <<
" " << stry <<
" " << strz;
1031 aOutFile <<
",\n" << strx <<
" " << stry <<
" " << strz;
1034 return !aOutFile.fail();
1043 error =
"Write3DVertices(): insufficient vertices";
1047 if( aPrecision < 4 )
1050 if( aTopZ <= aBottomZ )
1052 error =
"Write3DVertices(): top <= bottom";
1063 std::string strx, stry, strz;
1067 aOutFile << strx <<
" " << stry <<
" " << strz;
1069 for( i = 1, j =
ordmap.size(); i < j; ++i )
1079 aOutFile <<
", " << strx <<
" " << stry <<
" " << strz;
1081 aOutFile <<
",\n" << strx <<
" " << stry <<
" " << strz;
1093 aOutFile <<
", " << strx <<
" " << stry <<
" " << strz;
1098 aOutFile <<
",\n" << strx <<
" " << stry <<
" " << strz;
1102 for( i = 1, j =
ordmap.size(); i < j; ++i )
1109 aOutFile <<
", " << strx <<
" " << stry <<
" " << strz;
1114 aOutFile <<
",\n" << strx <<
" " << stry <<
" " << strz;
1119 return !aOutFile.fail();
1127 error =
"WriteIndices(): no triplets (triangular facets) to write";
1132 std::list<TRIPLET_3D>::const_iterator tbeg =
triplets.begin();
1133 std::list<TRIPLET_3D>::const_iterator tend =
triplets.end();
1138 aOutFile << tbeg->i1 <<
", " << tbeg->i2 <<
", " << tbeg->i3 <<
", -1";
1140 aOutFile << tbeg->i2 <<
", " << tbeg->i1 <<
", " << tbeg->i3 <<
", -1";
1144 while( tbeg != tend )
1146 if( (i++ & 7) == 4 )
1151 aOutFile <<
",\n" << tbeg->i1 <<
", " << tbeg->i2 <<
", " << tbeg->i3 <<
", -1";
1153 aOutFile <<
",\n" << tbeg->i2 <<
", " << tbeg->i1 <<
", " << tbeg->i3 <<
", -1";
1158 aOutFile <<
", " << tbeg->i1 <<
", " << tbeg->i2 <<
", " << tbeg->i3 <<
", -1";
1160 aOutFile <<
", " << tbeg->i2 <<
", " << tbeg->i1 <<
", " << tbeg->i3 <<
", -1";
1166 return !aOutFile.fail();
1174 error =
"WriteIndices(): no outline available";
1179 bool holes_only =
triplets.empty();
1182 int idx2 =
ordmap.size();
1189 std::list<TRIPLET_3D>::const_iterator tbeg =
triplets.begin();
1190 std::list<TRIPLET_3D>::const_iterator tend =
triplets.end();
1193 aOutFile << tbeg->i1 <<
", " << tbeg->i2 <<
", " << tbeg->i3 <<
", -1";
1196 while( tbeg != tend )
1198 if( (i++ & 7) == 4 )
1201 aOutFile <<
",\n" << tbeg->i1 <<
", " << tbeg->i2 <<
", " << tbeg->i3 <<
", -1";
1205 aOutFile <<
", " << tbeg->i1 <<
", " << tbeg->i2 <<
", " << tbeg->i3 <<
", -1";
1214 while( tbeg != tend )
1216 if( ( i++ & 7 ) == 4 )
1220 << ( tbeg->i2 + idx2 ) <<
", " << ( tbeg->i1 + idx2 ) <<
", "
1221 << ( tbeg->i3 + idx2 ) <<
", -1";
1225 aOutFile <<
", " << ( tbeg->i2 + idx2 ) <<
", " << ( tbeg->i1 + idx2 ) <<
", "
1226 << ( tbeg->i3 + idx2 ) <<
", -1";
1240 std::list<std::list<int>*>::const_iterator obeg =
outline.begin();
1241 std::list<std::list<int>*>::const_iterator oend =
outline.end();
1243 std::list<int>::const_iterator cbeg;
1244 std::list<int>::const_iterator cend;
1248 while( obeg != oend )
1252 if( cp->size() < 3 )
1261 lastPoint = *(cbeg++);
1264 if( !aIncludePlatedHoles && !
solid[curContour]
1272 while( cbeg != cend )
1274 curPoint = *(cbeg++);
1278 if( ( i++ & 3 ) == 2 )
1281 aOutFile << mark <<
"\n"
1282 << curPoint <<
", " << lastPoint <<
", " << curPoint + idx2;
1283 aOutFile <<
", -1, " << curPoint + idx2 <<
", " << lastPoint <<
", "
1284 << lastPoint + idx2 <<
", -1";
1288 aOutFile << mark <<
" " << curPoint <<
", " << lastPoint <<
", "
1290 aOutFile <<
", -1, " << curPoint + idx2 <<
", " << lastPoint <<
", "
1291 << lastPoint + idx2 <<
", -1";
1296 if( (i++ & 3) == 2 )
1299 aOutFile << mark <<
"\n"
1300 << curPoint <<
", " << curPoint + idx2 <<
", " << lastPoint;
1301 aOutFile <<
", -1, " << curPoint + idx2 <<
", " << lastPoint + idx2 <<
", "
1302 << lastPoint <<
", -1";
1306 aOutFile << mark <<
" " << curPoint <<
", " << curPoint + idx2 <<
", "
1308 aOutFile <<
", -1, " << curPoint + idx2 <<
", " << lastPoint + idx2 <<
", "
1309 << lastPoint <<
", -1";
1314 lastPoint = curPoint;
1322 lastPoint = *(cend);
1326 if( ( i++ & 3 ) == 2 )
1328 aOutFile <<
",\n" << curPoint <<
", " << lastPoint <<
", " << curPoint + idx2;
1329 aOutFile <<
", -1, " << curPoint + idx2 <<
", " << lastPoint <<
", "
1330 << lastPoint + idx2 <<
", -1";
1334 aOutFile <<
", " << curPoint <<
", " << lastPoint <<
", " << curPoint + idx2;
1335 aOutFile <<
", -1, " << curPoint + idx2 <<
", " << lastPoint <<
", "
1336 << lastPoint + idx2 <<
", -1";
1341 if( ( i++ & 3 ) == 2 )
1343 aOutFile <<
",\n" << curPoint <<
", " << curPoint + idx2 <<
", " << lastPoint;
1344 aOutFile <<
", -1, " << curPoint + idx2 <<
", " << lastPoint + idx2 <<
", "
1345 << lastPoint <<
", -1";
1349 aOutFile <<
", " << curPoint <<
", " << curPoint + idx2 <<
", " << lastPoint;
1350 aOutFile <<
", -1, " << curPoint + idx2 <<
", " << lastPoint + idx2 <<
", "
1351 << lastPoint <<
", -1";
1359 return !aOutFile.fail();
1365 double dx0 = p1->
x - p0->
x;
1366 double dx1 = p2->
x - p0->
x;
1367 double dx2 = p2->
x - p1->
x;
1369 double dy0 = p1->
y - p0->
y;
1370 double dy1 = p2->
y - p0->
y;
1371 double dy2 = p2->
y - p1->
y;
1383 double err = 0.000000001;
1386 if( ( dx0 + dy0 ) < err )
1389 if( ( dx1 + dy1 ) < err )
1392 if( ( dx2 + dy2 ) < err )
1412 vertex->
pth = aPlatedHole;
1424 while( !
vlist.empty() )
1434 ordmap.push_back( vertex->
i );
1437 vlist.push_back( vertex );
1448 std::list<int>* loop =
new std::list<int>;
1450 double firstX = 0.0;
1451 double firstY = 0.0;
1457 if(
vlist.size() > 0 )
1459 loop->push_back(
vlist[0]->o );
1460 firstX =
vlist[0]->x;
1461 firstY =
vlist[0]->y;
1466 for(
size_t i = 1; i <
vlist.size(); ++i )
1468 loop->push_back(
vlist[i]->o );
1471 area += ( curX - lastX ) * ( curY + lastY );
1476 area += ( firstX - lastX ) * ( firstY + lastY );
1481 solid.push_back(
true );
1483 solid.push_back(
false );
1488 case GL_TRIANGLE_FAN:
1492 case GL_TRIANGLE_STRIP:
1504 while( !
vlist.empty() )
1513 const char * msg = (
const char*)gluErrorString( errorID );
1523 std::ostringstream ostr;
1524 ostr <<
"Unknown OpenGL error: " << errorID;
1532 if(
vlist.size() < 3 )
1540 for( i = 2; i <
end; ++i )
1556 if(
vlist.size() < 3 )
1563 for( i = 2; i <
end; ++i )
1585 if(
vlist.size() < 3 )
1591 for( i = 2; i <
end; i += 3 )
1603 for(
size_t i = 0; i <
contours.size(); ++i )
1608 if( ( holes &&
areas[i] <= 0.0 ) || ( !holes &&
areas[i] > 0.0 ) )
1623 std::list<int>::const_iterator begin;
1624 std::list<int>::const_iterator
end;
1628 for( i = 0; i <
contours.size(); ++i )
1633 if( ( holes &&
areas[i] <= 0.0 ) || ( !holes &&
areas[i] > 0.0 ) )
1636 gluTessBeginContour(
tess );
1641 while( begin !=
end )
1647 gluTessVertex(
tess, pt, vp );
1651 gluTessEndContour(
tess );
1660 if( aPointIndex < 0 || (
unsigned int) aPointIndex >= (
idx +
hidx +
extra_verts.size() ) )
1662 error =
"getVertexByIndex():BUG: invalid index";
1666 if( aPointIndex <
idx )
1671 else if( aPointIndex >=
idx +
hidx )
1680 error =
"getVertexByIndex():BUG: invalid index";
1688 std::ostringstream ostr;
1689 ostr <<
"getVertexByIndex():FAILED: " << holes->
GetError();
1708 error =
"Import(): invalid index ( start < 0 )";
1714 error =
"Import(): NULL tesselator pointer";
1721 for( i = 0, j =
vertices.size(); i < j; ++i )
1731 std::list<int>::const_iterator cbeg;
1732 std::list<int>::const_iterator cend;
1734 for( i = 0; i <
contours.size(); ++i )
1742 gluTessBeginContour( aTesselator );
1744 while( cbeg != cend )
1750 gluTessVertex( aTesselator, pt, vp );
1753 gluTessEndContour( aTesselator );
1764 if( aPointIndex < i0 || aPointIndex >= ( i0 + (
int)
vertices.size() ) )
1766 error =
"GetVertexByIndex(): invalid index";
1789 std::vector< int > &aIndexPlane, std::vector< int > &aIndexSide,
1790 double aTopZ,
double aBotZ )
1792 aVertexList.clear();
1793 aIndexPlane.clear();
1799 if( aTopZ <= aBotZ )
1812 size_t vsize =
ordmap.size();
1815 for( i = 0; i < vsize; ++i )
1821 aVertexList.clear();
1825 aVertexList.push_back( vp->
x +
offsetX );
1826 aVertexList.push_back( vp->
y +
offsetY );
1827 aVertexList.push_back( aTopZ );
1831 for( i = 0; i < vsize; ++i )
1835 aVertexList.push_back( vp->
x +
offsetX );
1836 aVertexList.push_back( vp->
y +
offsetY );
1837 aVertexList.push_back( aBotZ );
1843 bool holes_only =
triplets.empty();
1848 std::list< TRIPLET_3D >::const_iterator tbeg =
triplets.begin();
1849 std::list< TRIPLET_3D >::const_iterator tend =
triplets.end();
1851 std::vector< int > aIndexBot;
1853 while( tbeg != tend )
1856 aIndexPlane.push_back( (
int) tbeg->i1 );
1857 aIndexPlane.push_back( (
int) tbeg->i2 );
1858 aIndexPlane.push_back( (
int) tbeg->i3 );
1861 aIndexBot.push_back( (
int) ( tbeg->i2 + vsize ) );
1862 aIndexBot.push_back( (
int) ( tbeg->i1 + vsize ) );
1863 aIndexBot.push_back( (
int) ( tbeg->i3 + vsize ) );
1868 aIndexPlane.insert( aIndexPlane.end(), aIndexBot.begin(), aIndexBot.end() );
1875 std::list< std::list< int >* >::const_iterator obeg =
outline.begin();
1876 std::list< std::list< int >* >::const_iterator oend =
outline.end();
1877 std::list< int >* cp;
1878 std::list< int >::const_iterator cbeg;
1879 std::list< int >::const_iterator cend;
1883 while( obeg != oend )
1887 if( cp->size() < 3 )
1895 lastPoint = *(cbeg++);
1897 while( cbeg != cend )
1899 curPoint = *(cbeg++);
1903 aIndexSide.push_back( curPoint );
1904 aIndexSide.push_back( lastPoint );
1905 aIndexSide.push_back( (
int)( curPoint + vsize ) );
1907 aIndexSide.push_back( (
int)( curPoint + vsize ) );
1908 aIndexSide.push_back( lastPoint );
1909 aIndexSide.push_back( (
int)( lastPoint + vsize ) );
1913 aIndexSide.push_back( curPoint );
1914 aIndexSide.push_back( (
int)( curPoint + vsize ) );
1915 aIndexSide.push_back( lastPoint );
1917 aIndexSide.push_back( (
int)( curPoint + vsize ) );
1918 aIndexSide.push_back( (
int)( lastPoint + vsize ) );
1919 aIndexSide.push_back( lastPoint );
1922 lastPoint = curPoint;
1930 lastPoint = *(cend);
1934 aIndexSide.push_back( curPoint );
1935 aIndexSide.push_back( lastPoint );
1936 aIndexSide.push_back( (
int)( curPoint + vsize ) );
1938 aIndexSide.push_back( (
int)( curPoint + vsize ) );
1939 aIndexSide.push_back( lastPoint );
1940 aIndexSide.push_back( (
int)( lastPoint + vsize ) );
1944 aIndexSide.push_back( curPoint );
1945 aIndexSide.push_back( (
int)( curPoint + vsize ) );
1946 aIndexSide.push_back( lastPoint );
1948 aIndexSide.push_back( (
int)( curPoint + vsize ) );
1949 aIndexSide.push_back( (
int)( lastPoint + vsize ) );
1950 aIndexSide.push_back( lastPoint );
1961 std::vector< int > &aIndexPlane,
double aHeight,
bool aTopPlane )
1963 aVertexList.clear();
1964 aIndexPlane.clear();
1975 size_t vsize =
ordmap.size();
1978 for( i = 0; i < vsize; ++i )
1984 aVertexList.clear();
1988 aVertexList.push_back( vp->
x +
offsetX );
1989 aVertexList.push_back( vp->
y +
offsetY );
1990 aVertexList.push_back( aHeight );
2000 std::list< TRIPLET_3D >::const_iterator tbeg =
triplets.begin();
2001 std::list< TRIPLET_3D >::const_iterator tend =
triplets.end();
2005 while( tbeg != tend )
2008 aIndexPlane.push_back( (
int) tbeg->i1 );
2009 aIndexPlane.push_back( (
int) tbeg->i2 );
2010 aIndexPlane.push_back( (
int) tbeg->i3 );
2017 while( tbeg != tend )
2020 aIndexPlane.push_back( (
int) ( tbeg->i2 ) );
2021 aIndexPlane.push_back( (
int) ( tbeg->i1 ) );
2022 aIndexPlane.push_back( (
int) ( tbeg->i3 ) );
void GetArcParams(int &aMaxSeg, double &aMinLength, double &aMaxLength)
Retrieve the parameters used in calculating the number of vertices in an arc.
std::vector< double > areas
bool AddSlot(double aCenterX, double aCenterY, double aSlotLength, double aSlotWidth, double aAngle, bool aHoleFlag=false, bool aPlatedHole=false)
Create and add a slot feature to the list of contours.
bool AddPolygon(const std::vector< wxRealPoint > &aPolySet, double aCenterX, double aCenterY, double aAngle)
Create an arbitrary polygon and adds it to the list of contours.
int Import(int start, GLUtesselator *aTesselator)
Inserts all contours into the given tesselator.
bool WriteIndices(bool aTopFlag, std::ostream &aOutFile)
Write out the vertex sets required to render a planar surface.
void ResetArcParams()
Reset the parameters used in calculating the number of vertices in an arc to default values.
std::vector< bool > solid
std::vector< std::list< int > * > contours
bool Tesselate(VRML_LAYER *holes=NULL, bool aHolesOnly=false)
Create a list of outline vertices as well as the vertex sets required to render the surface.
void glStart(GLenum cmd)
Invoked by the GLU tesselator callback to notify this object of the type of GL command which is appli...
bool SetArcParams(int aMaxSeg, double aMinLength, double aMaxLength)
Set the parameters used in calculating the number of vertices in an arc.
std::vector< VERTEX_3D * > extra_verts
bool Fault
set to true when a fault is encountered during tesselation
void SetVertexOffsets(double aXoffset, double aYoffset)
bool Get3DTriangles(std::vector< double > &aVertexList, std::vector< int > &aIndexPlane, std::vector< int > &aIndexSide, double aTopZ, double aBotZ)
Allocate and populate the 3D vertex and index lists with triangular vertices which may be used for re...
bool Write3DIndices(std::ostream &aOutFile, bool aIncludePlatedHoles=false)
Write out the vertex sets required to render an extruded solid.
bool WriteVertices(double aZcoord, std::ostream &aOutFile, int aPrecision)
Write out the list of vertices required to render a planar surface.
bool EnsureWinding(int aContourID, bool aHoleFlag)
Check the winding of a contour and ensures that it is a hole or a solid depending on the value of.
bool addTriplet(VERTEX_3D *p0, VERTEX_3D *p1, VERTEX_3D *p2)
bool AddCircle(double aXpos, double aYpos, double aRadius, bool aHoleFlag=false, bool aPlatedHole=false)
Create a circular contour and adds it to the internal list.
bool AddArc(double aCenterX, double aCenterY, double aStartX, double aStartY, double aArcWidth, double aAngle, bool aHoleFlag=false, bool aPlatedHole=false)
Create a slotted arc and adds it to the internal list of contours.
void SetGLError(GLenum error_id)
Set the error message according to the specified OpenGL error.
bool Get2DTriangles(std::vector< double > &aVertexList, std::vector< int > &aIndexPlane, double aHeight, bool aTopPlane)
Allocate and populate the 3D vertex and index lists with triangular vertices which may be used for re...
bool AppendCircle(double aXpos, double aYpos, double aRadius, int aContourID, bool aHoleFlag=false)
Add a circular contour to the specified (empty) contour.
bool pushOutline(VRML_LAYER *holes)
bool Write3DVertices(double aTopZ, double aBottomZ, std::ostream &aOutFile, int aPrecision)
Write out the list of vertices required to render an extruded solid.
VERTEX_3D * getVertexByIndex(int aPointIndex, VRML_LAYER *holes)
int checkNContours(bool holes)
void glEnd(void)
Invoked by the GLU tesselator callback to notify this object that the vertex list is complete and rea...
std::vector< int > ordmap
std::list< TRIPLET_3D > triplets
int NewContour(bool aPlatedHole=false)
Create a new list of vertices and returns an index to the list.
VERTEX_3D * AddExtraVertex(double aXpos, double aYpos, bool aPlatedHole)
Add an extra vertex as required by the GLU tesselator.
std::vector< VERTEX_3D * > vertices
std::list< std::list< int > * > outline
const std::string & GetError(void)
int calcNSides(double aRadius, double aAngle)
void glPushVertex(VERTEX_3D *vertex)
Invoked by the GLU tesselator callback; the supplied vertex is added to the internal list of vertices...
std::vector< VERTEX_3D * > vlist
bool AppendArc(double aCenterX, double aCenterY, double aRadius, double aStartAngle, double aAngle, int aContourID)
Add an arc to the specified contour.
void Clear(void)
Erase all data except for arc parameters.
void pushVertices(bool holes)
bool AddVertex(int aContourID, double aXpos, double aYpos)
Add a point to the requested contour.
VERTEX_3D * GetVertexByIndex(int aPointIndex)
Return a pointer to the requested vertex or NULL if no such vertex exists.
void RotatePoint(int *pX, int *pY, const EDA_ANGLE &aAngle)
Calculate the new point of coord coord pX, pY, for a rotation center 0, 0.
static void CALLBACK vrml_tess_vertex(void *vertex_data, void *user_data)
static void CALLBACK vrml_tess_end(void *user_data)
static void CALLBACK vrml_tess_err(GLenum errorID, void *user_data)
static void FormatDoublet(double x, double y, int precision, std::string &strx, std::string &stry)
static void CALLBACK vrml_tess_begin(GLenum cmd, void *user_data)
static void CALLBACK vrml_tess_combine(GLdouble coords[3], VERTEX_3D *vertex_data[4], GLfloat weight[4], void **outData, void *user_data)
static void FormatSinglet(double x, int precision, std::string &strx)