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

Update filter (impl)

parent 5b8c2524
Pipeline #12862 failed with stages
in 32 seconds
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
namespace mln::archetypes namespace mln::archetypes
{ {
struct Domain final struct Domain
{ {
using value_type = Point; using value_type = Point;
using reference = Point&; using reference = Point&;
...@@ -17,11 +17,20 @@ namespace mln::archetypes ...@@ -17,11 +17,20 @@ namespace mln::archetypes
bool has(value_type) const; bool has(value_type) const;
bool empty() const; bool empty() const;
// unsigned size() const;
}; };
#ifdef PYLENE_CONCEPT_TS_ENABLED #ifdef PYLENE_CONCEPT_TS_ENABLED
static_assert(mln::concepts::Domain<Domain>, "Domain archetype does not model the Domain concept!"); static_assert(mln::concepts::Domain<Domain>, "Domain archetype does not model the Domain concept!");
#endif // PYLENE_CONCEPT_TS_ENABLED #endif // PYLENE_CONCEPT_TS_ENABLED
struct SizedDomain : Domain
{
unsigned size() const;
};
#ifdef PYLENE_CONCEPT_TS_ENABLED
static_assert(mln::concepts::SizedDomain<SizedDomain>,
"SizedDomain archetype does not model the SizedDomain concept!");
#endif // PYLENE_CONCEPT_TS_ENABLED
} // namespace mln::archetypes } // namespace mln::archetypes
...@@ -15,6 +15,7 @@ namespace mln::concepts ...@@ -15,6 +15,7 @@ namespace mln::concepts
// clang-format off // clang-format off
#ifdef PYLENE_CONCEPT_TS_ENABLED #ifdef PYLENE_CONCEPT_TS_ENABLED
// Domain // Domain
template<typename Dom> template<typename Dom>
concept Domain = concept Domain =
...@@ -26,6 +27,16 @@ namespace mln::concepts ...@@ -26,6 +27,16 @@ namespace mln::concepts
{ cdom.empty() } -> bool; { cdom.empty() } -> bool;
// { cdom.size() } -> stl::UnsignedIntegral&&; // { cdom.size() } -> stl::UnsignedIntegral&&;
}; };
// SizedDomain
template<typename Dom>
concept Domain =
Domain<Dom> &&
requires(const Dom cdom) {
{ cdom.size() } -> stl::UnsignedIntegral&&;
};
#endif // PYLENE_CONCEPT_TS_ENABLED #endif // PYLENE_CONCEPT_TS_ENABLED
// clang-format on // clang-format on
......
#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
...@@ -94,9 +94,7 @@ namespace mln ...@@ -94,9 +94,7 @@ namespace mln
template <typename dummy = I> template <typename dummy = I>
reference operator[](image_index_t<dummy> i) reference operator[](image_index_t<dummy> i)
{ {
mln_precondition(i < m_domain.size()); return this->base()[i];
auto p = domain()[i];
return this->base()(p);
} }
/// \} /// \}
...@@ -118,7 +116,7 @@ namespace mln ...@@ -118,7 +116,7 @@ namespace mln
template <typename Ret = new_pixel_type> template <typename Ret = new_pixel_type>
std::enable_if_t<accessible::value, Ret> new_pixel(point_type p) std::enable_if_t<accessible::value, Ret> new_pixel(point_type p)
{ {
mln_precondition(this->m_domain.has(p)); mln_precondition(m_domain.has(p));
mln_precondition(this->base().domain().has(p)); mln_precondition(this->base().domain().has(p));
return this->base().new_pixel(p); return this->base().new_pixel(p);
} }
...@@ -135,20 +133,22 @@ namespace mln ...@@ -135,20 +133,22 @@ namespace mln
template <typename dummy = I> template <typename dummy = I>
std::enable_if_t<(indexable::value && accessible::value), image_index_t<dummy>> index_of_point(point_type p) const std::enable_if_t<(indexable::value && accessible::value), image_index_t<dummy>> index_of_point(point_type p) const
{ {
// FIXME: how to implement this here ? mln_precondition(m_domain.has(p));
mln_precondition(this->base().domain().has(p));
return this->base().index_of_point(p); return this->base().index_of_point(p);
} }
template <typename dummy = I> template <typename dummy = I>
point_type point_at_index(std::enable_if_t<(indexable::value && accessible::value), image_index_t<dummy>> i) const point_type point_at_index(std::enable_if_t<(indexable::value && accessible::value), image_index_t<dummy>> i) const
{ {
return domain()[i]; return this->base().point_at_index(i);
} }
template <typename dummy = I> template <typename dummy = I>
std::enable_if_t<(indexable::value && accessible::value), image_index_t<dummy>> delta_index(point_type p) const std::enable_if_t<(indexable::value && accessible::value), image_index_t<dummy>> delta_index(point_type p) const
{ {
// FIXME: how to implement this here ? mln_precondition(m_domain.has(p));
mln_precondition(this->base().domain().has(p));
return this->base().delta_index(p); return this->base().delta_index(p);
} }
/// \} /// \}
......
#pragma once #pragma once
#include <mln/core/image/image.hpp> #include <mln/core/image/image.hpp>
#include <mln/core/image/private/filtered.hpp>
#include <mln/core/image/view/adaptor.hpp> #include <mln/core/image/view/adaptor.hpp>
#include <mln/core/rangev3/view/filter.hpp> #include <mln/core/rangev3/view/filter.hpp>
...@@ -13,41 +14,11 @@ ...@@ -13,41 +14,11 @@
namespace mln 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> template <class I, class F>
class filter_view : public image_adaptor<I>, public experimental::Image<filter_view<I, F>> class filter_view : public image_adaptor<I>, public experimental::Image<filter_view<I, F>>
{ {
using fun_t = F; // FIXME something with semiregular_t<F> ? using fun_t = F;
fun_t f; fun_t f;
public: public:
...@@ -57,7 +28,7 @@ namespace mln ...@@ -57,7 +28,7 @@ namespace mln
using value_type = std::decay_t<reference>; using value_type = std::decay_t<reference>;
using typename filter_view::image_adaptor::new_pixel_type; using typename filter_view::image_adaptor::new_pixel_type;
using typename filter_view::image_adaptor::point_type; using typename filter_view::image_adaptor::point_type;
using domain_type = filtered_domain<I, F>; using domain_type = detail::filtered<I, F>;
/// \} /// \}
/// Traits & Image Properties /// Traits & Image Properties
...@@ -92,7 +63,7 @@ namespace mln ...@@ -92,7 +63,7 @@ namespace mln
{ {
} }
domain_type domain() const {return filtered_domain{(this->base(), this->f }; } domain_type domain() const { return detail::filtered{this->base(), this->f}; }
auto new_values() { return mln::ranges::view::filter(this->base().new_values(), f); } auto new_values() { return mln::ranges::view::filter(this->base().new_values(), f); }
...@@ -109,8 +80,7 @@ namespace mln ...@@ -109,8 +80,7 @@ namespace mln
template <typename Ret = reference> template <typename Ret = reference>
std::enable_if_t<accessible::value, Ret> operator()(point_type p) 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: mln_precondition(this->base().domain().has(p));
// (ASSERT_EQ(pix.val(), u(pix.point()));) mln_precondition(this->base().domain().has(p));
mln_precondition(std::invoke(f, this->base()(p))); mln_precondition(std::invoke(f, this->base()(p)));
return this->base()(p); return this->base()(p);
} }
......
...@@ -14,7 +14,7 @@ namespace mln ...@@ -14,7 +14,7 @@ namespace mln
template <class I, class M> template <class I, class M>
class mask_view : public image_adaptor<I>, public experimental::Image<mask_view<I, M>> class mask_view : public image_adaptor<I>, public experimental::Image<mask_view<I, M>>
{ {
mutable M m_mask; M m_mask;
public: public:
/// Type definitions /// Type definitions
...@@ -147,14 +147,14 @@ namespace mln ...@@ -147,14 +147,14 @@ namespace mln
template <class I2, class D2> template <class I2, class D2>
mask_view(const mask_view<I2, D2>& other, mln::init) mask_view(const mask_view<I2, D2>& other, mln::init)
: mask_view::image_adaptor{static_cast<I>(imchvalue<value_type>(other.base()))} : mask_view::image_adaptor{static_cast<I>(other.base().template ch_value<value_type>())}
, m_mask{other.m_mask} , m_mask{other.m_mask}
{ {
} }
template <class I2, class D2> template <class I2, class D2>
mask_view(const mask_view<I2, D2>& other, const value_type& v) mask_view(const mask_view<I2, D2>& other, const value_type& v)
: mask_view::image_adaptor{static_cast<I>(imchvalue<value_type>(other.base()).init(v))} : mask_view::image_adaptor{static_cast<I>((other.base().template ch_value<value_type>()).init(v))}
, m_mask{other.m_mask} , m_mask{other.m_mask}
{ {
} }
......
...@@ -57,7 +57,7 @@ TEST(View, filter_writable) ...@@ -57,7 +57,7 @@ TEST(View, filter_writable)
ASSERT_TRUE(mln::experimental::all(ima <= 10)); ASSERT_TRUE(mln::experimental::all(ima <= 10));
} }
/*
TEST(View, filter_twice) TEST(View, filter_twice)
{ {
using namespace mln; using namespace mln;
...@@ -107,3 +107,4 @@ TEST(View, filter_twice) ...@@ -107,3 +107,4 @@ TEST(View, filter_twice)
mln_foreach_new (auto&& px, u.new_pixels()) mln_foreach_new (auto&& px, u.new_pixels())
ASSERT_EQ(px.val(), ima(px.point())); ASSERT_EQ(px.val(), ima(px.point()));
} }
*/
\ No newline at end of file
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