Commit 177e8037 authored by Edwin Carlinet's avatar Edwin Carlinet

Old API cleaning.

Rename mln_foreach_new -> mln_foreach.
parent 7d850b1e
......@@ -53,7 +53,7 @@ unsigned threshold1_bis(mln::image2d<uint8_t> f, uint8_t v)
unsigned threshold2(mln::image2d<uint8_t> f, uint8_t v)
{
unsigned count = 0;
mln_foreach_new (auto val, f.values())
mln_foreach (auto val, f.values())
count += (val < v);
return count;
......@@ -62,7 +62,7 @@ unsigned threshold2(mln::image2d<uint8_t> f, uint8_t v)
unsigned threshold3(mln::image2d<uint8_t> f, uint8_t v)
{
unsigned count = 0;
mln_foreach_new (auto px, f.pixels())
mln_foreach (auto px, f.pixels())
count += (px.val() < v);
return count;
}
......
......@@ -9,7 +9,7 @@
void Mult_Inplace_New_Values(mln::image2d<uint8_t>& img)
{
mln_foreach_new (auto& v, img.values())
mln_foreach (auto& v, img.values())
{
v *= 2;
}
......@@ -17,7 +17,7 @@ void Mult_Inplace_New_Values(mln::image2d<uint8_t>& img)
void Mult_Inplace_New_Pixels(mln::image2d<uint8_t>& img)
{
mln_foreach_new (auto&& px, img.pixels())
mln_foreach (auto&& px, img.pixels())
{
px.val() *= 2;
}
......@@ -76,7 +76,7 @@ void Threshold_Inplace_New_Values(mln::image2d<uint8_t>& img)
{
constexpr uint8_t t = 128;
mln_foreach_new (auto& v, img.values())
mln_foreach (auto& v, img.values())
{
v = v < t ? 0 : 255;
}
......@@ -86,7 +86,7 @@ void Threshold_Inplace_New_Pixels(mln::image2d<uint8_t>& img)
{
constexpr uint8_t t = 128;
mln_foreach_new (auto&& px, img.pixels())
mln_foreach (auto&& px, img.pixels())
{
px.val() = px.val() < t ? 0 : 255;
}
......@@ -150,7 +150,7 @@ void Threshold_New_Pixels(const mln::image2d<uint8_t>& in, mln::image2d<uint8_t>
void LUT_Inplace_New_Values(const uint8_t LUT[], mln::image2d<uint8_t>& img)
{
mln_foreach_new (auto& v, img.values())
mln_foreach (auto& v, img.values())
{
v = LUT[v];
}
......@@ -158,7 +158,7 @@ void LUT_Inplace_New_Values(const uint8_t LUT[], mln::image2d<uint8_t>& img)
void LUT_Inplace_New_Pixels(const uint8_t LUT[], mln::image2d<uint8_t>& img)
{
mln_foreach_new (auto&& px, img.pixels())
mln_foreach (auto&& px, img.pixels())
{
px.val() = LUT[px.val()];
}
......
......@@ -11,7 +11,7 @@
void Mult_Inplace_New_Values_Reversed(mln::image2d<uint8_t>& img)
{
auto reversed_values = mln::ranges::view::reverse(img.values());
mln_foreach_new (auto& v, reversed_values)
mln_foreach (auto& v, reversed_values)
{
v *= 2;
}
......@@ -20,7 +20,7 @@ void Mult_Inplace_New_Values_Reversed(mln::image2d<uint8_t>& img)
void Mult_Inplace_New_Pixels_Reversed(mln::image2d<uint8_t>& img)
{
auto reversed_pixels = mln::ranges::view::reverse(img.pixels());
mln_foreach_new (auto&& px, reversed_pixels)
mln_foreach (auto&& px, reversed_pixels)
{
px.val() *= 2;
}
......@@ -84,7 +84,7 @@ void Threshold_Inplace_New_Values_Reversed(mln::image2d<uint8_t>& img)
constexpr uint8_t t = 128;
auto reversed_values = mln::ranges::view::reverse(img.values());
mln_foreach_new (auto& v, reversed_values)
mln_foreach (auto& v, reversed_values)
{
v = v < t ? 0 : 255;
}
......@@ -95,7 +95,7 @@ void Threshold_Inplace_New_Pixels_Reversed(mln::image2d<uint8_t>& img)
constexpr uint8_t t = 128;
auto reversed_pixels = mln::ranges::view::reverse(img.pixels());
mln_foreach_new (auto&& px, reversed_pixels)
mln_foreach (auto&& px, reversed_pixels)
{
px.val() = px.val() < t ? 0 : 255;
}
......@@ -164,7 +164,7 @@ void Threshold_New_Pixels_Reversed(const mln::image2d<uint8_t>& input, mln::imag
void LUT_Inplace_New_Values_Reversed(const uint8_t LUT[], mln::image2d<uint8_t>& img)
{
mln_foreach_new (auto& v, img.values())
mln_foreach (auto& v, img.values())
{
v = LUT[v];
}
......@@ -172,7 +172,7 @@ void LUT_Inplace_New_Values_Reversed(const uint8_t LUT[], mln::image2d<uint8_t>&
void LUT_Inplace_New_Pixels_Reversed(const uint8_t LUT[], mln::image2d<uint8_t>& img)
{
mln_foreach_new (auto&& px, img.pixels())
mln_foreach (auto&& px, img.pixels())
{
px.val() = LUT[px.val()];
}
......
......@@ -12,28 +12,28 @@ int main()
std::cout << "== Traversing forward ==\n";
std::cout << "Traversing through points.\n";
mln_foreach_new (auto p, f.domain())
mln_foreach (auto p, f.domain())
fmt::print("f({},{}) = {}\n", p.x(), p.y(), f(p));
std::cout << "Traversing on values.\n";
mln_foreach_new (int x, f.values())
mln_foreach (int x, f.values())
std::cout << x << "\n";
std::cout << "Traversing with pixels.\n";
mln_foreach_new (auto px, f.pixels())
mln_foreach (auto px, f.pixels())
fmt::print("f({},{}) = {}\n", px.point().x(), px.point().y(), px.val());
std::cout << "\n== Traversing backward ==\n";
std::cout << "Traversing through points.\n";
mln_foreach_new (auto p, mln::ranges::view::reverse(f.domain()))
mln_foreach (auto p, mln::ranges::view::reverse(f.domain()))
fmt::print("f({},{}) = {}\n", p.x(), p.y(), f(p));
std::cout << "Traversing on values.\n";
mln_foreach_new (auto x, mln::ranges::view::reverse(f.values()))
mln_foreach (auto x, mln::ranges::view::reverse(f.values()))
std::cout << x << "\n";
std::cout << "Traversing with pixels.\n";
mln_foreach_new (auto px, mln::ranges::view::reverse(f.pixels()))
mln_foreach (auto px, mln::ranges::view::reverse(f.pixels()))
fmt::print("f({},{}) = {}\n", px.point().x(), px.point().y(), px.val());
}
......@@ -31,7 +31,7 @@ namespace mln
mln::se::rect2d win(2 * SR + 1, 2 * SR + 1);
auto g = [](double x) -> double { return std::exp(-x); };
mln_foreach_new (auto p, f.domain())
mln_foreach (auto p, f.domain())
{
site_t py = {static_cast<double>(p.x()), static_cast<double>(p.y())};
value_t vy = f(p).as_vec();
......
......@@ -63,7 +63,7 @@ namespace mln
template <class InputImage, class InputRange, class OutputImage>
void paste_unsafe(InputImage src, InputRange roi, OutputImage dest)
{
mln_foreach_new(auto p, roi)
mln_foreach(auto p, roi)
dest.at(p) = src.at(p);
}
}
......@@ -85,7 +85,7 @@ namespace mln
}
else
{
mln_foreach_new(auto p, roi)
mln_foreach(auto p, roi)
dest(p) = src(p);
}
}
......
......@@ -79,7 +79,7 @@ namespace mln
sort_compute_cumulated_histogram(input, histogram, nvalues, proj);
auto out = ::ranges::begin(rng);
mln_foreach_new (auto px, input.pixels())
mln_foreach (auto px, input.pixels())
{
std::ptrdiff_t pos = histogram[proj(px.val())]++;
if constexpr (use_p)
......@@ -98,7 +98,7 @@ namespace mln
// Copy to container
{
auto it = ::ranges::begin(rng);
mln_foreach_new (auto px, input.pixels())
mln_foreach (auto px, input.pixels())
{
if constexpr (use_p)
*it = px.point();
......
......@@ -19,7 +19,7 @@
/// \code
/// mln_foreach((auto [a,b]), multispan)
/// \endcode
#define mln_foreach_new(PROTECTED_DECL, RNG) \
#define mln_foreach(PROTECTED_DECL, RNG) \
if (bool __mln_has_been_broken = false; false) \
{ \
} \
......
......@@ -84,7 +84,7 @@ namespace mln::io
template <class I>
void imprint(I&& image, ...)
{
mln_foreach_new(auto px, image.pixels())
mln_foreach(auto px, image.pixels())
fmt::print("{{{},{}}}\n", px.point(), px.val());
}
/// \}
......
......@@ -45,7 +45,7 @@ namespace mln::labeling
{
mln_foreach_new (auto px, lbl_input.pixels())
mln_foreach (auto px, lbl_input.pixels())
{
int lbl = px.val();
assert(0 <= lbl && lbl <= nlabel);
......@@ -77,7 +77,7 @@ namespace mln::labeling
{
auto zz = mln::ranges::view::zip(lbl_input.values(), values.values());
mln_foreach_new ((auto [lbl, v]), zz)
mln_foreach ((auto [lbl, v]), zz)
{
assert(0 <= lbl && lbl <= nlabel);
vec_acc[lbl].take(v);
......
......@@ -41,7 +41,7 @@ namespace mln::labeling
mln::extension::fill(out, LBL_MAX);
mln_foreach_new(auto p, ima.domain())
mln_foreach(auto p, ima.domain())
{
if (!ima(p) || out(p) > 0)
continue;
......@@ -84,7 +84,7 @@ namespace mln::labeling
mln::extension::fill(out, LBL_MAX);
auto dom = ima.domain();
mln_foreach_new(auto p, dom)
mln_foreach(auto p, dom)
{
if (!ima(p) || out(p) > 0)
continue;
......
......@@ -62,7 +62,7 @@ namespace mln::labeling
// Forward scan
{
auto zz = mln::ranges::view::zip(input.pixels(), output.pixels());
mln_foreach_new((auto [pxin, pxout]), zz)
mln_foreach((auto [pxin, pxout]), zz)
{
if (!pxin.val())
{
......@@ -80,7 +80,7 @@ namespace mln::labeling
// Backward
{
auto zz = mln::ranges::view::zip(input.pixels(), output.pixels());
mln_foreach_new((auto [pxin, pxout]), mln::ranges::view::reverse(zz))
mln_foreach((auto [pxin, pxout]), mln::ranges::view::reverse(zz))
{
if (!pxin.val())
continue;
......
......@@ -57,7 +57,7 @@ namespace mln::labeling
{
// Forward scan
mln_foreach_new(auto p, input.domain())
mln_foreach(auto p, input.domain())
{
auto fp = input(p);
......@@ -102,7 +102,7 @@ namespace mln::labeling
int n_label = 0;
// Labelisation
{
mln_foreach_new (auto pxOut, output.pixels())
mln_foreach (auto pxOut, output.pixels())
{
if (pxOut.val())
{
......
......@@ -59,7 +59,7 @@ namespace mln::labeling
int nlabel = 0;
// 1. Push labelize CC and add border pixel in queue
mln_foreach_new (auto p, dom)
mln_foreach (auto p, dom)
{
if (!ima(p) || out(p) > 0)
continue;
......
......@@ -52,7 +52,7 @@ namespace mln::morpho
std::size_t alphatree_create_nodemap(I node_map, J zpar)
{
std::size_t node_count = 0;
mln_foreach_new(auto px, node_map.pixels())
mln_foreach(auto px, node_map.pixels())
{
auto p = px.point();
auto rp = canvas::impl::zfindroot(zpar, p);
......@@ -108,7 +108,7 @@ namespace mln::morpho
void alphatree_compute_edges(I input, N nbh, F distance, std::vector<E>& edges)
{
auto dom = input.domain();
mln_foreach_new (auto p, dom)
mln_foreach (auto p, dom)
{
for (auto n : nbh.after(p))
if (dom.has(n))
......
......@@ -182,7 +182,7 @@ namespace mln::morpho::canvas
template <class I>
[[gnu::noinline]] void union_find_init_par(I par) noexcept
{
mln_foreach_new(auto px, par.pixels())
mln_foreach(auto px, par.pixels())
px.val() = px.point();
}
......
......@@ -167,7 +167,7 @@ namespace mln::morpho
template <class I, class F>
void component_tree<void>::update_node_map(I node_map, F pred) const
{
mln_foreach_new(auto& id, node_map.values())
mln_foreach(auto& id, node_map.values())
{
if (id > 0 && !pred(id))
id = this->parent[id];
......@@ -288,7 +288,7 @@ namespace mln::morpho
std::vector<decltype(a)> attr(parent.size(), a);
// Accumulate for each point
mln_foreach_new(auto px, node_map.pixels())
mln_foreach(auto px, node_map.pixels())
attr[px.val()].take(px.point());
......@@ -322,7 +322,7 @@ namespace mln::morpho
// Accumulate for each point
auto zz = mln::view::zip(node_map, input);
mln_foreach_new((auto [node_id, val]), zz.values())
mln_foreach((auto [node_id, val]), zz.values())
attr[node_id].take(val);
......@@ -355,7 +355,7 @@ namespace mln::morpho
std::vector<decltype(a)> attr(parent.size(), a);
// Accumulate for each point
mln_foreach_new (auto px, values.pixels())
mln_foreach (auto px, values.pixels())
attr[node_map(px.point())].take(px);
......@@ -383,7 +383,7 @@ namespace mln::morpho
image_ch_value_t<I, V> out = imchvalue<V>(node_map);
auto zz = mln::view::zip(node_map, out);
mln_foreach_new ((auto&& [node_id, val]), zz.values())
mln_foreach ((auto&& [node_id, val]), zz.values())
val = values[node_id];
return out;
......
......@@ -48,7 +48,7 @@ namespace mln::morpho
{
output.extension().fill(kWaterline);
mln_foreach_new(auto px, output.pixels())
mln_foreach(auto px, output.pixels())
{
// Not a local minimum => early exit
if (px.val() != 0)
......
......@@ -7,7 +7,7 @@ namespace mln::io::internal
{
// Compute column width
int width = 0;
mln_foreach_new (auto p, roi)
mln_foreach (auto p, roi)
{
int w = static_cast<int>(fmter.formatted_size(p));
if (width < w)
......@@ -28,7 +28,7 @@ namespace mln::io::internal
{
// Compute column width
int width = 0;
mln_foreach_new (auto p, roi)
mln_foreach (auto p, roi)
{
int w = static_cast<int>(fmter.formatted_size(p));
if (width < w)
......
......@@ -20,7 +20,7 @@ TEST(View, extended)
{
auto zz = mln::view::zip(ima, x);
mln_foreach_new (auto px, zz.pixels())
mln_foreach (auto px, zz.pixels())
{
auto [v1, v2] = px.val();
ASSERT_EQ(v1, v2);
......@@ -28,7 +28,7 @@ TEST(View, extended)
}
{
mln_foreach_new (auto p, x.pixels())
mln_foreach (auto p, x.pixels())
for (auto q : mln::c8(p))
if (!x.domain().has(q.point()))
ASSERT_EQ(q.val(), 69);
......
......@@ -34,7 +34,7 @@ TEST(View, filter_readonly)
ASSERT_TRUE(mln::all_of(x > 10));
mln_foreach_new (auto&& pix, ima.pixels())
mln_foreach (auto&& pix, ima.pixels())
{
if (pix.val() > 10)
ASSERT_EQ(pix.val(), x(pix.point()));
......@@ -42,7 +42,7 @@ TEST(View, filter_readonly)
ASSERT_EQ(pix.val(), x.at(pix.point()));
}
mln_foreach_new (auto&& pix, x.pixels())
mln_foreach (auto&& pix, x.pixels())
ASSERT_EQ(pix.val(), ima(pix.point()));
}
......@@ -92,7 +92,7 @@ TEST(View, filter_twice)
ASSERT_TRUE(mln::all_of(u > 10 && u < 15));
mln_foreach_new (auto&& pix, ima.pixels())
mln_foreach (auto&& pix, ima.pixels())
{
if (pix.val() > 10 and pix.val() < 15)
{
......@@ -107,14 +107,14 @@ TEST(View, filter_twice)
}
{
mln_foreach_new (auto&& pix, u.pixels())
mln_foreach (auto&& pix, u.pixels())
ASSERT_EQ(pix.val(), ima(pix.point()));
}
mln::image2d<int> before = mln::clone(ima);
mln::fill(u, 1);
{
mln_foreach_new ((auto [old_v, new_v]), mln::ranges::view::zip(before.values(), ima.values()))
mln_foreach ((auto [old_v, new_v]), mln::ranges::view::zip(before.values(), ima.values()))
{
if (old_v > 10 && old_v < 15)
ASSERT_EQ(1, new_v);
......@@ -123,7 +123,7 @@ TEST(View, filter_twice)
}
}
mln_foreach_new (auto&& px, u.pixels())
mln_foreach (auto&& px, u.pixels())
ASSERT_EQ(px.val(), ima(px.point()));
}
......
......@@ -174,7 +174,7 @@ TEST(Core, Where)
for (auto p : r)
ASSERT_EQ(1, x(p) % 2);
mln_foreach_new (auto p, x.domain())
mln_foreach (auto p, x.domain())
if (x(p) % 2 == 1)
{
ASSERT_TRUE(z.has(p));
......
......@@ -40,7 +40,7 @@ TEST(Core, Transform_Supports_RValue_Lambda)
// check that properties of pixels are preserved (point + index)
{
auto rng = mln::ranges::view::zip(ima.pixels(), out.pixels());
mln_foreach_new ((auto [px1, px2]), rng)
mln_foreach ((auto [px1, px2]), rng)
{
ASSERT_EQ(px1.point(), px2.point());
// ASSERT_EQ(px1.index(), px2.index());
......@@ -52,7 +52,7 @@ TEST(Core, Transform_Supports_RValue_Lambda)
// Test value iteration
{
auto rng = mln::ranges::view::zip(ima.values(), out.values());
mln_foreach_new ((auto [v1, v2]), rng)
mln_foreach ((auto [v1, v2]), rng)
ASSERT_EQ(2 * v1, v2);
}
}
......@@ -172,7 +172,7 @@ TEST(Core, Transform_Support_Writable)
// check that properties of pixels are preserved (point + index)
{
auto rng = mln::ranges::view::zip(ima.pixels(), c1.pixels(), c2.pixels());
mln_foreach_new ((auto [px1, px2, px3]), rng)
mln_foreach ((auto [px1, px2, px3]), rng)
{
ASSERT_EQ(px1.point(), px2.point());
ASSERT_EQ(px1.point(), px3.point());
......@@ -187,7 +187,7 @@ TEST(Core, Transform_Support_Writable)
// Test value iteration
{
auto rng = mln::ranges::view::zip(ima.values(), c1.values(), c2.values());
mln_foreach_new ((auto [v1, v2, v3]), rng)
mln_foreach ((auto [v1, v2, v3]), rng)
{
ASSERT_EQ(std::make_pair(69, 12), v1);
ASSERT_EQ(69, v2);
......
......@@ -29,7 +29,7 @@ TEST(View, value_extended)
{
auto zz = mln::view::zip(ima, x);
mln_foreach_new (auto px, zz.pixels())
mln_foreach (auto px, zz.pixels())
{
auto [v1, v2] = px.val();
ASSERT_EQ(v1, v2);
......@@ -37,7 +37,7 @@ TEST(View, value_extended)
}
{
mln_foreach_new (auto p, x.pixels())
mln_foreach (auto p, x.pixels())
for (auto q : mln::c8(p))
if (!x.domain().has(q.point()))
ASSERT_EQ(q.val(), 69);
......
......@@ -117,7 +117,7 @@ TEST(Core, ZipImage_Value_Iteration_2)
int sum1 = 0;
{
mln_foreach_new ((auto [x, y]), x.values())
mln_foreach ((auto [x, y]), x.values())
sum1 += x + y;
}
ASSERT_EQ(sum1, 25 * 24); // sum of 25 first integers * 2
......@@ -139,7 +139,7 @@ TEST(Core, ZipImage_Temporary_usage)
// static_assert(mln::concepts::BidirectionalImage<decltype(x)>); //FIXME
static_assert(not mln::concepts::RawImage<decltype(x)>);
mln_foreach_new (auto w, x.values())
mln_foreach (auto w, x.values())
std::get<0>(w) = std::get<1>(w);
ASSERT_TRUE(mln::all_of(ima == make_image()));
......
......@@ -23,7 +23,7 @@ TEST(Range, foreach_equal_twofors)
mdindex sp({width, height});
mln_foreach_new (auto v, sp)
mln_foreach (auto v, sp)
b.push_back(v);
ASSERT_EQ(a, b);
......@@ -47,7 +47,7 @@ TEST(Range, foreach_breaks)
endfor:
mdindex sp({width, height});
mln_foreach_new (auto v, sp)
mln_foreach (auto v, sp)
{
if (v[0] == 1 && v[1] == 3)
break;
......@@ -75,7 +75,7 @@ TEST(Range, foreach_continues)
mdindex sp({width, height});
mln_foreach_new (auto v, sp)
mln_foreach (auto v, sp)
{
if (v[0] % 2 == 0 && v[1] % 2 == 0)
continue;
......
......@@ -13,7 +13,7 @@ void naive_dilate(mln::image2d<bool>& f, const mln::se::periodic_line2d& se)
mln::resize(g, f).set_init_value(false);
mln_foreach_new ((auto [pxIn, pxOut]), mln::ranges::view::zip(f.pixels(), g.pixels()))
mln_foreach ((auto [pxIn, pxOut]), mln::ranges::view::zip(f.pixels(), g.pixels()))
if (pxIn.val())
for (auto nxOut : se(pxOut))
if (f.domain().has(nxOut.point()))
......@@ -56,7 +56,7 @@ float compute_disc_error(const mln::image2d<bool>& f, float radius)
int nerror = 0;
auto sqr = [](auto x) { return x * x; };
mln_foreach_new (auto px, f.pixels())
mln_foreach (auto px, f.pixels())
{
bool ref = sqr(px.point().x()) + sqr(px.point().y()) <= sqr(radius);
nerror += (ref != px.val());
......
......@@ -54,7 +54,7 @@ TEST(IO, FreeImage_ppm)
mln::image2d<mln::rgb8> ima;
mln::image2d<mln::rgb8> ref(5, 5);
mln_foreach_new (auto&& pix, ref.pixels())
mln_foreach (auto&& pix, ref.pixels())
{
pix.val()[0] = uint8_t(pix.point().y());
pix.val()[1] = uint8_t(pix.point().x());
......@@ -74,7 +74,7 @@ TEST(IO, FreeImage_pbm)
mln::image2d<bool> ima;
mln::image2d<bool> ref(5, 5);
mln_foreach_new (auto p, ref.domain())
mln_foreach (auto p, ref.domain())
ref(p) = ((p.x() % 2) == (p.y() % 2));
mln::io::imsave(ref, "test.tiff");
......@@ -108,7 +108,7 @@ TEST(IO, FreeImage_slow_ppm)
mln::image2d<mln::rgb8> ima;
mln::image2d<mln::rgb8> ref(5, 5);
mln_foreach_new (auto&& pix, ref.pixels())
mln_foreach (auto&& pix, ref.pixels())
{