9 #include <boost/test/unit_test.hpp>
35 BOOST_TEST_CONTEXT(
"2D") {
38 Box bb(&o, {-1, -1}, {2, 2});
41 rot = Eigen::Rotation2D<float>(
M_PI / 7.);
48 BOOST_TEST_CONTEXT(
"3D") {
51 Box bb(&o, {-1, -1, -1}, {2, 2, 2});
76 BOOST_CHECK(bb.intersect(p));
77 p = {0.25, 0.25, 0.25};
78 BOOST_CHECK(bb.intersect(p));
79 p = {0.75, 0.75, 0.75};
80 BOOST_CHECK(bb.intersect(p));
84 BOOST_CHECK(bb.intersect(p));
87 BOOST_CHECK(!bb.intersect(p));
91 BOOST_CHECK(!bb.intersect(p));
93 BOOST_CHECK(!bb.intersect(p));
95 BOOST_CHECK(!bb.intersect(p));
97 BOOST_CHECK(!bb.intersect(p));
99 BOOST_CHECK(!bb.intersect(p));
101 BOOST_CHECK(!bb.intersect(p));
104 BOOST_CHECK(!bb.intersect(p));
106 BOOST_CHECK(!bb.intersect(p));
108 BOOST_CHECK(!bb.intersect(p));
110 BOOST_CHECK(!bb.intersect(p));
112 BOOST_CHECK(!bb.intersect(p));
114 BOOST_CHECK(!bb.intersect(p));
118 BOOST_TEST_CONTEXT(
"2D") {
122 Box bb(&o, {-1, -1}, {1, 1});
127 BOOST_CHECK(bb.intersect(ray));
129 ray = {{-2, 2}, {1, 0}};
130 BOOST_CHECK(!bb.intersect(ray));
132 ray = {{-2, -2}, {1, 0}};
133 BOOST_CHECK(!bb.intersect(ray));
136 ray = {{-2, 1}, {1, 0}};
137 BOOST_CHECK(!bb.intersect(ray));
140 ray = {{-2, -1}, {1, 0}};
141 BOOST_CHECK(bb.intersect(ray));
144 ray = {{2, 0}, {1, 0}};
145 BOOST_CHECK(!bb.intersect(ray));
149 ray = {{2, 0}, {-1, 0}};
150 BOOST_CHECK(bb.intersect(ray));
152 ray = {{2, 2}, {-1, 0}};
153 BOOST_CHECK(!bb.intersect(ray));
155 ray = {{2, -2}, {-1, 0}};
156 BOOST_CHECK(!bb.intersect(ray));
159 ray = {{2, 1}, {-1, 0}};
160 BOOST_CHECK(!bb.intersect(ray));
163 ray = {{2, -1}, {-1, 0}};
164 BOOST_CHECK(bb.intersect(ray));
168 ray = {{0, -2}, {0, 1}};
169 BOOST_CHECK(bb.intersect(ray));
171 ray = {{2, -2}, {0, 1}};
172 BOOST_CHECK(!bb.intersect(ray));
174 ray = {{-2, -2}, {0, 1}};
175 BOOST_CHECK(!bb.intersect(ray));
178 ray = {{1, -2}, {0, 1}};
179 BOOST_CHECK(!bb.intersect(ray));
183 ray = {{-1, -2}, {0, 1}};
184 BOOST_CHECK(!bb.intersect(ray));
187 ray = {{0, -2}, {0, -1}};
188 BOOST_CHECK(!bb.intersect(ray));
192 ray = {{0, 2}, {0, -1}};
193 BOOST_CHECK(bb.intersect(ray));
195 ray = {{2, 2}, {0, -1}};
196 BOOST_CHECK(!bb.intersect(ray));
198 ray = {{-2, 2}, {0, -1}};
199 BOOST_CHECK(!bb.intersect(ray));
202 ray = {{1, 2}, {0, -1}};
203 BOOST_CHECK(!bb.intersect(ray));
207 ray = {{-1, 2}, {0, -1}};
208 BOOST_CHECK(!bb.intersect(ray));
211 ray = {{0, 2}, {0, 1}};
212 BOOST_CHECK(!bb.intersect(ray));
216 ray = {{-2, 0}, {0.5, 0.25}};
217 BOOST_CHECK(bb.intersect(ray));
219 ray = {{-2, 0}, {0.5, 0.4}};
220 BOOST_CHECK(bb.intersect(ray));
222 ray = {{-2, 0}, {0.5, 0.6}};
223 BOOST_CHECK(!bb.intersect(ray));
225 ray = {{-2, 0}, {0.5, 0.1}};
226 BOOST_CHECK(bb.intersect(ray));
228 ray = {{-2, 0}, {0.5, -0.4}};
229 BOOST_CHECK(bb.intersect(ray));
231 ray = {{-2, 0}, {0.5, -0.6}};
232 BOOST_CHECK(!bb.intersect(ray));
234 ray = {{-2, 0}, {0.1, 0.5}};
235 BOOST_CHECK(!bb.intersect(ray));
243 BOOST_CHECK(bb.intersect(ray));
249 BOOST_CHECK(bb.intersect(ray));
255 BOOST_CHECK(bb.intersect(ray));
261 BOOST_CHECK(bb.intersect(ray));
264 BOOST_TEST_CONTEXT(
"3D visualize") {
270 BOOST_CHECK(bb3.intersect(ray3));
275 std::ofstream os(
"ray3d.ply");
276 os << ply << std::flush;
280 BOOST_TEST_CONTEXT(
"3D") {
287 BOOST_CHECK(bb3.intersect(ray3));
290 ray3 = {{0, 0, -2}, {0, 0, -1}};
291 BOOST_CHECK(!bb3.intersect(ray3));
293 ray3 = {{0, 2, -2}, {0, 0, 1}};
294 BOOST_CHECK(!bb3.intersect(ray3));
296 ray3 = {{0, -2, -2}, {0, 0, 1}};
297 BOOST_CHECK(!bb3.intersect(ray3));
300 ray3 = {{0, 1, -2}, {0, 0, 1}};
301 BOOST_CHECK(!bb3.intersect(ray3));
304 ray3 = {{0, -1, -2}, {0, 0, 1}};
305 BOOST_CHECK(bb3.intersect(ray3));
308 ray3 = {{-1, 0, -2}, {0, 0, 1}};
309 BOOST_CHECK(!bb3.intersect(ray3));
312 ray3 = {{1, 0, -2}, {0, 0, 1}};
313 BOOST_CHECK(!bb3.intersect(ray3));
315 ray3 = {{-0.95, 0, -2}, {0, 0, 1}};
316 BOOST_CHECK(bb3.intersect(ray3));
321 ray3 = {
p, VertexType3(1, 1, 1) - p};
322 BOOST_CHECK(bb3.intersect(ray3));
324 ray3 = {
p, VertexType3(-1, 1, 1) - p};
325 BOOST_CHECK(bb3.intersect(ray3));
327 ray3 = {
p, VertexType3(-1, -1, 1) - p};
328 BOOST_CHECK(bb3.intersect(ray3));
330 ray3 = {
p, VertexType3(1, -1, 1) - p};
331 BOOST_CHECK(bb3.intersect(ray3));
333 ray3 = {
p, VertexType3(1.1, 0, -1) - p};
334 BOOST_CHECK(!bb3.intersect(ray3));
336 ray3 = {
p, VertexType3(-1.1, 0, -1) - p};
337 BOOST_CHECK(!bb3.intersect(ray3));
339 ray3 = {
p, VertexType3(0, 1.1, -1) - p};
340 BOOST_CHECK(!bb3.intersect(ray3));
342 ray3 = {
p, VertexType3(0, -1.1, -1) - p};
343 BOOST_CHECK(!bb3.intersect(ray3));
345 ray3 = {
p, VertexType3(0.9, 0, -1) - p};
346 BOOST_CHECK(bb3.intersect(ray3));
348 ray3 = {
p, VertexType3(-0.9, 0, -1) - p};
349 BOOST_CHECK(bb3.intersect(ray3));
351 ray3 = {
p, VertexType3(0, 0.9, -1) - p};
352 BOOST_CHECK(bb3.intersect(ray3));
354 ray3 = {
p, VertexType3(0, -0.9, -1) - p};
355 BOOST_CHECK(bb3.intersect(ray3));
357 ray3 = {{0, 0, 0}, {1, 0, 0}};
358 BOOST_CHECK(bb3.intersect(ray3));
359 ray3 = {{0, 0, 0}, {0, 1, 0}};
360 BOOST_CHECK(bb3.intersect(ray3));
361 ray3 = {{0, 0, 0}, {0, 0, 1}};
362 BOOST_CHECK(bb3.intersect(ray3));
364 ray3 = {{0, 0, 0}, {-1, 0, 0}};
365 BOOST_CHECK(bb3.intersect(ray3));
366 ray3 = {{0, 0, 0}, {0, -1, 0}};
367 BOOST_CHECK(bb3.intersect(ray3));
368 ray3 = {{0, 0, 0}, {0, 0, -1}};
369 BOOST_CHECK(bb3.intersect(ray3));
376 std::array<Vector3D, 8> vertices;
377 vertices = {{{0, 0, 0},
385 auto cubo = std::make_shared<GenericCuboidVolumeBounds>(vertices);
395 trl.translation() = trf.translation();
400 obb.
draw(ply, {200, 0, 0});
407 for (
const auto& vtx_ : vertices) {
416 for (
const auto& vtx_ : vertices) {
421 Ray ray(origin, (vtx - origin).normalized());
423 BOOST_CHECK(obb.intersect(ray));
424 ray.
draw(ply, (vtx - origin).norm());
428 vtx += (vtx - centroid);
429 ray =
Ray(origin, (vtx - origin).normalized());
431 BOOST_CHECK(!obb.intersect(ray));
432 ray.
draw(ply, (vtx - origin).norm());
437 BOOST_TEST_CONTEXT(
"2D") {
438 auto make_svg = [](std::string fname,
size_t w,
size_t h) {
439 std::ofstream os(fname);
440 os <<
"<?xml version=\"1.0\" standalone=\"no\"?>\n";
441 os <<
"<svg width=\"" << w <<
"\" height=\"" <<
h
442 <<
"\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">\n";
488 float stepx = (maxx - minx) /
float(n);
489 float stepy = (maxy - miny) /
float(n);
491 std::set<size_t> act_idxs;
494 std::vector<std::pair<Frustum2, std::set<size_t>>> fr_exp;
496 {Frustum2({0, 0}, {1, 0},
M_PI / 2.),
497 {60, 70, 71, 72, 80, 81, 82, 83, 84, 90, 91, 92,
498 93, 94, 95, 96, 100, 101, 102, 103, 104, 105, 106, 107,
499 108, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120}
501 {Frustum2({0, 0}, {1, 0}, 0.5 *
M_PI / 2.),
502 {60, 71, 81, 82, 83, 92, 93, 94, 102,
503 103, 104, 105, 106, 113, 114, 115, 116, 117}
505 {Frustum2({0, 0}, {1, 0}, 0.2 *
M_PI / 2.),
506 {60, 71, 82, 93, 104, 114, 115, 116}
508 {Frustum2({0, 0}, {1, 0}, 3 *
M_PI / 4.),
509 {60, 68, 69, 70, 71, 72, 73, 74, 77, 78, 79, 80, 81, 82, 83,
510 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98,
511 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
512 112, 113, 114, 115, 116, 117, 118, 119, 120}
514 {Frustum2({0, 0}, {0, 1}, 0.5 *
M_PI / 2.),
515 {42, 43, 51, 52, 53, 54, 60, 61, 62, 63, 64, 65, 73, 74, 75, 76, 86, 87}
517 {Frustum2({0, 0}, {-1, 0}, 0.5 *
M_PI / 2.),
518 {3, 4, 5, 6, 7, 14, 15, 16, 17, 18, 26, 27, 28, 37, 38, 39, 49, 60}
520 {Frustum2({0, 0}, {0, -1}, 0.5 *
M_PI / 2.),
521 {33, 34, 44, 45, 46, 47, 55, 56, 57, 58, 59, 60, 66, 67, 68, 69, 77, 78}
523 {Frustum2({0, 0}, {1, 1}, 0.5 *
M_PI / 2.),
524 {60, 72, 73, 74, 83, 84, 85, 86, 87, 94, 95, 96, 97, 98, 106, 107,
525 108, 109, 117, 118, 119, 120}
527 {Frustum2({0, 0}, {-1, 1}, 0.5 *
M_PI / 2.),
528 {7, 8, 9, 10, 18, 19, 20, 21, 28, 29, 30, 31, 32, 39, 40, 41, 42,
531 {Frustum2({0, 0}, {-1, -1}, 0.5 *
M_PI / 2.),
532 {0, 1, 2, 3, 11, 12, 13, 14, 22, 23, 24, 25, 26, 33, 34, 35, 36,
535 {Frustum2({0, 0}, {1, -1}, 0.5 *
M_PI / 2.),
536 {60, 68, 69, 70, 77, 78, 79, 80, 81, 88, 89, 90, 91, 92, 99, 100,
537 101, 102, 110, 111, 112, 113}
539 {Frustum2({1, 1}, {1, -1},
M_PI / 2.),
540 {55, 56, 57, 58, 59, 60, 66, 67, 68, 69, 70, 71, 77, 78, 79, 80,
541 81, 82, 88, 89, 90, 91, 92, 93, 99, 100, 101, 102, 103, 104, 110, 111, 112, 113, 114, 115}
543 {Frustum2({-1, -1}, {1, -1},
M_PI / 2.),
544 {55, 56, 57, 58, 59, 60, 66, 67, 68, 69, 70, 71, 77, 78, 79, 80,
545 81, 82, 88, 89, 90, 91, 92, 93, 99, 100, 101, 102, 103, 104, 110, 111, 112, 113, 114, 115}
547 {Frustum2({10, -10}, {1, 1}, 0.5 *
M_PI / 2.),
548 {91, 92, 102, 103, 104, 105, 114, 115, 116, 117, 118, 119}
550 {Frustum2({-10.3, 12.8}, {0.3, -1}, 0.5 *
M_PI / 2.),
551 {22, 23, 24, 25, 26, 27, 28, 33, 34, 35, 36, 37, 38, 39, 40, 41,
552 44, 45, 46, 47, 48, 49, 50, 55, 56, 57, 58, 59, 60, 66, 67, 68,
553 69, 70, 77, 78, 79, 80, 88, 89, 99}
555 {Frustum2({17.2, 19.45}, {-1, -0.1}, 0.5 *
M_PI / 2.),
556 {5, 6, 7, 8, 9, 10, 17, 18, 19, 20, 21, 28, 29, 30, 31, 32, 40,
557 41, 42, 43, 51, 52, 53, 54, 63, 64, 65, 74, 75, 76, 86, 87, 97,
563 for (
size_t l = 0; l < fr_exp.size(); l++) {
564 const Frustum2& fr = fr_exp.at(l).first;
565 const std::set<size_t>& exp_idxs = fr_exp.at(l).second;
566 std::stringstream ss;
567 ss <<
"frust2d_test_" << l <<
".svg";
568 os = make_svg(ss.str(), w, w);
572 std::vector<Box> boxes;
573 boxes.reserve((n + 1) * (n + 1));
574 for (
size_t i = 0; i <=
n; i++) {
575 for (
size_t j = 0; j <=
n; j++) {
578 std::stringstream st;
579 st << boxes.size() - 1;
581 std::string
color =
"red";
582 if (boxes.back().intersect(fr)) {
584 act_idxs.insert(boxes.size() - 1);
587 boxes.back().svg(os, w, w, unit, st.str(),
color);
591 BOOST_CHECK(act_idxs == exp_idxs);
593 fr.svg(os, w, w, maxx, unit);
601 BOOST_TEST_CONTEXT(
"3D - 3 Sides") {
606 double min = -10,
max = 10;
666 std::set<size_t> act_idxs;
668 std::vector<std::pair<Frustum3, std::set<size_t>>> fr_exp;
672 665, 763, 774, 775, 785, 786, 787, 788, 796, 797, 807,
673 872, 873, 883, 884, 885, 886, 894, 895, 896, 897, 898,
674 905, 906, 907, 908, 909, 910, 911, 916, 917, 918, 919,
675 920, 927, 928, 929, 930, 938, 939, 970, 971, 981, 982,
676 983, 992, 993, 994, 995, 996, 1003, 1004, 1005, 1006, 1007,
677 1008, 1009, 1014, 1015, 1016, 1017, 1018, 1019, 1020, 1021, 1025,
678 1026, 1027, 1028, 1029, 1030, 1031, 1032, 1033, 1036, 1037, 1038,
679 1039, 1040, 1041, 1042, 1043, 1047, 1048, 1049, 1050, 1051, 1052,
680 1053, 1058, 1059, 1060, 1061, 1062, 1069, 1070, 1071, 1080, 1081,
681 1090, 1091, 1092, 1093, 1094, 1101, 1102, 1103, 1104, 1105, 1106,
682 1112, 1113, 1114, 1115, 1116, 1117, 1118, 1119, 1123, 1124, 1125,
683 1126, 1127, 1128, 1129, 1130, 1131, 1132, 1134, 1135, 1136, 1137,
684 1138, 1139, 1140, 1141, 1142, 1143, 1145, 1146, 1147, 1148, 1149,
685 1150, 1151, 1152, 1153, 1154, 1156, 1157, 1158, 1159, 1160, 1161,
686 1162, 1163, 1164, 1165, 1167, 1168, 1169, 1170, 1171, 1172, 1173,
687 1174, 1175, 1176, 1178, 1179, 1180, 1181, 1182, 1183, 1184, 1185,
688 1189, 1190, 1191, 1192, 1193, 1194, 1200, 1201, 1202, 1203, 1204,
689 1210, 1211, 1212, 1213, 1214, 1215, 1216, 1217, 1221, 1222, 1223,
690 1224, 1225, 1226, 1227, 1228, 1229, 1232, 1233, 1234, 1235, 1236,
691 1237, 1238, 1239, 1240, 1241, 1242, 1243, 1244, 1245, 1246, 1247,
692 1248, 1249, 1250, 1251, 1252, 1253, 1254, 1255, 1256, 1257, 1258,
693 1259, 1260, 1261, 1262, 1263, 1264, 1265, 1266, 1267, 1268, 1269,
694 1270, 1271, 1272, 1273, 1274, 1275, 1276, 1277, 1278, 1279, 1280,
695 1281, 1282, 1283, 1284, 1285, 1286, 1287, 1288, 1289, 1290, 1291,
696 1292, 1293, 1294, 1295, 1296, 1297, 1298, 1299, 1300, 1301, 1302,
697 1303, 1304, 1305, 1306, 1307, 1308, 1309, 1310, 1311, 1312, 1313,
698 1314, 1315, 1316, 1317, 1320, 1321, 1322, 1323, 1324, 1325, 1326,
702 {93, 102, 103, 104, 105, 106, 112, 113, 114, 115, 116,
703 117, 118, 203, 213, 214, 215, 223, 224, 225, 226, 227,
704 233, 234, 235, 236, 237, 238, 239, 324, 333, 334, 335,
705 336, 337, 343, 344, 345, 346, 347, 348, 349, 353, 354,
706 355, 356, 357, 358, 359, 360, 361, 434, 444, 445, 446,
707 454, 455, 456, 457, 458, 464, 465, 466, 467, 468, 469,
708 470, 473, 474, 475, 476, 477, 478, 479, 480, 481, 482,
709 483, 555, 564, 565, 566, 567, 568, 574, 575, 576, 577,
710 578, 579, 580, 584, 585, 586, 587, 588, 589, 590, 591,
711 592, 594, 595, 596, 597, 598, 599, 600, 601, 602, 603,
712 604, 665, 675, 676, 677, 685, 686, 687, 688, 689, 695,
713 696, 697, 698, 699, 700, 701, 704, 705, 706, 707, 708,
714 709, 710, 711, 712, 713, 714, 715, 716, 717, 718, 719,
715 720, 721, 722, 723, 724, 725, 795, 796, 797, 798, 799,
716 805, 806, 807, 808, 809, 810, 811, 815, 816, 817, 818,
717 819, 820, 821, 822, 823, 825, 826, 827, 828, 829, 830,
718 831, 832, 833, 834, 835, 836, 837, 838, 839, 840, 841,
719 842, 843, 844, 845, 846, 926, 927, 928, 929, 930, 931,
720 932, 935, 936, 937, 938, 939, 940, 941, 942, 943, 944,
721 945, 946, 947, 948, 949, 950, 951, 952, 953, 954, 955,
722 956, 957, 958, 959, 960, 961, 962, 963, 964, 965, 966,
723 967, 1056, 1057, 1058, 1059, 1060, 1061, 1062, 1063, 1064, 1065,
724 1066, 1067, 1068, 1069, 1070, 1071, 1072, 1073, 1074, 1075, 1076,
725 1077, 1078, 1079, 1080, 1081, 1082, 1083, 1084, 1085, 1086, 1087,
726 1088, 1188, 1189, 1190, 1191, 1192, 1193, 1194, 1195, 1196, 1197,
727 1198, 1199, 1200, 1201, 1202, 1203, 1204, 1205, 1206, 1207, 1208,
728 1209, 1320, 1321, 1322, 1323, 1324, 1325, 1326, 1327, 1328, 1329,
731 {32, 42, 43, 53, 54, 63, 64, 65, 75, 76, 86,
732 87, 98, 153, 163, 164, 173, 174, 175, 183, 184, 185,
733 186, 195, 196, 197, 207, 208, 219, 263, 273, 274, 283,
734 284, 285, 294, 295, 296, 304, 305, 306, 307, 316, 317,
735 318, 327, 328, 329, 339, 340, 351, 373, 384, 394, 395,
736 404, 405, 406, 414, 415, 416, 417, 424, 425, 426, 427,
737 428, 436, 437, 438, 439, 448, 449, 450, 460, 461, 472,
738 483, 494, 504, 505, 514, 515, 516, 524, 525, 526, 527,
739 535, 536, 537, 538, 545, 546, 547, 548, 549, 557, 558,
740 559, 560, 568, 569, 570, 571, 580, 581, 582, 592, 593,
741 604, 614, 615, 625, 626, 635, 636, 637, 645, 646, 647,
742 648, 655, 656, 657, 658, 659, 665, 666, 667, 668, 669,
743 670, 677, 678, 679, 680, 681, 689, 690, 691, 692, 701,
744 702, 703, 713, 714, 724, 725, 735, 736, 745, 746, 747,
745 755, 756, 757, 758, 765, 766, 767, 768, 769, 776, 777,
746 778, 779, 780, 787, 788, 789, 790, 791, 798, 799, 800,
747 801, 802, 809, 810, 811, 812, 813, 821, 822, 823, 824,
748 833, 834, 835, 845, 846, 855, 856, 857, 866, 867, 868,
749 876, 877, 878, 879, 887, 888, 889, 890, 898, 899, 900,
750 901, 909, 910, 911, 912, 920, 921, 922, 923, 931, 932,
751 933, 934, 942, 943, 944, 945, 954, 955, 956, 965, 966,
752 967, 976, 977, 978, 987, 988, 989, 998, 999, 1000, 1009,
753 1010, 1011, 1020, 1021, 1022, 1031, 1032, 1033, 1042, 1043, 1044,
754 1053, 1054, 1055, 1064, 1065, 1066, 1075, 1076, 1077, 1086, 1087,
755 1088, 1098, 1099, 1109, 1110, 1120, 1121, 1131, 1132, 1142, 1143,
756 1153, 1154, 1164, 1165, 1175, 1176, 1186, 1187, 1197, 1198, 1208,
757 1209, 1220, 1231, 1242, 1253, 1264, 1275, 1286, 1297, 1308, 1319,
760 {186, 305, 306, 307, 416, 417, 425, 426, 427, 428, 438, 439,
761 527, 536, 537, 538, 545, 546, 547, 548, 549, 558, 559, 560,
762 571, 647, 648, 656, 657, 658, 659, 665, 666, 667, 668, 669,
763 670, 678, 679, 680, 681, 691, 692, 758, 767, 768, 769, 777,
764 778, 779, 780, 788, 789, 790, 791, 799, 800, 801, 802, 811,
765 812, 813, 824, 879, 890, 901, 912, 923, 934, 945}},
767 {427, 428, 546, 547, 548, 549, 658, 659, 665, 666, 667, 668, 669, 670,
768 680, 681, 780, 791, 802}},
770 {8, 9, 10, 19, 20, 21, 29, 30, 31, 32, 40,
771 41, 42, 43, 51, 52, 53, 54, 61, 62, 63, 64,
772 65, 73, 74, 75, 76, 84, 85, 86, 87, 95, 96,
773 97, 98, 107, 108, 109, 118, 119, 120, 129, 130, 131,
774 140, 141, 142, 150, 151, 152, 153, 161, 162, 163, 164,
775 171, 172, 173, 174, 175, 182, 183, 184, 185, 186, 193,
776 194, 195, 196, 197, 205, 206, 207, 208, 216, 217, 218,
777 219, 228, 229, 230, 239, 240, 241, 250, 251, 252, 260,
778 261, 262, 263, 271, 272, 273, 274, 282, 283, 284, 285,
779 292, 293, 294, 295, 296, 303, 304, 305, 306, 307, 314,
780 315, 316, 317, 318, 326, 327, 328, 329, 337, 338, 339,
781 340, 348, 349, 350, 351, 360, 361, 362, 370, 371, 372,
782 373, 381, 382, 383, 384, 392, 393, 394, 395, 402, 403,
783 404, 405, 406, 413, 414, 415, 416, 417, 424, 425, 426,
784 427, 428, 435, 436, 437, 438, 439, 446, 447, 448, 449,
785 450, 458, 459, 460, 461, 469, 470, 471, 472, 480, 481,
786 482, 483, 491, 492, 493, 494, 502, 503, 504, 505, 513,
787 514, 515, 516, 523, 524, 525, 526, 527, 534, 535, 536,
788 537, 538, 544, 545, 546, 547, 548, 549, 556, 557, 558,
789 559, 560, 567, 568, 569, 570, 571, 579, 580, 581, 582,
790 590, 591, 592, 593, 601, 602, 603, 604, 612, 613, 614,
791 615, 623, 624, 625, 626, 633, 634, 635, 636, 637, 644,
792 645, 646, 647, 648, 655, 656, 657, 658, 659, 665, 666,
793 667, 668, 669, 670, 677, 678, 679, 680, 681, 688, 689,
794 690, 691, 692, 699, 700, 701, 702, 703, 711, 712, 713,
795 714, 722, 723, 724, 725, 733, 734, 735, 736, 743, 744,
796 745, 746, 747, 754, 755, 756, 757, 758, 765, 766, 767,
797 768, 769, 776, 777, 778, 779, 780, 787, 788, 789, 790,
798 791, 798, 799, 800, 801, 802, 809, 810, 811, 812, 813,
799 820, 821, 822, 823, 824, 831, 832, 833, 834, 835, 843,
800 844, 845, 846, 854, 855, 856, 857, 864, 865, 866, 867,
801 868, 875, 876, 877, 878, 879, 886, 887, 888, 889, 890,
802 897, 898, 899, 900, 901, 908, 909, 910, 911, 912, 919,
803 920, 921, 922, 923, 930, 931, 932, 933, 934, 941, 942,
804 943, 944, 945, 952, 953, 954, 955, 956, 964, 965, 966,
805 967, 975, 976, 977, 978, 986, 987, 988, 989, 997, 998,
806 999, 1000, 1008, 1009, 1010, 1011, 1019, 1020, 1021, 1022, 1030,
807 1031, 1032, 1033, 1041, 1042, 1043, 1044, 1052, 1053, 1054, 1055,
808 1063, 1064, 1065, 1066, 1074, 1075, 1076, 1077, 1085, 1086, 1087,
809 1088, 1096, 1097, 1098, 1099, 1107, 1108, 1109, 1110, 1118, 1119,
810 1120, 1121, 1129, 1130, 1131, 1132, 1140, 1141, 1142, 1143, 1151,
811 1152, 1153, 1154, 1162, 1163, 1164, 1165, 1173, 1174, 1175, 1176,
812 1184, 1185, 1186, 1187, 1195, 1196, 1197, 1198, 1206, 1207, 1208,
813 1209, 1217, 1218, 1219, 1220, 1228, 1229, 1230, 1231, 1239, 1240,
814 1241, 1242, 1250, 1251, 1252, 1253, 1261, 1262, 1263, 1264, 1272,
815 1273, 1274, 1275, 1283, 1284, 1285, 1286, 1294, 1295, 1296, 1297,
816 1305, 1306, 1307, 1308, 1316, 1317, 1318, 1319, 1327, 1328, 1329,
819 {318, 426, 427, 428, 438, 439, 450, 538, 546, 547, 548,
820 549, 558, 559, 560, 570, 571, 582, 655, 656, 657, 658,
821 659, 667, 668, 669, 670, 678, 679, 680, 681, 690, 691,
822 692, 702, 703, 714, 768, 769, 777, 778, 779, 780, 787,
823 788, 789, 790, 791, 799, 800, 801, 802, 810, 811, 812,
824 813, 822, 823, 824, 834, 835, 846, 888, 889, 890, 899,
825 900, 901, 910, 911, 912, 920, 921, 922, 923, 931, 932,
826 933, 934, 942, 943, 944, 945, 954, 955, 956, 966, 967,
827 1000, 1010, 1011, 1021, 1022, 1032, 1033, 1042, 1043, 1044, 1053,
828 1054, 1055, 1064, 1065, 1066, 1074, 1075, 1076, 1077, 1086, 1087,
829 1088, 1143, 1154, 1165, 1175, 1176, 1186, 1187, 1197, 1198, 1207,
830 1208, 1209, 1308, 1319, 1330}}};
832 for (
size_t l = 0; l < fr_exp.size(); l++) {
833 const Frustum3& fr = fr_exp.at(l).first;
834 const std::set<size_t>& exp_idxs = fr_exp.at(l).second;
835 std::stringstream ss;
836 ss <<
"frust3d-3s_test_" << l <<
".ply";
838 os = std::ofstream(ss.str());
849 step = (
max -
min) /
float(n);
857 for (
size_t i = 0; i <=
n; i++) {
858 for (
size_t j = 0; j <=
n; j++) {
859 for (
size_t k = 0;
k <=
n;
k++) {
861 Box bb(&o, pos, size);
863 std::array<int, 3>
color = {255, 0, 0};
867 act_idxs.insert(idx);
870 bb.
draw(helper, color);
876 os << helper << std::flush;
879 BOOST_CHECK(act_idxs == exp_idxs);
883 BOOST_TEST_CONTEXT(
"3D - 4 Sides") {
886 double min = -10,
max = 10;
942 std::set<size_t> act_idxs;
944 std::vector<std::pair<Frustum34, std::set<size_t>>> fr_exp;
946 {Frustum34({0, 0, 0}, {1, 0, 0},
M_PI / 2.),
947 {665, 774, 775, 776, 785, 786, 787, 796, 797, 798, 883,
948 884, 885, 886, 887, 894, 895, 896, 897, 898, 905, 906,
949 907, 908, 909, 916, 917, 918, 919, 920, 927, 928, 929,
950 930, 931, 992, 993, 994, 995, 996, 997, 998, 1003, 1004,
951 1005, 1006, 1007, 1008, 1009, 1014, 1015, 1016, 1017, 1018, 1019,
952 1020, 1025, 1026, 1027, 1028, 1029, 1030, 1031, 1036, 1037, 1038,
953 1039, 1040, 1041, 1042, 1047, 1048, 1049, 1050, 1051, 1052, 1053,
954 1058, 1059, 1060, 1061, 1062, 1063, 1064, 1101, 1102, 1103, 1104,
955 1105, 1106, 1107, 1108, 1109, 1112, 1113, 1114, 1115, 1116, 1117,
956 1118, 1119, 1120, 1123, 1124, 1125, 1126, 1127, 1128, 1129, 1130,
957 1131, 1134, 1135, 1136, 1137, 1138, 1139, 1140, 1141, 1142, 1145,
958 1146, 1147, 1148, 1149, 1150, 1151, 1152, 1153, 1156, 1157, 1158,
959 1159, 1160, 1161, 1162, 1163, 1164, 1167, 1168, 1169, 1170, 1171,
960 1172, 1173, 1174, 1175, 1178, 1179, 1180, 1181, 1182, 1183, 1184,
961 1185, 1186, 1189, 1190, 1191, 1192, 1193, 1194, 1195, 1196, 1197,
962 1210, 1211, 1212, 1213, 1214, 1215, 1216, 1217, 1218, 1219, 1220,
963 1221, 1222, 1223, 1224, 1225, 1226, 1227, 1228, 1229, 1230, 1231,
964 1232, 1233, 1234, 1235, 1236, 1237, 1238, 1239, 1240, 1241, 1242,
965 1243, 1244, 1245, 1246, 1247, 1248, 1249, 1250, 1251, 1252, 1253,
966 1254, 1255, 1256, 1257, 1258, 1259, 1260, 1261, 1262, 1263, 1264,
967 1265, 1266, 1267, 1268, 1269, 1270, 1271, 1272, 1273, 1274, 1275,
968 1276, 1277, 1278, 1279, 1280, 1281, 1282, 1283, 1284, 1285, 1286,
969 1287, 1288, 1289, 1290, 1291, 1292, 1293, 1294, 1295, 1296, 1297,
970 1298, 1299, 1300, 1301, 1302, 1303, 1304, 1305, 1306, 1307, 1308,
971 1309, 1310, 1311, 1312, 1313, 1314, 1315, 1316, 1317, 1318, 1319,
972 1320, 1321, 1322, 1323, 1324, 1325, 1326, 1327, 1328, 1329, 1330}},
973 {Frustum34({0, 0, 0}, {0, 1, 0},
M_PI / 2.),
974 {110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120,
975 221, 222, 223, 224, 225, 226, 227, 228, 229, 231, 232,
976 233, 234, 235, 236, 237, 238, 239, 240, 241, 332, 333,
977 334, 335, 336, 337, 338, 342, 343, 344, 345, 346, 347,
978 348, 349, 350, 352, 353, 354, 355, 356, 357, 358, 359,
979 360, 361, 362, 443, 444, 445, 446, 447, 453, 454, 455,
980 456, 457, 458, 459, 463, 464, 465, 466, 467, 468, 469,
981 470, 471, 473, 474, 475, 476, 477, 478, 479, 480, 481,
982 482, 483, 554, 555, 556, 564, 565, 566, 567, 568, 574,
983 575, 576, 577, 578, 579, 580, 584, 585, 586, 587, 588,
984 589, 590, 591, 592, 594, 595, 596, 597, 598, 599, 600,
985 601, 602, 603, 604, 665, 675, 676, 677, 685, 686, 687,
986 688, 689, 695, 696, 697, 698, 699, 700, 701, 705, 706,
987 707, 708, 709, 710, 711, 712, 713, 715, 716, 717, 718,
988 719, 720, 721, 722, 723, 724, 725, 796, 797, 798, 806,
989 807, 808, 809, 810, 816, 817, 818, 819, 820, 821, 822,
990 826, 827, 828, 829, 830, 831, 832, 833, 834, 836, 837,
991 838, 839, 840, 841, 842, 843, 844, 845, 846, 927, 928,
992 929, 930, 931, 937, 938, 939, 940, 941, 942, 943, 947,
993 948, 949, 950, 951, 952, 953, 954, 955, 957, 958, 959,
994 960, 961, 962, 963, 964, 965, 966, 967, 1058, 1059, 1060,
995 1061, 1062, 1063, 1064, 1068, 1069, 1070, 1071, 1072, 1073, 1074,
996 1075, 1076, 1078, 1079, 1080, 1081, 1082, 1083, 1084, 1085, 1086,
997 1087, 1088, 1189, 1190, 1191, 1192, 1193, 1194, 1195, 1196, 1197,
998 1199, 1200, 1201, 1202, 1203, 1204, 1205, 1206, 1207, 1208, 1209,
999 1320, 1321, 1322, 1323, 1324, 1325, 1326, 1327, 1328, 1329, 1330}},
1000 {Frustum34({0, 0, 0}, {0, 0, 1},
M_PI / 2.),
1001 {10, 21, 32, 43, 54, 65, 76, 87, 98, 109, 120,
1002 131, 141, 142, 152, 153, 163, 164, 174, 175, 185, 186,
1003 196, 197, 207, 208, 218, 219, 229, 230, 241, 252, 262,
1004 263, 272, 273, 274, 283, 284, 285, 294, 295, 296, 305,
1005 306, 307, 316, 317, 318, 327, 328, 329, 338, 339, 340,
1006 350, 351, 362, 373, 383, 384, 393, 394, 395, 403, 404,
1007 405, 406, 414, 415, 416, 417, 425, 426, 427, 428, 436,
1008 437, 438, 439, 447, 448, 449, 450, 459, 460, 461, 471,
1009 472, 483, 494, 504, 505, 514, 515, 516, 524, 525, 526,
1010 527, 534, 535, 536, 537, 538, 545, 546, 547, 548, 549,
1011 556, 557, 558, 559, 560, 568, 569, 570, 571, 580, 581,
1012 582, 592, 593, 604, 615, 625, 626, 635, 636, 637, 645,
1013 646, 647, 648, 655, 656, 657, 658, 659, 665, 666, 667,
1014 668, 669, 670, 677, 678, 679, 680, 681, 689, 690, 691,
1015 692, 701, 702, 703, 713, 714, 725, 736, 746, 747, 756,
1016 757, 758, 766, 767, 768, 769, 776, 777, 778, 779, 780,
1017 787, 788, 789, 790, 791, 798, 799, 800, 801, 802, 810,
1018 811, 812, 813, 822, 823, 824, 834, 835, 846, 857, 867,
1019 868, 877, 878, 879, 887, 888, 889, 890, 898, 899, 900,
1020 901, 909, 910, 911, 912, 920, 921, 922, 923, 931, 932,
1021 933, 934, 943, 944, 945, 955, 956, 967, 978, 988, 989,
1022 998, 999, 1000, 1009, 1010, 1011, 1020, 1021, 1022, 1031, 1032,
1023 1033, 1042, 1043, 1044, 1053, 1054, 1055, 1064, 1065, 1066, 1076,
1024 1077, 1088, 1099, 1109, 1110, 1120, 1121, 1131, 1132, 1142, 1143,
1025 1153, 1154, 1164, 1165, 1175, 1176, 1186, 1187, 1197, 1198, 1209,
1026 1220, 1231, 1242, 1253, 1264, 1275, 1286, 1297, 1308, 1319, 1330}},
1027 {Frustum34({0, 0, 0}, {0, 0, 1},
M_PI / 4.),
1028 {406, 417, 428, 439, 450, 527, 535, 536, 537, 538, 546, 547, 548, 549,
1029 557, 558, 559, 560, 571, 648, 656, 657, 658, 659, 665, 666, 667, 668,
1030 669, 670, 678, 679, 680, 681, 692, 769, 777, 778, 779, 780, 788, 789,
1031 790, 791, 799, 800, 801, 802, 813, 890, 901, 912, 923, 934}},
1032 {Frustum34({0, 0, 0}, {0, 0, 1},
M_PI / 8.),
1033 {538, 549, 560, 659, 665, 666, 667, 668, 669, 670, 681, 780, 791,
1035 {Frustum34({0, 0, 0}, {0, 0, 1},
M_PI * 3. / 4.),
1036 {7, 8, 9, 10, 18, 19, 20, 21, 29, 30, 31,
1037 32, 40, 41, 42, 43, 51, 52, 53, 54, 62, 63,
1038 64, 65, 73, 74, 75, 76, 84, 85, 86, 87, 95,
1039 96, 97, 98, 106, 107, 108, 109, 117, 118, 119, 120,
1040 128, 129, 130, 131, 139, 140, 141, 142, 150, 151, 152,
1041 153, 161, 162, 163, 164, 172, 173, 174, 175, 183, 184,
1042 185, 186, 194, 195, 196, 197, 205, 206, 207, 208, 216,
1043 217, 218, 219, 227, 228, 229, 230, 238, 239, 240, 241,
1044 249, 250, 251, 252, 260, 261, 262, 263, 271, 272, 273,
1045 274, 282, 283, 284, 285, 293, 294, 295, 296, 304, 305,
1046 306, 307, 315, 316, 317, 318, 326, 327, 328, 329, 337,
1047 338, 339, 340, 348, 349, 350, 351, 359, 360, 361, 362,
1048 370, 371, 372, 373, 381, 382, 383, 384, 392, 393, 394,
1049 395, 402, 403, 404, 405, 406, 413, 414, 415, 416, 417,
1050 424, 425, 426, 427, 428, 435, 436, 437, 438, 439, 446,
1051 447, 448, 449, 450, 458, 459, 460, 461, 469, 470, 471,
1052 472, 480, 481, 482, 483, 491, 492, 493, 494, 502, 503,
1053 504, 505, 513, 514, 515, 516, 523, 524, 525, 526, 527,
1054 534, 535, 536, 537, 538, 545, 546, 547, 548, 549, 556,
1055 557, 558, 559, 560, 567, 568, 569, 570, 571, 579, 580,
1056 581, 582, 590, 591, 592, 593, 601, 602, 603, 604, 612,
1057 613, 614, 615, 623, 624, 625, 626, 634, 635, 636, 637,
1058 644, 645, 646, 647, 648, 655, 656, 657, 658, 659, 665,
1059 666, 667, 668, 669, 670, 677, 678, 679, 680, 681, 688,
1060 689, 690, 691, 692, 700, 701, 702, 703, 711, 712, 713,
1061 714, 722, 723, 724, 725, 733, 734, 735, 736, 744, 745,
1062 746, 747, 755, 756, 757, 758, 765, 766, 767, 768, 769,
1063 776, 777, 778, 779, 780, 787, 788, 789, 790, 791, 798,
1064 799, 800, 801, 802, 809, 810, 811, 812, 813, 821, 822,
1065 823, 824, 832, 833, 834, 835, 843, 844, 845, 846, 854,
1066 855, 856, 857, 865, 866, 867, 868, 876, 877, 878, 879,
1067 886, 887, 888, 889, 890, 897, 898, 899, 900, 901, 908,
1068 909, 910, 911, 912, 919, 920, 921, 922, 923, 930, 931,
1069 932, 933, 934, 942, 943, 944, 945, 953, 954, 955, 956,
1070 964, 965, 966, 967, 975, 976, 977, 978, 986, 987, 988,
1071 989, 997, 998, 999, 1000, 1008, 1009, 1010, 1011, 1019, 1020,
1072 1021, 1022, 1030, 1031, 1032, 1033, 1041, 1042, 1043, 1044, 1052,
1073 1053, 1054, 1055, 1063, 1064, 1065, 1066, 1074, 1075, 1076, 1077,
1074 1085, 1086, 1087, 1088, 1096, 1097, 1098, 1099, 1107, 1108, 1109,
1075 1110, 1118, 1119, 1120, 1121, 1129, 1130, 1131, 1132, 1140, 1141,
1076 1142, 1143, 1151, 1152, 1153, 1154, 1162, 1163, 1164, 1165, 1173,
1077 1174, 1175, 1176, 1184, 1185, 1186, 1187, 1195, 1196, 1197, 1198,
1078 1206, 1207, 1208, 1209, 1217, 1218, 1219, 1220, 1228, 1229, 1230,
1079 1231, 1239, 1240, 1241, 1242, 1250, 1251, 1252, 1253, 1261, 1262,
1080 1263, 1264, 1272, 1273, 1274, 1275, 1283, 1284, 1285, 1286, 1294,
1081 1295, 1296, 1297, 1305, 1306, 1307, 1308, 1316, 1317, 1318, 1319,
1082 1327, 1328, 1329, 1330}},
1083 {Frustum34({1.3, -5.9, 3.5}, {0.2, 0.4, 1},
M_PI / 3.),
1084 {461, 472, 537, 538, 548, 549, 558, 559, 560, 569, 570,
1085 571, 581, 582, 593, 655, 656, 657, 658, 659, 666, 667,
1086 668, 669, 670, 678, 679, 680, 681, 690, 691, 692, 702,
1087 703, 714, 777, 778, 779, 780, 787, 788, 789, 790, 791,
1088 799, 800, 801, 802, 811, 812, 813, 823, 824, 835, 846,
1089 899, 900, 901, 910, 911, 912, 920, 921, 922, 923, 932,
1090 933, 934, 944, 945, 955, 956, 967, 1021, 1022, 1032, 1033,
1091 1042, 1043, 1044, 1053, 1054, 1055, 1064, 1065, 1066, 1076, 1077,
1092 1088, 1143, 1154, 1165, 1175, 1176, 1186, 1187, 1197, 1198, 1209,
1093 1308, 1319, 1330}}};
1095 for (
size_t l = 0; l < fr_exp.size(); l++) {
1096 const Frustum34& fr = fr_exp.at(l).first;
1097 const std::set<size_t>& exp_idxs = fr_exp.at(l).second;
1098 std::stringstream ss;
1099 ss <<
"frust3d-4s_test_" << l <<
".ply";
1101 os = std::ofstream(ss.str());
1107 fr.draw(helper, 50);
1112 step = (
max -
min) /
float(n);
1119 for (
size_t i = 0; i <=
n; i++) {
1120 for (
size_t j = 0; j <=
n; j++) {
1121 for (
size_t k = 0;
k <=
n;
k++) {
1123 Box bb(&o, pos, size);
1125 std::array<int, 3>
color = {255, 0, 0};
1128 color = {0, 255, 0};
1129 act_idxs.insert(idx);
1132 bb.
draw(helper, color);
1138 os << helper << std::flush;
1141 BOOST_CHECK(act_idxs == exp_idxs);
1145 BOOST_TEST_CONTEXT(
"3D - 5 Sides") {
1157 Box bb(&o, {0, 0, 10}, size);
1160 BOOST_CHECK(bb.intersect(fr));
1162 std::ofstream os(
"frust3d-5s.ply");
1163 os << ply << std::flush;
1167 BOOST_TEST_CONTEXT(
"3D - 10 Sides") {
1178 vec3
pos = {-12.4205, 29.3578, 44.6207};
1179 vec3 dir = {-0.656862, 0.48138, 0.58035};
1180 Frustum fr(pos, dir, 0.972419);
1183 Box bb(&o, pos + dir * 10, size);
1188 std::ofstream os(
"frust3d-10s.ply");
1189 os << ply << std::flush;