LCOV - code coverage report
Current view: top level - projectors/tests - test_Intersection.cpp (source / functions) Hit Total Coverage
Test: test_coverage.info.cleaned Lines: 80 80 100.0 %
Date: 2022-02-28 03:37:41 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /**
       2             :  * @file test_Intersection.cpp
       3             :  *
       4             :  * @brief Test for Intersection class
       5             :  *
       6             :  * @author David Frank - initial code
       7             :  * @author Maximilian Hornung - modularization
       8             :  * @author Tobias Lasser - consistency changes
       9             :  */
      10             : 
      11             : #include "doctest/doctest.h"
      12             : 
      13             : #include "Intersection.h"
      14             : 
      15             : using namespace elsa;
      16             : using namespace doctest;
      17             : 
      18             : using Ray = Eigen::ParametrizedLine<real_t, Eigen::Dynamic>;
      19             : 
      20           1 : TEST_CASE("Intersection: Intersect corners of pixels")
      21             : {
      22           1 :     size_t dim = 2;
      23             : 
      24           2 :     IndexVector_t voxel(dim);
      25           1 :     voxel << 1, 0;
      26           2 :     BoundingBox aabb(voxel);
      27             : 
      28             :     // top left corner
      29           2 :     RealVector_t ro(dim);
      30           1 :     ro << -3, -3;
      31           2 :     RealVector_t rd(dim);
      32           1 :     rd << 1.0, 1.0;
      33           1 :     rd.normalize();
      34           1 :     Ray r(ro, rd);
      35             : 
      36           1 :     REQUIRE_UNARY(Intersection::withRay(aabb, r));
      37             : 
      38             :     // top right corner
      39           1 :     ro << 1, 2;
      40           1 :     rd << 1.0, -1.0;
      41           1 :     rd.normalize();
      42           1 :     r = Ray(ro, rd);
      43             : 
      44           1 :     REQUIRE_UNARY_FALSE(Intersection::withRay(aabb, r));
      45             : 
      46             :     // bottom left corner
      47           1 :     ro << 3, -2;
      48           1 :     rd << -1.0, 1.0;
      49           1 :     rd.normalize();
      50           1 :     r = Ray(ro, rd);
      51             : 
      52           1 :     REQUIRE_UNARY(Intersection::withRay(aabb, r));
      53             : 
      54             :     // bottom right corner
      55           1 :     ro << 3, 1;
      56           1 :     rd << -1.0, -1.0;
      57           1 :     rd.normalize();
      58           1 :     r = Ray(ro, rd);
      59             : 
      60           1 :     REQUIRE_UNARY_FALSE(Intersection::withRay(aabb, r));
      61           1 : }
      62             : 
      63           9 : TEST_CASE("Intersection: Intersect edges of voxels")
      64             : {
      65          18 :     GIVEN("A ray which intersects the edge of a voxel")
      66             :     {
      67           9 :         size_t dim = 2;
      68          18 :         RealVector_t ro(dim);
      69           9 :         ro << 132, 30;
      70          18 :         RealVector_t rd(dim);
      71           9 :         rd << -1.0, 0;
      72          18 :         Ray r(ro, rd);
      73             : 
      74          18 :         IndexVector_t voxel(dim);
      75             : 
      76             :         // horizontal check
      77           9 :         voxel << 30, 31;
      78          10 :         THEN("the ray intersects")
      79             :         {
      80           1 :             BoundingBox aabb(voxel);
      81           1 :             REQUIRE_UNARY(Intersection::withRay(aabb, r));
      82             :         }
      83             : 
      84           9 :         voxel << 40, 30;
      85          10 :         THEN("the ray intersects")
      86             :         {
      87           1 :             BoundingBox aabb(voxel);
      88           1 :             REQUIRE_UNARY(Intersection::withRay(aabb, r));
      89             :         }
      90             : 
      91           9 :         voxel << 40, 29;
      92          10 :         THEN("the ray does not intersect")
      93             :         {
      94           1 :             BoundingBox aabb(voxel);
      95           1 :             REQUIRE_UNARY_FALSE(Intersection::withRay(aabb, r));
      96             :         }
      97             : 
      98             :         // vertical check
      99           9 :         ro << 30, -35;
     100           9 :         rd << 0, 1.0;
     101           9 :         r = Ray(ro, rd);
     102             : 
     103           9 :         voxel << 31, 30;
     104          10 :         THEN("the ray intersects")
     105             :         {
     106           1 :             BoundingBox aabb(voxel);
     107           1 :             REQUIRE_UNARY(Intersection::withRay(aabb, r));
     108             :         }
     109             : 
     110           9 :         voxel << 30, 40;
     111          10 :         THEN("the ray intersects")
     112             :         {
     113           1 :             BoundingBox aabb(voxel);
     114           1 :             REQUIRE_UNARY(Intersection::withRay(aabb, r));
     115             :         }
     116             : 
     117           9 :         voxel << 29, 40;
     118          10 :         THEN("the ray does not intersect")
     119             :         {
     120           1 :             BoundingBox aabb(voxel);
     121           1 :             REQUIRE_UNARY_FALSE(Intersection::withRay(aabb, r));
     122             :         }
     123             : 
     124           9 :         rd << 0.0, 1.0;
     125           9 :         ro << 1.5, -10;
     126           9 :         r = Ray(ro, rd);
     127             : 
     128           9 :         voxel << 0, 1;
     129          10 :         THEN("the ray does not intersect")
     130             :         {
     131           1 :             BoundingBox aabb(voxel);
     132           1 :             REQUIRE_UNARY_FALSE(Intersection::withRay(aabb, r));
     133             :         }
     134             : 
     135           9 :         voxel << 1, 1;
     136          10 :         THEN("the ray does not intersect")
     137             :         {
     138           1 :             BoundingBox aabb(voxel);
     139           1 :             REQUIRE_UNARY_FALSE(Intersection::withRay(aabb, r));
     140             :         }
     141             : 
     142           9 :         voxel << 2, 1;
     143          10 :         THEN("the ray intersects")
     144             :         {
     145           1 :             BoundingBox aabb(voxel);
     146           1 :             REQUIRE_UNARY(Intersection::withRay(aabb, r));
     147             :         }
     148             :     }
     149           9 : }

Generated by: LCOV version 1.15