1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884
|
// Copyright (c) 2020 OPEN CASCADE SAS
//
// This file is part of the examples of the Open CASCADE Technology software library.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
#include "TopologySamples.h"
#include "AdaptorVec_AIS.h"
#include <gp_Circ.hxx>
#include <gp_Circ2d.hxx>
#include <gp_Cylinder.hxx>
#include <gp_Lin.hxx>
#include <gp_Pln.hxx>
#include <gp_Sphere.hxx>
#include <gp_Torus.hxx>
#include <Geom_Axis1Placement.hxx>
#include <Geom_Axis2Placement.hxx>
#include <Geom_BSplineCurve.hxx>
#include <Geom2d_BSplineCurve.hxx>
#include <Geom_BSplineSurface.hxx>
#include <Geom_CartesianPoint.hxx>
#include <Geom_CylindricalSurface.hxx>
#include <Geom_Line.hxx>
#include <Geom_Plane.hxx>
#include <Geom_ToroidalSurface.hxx>
#include <GeomAPI_PointsToBSpline.hxx>
#include <Geom2dAPI_PointsToBSpline.hxx>
#include <GeomAPI_PointsToBSplineSurface.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Iterator.hxx>
#include <TopoDS_Compound.hxx>
#include <TopoDS_Edge.hxx>
#include <TopoDS_Face.hxx>
#include <TopoDS_Shell.hxx>
#include <TopoDS_Solid.hxx>
#include <TopoDS_Vertex.hxx>
#include <TopoDS_Wire.hxx>
#include <TopExp.hxx>
#include <TopExp_Explorer.hxx>
#include <TColgp_Array2OfPnt.hxx>
#include <BRep_Builder.hxx>
#include <BRepGProp.hxx>
#include <BRep_Tool.hxx>
#include <BRepTools.hxx>
#include <BRepTools_ReShape.hxx>
#include <BRepAdaptor_Curve.hxx>
#include <BRepAdaptor_CompCurve.hxx>
#include <BRepAdaptor_Surface.hxx>
#include <BRepAlgoAPI_Common.hxx>
#include <BRepAlgoAPI_Cut.hxx>
#include <BRepAlgoAPI_Fuse.hxx>
#include <BRepAlgoAPI_Section.hxx>
#include <BRepAlgoAPI_Splitter.hxx>
#include <BRepAlgoAPI_Defeaturing.hxx>
#include <BRepBuilderAPI_Copy.hxx>
#include <BRepBuilderAPI_MakeVertex.hxx>
#include <BRepBuilderAPI_MakeEdge.hxx>
#include <BRepBuilderAPI_MakeEdge2d.hxx>
#include <BRepBuilderAPI_MakeFace.hxx>
#include <BRepBuilderAPI_MakePolygon.hxx>
#include <BRepBuilderAPI_MakeShell.hxx>
#include <BRepBuilderAPI_MakeSolid.hxx>
#include <BRepBuilderAPI_MakeWire.hxx>
#include <BRepBuilderAPI_NurbsConvert.hxx>
#include <BRepBuilderAPI_Sewing.hxx>
#include <BRepBuilderAPI_Transform.hxx>
#include <BRepCheck_Analyzer.hxx>
#include <BRepPrimAPI_MakeBox.hxx>
#include <BRepPrimAPI_MakeCylinder.hxx>
#include <BRepPrimAPI_MakeRevol.hxx>
#include <BRepFilletAPI_MakeChamfer.hxx>
#include <BRepFilletAPI_MakeFillet.hxx>
#include <BRepOffsetAPI_MakeOffset.hxx>
#include <BRepOffsetAPI_MakeEvolved.hxx>
#include <Extrema_ExtCS.hxx>
#include <GCPnts_QuasiUniformDeflection.hxx>
#include <GProp_GProps.hxx>
#include <GProp_PrincipalProps.hxx>
#include <AIS_Axis.hxx>
#include <AIS_ColoredShape.hxx>
#include <AIS_Plane.hxx>
#include <AIS_Point.hxx>
#include <AIS_TextLabel.hxx>
void TopologySamples::ExecuteSample (const TCollection_AsciiString& theSampleName)
{
Standard_Boolean anIsSamplePresent = Standard_True;
FindSourceCode(theSampleName);
if (theSampleName == "Vertex3dSample")
Vertex3dSample();
else if (theSampleName == "Edge3dSample")
Edge3dSample();
else if (theSampleName == "Face3dSample")
Face3dSample();
else if (theSampleName == "Wire3dSample")
Wire3dSample();
else if (theSampleName == "Shell3dSample")
Shell3dSample();
else if (theSampleName == "Solid3dSample")
Solid3dSample();
else if (theSampleName == "Edge2dSample")
Edge2dSample();
else if (theSampleName == "Box3dSample")
Box3dSample();
else if (theSampleName == "Cylinder3dSample")
Cylinder3dSample();
else if (theSampleName == "Revolution3dSample")
Revolution3dSample();
else if (theSampleName == "TopologyIterator3dSample")
TopologyIterator3dSample();
else if (theSampleName == "TopologyExplorer3dSample")
TopologyExplorer3dSample();
else if (theSampleName == "AssessToCurve3dSample")
AssessToCurve3dSample();
else if (theSampleName == "AssessToCompositeCurve3dSample")
AssessToCompositeCurve3dSample();
else if (theSampleName == "AssessToSurface3dSample")
AssessToSurface3dSample();
else if (theSampleName == "Common3dSample")
Common3dSample();
else if (theSampleName == "Cut3dSample")
Cut3dSample();
else if (theSampleName == "Cut3dSample")
Cut3dSample();
else if (theSampleName == "Fuse3dSample")
Fuse3dSample();
else if (theSampleName == "Section3dSample")
Section3dSample();
else if (theSampleName == "Splitter3dSample")
Splitter3dSample();
else if (theSampleName == "Defeaturing3dSample")
Defeaturing3dSample();
else if (theSampleName == "Fillet3dSample")
Fillet3dSample();
else if (theSampleName == "Chamfer3dSample")
Chamfer3dSample();
else if (theSampleName == "Offset3dSample")
Offset3dSample();
else if (theSampleName == "Evolved3dSample")
Evolved3dSample();
else if (theSampleName == "Copy3dSample")
Copy3dSample();
else if (theSampleName == "Transform3dSample")
Transform3dSample();
else if (theSampleName == "ConvertToNurbs3dSample")
ConvertToNurbs3dSample();
else if (theSampleName == "SewContiguousFaces3dSample")
SewContiguousFaces3dSample();
else if (theSampleName == "CheckValidity3dSample")
CheckValidity3dSample();
else if (theSampleName == "ComputeLinearProperties3dSample")
ComputeLinearProperties3dSample();
else if (theSampleName == "ComputeSurfaceProperties3dSample")
ComputeSurfaceProperties3dSample();
else if (theSampleName == "ComputeVolumeProperties3dSample")
ComputeVolumeProperties3dSample();
else
{
myResult << "No function found: " << theSampleName;
myCode += TCollection_AsciiString("No function found: ") + theSampleName;
anIsSamplePresent = Standard_False;
}
myIsProcessed = anIsSamplePresent;
}
void TopologySamples::Vertex3dSample()
{
// Make a vertex from a 3D point.
gp_Pnt aPnt(0.0, 0.0, 10.0);
TopoDS_Vertex aVertex = BRepBuilderAPI_MakeVertex(aPnt);
myResult << "TopoDS_Vertex was created at [ "
<< aPnt.X() << ", " << aPnt.Y() << ", " << aPnt.Z()
<< " ]" << std::endl;
Handle(AIS_Shape) aAisVertex = new AIS_Shape(aVertex);
Handle(AIS_TextLabel) anAisLabel = new AIS_TextLabel();
Standard_SStream aSS;
aSS << "TopoDS_Vertex [" << aPnt.X() << ", " << aPnt.Y() << ", " << aPnt.Z() << "]" << std::endl;
anAisLabel->SetText(aSS.str().c_str());
anAisLabel->SetPosition(aPnt);
myObject3d.Append(aAisVertex);
myObject3d.Append(anAisLabel);
}
void TopologySamples::Edge3dSample()
{
// Make an edge from two 3D points.
gp_Pnt aPnt1(0.0, 10.0, 0.0);
gp_Pnt aPnt2(10.0, 10.0, 0.0);
TopoDS_Edge anEdgeP12 = BRepBuilderAPI_MakeEdge(aPnt1, aPnt2);
myResult << "TopoDS_Edge between [ "
<< aPnt1.X() << ", " << aPnt1.Y() << ", " << aPnt1.Z()
<< " ] and [ "
<< aPnt2.X() << ", " << aPnt2.Y() << ", " << aPnt2.Z()
<< " ] was created in yellow" << std::endl
<< std::endl;
// Make an edge from a circular segment.
// Create a circle in XY plane of the radius 5.0.
gp_Circ aCirc(gp::XOY(), 5.0);
// Make a circular edge from the 1st quoter in the parametric space.
TopoDS_Edge anEdgeCirc = BRepBuilderAPI_MakeEdge(aCirc, 0.0, M_PI_2);
myResult << "TopoDS_Edge on the circle's 1st quoter" << std::endl
<< "with the center at [ "
<< aCirc.Location().X() << ", " << aCirc.Location().Y() << ", " << aCirc.Location().Z()
<< " ] and R = " << aCirc.Radius() << " was created in red" << std::endl
<< std::endl;
// Make an edge from a 3D curve (BSpline).
// Define points.
gp_Pnt aPole1(0.0, 0.0, 10.0);
gp_Pnt aPole2(5.0, 5.0, 5.0);
gp_Pnt aPole3(10.0, 10.0, 15.0);
gp_Pnt aPole4(15.0, 5.0, 20.0);
// Add points to the curve poles array.
TColgp_Array1OfPnt aPoles(1, 4);
aPoles.SetValue(1, aPole1);
aPoles.SetValue(2, aPole2);
aPoles.SetValue(3, aPole3);
aPoles.SetValue(4, aPole4);
// Make a BSpline curve from the points array
Handle(Geom_BSplineCurve) aBSplineCurve = GeomAPI_PointsToBSpline(aPoles).Curve();
// Make an edge between two point on the BSpline curve.
gp_Pnt aPntOnCurve1, aPntOnCurve2;
aBSplineCurve->D0 (0.75 * aBSplineCurve->FirstParameter()
+ 0.25 * aBSplineCurve->LastParameter(),
aPntOnCurve1);
aBSplineCurve->D0 (0.25 * aBSplineCurve->FirstParameter()
+ 0.75 * aBSplineCurve->LastParameter(),
aPntOnCurve2);
TopoDS_Edge anEdgeBSpline = BRepBuilderAPI_MakeEdge(aBSplineCurve, aPntOnCurve1, aPntOnCurve2);
myResult << "TopoDS_Edge on the BSpline curve" << std::endl
<< "between [ "
<< aPntOnCurve1.X() << ", " << aPntOnCurve1.Y() << ", " << aPntOnCurve1.Z()
<< " ] and [ "
<< aPntOnCurve2.X() << ", " << aPntOnCurve2.Y() << ", " << aPntOnCurve2.Z()
<< " ]" << std::endl
<< "was created in green" << std::endl;
Handle(AIS_ColoredShape) anAisEdgeP12 = new AIS_ColoredShape(anEdgeP12);
Handle(AIS_ColoredShape) anAisEdgeCirc = new AIS_ColoredShape(anEdgeCirc);
Handle(AIS_ColoredShape) anAisEdgeBSpline = new AIS_ColoredShape(anEdgeBSpline);
anAisEdgeP12->SetColor(Quantity_Color(Quantity_NOC_YELLOW));
anAisEdgeCirc->SetColor(Quantity_Color(Quantity_NOC_RED));
anAisEdgeBSpline->SetColor(Quantity_Color(Quantity_NOC_GREEN));
myObject3d.Append(anAisEdgeP12);
myObject3d.Append(anAisEdgeCirc);
myObject3d.Append(anAisEdgeBSpline);
Handle(AIS_TextLabel) anAisEdgeP12Label = new AIS_TextLabel();
anAisEdgeP12Label->SetText("Edge between two points");
anAisEdgeP12Label->SetPosition(0.5 * (aPnt1.XYZ() + aPnt2.XYZ()));
anAisEdgeP12Label->SetColor(Quantity_Color(Quantity_NOC_YELLOW));
myObject3d.Append(anAisEdgeP12Label);
Handle(AIS_TextLabel) anAisEdgeCircLabel = new AIS_TextLabel();
anAisEdgeCircLabel->SetText("Circular edge");
anAisEdgeCircLabel->SetPosition(aCirc.Location());
anAisEdgeCircLabel->SetColor(Quantity_Color(Quantity_NOC_RED));
myObject3d.Append(anAisEdgeCircLabel);
Handle(AIS_TextLabel) anAisEdgeBSplineLabel = new AIS_TextLabel();
anAisEdgeBSplineLabel->SetText("BSpline edge");
anAisEdgeBSplineLabel->SetPosition(aPole3);
anAisEdgeBSplineLabel->SetColor(Quantity_Color(Quantity_NOC_GREEN));
myObject3d.Append(anAisEdgeBSplineLabel);
TopoDS_Vertex anEdgeP12_V1, anEdgeP12_V2;
TopExp::Vertices(anEdgeP12, anEdgeP12_V1, anEdgeP12_V2);
myObject3d.Append(new AIS_Shape(anEdgeP12_V1));
myObject3d.Append(new AIS_Shape(anEdgeP12_V2));
TopoDS_Vertex anEdgeCirc_V1, anEdgeCirc_V2;
TopExp::Vertices(anEdgeCirc, anEdgeCirc_V1, anEdgeCirc_V2);
myObject3d.Append(new AIS_Shape(anEdgeCirc_V1));
myObject3d.Append(new AIS_Shape(anEdgeCirc_V2));
TopoDS_Vertex anEdgeBSpline_V1, anEdgeBSpline_V2;
TopExp::Vertices(anEdgeBSpline, anEdgeBSpline_V1, anEdgeBSpline_V2);
myObject3d.Append(new AIS_Shape(anEdgeBSpline_V1));
myObject3d.Append(new AIS_Shape(anEdgeBSpline_V2));
}
void TopologySamples::Face3dSample()
{
// Make a face from a sphere with the center
// at [0.0, 0.0, 10.0] and R = 5.
gp_Sphere aSphere(gp_Ax3(gp_Pnt(0.0, 0.0, 10.0), gp::DZ()), 5.0);
TopoDS_Face aFaceSphere = BRepBuilderAPI_MakeFace(aSphere);
myResult << "TopoDS_Face on the sphere with" << std::endl
<< "the center at [ "
<< aSphere.Location().X() << ", " << aSphere.Location().Y() << ", " << aSphere.Location().Z()
<< " ] and R = " << aSphere.Radius() << " was created in yellow" << std::endl
<< std::endl;
// Make a flat rectangular face on XY plane.
gp_Pln aPln(gp::XOY());
TopoDS_Face aFaceRect = BRepBuilderAPI_MakeFace(aPln, -10.0, +10.0, -20.0, +20.0);
myResult << "TopoDS_Face on the rectangle was created in red" << std::endl
<< std::endl;
// Make a face from a BSpline surface.
// Define a 4x4 grid of points for BSpline surface.
TColgp_Array2OfPnt aPoints(1, 4, 1, 4);
for (Standard_Integer i = 1; i <= 4; ++i)
{
gp_Pnt aPnt;
aPnt.SetX(5.0 * i);
for (Standard_Integer j = 1; j <= 4; ++j)
{
aPnt.SetY(5.0 * j);
if (1 < i && i < 4 && 1 < j && j < 4)
{
aPnt.SetZ(15.0);
}
else
{
aPnt.SetZ(10.0);
}
aPoints.SetValue(i, j, aPnt);
}
}
// Make a BSpline surface from the points array.
Handle(Geom_BSplineSurface) aBSplineSurf = GeomAPI_PointsToBSplineSurface(aPoints).Surface();
Standard_Real aU1, aU2, aV1, aV2;
aBSplineSurf->Bounds(aU1, aU2, aV1, aV2);
TopoDS_Face aFaceBSpline = BRepBuilderAPI_MakeFace(aBSplineSurf, aU1, aU2, aV1, aV2, Precision::Confusion());
myResult << "TopoDS_Face on the BSpline surface was created in green" << std::endl << std::endl;
Handle(AIS_ColoredShape) anAisFaceSphere = new AIS_ColoredShape(aFaceSphere);
Handle(AIS_ColoredShape) anAisFaceRect = new AIS_ColoredShape(aFaceRect);
Handle(AIS_ColoredShape) anAisFaceBSpline = new AIS_ColoredShape(aFaceBSpline);
anAisFaceSphere->SetColor(Quantity_Color(Quantity_NOC_YELLOW));
anAisFaceRect->SetColor(Quantity_Color(Quantity_NOC_RED));
anAisFaceBSpline->SetColor(Quantity_Color(Quantity_NOC_GREEN));
myObject3d.Append(anAisFaceSphere);
myObject3d.Append(anAisFaceRect);
myObject3d.Append(anAisFaceBSpline);
Handle(AIS_TextLabel) anAisFaceSphereLabel = new AIS_TextLabel();
anAisFaceSphereLabel->SetText("Spherical face");
anAisFaceSphereLabel->SetPosition(aSphere.Location().XYZ() + aSphere.Radius() * gp::DZ().XYZ());
anAisFaceSphereLabel->SetColor(Quantity_Color(Quantity_NOC_YELLOW));
myObject3d.Append(anAisFaceSphereLabel);
Handle(AIS_TextLabel) anAisFaceRectLabel = new AIS_TextLabel();
anAisFaceRectLabel->SetText("Flat rectangular face");
anAisFaceRectLabel->SetPosition(aPln.Location().XYZ() + 2.5 * gp::DZ().XYZ());
anAisFaceRectLabel->SetColor(Quantity_Color(Quantity_NOC_RED));
myObject3d.Append(anAisFaceRectLabel);
Handle(AIS_TextLabel) anAisFaceBSplineLabel = new AIS_TextLabel();
anAisFaceBSplineLabel->SetText("BSpline face");
anAisFaceBSplineLabel->SetPosition(aPoints(4, 4));
anAisFaceBSplineLabel->SetColor(Quantity_Color(Quantity_NOC_GREEN));
myObject3d.Append(anAisFaceBSplineLabel);
}
void TopologySamples::Wire3dSample()
{
// Make a wire from edges created on a set of points.
// Add points to the curve poles array.
TColgp_Array1OfPnt aPoints(1, 4);
aPoints.SetValue(1, gp_Pnt(0.0, 0.0, 0.0));
aPoints.SetValue(2, gp_Pnt(20.0, 0.0, 0.0));
aPoints.SetValue(3, gp_Pnt(20.0, 10.0, 0.0));
aPoints.SetValue(4, gp_Pnt(0.0, 10.0, 0.0));
// A wire maker contains an empty wire.
BRepBuilderAPI_MakeWire aMakeWire;
for (Standard_Integer i = 1; i <= 4; ++i)
{
Standard_Integer i1 = i;
Standard_Integer i2 = i1 < 4 ? i1 + 1 : 1;
const gp_Pnt& aPnt1 = aPoints.Value(i1);
const gp_Pnt& aPnt2 = aPoints.Value(i2);
TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge(aPnt1, aPnt2);
// Add an edge to the wire under construction.
// The edge must be connectible to the wire under construction, and,
// unless it is the first edge of the wire, must satisfy the following
// condition: one of its vertices must be geometrically coincident
// with one of the vertices of the wire (provided that the highest
// tolerance factor is assigned to the two vertices).
// It could also be the same vertex.
// Warning
// If the edge is not connectible to the wire under construction it is not added.
// The function IsDone will return false and the function
// Wire will raise an error, until a new connectible edge is added.
aMakeWire.Add(anEdge);
Standard_ASSERT_VOID(aMakeWire.IsDone(), "Added edge isn't connectible!");
}
// Retrieve a constructed wire.
TopoDS_Wire aWire = aMakeWire.Wire();
myResult << "TopoDS_Wire was created. Vertices :" << std::endl;
// Retrieve wire vertices. 4 vertices are expected, because of
// edges connecting during wire constructing.
TopTools_IndexedMapOfShape aVertices;
TopExp::MapShapes(aWire, TopAbs_VERTEX, aVertices);
for (TopTools_IndexedMapOfShape::Iterator anIt(aVertices); anIt.More(); anIt.Next())
{
TopoDS_Vertex aVertex = TopoDS::Vertex(anIt.Value());
gp_Pnt aPnt = BRep_Tool::Pnt(aVertex);
myResult << "[ " << aPnt.X() << ", " << aPnt.Y() << ", " << aPnt.Z() << " ]" << std::endl;
Handle(AIS_Shape) anAisVertex = new AIS_Shape(aVertex);
myObject3d.Append(anAisVertex);
}
Handle(AIS_Shape) anAisWire = new AIS_Shape(aWire);
myObject3d.Append(anAisWire);
}
void TopologySamples::Shell3dSample()
{
// Make a shell from a cylinder with R = 5 and directed along Z axis
gp_Cylinder aCyl(gp::XOY(), 5.0);
Handle(Geom_Surface) aCylSurf = new Geom_CylindricalSurface(aCyl);
TopoDS_Shell aCylShell = BRepBuilderAPI_MakeShell(aCylSurf, 0.0, 2.0 * M_PI, -10.0, +10.0);
myResult << "TopoDS_Shell on the cylinder R = " << aCyl.Radius() << std::endl
<< "with axis [ "
<< aCyl.Position().Direction().X() << ", "
<< aCyl.Position().Direction().Y() << ", "
<< aCyl.Position().Direction().Z() << " ]" << std::endl
<< "limited in length [-10 ... +10] was created" << std::endl;
Handle(AIS_Shape) anAisShell = new AIS_Shape(aCylShell);
myObject3d.Append(anAisShell);
}
void TopologySamples::Solid3dSample()
{
// Make a torus from a shell.
gp_Torus aTorus(gp::XOY(), 20.0, 7.5);
Handle(Geom_Surface) aTorusSurf = new Geom_ToroidalSurface(aTorus);
TopoDS_Shell aTorusShell = BRepBuilderAPI_MakeShell(aTorusSurf, 0.0, 2.0 * M_PI, 0.0, 2.0 * M_PI);
// Make a solid on the torus shell.
TopoDS_Solid aTorusSolid = BRepBuilderAPI_MakeSolid(aTorusShell);
myResult << "TopoDS_Solid on the torus with" << std::endl
<< "R major = " << aTorus.MajorRadius() << std::endl
<< "R minor = " << aTorus.MinorRadius() << std::endl
<< "was created" << std::endl;
Handle(AIS_Shape) anAisSolid = new AIS_Shape(aTorusSolid);
myObject3d.Append(anAisSolid);
}
void TopologySamples::Edge2dSample()
{
// Make an edge from two 2D points.
gp_Pnt2d aPnt1(0.0, 10.0);
gp_Pnt2d aPnt2(10.0, 10.0);
TopoDS_Edge anEdgeP12 = BRepBuilderAPI_MakeEdge2d(aPnt1, aPnt2);
myResult << "TopoDS_Edge between [ "
<< aPnt1.X() << ", " << aPnt1.Y() << " ] and [ "
<< aPnt2.X() << ", " << aPnt2.Y() << " ] was created in yellow" << std::endl
<< std::endl;
// Make an edge from a circular segment.
// Create a circle of the radius 5.0.
gp_Circ2d aCirc(gp::OX2d(), 5.0);
// Make a circular edge from the 1st quoter in the parametric space.
TopoDS_Edge anEdgeCirc = BRepBuilderAPI_MakeEdge2d(aCirc, 0.0, M_PI_2);
myResult << "TopoDS_Edge on the 2D circle's 1st quoter" << std::endl
<< "with the center at [ " << aCirc.Location().X() << ", " << aCirc.Location().Y()
<< " ] and R = " << aCirc.Radius() << " was created in red" << std::endl
<< std::endl;
// Make an edge from a 2D curve (BSpline).
// Define points.
gp_Pnt2d aPole1(0.0, 0.0);
gp_Pnt2d aPole2(5.0, 5.0);
gp_Pnt2d aPole3(10.0, 10.0);
gp_Pnt2d aPole4(15.0, 5.0);
// Add points to the curve poles array.
TColgp_Array1OfPnt2d aPoles(1, 4);
aPoles.SetValue(1, aPole1);
aPoles.SetValue(2, aPole2);
aPoles.SetValue(3, aPole3);
aPoles.SetValue(4, aPole4);
// Make a BSpline curve from the points array
Handle(Geom2d_BSplineCurve) aBSplineCurve = Geom2dAPI_PointsToBSpline(aPoles).Curve();
// Make an edge between two point on the BSpline curve.
gp_Pnt2d aPntOnCurve1, aPntOnCurve2;
aBSplineCurve->D0 (0.75 * aBSplineCurve->FirstParameter()
+ 0.25 * aBSplineCurve->LastParameter(),
aPntOnCurve1);
aBSplineCurve->D0 (0.25 * aBSplineCurve->FirstParameter()
+ 0.75 * aBSplineCurve->LastParameter(),
aPntOnCurve2);
TopoDS_Edge anEdgeBSpline = BRepBuilderAPI_MakeEdge2d(aBSplineCurve, aPntOnCurve1, aPntOnCurve2);
myResult << "TopoDS_Edge on the 2D BSpline curve" << std::endl
<< "between [ " << aPntOnCurve1.X() << ", " << aPntOnCurve1.Y()
<< " ] and [ " << aPntOnCurve2.X() << ", " << aPntOnCurve2.Y() << " ]" << std::endl
<< "was created in green" << std::endl;
Handle(AIS_ColoredShape) anAisEdgeP12 = new AIS_ColoredShape(anEdgeP12);
Handle(AIS_ColoredShape) anAisEdgeCirc = new AIS_ColoredShape(anEdgeCirc);
Handle(AIS_ColoredShape) anAisEdgeBSpline = new AIS_ColoredShape(anEdgeBSpline);
anAisEdgeP12->SetColor(Quantity_Color(Quantity_NOC_YELLOW));
anAisEdgeCirc->SetColor(Quantity_Color(Quantity_NOC_RED));
anAisEdgeBSpline->SetColor(Quantity_Color(Quantity_NOC_GREEN));
myObject2d.Append(anAisEdgeP12);
myObject2d.Append(anAisEdgeCirc);
myObject2d.Append(anAisEdgeBSpline);
Handle(AIS_TextLabel) anAisEdgeP12Label = new AIS_TextLabel();
anAisEdgeP12Label->SetText("Edge between two 2d points");
anAisEdgeP12Label->SetPosition(0.5 * (gp_XYZ(aPnt1.X(), aPnt1.Y() + 0.5, 0.0) + gp_XYZ(aPnt2.X(), aPnt2.Y() + 0.5, 0.0)));
anAisEdgeP12Label->SetColor(Quantity_Color(Quantity_NOC_YELLOW));
myObject2d.Append(anAisEdgeP12Label);
Handle(AIS_TextLabel) anAisEdgeCircLabel = new AIS_TextLabel();
anAisEdgeCircLabel->SetText("Circular edge");
anAisEdgeCircLabel->SetPosition(gp_XYZ(aCirc.Location().X(), aCirc.Location().Y() + 0.5, 0.0));
anAisEdgeCircLabel->SetColor(Quantity_Color(Quantity_NOC_RED));
myObject2d.Append(anAisEdgeCircLabel);
Handle(AIS_TextLabel) anAisEdgeBSplineLabel = new AIS_TextLabel();
anAisEdgeBSplineLabel->SetText("BSpline edge");
anAisEdgeBSplineLabel->SetPosition(gp_XYZ(aPole3.X(), aPole3.Y() + 0.5, 0.0));
anAisEdgeBSplineLabel->SetColor(Quantity_Color(Quantity_NOC_GREEN));
myObject2d.Append(anAisEdgeBSplineLabel);
TopoDS_Vertex anEdgeP12_V1, anEdgeP12_V2;
TopExp::Vertices(anEdgeP12, anEdgeP12_V1, anEdgeP12_V2);
myObject2d.Append(new AIS_Shape(anEdgeP12_V1));
myObject2d.Append(new AIS_Shape(anEdgeP12_V2));
TopoDS_Vertex anEdgeCirc_V1, anEdgeCirc_V2;
TopExp::Vertices(anEdgeCirc, anEdgeCirc_V1, anEdgeCirc_V2);
myObject2d.Append(new AIS_Shape(anEdgeCirc_V1));
myObject2d.Append(new AIS_Shape(anEdgeCirc_V2));
TopoDS_Vertex anEdgeBSpline_V1, anEdgeBSpline_V2;
TopExp::Vertices(anEdgeBSpline, anEdgeBSpline_V1, anEdgeBSpline_V2);
myObject2d.Append(new AIS_Shape(anEdgeBSpline_V1));
myObject2d.Append(new AIS_Shape(anEdgeBSpline_V2));
}
void TopologySamples::Box3dSample()
{
// Make a box with a corner at [0, 0, 0] and the specified sizes.
Standard_Real aSizeX = 5.0;
Standard_Real aSizeY = 10.0;
Standard_Real aSizeZ = 15.0;
TopoDS_Shape aBox1 = BRepPrimAPI_MakeBox(aSizeX, aSizeY, aSizeZ);
myResult << "Box at corner [0, 0, 0] and sizes ["
<< aSizeX << ", " << aSizeY << ", " << aSizeZ
<< "] was created in yellow" << std::endl;
// Make a box by two points.
gp_Pnt aPnt1(10.0, 0.0, 0.0);
gp_Pnt aPnt2(20.0, 10.0, 15.0);
TopoDS_Shape aBox2 = BRepPrimAPI_MakeBox(aPnt1, aPnt2);
myResult << "Box with corners ["
<< aPnt1.X() << ", " << aPnt1.Y() << ", " << aPnt1.Z()
<< "] and ["
<< aPnt2.X() << ", " << aPnt2.Y() << ", " << aPnt2.Z()
<< "] was created in red" << std::endl;
Handle(AIS_ColoredShape) anAisBox1 = new AIS_ColoredShape(aBox1);
Handle(AIS_ColoredShape) anAisBox2 = new AIS_ColoredShape(aBox2);
anAisBox1->SetColor(Quantity_Color(Quantity_NOC_YELLOW));
anAisBox2->SetColor(Quantity_Color(Quantity_NOC_RED));
myObject3d.Append(anAisBox1);
myObject3d.Append(anAisBox2);
}
void TopologySamples::Cylinder3dSample()
{
// Make a cylinder of the specified radius and length.
Standard_Real aRadius1 = 5.0;
Standard_Real aLength1 = 15.0;
TopoDS_Shape aCyl1 = BRepPrimAPI_MakeCylinder(aRadius1, aLength1);
myResult << "Cylinder with Radius = " << aRadius1
<< " and Length = " << aLength1
<< " was created in yellow" << std::endl;
// Make a cylinder of the specified radius, length and sector angle.
Standard_Real aRadius2 = 8.0;
Standard_Real aLength2 = 25.0;
Standard_Real anAngle = M_PI_2;
TopoDS_Shape aCyl2 = BRepPrimAPI_MakeCylinder(aRadius2, aLength2, anAngle);
myResult << "Cylinder with Radius = " << aRadius2
<< " , Length = " << aLength2
<< " and Angle = " << anAngle
<< " was created in red" << std::endl;
Handle(AIS_ColoredShape) anAisCyl1 = new AIS_ColoredShape(aCyl1);
Handle(AIS_ColoredShape) anAisCyl2 = new AIS_ColoredShape(aCyl2);
anAisCyl1->SetColor(Quantity_Color(Quantity_NOC_YELLOW));
anAisCyl2->SetColor(Quantity_Color(Quantity_NOC_RED));
myObject3d.Append(anAisCyl1);
myObject3d.Append(anAisCyl2);
}
void TopologySamples::Revolution3dSample()
{
// Make a toroidal face by a series of shape revolves.
// Make a starting vertex at [-1.0, 0, 0].
TopoDS_Shape aVertex = BRepBuilderAPI_MakeVertex(gp_Pnt(-1.0, 0.0, 0.0));
// Make a circular edge by revolting aVertex around
// an axis Y positioned at [-1.5, 0.0, 0.0] on 2*Pi angle
gp_Ax1 anAxis1(gp_Pnt(-1.5, 0.0, 0.0), gp::DY());
TopoDS_Shape anEdge = BRepPrimAPI_MakeRevol(aVertex, anAxis1);
myResult << "Circular edge was created in yellow" << std::endl;
// Make a toroidal face by revolting anEdge around
// Z axis on 2*Pi angle.
TopoDS_Shape aFace = BRepPrimAPI_MakeRevol(anEdge, gp::OZ());
myResult << "Toroidal face was created in red" << std::endl;
Handle(AIS_Axis) anAisAxis1 = new AIS_Axis(new Geom_Axis1Placement(anAxis1));
Handle(AIS_Axis) anAisAxis2 = new AIS_Axis(new Geom_Axis1Placement(gp::OZ()));
Handle(AIS_Shape) anAisVertex = new AIS_Shape(aVertex);
Handle(AIS_ColoredShape) anAisEdge = new AIS_ColoredShape(anEdge);
Handle(AIS_ColoredShape) anAisFace = new AIS_ColoredShape(aFace);
anAisEdge->SetColor(Quantity_Color(Quantity_NOC_GREEN));
anAisEdge->SetWidth(1.5);
anAisAxis1->SetColor(Quantity_NOC_GREEN);
anAisFace->SetColor(Quantity_Color(Quantity_NOC_RED));
anAisAxis2->SetColor(Quantity_NOC_RED);
myObject3d.Append(anAisVertex);
myObject3d.Append(anAisEdge);
myObject3d.Append(anAisFace);
}
void TopologySamples::TopologyIterator3dSample()
{
// Make a compound shape.
TopoDS_Compound aComp;
BRep_Builder aBuilder;
aBuilder.MakeCompound(aComp);
// Add shapes to the compound.
aBuilder.Add(aComp, BRepBuilderAPI_MakeVertex(gp::Origin()));
aBuilder.Add(aComp, BRepBuilderAPI_MakeEdge(gp_Pnt(5.0, 0.0, 0.0), gp_Pnt(10.0, 0.0, 0.0)));
aBuilder.Add(aComp, BRepBuilderAPI_MakeFace(gp_Sphere(gp::XOY(), 10.0)));
aBuilder.Add(aComp, BRepBuilderAPI_MakeWire(
BRepBuilderAPI_MakeEdge(gp_Pnt(15.0, 0.0, 0.0), gp_Pnt(20.0, 0.0, 0.0)),
BRepBuilderAPI_MakeEdge(gp_Pnt(20.0, 0.0, 0.0), gp_Pnt(25.0, 10.0, 5.0))
));
aBuilder.Add(aComp, BRepPrimAPI_MakeBox(5.0, 6.0, 7.0).Shell());
aBuilder.Add(aComp, BRepPrimAPI_MakeBox(5.0, 6.0, 7.0).Solid());
TopoDS_Compound aComp1;
aBuilder.MakeCompound(aComp1);
aBuilder.Add(aComp, aComp1);
// Iterate over compound components.
myResult << "Compound components:" << std::endl;
Standard_Integer anI = 1;
for (TopoDS_Iterator anIt(aComp); anIt.More(); anIt.Next(), ++anI)
{
const TopoDS_Shape& aShape = anIt.Value();
myResult << "#" << anI << " : ";
Handle(AIS_ColoredShape) anAisShape;
switch (aShape.ShapeType())
{
case TopAbs_VERTEX:
myResult << "TopAbs_VERTEX";
anAisShape = new AIS_ColoredShape(aShape);
anAisShape->SetColor(Quantity_Color(Quantity_NOC_YELLOW));
break;
case TopAbs_EDGE:
anAisShape = new AIS_ColoredShape(aShape);
anAisShape->SetColor(Quantity_Color(Quantity_NOC_GREEN));
myResult << "TopAbs_EDGE";
break;
case TopAbs_WIRE:
myResult << "TopAbs_WIRE";
break;
case TopAbs_FACE:
anAisShape = new AIS_ColoredShape(aShape);
anAisShape->SetColor(Quantity_Color(Quantity_NOC_RED));
myResult << "TopAbs_FACE";
break;
case TopAbs_SHELL:
myResult << "TopAbs_SHELL";
break;
case TopAbs_SOLID:
myResult << "TopAbs_SOLID";
break;
case TopAbs_COMPOUND:
myResult << "TopAbs_COMPOUND";
break;
case TopAbs_COMPSOLID:
myResult << "TopAbs_COMPSOLID";
break;
case TopAbs_SHAPE:
myResult << "TopAbs_SHAPE";
break;
}
myResult << std::endl;
if (anAisShape)
{
myObject3d.Append(anAisShape);
}
}
}
void TopologySamples::TopologyExplorer3dSample()
{
// Make a box with a corner at [0, 0, 0] and the specified sizes.
Standard_Real aSizeX = 5.0;
Standard_Real aSizeY = 10.0;
Standard_Real aSizeZ = 15.0;
TopoDS_Shape aBox = BRepPrimAPI_MakeBox(aSizeX, aSizeY, aSizeZ);
// Explore vertex references.
myResult << "Vertex refs. : ";
Standard_Integer nbVertices = 0;
for (TopExp_Explorer anExp(aBox, TopAbs_VERTEX); anExp.More(); anExp.Next(), ++nbVertices)
{
const TopoDS_Shape& aShape = anExp.Current();
Handle(AIS_ColoredShape) anAisShape = new AIS_ColoredShape(aShape);
anAisShape->SetColor(Quantity_Color(Quantity_NOC_YELLOW));
myObject3d.Append(anAisShape);
}
myResult << nbVertices << std::endl;
// Explore edge references.
myResult << "Edge refs. : ";
Standard_Integer nbEdges = 0;
for (TopExp_Explorer anExp(aBox, TopAbs_EDGE); anExp.More(); anExp.Next(), ++nbEdges)
{
const TopoDS_Shape& aShape = anExp.Current();
Handle(AIS_ColoredShape) anAisShape = new AIS_ColoredShape(aShape);
anAisShape->SetColor(Quantity_Color(Quantity_NOC_GREEN));
anAisShape->SetWidth(2.5);
myObject3d.Append(anAisShape);
}
myResult << nbEdges << std::endl;
// Explore face references.
myResult << "Face refs. : ";
Standard_Integer nbFaces = 0;
for (TopExp_Explorer anExp(aBox, TopAbs_FACE); anExp.More(); anExp.Next(), ++nbFaces)
{
const TopoDS_Shape& aShape = anExp.Current();
Handle(AIS_ColoredShape) anAisShape = new AIS_ColoredShape(aShape);
anAisShape->SetColor(Quantity_Color(Quantity_NOC_GREEN));
anAisShape->SetWidth(2.5);
myObject3d.Append(anAisShape);
}
myResult << nbFaces << std::endl;
// Explore shell references.
myResult << "Wire refs. : ";
Standard_Integer nbWires = 0;
for (TopExp_Explorer anExp(aBox, TopAbs_WIRE); anExp.More(); anExp.Next(), ++nbWires)
{
}
myResult << nbWires << std::endl;
// Explore shell references.
myResult << "Shell refs. : ";
Standard_Integer nbShells = 0;
for (TopExp_Explorer anExp(aBox, TopAbs_SHELL); anExp.More(); anExp.Next(), ++nbShells)
{
}
myResult << nbShells << std::endl;
// Explore solid references.
myResult << "Solid refs. : ";
Standard_Integer nbSolids = 0;
for (TopExp_Explorer anExp(aBox, TopAbs_SOLID); anExp.More(); anExp.Next(), ++nbSolids)
{
}
myResult << nbSolids << std::endl;
}
void TopologySamples::AssessToCurve3dSample()
{
// Make a face from a sphere.
gp_Sphere aSphere(gp::XOY(), 1.0);
TopoDS_Face aFace = BRepBuilderAPI_MakeFace(aSphere);
myResult << "TopoDS_Face on the sphere with" << std::endl
<< "the center at [ "
<< aSphere.Location().X() << ", " << aSphere.Location().Y() << ", " << aSphere.Location().Z()
<< " ] and R = " << aSphere.Radius() << " was created in yellow" << std::endl
<< std::endl;
Handle(AIS_ColoredShape) anAisFace = new AIS_ColoredShape(aFace);
anAisFace->SetColor(Quantity_Color(Quantity_NOC_YELLOW));
myObject3d.Append(anAisFace);
// Retrieve the first not degenerated edge.
TopoDS_Edge aCurveEdge;
for (TopExp_Explorer anExp(aFace, TopAbs_EDGE); anExp.More(); anExp.Next())
{
TopoDS_Edge anEdge = TopoDS::Edge(anExp.Current());
if (!BRep_Tool::Degenerated(anEdge))
{
aCurveEdge = anEdge;
break;
}
}
if (!aCurveEdge.IsNull())
{
// Make a curve on edge adaptor.
BRepAdaptor_Curve aCurveAdaptor(aCurveEdge);
myResult << "Curve adaptor for edge was built in red" << std::endl;
Handle(AIS_ColoredShape) anAisCurveEdge = new AIS_ColoredShape(aCurveEdge);
anAisCurveEdge->SetColor(Quantity_Color(Quantity_NOC_RED));
anAisCurveEdge->SetWidth(1.5);
myObject3d.Append(anAisCurveEdge);
// Use the curve adaptor for some calculations, e.g. compute
// a set of points using GCPnts_QuasiUniformDeflection algo.
Standard_Real aDeflection = 0.1;
GCPnts_QuasiUniformDeflection anAlgo(aCurveAdaptor, aDeflection);
Standard_ASSERT_VOID(anAlgo.IsDone(), "Success is expected!");
myResult << "Distribution of point on the curve with " << aDeflection
<< " deflection was performed:" << std::endl;
for (Standard_Integer i = 1; i <= anAlgo.NbPoints(); ++i)
{
gp_Pnt aPnt = anAlgo.Value(i);
myResult << "Point #" << i << " : [ "
<< aPnt.X() << ", " << aPnt.Y() << ", " << aPnt.Z() << " ]" << std::endl;
Handle(AIS_Point) anAisPnt = new AIS_Point(new Geom_CartesianPoint(aPnt));
myObject3d.Append(anAisPnt);
}
}
}
void TopologySamples::AssessToCompositeCurve3dSample()
{
// Make a wire containing two BSpline curves.
// Define points.
gp_Pnt aPole1(0.0, 0.0, 10.0);
gp_Pnt aPole2(5.0, 5.0, 5.0);
gp_Pnt aPole3(10.0, 10.0, 15.0);
gp_Pnt aPole4(15.0, 5.0, 20.0);
gp_Pnt aPole5(25.0, 15.0, 20.0);
gp_Pnt aPole6(35.0, 15.0, 15.0);
gp_Pnt aPole7(45.0, 25.0, 10.0);
// Add points to the curve poles array.
TColgp_Array1OfPnt aPoles1(1, 4), aPoles2(1, 4);
aPoles1.SetValue(1, aPole1);
aPoles1.SetValue(2, aPole2);
aPoles1.SetValue(3, aPole3);
aPoles1.SetValue(4, aPole4);
aPoles2.SetValue(1, aPole4);
aPoles2.SetValue(2, aPole5);
aPoles2.SetValue(3, aPole6);
aPoles2.SetValue(4, aPole7);
// Make a BSpline curves from the point arrays
Handle(Geom_BSplineCurve) aBSplineCurve1 = GeomAPI_PointsToBSpline(aPoles1).Curve();
Handle(Geom_BSplineCurve) aBSplineCurve2 = GeomAPI_PointsToBSpline(aPoles2).Curve();
// Make edges
TopoDS_Edge anEdge1 = BRepBuilderAPI_MakeEdge(aBSplineCurve1);
TopoDS_Edge anEdge2 = BRepBuilderAPI_MakeEdge(aBSplineCurve2);
// Make a wire
BRepBuilderAPI_MakeWire aMakeWire;
aMakeWire.Add(anEdge1);
aMakeWire.Add(anEdge2);
Standard_ASSERT_VOID(aMakeWire.IsDone(), "Added edge isn't connectible!");
TopoDS_Wire aWire = aMakeWire.Wire();
myResult << "Wire of two BSpline curves was created" << std::endl;
Handle(AIS_ColoredShape) anAisWire = new AIS_ColoredShape(aWire);
myObject3d.Append(anAisWire);
// Make an adaptor.
BRepAdaptor_CompCurve aCurveAdaptor(aWire);
// Use the curve adaptor for some calculations, e.g. compute
// a set of points using GCPnts_QuasiUniformDeflection algo.
Standard_Real aDeflection = 0.5;
GCPnts_QuasiUniformDeflection anAlgo(aCurveAdaptor, aDeflection);
Standard_ASSERT_VOID(anAlgo.IsDone(), "Success is expected!");
myResult << "Distribution of point on the curve with " << aDeflection
<< " deflection was performed:" << std::endl;
for (Standard_Integer i = 1; i <= anAlgo.NbPoints(); ++i)
{
gp_Pnt aPnt = anAlgo.Value(i);
myResult << "Point #" << i << " : [ "
<< aPnt.X() << ", " << aPnt.Y() << ", " << aPnt.Z() << " ]" << std::endl;
Handle(AIS_Point) anAisPnt = new AIS_Point(new Geom_CartesianPoint(aPnt));
myObject3d.Append(anAisPnt);
}
}
void TopologySamples::AssessToSurface3dSample()
{
// Make a face from a sphere.
gp_Sphere aSphere(gp::XOY(), 4.0);
TopoDS_Face aFace = BRepBuilderAPI_MakeFace(aSphere);
myResult << "TopoDS_Face on the sphere with" << std::endl
<< "the center at [ "
<< aSphere.Location().X() << ", " << aSphere.Location().Y() << ", " << aSphere.Location().Z()
<< " ] and R = " << aSphere.Radius() << " was created in yellow" << std::endl
<< std::endl;
// Make a surface adaptor.
BRepAdaptor_Surface aSurfAdaptor(aFace);
// Use the surface adaptor for some calculations, e.g. compute
// a normal vector at a surface point.
Standard_Real anU = 0.0, aV = 0.0;
gp_Pnt aPnt;
gp_Vec aDU, aDV;
aSurfAdaptor.D1(anU, aV, aPnt, aDU, aDV);
gp_Vec aNorm = aDU.Crossed(aDV);
Standard_ASSERT_VOID(aNorm.Magnitude() > Precision::Confusion(), "Non zero vector is expected!");
aNorm.Normalize();
myResult << "Normal vector at ( " << anU << ", " << aV << " )" << std::endl
<< " = " << aNorm.X() << ", " << aNorm.Y() << ", " << aNorm.Z() << " ] is in red" << std::endl;
Handle(AIS_ColoredShape) anAisFace = new AIS_ColoredShape(aFace);
anAisFace->SetColor(Quantity_Color(Quantity_NOC_YELLOW));
Handle(AIS_Point) anAisPnt = new AIS_Point(new Geom_CartesianPoint(aPnt));
Handle(AIS_ColoredShape) anAisNorm = new AIS_ColoredShape(
BRepBuilderAPI_MakeEdge(aPnt, aPnt.XYZ() + aNorm.XYZ()));
myObject3d.Append(anAisFace);
myObject3d.Append(anAisNorm);
myObject3d.Append(anAisPnt);
}
void TopologySamples::Common3dSample()
{
// Make a box #1 with a corner at [0, 0, 0] and the specified sizes.
Standard_Real aSizeX = 10.0;
Standard_Real aSizeY = 15.0;
Standard_Real aSizeZ = 20.0;
TopoDS_Shape aShape1 = BRepPrimAPI_MakeBox(aSizeX, aSizeY, aSizeZ);
myResult << "Box at corner [0, 0, 0] and sizes ["
<< aSizeX << ", " << aSizeY << ", " << aSizeZ
<< "] was created in yellow wireframe" << std::endl;
// Make a box #2 by two points.
gp_Pnt aPnt1(5.0, 7.5, 10.0);
gp_Pnt aPnt2(20.0, 25.0, 30.0);
TopoDS_Shape aShape2 = BRepPrimAPI_MakeBox(aPnt1, aPnt2);
myResult << "Box with corners ["
<< aPnt1.X() << ", " << aPnt1.Y() << ", " << aPnt1.Z()
<< "] and ["
<< aPnt2.X() << ", " << aPnt2.Y() << ", " << aPnt2.Z()
<< "] was created in green wirefreme" << std::endl;
// Create a boolean algo.
BRepAlgoAPI_Common anAlgo(aShape1, aShape2);
// Make operation.
anAlgo.Build();
if (!anAlgo.IsDone()) // Process errors
{
myResult << "Errors : " << std::endl;
anAlgo.DumpErrors(myResult);
}
if (anAlgo.HasWarnings()) // Process warnings
{
myResult << "Warnings : " << std::endl;
anAlgo.DumpErrors(myResult);
}
if (anAlgo.IsDone())
{
// Get result.
TopoDS_Shape aResultShape = anAlgo.Shape();
myResult << "Result shape was created in red shading" << std::endl;
Handle(AIS_ColoredShape) anAisShape1 = new AIS_ColoredShape(aShape1);
Handle(AIS_ColoredShape) anAisShape2 = new AIS_ColoredShape(aShape2);
anAisShape1->SetColor(Quantity_Color(Quantity_NOC_YELLOW));
anAisShape2->SetColor(Quantity_Color(Quantity_NOC_GREEN));
Handle(AIS_ColoredShape) anAisResult = new AIS_ColoredShape(aResultShape);
anAisResult->SetColor(Quantity_Color(Quantity_NOC_RED));
myObject3d.Append(anAisShape1);
myObject3d.Append(anAisShape2);
myObject3d.Append(anAisResult);
myContext->SetDisplayMode(anAisShape1, 0, Standard_True);
myContext->SetDisplayMode(anAisShape2, 0, Standard_True);
myContext->SetDisplayMode(anAisResult, 1, Standard_True);
}
}
void TopologySamples::Cut3dSample()
{
// Make a box #1 with a corner at [0, 0, 0] and the specified sizes.
Standard_Real aSizeX = 10.0;
Standard_Real aSizeY = 15.0;
Standard_Real aSizeZ = 20.0;
TopoDS_Shape aShape1 = BRepPrimAPI_MakeBox(aSizeX, aSizeY, aSizeZ);
myResult << "Box at corner [0, 0, 0] and sizes ["
<< aSizeX << ", " << aSizeY << ", " << aSizeZ
<< "] was created in yellow wireframe" << std::endl;
// Make a box #2 by two points as a cutting tool.
gp_Pnt aPnt1(5.0, 7.5, 10.0);
gp_Pnt aPnt2(20.0, 25.0, 30.0);
TopoDS_Shape aShape2 = BRepPrimAPI_MakeBox(aPnt1, aPnt2);
myResult << "Box with corners ["
<< aPnt1.X() << ", " << aPnt1.Y() << ", " << aPnt1.Z()
<< "] and ["
<< aPnt2.X() << ", " << aPnt2.Y() << ", " << aPnt2.Z()
<< "] was created in green wireframe" << std::endl;
// Create a boolean algo.
BRepAlgoAPI_Cut anAlgo(aShape1, aShape2);
// Make operation.
anAlgo.Build();
if (!anAlgo.IsDone()) // Process errors
{
myResult << "Errors : " << std::endl;
anAlgo.DumpErrors(myResult);
}
if (anAlgo.HasWarnings()) // Process warnings
{
myResult << "Warnings : " << std::endl;
anAlgo.DumpErrors(myResult);
}
if (anAlgo.IsDone())
{
// Get result.
TopoDS_Shape aResultShape = anAlgo.Shape();
myResult << "Result shape was created in red shading" << std::endl;
Handle(AIS_ColoredShape) anAisShape1 = new AIS_ColoredShape(aShape1);
Handle(AIS_ColoredShape) anAisShape2 = new AIS_ColoredShape(aShape2);
anAisShape1->SetColor(Quantity_Color(Quantity_NOC_YELLOW));
anAisShape2->SetColor(Quantity_Color(Quantity_NOC_GREEN));
Handle(AIS_ColoredShape) anAisResult = new AIS_ColoredShape(aResultShape);
anAisResult->SetColor(Quantity_Color(Quantity_NOC_RED));
myObject3d.Append(anAisShape1);
myObject3d.Append(anAisShape2);
myObject3d.Append(anAisResult);
myContext->SetDisplayMode(anAisShape1, 0, Standard_True);
myContext->SetDisplayMode(anAisShape2, 0, Standard_True);
myContext->SetDisplayMode(anAisResult, 1, Standard_True);
}
}
void TopologySamples::Fuse3dSample()
{
// Make a box #1 with a corner at [0, 0, 0] and the specified sizes.
Standard_Real aSizeX = 10.0;
Standard_Real aSizeY = 15.0;
Standard_Real aSizeZ = 20.0;
TopoDS_Shape aShape1 = BRepPrimAPI_MakeBox(aSizeX, aSizeY, aSizeZ);
myResult << "Box at corner [0, 0, 0] and sizes ["
<< aSizeX << ", " << aSizeY << ", " << aSizeZ
<< "] was created in yellow wireframe" << std::endl;
// Make a box #2 by two points.
gp_Pnt aPnt1(5.0, 7.5, 10.0);
gp_Pnt aPnt2(20.0, 25.0, 30.0);
TopoDS_Shape aShape2 = BRepPrimAPI_MakeBox(aPnt1, aPnt2);
myResult << "Box with corners ["
<< aPnt1.X() << ", " << aPnt1.Y() << ", " << aPnt1.Z()
<< "] and ["
<< aPnt2.X() << ", " << aPnt2.Y() << ", " << aPnt2.Z()
<< "] was created in green wireframe" << std::endl;
// Create a boolean algo.
BRepAlgoAPI_Fuse anAlgo(aShape1, aShape2);
// Make operation.
anAlgo.Build();
if (!anAlgo.IsDone()) // Process errors
{
myResult << "Errors : " << std::endl;
anAlgo.DumpErrors(myResult);
}
if (anAlgo.HasWarnings()) // Process warnings
{
myResult << "Warnings : " << std::endl;
anAlgo.DumpErrors(myResult);
}
if (anAlgo.IsDone())
{
// Get result.
TopoDS_Shape aResultShape = anAlgo.Shape();
myResult << "Result shape was created in red shading" << std::endl;
Handle(AIS_ColoredShape) anAisShape1 = new AIS_ColoredShape(aShape1);
Handle(AIS_ColoredShape) anAisShape2 = new AIS_ColoredShape(aShape2);
anAisShape1->SetColor(Quantity_Color(Quantity_NOC_YELLOW));
anAisShape2->SetColor(Quantity_Color(Quantity_NOC_GREEN));
Handle(AIS_ColoredShape) anAisResult = new AIS_ColoredShape(aResultShape);
anAisResult->SetColor(Quantity_Color(Quantity_NOC_RED));
myObject3d.Append(anAisShape1);
myObject3d.Append(anAisShape2);
myObject3d.Append(anAisResult);
myContext->SetDisplayMode(anAisShape1, 0, Standard_True);
myContext->SetDisplayMode(anAisShape2, 0, Standard_True);
myContext->SetDisplayMode(anAisResult, 1, Standard_True);
}
}
void TopologySamples::Section3dSample()
{
// Make a box #1 with a corner at [0, 0, 0] and the specified sizes.
Standard_Real aSizeX = 10.0;
Standard_Real aSizeY = 15.0;
Standard_Real aSizeZ = 20.0;
TopoDS_Shape aShape = BRepPrimAPI_MakeBox(aSizeX, aSizeY, aSizeZ);
myResult << "Box at corner [0, 0, 0] and sizes ["
<< aSizeX << ", " << aSizeY << ", " << aSizeZ
<< "] was created in yellow wireframe" << std::endl;
// Create a boolean algo.
// Make a section by a plane.
gp_Pln aPln(gp_Pnt(aSizeX / 2.0, aSizeY / 2.0, aSizeZ / 2.0), gp::DZ());
BRepAlgoAPI_Section anAlgo(aShape, aPln, Standard_False);
// Make operation.
anAlgo.Build();
if (!anAlgo.IsDone()) // Process errors
{
myResult << "Errors : " << std::endl;
anAlgo.DumpErrors(myResult);
}
if (anAlgo.HasWarnings()) // Process warnings
{
myResult << "Warnings : " << std::endl;
anAlgo.DumpErrors(myResult);
}
if (anAlgo.IsDone())
{
// Get result.
TopoDS_Shape aResultShape = anAlgo.Shape();
myResult << "Result shape was created in red" << std::endl;
Handle(AIS_ColoredShape) anAisShape = new AIS_ColoredShape(aShape);
Handle(AIS_Plane) anAisPlane = new AIS_Plane(new Geom_Plane(aPln));
anAisShape->SetColor(Quantity_Color(Quantity_NOC_YELLOW));
Handle(AIS_ColoredShape) anAisResult = new AIS_ColoredShape(aResultShape);
anAisResult->SetColor(Quantity_Color(Quantity_NOC_RED));
myObject3d.Append(anAisShape);
myObject3d.Append(anAisPlane);
myObject3d.Append(anAisResult);
myContext->SetDisplayMode(anAisShape, 0, Standard_True);
}
}
void TopologySamples::Splitter3dSample()
{
// Make a box by two points.
gp_Pnt aPnt1(-5.0, -7.5, -10.0);
gp_Pnt aPnt2(10.0, 15.0, 10.0);
TopoDS_Shape aBox = BRepPrimAPI_MakeBox(aPnt1, aPnt2);
myResult << "Box with corners ["
<< aPnt1.X() << ", " << aPnt1.Y() << ", " << aPnt1.Z()
<< "] and ["
<< aPnt2.X() << ", " << aPnt2.Y() << ", " << aPnt2.Z()
<< "] was created in yellow" << std::endl;
// Make a splitting tool as XY plane.
TopoDS_Shape aTool = BRepBuilderAPI_MakeFace(gp_Pln(gp::XOY()));
// Create a splitter algo.
BRepAlgoAPI_Splitter aSplitter;
// Add shapes to be split.
TopTools_ListOfShape anArguments;
anArguments.Append(aBox);
aSplitter.SetArguments(anArguments);
// Add tool shapes.
TopTools_ListOfShape aTools;
aTools.Append(aTool);
aSplitter.SetTools(aTools);
// Perform splitting.
aSplitter.Build();
if (!aSplitter.IsDone()) // Process errors
{
myResult << "Errors : " << std::endl;
aSplitter.DumpErrors(myResult);
}
if (aSplitter.HasWarnings()) // Process warnings
{
myResult << "Warnings : " << std::endl;
aSplitter.DumpErrors(myResult);
}
Handle(AIS_ColoredShape) anAisBox = new AIS_ColoredShape(aBox);
anAisBox->SetColor(Quantity_Color(Quantity_NOC_YELLOW));
myObject3d.Append(anAisBox);
if (aSplitter.IsDone()) // Process results
{
// Simplification of the result shape is performed by the means of
// ShapeUpgrade_UnifySameDomain algorithm. The result of the operation will
// be overwritten with the simplified result.
// The simplification is performed without creation of the Internal shapes,
// i.e. shapes connections will never be broken.
// Simplification is performed on the whole result shape. Thus, if the input
// shapes contained connected tangent edges or faces unmodified during the operation
// they will also be unified.
aSplitter.SimplifyResult();
// Get result of splitting.
TopoDS_Shape aResult = aSplitter.Shape();
myResult << "Splitting result (shapes are moved apart for illustativeness) is in red" << std::endl;
// In this particular sample two shapes in the result are expected.
// Lets move apart them for illustrative purposes.
TopoDS_Iterator anIt(aResult);
Standard_ASSERT_VOID(anIt.More(), "Not empty result is expected!");
TopoDS_Shape aBox1 = anIt.Value(); anIt.Next();
Standard_ASSERT_VOID(anIt.More(), "Two shapes in the result are expected!");
TopoDS_Shape aBox2 = anIt.Value();
gp_Trsf aTrsf1; aTrsf1.SetTranslation(gp_Vec(0.0, 0.0, -15.0));
aBox1.Move(aTrsf1);
gp_Trsf aTrsf2; aTrsf2.SetTranslation(gp_Vec(0.0, 0.0, +15.0));
aBox2.Move(aTrsf2);
Handle(AIS_ColoredShape) anAisBox1 = new AIS_ColoredShape(aBox1);
Handle(AIS_ColoredShape) anAisBox2 = new AIS_ColoredShape(aBox2);
anAisBox1->SetColor(Quantity_Color(Quantity_NOC_RED));
anAisBox2->SetColor(Quantity_Color(Quantity_NOC_RED));
myObject3d.Append(anAisBox1);
myObject3d.Append(anAisBox2);
}
}
void TopologySamples::Defeaturing3dSample()
{
// Prepare a box with a chamfer.
// Make a box with a corner at [0, 0, 0] and the specified sizes.
Standard_Real aSizeX = 8.0;
Standard_Real aSizeY = 10.0;
Standard_Real aSizeZ = 15.0;
TopoDS_Shape aBox = BRepPrimAPI_MakeBox(aSizeX, aSizeY, aSizeZ);
// Initialize chamfer algo.
BRepFilletAPI_MakeChamfer anAlgo(aBox);
// Set edge to apply a chamfer with specified distance from it.
// Select the 5th edge in the map returned by TopExp::MapShapes method.
TopTools_IndexedMapOfShape anEdges;
TopExp::MapShapes(aBox, TopAbs_EDGE, anEdges);
TopoDS_Edge anEdge = TopoDS::Edge(anEdges.FindKey(5));
Standard_Real aDist = 4.0;
anAlgo.Add(aDist, anEdge);
// Make a chamfer.
anAlgo.Build();
Standard_ASSERT_VOID(anAlgo.IsDone(), "Couldn't prepare a box with a chamfer!");
// Get a box with a chamfer.
TopoDS_Shape aBoxWithChamfer = anAlgo.Shape();
myResult << "Box with a chamfer is in yellow shading" << std::endl;
Handle(AIS_ColoredShape) anAisBoxWithChamfer = new AIS_ColoredShape(aBoxWithChamfer);
anAisBoxWithChamfer->SetColor(Quantity_Color(Quantity_NOC_YELLOW));
myObject3d.Append(anAisBoxWithChamfer);
myContext->SetDisplayMode(anAisBoxWithChamfer, 1, Standard_True);
// Retrieve chamfer faces generated from the edge
const TopTools_ListOfShape& aGenShapes = anAlgo.Generated(anEdge);
Standard_ASSERT_VOID(!aGenShapes.IsEmpty(), "Chamfer face is expected!");
for (TopTools_ListOfShape::Iterator anIt(aGenShapes); anIt.More(); anIt.Next())
{
Handle(AIS_ColoredShape) anAisShape = new AIS_ColoredShape(anIt.Value());
anAisShape->SetColor(Quantity_Color(Quantity_NOC_GREEN));
anAisShape->SetWidth(2.5);
myObject3d.Append(anAisShape);
myContext->SetDisplayMode(anAisBoxWithChamfer, 1, Standard_True);
}
myResult << "Chamfer faces : " << aGenShapes.Size() << std::endl;
myResult << "The first one is using to remove" << std::endl;
myResult << "The removed face is in green" << std::endl;
// Initialize defeaturing algo.
BRepAlgoAPI_Defeaturing aDefeatAlgo;
aDefeatAlgo.SetShape(aBoxWithChamfer);
aDefeatAlgo.AddFaceToRemove(aGenShapes.First());
// Remove the chamfer.
aDefeatAlgo.Build();
if (aDefeatAlgo.IsDone())
{
// Get result.
TopoDS_Shape aResult = aDefeatAlgo.Shape();
myResult << "Defeatured box is in red wireframe" << std::endl;
Handle(AIS_ColoredShape) anAisResult = new AIS_ColoredShape(aResult);
anAisResult->SetColor(Quantity_Color(Quantity_NOC_RED));
myObject3d.Append(anAisResult);
myContext->SetDisplayMode(anAisResult, 0, Standard_True);
}
}
void TopologySamples::Fillet3dSample()
{
// Make a box with a corner at [0, 0, 0] and the specified sizes.
Standard_Real aSizeX = 8.0;
Standard_Real aSizeY = 10.0;
Standard_Real aSizeZ = 15.0;
TopoDS_Shape aBox = BRepPrimAPI_MakeBox(aSizeX, aSizeY, aSizeZ);
myResult << "Box at corner [0, 0, 0] and sizes ["
<< aSizeX << ", " << aSizeY << ", " << aSizeZ
<< "] was created in yellow wireframe" << std::endl;
// Initialize fillet algo.
BRepFilletAPI_MakeFillet anAlgo(aBox);
// Set edge to apply a fillet with specified radius.
// Select the first edge in the map returned by TopExp::MapShapes method.
TopTools_IndexedMapOfShape anEdges;
TopExp::MapShapes(aBox, TopAbs_EDGE, anEdges);
TopoDS_Edge anEdge = TopoDS::Edge(anEdges.FindKey(1));
Standard_Real aRadius = 3.0;
anAlgo.Add(aRadius, anEdge);
myResult << "Make a fillet of " << aRadius << " radius on an edge in green" << std::endl;
Handle(AIS_ColoredShape) anAisBox = new AIS_ColoredShape(aBox);
Handle(AIS_ColoredShape) anAisEdge = new AIS_ColoredShape(anEdge);
anAisBox->SetColor(Quantity_Color(Quantity_NOC_YELLOW));
anAisEdge->SetColor(Quantity_Color(Quantity_NOC_GREEN));
anAisEdge->SetWidth(2.5);
myObject3d.Append(anAisBox);
myObject3d.Append(anAisEdge);
myContext->SetDisplayMode(anAisBox, 0, Standard_True);
// Make a fillet.
anAlgo.Build();
if (anAlgo.IsDone())
{
// Get result.
TopoDS_Shape aResult = anAlgo.Shape();
myResult << "Fillet was built. Result shape is in red shading" << std::endl;
Handle(AIS_ColoredShape) anAisResult = new AIS_ColoredShape(aResult);
anAisResult->SetColor(Quantity_Color(Quantity_NOC_RED));
myObject3d.Append(anAisResult);
myContext->SetDisplayMode(anAisResult, 1, Standard_True);
}
}
void TopologySamples::Chamfer3dSample()
{
// Make a box with a corner at [0, 0, 0] and the specified sizes.
Standard_Real aSizeX = 8.0;
Standard_Real aSizeY = 10.0;
Standard_Real aSizeZ = 15.0;
TopoDS_Shape aBox = BRepPrimAPI_MakeBox(aSizeX, aSizeY, aSizeZ);
myResult << "Box at corner [0, 0, 0] and sizes ["
<< aSizeX << ", " << aSizeY << ", " << aSizeZ
<< "] was created in yellow wirewrame" << std::endl;
// Initialize chamfer algo.
BRepFilletAPI_MakeChamfer anAlgo(aBox);
// Set edge to apply a chamfer with specified distance from it.
// Select the 5th edge in the map returned by TopExp::MapShapes method.
TopTools_IndexedMapOfShape anEdges;
TopExp::MapShapes(aBox, TopAbs_EDGE, anEdges);
TopoDS_Edge anEdge = TopoDS::Edge(anEdges.FindKey(5));
Standard_Real aDist = 4.0;
anAlgo.Add(aDist, anEdge);
myResult << "Make a chamfer of " << aDist << " size on an edge in green" << std::endl;
Handle(AIS_ColoredShape) anAisBox = new AIS_ColoredShape(aBox);
Handle(AIS_ColoredShape) anAisEdge = new AIS_ColoredShape(anEdge);
anAisBox->SetColor(Quantity_Color(Quantity_NOC_YELLOW));
anAisEdge->SetColor(Quantity_Color(Quantity_NOC_GREEN));
anAisEdge->SetWidth(2.5);
myObject3d.Append(anAisBox);
myObject3d.Append(anAisEdge);
myContext->SetDisplayMode(anAisBox, 0, Standard_True);
// Make a chamfer.
anAlgo.Build();
if (anAlgo.IsDone())
{
// Get result.
TopoDS_Shape aResult = anAlgo.Shape();
myResult << "Fillet was built. Result shape is in red shading" << std::endl;
Handle(AIS_ColoredShape) anAisResult = new AIS_ColoredShape(aResult);
anAisResult->SetColor(Quantity_Color(Quantity_NOC_RED));
myObject3d.Append(anAisResult);
myContext->SetDisplayMode(anAisResult, 1, Standard_True);
const TopTools_ListOfShape& aGenShapes = anAlgo.Generated(anEdge);
for (TopTools_ListOfShape::Iterator anIt(aGenShapes); anIt.More(); anIt.Next())
{
Handle(AIS_ColoredShape) anAisShape = new AIS_ColoredShape(anIt.Value());
anAisShape->SetColor(Quantity_Color(Quantity_NOC_RED));
anAisShape->SetWidth(2.5);
myObject3d.Append(anAisShape);
}
}
}
void TopologySamples::Offset3dSample()
{
// Make a triangle wire.
BRepBuilderAPI_MakePolygon aTria;
TopoDS_Vertex aVertA = BRepBuilderAPI_MakeVertex(gp_Pnt(-0.5, 0.0, 0.0));
TopoDS_Vertex aVertB = BRepBuilderAPI_MakeVertex(gp_Pnt(0.0, 0.0, +1.0));
TopoDS_Vertex aVertC = BRepBuilderAPI_MakeVertex(gp_Pnt(+0.5, 0.0, 0.0));
aTria.Add(aVertA);
aTria.Add(aVertB);
aTria.Add(aVertC);
aTria.Close();
TopoDS_Wire aWire = aTria.Wire();
myResult << "Triangular wire was created in yellow" << std::endl;
Handle(AIS_ColoredShape) anAisWire = new AIS_ColoredShape(aWire);
anAisWire->SetColor(Quantity_Color(Quantity_NOC_YELLOW));
myObject3d.Append(anAisWire);
// Initialize offset algo.
BRepOffsetAPI_MakeOffset anAlgo(aWire);
// Perform a series of offsets with linearly increasing value and altitude.
Standard_Real anOffsetStep = 0.2;
Standard_Real anAltitudeStep = 0.1;
for (Standard_Integer i = 1; i <= 4; ++i)
{
Standard_Real anOffset = anOffsetStep * i;
Standard_Real anAltitude = anAltitudeStep * i;
anAlgo.Perform(anOffset, anAltitude);
if (anAlgo.IsDone())
{
// Get result.
TopoDS_Shape aResult = anAlgo.Shape();
myResult << "#" << i << " : Offset = " << anOffset << " Altitude = " << anAltitude
<< ". Result is in red." << std::endl;
Handle(AIS_ColoredShape) anAisResult = new AIS_ColoredShape(aResult);
anAisResult->SetColor(Quantity_Color(Quantity_NOC_RED));
myObject3d.Append(anAisResult);
}
}
}
void TopologySamples::Evolved3dSample()
{
// Make a triangle wire as a spine.
BRepBuilderAPI_MakePolygon aTria;
TopoDS_Vertex aVertA = BRepBuilderAPI_MakeVertex(gp_Pnt(-0.5, 0.0, 0.0));
TopoDS_Vertex aVertB = BRepBuilderAPI_MakeVertex(gp_Pnt(0.0, +1.0, 0.0));
TopoDS_Vertex aVertC = BRepBuilderAPI_MakeVertex(gp_Pnt(+0.5, 0.0, 0.0));
aTria.Add(aVertA);
aTria.Add(aVertB);
aTria.Add(aVertC);
aTria.Close();
TopoDS_Wire aSpine = aTria.Wire();
myResult << "Profile wire was created in yellow" << std::endl;
// Make a wire as a profile.
BRepBuilderAPI_MakePolygon aPoly;
TopoDS_Vertex aVert1 = BRepBuilderAPI_MakeVertex(gp_Pnt(-0.5, 0.0, 0.0));
TopoDS_Vertex aVert2 = BRepBuilderAPI_MakeVertex(gp_Pnt(-0.5, -0.1, 0.5));
TopoDS_Vertex aVert3 = BRepBuilderAPI_MakeVertex(gp_Pnt(-0.5, -0.2, 1.0));
aPoly.Add(aVert1);
aPoly.Add(aVert2);
aPoly.Add(aVert3);
TopoDS_Wire aProfile = aPoly.Wire();
myResult << "Spine wire was created in greed" << std::endl;
Handle(AIS_ColoredShape) anAisSpine = new AIS_ColoredShape(aSpine);
Handle(AIS_ColoredShape) anAisProfile = new AIS_ColoredShape(aProfile);
anAisSpine->SetColor(Quantity_Color(Quantity_NOC_YELLOW));
anAisSpine->SetWidth(2.5);
anAisProfile->SetColor(Quantity_Color(Quantity_NOC_GREEN));
anAisProfile->SetWidth(2.5);
myObject3d.Append(anAisSpine);
myObject3d.Append(anAisProfile);
// Initialize evolving algo.
GeomAbs_JoinType aJoinType = GeomAbs_Arc;
Standard_Boolean aIsGlobalCS = Standard_False;
Standard_Boolean aIsSolid = Standard_True;
BRepOffsetAPI_MakeEvolved anAlgo(aSpine, aProfile, aJoinType, aIsGlobalCS, aIsSolid);
// Perform evolving.
anAlgo.Build();
if (anAlgo.IsDone())
{
// Get result.
TopoDS_Shape aResult = anAlgo.Shape();
myResult << "Evolving result is in red" << std::endl;
Handle(AIS_ColoredShape) anAisResult = new AIS_ColoredShape(aResult);
anAisResult->SetColor(Quantity_Color(Quantity_NOC_RED));
myObject3d.Append(anAisResult);
}
}
void TopologySamples::Copy3dSample()
{
// Make a box with a corner at [0, 0, 0] and the specified sizes.
Standard_Real aSizeX = 10.0;
Standard_Real aSizeY = 15.0;
Standard_Real aSizeZ = 20.0;
BRepPrimAPI_MakeBox aBoxMake(aSizeX, aSizeY, aSizeZ);
TopoDS_Shape aBox = aBoxMake.Shape();
myResult << "Box at corner [0, 0, 0] and sizes ["
<< aSizeX << ", " << aSizeY << ", " << aSizeZ
<< "] was created in yellow" << std::endl;
// Make a box copy.
TopoDS_Shape aBoxCopy = BRepBuilderAPI_Copy(aBox);
myResult << "Box copy was created in red" << std::endl;
gp_Trsf aTrsf1; aTrsf1.SetTranslation(gp_Vec(15.0, 0.0, 0.0));
aBoxCopy.Move(aTrsf1);
myResult << "Box copy shape is moved apart for illustativeness" << std::endl;
Handle(AIS_ColoredShape) anAisBox = new AIS_ColoredShape(aBox);
anAisBox->SetColor(Quantity_Color(Quantity_NOC_YELLOW));
anAisBox->SetWidth(2.5);
Handle(AIS_ColoredShape) anAisBoxCopy = new AIS_ColoredShape(aBoxCopy);
anAisBoxCopy->SetColor(Quantity_Color(Quantity_NOC_RED));
myObject3d.Append(anAisBox);
myObject3d.Append(anAisBoxCopy);
}
void TopologySamples::Transform3dSample()
{
// Make a box with a corner at [0, 0, 0] and the specified sizes.
Standard_Real aSizeX = 10.0;
Standard_Real aSizeY = 15.0;
Standard_Real aSizeZ = 20.0;
BRepPrimAPI_MakeBox aBoxMake(aSizeX, aSizeY, aSizeZ);
TopoDS_Shape aBox = aBoxMake.Shape();
myResult << "Box at corner [0, 0, 0] and sizes ["
<< aSizeX << ", " << aSizeY << ", " << aSizeZ
<< "] was created in yellow" << std::endl;
// Move the box.
gp_Trsf aTrMove; aTrMove.SetTranslation(gp_Vec(15.0, 20.0, 25.0));
TopoDS_Shape aMovedBox = BRepBuilderAPI_Transform(aBox, aTrMove, Standard_True);
myResult << "Moved box in green" << std::endl;
// Rotate the moved box
gp_Trsf aTrRot; aTrRot.SetRotation(gp_Ax1(gp_Pnt(15.0, 20.0, 25.0), gp::DZ()), 3.0*M_PI_4);
TopoDS_Shape aRotatedBox = BRepBuilderAPI_Transform(aBox, aTrRot, Standard_True);
myResult << "Rotated box in red" << std::endl;
Handle(AIS_ColoredShape) anAisBox = new AIS_ColoredShape(aBox);
Handle(AIS_ColoredShape) anAisMovedBox = new AIS_ColoredShape(aMovedBox);
Handle(AIS_ColoredShape) anAisRotatedBox = new AIS_ColoredShape(aRotatedBox);
anAisBox->SetColor(Quantity_Color(Quantity_NOC_YELLOW));
anAisMovedBox->SetColor(Quantity_Color(Quantity_NOC_GREEN));
anAisRotatedBox->SetColor(Quantity_Color(Quantity_NOC_RED));
myObject3d.Append(anAisBox);
myObject3d.Append(anAisMovedBox);
myObject3d.Append(anAisRotatedBox);
}
void TopologySamples::ConvertToNurbs3dSample()
{
// Make a torus face.
gp_Torus aTorus(gp::XOY(), 20.0, 7.5);
TopoDS_Shape aTorusFace = BRepBuilderAPI_MakeFace(aTorus);
myResult << "TopoDS_Solid on the torus with" << std::endl
<< "R major = " << aTorus.MajorRadius() << std::endl
<< "R minor = " << aTorus.MinorRadius() << std::endl
<< "was created in yellow" << std::endl;
// Convert faces/edges from analytic to NURBS geometry.
TopoDS_Shape aNurbsFace = BRepBuilderAPI_NurbsConvert(aTorusFace);
myResult << "Converted torus in red" << std::endl;
gp_Trsf aTrsf1; aTrsf1.SetTranslation(gp_Vec(60.0, 0.0, 0.0));
aNurbsFace.Move(aTrsf1);
myResult << "Converted torus is moved apart for illustativeness" << std::endl;
Handle(AIS_ColoredShape) anAisTorus = new AIS_ColoredShape(aTorusFace);
Handle(AIS_ColoredShape) anAisNurbs = new AIS_ColoredShape(aNurbsFace);
anAisTorus->SetColor(Quantity_Color(Quantity_NOC_YELLOW));
anAisTorus->SetWidth(2.5);
anAisNurbs->SetColor(Quantity_Color(Quantity_NOC_RED));
myObject3d.Append(anAisTorus);
myObject3d.Append(anAisNurbs);
}
void TopologySamples::SewContiguousFaces3dSample()
{
// Make a sphere.
gp_Sphere aSphere(gp::XOY(), 1.0);
// South hemisphere.
TopoDS_Face aFace1 = BRepBuilderAPI_MakeFace(aSphere, 0.0, 2.0 * M_PI, -M_PI_2, 0.0);
// North hemisphere.
TopoDS_Face aFace2 = BRepBuilderAPI_MakeFace(aSphere, 0.0, 2.0 * M_PI, 0.0, +M_PI_2);
// Make a default tailor.
BRepBuilderAPI_Sewing aTailor;
// Add hemisphere faces.
aTailor.Add(aFace1);
aTailor.Add(aFace2);
// Perform sewing.
aTailor.Perform();
// Get result.
const TopoDS_Shape& aSewedSphere = aTailor.SewedShape();
myResult << "Two hemispheres were sewed : " << aTailor.NbFreeEdges() << " free edges" << std::endl;
Handle(AIS_ColoredShape) anAisSewedSphere = new AIS_ColoredShape(aSewedSphere);
anAisSewedSphere->SetColor(Quantity_Color(Quantity_NOC_RED));
myObject3d.Append(anAisSewedSphere);
}
void TopologySamples::CheckValidity3dSample()
{
// Make a box with a corner at [0, 0, 0] and the specified sizes.
Standard_Real aSizeX = 10.0;
Standard_Real aSizeY = 15.0;
Standard_Real aSizeZ = 20.0;
BRepPrimAPI_MakeBox aBoxMake(aSizeX, aSizeY, aSizeZ);
TopoDS_Shape aBox = aBoxMake.Shape();
myResult << "Box at corner [0, 0, 0] and sizes ["
<< aSizeX << ", " << aSizeY << ", " << aSizeZ
<< "] was created in yellow" << std::endl;
// Analyze the box.
BRepCheck_Analyzer anAnalyzer(aBox);
myResult << "Box is " << (anAnalyzer.IsValid() ? "valid" : "invalid") << std::endl;
// Make the box invalid manually.
Handle(BRepTools_ReShape) aReShape = new BRepTools_ReShape();
myResult << "Remove the top face from the box (red)" << std::endl;
aReShape->Remove(aBoxMake.TopFace());
TopoDS_Shape aBox1 = aReShape->Apply(aBox);
myResult << "The top face was removed" << std::endl;
// Analyze the modified box.
BRepCheck_Analyzer anAnalyzer1(aBox1);
myResult << "Modified box is " << (anAnalyzer1.IsValid() ? "valid" : "invalid") << std::endl;
Handle(AIS_ColoredShape) anAisBox = new AIS_ColoredShape(aBox);
Handle(AIS_ColoredShape) anAisTopFace = new AIS_ColoredShape(aBoxMake.TopFace());
anAisBox->SetColor(Quantity_Color(Quantity_NOC_YELLOW));
anAisTopFace->SetColor(Quantity_Color(Quantity_NOC_RED));
myObject3d.Append(anAisBox);
myObject3d.Append(anAisTopFace);
}
void TopologySamples::ComputeLinearProperties3dSample()
{
// Make an edge from a circular segment.
// Create a circle in XY plane of the radius 1.0.
gp_Circ aCirc(gp::XOY(), 1.0);
// Make a circular edge from the 1st quoter in the parametric space.
TopoDS_Edge aShape = BRepBuilderAPI_MakeEdge(aCirc, 0.0, M_PI);
myResult << "TopoDS_Edge on the circle's 1st quoter" << std::endl
<< "with the center at [ "
<< aCirc.Location().X() << ", " << aCirc.Location().Y() << ", " << aCirc.Location().Z()
<< " ] and R = " << aCirc.Radius() << " was created in red" << std::endl
<< std::endl;
// Retrieve linear properties from the edge.
GProp_GProps aGProps;
BRepGProp::LinearProperties(aShape, aGProps);
Standard_Real aLength = aGProps.Mass();
gp_Pnt aCOM = aGProps.CentreOfMass();
Standard_Real anIx, anIy, anIz;
aGProps.StaticMoments(anIx, anIy, anIz);
gp_Mat aMOI = aGProps.MatrixOfInertia();
myResult << "Linear properties:" << std::endl
<< " Length = " << aLength << std::endl
<< " Center of mass = [ " << aCOM.X() << ", " << aCOM.Y() << ", " << aCOM.Z() << " ]" << std::endl
<< " Static moments = [ " << anIx << ", " << anIy << ", " << anIz << " ]" << std::endl
<< " Matrix of inertia = [ "
<< aMOI(1, 1) << ", " << aMOI(1, 2) << ", " << aMOI(1, 3) << std::endl
<< std::setw(33) << aMOI(2, 1) << ", " << aMOI(2, 2) << ", " << aMOI(2, 3) << std::endl
<< std::setw(33) << aMOI(3, 1) << ", " << aMOI(3, 2) << ", " << aMOI(3, 3) << " ]" << std::endl;
GProp_PrincipalProps aPProps = aGProps.PrincipalProperties();
Standard_Real anIxx, anIyy, anIzz;
aPProps.Moments(anIxx, anIyy, anIzz);
Standard_Real aRxx, aRyy, aRzz;
aPProps.RadiusOfGyration(aRxx, aRyy, aRzz);
myResult << "Principal properties:" << std::endl
<< " Has symmetric axis : " << (aPProps.HasSymmetryAxis() ? "YES" : "NO") << std::endl
<< " Has symmetric point : " << (aPProps.HasSymmetryPoint() ? "YES" : "NO") << std::endl
<< " Moments of inertia = [ " << anIxx << ", " << anIyy << ", " << anIzz << " ]" << std::endl
<< " Radius of gyration = [ " << aRxx << ", " << aRyy << ", " << aRzz << " ]" << std::endl;
if (!aPProps.HasSymmetryPoint())
{
const gp_Vec& anAxis1 = aPProps.FirstAxisOfInertia();
myResult << " 1st axis of inertia = [ " << anAxis1.X() << ", " << anAxis1.Y() << ", " << anAxis1.Z() << " ]" << std::endl;
Handle(AIS_ColoredShape) anAisAxis1 = new AIS_ColoredShape(
BRepBuilderAPI_MakeEdge(aCOM, aCOM.XYZ() + anAxis1.XYZ()));
anAisAxis1->SetColor(Quantity_Color(Quantity_NOC_GREEN));
myObject3d.Append(anAisAxis1);
if (!aPProps.HasSymmetryPoint())
{
const gp_Vec& anAxis2 = aPProps.SecondAxisOfInertia();
myResult << " 2nd axis of inertia = [ " << anAxis2.X() << ", " << anAxis2.Y() << ", " << anAxis2.Z() << " ]" << std::endl;
Handle(AIS_ColoredShape) anAisAxis2 = new AIS_ColoredShape(
BRepBuilderAPI_MakeEdge(aCOM, aCOM.XYZ() + anAxis2.XYZ()));
anAisAxis2->SetColor(Quantity_Color(Quantity_NOC_GREEN));
myObject3d.Append(anAisAxis2);
const gp_Vec& anAxis3 = aPProps.ThirdAxisOfInertia();
myResult << " 3rd axis of inertia = [ " << anAxis3.X() << ", " << anAxis3.Y() << ", " << anAxis3.Z() << " ]" << std::endl;
Handle(AIS_ColoredShape) anAisAxis3 = new AIS_ColoredShape(
BRepBuilderAPI_MakeEdge(aCOM, aCOM.XYZ() + anAxis3.XYZ()));
anAisAxis3->SetColor(Quantity_Color(Quantity_NOC_GREEN));
myObject3d.Append(anAisAxis3);
}
}
Handle(AIS_ColoredShape) anAisShape = new AIS_ColoredShape(aShape);
Handle(AIS_Point) anAisCOM = new AIS_Point(new Geom_CartesianPoint(aCOM));
anAisShape->SetColor(Quantity_Color(Quantity_NOC_RED));
Handle(AIS_TextLabel) aCOMLabel = new AIS_TextLabel();
aCOMLabel->SetText("Center of mass");
aCOMLabel->SetPosition(aCOM);
Handle(AIS_Axis) anAisAxisX = new AIS_Axis(new Geom_Axis2Placement(gp::YOZ()), AIS_TOAX_XAxis);
Handle(AIS_Axis) anAisAxisY = new AIS_Axis(new Geom_Axis2Placement(gp::ZOX()), AIS_TOAX_YAxis);
Handle(AIS_Axis) anAisAxisZ = new AIS_Axis(new Geom_Axis2Placement(gp::XOY()), AIS_TOAX_ZAxis);
myObject3d.Append(anAisAxisX);
myObject3d.Append(anAisAxisY);
myObject3d.Append(anAisAxisZ);
myObject3d.Append(anAisShape);
myObject3d.Append(anAisCOM);
myObject3d.Append(aCOMLabel);
}
void TopologySamples::ComputeSurfaceProperties3dSample()
{
// Make a face from a cylinder with R = 1
// and directed along Z axis
gp_Cylinder aCyl(gp::XOY(), 1.0);
TopoDS_Face aShape = BRepBuilderAPI_MakeFace(aCyl, 0.0, M_PI, -1.0, +1.0).Face();
myResult << "TopoDS_Face on the cylinder R = " << aCyl.Radius() << std::endl
<< "with axis [ " << aCyl.Position().Direction().X() << ", " << aCyl.Position().Direction().Y() << ", " << aCyl.Position().Direction().Z() << " ]" << std::endl
<< "limited in length [-1 ... +1] was created in red" << std::endl;
// Retrieve surface properties from the face.
GProp_GProps aGProps;
BRepGProp::SurfaceProperties(aShape, aGProps);
Standard_Real aArea = aGProps.Mass();
gp_Pnt aCOM = aGProps.CentreOfMass();
Standard_Real anIx, anIy, anIz;
aGProps.StaticMoments(anIx, anIy, anIz);
gp_Mat aMOI = aGProps.MatrixOfInertia();
myResult << "Linear properties:" << std::endl
<< " Area = " << aArea << std::endl
<< " Center of mass = [ " << aCOM.X() << ", " << aCOM.Y() << ", " << aCOM.Z() << " ]" << std::endl
<< " Static moments = [ " << anIx << ", " << anIy << ", " << anIz << " ]" << std::endl
<< " Matrix of inertia = [ "
<< aMOI(1, 1) << ", " << aMOI(1, 2) << ", " << aMOI(1, 3) << std::endl
<< std::setw(33) << aMOI(2, 1) << ", " << aMOI(2, 2) << ", " << aMOI(2, 3) << std::endl
<< std::setw(33) << aMOI(3, 1) << ", " << aMOI(3, 2) << ", " << aMOI(3, 3) << " ]" << std::endl;
GProp_PrincipalProps aPProps = aGProps.PrincipalProperties();
Standard_Real anIxx, anIyy, anIzz;
aPProps.Moments(anIxx, anIyy, anIzz);
Standard_Real aRxx, aRyy, aRzz;
aPProps.RadiusOfGyration(aRxx, aRyy, aRzz);
myResult << "Principal properties:" << std::endl
<< " Has symmetric axis : " << (aPProps.HasSymmetryAxis() ? "YES" : "NO") << std::endl
<< " Has symmetric point : " << (aPProps.HasSymmetryPoint() ? "YES" : "NO") << std::endl
<< " Moments of inertia = [ " << anIxx << ", " << anIyy << ", " << anIzz << " ]" << std::endl
<< " Radius of gyration = [ " << aRxx << ", " << aRyy << ", " << aRzz << " ]" << std::endl;
if (!aPProps.HasSymmetryPoint())
{
const gp_Vec& anAxis1 = aPProps.FirstAxisOfInertia();
myResult << " 1st axis of inertia = [ " << anAxis1.X() << ", " << anAxis1.Y() << ", " << anAxis1.Z() << " ]" << std::endl;
Handle(AIS_ColoredShape) anAisAxis1 = new AIS_ColoredShape(
BRepBuilderAPI_MakeEdge(aCOM, aCOM.XYZ() + anAxis1.XYZ()));
anAisAxis1->SetColor(Quantity_Color(Quantity_NOC_GREEN));
myObject3d.Append(anAisAxis1);
if (!aPProps.HasSymmetryPoint())
{
const gp_Vec& anAxis2 = aPProps.SecondAxisOfInertia();
myResult << " 2nd axis of inertia = [ " << anAxis2.X() << ", " << anAxis2.Y() << ", " << anAxis2.Z() << " ]" << std::endl;
Handle(AIS_ColoredShape) anAisAxis2 = new AIS_ColoredShape(
BRepBuilderAPI_MakeEdge(aCOM, aCOM.XYZ() + anAxis2.XYZ()));
anAisAxis2->SetColor(Quantity_Color(Quantity_NOC_GREEN));
myObject3d.Append(anAisAxis2);
const gp_Vec& anAxis3 = aPProps.ThirdAxisOfInertia();
myResult << " 3rd axis of inertia = [ " << anAxis3.X() << ", " << anAxis3.Y() << ", " << anAxis3.Z() << " ]" << std::endl;
Handle(AIS_ColoredShape) anAisAxis3 = new AIS_ColoredShape(
BRepBuilderAPI_MakeEdge(aCOM, aCOM.XYZ() + anAxis3.XYZ()));
anAisAxis3->SetColor(Quantity_Color(Quantity_NOC_GREEN));
myObject3d.Append(anAisAxis3);
}
}
Handle(AIS_ColoredShape) anAisShape = new AIS_ColoredShape(aShape);
Handle(AIS_Point) anAisCOM = new AIS_Point(new Geom_CartesianPoint(aCOM));
anAisShape->SetColor(Quantity_Color(Quantity_NOC_RED));
Handle(AIS_TextLabel) aCOMLabel = new AIS_TextLabel();
aCOMLabel->SetText("Center of mass");
aCOMLabel->SetPosition(aCOM);
Handle(AIS_Axis) anAisAxisX = new AIS_Axis(new Geom_Axis2Placement(gp::YOZ()), AIS_TOAX_XAxis);
Handle(AIS_Axis) anAisAxisY = new AIS_Axis(new Geom_Axis2Placement(gp::ZOX()), AIS_TOAX_YAxis);
Handle(AIS_Axis) anAisAxisZ = new AIS_Axis(new Geom_Axis2Placement(gp::XOY()), AIS_TOAX_ZAxis);
myObject3d.Append(anAisAxisX);
myObject3d.Append(anAisAxisY);
myObject3d.Append(anAisAxisZ);
myObject3d.Append(anAisShape);
myObject3d.Append(anAisCOM);
myObject3d.Append(aCOMLabel);
}
void TopologySamples::ComputeVolumeProperties3dSample()
{
// Make a box by two points.
gp_Pnt aPnt1(-0.5, -0.6, -0.7);
gp_Pnt aPnt2(+0.8, +0.9, +1.0);
TopoDS_Shape aShape = BRepPrimAPI_MakeBox(aPnt1, aPnt2);
myResult << "Box with corners [" << aPnt1.X() << ", " << aPnt1.Y() << ", " << aPnt1.Z()
<< "] and [" << aPnt2.X() << ", " << aPnt2.Y() << ", " << aPnt2.Z()
<< "] was created in red" << std::endl;
// Retrieve volume properties from the face.
GProp_GProps aGProps;
BRepGProp::VolumeProperties(aShape, aGProps);
Standard_Real aVolume = aGProps.Mass();
gp_Pnt aCOM = aGProps.CentreOfMass();
Standard_Real anIx, anIy, anIz;
aGProps.StaticMoments(anIx, anIy, anIz);
gp_Mat aMOI = aGProps.MatrixOfInertia();
myResult << "Linear properties:" << std::endl
<< " Volume = " << aVolume << std::endl
<< " Center of mass = [ " << aCOM.X() << ", " << aCOM.Y() << ", " << aCOM.Z() << " ]" << std::endl
<< " Static moments = [ " << anIx << ", " << anIy << ", " << anIz << " ]" << std::endl
<< " Matrix of inertia = [ "
<< aMOI(1, 1) << ", " << aMOI(1, 2) << ", " << aMOI(1, 3) << std::endl
<< std::setw(33) << aMOI(2, 1) << ", " << aMOI(2, 2) << ", " << aMOI(2, 3) << std::endl
<< std::setw(33) << aMOI(3, 1) << ", " << aMOI(3, 2) << ", " << aMOI(3, 3) << " ]" << std::endl;
GProp_PrincipalProps aPProps = aGProps.PrincipalProperties();
Standard_Real anIxx, anIyy, anIzz;
aPProps.Moments(anIxx, anIyy, anIzz);
Standard_Real aRxx, aRyy, aRzz;
aPProps.RadiusOfGyration(aRxx, aRyy, aRzz);
myResult << "Principal properties:" << std::endl
<< " Has symmetric axis : " << (aPProps.HasSymmetryAxis() ? "YES" : "NO") << std::endl
<< " Has symmetric point : " << (aPProps.HasSymmetryPoint() ? "YES" : "NO") << std::endl
<< " Moments of inertia = [ " << anIxx << ", " << anIyy << ", " << anIzz << " ]" << std::endl
<< " Radius of gyration = [ " << aRxx << ", " << aRyy << ", " << aRzz << " ]" << std::endl;
if (!aPProps.HasSymmetryPoint())
{
const gp_Vec& anAxis1 = aPProps.FirstAxisOfInertia();
myResult << " 1st axis of inertia = [ " << anAxis1.X() << ", " << anAxis1.Y() << ", " << anAxis1.Z() << " ]" << std::endl;
Handle(AIS_ColoredShape) anAisAxis1 = new AIS_ColoredShape(
BRepBuilderAPI_MakeEdge(aCOM, aCOM.XYZ() + anAxis1.XYZ()));
anAisAxis1->SetColor(Quantity_Color(Quantity_NOC_GREEN));
myObject3d.Append(anAisAxis1);
if (!aPProps.HasSymmetryPoint())
{
const gp_Vec& anAxis2 = aPProps.SecondAxisOfInertia();
myResult << " 2nd axis of inertia = [ " << anAxis2.X() << ", " << anAxis2.Y() << ", " << anAxis2.Z() << " ]" << std::endl;
Handle(AIS_ColoredShape) anAisAxis2 = new AIS_ColoredShape(
BRepBuilderAPI_MakeEdge(aCOM, aCOM.XYZ() + anAxis2.XYZ()));
anAisAxis2->SetColor(Quantity_Color(Quantity_NOC_GREEN));
myObject3d.Append(anAisAxis2);
const gp_Vec& anAxis3 = aPProps.ThirdAxisOfInertia();
myResult << " 3rd axis of inertia = [ " << anAxis3.X() << ", " << anAxis3.Y() << ", " << anAxis3.Z() << " ]" << std::endl;
Handle(AIS_ColoredShape) anAisAxis3 = new AIS_ColoredShape(
BRepBuilderAPI_MakeEdge(aCOM, aCOM.XYZ() + anAxis3.XYZ()));
anAisAxis3->SetColor(Quantity_Color(Quantity_NOC_GREEN));
myObject3d.Append(anAisAxis3);
}
}
Handle(AIS_ColoredShape) anAisShape = new AIS_ColoredShape(aShape);
Handle(AIS_Point) anAisCOM = new AIS_Point(new Geom_CartesianPoint(aCOM));
anAisShape->SetColor(Quantity_Color(Quantity_NOC_RED));
Handle(AIS_TextLabel) aCOMLabel = new AIS_TextLabel();
aCOMLabel->SetText("Center of mass");
aCOMLabel->SetPosition(aCOM);
Handle(AIS_Axis) anAisAxisX = new AIS_Axis(new Geom_Axis2Placement(gp::YOZ()), AIS_TOAX_XAxis);
Handle(AIS_Axis) anAisAxisY = new AIS_Axis(new Geom_Axis2Placement(gp::ZOX()), AIS_TOAX_YAxis);
Handle(AIS_Axis) anAisAxisZ = new AIS_Axis(new Geom_Axis2Placement(gp::XOY()), AIS_TOAX_ZAxis);
myObject3d.Append(anAisAxisX);
myObject3d.Append(anAisAxisY);
myObject3d.Append(anAisAxisZ);
myObject3d.Append(anAisShape);
myObject3d.Append(anAisCOM);
myObject3d.Append(aCOMLabel);
}
|