Commit 10de4ab0 authored by Nikola Dinev's avatar Nikola Dinev
Browse files

DataContainer constructor now accepts a DataVector instead of a RealVector

parent 2e35946b
Pipeline #152162 passed with stages
in 2 minutes and 36 seconds
......@@ -13,7 +13,7 @@ namespace elsa {
{}
template <typename data_t>
DataContainer<data_t>::DataContainer(const DataDescriptor& dataDescriptor, const RealVector_t& data,
DataContainer<data_t>::DataContainer(const DataDescriptor& dataDescriptor, const Eigen::Matrix<data_t, Eigen::Dynamic, 1>& data,
DataHandlerType handlerType)
: _dataDescriptor{dataDescriptor.clone()},
_dataHandler{createDataHandler(handlerType, _dataDescriptor->getNumberOfCoefficients())}
......
......@@ -50,13 +50,13 @@ namespace elsa
/**
* \brief Constructor for DataContainer, initializing it with a RealVector
* \brief Constructor for DataContainer, initializing it with a DataVector
*
* \param[in] dataDescriptor containing the associated metadata
* \param[in] data vector containing the initialization data
* \param[in] handlerType the data handler (default: CPU)
*/
DataContainer(const DataDescriptor& dataDescriptor, const RealVector_t& data,
DataContainer(const DataDescriptor& dataDescriptor, const Eigen::Matrix<data_t, Eigen::Dynamic, 1>& data,
DataHandlerType handlerType = DataHandlerType::CPU);
......@@ -108,6 +108,7 @@ namespace elsa
/// return an element by n-dimensional coordinate as read-only (not bounds-checked!)
const data_t& operator()(IndexVector_t coordinate) const;
/// return an element by its coordinates (not bounds-checked!)
template <typename idx0_t, typename... idx_t,
typename = std::enable_if_t<std::is_integral_v<idx0_t> && (... && std::is_integral_v<idx_t>)>>
data_t& operator()(idx0_t idx0, idx_t... indices) {
......@@ -116,6 +117,7 @@ namespace elsa
return operator()(coordinate);
}
/// return an element by its coordinates as read-only (not bounds-checked!)
template <typename idx0_t, typename... idx_t,
typename = std::enable_if_t<std::is_integral_v<idx0_t> && (... && std::is_integral_v<idx_t>)>>
const data_t& operator()(idx0_t idx0, idx_t... indices) const{
......
......@@ -90,7 +90,7 @@ SCENARIO("Testing the l2 norm (squared) functional") {
REQUIRE(func.evaluate(x) == Approx(0.5f * (dataVec - randomData).squaredNorm()));
DataContainer grad(dd, dataVec - randomData);
DataContainer grad(dd, (dataVec - randomData).eval() );
REQUIRE(func.getGradient(x) == grad);
auto hessian = func.getHessian(x);
......
......@@ -52,7 +52,7 @@ SCENARIO("Testing the Quadric functional") {
real_t trueValue = static_cast<real_t>(0.5) * x.dot(x) - x.dot(dc);
REQUIRE(func.evaluate(x) == Approx(trueValue));
DataContainer grad(dd, dataVec - randomData);
DataContainer grad(dd, (dataVec - randomData).eval() );
REQUIRE(func.getGradient(x) == grad);
REQUIRE(func.getHessian(x) == leaf(idOp));
}
......
......@@ -308,7 +308,7 @@ SCENARIO("Testing BinaryMethod") {
op.apply(dataDomain, dataRange);
auto res = RealVector_t::Ones(sizeRange.prod()) * 5;
RealVector_t res = RealVector_t::Constant(sizeRange.prod(),1,5);
DataContainer tmpRes(range, res);
REQUIRE(tmpRes == dataRange);
......@@ -344,7 +344,7 @@ SCENARIO("Testing BinaryMethod") {
op.apply(dataDomain, dataRange);
auto res = RealVector_t::Ones(sizeRange.prod()) * 5;
RealVector_t res = RealVector_t::Constant(sizeRange.prod(),1,5);
DataContainer tmpRes(range, res);
REQUIRE(tmpRes == dataRange);
......@@ -379,7 +379,7 @@ SCENARIO("Testing BinaryMethod") {
op.apply(dataDomain, dataRange);
auto res = RealVector_t::Ones(sizeRange.prod()) * 5;
RealVector_t res = RealVector_t::Constant(sizeRange.prod(),1,5);
DataContainer tmpRes(range, res);
REQUIRE(tmpRes == dataRange);
......@@ -415,7 +415,7 @@ SCENARIO("Testing BinaryMethod") {
op.apply(dataDomain, dataRange);
auto res = RealVector_t::Ones(sizeRange.prod()) * 5;
RealVector_t res = RealVector_t::Constant(sizeRange.prod(),1,5);
DataContainer tmpRes(range, res);
REQUIRE(tmpRes == dataRange);
......@@ -764,7 +764,9 @@ SCENARIO("Axis-aligned rays are present")
const index_t numCases = 4;
const real_t angles[numCases] = {0.0, pi/2, pi, 3*pi/2};
Eigen::Matrix<real_t,volSize*volSize,1> backProj[2];
RealVector_t backProj[2];
backProj[0].resize(volSize*volSize);
backProj[1].resize(volSize*volSize);
backProj[1] << 0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
1, 1, 1, 1, 1,
......@@ -899,7 +901,9 @@ SCENARIO("Axis-aligned rays are present")
real_t gamma[numCases] = {0.0, pi, pi/2, 3*pi/2,pi/2,3*pi/2};
std::string al[numCases] = {"z","-z","x","-x","y","-y"};
Eigen::Matrix<real_t,volSize*volSize*volSize,1> backProj[numCases];
RealVector_t backProj[numCases];
for (auto& backPr: backProj)
backPr.resize(volSize*volSize*volSize);
backProj[2] << 0, 0, 0,
0, 0, 0,
......@@ -1672,7 +1676,7 @@ SCENARIO("Projection under an angle") {
DataContainer sino(sinoDescriptor);
std::vector<Geometry> geom;
Eigen::Matrix<real_t,volSize*volSize*volSize,1> backProj;
RealVector_t backProj(volSize*volSize*volSize);
WHEN("A ray with an angle of 30 degrees goes through the center of the volume") {
......
......@@ -542,7 +542,9 @@ SCENARIO("Axis-aligned rays are present")
const index_t numCases = 4;
const real_t angles[numCases] = {0.0,pi/2, pi, 3*pi/2};
Eigen::Matrix<real_t,volSize*volSize,1> backProj[2];
RealVector_t backProj[2];
backProj[0].resize(volSize*volSize);
backProj[1].resize(volSize*volSize);
backProj[1] << 0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
1, 1, 1, 1, 1,
......@@ -694,8 +696,9 @@ SCENARIO("Axis-aligned rays are present")
real_t gamma[numCases] = {0.0,pi,pi/2, 3*pi/2,pi/2,3*pi/2};
std::string al[numCases] = {"z","-z","x","-x","y","-y"};
Eigen::Matrix<real_t,volSize*volSize*volSize,1> backProj[numCases];
RealVector_t backProj[numCases];
for (auto& backPr: backProj)
backPr.resize(volSize*volSize*volSize);
backProj[2] << 0, 0, 0,
0, 0, 0,
0, 0, 0,
......@@ -1400,7 +1403,7 @@ REQUIRE(sino == zero);
DataContainer sino(sinoDescriptor);
std::vector<Geometry> geom;
Eigen::Matrix<real_t,volSize*volSize*volSize,1> backProj;
RealVector_t backProj(volSize*volSize*volSize);
WHEN("A ray with an angle of 30 degrees goes through the center of the volume") {
......
......@@ -511,7 +511,9 @@ SCENARIO("Axis-aligned rays are present")
const index_t numCases = 4;
const real_t angles[numCases] = {0.0, pi/2, pi, 3*pi/2};
Eigen::Matrix<real_t,volSize*volSize,1> backProj[2];
RealVector_t backProj[2];
backProj[0].resize(volSize*volSize);
backProj[1].resize(volSize*volSize);
backProj[1] << 0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
1, 1, 1, 1, 1,
......@@ -637,7 +639,9 @@ SCENARIO("Axis-aligned rays are present")
real_t gamma[numCases] = {0.0, pi, pi/2, 3*pi/2,pi/2,3*pi/2};
std::string al[numCases] = {"z","-z","x","-x","y","-y"};
Eigen::Matrix<real_t,volSize*volSize*volSize,1> backProj[numCases];
RealVector_t backProj[numCases];
for (auto& backPr: backProj)
backPr.resize(volSize*volSize*volSize);
backProj[2] << 0, 0, 0,
0, 0, 0,
......@@ -1301,7 +1305,7 @@ SCENARIO("Projection under an angle") {
DataContainer sino(sinoDescriptor);
std::vector<Geometry> geom;
Eigen::Matrix<real_t,volSize*volSize*volSize,1> backProj;
RealVector_t backProj(volSize*volSize*volSize);
WHEN("A ray with an angle of 30 degrees goes through the center of the volume") {
......
......@@ -329,7 +329,7 @@ TEMPLATE_TEST_CASE("Scenario: Axis-aligned rays are present", "",
const index_t numCases = 4;
const real_t angles[numCases] = {0.0, pi/2, pi, 3*pi/2};
Eigen::Matrix<real_t,volSize*volSize,1> backProj[2];
Eigen::Matrix<data_t,volSize*volSize,1> backProj[2];
backProj[1] << 0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
1, 1, 1, 1, 1,
......@@ -451,7 +451,7 @@ TEMPLATE_TEST_CASE("Scenario: Axis-aligned rays are present", "",
real_t gamma[numCases] = {0.0, pi, pi/2, 3*pi/2,pi/2,3*pi/2};
std::string al[numCases] = {"z","-z","x","-x","y","-y"};
Eigen::Matrix<real_t,volSize*volSize*volSize,1> backProj[numCases];
Eigen::Matrix<data_t,volSize*volSize*volSize,1> backProj[numCases];
backProj[2] << 0, 0, 0,
0, 0, 0,
......@@ -671,7 +671,7 @@ TEMPLATE_TEST_CASE("Scenario: Axis-aligned rays are present", "",
REQUIRE(sino[i]==Approx(5.0));
AND_THEN("Backprojection yields the exact adjoint") {
RealVector_t cmp(volSize*volSize);
Eigen::Matrix<data_t,Eigen::Dynamic,1> cmp(volSize*volSize);
cmp << 0, 0, 10, 0, 0,
0, 0, 10, 0, 0,
......@@ -723,7 +723,7 @@ TEMPLATE_TEST_CASE("Scenario: Axis-aligned rays are present", "",
REQUIRE(sino[i]==Approx(3.0));
AND_THEN("Backprojection yields the exact adjoint") {
RealVector_t cmp(volSize*volSize*volSize);
Eigen::Matrix<data_t,Eigen::Dynamic,1> cmp(volSize*volSize*volSize);
cmp << 0, 0, 0,
0, 6, 0,
......@@ -800,7 +800,7 @@ TEMPLATE_TEST_CASE("Scenario: Projection under an angle", "",
sino[0] = 1;
RealVector_t expected(volSize*volSize);
Eigen::Matrix<data_t,Eigen::Dynamic,1> expected(volSize*volSize);
expected << 0, 0, 2-2/sqrt(3), 4/sqrt(3)-2,
0, 0, 2/sqrt(3), 0,
0, 2/sqrt(3), 0, 0,
......@@ -841,7 +841,7 @@ TEMPLATE_TEST_CASE("Scenario: Projection under an angle", "",
sino[0] = 1;
RealVector_t expected(volSize*volSize);
Eigen::Matrix<data_t,Eigen::Dynamic,1> expected(volSize*volSize);
expected << 0, 0, 0, 0,
0, 0, 0, 4-2*sqrt(3),
0, 0, 0, 2/sqrt(3),
......@@ -882,7 +882,7 @@ TEMPLATE_TEST_CASE("Scenario: Projection under an angle", "",
sino[0] = 1;
RealVector_t expected(volSize*volSize);
Eigen::Matrix<data_t,Eigen::Dynamic,1> expected(volSize*volSize);
expected << 4/sqrt(3)-2, 2-2/sqrt(3), 0, 0,
2/sqrt(3) , 0, 0, 0,
4-2*sqrt(3), 0, 0, 0,
......@@ -915,7 +915,7 @@ TEMPLATE_TEST_CASE("Scenario: Projection under an angle", "",
sino[0] = 1;
RealVector_t expected(volSize*volSize);
Eigen::Matrix<data_t,Eigen::Dynamic,1> expected(volSize*volSize);
expected << 1/sqrt(3), 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
......@@ -967,7 +967,7 @@ TEMPLATE_TEST_CASE("Scenario: Projection under an angle", "",
sino[0] = 1;
RealVector_t expected(volSize*volSize);
Eigen::Matrix<data_t,Eigen::Dynamic,1> expected(volSize*volSize);
expected << 4/sqrt(3)-2, 0, 0, 0,
2-2/sqrt(3), 2/sqrt(3),0, 0,
......@@ -1009,7 +1009,7 @@ TEMPLATE_TEST_CASE("Scenario: Projection under an angle", "",
sino[0] = 1;
RealVector_t expected(volSize*volSize);
Eigen::Matrix<data_t,Eigen::Dynamic,1> expected(volSize*volSize);
expected << 0, 0, 0, 0,
0, 0, 0, 0,
......@@ -1051,7 +1051,7 @@ TEMPLATE_TEST_CASE("Scenario: Projection under an angle", "",
sino[0] = 1;
RealVector_t expected(volSize*volSize);
Eigen::Matrix<data_t,Eigen::Dynamic,1> expected(volSize*volSize);
expected << 0,4-2*sqrt(3), 2/sqrt(3), 4/sqrt(3)-2,
0, 0, 0, 2-2/sqrt(3),
......@@ -1086,7 +1086,7 @@ TEMPLATE_TEST_CASE("Scenario: Projection under an angle", "",
sino[0] = 1;
RealVector_t expected(volSize*volSize);
Eigen::Matrix<data_t,Eigen::Dynamic,1> expected(volSize*volSize);
expected << 0, 0, 0, 1/sqrt(3),
0, 0, 0, 0,
0, 0, 0, 0,
......@@ -1115,7 +1115,7 @@ TEMPLATE_TEST_CASE("Scenario: Projection under an angle", "",
DataContainer<data_t> sino(sinoDescriptor);
std::vector<Geometry> geom;
Eigen::Matrix<real_t,volSize*volSize*volSize,1> backProj;
Eigen::Matrix<data_t,volSize*volSize*volSize,1> backProj;
WHEN("A ray with an angle of 30 degrees goes through the center of the volume") {
......
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