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

          Line data    Source code
       1             : /**
       2             :  * @file test_PhantomGenerator.cpp
       3             :  *
       4             :  * @brief Tests for the PhantomGenerator class
       5             :  *
       6             :  * @author Tobias Lasser - nothing to see here...
       7             :  */
       8             : 
       9             : #include "doctest/doctest.h"
      10             : #include "PhantomGenerator.h"
      11             : #include "VolumeDescriptor.h"
      12             : #include "testHelpers.h"
      13             : #include <array>
      14             : #include <iostream>
      15             : 
      16             : using namespace elsa;
      17             : using namespace doctest;
      18             : 
      19             : RealVector_t get2dModifiedSheppLogan45x45();
      20             : 
      21          13 : TEST_CASE_TEMPLATE("PhantomGenerator: Drawing a 2d Shepp-Logan phantom", data_t, float, double)
      22             : {
      23             : 
      24           8 :     GIVEN("A small 2D volume")
      25             :     {
      26           8 :         const IndexVector_t size({{16, 16}});
      27             : 
      28           8 :         WHEN("Creating the Sheep Logan phantom")
      29             :         {
      30           8 :             const auto dc = PhantomGenerator<data_t>::createModifiedSheppLogan(size);
      31             : 
      32           6 :             THEN("It's close to the reference (This is just to track difference)")
      33             :             {
      34             : // I'm sorry, but I'm not going to cast each and every single float here
      35             : #pragma GCC diagnostic push
      36             : #pragma GCC diagnostic ignored "-Wimplicit-float-conversion"
      37           4 :                 const Vector_t<data_t> expected({{
      38             :                     // clang-format off
      39             :                     0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
      40             :                     0,   0,   0,   0,   0,   0,   0, 0.2, 0.2, 0.2,   0,   0,   0,   0,   0,   0,
      41             :                     0,   0,   0,   0,   0, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2,   0,   0,   0,   0,
      42             :                     0,   0,   0,   0,   0, 0.2, 0.2, 0.3, 0.3, 0.3, 0.2, 0.2,   0,   0,   0,   0,
      43             :                     0,   0,   0,   0, 0.2,   0, 0.3, 0.3, 0.3, 0.3, 0.3, 0.2, 0.2,   0,   0,   0,
      44             :                     0,   0,   0,   0, 0.2,   0, 0.1, 0.3, 0.3, 0.3, 0.3, 0.2, 0.2,   0,   0,   0,
      45             :                     0,   0,   0, 0.2, 0.2,   0, 0.1, 0.3, 0.3, 0.3, 0.1, 0.2, 0.2, 0.2,   0,   0,
      46             :                     0,   0,   0, 0.2, 0.2,   0,   0, 0.3, 0.3, 0.1,   0,   0, 0.2, 0.2,   0,   0,
      47             :                     0,   0,   0, 0.2, 0.2,   0,   0,   0, 0.2,   0,   0,   0, 0.2, 0.2,   0,   0,
      48             :                     0,   0,   0, 0.2, 0.2, 0.2,   0,   0, 0.2,   0,   0,   0, 0.2, 0.2,   0,   0,
      49             :                     0,   0,   0, 0.2, 0.2, 0.2,   0,   0, 0.2, 0.2,   0, 0.2, 0.2, 0.2,   0,   0,
      50             :                     0,   0,   0,   0, 0.2, 0.2,   0,   0, 0.2, 0.2, 0.2, 0.2, 0.2,   0,   0,   0,
      51             :                     0,   0,   0,   0, 0.2, 0.2, 0.2,   0, 0.2, 0.2, 0.2, 0.2, 0.2,   0,   0,   0,
      52             :                     0,   0,   0,   0,   0, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2,   0,   0,   0,   0,
      53             :                     0,   0,   0,   0,   0, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2,   0,   0,   0,   0,
      54             :                     0,   0,   0,   0,   0,   0,   0, 0.2, 0.2, 0.2,   0,   0,   0,   0,   0,   0
      55             :                     // clang-format on
      56             :                 }});
      57             : #pragma GCC diagnostic pop
      58             : 
      59           6 :                 auto ref = DataContainer(VolumeDescriptor(size), expected);
      60             : 
      61           4 :                 INFO("Computed phantom: ", dc);
      62           4 :                 INFO("Refernce phantom: ", ref);
      63             : 
      64         514 :                 for (int i = 0; i < ref.getSize(); ++i) {
      65         512 :                     INFO("Error at position: ", i);
      66         512 :                     CHECK_UNARY(checkApproxEq(dc[i], ref[i]));
      67             :                 }
      68             :             }
      69           6 :             THEN("It's not close to the matlab reference :-(")
      70             :             {
      71             : // I'm sorry, but I'm not going to cast each and every single float here
      72             : #pragma GCC diagnostic push
      73             : #pragma GCC diagnostic ignored "-Wimplicit-float-conversion"
      74           4 :                 const Vector_t<data_t> matlab({{
      75             :                     // clang-format off
      76             :                     0,  0,  0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,  0,  0,  0,
      77             :                     0,  0,  0,   0,   0,   0,   1,   1,   1,   1,   0,   0,   0,  0,  0,  0,
      78             :                     0,  0,  0,   0,   0, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2,   0,   0,  0,  0,  0,
      79             :                     0,  0,  0,   0, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2,   0,  0,  0,  0,
      80             :                     0,  0,  0,   0, 0.2, 0.2, 0.2, 0.3, 0.3, 0.2, 0.2, 0.2,   0,  0,  0,  0,
      81             :                     0,  0,  0, 0.2, 0.2,   0, 0.3, 0.3, 0.3, 0.3, 0.2, 0.2, 0.2,  0,  0,  0,
      82             :                     0,  0,  0, 0.2, 0.2,   0,   0, 0.3, 0.3,   0,   0, 0.2, 0.2,  0,  0,  0,
      83             :                     0,  0,  0, 0.2, 0.2,   0,   0, 0.2, 0.2,   0,   0, 0.2, 0.2,  0,  0,  0,
      84             :                     0,  0,  0, 0.2, 0.2,   0,   0,   0, 0.2,   0, 0.2, 0.2, 0.2,  0,  0,  0,
      85             :                     0,  0,  0, 0.2, 0.2, 0.2,   0,   0, 0.2,   0, 0.2, 0.2, 0.2,  0,  0,  0,
      86             :                     0,  0,  0, 0.2, 0.2, 0.2,   0,   0, 0.2, 0.2, 0.2, 0.2, 0.2,  0,  0,  0,
      87             :                     0,  0,  0,   0, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2,   0,  0,  0,  0,
      88             :                     0,  0,  0,   0, 0.2, 0.2, 0.2, 0.3, 0.3, 0.2, 0.2, 0.2,   0,  0,  0,  0,
      89             :                     0,  0,  0,   0,   0, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2,   0,   0,  0,  0,  0,
      90             :                     0,  0,  0,   0,   0,   0,   1, 0.2, 0.2,   1,   0,   0,   0,  0,  0,  0,
      91             :                     0,  0,  0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,  0,  0,  0
      92             :                     // clang-format on
      93             :                 }});
      94             : #pragma GCC diagnostic pop
      95             : 
      96           4 :                 auto ref = DataContainer(VolumeDescriptor(size), matlab);
      97           2 :                 CHECK_UNARY_FALSE(isApprox(dc, ref));
      98             :             }
      99             :         }
     100             :     }
     101           4 : }
     102             : 
     103           1 : TEST_CASE("PhantomGenerator: Drawing a 3d Shepp-Logan phantom")
     104             : {
     105           2 :     GIVEN("a volume size")
     106             :     {
     107           2 :         IndexVector_t numCoeff(3);
     108           1 :         numCoeff << 64, 64, 64;
     109             : 
     110           2 :         WHEN("creating a 3d Shepp-Logan")
     111             :         {
     112           2 :             auto dc = PhantomGenerator<real_t>::createModifiedSheppLogan(numCoeff);
     113             : 
     114           2 :             THEN("it looks good")
     115             :             {
     116           1 :                 REQUIRE(true); // TODO: add a proper test here
     117             :             }
     118             :         }
     119             :     }
     120           1 : }

Generated by: LCOV version 1.15