Commit 9f1bc656 authored by David Frank's avatar David Frank
Browse files

#20 Proper testing for 2D Shepp-Logan phantom

parent 8e809781
......@@ -8,27 +8,93 @@
#include "doctest/doctest.h"
#include "PhantomGenerator.h"
#include "VolumeDescriptor.h"
#include "testHelpers.h"
#include <array>
#include <iostream>
using namespace elsa;
using namespace doctest;
RealVector_t get2dModifiedSheppLogan45x45();
TEST_CASE("PhantomGenerator: Drawing a 2d Shepp-Logan phantom")
TEST_CASE_TEMPLATE("PhantomGenerator: Drawing a 2d Shepp-Logan phantom", data_t, float, double)
{
GIVEN("a volume size")
GIVEN("A small 2D volume")
{
IndexVector_t numCoeff(2);
numCoeff << 512, 512;
const IndexVector_t size({{16, 16}});
WHEN("creating a 2d Shepp-Logan")
WHEN("Creating the Sheep Logan phantom")
{
auto dc = PhantomGenerator<real_t>::createModifiedSheppLogan(numCoeff);
const auto dc = PhantomGenerator<data_t>::createModifiedSheppLogan(size);
THEN("it looks good")
THEN("It's close to the reference (This is just to track difference)")
{
REQUIRE(true); // TODO: add a proper test here
// I'm sorry, but I'm not going to cast each and every single float here
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wimplicit-float-conversion"
const Vector_t<data_t> expected({{
// clang-format off
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0.2, 0.2, 0.2, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0.2, 0.2, 0.3, 0.3, 0.3, 0.2, 0.2, 0, 0, 0, 0,
0, 0, 0, 0, 0.2, 0, 0.3, 0.3, 0.3, 0.3, 0.3, 0.2, 0.2, 0, 0, 0,
0, 0, 0, 0, 0.2, 0, 0.1, 0.3, 0.3, 0.3, 0.3, 0.2, 0.2, 0, 0, 0,
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,
0, 0, 0, 0.2, 0.2, 0, 0, 0.3, 0.3, 0.1, 0, 0, 0.2, 0.2, 0, 0,
0, 0, 0, 0.2, 0.2, 0, 0, 0, 0.2, 0, 0, 0, 0.2, 0.2, 0, 0,
0, 0, 0, 0.2, 0.2, 0.2, 0, 0, 0.2, 0, 0, 0, 0.2, 0.2, 0, 0,
0, 0, 0, 0.2, 0.2, 0.2, 0, 0, 0.2, 0.2, 0, 0.2, 0.2, 0.2, 0, 0,
0, 0, 0, 0, 0.2, 0.2, 0, 0, 0.2, 0.2, 0.2, 0.2, 0.2, 0, 0, 0,
0, 0, 0, 0, 0.2, 0.2, 0.2, 0, 0.2, 0.2, 0.2, 0.2, 0.2, 0, 0, 0,
0, 0, 0, 0, 0, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0.2, 0.2, 0.2, 0, 0, 0, 0, 0, 0
// clang-format on
}});
#pragma GCC diagnostic pop
auto ref = DataContainer(VolumeDescriptor(size), expected);
INFO("Computed phantom: ", dc);
INFO("Refernce phantom: ", ref);
for (int i = 0; i < ref.getSize(); ++i) {
INFO("Error at position: ", i);
CHECK_UNARY(checkApproxEq(dc[i], ref[i]));
}
}
THEN("It's not close to the matlab reference :-(")
{
// I'm sorry, but I'm not going to cast each and every single float here
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wimplicit-float-conversion"
const Vector_t<data_t> matlab({{
// clang-format off
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0, 0, 0, 0,
0, 0, 0, 0, 0.2, 0.2, 0.2, 0.3, 0.3, 0.2, 0.2, 0.2, 0, 0, 0, 0,
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,
0, 0, 0, 0.2, 0.2, 0, 0, 0.3, 0.3, 0, 0, 0.2, 0.2, 0, 0, 0,
0, 0, 0, 0.2, 0.2, 0, 0, 0.2, 0.2, 0, 0, 0.2, 0.2, 0, 0, 0,
0, 0, 0, 0.2, 0.2, 0, 0, 0, 0.2, 0, 0.2, 0.2, 0.2, 0, 0, 0,
0, 0, 0, 0.2, 0.2, 0.2, 0, 0, 0.2, 0, 0.2, 0.2, 0.2, 0, 0, 0,
0, 0, 0, 0.2, 0.2, 0.2, 0, 0, 0.2, 0.2, 0.2, 0.2, 0.2, 0, 0, 0,
0, 0, 0, 0, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0, 0, 0, 0,
0, 0, 0, 0, 0.2, 0.2, 0.2, 0.3, 0.3, 0.2, 0.2, 0.2, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 1, 0.2, 0.2, 1, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
// clang-format on
}});
#pragma GCC diagnostic pop
auto ref = DataContainer(VolumeDescriptor(size), matlab);
CHECK_UNARY_FALSE(isApprox(dc, ref));
}
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment