-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for convertibility of interpolators
This commit adds a test for the convertability of interpolation types at binary IO time, which is a problem faced by @beomki-yeo.
- Loading branch information
1 parent
12c8a37
commit 9786d9d
Showing
2 changed files
with
187 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,183 @@ | ||
/* | ||
* This file is part of covfie, a part of the ACTS project | ||
* | ||
* Copyright (c) 2024 CERN | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public License, | ||
* v. 2.0. If a copy of the MPL was not distributed with this file, You can | ||
* obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
#include <fstream> | ||
|
||
#include <boost/filesystem.hpp> | ||
#include <gtest/gtest.h> | ||
#include <tmp_file.hpp> | ||
|
||
#include <covfie/core/backend/primitive/array.hpp> | ||
#include <covfie/core/backend/transformer/affine.hpp> | ||
#include <covfie/core/backend/transformer/linear.hpp> | ||
#include <covfie/core/backend/transformer/nearest_neighbour.hpp> | ||
#include <covfie/core/backend/transformer/strided.hpp> | ||
#include <covfie/core/field.hpp> | ||
|
||
using basic_backend_t = covfie::backend::strided< | ||
covfie::vector::size3, | ||
covfie::backend::array<covfie::vector::float3>>; | ||
|
||
using field_nn_backend_t = covfie::backend::affine< | ||
covfie::backend::nearest_neighbour<basic_backend_t>>; | ||
|
||
using field_li_backend_t = | ||
covfie::backend::affine<covfie::backend::linear<basic_backend_t>>; | ||
|
||
TEST(TestAtlasLikeIO, WriteReadAtlasLike) | ||
{ | ||
covfie::field<basic_backend_t> bf( | ||
covfie::make_parameter_pack_for<covfie::field<basic_backend_t>>( | ||
{2, 2, 2}, {8} | ||
) | ||
); | ||
covfie::field<basic_backend_t>::view_t bv(bf); | ||
|
||
for (int x = 0; x < 2; x++) { | ||
for (int y = 0; y < 2; y++) { | ||
for (int z = 0; z < 2; z++) { | ||
bv.at(x, y, z) = { | ||
static_cast<float>(x), | ||
static_cast<float>(y), | ||
static_cast<float>(z)}; | ||
} | ||
} | ||
} | ||
|
||
for (int x = 0; x < 2; x++) { | ||
for (int y = 0; y < 2; y++) { | ||
for (int z = 0; z < 2; z++) { | ||
covfie::field<field_nn_backend_t>::output_t & p = | ||
bv.at(x, y, z); | ||
EXPECT_EQ(p[0], static_cast<float>(x)); | ||
EXPECT_EQ(p[1], static_cast<float>(y)); | ||
EXPECT_EQ(p[2], static_cast<float>(z)); | ||
} | ||
} | ||
} | ||
|
||
covfie::algebra::affine<3> translation = | ||
covfie::algebra::affine<3>::translation(0.0f, 0.0f, 0.0f); | ||
|
||
covfie::field<field_nn_backend_t> nnf(covfie::make_parameter_pack( | ||
field_nn_backend_t::configuration_t(translation), | ||
field_nn_backend_t::backend_t::configuration_t{}, | ||
std::move(bf.backend()) | ||
)); | ||
|
||
boost::filesystem::path ofile = get_tmp_file(); | ||
|
||
std::ofstream ofs(ofile.native(), std::ofstream::binary); | ||
|
||
if (!ofs.good()) { | ||
throw std::runtime_error("Invalid file was somehow opened!"); | ||
} | ||
|
||
nnf.dump(ofs); | ||
ofs.close(); | ||
|
||
std::ifstream ifs(ofile.native(), std::ifstream::binary); | ||
|
||
if (!ifs.good()) { | ||
throw std::runtime_error("Invalid file was somehow opened!"); | ||
} | ||
|
||
covfie::field<field_nn_backend_t> nnnf(ifs); | ||
ifs.close(); | ||
|
||
covfie::field<field_nn_backend_t>::view_t nnnv(nnnf); | ||
|
||
for (int x = 0; x < 2; x++) { | ||
for (int y = 0; y < 2; y++) { | ||
for (int z = 0; z < 2; z++) { | ||
covfie::field<field_nn_backend_t>::output_t & p = | ||
nnnv.at(x, y, z); | ||
EXPECT_EQ(p[0], static_cast<float>(x)); | ||
EXPECT_EQ(p[1], static_cast<float>(y)); | ||
EXPECT_EQ(p[2], static_cast<float>(z)); | ||
} | ||
} | ||
} | ||
} | ||
|
||
TEST(TestAtlasLikeIO, WriteReadAtlasLikeChangeInterpolation) | ||
{ | ||
covfie::field<basic_backend_t> bf( | ||
covfie::make_parameter_pack_for<covfie::field<basic_backend_t>>( | ||
{2, 2, 2}, {8} | ||
) | ||
); | ||
covfie::field<basic_backend_t>::view_t bv(bf); | ||
|
||
for (int x = 0; x < 2; x++) { | ||
for (int y = 0; y < 2; y++) { | ||
for (int z = 0; z < 2; z++) { | ||
bv.at(x, y, z) = { | ||
static_cast<float>(x), | ||
static_cast<float>(y), | ||
static_cast<float>(z)}; | ||
} | ||
} | ||
} | ||
|
||
for (int x = 0; x < 2; x++) { | ||
for (int y = 0; y < 2; y++) { | ||
for (int z = 0; z < 2; z++) { | ||
covfie::field<field_nn_backend_t>::output_t p = bv.at(x, y, z); | ||
EXPECT_EQ(p[0], static_cast<float>(x)); | ||
EXPECT_EQ(p[1], static_cast<float>(y)); | ||
EXPECT_EQ(p[2], static_cast<float>(z)); | ||
} | ||
} | ||
} | ||
|
||
covfie::algebra::affine<3> translation = | ||
covfie::algebra::affine<3>::translation(0.0f, 0.0f, 0.0f); | ||
|
||
covfie::field<field_nn_backend_t> nnf(covfie::make_parameter_pack( | ||
field_nn_backend_t::configuration_t(translation), | ||
field_nn_backend_t::backend_t::configuration_t{}, | ||
std::move(bf.backend()) | ||
)); | ||
|
||
boost::filesystem::path ofile = get_tmp_file(); | ||
|
||
std::ofstream ofs(ofile.native(), std::ofstream::binary); | ||
|
||
if (!ofs.good()) { | ||
throw std::runtime_error("Invalid file was somehow opened!"); | ||
} | ||
|
||
nnf.dump(ofs); | ||
ofs.close(); | ||
|
||
std::ifstream ifs(ofile.native(), std::ifstream::binary); | ||
|
||
if (!ifs.good()) { | ||
throw std::runtime_error("Invalid file was somehow opened!"); | ||
} | ||
|
||
covfie::field<field_li_backend_t> nnnf(ifs); | ||
ifs.close(); | ||
|
||
covfie::field<field_li_backend_t>::view_t nnnv(nnnf); | ||
|
||
for (int x = 0; x < 2; x++) { | ||
for (int y = 0; y < 2; y++) { | ||
for (int z = 0; z < 2; z++) { | ||
covfie::field<field_li_backend_t>::output_t p = | ||
nnnv.at(x, y, z); | ||
EXPECT_EQ(p[0], static_cast<float>(x)); | ||
EXPECT_EQ(p[1], static_cast<float>(y)); | ||
EXPECT_EQ(p[2], static_cast<float>(z)); | ||
} | ||
} | ||
} | ||
} |