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