Commit 7be1c7e2 authored by Michaël Roynard's avatar Michaël Roynard
Browse files

Fix filter chaining issue.

parent d0500388
Pipeline #12881 failed with stages
in 5 minutes and 35 seconds
......@@ -30,33 +30,35 @@ namespace mln
using typename filter_view::image_adaptor::reference;
using typename filter_view::image_adaptor::value_type;
class domain_type
class domain_type : ::ranges::view_base
{
using fun_t = ::ranges::semiregular_t<F>;
using pred_t = ::ranges::composed<F, std::reference_wrapper<I>>; // f o I::operator()
using dom_t = decltype(std::declval<I*>()->domain());
using rng_t = mln::ranges::remove_if_view<::ranges::view::all_t<dom_t>, ::ranges::logical_negate<pred_t>>;
pred_t pred_;
mutable rng_t rng_; // domain can be a range, so non-const
pred_t m_pred;
dom_t m_dom;
mutable rng_t m_rng; // domain can be a range, so non-const
static_assert(::ranges::ForwardRange<rng_t>());
static_assert(::ranges::View<::ranges::view::all_t<dom_t>>());
public:
using value_type = ::ranges::range_value_t<rng_t>;
using reference = ::ranges::range_reference_t<rng_t>;
domain_type(I* ima, F f)
: pred_(std::move(f), std::ref(*ima))
, rng_(mln::ranges::view::filter(ima->domain(), pred_))
: m_pred(std::move(f), std::ref(*ima))
, m_dom(ima->domain())
, m_rng(mln::ranges::view::filter(::ranges::view::all(m_dom), m_pred))
{
}
auto begin() const { return ::ranges::begin(rng_); }
auto end() const { return ::ranges::end(rng_); }
auto begin() const { return ::ranges::begin(m_rng); }
auto end() const { return ::ranges::end(m_rng); }
bool has(point_type p) const { return pred_(p); }
bool empty() const { return this->begin() == this->end(); /*::ranges::empty(rng_);*/ }
bool has(point_type p) const { return m_pred(p); }
bool empty() const { return ::ranges::empty(m_rng); }
};
/// \}
......@@ -64,7 +66,7 @@ namespace mln
/// Traits & Image Properties
/// \{
using accessible = image_accessible_t<I>;
using indexable = std::false_type;
using indexable = image_indexable_t<I>;
using view = std::true_type;
// May be too restrictive (might be extended by image)
using extension_category = mln::extension::none_extension_tag;
......@@ -74,8 +76,7 @@ namespace mln
/// \}
// Checks
// FIXME: accessible prerequisite
// FIXME: can be indexable
PYLENE_CONCEPT_TS_ASSERT(mln::concepts::AccessibleImage<I>, "The image must be accessible.");
private:
struct pix_filter_fn
......@@ -119,6 +120,16 @@ namespace mln
}
/// Indexable-image related methods
/// \{
template <typename dummy = I>
reference operator[](image_index_t<dummy> i)
{
return this->base()[i];
}
/// \}
/// Accessible-image related methods
/// \{
template <typename Ret = reference>
......@@ -148,6 +159,28 @@ namespace mln
/// \}
/// IndexableAndAccessible-image related methods
/// \{
template <typename dummy = I>
std::enable_if_t<(indexable::value && accessible::value), image_index_t<dummy>> index_of_point(point_type p) const
{
return this->base().index_of_point(p);
}
template <typename dummy = I>
point_type point_at_index(std::enable_if_t<(indexable::value && accessible::value), image_index_t<dummy>> i) const
{
return this->base().point_at_index(i);
}
template <typename dummy = I>
std::enable_if_t<(indexable::value && accessible::value), image_index_t<dummy>> delta_index(point_type p) const
{
return this->base().delta_index(p);
}
/// \}
/// Raw-image related methods
/// \{
auto data() const = delete;
......
......@@ -13,14 +13,6 @@
#include <gtest/gtest.h>
#ifdef PYLENE_CONCEPT_TS_ENABLED
template <concepts::Image I>
void foo(I)
{
}
#endif // PYLENE_CONCEPT_TS_ENABLED
TEST(View, filter_readonly)
{
......@@ -33,13 +25,10 @@ TEST(View, filter_readonly)
auto x = mln::view::filter(ima, [](int v) { return v > 10; });
#ifdef PYLENE_CONCEPT_TS_ENABLED
foo(x);
static_assert(concepts::OutputImage<decltype(x)>);
static_assert(concepts::Image<decltype(x)>);
static_assert(concepts::ViewImage<decltype(x)>);
// FIXME
static_assert(not concepts::IndexableAndAccessibleImage<decltype(x)>);
static_assert(concepts::IndexableAndAccessibleImage<decltype(x)>);
static_assert(concepts::BidirectionalImage<decltype(x)>);
static_assert(not concepts::RawImage<decltype(x)>);
#endif // PYLENE_CONCEPT_TS_ENABLED
......@@ -71,15 +60,14 @@ TEST(View, filter_writable)
mln::experimental::iota(ima, 0);
auto x = mln::view::filter(ima, [](int v) { return v > 10; });
/*
#ifdef PYLENE_CONCEPT_TS_ENABLED
static_assert(concepts::OutputImage<decltype(x)>);
static_assert(concepts::ViewImage<decltype(x)>);
static_assert(concepts::IndexableAndAccessibleImage<decltype(x)>);
static_assert(not concepts::BidirectionalImage<decltype(x)>);
static_assert(not concepts::RawImage<decltype(x)>);
#endif // PYLENE_CONCEPT_TS_ENABLED
*/
#ifdef PYLENE_CONCEPT_TS_ENABLED
static_assert(concepts::OutputImage<decltype(x)>);
static_assert(concepts::ViewImage<decltype(x)>);
static_assert(concepts::IndexableAndAccessibleImage<decltype(x)>);
static_assert(concepts::BidirectionalImage<decltype(x)>);
static_assert(not concepts::RawImage<decltype(x)>);
#endif // PYLENE_CONCEPT_TS_ENABLED
mln::experimental::fill(x, 10);
ASSERT_TRUE(mln::experimental::all_of(ima <= 10));
......@@ -94,24 +82,19 @@ TEST(View, filter_twice)
mln::image2d<int> ima(dom);
mln::experimental::iota(ima, 0);
auto u = mln::view::filter(ima, [](int v) { return v > 10 && v < 15; });
/*
#ifdef PYLENE_CONCEPT_TS_ENABLED
static_assert(concepts::OutputImage<decltype(u)>);
static_assert(concepts::ViewImage<decltype(u)>);
static_assert(concepts::IndexableAndAccessibleImage<decltype(u)>);
static_assert(not concepts::BidirectionalImage<decltype(u)>);
static_assert(not concepts::RawImage<decltype(u)>);
#endif // PYLENE_CONCEPT_TS_ENABLED
*/
auto x = mln::view::filter(ima, [](int v) { return v > 10; });
auto u = mln::view::filter(x, [](int v) { return v < 15; });
// FIXME:
// auto x = view::filter(ima, [](int v) { return v > 10; });
// auto u = view::filter(x, [](int v) { return v < 15; });
#ifdef PYLENE_CONCEPT_TS_ENABLED
static_assert(concepts::OutputImage<decltype(u)>);
static_assert(concepts::ViewImage<decltype(u)>);
static_assert(concepts::IndexableAndAccessibleImage<decltype(u)>);
static_assert(concepts::BidirectionalImage<decltype(u)>);
static_assert(not concepts::RawImage<decltype(u)>);
#endif // PYLENE_CONCEPT_TS_ENABLED
// FIXME:
// ASSERT_TRUE(mln::experimental::all(land(u > 10, u < 15)));
ASSERT_TRUE(mln::experimental::all(land(u > 10, u < 15)));
mln_foreach_new (auto&& pix, ima.new_pixels())
{
......@@ -120,8 +103,7 @@ TEST(View, filter_twice)
else
ASSERT_EQ(pix.val(), u.at(pix.point()));
// FIXME:
// ASSERT_TRUE(!u.domain().has(pix.point()));
ASSERT_TRUE(!u.domain().has(pix.point()));
}
......
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