Skip to content
Snippets Groups Projects
Commit 952df634 authored by Paul McCarthy's avatar Paul McCarthy :mountain_bicyclist:
Browse files

TEST: Expand splinterpolator tests to cover all extrapolation methods, and

order=2 interpolation
parent 7a32a55f
No related branches found
No related tags found
1 merge request!17ENH: Allow `Splinterpolator` instances to be created from an existing set of spline coefficients, and extend extrapolation options
Pipeline #25995 passed
This commit is part of merge request !17. Comments created here will be created in the context of that merge request.
Showing
with 104 additions and 14 deletions
...@@ -16,6 +16,7 @@ namespace fs = std::filesystem; ...@@ -16,6 +16,7 @@ namespace fs = std::filesystem;
namespace BTF = boost::unit_test::framework; namespace BTF = boost::unit_test::framework;
namespace SPL = SPLINTERPOLATOR; namespace SPL = SPLINTERPOLATOR;
class TestFixture { class TestFixture {
public: public:
...@@ -56,10 +57,11 @@ public: ...@@ -56,10 +57,11 @@ public:
TestFixture() { TestFixture() {
// the data is up-sampled by 3x // the data is up-sampled by 3x and
for (float z = -4; z < 9.01; z+=1/3.0) { // extrapolated x3 in all directions
for (float y = -4; y < 9.01; y+=1/3.0) { for (float z = -8; z < 14.01; z+=1/3.0) {
for (float x = -4; x < 9.01; x+=1/3.0) { for (float y = -8; y < 14.01; y+=1/3.0) {
for (float x = -8; x < 14.01; x+=1/3.0) {
if (std::abs(x) < 0.01) x = 0; if (std::abs(x) < 0.01) x = 0;
if (std::abs(y) < 0.01) y = 0; if (std::abs(y) < 0.01) y = 0;
if (std::abs(z) < 0.01) z = 0; if (std::abs(z) < 0.01) z = 0;
...@@ -68,9 +70,9 @@ public: ...@@ -68,9 +70,9 @@ public:
zpts.push_back(z); zpts.push_back(z);
}}} }}}
npts = xpts.size(); npts = xpts.size();
xsz = 40; xsz = 67;
ysz = 40; ysz = 67;
zsz = 40; zsz = 67;
// pre-allocate space to store test outputs // pre-allocate space to store test outputs
values = std::vector<float>(npts); values = std::vector<float>(npts);
...@@ -127,7 +129,6 @@ public: ...@@ -127,7 +129,6 @@ public:
} }
compare(values, load_nifti(test_name + "_values.nii.gz")); compare(values, load_nifti(test_name + "_values.nii.gz"));
// derivatives are only valid for interpolation of order > 1 // derivatives are only valid for interpolation of order > 1
if (spl.Order() > 1) { if (spl.Order() > 1) {
std::vector<float> gradvals; std::vector<float> gradvals;
...@@ -143,6 +144,7 @@ public: ...@@ -143,6 +144,7 @@ public:
BOOST_FIXTURE_TEST_SUITE(test_splinterpolator, TestFixture) BOOST_FIXTURE_TEST_SUITE(test_splinterpolator, TestFixture)
BOOST_AUTO_TEST_CASE(order_1_3d_extrap_zeros) { BOOST_AUTO_TEST_CASE(order_1_3d_extrap_zeros) {
run_test(SPL::Splinterpolator<float>(data.data(), dims, SPL::Zeros, 1)); run_test(SPL::Splinterpolator<float>(data.data(), dims, SPL::Zeros, 1));
} }
...@@ -155,6 +157,37 @@ BOOST_AUTO_TEST_CASE(order_1_3d_extrap_constant) { ...@@ -155,6 +157,37 @@ BOOST_AUTO_TEST_CASE(order_1_3d_extrap_constant) {
run_test(SPL::Splinterpolator<float>(data.data(), dims, SPL::Constant, 1)); run_test(SPL::Splinterpolator<float>(data.data(), dims, SPL::Constant, 1));
} }
BOOST_AUTO_TEST_CASE(order_1_3d_extrap_mirror) {
run_test(SPL::Splinterpolator<float>(data.data(), dims, SPL::Mirror, 1));
}
BOOST_AUTO_TEST_CASE(order_1_3d_extrap_periodic) {
run_test(SPL::Splinterpolator<float>(data.data(), dims, SPL::Periodic, 1));
}
BOOST_AUTO_TEST_CASE(order_2_3d_extrap_zeros) {
run_test(SPL::Splinterpolator<float>(data.data(), dims, SPL::Zeros, 2));
}
BOOST_AUTO_TEST_CASE(order_2_3d_extrap_soft_zeros) {
run_test(SPL::Splinterpolator<float>(data.data(), dims, SPL::SoftZeros, 2));
}
BOOST_AUTO_TEST_CASE(order_2_3d_extrap_constant) {
run_test(SPL::Splinterpolator<float>(data.data(), dims, SPL::Constant, 2));
}
BOOST_AUTO_TEST_CASE(order_2_3d_extrap_mirror) {
run_test(SPL::Splinterpolator<float>(data.data(), dims, SPL::Mirror, 2));
}
BOOST_AUTO_TEST_CASE(order_2_3d_extrap_periodic) {
run_test(SPL::Splinterpolator<float>(data.data(), dims, SPL::Periodic, 2));
}
BOOST_AUTO_TEST_CASE(order_3_3d_extrap_zeros) { BOOST_AUTO_TEST_CASE(order_3_3d_extrap_zeros) {
run_test(SPL::Splinterpolator<float>(data.data(), dims, SPL::Zeros, 3)); run_test(SPL::Splinterpolator<float>(data.data(), dims, SPL::Zeros, 3));
} }
...@@ -167,4 +200,13 @@ BOOST_AUTO_TEST_CASE(order_3_3d_extrap_constant) { ...@@ -167,4 +200,13 @@ BOOST_AUTO_TEST_CASE(order_3_3d_extrap_constant) {
run_test(SPL::Splinterpolator<float>(data.data(), dims, SPL::Constant, 3)); run_test(SPL::Splinterpolator<float>(data.data(), dims, SPL::Constant, 3));
} }
BOOST_AUTO_TEST_CASE(order_3_3d_extrap_mirror) {
run_test(SPL::Splinterpolator<float>(data.data(), dims, SPL::Mirror, 3));
}
BOOST_AUTO_TEST_CASE(order_3_3d_extrap_periodic) {
run_test(SPL::Splinterpolator<float>(data.data(), dims, SPL::Periodic, 3));
}
BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE_END()
File added
No preview for this file type
File added
File added
File added
File added
File added
No preview for this file type
File added
No preview for this file type
File added
File added
File added
File added
File added
File added
File added
File added
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment