Commit b7eef55a authored by Edwin Carlinet's avatar Edwin Carlinet
Browse files

Update mask impl.

parent f873a36e
Pipeline #12783 failed with stages
in 7 minutes and 41 seconds
......@@ -18,7 +18,7 @@ namespace mln
friend ::ranges::range_access;
using pixel_range_type = decltype(std::declval<I&>().new_pixels());
I m_ima;
mutable I m_ima;
pixel_range_type m_pixels;
struct cursor
......@@ -57,14 +57,21 @@ namespace mln
where_t() = default;
bool has(image_point_t<I> p) { return m_ima(p); }
bool has(image_point_t<I> p) const { return m_ima(p); }
bool empty() const { return m_ima.domain().empty(); }
};
} // namespace ranges
template <class I>
ranges::where_t<I> new_where(const experimental::Image<I>& ima)
namespace experimental
{
return {static_cast<const I&>(ima)};
template <class I>
mln::ranges::where_t<I> where(const experimental::Image<I>& ima)
{
return {static_cast<const I&>(ima)};
}
}
} // namespace mln
......@@ -25,13 +25,15 @@ namespace mln
using typename mask_view::image_adaptor::reference;
using typename mask_view::image_adaptor::value_type;
using domain_type = mln::ranges::where_t<M>;
/// \}
static_assert(std::is_same_v<typename M::value_type, bool>, "Image value type must be boolean.");
/// \}
static_assert(image_accessible_v<M>, "The mask must accessible (ima(p) must be valid");
/// Traits & Image Properties
/// \{
using category = forward_image_tag;
using accessible = image_accessible_t<I>;
using indexable = image_indexable_t<I>;
using view = std::true_type;
......@@ -40,8 +42,6 @@ namespace mln
template <class V>
using ch_value_type = mask_view<image_ch_value_t<I, V>, M>;
static_assert(I::accessible::value, "Image must be pw-accessible.");
/// \}
......@@ -175,17 +175,8 @@ namespace mln
pixel_range_t new_pixels() { return {this->base().new_pixels(), m_mask.new_values()}; }
/// Indexable-image related methods
/// \{
template <typename dummy = I>
reference operator[](image_index_t<dummy> i)
{
return this->base()[i];
}
/// \}
/// Accessible-image related methods
/// Accessible-image related methods (overwritten from adaptor)
/// \{
template <typename Ret = reference>
std::enable_if_t<accessible::value, Ret> operator()(point_type p)
......@@ -195,12 +186,6 @@ namespace mln
return this->base()(p);
}
template <typename Ret = reference>
std::enable_if_t<accessible::value, Ret> at(point_type p)
{
return this->base().at(p);
}
template <typename Ret = new_pixel_type>
std::enable_if_t<accessible::value, Ret> new_pixel(point_type p)
{
......@@ -208,12 +193,6 @@ namespace mln
mln_precondition(this->base().domain().has(p));
return this->base().new_pixel(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);
}
/// \}
......
......@@ -220,7 +220,7 @@ TEST(Core, Where)
mln::image2d<uint8_t> x = {{1, 2, 3}, {4, 5, 6}};
auto y = x % 2;
auto z = mln::new_where(y);
auto z = mln::experimental::where(y);
static_assert(::ranges::ForwardRange<decltype(z)>());
......@@ -234,3 +234,56 @@ TEST(Core, Where)
ASSERT_TRUE(z.has(p));
}
}
struct mask_archetype : mln::experimental::Image<mask_archetype>
{
using value_type = bool;
using reference = const bool&;
using domain_type = mln::archetypes::Domain;
using point_type = ::ranges::range_value_t<domain_type>;
using category_type = mln::forward_image_tag;
using concrete_type = mask_archetype;
struct new_pixel_type
{
bool val() const;
point_type point() const;
};
template <class V>
using ch_value_type = mask_archetype;
// additional traits
using extension_category = mln::extension::none_extension_tag;
using indexable = std::false_type;
using accessible = std::true_type;
using view = std::false_type;
domain_type domain() const;
reference operator()(point_type);
reference at(point_type);
new_pixel_type new_pixel(point_type);
new_pixel_type new_pixel_at(point_type);
struct pixel_range
{
const new_pixel_type* begin();
const new_pixel_type* end();
};
pixel_range new_pixels();
struct value_range
{
const value_type* begin();
const value_type* end();
};
value_range new_values();
};
#ifdef PYLENE_CONCEPT_TS_ENABLED
static_assert(mln::concepts::Domain<mln::ranges::where_t<mask_archetype>>);
#endif
#include <mln/core/image/image2d.hpp>
#include <mln/core/image/private/image_operators.hpp>
#include <mln/core/image/view/mask.hpp>
#include <mln/core/algorithm/all_of.hpp>
#include <mln/core/algorithm/fill.hpp>
#include <mln/core/concept/new/archetype/image.hpp>
#include <mln/core/image/image2d.hpp>
#include <mln/core/image/private/image_operators.hpp>
#include <mln/core/rangev3/foreach.hpp>
#include <helpers.hpp>
......@@ -35,7 +36,7 @@ TEST(View, mask)
ASSERT_EQ(42, ima(p));
ASSERT_EQ(42, z(p));
}
ASSERT_TRUE(mln::experimental::all(ima == ref));
ASSERT_TRUE(mln::experimental::all_of(ima == ref));
}
......@@ -65,5 +66,70 @@ TEST(View, mask_twice)
ASSERT_EQ(42, B(p));
}
ASSERT_TRUE(mln::experimental::all(ima == ref));
ASSERT_TRUE(mln::experimental::all_of(ima == ref));
}
struct mask_archetype : mln::experimental::Image<mask_archetype>
{
using value_type = bool;
using reference = const bool&;
using domain_type = mln::archetypes::Domain;
using point_type = ::ranges::range_value_t<domain_type>;
using category_type = mln::forward_image_tag;
using concrete_type = mask_archetype;
struct new_pixel_type
{
bool val() const;
point_type point() const;
};
template <class V>
using ch_value_type = mask_archetype;
// additional traits
using extension_category = mln::extension::none_extension_tag;
using indexable = std::false_type;
using accessible = std::true_type;
using view = std::false_type;
domain_type domain() const;
reference operator()(point_type);
reference at(point_type);
new_pixel_type new_pixel(point_type);
new_pixel_type new_pixel_at(point_type);
struct pixel_range
{
const new_pixel_type* begin();
const new_pixel_type* end();
};
pixel_range new_pixels();
struct value_range
{
const value_type* begin();
const value_type* end();
};
value_range new_values();
};
template <mln::concepts::Image I>
void foo(I*);
#ifdef PYLENE_CONCEPT_TS_ENABLED
static_assert(mln::concepts::AccessibleImage<mln::mask_view<mln::archetypes::AccessibleImage, mask_archetype>>);
static_assert(mln::concepts::IndexableImage<mln::mask_view<mln::archetypes::IndexableImage, mask_archetype>>);
static_assert(mln::concepts::IndexableAndAccessibleImage<mln::mask_view<mln::archetypes::IndexableAndAccessibleImage, mask_archetype>>);
static_assert(mln::concepts::OutputImage<mln::mask_view<mln::archetypes::OutputAccessibleImage, mask_archetype>>);
static_assert(mln::concepts::OutputImage<mln::mask_view<mln::archetypes::OutputIndexableImage, mask_archetype>>);
static_assert(mln::concepts::OutputImage<mln::mask_view<mln::archetypes::OutputIndexableAndAccessibleImage, mask_archetype>>);
#endif
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