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

          Line data    Source code
       1             : /**
       2             :  * @file test_EllipseGenerator.cpp
       3             :  *
       4             :  * @brief Tests for the EllipseGenerator class
       5             :  *
       6             :  * @author Tobias Lasser - initial code
       7             :  */
       8             : 
       9             : #include "doctest/doctest.h"
      10             : #include "EllipseGenerator.h"
      11             : #include "VolumeDescriptor.h"
      12             : #include "testHelpers.h"
      13             : 
      14             : using namespace elsa;
      15             : using namespace doctest;
      16             : 
      17             : static constexpr auto pi_d = pi<real_t>;
      18             : 
      19           1 : TEST_CASE("EllipseGenerator: Drawing a rotated filled ellipse in 2d")
      20             : {
      21           2 :     GIVEN("a volume and example ellipse parameters")
      22             :     {
      23           2 :         IndexVector_t numCoeff(2);
      24           1 :         numCoeff << 200, 200;
      25           2 :         VolumeDescriptor dd(numCoeff);
      26           2 :         DataContainer dc(dd);
      27             : 
      28           1 :         Eigen::Matrix<index_t, 2, 1> center{100, 100};
      29           1 :         Eigen::Matrix<index_t, 2, 1> sizes{40, 80};
      30             : 
      31           2 :         WHEN("comparing an ellipse created using an inefficient method")
      32             :         {
      33           2 :             THEN("the ellipse mostly matches the efficient one")
      34             :             {
      35             :                 // check a few rotation angles
      36           8 :                 for (real_t angleDeg : {0.0f, 18.0f, 30.0f, 45.0f, 60.0f, 72.0f, 90.0f}) {
      37           7 :                     real_t angleRad = angleDeg * pi_d / 180.0f;
      38             : 
      39           7 :                     dc = 0;
      40           7 :                     EllipseGenerator<real_t>::drawFilledEllipse2d(dc, 1.0, center, sizes, angleDeg);
      41             : 
      42           7 :                     index_t wrongPixelCounter = 0;
      43             : 
      44        1407 :                     for (index_t x = 0; x < numCoeff[0]; ++x) {
      45      281400 :                         for (index_t y = 0; y < numCoeff[1]; ++y) {
      46             :                             real_t aPart =
      47      280000 :                                 static_cast<real_t>(x - center[0]) * std::cos(angleRad)
      48      280000 :                                 + static_cast<real_t>(y - center[1]) * std::sin(angleRad);
      49      280000 :                             aPart *= aPart;
      50      280000 :                             aPart /= static_cast<real_t>(sizes[0] * sizes[0]);
      51             : 
      52             :                             real_t bPart =
      53      280000 :                                 -static_cast<real_t>(x - center[0]) * std::sin(angleRad)
      54      280000 :                                 + static_cast<real_t>(y - center[1]) * std::cos(angleRad);
      55      280000 :                             bPart *= bPart;
      56      280000 :                             bPart /= static_cast<real_t>(sizes[1] * sizes[1]);
      57             : 
      58      560000 :                             IndexVector_t coord(2);
      59      280000 :                             coord[0] = x;
      60      280000 :                             coord[1] = numCoeff[1] - 1 - y; // flip y axis
      61             : 
      62      280000 :                             if (aPart + bPart <= 1.0) { // point in ellipse
      63       70313 :                                 if (dc(coord) == 0)
      64         580 :                                     ++wrongPixelCounter; // CHECK(dc(coord) > 0);
      65             :                             } else {                     // point not in ellipse
      66      209687 :                                 if (dc(coord) != 0)
      67        1326 :                                     ++wrongPixelCounter; // CHECK(dc(coord) == 0);
      68             :                             }
      69             :                         }
      70             :                     }
      71           7 :                     REQUIRE_LT((as<real_t>(wrongPixelCounter) / as<real_t>(sizes.prod())),
      72             :                                Approx(0.11)); // 11% isn't great... :(
      73             :                 }
      74             :             }
      75             :         }
      76             :     }
      77           1 : }
      78             : 
      79           1 : TEST_CASE("EllipseGenerator: Drawing a rotated filled ellipsoid in 3d")
      80             : {
      81           2 :     GIVEN("a volume and example ellipsoid parameters")
      82             :     {
      83           2 :         IndexVector_t numCoeff(3);
      84           1 :         numCoeff << 64, 64, 64;
      85           2 :         VolumeDescriptor dd(numCoeff);
      86           2 :         DataContainer dc(dd);
      87             : 
      88           1 :         Eigen::Matrix<index_t, 3, 1> center{32, 32, 32};
      89           1 :         Eigen::Matrix<index_t, 3, 1> sizes{10, 25, 5};
      90             : 
      91           2 :         WHEN("creating an ellipse")
      92             :         {
      93           1 :             EllipseGenerator<real_t>::drawFilledEllipsoid3d(dc, 1.0, center, sizes, -18, 0, 10);
      94             : 
      95           2 :             THEN("somebody should check it...")
      96             :             {
      97           1 :                 REQUIRE(true); // TODO: add a reasonable test here
      98             :             }
      99             :         }
     100             :     }
     101           1 : }

Generated by: LCOV version 1.15