Commit 2517cc72 authored by Michaël Roynard's avatar Michaël Roynard
Browse files

WIP

parent 876a5afa
Pipeline #12910 failed with stages
in 5 minutes and 8 seconds
#pragma once
#include <mln/core/image/private/image_traits.hpp>
#include <mln/core/rangev3/view/filter.hpp>
#include <range/v3/begin_end.hpp>
#include <range/v3/empty.hpp>
#include <utility>
namespace mln::detail
{
template <typename I, typename F>
struct filtered
{
using value_type = image_value_t<I>;
using reference = image_reference_t<I>;
filtered(I ima, F f)
: rng_(mln::ranges::view::filter(ima.domain(), f))
, ima_(ima)
, f_(f)
{
}
auto begin() { return ::ranges::begin(rng_); }
auto end() { return ::ranges::end(rng_); }
bool has(value_type p) const { return f_(ima_(p)); }
bool empty() const { return ::ranges::empty(rng_); }
private:
using rng_t = decltype(mln::ranges::view::filter(std::declval<I>().domain(), std::declval<F>()));
rng_t rng_;
I ima_;
F f_;
};
} // namespace mln::detail
#pragma once
#include <mln/core/image/image.hpp>
#include <mln/core/image/private/filtered.hpp>
#include <mln/core/image/view/adaptor.hpp>
#include <mln/core/rangev3/view/filter.hpp>
......@@ -28,9 +27,36 @@ namespace mln
using typename filter_view::image_adaptor::point_type;
using typename filter_view::image_adaptor::reference;
using typename filter_view::image_adaptor::value_type;
using domain_type = detail::filtered<I, F>;
class domain_type
{
using fun_t = ::ranges::semiregular_t<F>;
using rng_t = decltype(mln::ranges::view::filter(std::declval<I>().domain(), std::declval<fun_t>()));
rng_t rng_;
I ima_;
fun_t f_;
public:
using value_type = image_value_t<I>;
using reference = image_reference_t<I>;
domain_type(I ima, F f)
: rng_(mln::ranges::view::filter(ima.domain(), std::move(f)))
, ima_(std::move(ima))
, f_(std::move(f))
{
}
auto begin() { return ::ranges::begin(rng_); }
auto end() { return ::ranges::end(rng_); }
bool has(value_type p) const { return f_(ima_(p)); }
bool empty() const { return ::ranges::empty(rng_); }
};
/// \}
/// Traits & Image Properties
/// \{
using accessible = image_accessible_t<I>;
......@@ -56,6 +82,7 @@ namespace mln
}
};
public:
filter_view(I ima, F fun)
: filter_view::image_adaptor{std::move(ima)}
......@@ -63,8 +90,8 @@ namespace mln
{
}
domain_type domain() const { return detail::filtered{this->base(), this->f}; }
domain_type domain() const { return {this->base(), this->f}; }
auto new_values() { return mln::ranges::view::filter(this->base().new_values(), f); }
......
......@@ -24,6 +24,14 @@ TEST(View, filter_readonly)
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
ASSERT_TRUE(mln::experimental::all_of(x > 10));
mln_foreach_new (auto&& pix, ima.new_pixels())
......@@ -50,6 +58,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
mln::experimental::fill(x, 10);
ASSERT_TRUE(mln::experimental::all_of(ima <= 10));
}
......@@ -65,6 +81,14 @@ TEST(View, filter_twice)
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
// FIXME:
// auto x = view::filter(ima, [](int v) { return v > 10; });
// auto u = view::filter(x, [](int v) { return v < 15; });
......
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