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

WIP: Update filter (impl)

parent 70f26a52
Pipeline #12864 failed with stages
in 5 minutes and 3 seconds
......@@ -15,9 +15,9 @@ namespace mln::archetypes
value_type* begin();
value_type* end();
bool has(value_type) const;
bool empty() const;
unsigned size() const;
bool has(value_type) const;
bool empty() const;
// unsigned size() const;
};
#ifdef PYLENE_CONCEPT_TS_ENABLED
......
......@@ -24,7 +24,7 @@ namespace mln::concepts
requires(const Dom cdom, domain_point_t<Dom> p) {
{ cdom.has(p) } -> bool;
{ cdom.empty() } -> bool;
{ cdom.size() } -> stl::UnsignedIntegral&&;
// { cdom.size() } -> stl::UnsignedIntegral&&;
};
#endif // PYLENE_CONCEPT_TS_ENABLED
......
......@@ -4,11 +4,45 @@
#include <mln/core/image/view/adaptor.hpp>
#include <mln/core/rangev3/view/filter.hpp>
#include <range/v3/empty.hpp>
#include <range/v3/size.hpp>
#include <range/v3/utility/functional.hpp>
#include <type_traits>
namespace mln
{
// FIXME: move into a different file
// FIXME: use all_t for ima
// FIXME: use
template <typename I, typename F>
struct filtered_domain
{
using value_type = image_value_t<I>;
using reference = image_reference_t<I>;
filtered_domain(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_); }
// unsigned size() const { return ::ranges::size(rng_); }
private:
decltype(mln::ranges::view::filter(std::declval<I>().domain(), std::declval<F>())) rng_;
I ima_;
F f_;
};
template <class I, class F>
class filter_view : public image_adaptor<I>, public experimental::Image<filter_view<I, F>>
......@@ -19,24 +53,23 @@ namespace mln
public:
/// Type definitions
/// \{
using reference = std::invoke_result_t<F&, typename I::reference>;
using reference = std::invoke_result_t<F&, image_reference_t<I>>;
using value_type = std::decay_t<reference>;
using point_type = typename I::point_type;
using concrete_type = void; // This image has no automatic concrete type
template <class V>
using ch_value_type = void; // This image has no automatic concrete type
using typename filter_view::image_adaptor::new_pixel_type;
using typename filter_view::image_adaptor::point_type;
using domain_type = filtered_domain<I, F>;
/// \}
/// Traits & Image Properties
/// \{
using accessible = typename I::accessible;
using indexable = std::false_type; // May be too restrictive
using extension_category =
mln::extension::none_extension_tag; // May be too restrictive (might be extended by image)
using accessible = image_accessible_t<I>;
using indexable = std::false_type;
using view = std::true_type;
// May be too restrictive (might be extended by image)
using extension_category = mln::extension::none_extension_tag;
using concrete_type = void; // This image has no automatic concrete type
template <class V>
using ch_value_type = void; // This image has no automatic concrete type
/// \}
......@@ -52,7 +85,6 @@ namespace mln
}
};
public:
filter_view(I ima, F fun)
: filter_view::image_adaptor{std::move(ima)}
......@@ -60,15 +92,8 @@ namespace mln
{
}
auto domain() const
{
// FIXME: this range has not a "has" method so not a domain.
auto g = [this](point_type p) -> bool { return this->f(this->base().at(p)); };
return mln::ranges::view::filter(this->base().domain(), g);
}
domain_type domain() const {return filtered_domain{(this->base(), this->f }; }
// using domain_type = decltype(domain());
auto new_values() { return mln::ranges::view::filter(this->base().new_values(), f); }
......@@ -79,36 +104,42 @@ namespace mln
}
template <typename dummy = reference>
std::enable_if_t<accessible::value, dummy> operator()(point_type p)
/// Accessible-image related methods
/// \{
template <typename Ret = reference>
std::enable_if_t<accessible::value, Ret> operator()(point_type p)
{
// FIXME: with I = mln::image2d<int> has no member named 'has', from tests/core/image/view/filter.cpp:71:
// (ASSERT_EQ(pix.val(), u(pix.point()));) mln_precondition(this->base().domain().has(p));
mln_precondition(std::invoke(f, this->base().at(p)));
return this->base().at(p);
mln_precondition(std::invoke(f, this->base()(p)));
return this->base()(p);
}
template <typename dummy = reference>
std::enable_if_t<accessible::value, dummy> at(point_type p)
template <typename Ret = reference>
std::enable_if_t<accessible::value, Ret> at(point_type p)
{
return this->base().at(p);
}
template <typename dummy = new_pixel_type>
std::enable_if_t<accessible::value, dummy> new_pixel(point_type p)
template <typename Ret = new_pixel_type>
std::enable_if_t<accessible::value, Ret> new_pixel(point_type p)
{
mln_precondition(this->base().domain().has(p));
mln_precondition(std::invoke(f, this->base().at(p)));
return this->base().new_pixel(p);
}
template <typename dummy = new_pixel_type>
std::enable_if_t<accessible::value, dummy> new_pixel_at(point_type p)
template <typename Ret = new_pixel_type>
std::enable_if_t<accessible::value, Ret> new_pixel_at(point_type p)
{
return this->base().new_pixel_at(p);
}
/// \}
/// Raw-image related methods
/// \{
auto data() const = delete;
auto data() = delete;
auto strides(int dim) const = delete;
/// \}
};
......
......@@ -20,7 +20,7 @@ add_core_test(${test_prefix}range_zip range/zip.cpp)
add_core_test(${test_prefix}view_adaptor image/view/adaptor.cpp)
add_core_test(${test_prefix}view_transform image/view/transform.cpp)
# FIXME: segfault
# add_core_test(${test_prefix}view_filter image/view/filter.cpp)
add_core_test(${test_prefix}view_filter image/view/filter.cpp)
add_core_test(${test_prefix}view_clip image/view/clip.cpp)
add_core_test(${test_prefix}view_mask image/view/mask.cpp)
add_core_test(${test_prefix}view_zip image/view/zip.cpp)
......
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