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
|
// ----------------------------------------------------------------------------
// - Open3D: www.open3d.org -
// ----------------------------------------------------------------------------
// The MIT License (MIT)
//
// Copyright (c) 2018-2021 www.open3d.org
//
// 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 "open3d/geometry/Line3D.h"
#include "tests/Tests.h"
using namespace open3d::geometry;
using namespace ::testing;
using opt_d_t = open3d::utility::optional<double>;
using v_t = Eigen::Vector3d;
using plane_t = Eigen::Hyperplane<double, 3>;
// Test case parameter types
using lt_t = Line3D::LineType;
// Test data for failed intersection parameter tests
// line-type, plane-normal, line-origin, line-dir/seg-endpoint
using fl_intr_t = std::tuple<lt_t, v_t, v_t, v_t>;
// Test data for intersection parameter tests
// line-type, plane-normal, line-origin, line-dir/seg-endpoint, expected-param
using intr_t = std::tuple<lt_t, v_t, v_t, v_t, double>;
// Test data for projection parameter tests
// line-type, test-point, line-origin, line-dir/seg-endpoint, expected-param
using proj_t = std::tuple<lt_t, v_t, v_t, v_t, double>;
// Test data for intersections against AABBs
// line-type, line-origin, line-dir/seg-endpoint, optional expected parameter
using ab_t = std::tuple<lt_t, v_t, v_t, opt_d_t>;
// Test data for closest parameter tests
// line0-type, line0-origin, line0-dir/endpoint, line1-type, line1-origin,
// line1-dir/endpoint, line0-expected, line1-expected
using cp_t = std::tuple<lt_t, v_t, v_t, lt_t, v_t, v_t, double, double>;
// Factory function to build appropriate type from enum
std::shared_ptr<Line3D> LineFactory(lt_t type, const v_t& v0, const v_t& v1) {
if (type == lt_t::Line) {
return std::make_shared<Line3D>(v0, v1);
} else if (type == lt_t::Ray) {
return std::make_shared<Ray3D>(v0, v1);
} else if (type == lt_t::Segment) {
return std::make_shared<Segment3D>(v0, v1);
} else {
throw std::exception();
}
}
namespace open3d {
namespace tests {
// Line Transformation Tests
// ============================================================================
TEST(Line3D, Transform) {
Line3D line{{0, 1, 0}, {1, 0, 0}};
auto t = Eigen::Translation<double, 3>(1, 0, 0) *
Eigen::AngleAxis<double>(EIGEN_PI / 2., Eigen::Vector3d::UnitZ());
line.Transform(t);
// For some reason this does not work with ExpectEQ, even though the
// difference is ~1e-17 and the threshold is 1e-6
EXPECT_TRUE((line.Origin() - Eigen::Vector3d{0, 0, 0}).norm() < 1e-10);
ExpectEQ(line.Direction(), Eigen::Vector3d{0, 1, 0});
}
// Segment Transformation Tests
// ============================================================================
TEST(Segment3D, Transform) {
Segment3D seg{{0, 1, 0}, {1, 1, 0}};
auto t = Eigen::Translation<double, 3>(1, 0, 0) *
Eigen::AngleAxis<double>(EIGEN_PI / 2., Eigen::Vector3d::UnitZ());
seg.Transform(t);
// For some reason this does not work with ExpectEQ, even though the
// difference is ~1e-17 and the threshold is 1e-6
EXPECT_TRUE((seg.Origin() - Eigen::Vector3d{0, 0, 0}).norm() < 1e-10);
EXPECT_TRUE((seg.EndPoint() - Eigen::Vector3d{0, 1, 0}).norm() < 1e-10);
ExpectEQ(seg.Direction(), Eigen::Vector3d{0, 1, 0});
}
// Special Segment3D Tests
// ============================================================================
TEST(Segment3D, ConstructedNormalized) {
// In order to override ambiguity with Eigen's handling of direction
// normalization, the Segment3D constructor normalizes the direction on
// creation. This allows the length to be directly compared to line
// parameters without fear of breaking behavior. This is only necessary for
// segments, since lines and rays are by definition infinite.
Segment3D seg{{0, 0, 0}, {10, 0, 0}};
EXPECT_EQ(10., seg.Length());
}
TEST(Segment3D, GetBoundingBox0) {
Segment3D seg{{-3, -2, -1}, {3, 2, 1}};
AxisAlignedBoundingBox expected{{-3, -2, -1}, {3, 2, 1}};
ExpectEQ(expected.min_bound_, seg.GetBoundingBox().min_bound_);
ExpectEQ(expected.max_bound_, seg.GetBoundingBox().max_bound_);
}
TEST(Segment3D, GetBoundingBox1) {
Segment3D seg{{3, 2, 1}, {-3, -2, -1}};
AxisAlignedBoundingBox expected{{-3, -2, -1}, {3, 2, 1}};
ExpectEQ(expected.min_bound_, seg.GetBoundingBox().min_bound_);
ExpectEQ(expected.max_bound_, seg.GetBoundingBox().max_bound_);
}
// Intersection Parameter Tests
// ============================================================================
class FailedIntersectionParamTests : public TestWithParam<fl_intr_t> {};
TEST_P(FailedIntersectionParamTests, CheckFailedPlaneIntersections) {
auto line_type = std::get<0>(GetParam());
plane_t plane{std::get<1>(GetParam()), 0};
const auto& l0 = std::get<2>(GetParam());
const auto& l1 = std::get<3>(GetParam());
auto line = LineFactory(line_type, l0, l1);
auto result = line->IntersectionParameter(plane);
EXPECT_FALSE(result.has_value());
}
INSTANTIATE_TEST_SUITE_P(
Fail,
FailedIntersectionParamTests,
Values(
// Test parameters contain in this order:
// line type, plane normal, line origin, line-dir/seg-endpoint
// Lines should fail the plane intersections only when they are
// parallel to the plane. Test plane normals both ways to make
// sure that the code handles Eigen's +inf and -inf
fl_intr_t{lt_t::Line, {0, 0, -1}, {0, 0, 1}, {1, 0, 0}},
fl_intr_t{lt_t::Line, {0, 0, 1}, {0, 0, 1}, {1, 0, 0}},
fl_intr_t{lt_t::Line, {1, 0, 0}, {1, 0, 0}, {0, 1, 0}},
fl_intr_t{lt_t::Line, {-1, 0, 0}, {1, 0, 0}, {0, 1, 0}},
// Rays should fail where lines fail and also when the plane
// lies behind the origin
fl_intr_t{lt_t::Ray, {1, 0, 0}, {1, 0, 0}, {0, 1, 0}},
fl_intr_t{lt_t::Ray, {-1, 0, 0}, {1, 0, 0}, {0, 1, 0}},
fl_intr_t{lt_t::Ray, {1, 0, 0}, {1, 0, 0}, {1, 0, 0}},
// Segments should fail in the same cases as rays and lines,
// plus when the plane lies past the end point
fl_intr_t{lt_t::Segment, {1, 0, 0}, {1, 0, 0}, {1, 1, 0}},
fl_intr_t{lt_t::Segment, {-1, 0, 0}, {1, 0, 0}, {1, 1, 0}},
fl_intr_t{lt_t::Segment, {-1, 0, 0}, {1, 0, 0}, {2, 0, 0}},
fl_intr_t{lt_t::Segment, {1, 0, 0}, {-2, 0, 0}, {-1, 0, 0}}));
class IntersectionParamTests : public TestWithParam<intr_t> {};
TEST_P(IntersectionParamTests, CheckPlaneIntersections) {
auto line_type = std::get<0>(GetParam());
plane_t plane{std::get<1>(GetParam()), 0};
const auto& l0 = std::get<2>(GetParam());
const auto& l1 = std::get<3>(GetParam());
double expected = std::get<4>(GetParam());
auto line = LineFactory(line_type, l0, l1);
auto result = line->IntersectionParameter(plane);
EXPECT_TRUE(result.has_value());
EXPECT_EQ(expected, result.value());
}
INSTANTIATE_TEST_SUITE_P(
Pass,
IntersectionParamTests,
Values(
// Test parameters contain in this order:
// line type, plane normal, line origin, line-dir/seg-end,
// expected param
intr_t{lt_t::Line, {1, 0, 0}, {1, 0, 0}, {1, 0, 0}, -1},
intr_t{lt_t::Line, {0, 1, 0}, {-2, -2, 0}, {0, 1, 0}, 2},
intr_t{lt_t::Ray, {1, 0, 0}, {1, 0, 0}, {-1, 0, 0}, 1},
intr_t{lt_t::Ray, {0, 1, 0}, {-2, -2, 0}, {0, 1, 0}, 2},
intr_t{lt_t::Segment, {1, 0, 0}, {1, 0, 0}, {-2, 0, 0}, 1},
intr_t{lt_t::Segment, {0, 1, 0}, {-2, -2, 0}, {-2, 1, 0}, 2}));
// Projection Parameter Tests
// ============================================================================
class ProjectionParamTests : public TestWithParam<proj_t> {};
TEST_P(ProjectionParamTests, CheckProjectionParameters) {
auto line_type = std::get<0>(GetParam());
const auto& test_point = std::get<1>(GetParam());
const auto& l0 = std::get<2>(GetParam());
const auto& l1 = std::get<3>(GetParam());
double expected = std::get<4>(GetParam());
auto line = LineFactory(line_type, l0, l1);
double result = line->ProjectionParameter(test_point);
EXPECT_EQ(expected, result);
}
INSTANTIATE_TEST_SUITE_P(
Tests,
ProjectionParamTests,
Values(
// Lines will project to any point, positive or negative
proj_t{lt_t::Line, {1, 1, 0}, {0, 0, 0}, {1, 0, 0}, 1},
proj_t{lt_t::Line, {1, 1, 0}, {-4, 0, 0}, {1, 0, 0}, 5},
proj_t{lt_t::Line, {1, 1, 0}, {4, 0, 0}, {1, 0, 0}, -3},
// Rays will project to any positive point, but negative points
// will return 0
proj_t{lt_t::Ray, {1, 1, 0}, {0, 0, 0}, {0, 1, 0}, 1},
proj_t{lt_t::Ray, {1, 1, 0}, {0, -4, 0}, {0, 1, 0}, 5},
proj_t{lt_t::Ray, {1, 1, 0}, {0, 4, 0}, {0, 1, 0}, 0},
// Line segments will only project between 0 and their length
proj_t{lt_t::Segment, {1, 1, 0}, {0, 0, 0}, {0, 2, 0}, 1},
proj_t{lt_t::Segment, {1, 1, 0}, {0, 0, 0}, {0, 1, 0}, 1},
proj_t{lt_t::Segment, {1, 1, 0}, {0, -4, 0}, {0, 0, 0}, 4},
proj_t{lt_t::Segment, {1, 1, 0}, {0, 4, 0}, {0, 8, 0}, 0}));
// AxisAlignedBoundingBox Tests
// ============================================================================
// These are cases which should work for both the exact method and the slab
// method
auto basic_cases = Values(
// Basic directional tests
ab_t{lt_t::Line, {-6, 0, 0}, {-1, 0, 0}, -7.},
ab_t{lt_t::Line, {4, 0, 0}, {1, 0, 0}, -5.},
ab_t{lt_t::Line, {7, 0, 0}, {-1, 0, 0}, 6.},
ab_t{lt_t::Line, {0, 4, 0}, {0, -1, 0}, 3.},
ab_t{lt_t::Line, {0, -10, 0}, {0, -1, 0}, -11.},
ab_t{lt_t::Line, {0, -6, 0}, {0, 1, 0}, 5.},
ab_t{lt_t::Line, {0, 0, -9}, {0, 0, -1}, -10.},
ab_t{lt_t::Line, {0, 0, -5}, {0, 0, 1}, 4.},
ab_t{lt_t::Line, {0, 0, 8}, {0, 0, -1}, 7.},
ab_t{lt_t::Ray, {7, 0, 0}, {-1, 0, 0}, 6.},
ab_t{lt_t::Ray, {0, 4, 0}, {0, -1, 0}, 3.},
ab_t{lt_t::Ray, {0, -6, 0}, {0, 1, 0}, 5.},
ab_t{lt_t::Ray, {0, 0, -5}, {0, 0, 1}, 4.},
ab_t{lt_t::Ray, {0, 0, 8}, {0, 0, -1}, 7.},
ab_t{lt_t::Segment, {7, 0, 0}, {0, 0, 0}, 6.},
ab_t{lt_t::Segment, {0, 4, 0}, {0, 0, 0}, 3.},
ab_t{lt_t::Segment, {0, -6, 0}, {0, 6, 0}, 5.},
ab_t{lt_t::Segment, {0, 0, -5}, {0, 0, 1}, 4.},
ab_t{lt_t::Segment, {0, 0, 8}, {0, 0, -1}, 7.},
// Interior tests
ab_t{lt_t::Line, {0, 0, 0.5}, {0, 0, 1}, -1.5},
ab_t{lt_t::Line, {0, 0, 0}, {-1, 0, 0}, -1.},
ab_t{lt_t::Ray, {0, 0, 0.5}, {0, 0, 1}, 0.},
ab_t{lt_t::Ray, {0, 0, 0}, {-1, 0, 0}, 0.},
ab_t{lt_t::Segment, {0, 0, 0.5}, {0, 0, 3}, 0.},
ab_t{lt_t::Segment, {0, 0, 0}, {-3, 0, 0}, 0.},
// face tests
ab_t{lt_t::Line, {1, 0, 0}, {-1, 0, 0}, 0.},
ab_t{lt_t::Line, {1, 0, 0}, {1, 0, 0}, -2.},
ab_t{lt_t::Ray, {1, 0, 0}, {-1, 0, 0}, 0.},
ab_t{lt_t::Segment, {1, 0, 0}, {2, 0, 0}, 0.},
// Corner tests (direction isn't normalized here so that the return
// value will be 1.}
ab_t{lt_t::Line, {2, 2, 0}, {-1, -1, 1}, 1.},
ab_t{lt_t::Line, {0, 0, 2}, {1, 1, -1}, 1.},
ab_t{lt_t::Ray, {2, 2, 0}, {-1, -1, 1}, 1.},
ab_t{lt_t::Ray, {0, 0, 2}, {1, 1, -1}, 1.},
// Segment non-normalization doesn't work, so we'll start the segment
// at the corner point
ab_t{lt_t::Segment, {1, 1, 1}, {2, 2, 0}, 0.},
ab_t{lt_t::Segment, {-1, 1, 1}, {-2, 2, 0}, 0.},
// Non-intersecting tests
ab_t{lt_t::Segment, {3, 0, 0}, {4, 0, 0}, {}},
ab_t{lt_t::Segment, {4, 0, 0}, {3, 0, 0}, {}},
ab_t{lt_t::Segment, {0, 3, -1}, {0, 3, 1}, {}},
ab_t{lt_t::Line, {-6, 0, 0}, {0, 1, 0}, {}},
ab_t{lt_t::Line, {0, 3, 0}, {0, 0, 1}, {}},
ab_t{lt_t::Line, {0, 0, 1.5}, {1, 0, 0}, {}},
ab_t{lt_t::Ray, {-6, 0, 0}, {-1, 0, 0}, {}},
ab_t{lt_t::Ray, {4, 0, 0}, {1, 0, 0}, {}},
ab_t{lt_t::Ray, {0, -10, 0}, {0, -1, 0}, {}},
ab_t{lt_t::Ray, {0, 0, -9}, {0, 0, -1}, {}});
class LineAABBParamTests : public TestWithParam<ab_t> {
protected:
AxisAlignedBoundingBox box{{-1, -1, -1}, {1, 1, 1}};
};
TEST_P(LineAABBParamTests, CheckExact) {
auto line_type = std::get<0>(GetParam());
const auto& l0 = std::get<1>(GetParam());
const auto& l1 = std::get<2>(GetParam());
const auto& expected = std::get<3>(GetParam());
auto line = LineFactory(line_type, l0, l1);
auto result = line->ExactAABB(box);
if (expected.has_value()) {
EXPECT_TRUE(result.has_value());
if (result.has_value()) {
EXPECT_EQ(expected.value(), result.value());
}
} else {
EXPECT_FALSE(result.has_value());
}
}
TEST_P(LineAABBParamTests, CheckSlab) {
auto line_type = std::get<0>(GetParam());
const auto& l0 = std::get<1>(GetParam());
const auto& l1 = std::get<2>(GetParam());
const auto& expected = std::get<3>(GetParam());
auto line = LineFactory(line_type, l0, l1);
auto result = line->SlabAABB(box);
if (expected.has_value()) {
EXPECT_TRUE(result.has_value());
if (result.has_value()) {
EXPECT_EQ(expected.value(), result.value());
}
} else {
EXPECT_FALSE(result.has_value());
}
}
INSTANTIATE_TEST_SUITE_P(Checks, LineAABBParamTests, basic_cases);
class DegenerateLineAABBTests : public LineAABBParamTests {};
TEST_P(DegenerateLineAABBTests, CheckExact) {
auto line_type = std::get<0>(GetParam());
const auto& l0 = std::get<1>(GetParam());
const auto& l1 = std::get<2>(GetParam());
const auto& expected = std::get<3>(GetParam());
auto line = LineFactory(line_type, l0, l1);
auto result = line->ExactAABB(box);
EXPECT_TRUE(result.has_value());
EXPECT_EQ(expected.value(), result.value());
}
INSTANTIATE_TEST_SUITE_P(
Checks,
DegenerateLineAABBTests,
Values(ab_t{lt_t::Line, {1, 2, 0}, {0, -1, 0}, 1.},
ab_t{lt_t::Line, {-2, 0, 1}, {1, 0, 0}, 1.},
ab_t{lt_t::Ray, {1, 2, 0}, {0, -1, 0}, 1.},
ab_t{lt_t::Ray, {-2, 0, 1}, {1, 0, 0}, 1.},
ab_t{lt_t::Segment, {1, 2, 0}, {1, 0, 0}, 1.},
ab_t{lt_t::Segment, {-2, 0, 1}, {0, 0, 1}, 1.}));
// Line/Ray/Segment Closest Point Tests
// ============================================================================
class ClosestPointTests : public TestWithParam<cp_t> {};
TEST_P(ClosestPointTests, CheckClosestPoints) {
auto l0_type = std::get<0>(GetParam());
auto l0_origin = std::get<1>(GetParam());
auto l0_dir = std::get<2>(GetParam());
auto l1_type = std::get<3>(GetParam());
auto l1_origin = std::get<4>(GetParam());
auto l1_dir = std::get<5>(GetParam());
double e0 = std::get<6>(GetParam());
double e1 = std::get<7>(GetParam());
auto l0 = LineFactory(l0_type, l0_origin, l0_dir);
auto l1 = LineFactory(l1_type, l1_origin, l1_dir);
auto result = l0->ClosestParameters(*l1);
EXPECT_DOUBLE_EQ(std::get<0>(result), e0);
EXPECT_DOUBLE_EQ(std::get<1>(result), e1);
}
INSTANTIATE_TEST_SUITE_P(LineTests,
ClosestPointTests,
Values(
// Line to line
cp_t(lt_t::Line,
{0, -1, 0},
{0, 1, 0},
lt_t::Line,
{-1, 0, 0},
{1, 0, 0},
1,
1),
cp_t(lt_t::Line,
{-1, 0, 0},
{1, 0, 0},
lt_t::Line,
{0, -1, 0},
{0, 1, 0},
1,
1),
cp_t(lt_t::Line,
{0, 1, 0},
{0, 1, 0},
lt_t::Line,
{1, 0, 0},
{1, 0, 0},
-1,
-1),
cp_t(lt_t::Line,
{1, 0, 0},
{1, 0, 0},
lt_t::Line,
{0, 1, 0},
{0, 1, 0},
-1,
-1),
// Line to line parallel
cp_t(lt_t::Line,
{0, 0, 0},
{1, 0, 0},
lt_t::Line,
{1, 0, 1},
{1, 0, 0},
0,
-1),
cp_t(lt_t::Line,
{1, 0, 1},
{1, 0, 0},
lt_t::Line,
{0, 0, 0},
{1, 0, 0},
0,
1),
// Line to ray
cp_t(lt_t::Line,
{0, -1, 0},
{0, 1, 0},
lt_t::Ray,
{-1, 0, 0},
{1, 0, 0},
1,
1),
cp_t(lt_t::Line,
{-1, 0, 0},
{1, 0, 0},
lt_t::Ray,
{0, -1, 0},
{0, 1, 0},
1,
1),
cp_t(lt_t::Line,
{0, 1, 0},
{0, 1, 0},
lt_t::Ray,
{1, 0, 0},
{1, 0, 0},
-1,
0),
cp_t(lt_t::Line,
{1, 0, 0},
{1, 0, 0},
lt_t::Ray,
{0, 1, 0},
{0, 1, 0},
-1,
0),
// Line to ray parallel
cp_t(lt_t::Ray,
{0, 0, 0},
{1, 0, 0},
lt_t::Line,
{1, 0, 1},
{1, 0, 0},
0,
-1),
cp_t(lt_t::Line,
{0, 0, 0},
{1, 0, 0},
lt_t::Ray,
{1, 0, 1},
{1, 0, 0},
1,
0),
cp_t(lt_t::Line,
{1, 0, 1},
{1, 0, 0},
lt_t::Ray,
{0, 0, 0},
{1, 0, 0},
0,
1),
// Line to segment
cp_t(lt_t::Line,
{0, -1, 0},
{0, 1, 0},
lt_t::Segment,
{-1, 0, 0},
{1, 0, 0},
1,
1),
cp_t(lt_t::Line,
{-1, 0, 0},
{1, 0, 0},
lt_t::Segment,
{0, -1, 0},
{0, 1, 0},
1,
1),
cp_t(lt_t::Segment,
{0, 1, 0},
{0, 2, 0},
lt_t::Line,
{1, 0, 0},
{1, 0, 0},
0,
-1),
cp_t(lt_t::Segment,
{0, 2, 0},
{0, 1, 0},
lt_t::Line,
{1, 0, 0},
{1, 0, 0},
1,
-1),
// Line to segment parallel
cp_t(lt_t::Line,
{0, 0, 0},
{1, 0, 0},
lt_t::Segment,
{1, 0, 1},
{2, 0, 1},
1,
0),
cp_t(lt_t::Line,
{0, 0, 0},
{1, 0, 0},
lt_t::Segment,
{2, 0, 1},
{1, 0, 1},
1,
1),
cp_t(lt_t::Line,
{1, 0, 1},
{1, 0, 0},
lt_t::Segment,
{0, 0, 0},
{0.5, 0, 0},
-0.5,
0.5)));
const double root2 = 1.41421356237309504880168;
INSTANTIATE_TEST_SUITE_P(
RayTests,
ClosestPointTests,
Values(
// Ray to ray
cp_t(lt_t::Ray,
{0, -1, 0},
{0, 1, 0},
lt_t::Ray,
{-1, 0, 0},
{1, 0, 0},
1,
1),
cp_t(lt_t::Ray,
{-1, 0, 0},
{1, 0, 0},
lt_t::Ray,
{0, -1, 0},
{0, 1, 0},
1,
1),
cp_t(lt_t::Ray,
{0, 1, 0},
{0, 1, 0},
lt_t::Ray,
{1, 0, 0},
{1, 0, 0},
0,
0),
cp_t(lt_t::Ray,
{1, 0, 0},
{1, 0, 0},
lt_t::Ray,
{0, 1, 0},
{0, 1, 0},
0,
0),
// Ray to ray out of bounds behind origin, these cases test the
// clamp/project/clamp/project procedure
cp_t(lt_t::Ray,
{0, 1, 0},
{1, 0, 0},
lt_t::Ray,
{2, 2, 0},
{1, 1, 0},
2,
0),
cp_t(lt_t::Ray,
{2, 2, 0},
{1, 1, 0},
lt_t::Ray,
{0, 1, 0},
{1, 0, 0},
0,
2),
cp_t(lt_t::Ray,
{1.5, 1, 0},
{1, 0, 0},
lt_t::Ray,
{2, 2, 0},
{1, 1, 0},
.5,
0),
cp_t(lt_t::Ray,
{2, 2, 0},
{1, 1, 0},
lt_t::Ray,
{1.5, 1, 0},
{1, 0, 0},
0,
.5),
// Ray to ray parallel
cp_t(lt_t::Ray,
{0, 0, 0},
{1, 0, 0},
lt_t::Ray,
{1, 0, 1},
{1, 0, 0},
1,
0),
cp_t(lt_t::Ray,
{1, 0, 1},
{1, 0, 0},
lt_t::Ray,
{0, 0, 0},
{1, 0, 0},
0,
1),
// Ray to segment
cp_t(lt_t::Ray,
{0, -1, 0},
{0, 1, 0},
lt_t::Segment,
{-1, 0, 0},
{1, 0, 0},
1,
1),
cp_t(lt_t::Ray,
{-1, 0, 0},
{1, 0, 0},
lt_t::Segment,
{0, -1, 0},
{0, 1, 0},
1,
1),
cp_t(lt_t::Ray,
{0, 1, 0},
{0, 1, 0},
lt_t::Segment,
{1, 0, 0},
{2, 0, 0},
0,
0),
cp_t(lt_t::Ray,
{1, 0, 0},
{1, 0, 0},
lt_t::Segment,
{0, 1, 0},
{0, 2, 0},
0,
0),
// Ray to ray out of bounds behind origin, these cases test the
// clamp/project/clamp/project procedure
cp_t(lt_t::Ray,
{0, 1, 0},
{1, 0, 0},
lt_t::Segment,
{2, 2, 0},
{3, 3, 0},
2,
0),
cp_t(lt_t::Ray,
{0, 1, 0},
{1, 0, 0},
lt_t::Segment,
{3, 3, 0},
{2, 2, 0},
2,
root2),
cp_t(lt_t::Ray,
{2, 2, 0},
{1, 1, 0},
lt_t::Segment,
{0, 1, 0},
{0.5, 1, 0},
0,
0.5),
cp_t(lt_t::Ray,
{2, 2, 0},
{1, 1, 0},
lt_t::Segment,
{0.5, 1, 0},
{0, 1, 0},
0,
0)));
INSTANTIATE_TEST_SUITE_P(
SegmentTests,
ClosestPointTests,
Values(
// Regular segment to segment intersections
cp_t(lt_t::Segment,
{0, -1, 0},
{0, 1, 0},
lt_t::Segment,
{-1, 0, 0},
{1, 0, 0},
1,
1),
cp_t(lt_t::Segment,
{-1, 0, 0},
{1, 0, 0},
lt_t::Segment,
{0, -1, 0},
{0, 1, 0},
1,
1),
// Tests corresponding with special case b from "Real-Time
// Collision Detection" Figure 5.9b, p148
cp_t(lt_t::Segment,
{0, 1, 0},
{3, 1, 0},
lt_t::Segment,
{2, 2, 0},
{3, 3, 0},
2,
0),
cp_t(lt_t::Segment,
{0, 1, 0},
{3, 1, 0},
lt_t::Segment,
{3, 3, 0},
{2, 2, 0},
2,
root2),
cp_t(lt_t::Segment,
{2, 2, 0},
{3, 3, 0},
lt_t::Segment,
{0, 1, 0},
{3, 1, 0},
0,
2),
cp_t(lt_t::Segment,
{3, 3, 0},
{2, 2, 0},
lt_t::Segment,
{0, 1, 0},
{3, 1, 0},
root2,
2),
// Tests corresponding with special case b from "Real-Time
// Collision Detection" Figure 5.9c, p148
cp_t(lt_t::Segment,
{1.5, 1, 0},
{3, 1, 0},
lt_t::Segment,
{2, 2, 0},
{3, 3, 0},
0.5,
0),
cp_t(lt_t::Segment,
{1.5, 1, 0},
{3, 1, 0},
lt_t::Segment,
{3, 3, 0},
{2, 2, 0},
0.5,
root2),
cp_t(lt_t::Segment,
{2, 2, 0},
{3, 3, 0},
lt_t::Segment,
{1.5, 1, 0},
{3, 1, 0},
0,
0.5),
cp_t(lt_t::Segment,
{3, 3, 0},
{2, 2, 0},
lt_t::Segment,
{1.5, 1, 0},
{3, 1, 0},
root2,
0.5)));
} // namespace tests
} // namespace open3d
|