Commit 9e7a2262 authored by Edwin Carlinet's avatar Edwin Carlinet
Browse files

Update tos tests.

parent 9a690ad2
Pipeline #15756 failed with stages
in 11 minutes and 11 seconds
......@@ -236,7 +236,7 @@ namespace mln::morpho::experimental
component_tree<void>::compute_attribute_on_points(I node_map, Accu acc)
{
static_assert(mln::is_a<I, mln::experimental::Image>());
static_assert(mln::is_a<Accu, mln::Accumulator>());
static_assert(mln::is_a<Accu, mln::AccumulatorLike>());
using R = typename accu::result_of<Accu, image_point_t<I>>::type;
auto a = accu::make_accumulator(acc, image_point_t<I>());
......@@ -267,7 +267,7 @@ namespace mln::morpho::experimental
component_tree<void>::compute_attribute_on_values(I node_map, J input, Accu acc)
{
static_assert(mln::is_a<I, mln::experimental::Image>());
static_assert(mln::is_a<Accu, mln::Accumulator>());
static_assert(mln::is_a<Accu, mln::AccumulatorLike>());
using R = typename accu::result_of<Accu, image_value_t<J>>::type;
auto a = accu::make_accumulator(acc, image_value_t<J>());
......
......@@ -89,7 +89,7 @@ namespace mln::morpho::experimental::details
auto pset<I>::try_pop(int level) noexcept -> std::optional<Point>
{
if (m_delegate.empty(level))
return {};
return std::nullopt;
m_size--;
return m_delegate.pop_front(level);
}
......
......@@ -12,22 +12,22 @@
#include <fixtures/ImageCompare/image_compare.hpp>
#include <gtest/gtest.h>
#include "tos_tests_helper.hpp"
TEST(ToSImmersion, twodimensional)
{
const mln::experimental::image2d<uint8_t> f = {{0, 1, 2}, //
{3, 0, 1}};
{3, 0, 1}};
const mln::experimental::image2d<uint8_t> ref_inf = {{0, 0, 1, 1, 2}, //
{0, 0, 0, 0, 1}, //
{3, 0, 0, 0, 1}};
{0, 0, 0, 0, 1}, //
{3, 0, 0, 0, 1}};
const mln::experimental::image2d<uint8_t> ref_sup = {{0, 1, 1, 2, 2}, //
{3, 3, 1, 2, 2}, //
{3, 3, 0, 1, 1}};
{3, 3, 1, 2, 2}, //
{3, 3, 0, 1, 1}};
auto [inf, sup] = mln::morpho::experimental::details::immersion(f);
......@@ -39,17 +39,18 @@ TEST(ToSImmersion, twodimensional_generic)
{
using namespace mln::view::ops;
const mln::experimental::image2d<uint8_t> f = {{0, 1, 2}, //
{3, 0, 1}};
{3, 0, 1}};
auto fprime = f * uint8_t(1);
const mln::experimental::image2d<uint8_t> ref_inf = {{0, 0, 1, 1, 2}, //
{0, 0, 0, 0, 1}, //
{3, 0, 0, 0, 1}};
{0, 0, 0, 0, 1}, //
{3, 0, 0, 0, 1}};
const mln::experimental::image2d<uint8_t> ref_sup = {{0, 1, 1, 2, 2}, //
{3, 3, 1, 2, 2}, //
{3, 3, 0, 1, 1}};
{3, 3, 1, 2, 2}, //
{3, 3, 0, 1, 1}};
auto [inf, sup] = mln::morpho::experimental::details::immersion(fprime);
......@@ -247,5 +248,6 @@ TEST(ToSConstruction, saddle_point)
{a, a, a, a, a, a, a}, //
{a, a, a, a, a, a, a}, //
{a, a, a, a, a, a, a}};
mln::morpho::experimental::tos(f, {0,0});
auto [tree, node_map ] = mln::morpho::experimental::tos(f, {0,0});
compare_tree_to_ref(tree, node_map, ref_parent, ref_roots);
}
#include "tos_tests_helper.hpp"
#include <mln/core/image/image2d.hpp>
#include <mln/core/image/image3d.hpp>
#include <mln/morpho/component_tree/component_tree.hpp>
#include <mln/morpho/component_tree/reconstruction.hpp>
#include <mln/core/algorithm/transform.hpp>
#include <mln/core/image/experimental/ndimage.hpp>
#include <mln/morpho/experimental/component_tree.hpp>
template <class ParentImageType>
ParentImageType
tree_as_parent_image(const mln::morpho::component_tree<unsigned, mln_ch_value(ParentImageType, unsigned)>& tree,
ParentImageType& rootimage)
{
using tree_t = std::decay_t<decltype(tree)>;
#include <fixtures/ImageCompare/image_compare.hpp>
const auto& pmap = tree._get_data()->m_pmap;
namespace
{
// Store the minimal index for each component
using P = mln_point(ParentImageType);
constexpr P UNDEF = mln::value_traits<P>::inf();
mln::property_map<tree_t, P> roots(tree, UNDEF);
mln_foreach (auto px, pmap.pixels())
template <class I, class J>
void compare_tree_to_ref_T(const mln::morpho::experimental::component_tree<>& tree, //
const J& node_map, //
const I& parents_ref, //
const I& roots_ref)
{
auto node_id = px.val();
auto& r = roots[node_id];
if (r == UNDEF)
r = px.point();
using P = mln::image_point_t<J>;
const auto& par = tree.parent;
auto pmax = node_map.domain().br();
std::size_t n = par.size();
std::vector<P> repr(n, pmax);
mln_foreach_new(auto px, node_map.new_pixels())
{
int id = px.val();
P p = px.point();
repr[id] = std::min(repr[id], p);
}
// Build parent image
auto roots = mln::transform(node_map, [&repr](int x) { return repr[x]; });
auto parents = mln::transform(node_map, [&repr, &par](int x) { return repr[par[x]]; });
ASSERT_IMAGES_EQ_EXP(roots, roots_ref);
ASSERT_IMAGES_EQ_EXP(parents, parents_ref);
}
mln::resize(rootimage, pmap);
mln::morpho::reconstruction(tree, roots, rootimage);
}
auto parent = mln::clone(rootimage);
mln_foreach (auto node, tree.nodes_without_root())
parent(roots[node.id()]) = roots[node.get_parent_id()];
return parent;
void compare_tree_to_ref(const mln::morpho::experimental::component_tree<>& tree,
const mln::experimental::image2d<int>& node_map,
const mln::experimental::image2d<mln::experimental::point2d>& parents,
const mln::experimental::image2d<mln::experimental::point2d>& roots)
{
compare_tree_to_ref_T(tree, node_map, parents, roots);
}
using tree_2d_t = mln::morpho::component_tree<unsigned, mln::image2d<unsigned>>;
using par_2d_t = mln::image2d<mln::point2d>;
using tree_3d_t = mln::morpho::component_tree<unsigned, mln::image3d<unsigned>>;
using par_3d_t = mln::image3d<mln::point3d>;
void compare_tree_to_ref(const mln::morpho::experimental::component_tree<>& tree,
const mln::experimental::image2d<int>& node_map,
const mln::experimental::image3d<mln::experimental::point3d>& parents,
const mln::experimental::image3d<mln::experimental::point3d>& roots)
{
compare_tree_to_ref_T(tree, node_map, parents, roots);
}
// Explicit instanciation
template par_2d_t tree_as_parent_image(const tree_2d_t& tree, par_2d_t& roots);
template par_3d_t tree_as_parent_image(const tree_3d_t& tree, par_3d_t& roots);
#pragma once
#include <mln/core/image/image.hpp>
#include <mln/morpho/datastruct/component_tree.hpp>
#include <mln/core/experimental/point.hpp>
#include <mln/core/image/experimental/ndimage_fwd.hpp>
#include <mln/morpho/experimental/component_tree.hpp>
/// \brief Compute the parent image representation of the tree
/// The root a component is set to the mininum point of the component to ensure uniqueness
void compare_tree_to_ref(const mln::morpho::experimental::component_tree<>& tree,
const mln::experimental::image2d<int>& node_map,
const mln::experimental::image2d<mln::experimental::point2d>& parent,
const mln::experimental::image2d<mln::experimental::point2d>& roots);
void compare_tree_to_ref(const mln::morpho::experimental::component_tree<>& tree,
const mln::experimental::image2d<int>& node_map,
const mln::experimental::image3d<mln::experimental::point3d>& parent,
const mln::experimental::image3d<mln::experimental::point3d>& roots);
template <class ParentImage>
ParentImage tree_as_parent_image(const mln::morpho::component_tree<unsigned, mln_ch_value(ParentImage, unsigned)>& tree,
ParentImage& roots);
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