Commit 431aba86 authored by Ludovic Courtès's avatar Ludovic Courtès

core: vertical_segment: Fix 'get', 'data_view', and 'matrix_view'.

Partly fixes a regression introduced in f8843e56.
Reported by Laurent BELCOUR <laurent.belcour@gmail.com>
at <http://lists.gforge.inria.fr/pipermail/alta-devel/2017-January/000746.html>.
parent 2f643f58
/* ALTA --- Analysis of Bidirectional Reflectance Distribution Functions
Copyright (C) 2014 CNRS
Copyright (C) 2013, 2014, 2015, 2016 Inria
Copyright (C) 2013, 2014, 2015, 2016, 2017 Inria
This file is part of ALTA.
......@@ -38,6 +38,8 @@
typedef Eigen::VectorXd vec;
typedef Eigen::Ref<vec> vecref;
typedef Eigen::Ref<const vec> const_vecref;
typedef Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>
RowMatrixXd;
// Convenience functions.
static inline double norm(const vec& v)
......
......@@ -142,7 +142,7 @@ void vertical_segment::get(int i, vec& yl, vec& yu) const
vec vertical_segment::get(int i) const
{
return data_view().col(i);
return data_view().row(i);
}
void vertical_segment::set(int i, const vec& x)
......
/* ALTA --- Analysis of Bidirectional Reflectance Distribution Functions
Copyright (C) 2013, 2014, 2015, 2016 Inria
Copyright (C) 2013, 2014, 2015, 2016, 2017 Inria
This file is part of ALTA.
......@@ -164,20 +164,19 @@ class vertical_segment : public data
// Thus, it has (dimX + dimY + N * dimY) columns, where N is between 0
// and 2 depending on the confidence interval data available, and SIZE
// rows.
Eigen::Map<Eigen::MatrixXd> matrix_view() const
Eigen::Map<RowMatrixXd> matrix_view() const
{
return Eigen::Map<Eigen::MatrixXd>(_data.get(), size(),
column_number());
return Eigen::Map<RowMatrixXd>(_data.get(), size(), column_number());
}
private: // method
//! \brief Return a matrix view of DATA that excludes confidence
// interval data. It has (dimX + dimY) columns and SIZE rows.
Eigen::Map<Eigen::MatrixXd, 0, Eigen::OuterStride<> > data_view() const
Eigen::Map<RowMatrixXd, 0, Eigen::OuterStride<> > data_view() const
{
return Eigen::Map<Eigen::MatrixXd, 0, Eigen::OuterStride<> >
(_data.get(), _parameters.dimX() + _parameters.dimY(), size(),
return Eigen::Map<RowMatrixXd, 0, Eigen::OuterStride<> >
(_data.get(), _size, _parameters.dimX() + _parameters.dimY(),
Eigen::OuterStride<>(column_number()));
}
......
/* ALTA --- Analysis of Bidirectional Reflectance Distribution Functions
Copyright (C) 2015, 2016 Inria
Copyright (C) 2015, 2016, 2017 Inria
This file is part of ALTA.
......@@ -23,6 +23,7 @@
#include <string>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cstdlib>
......@@ -37,6 +38,49 @@
using namespace alta;
// Try loading a simple example from a text-format stream.
static void test_simple_load_from_text()
{
static const char example[] = "\
#DIM 1 3f\n\
#VS 0\n\
#PARAM_IN COS_TH\n\
#PARAM_OUT RGB_COLOR\n\
0 1 2 3\n\
4 5 6 7\n\
8 9 10 11\n";
std::istringstream input(example);
auto data = dynamic_pointer_cast<vertical_segment>(
plugins_manager::load_data("vertical_segment", input));
TEST_ASSERT(data != NULL);
TEST_ASSERT(data->size() == 3);
TEST_ASSERT(data->parametrization().input_parametrization()
== params::COS_TH);
TEST_ASSERT(data->parametrization().output_parametrization()
== params::RGB_COLOR);
// Currently we always get ASYMMETRICAL_CONFIDENCE_INTERVAL for backward
// compatibility reasons.
TEST_ASSERT(data->confidence_interval_kind()
== vertical_segment::ASYMMETRICAL_CONFIDENCE_INTERVAL);
TEST_ASSERT(data->get(0) == Eigen::Vector4d(0., 1., 2., 3.));
TEST_ASSERT(data->get(1) == Eigen::Vector4d(4., 5., 6., 7.));
TEST_ASSERT(data->get(2) == Eigen::Vector4d(8., 9., 10., 11.));
// The "matrix view" includes confidence interval data.
auto view = data->matrix_view();
TEST_ASSERT(view.cols() == 1 + 3 + 2 * 3);
TEST_ASSERT(view.rows() == 3);
TEST_ASSERT(view.col(0) == Eigen::Vector3d(0., 4., 8.));
TEST_ASSERT(view.col(1) == Eigen::Vector3d(1., 5., 9.));
TEST_ASSERT(view.col(2) == Eigen::Vector3d(2., 6., 10.));
TEST_ASSERT(view.col(3) == Eigen::Vector3d(3., 7., 11.));
}
// Files that are automatically deleted upon destruction.
class temporary_file
{
......@@ -116,6 +160,10 @@ int main(int argc, char** argv)
input_file = data_dir + "/" + data_file;
}
// Simple test first.
test_simple_load_from_text();
// Try a sequence of loads and saves.
try
{
std::ifstream input;
......
Markdown is supported
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