Olena-patches
Threads by month
- ----- 2025 -----
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- 9625 discussions
Index: ChangeLog
from Nicolas Widynski <nicolas.widynski(a)lrde.epita.fr>
* oln/core/abstract/image.hh: patch for adding method call.
* oln/core/abstract/image_constness.hh: add method call for
readwrite images.
* oln/core/abstract/image_with_data.hh: likewise.
* oln/core/2d/array2d.hh: likewise.
* oln/core/box.hh: likewise.
* oln/makefile.src: add files.
appli/astro/clean.hh | 420 +++++++++++++++++++++++++++++++++++++++
canvas/maxtree.hh | 346 ++++++++++++++++++++++++++++++++
canvas/tree.hh | 215 +++++++++++++++++++
core/2d/array2d.hh | 2
core/abstract/image.hh | 2
core/abstract/image_constness.hh | 16 +
core/abstract/image_with_data.hh | 2
core/box.hh | 17 +
makefile.src | 4
morpho/clean_astro_images.hh | 269 ------------------------
morpho/maxtree.hh | 313 -----------------------------
morpho/tree.hh | 194 ------------------
12 files changed, 1016 insertions(+), 784 deletions(-)
Index: oln/core/abstract/image_constness.hh
--- oln/core/abstract/image_constness.hh (revision 209)
+++ oln/core/abstract/image_constness.hh (working copy)
@@ -34,7 +34,7 @@
// image
//
// ^
-// |
+// |
// ---------------
// | |
//
@@ -158,11 +158,19 @@
// return *this;
// }
+ typedef internal::get_image_impl < readwrite_image<E>, E > super_rw_impl;
+ typedef internal::get_image_impl < image<E>, E > super_impl;
+
template <typename T, typename A, typename V>
void call(const point_type& p,
void (T::*method)(A),
V arg);
+ template <typename R, typename T>
+ R call(const oln_type_of(E, point)& p,
+ R (T::*method)() const) const;
+
+
protected:
/*! \brief Constructor (protected, empty).
@@ -201,6 +209,12 @@
this->delegate().impl_call(p, method, arg);
}
+ template <typename R, typename T>
+ R impl_call(const oln_type_of(E, point)& p,
+ R (T::*method)() const) const
+ {
+ return this->delegate().call(p, method);
+ }
// extra code; default is 'do nothing':
Index: oln/core/abstract/image.hh
--- oln/core/abstract/image.hh (revision 209)
+++ oln/core/abstract/image.hh (working copy)
@@ -371,7 +371,6 @@
const value_type get(const point_type& p) const; // impl is in box.hh
-
// FIXME: patch!
void resize_border(size_t new_border, bool copy_border = false) const
@@ -414,7 +413,6 @@
typedef oln_type_of(D, point) point_type;
typedef oln_type_of(D, value) value_type;
-
// delegations are "template methods" (Cf. the GOF's book)
const size_type& impl_size() const
Index: oln/core/abstract/image_with_data.hh
--- oln/core/abstract/image_with_data.hh (revision 209)
+++ oln/core/abstract/image_with_data.hh (working copy)
@@ -156,7 +156,6 @@
R (T::*method)() const) const
{
return (this->data_->get(p).*method)();
- //this->data_->call(p, method);
}
template <typename T, typename A, typename V>
@@ -164,7 +163,6 @@
void (T::*method)(A),
V arg)
{
- // std::cout << "yes!" << std::endl;
this->data_->call(p, method, arg);
}
Index: oln/core/2d/array2d.hh
--- oln/core/2d/array2d.hh (revision 209)
+++ oln/core/2d/array2d.hh (working copy)
@@ -223,8 +223,6 @@
(value.*method)(arg);
}
-
-
void impl_set_data(const T& v)
{
invariant_();
Index: oln/core/box.hh
--- oln/core/box.hh (revision 209)
+++ oln/core/box.hh (working copy)
@@ -279,8 +279,9 @@
return this->exact().impl_get(p);
}
- /// Implementation of abstract::image<E>::call(p, method) const.
+ /// Implementation of abstract::readonly_image<E>::call(p, method) const.
+
template <typename E>
template <typename R, typename T>
R
@@ -293,6 +294,20 @@
return this->exact().impl_call(p, method);
}
+ /// Implementation of abstract::readwrite_image<E>::call(p, method) const.
+
+ template <typename E>
+ template <typename R, typename T>
+ R
+ readwrite_image<E>::call(const oln_type_of(E, point)& p,
+ R (T::*method)() const) const
+ {
+# ifdef OLNTRACE
+ inc_ncalls("call", *this);
+# endif // ! OLNTRACE
+ return this->exact().impl_call(p, method);
+ }
+
/// Implementation of abstract::readwrite_image<E>::call(p, method, value).
template <typename E>
template <typename T, typename A, typename V>
Index: oln/makefile.src
--- oln/makefile.src (revision 209)
+++ oln/makefile.src (working copy)
@@ -6,6 +6,8 @@
OLN_DEP = \
all.hh \
\
+ appli/astro/clean.hh \
+ \
basics1d.hh \
basics2d.hh \
basics3d.hh \
@@ -14,6 +16,8 @@
canvas/backandforth.hh \
canvas/io.hh \
canvas/reconstruction.hh \
+ canvas/tree.hh \
+ canvas/maxtree.hh \
\
config/pconf.hh \
config/system.hh \
Index: oln/morpho/tree.hh
--- oln/morpho/tree.hh (revision 209)
+++ oln/morpho/tree.hh (working copy)
@@ -1,194 +0,0 @@
-// Copyright (C) 2005 EPITA Research and Development Laboratory
-//
-// This file is part of the Olena Library. This library is free
-// software; you can redistribute it and/or modify it under the terms
-// of the GNU General Public License version 2 as published by the
-// Free Software Foundation.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this library; see the file COPYING. If not, write to
-// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
-// MA 02111-1307, USA.
-//
-// As a special exception, you may use this file as part of a free
-// software library without restriction. Specifically, if other files
-// instantiate templates or use macros or inline functions from this
-// file, or you compile this file and link it with other files to
-// produce an executable, this file does not by itself cause the
-// resulting executable to be covered by the GNU General Public
-// License. This exception does not however invalidate any other
-// reasons why the executable file might be covered by the GNU General
-// Public License.
-
-#ifndef OLENA_MORPHO_CANVAS_TREE_HH
-# define OLENA_MORPHO_CANVAS_TREE_HH
-
-# include <mlc/any.hh>
-
-# include <oln/core/box.hh>
-# include <oln/utils/record.hh>
-# include <oln/core/abstract/image_entry.hh>
-# include <oln/core/ch_value_type.hh>
-# include <oln/level/fill.hh>
-# include <oln/basics.hh>
-
-# include <vector>
-
-
-namespace oln {
-
- namespace morpho {
-
- namespace canvas {
-
-
- template <typename I, typename E>
- struct tree : public mlc::any<E>
- {
- typedef oln_type_of(I, point) point_type;
-
- // Attribute.
- box<const I> input;
- oln_type_of(I, concrete) output;
- std::vector<std::vector<point_type> > S;
- point_type root_point;
-
- void run_compute_tree()
- {
- first_pass();
- compute_tree();
- }
-
- void run_compute_output()
- {
- init_processing();
- processing();
- }
-
- // Concrete method.
- void first_pass()
- {
- oln_type_of(I, niter) n(input);
-
- // init
- compute_S();
- set_is_processed_to_false();
- set_default_output();
-
- typename std::vector<std::vector<point_type> >::reverse_iterator i;
- typename std::vector<point_type>::const_iterator j;
- for (i = S.rbegin(); i != S.rend(); i++)
- {
- for (j = i->begin(); j != i->end(); j++)
- {
- make_set(*j);
- for_all_n_of_p (n, *j)
- if (input.hold(n) and is_processed(n))
- do_union(n, *j);
- set_is_processed(*j);
- }
- }
- root_point = *j;
- }
-
- void do_union(const point_type& n, const point_type& p)
- {
- point_type r = find_root(n);
- if (r != p)
- set_father(r, p);
- }
-
- // Abstract methods.
- // ---------------------------
-
- // init
-
- void init_processing()
- {
- this->exact().impl_init_processing();
- }
-
- void compute_S()
- {
- this->exact().impl_compute_S();
- }
- void set_default_output()
- {
- this->exact().impl_set_default_output();
- }
-
- // about is_processed
- void set_is_processed_to_false()
- {
- this->exact().impl_set_is_processed_to_false();
- }
- void set_is_processed(const point_type& p)
- {
- this->exact().impl_set_is_processed(p);
- }
- bool is_processed(const point_type& n) const
- {
- return this->exact().impl_is_processed(n);
- }
-
- const point_type get_father(const point_type& p) const
- {
- return this->exact().impl_get_father(p);
- }
-
- // core
-
- void compute_tree()
- {
- this->exact().impl_compute_tree();
- }
-
- void processing()
- {
- this->exact().impl_processing();
- }
-
- void make_set(const point_type& p)
- {
- this->exact().impl_make_set(p);
- }
- point_type find_root(const point_type& x)
- {
- return this->exact().impl_find_root(x);
- }
- void set_father(const point_type& r, const point_type& p)
- {
- this->exact().impl_set_father(r, p);
- }
-
- protected:
-
- // Ctor.
- tree(const abstract::image_with_nbh<I>& input) :
- input(input),
- S()
- {
- }
-
- // Check for impls..
- ~tree()
- {
- // FIXME... mlc_check_method_impl(E, void, init, , );
- }
-
- };
-
-
- } // end of namespace oln::morpho::canvas
-
- } // end of namespace oln::morpho
-
-} // end of namespace oln
-
-
-#endif // ! OLENA_MORPHO_CANVAS_TREE_HH
Index: oln/morpho/maxtree.hh
--- oln/morpho/maxtree.hh (revision 209)
+++ oln/morpho/maxtree.hh (working copy)
@@ -1,313 +0,0 @@
-// Copyright (C) 2005 EPITA Research and Development Laboratory
-//
-// This file is part of the Olena Library. This library is free
-// software; you can redistribute it and/or modify it under the terms
-// of the GNU General Public License version 2 as published by the
-// Free Software Foundation.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this library; see the file COPYING. If not, write to
-// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
-// MA 02111-1307, USA.
-//
-// As a special exception, you may use this file as part of a free
-// software library without restriction. Specifically, if other files
-// instantiate templates or use macros or inline functions from this
-// file, or you compile this file and link it with other files to
-// produce an executable, this file does not by itself cause the
-// resulting executable to be covered by the GNU General Public
-// License. This exception does not however invalidate any other
-// reasons why the executable file might be covered by the GNU General
-// Public License.
-
-#ifndef OLENA_MORPHO_MAX_TREE_HH
-# define OLENA_MORPHO_MAX_TREE_HH
-
-# include <mlc/any.hh>
-
-# include <oln/core/box.hh>
-# include <oln/utils/record.hh>
-# include <oln/core/abstract/image_entry.hh>
-# include <oln/core/ch_value_type.hh>
-# include <oln/level/fill.hh>
-
-# include <oln/morpho/tree.hh>
-# include <oln/basics.hh>
-
-# include <cassert>
-# include <vector>
-# include <functional>
-# include <set>
-
-
-namespace oln {
-
- namespace morpho {
-
- namespace misc {
-
- struct pair_cmp
- {
- template<typename L, typename P>
- bool operator()(const std::pair<L,P>& lhs,
- const std::pair<L,P>& rhs) const
- {
- return lhs.first < rhs.first
- or (lhs.first == rhs.first
- and lhs.second.fwd_less(rhs.second));
- }
- };
-
- template<typename I, typename II, typename O, typename V>
- void set_children(abstract::image_with_nbh<I>& marked,
- const abstract::image_with_nbh<II>& children,
- abstract::image_with_nbh<O>& out,
- const oln_type_of(I, point)& p,
- const V v)
- {
- typedef oln_type_of(I, point) point_type;
- std::vector<point_type> f = children[p].value();
- typename std::vector<point_type>::const_iterator pt;
- for (pt = f.begin(); pt != f.end(); pt++)
- {
- out[*pt] = v;
- marked[*pt] = true;
- set_children(marked, children, out, *pt, v);
- }
- }
-
-
- template <class I>
- std::vector<std::vector<oln_type_of(I, point)> >
- sort(const abstract::image_with_nbh<I>& input)
- {
- typedef oln_type_of(I, point) point_type;
- std::vector<std::vector<point_type> > S(256);
- oln_type_of(I, fwd_piter) p(input.size());
-
-#ifdef DEBUG
- typedef std::pair<oln_type_of(I, value), point_type> pair_t;
- std::set<pair_t,pair_cmp> sc;
-#endif // ! DEBUG
-
- for_all_p (p)
- {
- S[input[p]].push_back(p);
-#ifdef DEBUG
- sc.insert(pair_t(input[p], p));
-#endif // ! DEBUG
- }
-
-#ifdef DEBUG
- {
- unsigned l;
-
- typename std::set<pair_t,pair_cmp>::const_iterator i = sc.begin();
- typename std::vector<std::vector<point_type> >::const_iterator v;
-
- for (l = 0, v = S.begin();
- v != S.end(); v++, ++l)
- {
- for (typename std::vector<point_type>::const_iterator p = v->begin();
- p != v->end(); p++, ++i)
- {
- assert(input[*p] == l);
- assert(i->first == l);
- assert(i->second == *p);
- }
- }
- }
-#endif // ! DEBUG
-
- return S;
- }
-
- } // end of oln::morpho::misc
-
-
- template <typename I, typename E>
- struct max_tree : public canvas::tree<I, E>
- {
- typedef canvas::tree<I, E> super_type;
- typedef oln_type_of(I, point) point_type;
-
- // Attributes.
- oln_ch_concrete_type(I, bool) is_proc;
- oln_ch_concrete_type(I, bool) marked;
- oln_ch_concrete_type(I, bool) is_deleted;
- oln_ch_concrete_type(I, point_type) father;
- oln_ch_concrete_type(I, std::vector<point_type>) children;
- std::vector<std::vector<point_type> > v_root_point;
- oln_type_of(I, concrete) new_value;
-
- void impl_compute_S()
- {
- this->S = misc::sort(this->input);
- }
-
- bool condition_add_root_point(const point_type& f, const point_type& p)
- {
- if (this->input[f] == this->input[p])
- return false;
- return true;
- }
-
- void left_hand_walk(const point_type& p)
- {
- if (condition_add_root_point(p, father[p]))
- v_root_point[this->input[p]].push_back(p);
-
- std::vector<point_type> f = children[p].value();
- typename std::vector<point_type>::const_iterator pt;
- for (pt = f.begin(); pt != f.end(); pt++)
- {
- left_hand_walk(*pt);
- }
- }
-
- void impl_compute_tree()
- {
- v_root_point[this->input[this->root_point]].push_back(this->root_point);
- left_hand_walk(this->root_point);
- }
-
- void impl_set_default_output()
- {
- }
-
- void impl_set_is_processed_to_false()
- {
- oln_type_of(I, fwd_piter) p(is_proc.size());
- for_all_p (p)
- is_proc[p] = false;
- }
-
- void impl_set_is_processed(const point_type& p)
- {
- is_proc[p] = true;
- }
-
- bool impl_is_processed(const point_type& n) const
- {
- return is_proc[n];
- }
-
- void init_aux_data(const point_type& p)
- {
- this->exact().impl_init_aux_data(p);
- }
-
- const point_type impl_get_father(const point_type& p) const
- {
- return father[p].value();
- }
-
- void merge_aux_data(const point_type& r , const point_type& p)
- {
- children[p].call(&std::vector<point_type>::push_back, r);
- this->exact().impl_merge_aux_data(r,p);
- }
-
- void impl_make_set(const point_type& p)
- {
- father[p] = p;
- init_aux_data(p);
- }
-
- point_type impl_find_root(const point_type& x)
- {
- if (is_root(x))
- return x;
- return find_root(father[x]);
- }
-
- bool is_root(const point_type& x) const
- {
- return father[x] == x;
- }
-
- void impl_set_father(const point_type& r, const point_type& p)
- {
- father[r] = p;
- merge_aux_data(r,p);
- }
-
- void eligible_component(const point_type& p)
- {
- this->exact().impl_eligible_component(p);
- }
-
- void compute_image_is_deleted()
- {
- for (int i = 0; i <= 255 ;i++)
- for (typename std::vector<point_type>::const_iterator p = v_root_point[i].begin();
- p != v_root_point[i].end(); p++)
- eligible_component(*p);
- }
-
- void impl_init_processing()
- {
- level::fill(this->marked, false);
- level::fill(this->is_deleted, false);
- this->exact().impl_init_aux_processing();
- }
-
- void impl_processing()
- {
- compute_image_is_deleted();
-
- oln_type_of(I, fwd_piter) p(this->input.size());
- for_all_p (p)
- {
- if (is_deleted[p])
- this->output[p] = this->new_value[p];
- else
- this->output[p] = this->input[p];
- }
- }
-
- protected:
-
- // Ctor.
- // FIXME : will be changed
- max_tree(const abstract::image_with_nbh<I>& input) :
- super_type(input)
- {
- oln_ch_concrete_type(I, bool) tmp1(input.size());
- is_proc = tmp1;
-
- oln_ch_concrete_type(I, point_type) tmp2(input.size());
- father = tmp2;
-
- oln_ch_concrete_type(I, std::vector<point_type>) tmp3(input.size());
- children = tmp3;
-
- oln_type_of(I, concrete) tmp4(input.size());
- this->output = tmp4;
-
- std::vector<std::vector<point_type> > tmp5(256);
- v_root_point = tmp5;
-
- oln_ch_concrete_type(I, bool) tmp6(input.size());
- marked = tmp6;
-
- oln_ch_concrete_type(I, bool) tmp7(input.size());
- is_deleted = tmp7;
-
- oln_type_of(I, concrete) tmp8(input.size());
- new_value = tmp8;
- }
-
- };
-
- } // end of namespace oln::morpho
-
-} // end of namespace oln
-
-
-#endif // ! OLENA_MORPHO_MAX_TREE_HH
Index: oln/morpho/clean_astro_images.hh
--- oln/morpho/clean_astro_images.hh (revision 209)
+++ oln/morpho/clean_astro_images.hh (working copy)
@@ -1,269 +0,0 @@
-// Copyright (C) 2005 EPITA Research and Development Laboratory
-//
-// This file is part of the Olena Library. This library is free
-// software; you can redistribute it and/or modify it under the terms
-// of the GNU General Public License version 2 as published by the
-// Free Software Foundation.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this library; see the file COPYING. If not, write to
-// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
-// MA 02111-1307, USA.
-//
-// As a special exception, you may use this file as part of a free
-// software library without restriction. Specifically, if other files
-// instantiate templates or use macros or inline functions from this
-// file, or you compile this file and link it with other files to
-// produce an executable, this file does not by itself cause the
-// resulting executable to be covered by the GNU General Public
-// License. This exception does not however invalidate any other
-// reasons why the executable file might be covered by the GNU General
-// Public License.
-
-#ifndef OLENA_MORPHO_CLEAN_ASTRO_IMAGES_HH
-# define OLENA_MORPHO_CLEAN_ASTRO_IMAGES_HH
-
-# include <mlc/any.hh>
-
-# include <oln/core/box.hh>
-# include <oln/utils/record.hh>
-# include <oln/core/abstract/image_entry.hh>
-# include <oln/core/ch_value_type.hh>
-# include <oln/level/fill.hh>
-
-# include <oln/morpho/maxtree.hh>
-# include <oln/basics.hh>
-
-# include <vector>
-
-
-namespace oln {
-
- namespace morpho {
-
- namespace misc {
-
- template<typename I>
- bool have_the_center_point(const abstract::image_with_nbh<I>& children,
- const oln_type_of(I, point)& p,
- int row,
- int col)
- {
- typedef oln_type_of(I, point) point_type;
- if (((p.row() == (row / 2)) or
- (p.row() == (row - 1) / 2) or
- (p.row() == (row + 1) / 2))
- and ((p.col() == (col / 2)) or
- (p.col() == (col - 1) / 2) or
- (p.col() == (col + 1) / 2)))
- return true;
- std::vector<point_type> f = children[p].value();
- typename std::vector<point_type>::const_iterator pt;
- for (pt = f.begin(); pt != f.end(); pt++)
- {
- return have_the_center_point(children, *pt, row, col);
- }
- return false;
- }
-
-
- template <typename I, typename II>
- const oln_type_of(I, value) min_nbh(const abstract::image_with_nbh<I>& input,
- const abstract::image_with_nbh<II>& children,
- const oln_type_of(II, point)& p)
- {
- typedef oln_type_of(I, point) point_type;
- std::vector<point_type> f = children[p].value();
- oln_type_of(I, niter) n(input.exact());
- oln_type_of(I, value) min;
- typename std::vector<point_type>::const_iterator pt;
- for (pt = f.begin(); pt != f.end(); pt++)
- {
- min = input[*pt].value();
- for_all_n_of_p (n, *pt)
- {
- min = ntg::min(min, input[n].value());
- }
-
- return ntg::min(min, min_nbh(input, children, *pt));
- }
- return input[p];
- }
-
- template <typename I>
- struct find_box
- {
- typedef oln_type_of(I, point) point_type;
-
- find_box(const point_type& p) { row_min_ = p.row(); row_max_ = p.row(); col_min_ = p.col(); col_max_ = p.col(); }
- int row_min_, row_max_, col_min_, col_max_;
-
-
- void box(const abstract::image_with_nbh<I>& children,
- const oln_type_of(I, point)& p)
- {
- std::vector<point_type> f = children[p].value();
- typename std::vector<point_type>::const_iterator pt;
- for (pt = f.begin(); pt != f.end(); pt++)
- {
- if (row_min_ > pt->row())
- row_min_ = pt->row();
- if (row_max_ < pt->row())
- row_max_ = pt->row();
- if (col_min_ > pt->col())
- col_min_ = pt->col();
- if (col_max_ < pt->col())
- col_max_ = pt->col();
- box(children, *pt);
- }
- }
- };
-
-
- template <typename I>
- bool is_a_circle(const abstract::image_with_nbh<I>& children,
- const oln_type_of(I, point)& p,
- float c_a)
- {
- find_box<I> fb(p);
- fb.box(children,p);
- int w = fb.col_max_ - fb.col_min_ + 1;
- int h = fb.row_max_ - fb.row_min_ + 1;
- float theoric_area = 3.14f * ((h + w) / 4.0) * ((h + w) / 4.0);
-
-#ifdef DEBUG
- std::cout << "POINT : " << p << std::endl;
- std::cout << "col_min : " << fb.col_min_ << std::endl;
- std::cout << "col_max : " << fb.col_max_ << std::endl;
- std::cout << "row_min : " << fb.row_min_ << std::endl;
- std::cout << "row_max : " << fb.row_max_ << std::endl;
- std::cout << "theoric area : " << theoric_area << std::endl;
- std::cout << "computed area : " << c_a << std::endl;
- std::cout << "t - sqrt(c) : " << theoric_area - sqrt(c_a) << std::endl;
- std::cout << "t + sqrt(c) : " << theoric_area + sqrt(c_a) << std::endl;
- std::cout << "w : " << w << std::endl << "h : " << h << std::endl;
-#endif // ! DEBUG
- if (((theoric_area - sqrt(c_a) < c_a) &&
- (theoric_area + sqrt(c_a) > c_a)) &&
- (c_a > (0.9 * 0.75 * w * h)) &&
- (c_a < (1.1 * 0.75 * w * h)))
- return true;
- return false;
- }
-
- } // end of oln::morpho::misc
-
-
- template <typename I>
- struct clean_astro : public max_tree<I, clean_astro<I> >
- {
- typedef max_tree<I, clean_astro<I> > super_type;
- typedef oln_type_of(I, point) point_type;
-
- // Attributes.
- oln_ch_concrete_type(I, unsigned) area;
- oln_type_of(I, value) level_;
- unsigned area_;
-
-
- // specific methods
-
- void set_area(unsigned nb)
- {
- area_ = nb;
- }
-
- void set_level(unsigned nb)
- {
- level_ = nb;
- }
-
- void remove_star(const point_type& p)
- {
- this->is_deleted[p] = true;
- misc::set_children(this->marked, this->children, this->is_deleted, p, true);
- this->new_value[p] = this->input[this->father[p]].value();
- misc::set_children(this->marked,
- this->children, this->new_value, p, this->input[this->father[p]].value());
- }
-
- void remove_little_surface(const point_type& p)
- {
- this->is_deleted[p] = true;
- misc::set_children(this->marked, this->children, this->is_deleted, p, true);
- this->new_value[p] = this->input[this->father[p]].value();
- misc::set_children(this->marked,
- this->children, this->new_value, p, this->input[this->father[p]].value());
- }
-
- bool is_a_star(const point_type& p)
- {
- if (not (this->marked[p]))
- {
- if (this->area[p] >= area_)
- if (not (misc::have_the_center_point(this->children, p, this->input.size().nrows(),
- this->input.size().ncols())))
- if (misc::is_a_circle(this->children, p, this->area[p]))
- return true;
- }
- return false;
- }
-
- bool is_a_little_surface(const point_type& p)
- {
- if (this->area[p] <= 20 && this->input[p] < 150)
- return true;
- return false;
- }
-
- // fill the holes
-
- void impl_init_aux_data(const point_type& p)
- {
- this->area[p] = 1;
- }
-
- void impl_merge_aux_data(const point_type& r , const point_type& p)
- {
- this->area[p] = this->area[r].value() + this->area[p].value();
- }
-
- void impl_eligible_component(const point_type& p)
- {
- if (this->input[p].value() > this->level_)
- {
- // if (is_a_little_surface(p))
- // remove_little_surface(p);
- if (is_a_star(p))
- remove_star(p);
- }
- }
-
- void impl_init_aux_processing()
- {
- }
-
- // Ctor.
- clean_astro(const abstract::image_with_nbh<I>& input) :
- super_type(input)
- {
- oln_ch_concrete_type(I, unsigned) tmp(input.size());
- this->area = tmp;
-
- this->area_ = 0;
- this->level_ = 0;
- }
-
- };
-
- } // end of namespace oln::morpho
-
-} // end of namespace oln
-
-
-#endif // ! OLENA_MORPHO_CLEAN_ASTRO_IMAGES_HH
Index: oln/appli/astro/clean.hh
--- oln/appli/astro/clean.hh (revision 0)
+++ oln/appli/astro/clean.hh (revision 0)
@@ -0,0 +1,420 @@
+// Copyright (C) 2005 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLENA_APPLI_ASTRO_CLEAN_HH
+# define OLENA_APPLI_ASTRO_CLEAN_HH
+
+# include <mlc/any.hh>
+
+# include <oln/core/box.hh>
+# include <oln/utils/record.hh>
+# include <oln/core/abstract/image_entry.hh>
+# include <oln/core/ch_value_type.hh>
+# include <oln/level/fill.hh>
+
+# include <oln/canvas/maxtree.hh>
+# include <oln/basics.hh>
+
+# include <vector>
+
+
+
+#define get_aux_data(IT1ER, AT1T1R) this->aux_data_[IT1ER].call(&T1::AT1T1R##_get)
+#define set_aux_data(IT1ER, AT1T1R, VAL) this->aux_data_[IT1ER].call(&T1::AT1T1R##_set, VAL)
+
+
+
+namespace oln {
+
+ namespace appli {
+
+ namespace astro {
+
+ namespace misc {
+
+ template<typename I>
+ bool have_the_center_point(const abstract::image_with_nbh<I>& children,
+ const oln_type_of(I, point)& p,
+ int row,
+ int col)
+ {
+ typedef oln_type_of(I, point) point_type;
+ if (((p.row() == (row / 2)) or
+ (p.row() == (row - 1) / 2) or
+ (p.row() == (row + 1) / 2))
+ and ((p.col() == (col / 2)) or
+ (p.col() == (col - 1) / 2) or
+ (p.col() == (col + 1) / 2)))
+ return true;
+ std::vector<point_type> f = children[p].value();
+ typename std::vector<point_type>::const_iterator pt;
+
+ bool ret = false;
+ for (pt = f.begin(); pt != f.end(); pt++)
+ ret |= have_the_center_point(children, *pt, row, col);
+ return ret;
+ }
+
+
+ template <typename I, typename II>
+ const oln_type_of(I, value) min_nbh(const abstract::image_with_nbh<I>& input,
+ const abstract::image_with_nbh<II>& children,
+ const oln_type_of(II, point)& p)
+ {
+ typedef oln_type_of(I, point) point_type;
+ std::vector<point_type> f = children[p].value();
+ oln_type_of(I, niter) n(input.exact());
+ oln_type_of(I, value) min;
+ typename std::vector<point_type>::const_iterator pt;
+ for (pt = f.begin(); pt != f.end(); pt++)
+ {
+ min = input[*pt].value();
+ for_all_n_of_p (n, *pt)
+ {
+ min = ntg::min(min, input[n].value());
+ }
+
+ return ntg::min(min, min_nbh(input, children, *pt));
+ }
+ return input[p];
+ }
+
+ template <typename I>
+ struct is_a_circle_recu
+ {
+ typedef oln_type_of(I, point) point_type;
+
+ is_a_circle_recu(const point_type& p) { row_min_ = p.row(); row_max_ = p.row(); col_min_ = p.col(); col_max_ = p.col(); }
+ int row_min_, row_max_, col_min_, col_max_;
+
+
+ void box(const abstract::image_with_nbh<I>& children,
+ const oln_type_of(I, point)& p)
+ {
+ std::vector<point_type> f = children[p].value();
+ typename std::vector<point_type>::const_iterator pt;
+ for (pt = f.begin(); pt != f.end(); pt++)
+ {
+ if (row_min_ > pt->row())
+ row_min_ = pt->row();
+ if (row_max_ < pt->row())
+ row_max_ = pt->row();
+ if (col_min_ > pt->col())
+ col_min_ = pt->col();
+ if (col_max_ < pt->col())
+ col_max_ = pt->col();
+ box(children, *pt);
+ }
+ }
+ };
+
+ // by checking the geometry of the image
+ template <typename I>
+ bool is_a_circle(const abstract::image_with_nbh<I>& children,
+ const oln_type_of(I, point)& p,
+ float c_a)
+ {
+ is_a_circle_recu<I> fb(p);
+ fb.box(children,p);
+ int w = fb.col_max_ - fb.col_min_ + 1;
+ int h = fb.row_max_ - fb.row_min_ + 1;
+ float theoretic_area = 3.14f * ((h + w) / 4.0) * ((h + w) / 4.0);
+
+#ifdef DEBUG
+ std::cout << "POINT1 : " << p << std::endl;
+ std::cout << "col_min : " << fb.col_min_ << std::endl;
+ std::cout << "col_max : " << fb.col_max_ << std::endl;
+ std::cout << "row_min : " << fb.row_min_ << std::endl;
+ std::cout << "row_max : " << fb.row_max_ << std::endl;
+ std::cout << "theoretic area : " << theoretic_area << std::endl;
+ std::cout << "computed area : " << c_a << std::endl;
+ std::cout << "t - sqrt(c) : " << theoretic_area - sqrt(c_a) << std::endl;
+ std::cout << "t + sqrt(c) : " << theoretic_area + sqrt(c_a) << std::endl;
+ std::cout << "w : " << w << std::endl << "h : " << h << std::endl;
+#endif // ! DEBUG
+ // 0.75
+ if (((theoretic_area - sqrt(c_a) < c_a) &&
+ (theoretic_area + sqrt(c_a) > c_a)) &&
+ (c_a > (0.9 * 0.9 * w * h)) &&
+ (c_a < (1.1 * 0.9 * w * h)))
+ return true;
+ return false;
+ }
+
+ // by checking the geometry of the component.
+// void is_a_rectangle(const abstract::image_with_nbh<I>& children,
+// const oln_type_of(I, point)& p,
+// float min, float max)
+// {
+
+
+
+// }
+
+
+ } // end of oln::appli::astro::misc
+
+ struct my_type
+ {
+ my_type() { area_ = 0; height_ = 0; area2_= 0; int_volume_ = 0; ext_volume_ = 0;}
+
+ unsigned area_get() const { return area_; }
+ void area_set(unsigned a) { area_ = a; }
+ unsigned area_;
+
+ unsigned area2_get() const { return area2_; }
+ void area2_set(unsigned a) { area2_ = a; }
+ unsigned area2_;
+
+ unsigned height_get() const { return height_; }
+ void height_set(unsigned a) { height_ = a; }
+ unsigned height_;
+
+ unsigned ext_volume_get() const { return ext_volume_; }
+ void ext_volume_set(unsigned a) { ext_volume_ = a; }
+ unsigned ext_volume_;
+
+ unsigned int_volume_get() const { return int_volume_; }
+ void int_volume_set(unsigned a) { int_volume_ = a; }
+ unsigned int_volume_;
+ };
+
+ struct my_type2
+ {
+ my_type2() {}
+ };
+
+
+ template <typename I, typename T1 = my_type, typename T2 = my_type2>
+ struct clean : public canvas::max_tree<I, T1, T2, clean<I, T1, T2> >
+ {
+ typedef canvas::max_tree<I, T1, T2, clean<I, T1, T2> > super_type;
+ typedef oln_type_of(I, point) point_type;
+
+ // specific methods
+ void set_area(unsigned nb)
+ {
+ area_ = nb;
+ }
+
+ void set_level(unsigned nb)
+ {
+ level_ = nb;
+ }
+
+ void set_height(unsigned nb)
+ {
+ height_ = nb;
+ }
+
+ void remove_star(const point_type& p)
+ {
+ this->is_deleted[p] = true;
+ canvas::misc::set_children(this->marked, this->children, this->is_deleted, p, true);
+ this->new_value[p] = this->input[this->parent[p]].value();
+ canvas::misc::set_children(this->marked,
+ this->children, this->new_value, p, this->input[this->parent[p]].value());
+ }
+
+ // attributes to compute the output
+
+ bool level_attr(const point_type& p)
+ {
+ if (level_tag_)
+ if (not (this->input[p].value() > this->level_))
+ return false;
+ return true;
+ }
+
+ bool area_attr(const point_type& p)
+ {
+ if (area_tag_)
+ if (not (this->aux_data_[p].call(&T1::area_get) >= area_))
+ return false;
+ return true;
+ }
+
+ bool circle_attr(const point_type& p)
+ {
+ if (circle_tag_)
+ if (not (misc::is_a_circle(this->children,
+ p,
+ this->aux_data_[p].call(&T1::area_get))))
+ return false;
+ return true;
+ }
+
+ bool tour_attr(const point_type& p)
+ {
+ if (tour_tag_)
+ if (not (get_aux_data(p, int_volume) <=
+ get_aux_data(p, ext_volume) / 2))
+ return false;
+ return true;
+ }
+
+ bool center_p_attr(const point_type& p)
+ {
+ if (center_p_tag_)
+ if (misc::have_the_center_point(this->children,
+ p,
+ this->input.size().nrows(),
+ this->input.size().ncols()))
+ return false;
+ return true;
+ }
+
+ bool height_attr(const point_type& p)
+ {
+ if (height_tag_)
+ if (not (get_aux_data(p, height) > height_))
+ return false;
+ return true;
+ }
+
+ // fill the holes
+
+ void impl_init_aux_data(const point_type& p)
+ {
+ this->aux_data_[p].call(&T1::area2_set, 1);
+ }
+
+ void impl_merge_aux_data(const point_type& r , const point_type& p)
+ {
+ this->aux_data_[p].call(&T1::area2_set,
+ this->aux_data_[r].call(&T1::area2_get) +
+ this->aux_data_[p].call(&T1::area2_get));
+ }
+
+ void impl_eligible_component(const point_type& p)
+ {
+ if (not (this->marked[p]))
+ if (level_attr(p))
+ if (area_attr(p))
+ if (circle_attr(p))
+ if (tour_attr(p))
+ if (center_p_attr(p))
+ remove_star(p);
+ }
+
+
+ void impl_init_compute_attributes()
+ {
+ oln_type_of(I, fwd_piter) p(this->input.size());
+ for_all_p(p)
+ {
+ this->aux_data_[p].call(&T1::area_set, 1);
+ this->aux_data_[p].call(&T1::height_set, 0);
+ this->aux_data_[p].call(&T1::int_volume_set, 0);
+ this->aux_data_[p].call(&T1::ext_volume_set, 0);
+ }
+ }
+
+
+ // FIXME S: structure a la olena, avec iterateurs d olena
+ void impl_compute_attributes()
+ {
+ typename std::vector<std::vector<point_type> >::reverse_iterator s;
+ typename std::vector<point_type>::const_iterator p;
+ typename std::vector<point_type>::const_iterator c;
+ for (s = this->S.rbegin(); s != this->S.rend(); s++)
+ {
+ for (p = s->begin(); p != s->end(); p++)
+ {
+ std::vector<point_type> v = this->children[*p].value();
+ for (c = v.begin(); c != v.end(); c++)
+ {
+
+ set_aux_data(*p, area, get_aux_data(*p, area) + get_aux_data(*c, area));
+
+ unsigned tmp = get_aux_data(*c, height) +
+ this->input[*c].value() - this->input[*p].value();
+
+ set_aux_data(*p, height, ntg::max(tmp, get_aux_data(*p, height)));
+
+ set_aux_data(*p, int_volume, get_aux_data(*p, int_volume) +
+ get_aux_data(*c, int_volume));
+ }
+
+ unsigned tmp = this->input[*p].value() - this->input[this->parent[local_root(*p)].value()].value();
+ if (not tmp)
+ tmp = 1;
+
+ set_aux_data(*p, int_volume, get_aux_data(*p, int_volume) + (get_aux_data(*p, area) * tmp));
+ set_aux_data(*p, ext_volume, get_aux_data(*p, int_volume) +
+ (get_aux_data(*p, area) * get_aux_data(*p, height)));
+ if (not get_aux_data(*p, ext_volume))
+ set_aux_data(*p, ext_volume, 1);
+ }
+ }
+ }
+
+ void impl_init_aux_processing()
+ {
+ }
+
+ // Ctor.
+ clean(const abstract::image_with_nbh<I>& input) :
+ super_type(input)
+ {
+ area_ = 0;
+ level_ = 0;
+ height_ = 0;
+
+ level_tag_ = false;
+ area_tag_ = false;
+ tour_tag_ = false;
+ circle_tag_ = false;
+ height_tag_ = false;
+ center_p_tag_ = false;
+ }
+
+ // Attributes.
+ // tags
+ bool level_tag_;
+ bool area_tag_;
+ bool tour_tag_;
+ bool circle_tag_;
+ bool height_tag_;
+ bool center_p_tag_;
+
+ protected:
+
+ // Attributes.
+ oln_type_of(I, value) level_;
+ oln_type_of(I, value) height_;
+ unsigned area_;
+ };
+
+ } // end of namespace oln::appli::astro
+
+ } // end of namespace oln::appli
+
+} // end of namespace oln
+
+
+#endif // ! OLENA_APPLI_ASTRO_CLEAN_HH
Index: oln/canvas/maxtree.hh
--- oln/canvas/maxtree.hh (revision 0)
+++ oln/canvas/maxtree.hh (revision 0)
@@ -0,0 +1,346 @@
+// Copyright (C) 2005 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLENA_CANVAS_MAXTREE_HH
+# define OLENA_CANVAS_MAXTREE_HH
+
+# include <mlc/any.hh>
+
+# include <oln/core/box.hh>
+# include <oln/utils/record.hh>
+# include <oln/core/abstract/image_entry.hh>
+# include <oln/core/ch_value_type.hh>
+# include <oln/level/fill.hh>
+
+# include <oln/canvas/tree.hh>
+# include <oln/basics.hh>
+
+# include <cassert>
+# include <vector>
+# include <functional>
+# include <set>
+
+
+namespace oln {
+
+ namespace canvas {
+
+ namespace misc {
+
+ struct pair_cmp
+ {
+ template<typename L, typename P>
+ bool operator()(const std::pair<L,P>& lhs,
+ const std::pair<L,P>& rhs) const
+ {
+ return lhs.first < rhs.first
+ or (lhs.first == rhs.first
+ and lhs.second.fwd_less(rhs.second));
+ }
+ };
+
+ template<typename I, typename II, typename O, typename V>
+ void set_children(abstract::image_with_nbh<I>& marked,
+ const abstract::image_with_nbh<II>& children,
+ abstract::image_with_nbh<O>& out,
+ const oln_type_of(I, point)& p,
+ const V v)
+ {
+ typedef oln_type_of(I, point) point_type;
+ std::vector<point_type> f = children[p].value();
+ typename std::vector<point_type>::const_iterator pt;
+ for (pt = f.begin(); pt != f.end(); pt++)
+ {
+ out[*pt] = v;
+ marked[*pt] = true;
+ set_children(marked, children, out, *pt, v);
+ }
+ }
+
+
+ template <class I>
+ std::vector<std::vector<oln_type_of(I, point)> >
+ sort(const abstract::image_with_nbh<I>& input)
+ {
+ typedef oln_type_of(I, point) point_type;
+ std::vector<std::vector<point_type> > S(256);
+ oln_type_of(I, fwd_piter) p(input.size());
+
+#ifdef DEBUG
+ typedef std::pair<oln_type_of(I, value), point_type> pair_t;
+ std::set<pair_t,pair_cmp> sc;
+#endif // ! DEBUG
+
+ for_all_p (p)
+ {
+ S[input[p]].push_back(p);
+#ifdef DEBUG
+ sc.insert(pair_t(input[p], p));
+#endif // ! DEBUG
+ }
+
+#ifdef DEBUG
+ {
+ unsigned l;
+
+ typename std::set<pair_t,pair_cmp>::const_iterator i = sc.begin();
+ typename std::vector<std::vector<point_type> >::const_iterator v;
+
+ for (l = 0, v = S.begin();
+ v != S.end(); v++, ++l)
+ {
+ for (typename std::vector<point_type>::const_iterator p = v->begin();
+ p != v->end(); p++, ++i)
+ {
+ assert(input[*p] == l);
+ assert(i->first == l);
+ assert(i->second == *p);
+ }
+ }
+ }
+#endif // ! DEBUG
+
+ return S;
+ }
+
+ } // end of oln::canvas::misc
+
+
+ template <typename I, typename T1, typename T2, typename E>
+ struct max_tree : public tree<I, T1, T2, E>
+ {
+ public:
+
+ typedef canvas::tree<I, T1, T2, E> super_type;
+ typedef oln_type_of(I, point) point_type;
+
+ const point_type impl_parent_get(const point_type& p) const
+ {
+ return parent[p].value();
+ }
+
+// const std::vector<point_type> impl_component_get(const point_type& p) const
+// {
+// // fixme
+// }
+
+ const std::vector<point_type> impl_children_get(const point_type& p) const
+ {
+ return this->children[p].value();
+ }
+
+ const point_type impl_local_root(const point_type& p) const
+ {
+ if ((this->input[parent[p]] == this->input[p]) &&
+ not is_root(p))
+ return local_root(parent[p]);
+ return p;
+ }
+
+ void impl_compute_S()
+ {
+ this->S = misc::sort(this->input);
+ }
+
+ void left_hand_walk(const point_type& p)
+ {
+ for (oln_type_of(I, value) i = this->input[parent[p]].value();
+ i < this->input[p].value(); i++)
+ v_root_point[i + 1].push_back(p);
+
+ std::vector<point_type> f = children[p].value();
+ typename std::vector<point_type>::const_iterator pt;
+ for (pt = f.begin(); pt != f.end(); pt++)
+ left_hand_walk(*pt);
+ }
+
+ void impl_compute_tree()
+ {
+ oln_type_of(I, fwd_piter) p(this->input.size());
+ for_all_p(p)
+ {
+ if (is_root(p))
+ {
+ v_root_point[this->input[p]].push_back(p);
+ left_hand_walk(p);
+ }
+ }
+ }
+
+ void impl_set_default_output()
+ {
+ }
+
+ void impl_set_is_processed_to_false()
+ {
+ oln_type_of(I, fwd_piter) p(is_proc.size());
+ for_all_p (p)
+ is_proc[p] = false;
+ }
+
+ void impl_set_is_processed(const point_type& p)
+ {
+ is_proc[p] = true;
+ }
+
+ bool impl_is_processed(const point_type& n) const
+ {
+ return is_proc[n];
+ }
+
+ void init_aux_data(const point_type& p)
+ {
+ this->exact().impl_init_aux_data(p);
+ }
+
+ void merge_aux_data(const point_type& r , const point_type& p)
+ {
+ children[p].call(&std::vector<point_type>::push_back, r);
+ this->exact().impl_merge_aux_data(r,p);
+ }
+
+ void impl_make_set(const point_type& p)
+ {
+ parent[p] = p;
+ init_aux_data(p);
+ }
+
+ point_type impl_find_root(const point_type& x)
+ {
+ if (is_root(x))
+ return x;
+ return find_root(parent[x]);
+ }
+
+ bool is_root(const point_type& x) const
+ {
+ return parent[x] == x;
+ }
+
+ void impl_parent_set(const point_type& r, const point_type& p)
+ {
+ parent[r] = p;
+ merge_aux_data(r,p);
+ }
+
+ void eligible_component(const point_type& p)
+ {
+ this->exact().impl_eligible_component(p);
+ }
+
+ void compute_image_is_deleted()
+ {
+ for (int i = 0; i <= 255 ;i++)
+ for (typename std::vector<point_type>::const_iterator p = v_root_point[i].begin();
+ p != v_root_point[i].end(); p++)
+ eligible_component(*p);
+ }
+
+ void impl_init_processing()
+ {
+ level::fill(this->marked, false);
+ level::fill(this->is_deleted, false);
+ this->exact().impl_init_aux_processing();
+ }
+
+ void init_compute_attributes()
+ {
+ this->exact().impl_init_compute_attributes();
+ }
+
+ void compute_attributes()
+ {
+ this->exact().impl_compute_attributes();
+ }
+
+ void impl_processing()
+ {
+ init_compute_attributes();
+ compute_attributes();
+ compute_image_is_deleted();
+
+ oln_type_of(I, fwd_piter) p(this->input.size());
+ for_all_p (p)
+ {
+ if (is_deleted[p])
+ this->output[p] = this->new_value[p];
+ else
+ this->output[p] = this->input[p];
+ }
+ }
+
+ // FIXME
+ // protected:
+
+ // Attributes.
+ oln_ch_concrete_type(I, bool) is_proc;
+ oln_ch_concrete_type(I, bool) marked;
+ oln_ch_concrete_type(I, bool) is_deleted;
+ oln_ch_concrete_type(I, point_type) parent;
+ oln_ch_concrete_type(I, std::vector<point_type>) children;
+ std::vector<std::vector<point_type> > v_root_point;
+ oln_type_of(I, concrete) new_value;
+
+ protected:
+
+ // Ctor.
+ // FIXME : will be changed
+ max_tree(const abstract::image_with_nbh<I>& input) :
+ super_type(input)
+ {
+ oln_ch_concrete_type(I, bool) tmp1(input.size());
+ is_proc = tmp1;
+
+ oln_ch_concrete_type(I, point_type) tmp2(input.size());
+ parent = tmp2;
+
+ oln_ch_concrete_type(I, std::vector<point_type>) tmp3(input.size());
+ children = tmp3;
+
+ oln_type_of(I, concrete) tmp4(input.size());
+ this->output = tmp4;
+
+ std::vector<std::vector<point_type> > tmp5(256);
+ v_root_point = tmp5;
+
+ oln_ch_concrete_type(I, bool) tmp6(input.size());
+ marked = tmp6;
+
+ oln_ch_concrete_type(I, bool) tmp7(input.size());
+ is_deleted = tmp7;
+
+ oln_type_of(I, concrete) tmp8(input.size());
+ new_value = tmp8;
+ }
+
+ };
+
+ } // end of namespace oln::canvas
+
+} // end of namespace oln
+
+#endif // ! OLENA_CANVAS_MAXTREE_HH
Index: oln/canvas/tree.hh
--- oln/canvas/tree.hh (revision 0)
+++ oln/canvas/tree.hh (revision 0)
@@ -0,0 +1,215 @@
+// Copyright (C) 2005 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLENA_CANVAS_TREE_HH
+# define OLENA_CANVAS_TREE_HH
+
+# include <mlc/any.hh>
+
+# include <oln/core/box.hh>
+# include <oln/utils/record.hh>
+# include <oln/core/abstract/image_entry.hh>
+# include <oln/core/ch_value_type.hh>
+# include <oln/level/fill.hh>
+# include <oln/basics.hh>
+
+# include <vector>
+
+
+namespace oln {
+
+ namespace canvas {
+
+ template <typename I, typename T1, typename T2, typename E>
+ struct tree : public mlc::any<E>
+ {
+ typedef oln_type_of(I, point) point_type;
+
+ // interface
+ void compute_tree()
+ {
+ first_pass();
+ this->exact().impl_compute_tree();
+ }
+
+ void filter_process()
+ {
+ init_processing();
+ processing();
+ }
+
+ const point_type parent_get(const point_type& p) const
+ {
+ return this->exact().impl_parent_get(p);
+ }
+
+ // const std::vector<point_type>& component_get(const point_type& p) const
+// {
+// return this->exact().impl_component_get(p);
+// }
+
+ const std::vector<point_type> children_get(const point_type& p) const
+ {
+ return this->exact().impl_children_get(p);
+ }
+
+ const point_type local_root(const point_type& p) const
+ {
+ return this->exact().impl_local_root(p);
+ }
+
+ point_type find_root(const point_type& p)
+ {
+ return this->exact().impl_find_root(p);
+ }
+
+ oln_ch_concrete_type(I, T1)& aux_data_get()
+ {
+ return aux_data_;
+ }
+
+ // Concrete method.
+ void first_pass()
+ {
+ // init
+ compute_S();
+ set_is_processed_to_false();
+ set_default_output();
+
+ oln_type_of(I, niter) n(input);
+ typename std::vector<std::vector<point_type> >::reverse_iterator i;
+ typename std::vector<point_type>::const_iterator j;
+ for (i = S.rbegin(); i != S.rend(); i++)
+ {
+ for (j = i->begin(); j != i->end(); j++)
+ {
+ make_set(*j);
+ for_all_n_of_p (n, *j)
+ if (input.hold(n) and is_processed(n) and merge_condition(n, *j))
+ do_union(n, *j);
+ set_is_processed(*j);
+ }
+ }
+ }
+
+ bool merge_condition(const point_type& n, const point_type& p)
+ {
+ // FIXME
+ return true;
+ }
+
+ void do_union(const point_type& n, const point_type& p)
+ {
+ point_type r = find_root(n);
+ if (r != p)
+ parent_set(r, p);
+ }
+
+ // Abstract methods.
+ // ---------------------------
+
+ // init
+
+ void init_processing()
+ {
+ this->exact().impl_init_processing();
+ }
+
+ void compute_S()
+ {
+ this->exact().impl_compute_S();
+ }
+ void set_default_output()
+ {
+ this->exact().impl_set_default_output();
+ }
+
+ // about is_processed
+ void set_is_processed_to_false()
+ {
+ this->exact().impl_set_is_processed_to_false();
+ }
+ void set_is_processed(const point_type& p)
+ {
+ this->exact().impl_set_is_processed(p);
+ }
+ bool is_processed(const point_type& n) const
+ {
+ return this->exact().impl_is_processed(n);
+ }
+
+ // core
+
+ void processing()
+ {
+ this->exact().impl_processing();
+ }
+
+ void make_set(const point_type& p)
+ {
+ this->exact().impl_make_set(p);
+ }
+
+ void parent_set(const point_type& r, const point_type& p)
+ {
+ this->exact().impl_parent_set(r, p);
+ }
+
+ // Attributes.
+ box<const I> input;
+ oln_type_of(I, concrete) output;
+
+ protected:
+ std::vector<std::vector<point_type> > S;
+ oln_ch_concrete_type(I, T1) aux_data_;
+ std::vector<std::vector<T2> > aux_level_data_;
+
+
+ // Ctor.
+ tree(const abstract::image_with_nbh<I>& input) :
+ input(input),
+ S()
+ {
+ oln_ch_concrete_type(I, T1) tmp(this->input.size());
+ aux_data_ = tmp;
+ }
+
+ // Check for impls..
+ ~tree()
+ {
+ // FIXME... mlc_check_method_impl(E, void, init, , );
+ }
+
+ };
+
+
+ } // end of namespace oln::canvas
+
+} // end of namespace oln
+
+
+#endif // ! OLENA_CANVAS_TREE_HH
2
1
Re: [Olena-patches] Re: proto-1.0 202: Tree and Maxtree modifications.
by Nicolas Widynski 14 Jun '05
by Nicolas Widynski 14 Jun '05
14 Jun '05
Roland Levillain a écrit :
>>>>>>"Théo" == Thierry GERAUD <theo(a)lrde.epita.fr> writes:
>
>
> Théo> Nicolas Widynski wrote:
>
>
>>>... * oln/morpho/clean_astro_images.hh: Likewise.
>
>
> Théo> en fait, il faudrait que tout ce qui n'est pas opérateur
> Théo> "élémentaire" (généraliste) de traitement d'images, mais qui est
> Théo> *application* du traitement d'images à un domaine et un objectif
> Théo> particulier, soit dans un répertoire à part.
>
> Théo> même si la méthode est de la morpho, alors cette *méthode* (qui
> Théo> n'est pas un *opérateur*) est avant tout un /machin/ pour
> Théo> l'astro.
>
> Théo> je propose qqch comme :
>
> Théo> oln/appli/astro/clean.hh
>
> Théo> qu'en pensez-vous ?
>
> J'approuve !
>
>
Egalement !
--
Widynski Nicolas
Promo 2007
1
0
Index: ChangeLog
from Nicolas Widynski <nicolas.widynski(a)lrde.epita.fr>
* oln/morpho/tree.hh: Modifications.
* oln/morpho/maxtree.hh: Likewise.
* oln/morpho/clean_astro_images.hh: Likewise.
0 files changed
3
3
13 Jun '05
Index: ChangeLog
from Damien Thivolle <damien(a)lrde.epita.fr>
* tests/check/Makefile.runtests: Modify compilation flags.
Makefile.runtests | 2 +-
1 files changed, 1 insertion(+), 1 deletion(-)
Index: tests/check/Makefile.runtests
--- tests/check/Makefile.runtests (revision 208)
+++ tests/check/Makefile.runtests (working copy)
@@ -6,7 +6,7 @@
CPPFLAGS_RUNTESTS = $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \
-I$(top_builddir) -I$(srcdir) -I.
CXXFLAGS_RUNTESTS = $(CXXFLAGS) $(AM_CXXFLAGS)
-LDADD_RUNTESTS = ../check/libolncheck.a $(ZLIB_LDFLAGS)
+LDADD_RUNTESTS = ../check/libolncheck.a $(ZLIB_LDFLAGS) $(FITSIO2_LDFLAGS)
check-runtests:
TOP_SRCDIR=$(top_srcdir) SRCDIR=$(srcdir) \
1
0
Index: ChangeLog
from Damien Thivolle <damien(a)lrde.epita.fr>
* config/oln.m4: Add AC_WITH_CXX_FITSIO2 macro.
* configure.ac: Add FITSIO2 detection call.
config/oln.m4 | 40 ++++++++++++++++++++++++++++++++++++++++
configure.ac | 6 ++++--
2 files changed, 44 insertions(+), 2 deletions(-)
Index: config/oln.m4
--- config/oln.m4 (revision 207)
+++ config/oln.m4 (working copy)
@@ -623,6 +623,46 @@
AC_LANG_POP([C++])
])
+
+# Check for availability of libcfitsio
+
+AC_DEFUN([AC_WITH_CXX_FITSIO2],
+[dnl
+ AC_REQUIRE([AC_PROG_CXX])
+ AC_LANG_PUSH([C++])
+
+ AC_ARG_WITH([fitsio2],
+ [AC_HELP_STRING([--with-fitsio2@<:@=DIR@:>@],
+ [using fitsio2 (DIR = prefix for fitsio2 installation)])])
+ FITSIO2_CXXFLAGS=''
+ FITSIO2_LDFLAGS=''
+ if test "x$with_fitsio2" != xno; then
+ if test -n "$with_fitsio2"; then
+ FITSIO2_CXXFLAGS="-I${with_fitsio2}/include"
+ FITSIO2_LDFLAGS="-L${with_fitsio2}/lib -lm"
+ fi
+ oln_save_CXXFLAGS=$CXXFLAGS
+ oln_save_LDFLAGS=$LDFLAGS
+ CXXFLAGS="$CXXFLAGS $FITSIO2_CXXFLAGS"
+ LDFLAGS="$LDFLAGS $FITSIO2_LDFLAGS"
+ oln_have_fitsio2=no
+ AC_CHECK_HEADER([fitsio2.h],
+ [AC_CHECK_LIB([cfitsio],
+ [ffopen],
+ [oln_have_fitsio2=yes
+ FITSIO2_LDFLAGS="$FITSIO2_LDFLAGS -lcfitsio -lm"
+ AC_DEFINE([HAVE_FITSIO2], 1,
+ [Define to 1 if we can use fitsio2])])])
+ CXXFLAGS=$oln_save_CXXFLAGS
+ LDFLAGS=$oln_save_LDFLAGS
+ TOOLS_LDFLAGS="$TOOLS_LDFLAGS $FITSIO2_LDFLAGS"
+ fi
+ AC_SUBST([FITSIO2_CXXFLAGS])
+ AC_SUBST([FITSIO2_LDFLAGS])
+
+ AC_LANG_POP([C++])
+])
+
###
### Internal stuff for Olena
###
Index: configure.ac
--- configure.ac (revision 207)
+++ configure.ac (working copy)
@@ -28,6 +28,8 @@
AC_WITH_CXX_ZLIB
AC_WITH_CXX_FFTW
+AC_WITH_CXX_FITSIO2
+
# Attempt to use strict language conformance checking.
AC_CXX_FLAGS
@@ -107,8 +109,8 @@
OLN_TESTS([level])
OLN_TESTS([morpho])
OLN_TESTS([pw])
- OLN_TESTS([utils])
-
+ OLN_TESTS([utils])
+
AC_SUBST([OLN_TESTS_SUBDIRS])
], [tests])dnl End of OLN_COMPONENT([olena/tests])
1
0
J'ai toujours des problème chez moi avec le test
olena/tests/io/tests/2d : il sort avec un exit status de 1.
Apparemment, les faits suivants :
1. srcdir != builddir ; et
2. utilisation de la Zlib
ne sont pas étrangers à ce problème.
Pourriez-vous essayer de reproduire ça chez vous ? Il suffit de lancer
le test sur une copie de travail où le build n'est pas fait dans le
répertoire des sources :
cd my/working/copy/of/olena
./bootstrap.sh # Si c'est une copie neuve récupérée depuis le dépôt
mkdir _build
cd _build
../configure
make
make olena/tests/check check
make olena/tests/io check
(et vérifier que la Zlib est bien installée sur votre système, mais
c'est sans doute le cas).
Merci !
https://svn.lrde.epita.fr/svn/oln/prototypes/proto-1.0/olena
ChangeLog | 9 +++++++++
tests/check/Makefile.flags | 4 ++--
tests/io/loadsave.hh | 8 ++++----
3 files changed, 15 insertions(+), 6 deletions(-)
Index: ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Enforce tests on oln::io.
* tests/io/loadsave.hh (compare): Check whether images have data.
* tests/io/tests/2d: Aesthetic changes.
* tests/check/Makefile.flags (AM_CPPFLAGS): Look in
olena/tests/check before metalic/tests/check.
Index: tests/io/loadsave.hh
--- tests/io/loadsave.hh (revision 203)
+++ tests/io/loadsave.hh (working copy)
@@ -13,13 +13,13 @@
bool compare(const oln::abstract::image<E>& a,
const oln::abstract::image<E>& b)
{
-
- oln_type_of(E, fwd_piter) it(a.size());
-
- if (a.size().nrows() != b.size().nrows() ||
+ if (!a.exact().has_data() or !b.exact().has_data())
+ return false;
+ if (a.size().nrows() != b.size().nrows() or
a.size().ncols() != b.size().ncols())
return false;
+ oln_type_of(E, fwd_piter) it(a.size());
for_all_p(it)
{
if (a[it] != b[it])
Index: tests/check/Makefile.flags
--- tests/check/Makefile.flags (revision 203)
+++ tests/check/Makefile.flags (working copy)
@@ -4,6 +4,6 @@
$(CXXFLAGS_DEBUG) \
$(CXXFLAGS_STRICT_ERRORS) $(ZLIB_CXXFLAGS)
AM_CPPFLAGS = \
- -I$(top_srcdir)/metalic/tests/check \
- -I$(top_srcdir)/olena/tests/check
+ -I$(top_srcdir)/olena/tests/check \
+ -I$(top_srcdir)/metalic/tests/check
AM_LDFLAGS =
Index: tests/io/tests/2d
--- tests/io/tests/2d (revision 203)
+++ tests/io/tests/2d (working copy)
@@ -42,22 +42,22 @@
typedef oln::image2d<unsigned char> ima_uchar;
typedef oln::image2d<signed char> ima_schar;
- fail |= loadsave< ima_int_u8 >(rdata("16x16.pgm"), "16x16.pgm");
- fail |= loadsave< ima_bin >(rdata("16x16.pbm"), "16x16.pbm");
- fail |= loadsave< ima_rgb_8 >(rdata("16x16.ppm"), "16x16.ppm");
- fail |= loadsave< ima_int_s8 >(rdata("16x16.pgm"), "16x16.pgm");
- fail |= loadsave< ima_bool >(rdata("16x16.pbm"), "16x16.pbm");
- fail |= loadsave< ima_uchar >(rdata("16x16.pgm"), "16x16.pgm");
- fail |= loadsave< ima_schar >(rdata("16x16.pgm"), "16x16.pgm");
+ fail |= loadsave< ima_int_u8 >(rdata("16x16.pgm"), "16x16.pgm");
+ fail |= loadsave< ima_bin >(rdata("16x16.pbm"), "16x16.pbm");
+ fail |= loadsave< ima_rgb_8 >(rdata("16x16.ppm"), "16x16.ppm");
+ fail |= loadsave< ima_int_s8 >(rdata("16x16.pgm"), "16x16.pgm");
+ fail |= loadsave< ima_bool >(rdata("16x16.pbm"), "16x16.pbm");
+ fail |= loadsave< ima_uchar >(rdata("16x16.pgm"), "16x16.pgm");
+ fail |= loadsave< ima_schar >(rdata("16x16.pgm"), "16x16.pgm");
#if HAVE_ZLIB
- fail |= loadsave< ima_bin >(rdata("16x16.pbm.gz"), "16x16.pbm.gz");
- fail |= loadsave< ima_int_u8 >(rdata("16x16.pgm.gz"), "16x16.pgm.gz");
- fail |= loadsave< ima_rgb_8 >(rdata("16x16.ppm.gz"), "16x16.ppm.gz");
- fail |= loadsave< ima_int_s8 >(rdata("16x16.pgm.gz"), "16x16.pgm.gz");
- fail |= loadsave< ima_bool >(rdata("16x16.pbm.gz"), "16x16.pbm.gz");
- fail |= loadsave< ima_uchar >(rdata("16x16.pgm.gz"), "16x16.pgm.gz");
- fail |= loadsave< ima_schar >(rdata("16x16.pgm.gz"), "16x16.pgm.gz");
+ fail |= loadsave< ima_bin >(rdata("16x16.pbm.gz"), "16x16.pbm.gz");
+ fail |= loadsave< ima_int_u8 >(rdata("16x16.pgm.gz"), "16x16.pgm.gz");
+ fail |= loadsave< ima_rgb_8 >(rdata("16x16.ppm.gz"), "16x16.ppm.gz");
+ fail |= loadsave< ima_int_s8 >(rdata("16x16.pgm.gz"), "16x16.pgm.gz");
+ fail |= loadsave< ima_bool >(rdata("16x16.pbm.gz"), "16x16.pbm.gz");
+ fail |= loadsave< ima_uchar >(rdata("16x16.pgm.gz"), "16x16.pgm.gz");
+ fail |= loadsave< ima_schar >(rdata("16x16.pgm.gz"), "16x16.pgm.gz");
#endif
return fail;
1
1
https://svn.lrde.epita.fr/svn/oln/prototypes/proto-1.0
ChangeLog | 7 +++
oln/funobj/compose.hh | 93 +++++++++++++++++++++++++++++++++++++++++++++
tests/funobj/tests/compose | 14 ++++++
3 files changed, 114 insertions(+)
Index: olena/ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Add composition of two unary functors.
* oln/funobj/compose.hh: New file.
* tests/funobj/tests/compose: New test.
2005-06-09 Roland Levillain <roland(a)lrde.epita.fr>
Index: olena/tests/funobj/tests/compose
--- olena/tests/funobj/tests/compose (revision 0)
+++ olena/tests/funobj/tests/compose (revision 0)
@@ -0,0 +1,14 @@
+ // -*- C++ -*-
+#include <oln/funobj/arith.hh>
+#include <oln/funobj/compose.hh>
+
+using namespace oln;
+
+bool check()
+{
+ f_::uminus_<int> negate;
+ if (compose_uu(negate, negate)(1) != 1)
+ return true;
+
+ return false;
+}
Index: olena/oln/funobj/compose.hh
--- olena/oln/funobj/compose.hh (revision 0)
+++ olena/oln/funobj/compose.hh (revision 0)
@@ -0,0 +1,93 @@
+// Copyright (C) 2005 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLENA_CORE_FUNOBJ_CONVERSION_HH
+# define OLENA_CORE_FUNOBJ_CONVERSION_HH
+
+# include <oln/funobj/abstract/unary.hh>
+# include <oln/funobj/abstract/binary.hh>
+
+namespace oln
+{
+
+ namespace f_ {
+ template <typename F1, typename F2> struct compose_uu_;
+ } // end of namespace oln::f_
+
+ template <typename F1, typename F2>
+ struct set_super_type < f_::compose_uu_<F1, F2> > { typedef f_::abstract::unary< f_::compose_uu_<F1, F2> > ret; };
+
+ template <typename F1, typename F2>
+ struct set_props < category::fun1, f_::compose_uu_<F1, F2> >
+ {
+ typedef oln_fun1_type_of(F1, res) res_type;
+ typedef oln_fun1_type_of(F2, arg) arg_type;
+ };
+
+ namespace f_
+ {
+
+ /*! \class compose_uu_
+ **
+ ** This functor performs a composition between two unary functors.
+ */
+ template <typename F1, typename F2>
+ struct compose_uu_ : public oln_super2_of_(f_::compose_uu_<F1, F2>)
+ {
+ typedef compose_uu_<F1, F2> self_type;
+ typedef oln_fun1_type_of(self_type, res) res_type;
+ typedef oln_fun1_type_of(self_type, arg) arg_type;
+
+ compose_uu_(const F1& f1, const F2& f2) :
+ f1_(f1.exact()), f2_(f2.exact())
+ {
+ }
+
+ const res_type impl_unop(const arg_type& arg) const
+ {
+ return f1_(f2_(arg));
+ }
+
+ private:
+ const F1 f1_;
+ const F2 f2_;
+ };
+
+ } // end of namespace oln::f_
+
+ /// Compose two unary functors.
+ template<class UF1, class UF2>
+ f_::compose_uu_<UF1, UF2>
+ compose_uu(const UF1& f1, const UF2& f2)
+ {
+ return f_::compose_uu_<UF1, UF2>(f1, f2);
+ }
+
+} // end of namespace oln
+
+#endif // ! OLENA_CORE_FUNOBJ_CONVERSION_HH
+
1
0
https://svn.lrde.epita.fr/svn/oln/prototypes/proto-1.0
ChangeLog | 4 ++++
configure.ac | 1 +
2 files changed, 5 insertions(+)
Index: ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
* configure.ac (OLN_TESTS): Add funobj.
Index: configure.ac
--- configure.ac (revision 204)
+++ configure.ac (working copy)
@@ -102,6 +102,7 @@
OLN_TESTS([sanity])
OLN_TESTS([convert])
OLN_TESTS([core])
+ OLN_TESTS([funobj])
OLN_TESTS([io])
OLN_TESTS([level])
OLN_TESTS([morpho])
1
0
https://svn.lrde.epita.fr/svn/oln/prototypes/proto-1.0/olena
ChangeLog | 9 +++++++++
oln/funobj/arith.hh | 32 +++++++++++++++++++++++++-------
tests/funobj/Makefile.am | 3 +++
tests/funobj/tests/arith | 12 ++++++++++++
4 files changed, 49 insertions(+), 7 deletions(-)
Index: ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Add unary minus function object.
* oln/funobj/arith.hh (f_::uminus_): New functor.
(f_uminus): New.
* tests/funobj/tests/arith: New test.
* tests/funobj/Makefile.am: New file.
2005-06-09 Roland Levillain <roland(a)lrde.epita.fr>
Property changes on: tests/funobj
___________________________________________________________________
Name: svn:ignore
+ *Makefile
*Makefile?in
Index: tests/funobj/tests/arith
--- tests/funobj/tests/arith (revision 0)
+++ tests/funobj/tests/arith (revision 0)
@@ -0,0 +1,12 @@
+ // -*- C++ -*-
+#include <oln/funobj/arith.hh>
+
+using namespace oln;
+
+bool check()
+{
+ if (f_uminus(42) != -42)
+ return true;
+
+ return false;
+}
Index: tests/funobj/Makefile.am
--- tests/funobj/Makefile.am (revision 0)
+++ tests/funobj/Makefile.am (revision 0)
@@ -0,0 +1,3 @@
+## Process this file through Automake to create Makefile.in -*- Makefile -*-
+
+include ../check/Makefile.runtests
Index: oln/funobj/arith.hh
--- oln/funobj/arith.hh (revision 204)
+++ oln/funobj/arith.hh (working copy)
@@ -86,15 +86,14 @@
oln_decl_funobj_binary(div, /);
oln_decl_funobj_binary(mod, %);
- // FIXME: min, max?
- // FIXME: uminus?
-
-
-
namespace f_ {
+ template <typename T> struct uminus_;
template <typename T> struct min_;
template <typename T> struct max_;
- }
+ } // end of namespace oln::f_
+
+ template <typename T>
+ struct set_super_type < f_::uminus_<T> > { typedef f_::abstract::unary< f_::uminus_<T> > ret; };
template <typename T>
struct set_super_type < f_::min_<T> > { typedef f_::abstract::binary< f_::min_<T> > ret; };
@@ -103,6 +102,13 @@
struct set_super_type < f_::max_<T> > { typedef f_::abstract::binary< f_::max_<T> > ret; };
template <typename T>
+ struct set_props < category::fun1, f_::uminus_<T> >
+ {
+ typedef T res_type;
+ typedef T arg_type;
+ };
+
+ template <typename T>
struct set_props < category::fun2, f_::min_<T> >
{
typedef T res_type;
@@ -122,6 +128,15 @@
{
template <typename T>
+ struct uminus_ : public oln_super_of_(f_::uminus_<T>)
+ {
+ const T impl_unop(const T& arg) const
+ {
+ return -arg;
+ }
+ };
+
+ template <typename T>
struct min_ : public oln_super_of_(f_::min_<T>)
{
const T impl_binop(const T& left, const T& right) const
@@ -139,7 +154,10 @@
}
};
- }
+ } // end of namespace oln::f_
+
+ typedef f_::unary_meta<f_::uminus_> f_uminus_type;
+ static f_uminus_type f_uminus;
typedef f_::binary1_meta<f_::min_> f_min_type;
static f_min_type f_min;
1
0
Index: ChangeLog
from Nicolas Widynski <nicolas.widynski(a)lrde.epita.fr>
* olena/oln/morpho/tree.hh: tree (canva).
* olena/oln/morpho/maxtree.hh: creation of maxtree.
* olena/oln/morpho/clean_astro_images.hh: maxtree utilisation's sample.
clean_astro_images.hh | 268 ++++++++++++++++++++++++++++++++++++++++++
maxtree.hh | 315 ++++++++++++++++++++++++++++++++++++++++++++++++++
tree.hh | 196 +++++++++++++++++++++++++++++++
3 files changed, 779 insertions(+)
Index: olena/oln/morpho/tree.hh
--- olena/oln/morpho/tree.hh (revision 0)
+++ olena/oln/morpho/tree.hh (revision 0)
@@ -0,0 +1,196 @@
+// Copyright (C) 2001-2005 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLENA_MORPHO_CANVAS_TREE_HH
+# define OLENA_MORPHO_CANVAS_TREE_HH
+
+# include <mlc/any.hh>
+
+# include <oln/core/box.hh>
+# include <oln/utils/record.hh>
+# include <oln/core/abstract/image_entry.hh>
+# include <oln/core/ch_value_type.hh>
+# include <oln/level/fill.hh>
+# include <oln/basics.hh>
+
+# include <vector>
+
+// just for test
+#include <ntg/real/int_u.hh>
+
+namespace oln {
+
+ namespace morpho {
+
+ namespace canvas {
+
+
+ template <typename I, typename E>
+ struct tree : public mlc::any<E>
+ {
+ typedef oln_type_of(I, point) point_type;
+
+ // Attribute.
+ box<const I> input;
+ oln_type_of(I, concrete) output;
+ std::vector<std::vector<point_type> > S;
+ point_type root_point;
+
+ void run_compute_tree()
+ {
+ first_pass();
+ compute_tree();
+ }
+
+ void run_compute_output()
+ {
+ init_traitement();
+ traitement();
+ }
+
+ // Concrete method.
+ void first_pass()
+ {
+ oln_type_of(I, niter) n(input);
+
+ // init
+ compute_S();
+ set_is_processed_to_false();
+ set_default_output();
+
+ typename std::vector<std::vector<point_type> >::reverse_iterator i;
+ typename std::vector<point_type>::const_iterator j;
+ for (i = S.rbegin(); i != S.rend(); i++)
+ {
+ for (j = i->begin(); j != i->end(); j++)
+ {
+ make_set(*j);
+ for_all_n_of_p (n, *j)
+ if (input.hold(n) and is_processed(n))
+ do_union(n, *j);
+ set_is_processed(*j);
+ }
+ }
+ root_point = *j;
+ }
+
+ void do_union(const point_type& n, const point_type& p)
+ {
+ point_type r = find_root(n);
+ if (r != p)
+ set_father(r, p);
+ }
+
+ // Abstract methods.
+ // ---------------------------
+
+ // init
+
+ void init_traitement()
+ {
+ this->exact().impl_init_traitement();
+ }
+
+ void compute_S()
+ {
+ this->exact().impl_compute_S();
+ }
+ void set_default_output()
+ {
+ this->exact().impl_set_default_output();
+ }
+
+ // about is_processed
+ void set_is_processed_to_false()
+ {
+ this->exact().impl_set_is_processed_to_false();
+ }
+ void set_is_processed(const point_type& p)
+ {
+ this->exact().impl_set_is_processed(p);
+ }
+ bool is_processed(const point_type& n) const
+ {
+ return this->exact().impl_is_processed(n);
+ }
+
+ const point_type get_father(const point_type& p) const
+ {
+ return this->exact().impl_get_father(p);
+ }
+
+ // core
+
+ void compute_tree()
+ {
+ this->exact().impl_compute_tree();
+ }
+
+ void traitement()
+ {
+ this->exact().impl_traitement();
+ }
+
+ void make_set(const point_type& p)
+ {
+ this->exact().impl_make_set(p);
+ }
+ point_type find_root(const point_type& x)
+ {
+ return this->exact().impl_find_root(x);
+ }
+ void set_father(const point_type& r, const point_type& p)
+ {
+ this->exact().impl_set_father(r, p);
+ }
+
+ protected:
+
+ // Ctor.
+ tree(const abstract::image_with_nbh<I>& input) :
+ input(input),
+ S()
+ {
+ }
+
+ // Check for impls..
+ ~tree()
+ {
+ // FIXME... mlc_check_method_impl(E, void, init, , );
+ }
+
+ };
+
+
+ } // end of namespace oln::morpho::canvas
+
+ } // end of namespace oln::morpho
+
+} // end of namespace oln
+
+
+#endif // ! OLENA_MORPHO_CANVAS_TREE_HH
Index: olena/oln/morpho/maxtree.hh
--- olena/oln/morpho/maxtree.hh (revision 0)
+++ olena/oln/morpho/maxtree.hh (revision 0)
@@ -0,0 +1,315 @@
+// Copyright (C) 2001-2005 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLENA_MORPHO_MAX_TREE_HH
+# define OLENA_MORPHO_MAX_TREE_HH
+
+# include <mlc/any.hh>
+
+# include <oln/core/box.hh>
+# include <oln/utils/record.hh>
+# include <oln/core/abstract/image_entry.hh>
+# include <oln/core/ch_value_type.hh>
+# include <oln/level/fill.hh>
+
+# include <oln/morpho/tree.hh>
+# include <oln/basics.hh>
+
+# include <cassert>
+# include <vector>
+# include <functional>
+# include <set>
+
+// just for test
+#include <ntg/real/int_u.hh>
+
+
+namespace oln {
+
+ namespace morpho {
+
+ namespace misc {
+
+ struct pair_cmp
+ {
+ template<typename L, typename P>
+ bool operator()(const std::pair<L,P>& lhs,
+ const std::pair<L,P>& rhs) const
+ {
+ return lhs.first < rhs.first
+ or (lhs.first == rhs.first
+ and lhs.second.fwd_less(rhs.second));
+ }
+ };
+
+ template<typename I, typename II, typename O, typename V>
+ void set_children(abstract::image_with_nbh<I>& marked,
+ const abstract::image_with_nbh<II>& children,
+ abstract::image_with_nbh<O>& out,
+ const oln_type_of(I, point)& p,
+ const V v)
+ {
+ typedef oln_type_of(I, point) point_type;
+ std::vector<point_type> f = children[p].value();
+ typename std::vector<point_type>::const_iterator pt;
+ for (pt = f.begin(); pt != f.end(); pt++)
+ {
+ out[*pt] = v;
+ marked[*pt] = true;
+ set_children(marked, children, out, *pt, v);
+ }
+ }
+
+
+ template <class I>
+ std::vector<std::vector<oln_type_of(I, point)> >
+ sort(const abstract::image_with_nbh<I>& input)
+ {
+ typedef oln_type_of(I, point) point_type;
+ std::vector<std::vector<point_type> > S(256);
+ oln_type_of(I, fwd_piter) p(input.size());
+
+#ifdef DEBUG
+ typedef std::pair<oln_type_of(I, value), point_type> pair_t;
+ std::set<pair_t,pair_cmp> sc;
+#endif // ! DEBUG
+
+ for_all_p (p)
+ {
+ S[input[p]].push_back(p);
+#ifdef DEBUG
+ sc.insert(pair_t(input[p], p));
+#endif // ! DEBUG
+ }
+
+#ifdef DEBUG
+ {
+ unsigned l;
+
+ typename std::set<pair_t,pair_cmp>::const_iterator i = sc.begin();
+ typename std::vector<std::vector<point_type> >::const_iterator v;
+
+ for (l = 0, v = S.begin();
+ v != S.end(); v++, ++l)
+ {
+ for (typename std::vector<point_type>::const_iterator p = v->begin();
+ p != v->end(); p++, ++i)
+ {
+ assert(input[*p] == l);
+ assert(i->first == l);
+ assert(i->second == *p);
+ }
+ }
+ }
+#endif // ! DEBUG
+
+ return S;
+ }
+
+ } // end of oln::morpho::misc
+
+
+ template <typename I, typename E>
+ struct max_tree : public canvas::tree<I, E>
+ {
+ typedef canvas::tree<I, E> super_type;
+ typedef oln_type_of(I, point) point_type;
+
+ // Attributes.
+ oln_ch_concrete_type(I, bool) is_proc;
+ oln_ch_concrete_type(I, bool) marked;
+ oln_ch_concrete_type(I, bool) is_deleted;
+ oln_ch_concrete_type(I, point_type) father;
+ oln_ch_concrete_type(I, std::vector<point_type>) children;
+ std::vector<std::vector<point_type> > v_root_point;
+ oln_type_of(I, concrete) new_value;
+
+ void impl_compute_S()
+ {
+ this->S = misc::sort(this->input);
+ }
+
+ bool condition_add_root_point(const point_type& f, const point_type& p)
+ {
+ if (this->input[f] == this->input[p])
+ return false;
+ return true;
+ }
+
+ void left_hand_walk(const point_type& p)
+ {
+ if (condition_add_root_point(p, father[p]))
+ v_root_point[this->input[p]].push_back(p);
+
+ std::vector<point_type> f = children[p].value();
+ typename std::vector<point_type>::const_iterator pt;
+ for (pt = f.begin(); pt != f.end(); pt++)
+ {
+ left_hand_walk(*pt);
+ }
+ }
+
+ void impl_compute_tree()
+ {
+ v_root_point[this->input[this->root_point]].push_back(this->root_point);
+ left_hand_walk(this->root_point);
+ }
+
+ void impl_set_default_output()
+ {
+ }
+
+ void impl_set_is_processed_to_false()
+ {
+ oln_type_of(I, fwd_piter) p(is_proc.size());
+ for_all_p (p)
+ is_proc[p] = false;
+ }
+
+ void impl_set_is_processed(const point_type& p)
+ {
+ is_proc[p] = true;
+ }
+
+ bool impl_is_processed(const point_type& n) const
+ {
+ return is_proc[n];
+ }
+
+ void init_aux_data(const point_type& p)
+ {
+ this->exact().impl_init_aux_data(p);
+ }
+
+ const point_type impl_get_father(const point_type& p) const
+ {
+ return father[p].value();
+ }
+
+ void merge_aux_data(const point_type& r , const point_type& p)
+ {
+ children[p].call(&std::vector<point_type>::push_back, r);
+ this->exact().impl_merge_aux_data(r,p);
+ }
+
+ void impl_make_set(const point_type& p)
+ {
+ father[p] = p;
+ init_aux_data(p);
+ }
+
+ point_type impl_find_root(const point_type& x)
+ {
+ if (is_root(x))
+ return x;
+ return find_root(father[x]);
+ }
+
+ bool is_root(const point_type& x) const
+ {
+ return father[x] == x;
+ }
+
+ void impl_set_father(const point_type& r, const point_type& p)
+ {
+ father[r] = p;
+ merge_aux_data(r,p);
+ }
+
+ void eligible_component(const point_type& p)
+ {
+ this->exact().impl_eligible_component(p);
+ }
+
+ void compute_image_is_deleted()
+ {
+ for (int i = 0; i <= 255 ;i++)
+ for (typename std::vector<point_type>::const_iterator p = v_root_point[i].begin();
+ p != v_root_point[i].end(); p++)
+ eligible_component(*p);
+ }
+
+ void impl_init_traitement()
+ {
+ level::fill(this->marked, false);
+ level::fill(this->is_deleted, false);
+ this->exact().impl_init_aux_traitement();
+ }
+
+ void impl_traitement()
+ {
+ compute_image_is_deleted();
+
+ oln_type_of(I, fwd_piter) p(this->input.size());
+ for_all_p (p)
+ {
+ if (is_deleted[p])
+ this->output[p] = this->new_value[p];
+ else
+ this->output[p] = this->input[p];
+ }
+ }
+
+ protected:
+
+ // Ctor.
+ max_tree(const abstract::image_with_nbh<I>& input) :
+ super_type(input)
+ {
+ oln_ch_concrete_type(I, bool) tmp1(input.size());
+ is_proc = tmp1;
+
+ oln_ch_concrete_type(I, point_type) tmp2(input.size());
+ father = tmp2;
+
+ oln_ch_concrete_type(I, std::vector<point_type>) tmp3(input.size());
+ children = tmp3;
+
+ oln_type_of(I, concrete) tmp4(input.size());
+ this->output = tmp4;
+
+ std::vector<std::vector<point_type> > tmp5(256);
+ v_root_point = tmp5;
+
+ oln_ch_concrete_type(I, bool) tmp6(input.size());
+ marked = tmp6;
+
+ oln_ch_concrete_type(I, bool) tmp7(input.size());
+ is_deleted = tmp7;
+
+ oln_type_of(I, concrete) tmp8(input.size());
+ new_value = tmp8;
+ }
+
+ };
+
+ } // end of namespace oln::morpho
+
+} // end of namespace oln
+
+
+#endif // ! OLENA_MORPHO_MAX_TREE_HH
Index: olena/oln/morpho/clean_astro_images.hh
--- olena/oln/morpho/clean_astro_images.hh (revision 0)
+++ olena/oln/morpho/clean_astro_images.hh (revision 0)
@@ -0,0 +1,268 @@
+// Copyright (C) 2001-2005 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLENA_MORPHO_CLEAN_ASTRO_IMAGES_HH
+# define OLENA_MORPHO_CLEAN_ASTRO_IMAGES_HH
+
+# include <mlc/any.hh>
+
+# include <oln/core/box.hh>
+# include <oln/utils/record.hh>
+# include <oln/core/abstract/image_entry.hh>
+# include <oln/core/ch_value_type.hh>
+# include <oln/level/fill.hh>
+
+# include <oln/morpho/maxtree.hh>
+# include <oln/basics.hh>
+
+# include <vector>
+
+// just for test
+#include <ntg/real/int_u.hh>
+
+
+namespace oln {
+
+ namespace morpho {
+
+ namespace misc {
+
+ template<typename I>
+ bool have_the_center_point(const abstract::image_with_nbh<I>& children,
+ const oln_type_of(I, point)& p,
+ int row,
+ int col)
+ {
+ typedef oln_type_of(I, point) point_type;
+ if (((p.row() == (row / 2)) or (p.row() == (row - 1) / 2) or (p.row() == (row + 1) / 2))
+ and ((p.col() == (col / 2)) or (p.col() == (col - 1) / 2) or (p.col() == (col + 1) / 2)))
+ return true;
+ std::vector<point_type> f = children[p].value();
+ typename std::vector<point_type>::const_iterator pt;
+ for (pt = f.begin(); pt != f.end(); pt++)
+ {
+ return have_the_center_point(children, *pt, row, col);
+ }
+ return false;
+ }
+
+
+ template <typename I, typename II>
+ const oln_type_of(I, value) min_nbh(const abstract::image_with_nbh<I>& input,
+ const abstract::image_with_nbh<II>& children,
+ const oln_type_of(II, point)& p)
+ {
+ typedef oln_type_of(I, point) point_type;
+ std::vector<point_type> f = children[p].value();
+ oln_type_of(I, niter) n(input.exact());
+ oln_type_of(I, value) min;
+ typename std::vector<point_type>::const_iterator pt;
+ for (pt = f.begin(); pt != f.end(); pt++)
+ {
+ min = input[*pt].value();
+ for_all_n_of_p (n, *pt)
+ {
+ min = ntg::min(min, input[n].value());
+ }
+
+ return ntg::min(min, min_nbh(input, children, *pt));
+ }
+ return input[p];
+ }
+
+ template <typename I>
+ struct find_box
+ {
+ typedef oln_type_of(I, point) point_type;
+
+ find_box(const point_type& p) { row_min_ = p.row(); row_max_ = p.row(); col_min_ = p.col(); col_max_ = p.col(); }
+ int row_min_, row_max_, col_min_, col_max_;
+
+
+ void box(const abstract::image_with_nbh<I>& children,
+ const oln_type_of(I, point)& p)
+ {
+ std::vector<point_type> f = children[p].value();
+ typename std::vector<point_type>::const_iterator pt;
+ for (pt = f.begin(); pt != f.end(); pt++)
+ {
+ if (row_min_ > pt->row())
+ row_min_ = pt->row();
+ if (row_max_ < pt->row())
+ row_max_ = pt->row();
+ if (col_min_ > pt->col())
+ col_min_ = pt->col();
+ if (col_max_ < pt->col())
+ col_max_ = pt->col();
+ box(children, *pt);
+ }
+ }
+ };
+
+
+ template <typename I>
+ bool is_a_circle(const abstract::image_with_nbh<I>& children,
+ const oln_type_of(I, point)& p,
+ float c_a)
+ {
+ find_box<I> fb(p);
+ fb.box(children,p);
+ int w = fb.col_max_ - fb.col_min_ + 1;
+ int h = fb.row_max_ - fb.row_min_ + 1;
+ float theoric_area = 3.14f * ((h + w) / 4.0) * ((h + w) / 4.0);
+
+#ifdef DEBUG
+ std::cout << "POINT : " << p << std::endl;
+ std::cout << "col_min : " << fb.col_min_ << std::endl;
+ std::cout << "col_max : " << fb.col_max_ << std::endl;
+ std::cout << "row_min : " << fb.row_min_ << std::endl;
+ std::cout << "row_max : " << fb.row_max_ << std::endl;
+ std::cout << "theoric area : " << theoric_area << std::endl;
+ std::cout << "computed area : " << c_a << std::endl;
+ std::cout << "t - sqrt(c) : " << theoric_area - sqrt(c_a) << std::endl;
+ std::cout << "t + sqrt(c) : " << theoric_area + sqrt(c_a) << std::endl;
+ std::cout << "w : " << w << std::endl << "h : " << h << std::endl;
+#endif // ! DEBUG
+ if (((theoric_area - sqrt(c_a) < c_a) &&
+ (theoric_area + sqrt(c_a) > c_a)) &&
+ (c_a > (0.9 * 0.75 * w * h)) &&
+ (c_a < (1.1 * 0.75 * w * h)))
+ return true;
+ return false;
+ }
+
+ } // end of oln::morpho::misc
+
+
+ template <typename I>
+ struct clean_astro : public max_tree<I, clean_astro<I> >
+ {
+ typedef max_tree<I, clean_astro<I> > super_type;
+ typedef oln_type_of(I, point) point_type;
+
+ // Attributes.
+ oln_ch_concrete_type(I, unsigned) area;
+ oln_type_of(I, value) level_;
+ unsigned area_;
+
+
+ // specific methods
+
+ void set_area(unsigned nb)
+ {
+ area_ = nb;
+ }
+
+ void set_level(unsigned nb)
+ {
+ level_ = nb;
+ }
+
+ void remove_star(const point_type& p)
+ {
+ this->is_deleted[p] = true;
+ misc::set_children(this->marked, this->children, this->is_deleted, p, true);
+ this->new_value[p] = this->input[this->father[p]].value();
+ misc::set_children(this->marked,
+ this->children, this->new_value, p, this->input[this->father[p]].value());
+ }
+
+ void remove_little_surface(const point_type& p)
+ {
+ this->is_deleted[p] = true;
+ misc::set_children(this->marked, this->children, this->is_deleted, p, true);
+ this->new_value[p] = this->input[this->father[p]].value();
+ misc::set_children(this->marked,
+ this->children, this->new_value, p, this->input[this->father[p]].value());
+ }
+
+ bool is_a_star(const point_type& p)
+ {
+ if (not (this->marked[p]))
+ {
+ if (this->area[p] >= area_)
+ if (not (misc::have_the_center_point(this->children, p, this->input.size().nrows(),
+ this->input.size().ncols())))
+ if (misc::is_a_circle(this->children, p, this->area[p]))
+ return true;
+ }
+ return false;
+ }
+
+ bool is_a_little_surface(const point_type& p)
+ {
+ if (this->area[p] <= 20 && this->input[p] < 150)
+ return true;
+ return false;
+ }
+
+ // fill the holes
+
+ void impl_init_aux_data(const point_type& p)
+ {
+ this->area[p] = 1;
+ }
+
+ void impl_merge_aux_data(const point_type& r , const point_type& p)
+ {
+ this->area[p] = this->area[r].value() + this->area[p].value();
+ }
+
+ void impl_eligible_component(const point_type& p)
+ {
+ if (this->input[p].value() > this->level_)
+ {
+ // if (is_a_little_surface(p))
+ // remove_little_surface(p);
+ if (is_a_star(p))
+ remove_star(p);
+ }
+ }
+
+ void impl_init_aux_traitement()
+ {
+ }
+
+ // Ctor.
+ clean_astro(const abstract::image_with_nbh<I>& input) :
+ super_type(input)
+ {
+ oln_ch_concrete_type(I, unsigned) tmp(input.size());
+ this->area = tmp;
+
+ this->area_ = 0;
+ this->level_ = 0;
+ }
+
+ };
+
+ } // end of namespace oln::morpho
+
+} // end of namespace oln
+
+
+#endif // ! OLENA_MORPHO_CLEAN_ASTRO_IMAGES_HH
5
5