Index: olena/ChangeLog
from Giovanni Palma <giovanni(a)lrde.epita.fr>
* oln/morpho/attributes.hh: Add file. Add new atributes.
* oln/morpho/attribute_union_find.hh: Correct genericity errors.
* oln/morpho/attribute_closing_opening.hh: Add some prototypes for
attribute opening/closing.
* oln/utils/histogram.hh: Add comments.
Index: olena/oln/utils/histogram.hh
--- olena/oln/utils/histogram.hh Fri, 06 Feb 2004 15:26:24 +0100 van-vl_n
(oln/10_histogram. 1.6.1.14.1.3 644)
+++ olena/oln/utils/histogram.hh Fri, 06 Feb 2004 15:55:50 +0100 palma_g
(oln/10_histogram. 1.6.1.14.1.3 644)
@@ -80,7 +80,7 @@
return s;
}
};
- }
+ } // end of namespace internal
namespace abstract
{
@@ -119,7 +119,7 @@
return this->exact().init_impl(img.exact());
}
};
- }
+ } // end of namespace abstract
template<typename T,
typename CPT = unsigned,
Index: olena/oln/morpho/attribute_closing_opening.hh
--- olena/oln/morpho/attribute_closing_opening.hh Thu, 07 Aug 2003 02:08:21 +0200 david
(oln/q/49_attribute_ 1.10 644)
+++ olena/oln/morpho/attribute_closing_opening.hh Fri, 06 Feb 2004 14:56:42 +0100 palma_g
(oln/q/49_attribute_ 1.10 640)
@@ -34,6 +34,76 @@
namespace morpho {
namespace tarjan {
+ namespace internal {
+
+ // attribute closing
+ template<class I, class N, class A>
+ oln_concrete_type(I)
+ attr_closing_(const abstract::non_vectorial_image<I>& input,
+ const abstract::neighborhood<N>& Ng,
+ const attr_lambda_type(A) lambda)
+ {
+ typedef tarjan::tarjan_set<oln_concrete_type(I), A > tarjan_set_type;
+ tarjan_set_type area_closing(input.exact(), attr_env_type(A)());
+ return area_closing.get_comptute(lambda, Ng, true);
+ }
+
+ // attribute opening
+ template<class I, class N, class A>
+ oln_concrete_type(I)
+ attr_opening_(const abstract::non_vectorial_image<I>& input,
+ const abstract::neighborhood<N>& Ng,
+ const attr_lambda_type(A) lambda)
+ {
+ typedef tarjan::tarjan_set<oln_concrete_type(I), A > tarjan_set_type;
+ tarjan_set_type area_opening(input.exact(), attr_env_type(A)());
+ return area_opening.get_comptute(lambda , Ng, false);
+ }
+
+ } // !internal
+
+// macro for some attribute opening/closing declarations
+# define xxx_opening_decl(T) \
+ template<class I, class N> \
+ oln_concrete_type(I) \
+ T##_opening(const abstract::non_vectorial_image<I>& input, \
+ const abstract::neighborhood<N>& Ng, \
+ const attr_lambda_type(T##_type<unsigned>) lambda) \
+ { \
+ return internal::attr_opening_<I, N, T##_type<unsigned> >(input, Ng,
lambda); \
+ }
+
+# define xxx_closing_decl(T) \
+ template<class I, class N> \
+ oln_concrete_type(I) \
+ T##_closing(const abstract::non_vectorial_image<I>& input, \
+ const abstract::neighborhood<N>& Ng, \
+ const attr_lambda_type(T##_type<unsigned>) lambda) \
+ { \
+ return internal::attr_closing_<I, N, T##_type<unsigned> >(input, Ng,
lambda); \
+ }
+
+
+ // same as previous, but for attribute based on image types
+# define xxx_opening_im_decl(T) \
+ template<class I, class N> \
+ oln_concrete_type(I) \
+ T##_opening(const abstract::non_vectorial_image<I>& input, \
+ const abstract::neighborhood<N>& Ng, \
+ const attr_lambda_type(T##_type<I>) lambda) \
+ { \
+ return internal::attr_opening_<I, N, T##_type<I> >(input, Ng, lambda); \
+ }
+
+# define xxx_closing_im_decl(T) \
+ template<class I, class N> \
+ oln_concrete_type(I) \
+ T##_closing(const abstract::non_vectorial_image<I>& input, \
+ const abstract::neighborhood<N>& Ng, \
+ const attr_lambda_type(T##_type<I>) lambda) \
+ { \
+ return internal::attr_closing_<I, N, T##_type<I> >(input, Ng, lambda); \
+ }
/*=processing area_closing
* ns: morpho
@@ -53,19 +123,7 @@
* exi: lena256.pgm
* exo: out.pgm
=*/
- template<class I, class N>
- oln_concrete_type(I)
- area_closing(const abstract::non_vectorial_image<I>& input,
- const abstract::neighborhood<N>& Ng,
- const unsigned int area)
- {
- typedef T_attribute<unsigned int> area_type;
-
- typedef tarjan::tarjan_set<oln_concrete_type(I), area_type > tarjan_set_type;
- tarjan_set_type area_closing(input.exact());
- return area_closing.get_comptute(area_type(area) , Ng, true);
- }
-
+ xxx_closing_decl(area)
/*=processing area_opening
* ns: morpho
@@ -85,19 +143,22 @@
* exi: lena256.pgm
* exo: out.pgm
=*/
- template<class I, class N>
- oln_concrete_type(I)
- area_opening(const abstract::non_vectorial_image<I>& input,
- const abstract::neighborhood<N>& Ng,
- const unsigned int area)
- {
- typedef T_attribute<unsigned int> area_type;
-
- typedef tarjan::tarjan_set<oln_concrete_type(I), T_attribute<unsigned int> >
tarjan_set_type;
- tarjan_set_type area_closing(input.exact());
- return area_closing.get_comptute(area_type(area) , Ng, false);
- }
+ xxx_opening_decl(area)
+ xxx_opening_decl(volume)
+ xxx_closing_decl(volume)
+ xxx_opening_decl(height)
+ xxx_closing_decl(height)
+ xxx_opening_decl(maxvalue)
+ xxx_closing_decl(maxvalue)
+ xxx_opening_decl(minvalue)
+ xxx_closing_decl(minvalue)
+ xxx_opening_im_decl(disk)
+ xxx_closing_im_decl(disk)
+ xxx_opening_im_decl(dist)
+ xxx_closing_im_decl(dist)
+ xxx_closing_im_decl(square)
+ xxx_opening_im_decl(square)
}
}
}
Index: olena/oln/morpho/attribute_union_find.hh
--- olena/oln/morpho/attribute_union_find.hh Thu, 07 Aug 2003 02:08:21 +0200 david
(oln/q/50_attribute_ 1.8 644)
+++ olena/oln/morpho/attribute_union_find.hh Fri, 06 Feb 2004 15:54:51 +0100 palma_g
(oln/q/50_attribute_ 1.8 640)
@@ -33,49 +33,8 @@
#include <ntg/bin.hh>
#include <vector>
-
-namespace oln {
- namespace morpho {
- namespace tarjan {
- namespace internal_tarjan_ {
-
- template <class P, class V>
- bool
- vec_sort_max(const std::pair<P, V>& l,
- const std::pair<P, V>& r)
- {
- if (r.second != l.second)
- return r.second < l.second;
-
- const unsigned dim = 2;
- for (unsigned i = 0; i< dim; ++i)
- if (l.first.nth(i) != r.first.nth(i))
- return l.first.nth(i) < r.first.nth(i);
- // it means l == r
- return true;
- }
-
-
- template <class P, class V>
- bool
- vec_sort_min(const std::pair<P, V>& l,
- const std::pair<P, V>& r)
- {
- if (r.second != l.second)
- return r.second > l.second;
-
- const unsigned dim = P::dim;
- for (unsigned i = 0; i< dim; ++i)
- if (l.first.nth(i) != r.first.nth(i))
- return l.first.nth(i) < r.first.nth(i);
- // it means l == r
- return true;
- }
-
- }
- }
- }
-}
+#include <oln/utils/histogram.hh>
+#include <oln/morpho/attributes.hh>
namespace oln {
namespace morpho {
@@ -114,13 +73,14 @@
};
- template<class T, class ATTRIBUTE>
+ template<class T, class ATTRIBUTE, class Env = NullEnv>
struct tarjan_set
{
typedef oln_point_type(T) point_type;
typedef oln_value_type(T) data_type;
typedef oln_concrete_type(T) image_type;
-
+ typedef typename ATTRIBUTE::lambda_type lambda_type;
+ typedef Env env_type;
// ACTIVE and INACTIVE are defined with a hook to be static
// and initialized ionly once.
@@ -157,9 +117,10 @@
return tmp.elt;
}
- tarjan_set(const image_type& ima) : input_(ima),
+ tarjan_set(const image_type& ima, const env_type &env) : input_(ima),
parent_(ima.size()),
- aux_data_(ima.size())
+ aux_data_(ima.size()),
+ env_(env)
{
level::fill(parent_, INACTIVE());
}
@@ -169,7 +130,7 @@
{
precondition(parent_[x] == INACTIVE());
parent_[x] = ACTIVE();
- aux_data_[x] = 1;
+ aux_data_[x] = ATTRIBUTE(input_, x, env_);
}
point_type
@@ -199,7 +160,7 @@
if (r != p)
if (criterion(r,p))
{
- aux_data_[p] = aux_data_[p] + aux_data_[r];
+ aux_data_[p] += aux_data_[r];
parent_[r] = p;
}
else
@@ -212,39 +173,30 @@
// an opening otherwise.
template<class N>
image_type
- get_comptute(const ATTRIBUTE & lambda,
+ get_comptute(const lambda_type & lambda,
const abstract::neighborhood<N>& Ng,
const bool closing)
{
- typedef std::pair<point_type, data_type> pixel_type;
lambda_ = lambda;
- std::vector<pixel_type> I;
- I.reserve(input_.npoints());
+ std::vector<point_type> I(input_.npoints());
- {
- // sort pixels with respect to their level and scanning order
- oln_iter_type(T) p(input_);
- for_all(p)
- I.push_back(pixel_type(p.cur(), input_[p]));
if (closing)
- sort(I.begin(), I.end(), internal_tarjan_::vec_sort_min<point_type,
data_type> );
+ oln::utils::distrib_sort(input_, I);
else
- sort(I.begin(), I.end(), internal_tarjan_::vec_sort_max<point_type,
data_type> );
- }
+ oln::utils::distrib_sort_inv(input_, I);
- // Image to know which pixels have been processed
- typename mute<T, ntg::bin>::ret is_proc(input_.size());
- level::fill(is_proc, false);
+ level::fill(aux_data_, ntg_sup_val(lambda_type));
+ aux_data_.border_adapt_assign(Ng.delta(), ntg_sup_val(lambda_type));
// We are ready to perform stuff
for (unsigned int p = 0; p < I.size(); ++p)
{
- point_type p_p = I[p].first;
+ point_type p_p = I[p];
make_set(p_p);
- is_proc[p_p] = true;
oln_neighb_type(N) Q_prime(Ng, p_p);
- for_all (Q_prime) if (input_.hold(Q_prime)) if (is_proc[Q_prime] == true)
+ for_all (Q_prime)
+ if (is_proc(Q_prime))
uni(Q_prime.cur(), p_p);
}
@@ -252,9 +204,9 @@
image_type output(input_.size());
for (int p = I.size() - 1; p >= 0; --p)
{
- point_type p_p = I[p].first;
+ point_type p_p = I[p];
if ((parent_[p_p] == ACTIVE()) || (parent_[p_p] == INACTIVE()))
- output[p_p] = I[p].second;
+ output[p_p] = input_[p_p];
else
output[p_p] = output[parent_[p_p]];
// this code is equivalent to
@@ -264,11 +216,24 @@
return output;
}
+ protected:
+ // tells if a point has been proceded
+ bool is_proc(const point_type &p) const
+ {
+ //FIXME: odd way to call !=, but it is to help the compiler
+ //to find the good one when ATTRIBUTE is templeted by types
+ //in other namepaces.
+
+ // return aux_data_[p] != ntg_max_val(lambda_type);
+ return aux_data_[p].operator!=(ntg_sup_val(lambda_type));
+ };
+
+
const image_type & input_;
typename mute<T, point_type>::ret parent_;
typename mute<T, ATTRIBUTE>::ret aux_data_;
- ATTRIBUTE lambda_;
-
+ lambda_type lambda_;
+ const env_type env_;
};
}
}
Index: olena/oln/morpho/attributes.hh
--- olena/oln/morpho/attributes.hh Fri, 06 Feb 2004 16:01:51 +0100 palma_g ()
+++ olena/oln/morpho/attributes.hh Fri, 06 Feb 2004 16:01:43 +0100 palma_g
(oln/j/45_attributes 644)
@@ -0,0 +1,847 @@
+// Copyright (C) 2001, 2002, 2003 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 ATTRIBUTES_HH
+# define ATTRIBUTES_HH
+// some usefull macros
+
+// those macros should be moved into mlc
+# define oln_exact_vt_type(T, Exact) typename mlc::exact_vt<T, Exact>::ret
+# define oln_2_exact_vt_type(self, T, Exact) typename mlc::exact_vt<self<T,
Exact>, Exact>::ret
+# define dispatch(Fun) return exact().Fun##_impl
+
+// attribute dedicated macros
+# define attr_lambda_type(T) typename attr_traits<T>::lambda_type
+# define attr_env_type(T) typename attr_traits<T>::env_type
+# define attr_value_type(T) typename attr_traits<T>::value_type
+
+# define attr_type_decl(slef_type) \
+ typedef oln_exact_vt_type(self_type, Exact) exact_type; \
+ typedef attr_value_type(exact_type) value_type; \
+ typedef attr_env_type(exact_type) env_type; \
+ typedef attr_lambda_type(exact_type) lambda_type
+
+
+
+// misc
+namespace my {
+
+ int diffabs(int v1, int v2)
+ {
+ return v1 > v2 ? v1 - v2 : v2 - v1;
+ }
+
+ template <class T>
+ T max(T v1, T v2)
+ {
+ return v1 > v2 ? v1 : v2;
+ }
+
+ template <class T>
+ T min(T v1, T v2)
+ {
+ return v1 < v2 ? v1 : v2;
+ }
+
+} // end of namespace my
+
+namespace oln {
+ namespace morpho {
+ namespace tarjan {
+ // environment herarchy
+ // not used yet
+ template <class Exact>
+ struct env: public mlc_hierarchy::any<Exact>
+ {
+ };
+
+ // this env is an empty one
+ struct NullEnv: public env<NullEnv>
+ {
+ };
+
+
+ // the traits fwd declaration
+ template <class T>
+ struct attr_traits;
+
+
+ // the attributes hierarchy
+
+ /*------------*
+ | attribute |
+ *-----------*/
+ template <class Exact>
+ class attribute: public mlc_hierarchy::any<Exact>
+ {
+ public:
+ typedef attribute<Exact> self_type;
+ attr_type_decl(self_type);
+
+ void operator+=(const exact_type& rhs)
+ {
+ dispatch(pe)(rhs);
+ };
+
+ void operator=(lambda_type lambda)
+ {
+ dispatch(equal)(lambda);
+ };
+
+ bool operator<(const lambda_type& lambda) const
+ {
+ dispatch(less)(lambda);
+ };
+
+ bool operator!=(const lambda_type& lambda) const
+ {
+ dispatch(ne)(lambda);
+ };
+
+ protected:
+ attribute() {};
+
+ };
+
+ /*-----------*
+ | area |
+ *-----------*/
+
+ template <class T, class Exact = mlc::final>
+ class area_type:
+ public attribute<oln_2_exact_vt_type(area_type, T, Exact)>
+ {
+ public:
+ typedef area_type<T, Exact> self_type;
+ attr_type_decl(self_type);
+
+ area_type()
+ {
+ };
+
+ area_type(const lambda_type &lambda): value_(lambda)
+ {
+ };
+
+ template <class I>
+ area_type(const abstract::image<I>&,
+ const oln_point_type(I)&,
+ const env_type&):
+ value_(1)
+ {
+ };
+
+ void pe_impl(const area_type& rhs)
+ {
+ value_ += rhs.value_;
+ };
+
+ void equal_impl(lambda_type lambda)
+ {
+ value_ = lambda;
+ };
+
+ bool less_impl(const lambda_type& lambda) const
+ {
+ return value_ < lambda;
+ };
+
+ bool ne_impl(const lambda_type& lambda) const
+ {
+ return lambda != value_;
+ };
+
+ protected:
+ value_type value_;
+ // const client_data_type& client_data;
+ // FIXME: client_data is usefull when attribute is computed from other data
+ };
+
+
+ /*-----------*
+ | volume |
+ *-----------*/
+
+ template <class T, class Exact = mlc::final>
+ class volume_type:
+ public attribute<oln_2_exact_vt_type(volume_type, T, Exact)>
+ {
+ public:
+ typedef volume_type<T, Exact> self_type;
+ attr_type_decl(self_type);
+
+ // Ctors
+ volume_type()
+ {
+ };
+
+
+ volume_type(const lambda_type &lambda): value_(lambda)
+ {
+ };
+
+ template <class I>
+ volume_type(const abstract::image<I>& input,
+ const oln_point_type(I)& p,
+ const env_type &) :
+ reflevel_(input[p]),
+ area_(1),
+ value_(1)
+ {
+ };
+ // interface part
+ const value_type &getValue() const
+ {
+ dispatch(getValue)();
+ };
+
+ const value_type &getReflevel() const
+ {
+ dispatch(getReflevel)();
+ };
+
+ const value_type &getArea() const
+ {
+ dispatch(getArea)();
+ };
+
+ // impl part
+ const value_type &getValue_impl() const
+ {
+ return value_;
+ };
+
+ const value_type &getReflevel_impl() const
+ {
+ return reflevel_;
+ };
+
+ const value_type &getArea_impl() const
+ {
+ return area_;
+ };
+
+ void equal_impl(lambda_type lambda)
+ {
+ value_ = lambda;
+ };
+
+ void pe_impl(const volume_type& rhs)
+ {
+ value_ += rhs.getValue() + area_ * my::diffabs(reflevel_, rhs.getReflevel());
+ area_ += rhs.getArea();
+ };
+
+ bool less_impl(const lambda_type& lambda) const
+ {
+ return value_ < lambda;
+ };
+
+ bool ne_impl(const lambda_type& lambda) const
+ {
+ return lambda != value_;
+ };
+
+ protected:
+ value_type reflevel_;
+ value_type area_;
+ value_type value_;
+ };
+
+ /*-----------*
+ | height |
+ *-----------*/
+
+ template <class T, class Exact = mlc::final>
+ class height_type:
+ public attribute<oln_2_exact_vt_type(height_type, T, Exact)>
+ {
+ public:
+ typedef height_type<T, Exact> self_type;
+ attr_type_decl(self_type);
+
+ height_type()
+ {
+ };
+
+ height_type(const lambda_type &lambda): value_(lambda)
+ {
+ };
+
+ template <class I>
+ height_type(const abstract::image<I>& input,
+ const oln_point_type(I)& p,
+ const env_type&):
+ reflevel_(input[p]),
+ value_(0)
+ {
+ };
+
+ const value_type &getReflevel() const
+ {
+ dispatch(getReflevel)();
+ };
+
+ // impl part
+ const value_type &getReflevel_impl() const
+ {
+ return reflevel_;
+ };
+
+ void equal_impl(lambda_type lambda)
+ {
+ value_ = lambda;
+ };
+
+ void pe_impl(const height_type& rhs)
+ {
+ value_ = my::diffabs(reflevel_, rhs.getReflevel());
+ };
+
+ bool less_impl(const lambda_type& lambda) const
+ {
+ return value_ < lambda;
+ };
+
+ bool ne_impl(const lambda_type& lambda) const
+ {
+ return lambda != value_;
+ };
+
+ protected:
+ value_type reflevel_;
+ value_type value_;
+ };
+
+
+ /*-----------*
+ | maxvalue |
+ *-----------*/
+
+ template <class T, class Exact = mlc::final>
+ class maxvalue_type:
+ public attribute<oln_2_exact_vt_type(maxvalue_type, T, Exact)>
+ {
+ public:
+ typedef maxvalue_type<T, Exact> self_type;
+ attr_type_decl(self_type);
+
+ maxvalue_type()
+ {
+ };
+
+ maxvalue_type(const lambda_type &lambda): value_(lambda)
+ {
+ };
+
+ template <class I>
+ maxvalue_type(const abstract::image<I>& input,
+ const oln_point_type(I)& p,
+ const env_type &):
+ value_(input[p])
+ {
+ };
+
+ const value_type &getValue() const
+ {
+ dispatch(getValue)();
+ };
+
+ const value_type &getValue_impl() const
+ {
+ return value_;
+ };
+
+ void pe_impl(const maxvalue_type& rhs)
+ {
+ value_ = my::max(value_, rhs.getValue());
+ };
+
+ bool less_impl(const lambda_type& lambda) const
+ {
+ return value_ < lambda;
+ };
+
+ bool ne_impl(const lambda_type& lambda) const
+ {
+ return lambda != value_;
+ };
+
+ protected:
+ value_type value_;
+ };
+
+
+ /*-----------*
+ | minvalue |
+ *-----------*/
+
+ template <class T, class Exact = mlc::final>
+ class minvalue_type:
+ public attribute<oln_2_exact_vt_type(minvalue_type, T, Exact)>
+ {
+ public:
+ typedef minvalue_type<T, Exact> self_type;
+ attr_type_decl(self_type);
+
+ minvalue_type()
+ {
+ };
+
+ minvalue_type(const lambda_type &lambda): value_(lambda)
+ {
+ };
+
+ template <class I>
+ minvalue_type(const abstract::image<I>& input,
+ const oln_point_type(I)& p,
+ const env_type &) :
+ value_(input[p])
+ {
+ };
+
+ const value_type &getValue() const
+ {
+ dispatch(getValue)();
+ };
+
+ const value_type &getValue_impl() const
+ {
+ return value_;
+ };
+
+ void pe_impl(const minvalue_type& rhs)
+ {
+ value_ = my::min(value_, rhs.getValue());
+ };
+
+ bool less_impl(const lambda_type& lambda) const
+ {
+ return value_ < lambda;
+ };
+
+ bool ne_impl(const lambda_type& lambda) const
+ {
+ return lambda != value_;
+ };
+
+ protected:
+ value_type value_;
+ };
+
+
+ /*-----------*
+ | disk |
+ *-----------*/
+
+ template <class I, class Exact = mlc::final>
+ class disk_type:
+ public attribute<oln_2_exact_vt_type(disk_type, I, Exact)>
+ {
+ public:
+ typedef disk_type<I, Exact> self_type;
+ attr_type_decl(self_type);
+ typedef abstract::image<mlc_exact_type(I)> im_type;
+ typedef oln_point_type(im_type) point_type;
+ typedef oln_dpoint_type(im_type) dpoint_type;
+ typedef std::vector<point_type> pts_type;
+ typedef typename pts_type::const_iterator cst_iter_type;
+
+ disk_type()
+ {
+ };
+
+ disk_type(const lambda_type &lambda): value_(lambda), pts_()
+ {
+ };
+
+ disk_type(const im_type&, const point_type& p, const env_type &) :
+ value_(1), pts_()
+ {
+ pts_.push_back(p);
+ };
+
+ const pts_type &getPts() const
+ {
+ dispatch(getPts)();
+ };
+
+ // impl
+
+ const pts_type &getPts_impl() const
+ {
+ return pts_;
+ };
+
+ void pe_impl(const disk_type& rhs)
+ {
+ std::copy(rhs.getPts().begin(), rhs.getPts().end(), std::back_inserter(pts_));
+ value_ = 0;
+ for (cst_iter_type p1 = pts_.begin(); p1 != pts_.end(); ++p1)
+ for (cst_iter_type p2 = pts_.begin(); p2 != pts_.end(); ++p2)
+ {
+ unsigned d = 0;
+ dpoint_type p = *p1 - *p2;
+ for (int i = 0; i < point_traits<point_type>::dim; ++i)
+ d += p.nth(i) * p.nth(i);
+ if (d > value_)
+ value_ = d;
+ }
+ value_ /= 2;
+ };
+
+ bool less_impl(const lambda_type& lambda) const
+ {
+ return value_ < lambda;
+ };
+
+ bool ne_impl(const lambda_type& lambda) const
+ {
+ return lambda != value_;
+ };
+
+ protected:
+ value_type value_;
+ pts_type pts_;
+ };
+
+
+
+ /*-----------*
+ | dist |
+ *-----------*/
+
+ template <class I, class Exact = mlc::final>
+ class dist_type:
+ public attribute<oln_2_exact_vt_type(dist_type, I, Exact)>
+ {
+ public:
+ typedef dist_type<I, Exact> self_type;
+ attr_type_decl(self_type);
+ typedef abstract::image<mlc_exact_type(I)> im_type;
+ typedef oln_point_type(im_type) point_type;
+ typedef oln_dpoint_type(im_type) dpoint_type;
+
+// typedef float value_type;
+// typedef value_type lambda_type;
+
+ dist_type()
+ {
+ };
+
+ dist_type(const im_type&,
+ const point_type& p,
+ const env_type &) :
+ value_(0),
+ center_(p)
+ {
+ };
+
+ dist_type(const lambda_type lambda): value_(lambda)
+ {
+ };
+
+ const point_type &getCenter() const
+ {
+ dispatch(getCenter)();
+ };
+
+ // impl
+ const point_type &getCenter_impl() const
+ {
+ return center_;
+ };
+
+ void pe_impl(const dist_type& rhs)
+ {
+ dpoint_type p = center_ - rhs.getCenter();
+
+ value_ = 0;
+ for (int i = 0; i < point_traits<point_type>::dim; ++i)
+ value_ += p.nth(i) * p.nth(i);
+ value_ = sqrt(value_);
+ };
+
+ bool less_impl(const lambda_type& lambda) const
+ {
+ return value_ < lambda;
+ };
+
+ bool ne_impl(const lambda_type &lambda) const
+ {
+ return value_ != lambda;
+ };
+
+ protected:
+ value_type value_;
+ point_type center_;
+
+ };
+
+
+
+ /*-----------*
+ | square |
+ *-----------*/
+
+ template <class I, class Exact = mlc::final>
+ class square_type:
+ public attribute<oln_2_exact_vt_type(square_type, I, Exact)>
+ {
+ public:
+ typedef square_type<I, Exact> self_type;
+ attr_type_decl(self_type);
+ typedef abstract::image<mlc_exact_type(I)> im_type;
+ typedef oln_point_type(im_type) point_type;
+ typedef oln_dpoint_type(im_type) dpoint_type;
+
+// typedef unsigned value_type;
+// typedef value_type lambda_type;
+
+ square_type()
+ {
+ }
+
+ square_type(const lambda_type &lambda) : value_(lambda)
+ {
+ };
+
+ square_type(const im_type&,
+ const point_type& p,
+ const env_type &) :
+ value_(0)
+ {
+ min_row_ = max_row_ = p.row();
+ min_col_ = max_col_ = p.col();
+ }
+
+ int getMinRow() const
+ {
+ dispatch(getMinRow)();
+ };
+
+ int getMaxRow() const
+ {
+ dispatch(getMaxRow)();
+ };
+
+ int getMaxCol() const
+ {
+ dispatch(getMaxCol)();
+ };
+
+ int getMinCol() const
+ {
+ dispatch(getMinCol)();
+ };
+
+ // impl
+ int getMinRow_impl() const
+ {
+ return min_row_;
+ };
+
+ int getMaxRow_impl() const
+ {
+ return max_row_;
+ };
+
+ int getMaxCol_impl() const
+ {
+ return max_col_;
+ };
+
+ int getMinCol_impl() const
+ {
+ return min_col_;
+ };
+
+ void pe_impl(const square_type& rhs)
+ {
+ min_row_ = my::min(min_row_, rhs.getMinRow());
+ min_col_ = my::min(min_col_, rhs.getMinCol());
+ max_row_ = my::max(max_row_, rhs.getMaxRow());
+ max_col_ = my::max(max_col_, rhs.getMaxCol());
+ value_ = my::max(max_row_ - min_row_, max_col_ - min_col_);
+ }
+
+ bool less_impl(const lambda_type& lambda) const
+ {
+ return value_ < lambda;
+ }
+
+ bool ne_impl(const lambda_type &lambda) const
+ {
+ return value_ != lambda;
+ };
+
+ protected:
+ value_type value_;
+ int min_row_;
+ int max_row_;
+ int min_col_;
+ int max_col_;
+ };
+
+
+
+// /*-----------*
+// | rectangle |
+// *-----------*/
+// template <class I, class Exact = mlc::final>
+// struct rectangle_type
+// {
+// typedef unsigned value_type;
+// typedef std::pair<value_type,value_type> lambda_type;
+
+// value_type drow, dcol;
+// int min_row, max_row, min_col, max_col;
+
+// rectangle_type()
+// {
+// }
+
+// template <class T>
+// rectangle_type(const image2d<T>&, const point2d& p) :
+// drow(0),
+// dcol(0)
+// {
+// min_row = max_row = p.row();
+// min_col = max_col = p.col();
+// }
+
+// void operator+=(const rectangle_type& rhs)
+// {
+// min_row = my::min(min_row, rhs.min_row);
+// min_col = my::min(min_col, rhs.min_col);
+// max_row = my::max(max_row, rhs.max_row);
+// max_col = my::max(max_col, rhs.max_col);
+// drow = max_row - min_row;
+// dcol = max_col - min_col;
+// }
+
+// bool operator>=(const lambda_type& lambda) const
+// {
+// return drow >= lambda.first || dcol >= lambda.second;
+// }
+// };
+
+
+// traits specialisations
+
+
+ // volume traits
+ template <class T, class Exact>
+ struct attr_traits<volume_type<T, Exact> >
+ {
+ typedef T value_type;
+ typedef value_type lambda_type;
+ typedef NullEnv env_type;
+ };
+
+ // volume traits
+ template <class T, class Exact>
+ struct attr_traits<height_type<T, Exact> >
+ {
+ typedef T value_type;
+ typedef value_type lambda_type;
+ typedef NullEnv env_type;
+ };
+
+ // area traits
+ template <class T, class Exact>
+ struct attr_traits<area_type<T, Exact> >
+ {
+ typedef T value_type;
+ typedef value_type lambda_type;
+ typedef NullEnv env_type;
+ };
+
+ // maxvalue traits
+ template <class T, class Exact>
+ struct attr_traits<maxvalue_type<T, Exact> >
+ {
+ typedef T value_type;
+ typedef value_type lambda_type;
+ typedef NullEnv env_type;
+ };
+
+ // minvalue traits
+ template <class T, class Exact>
+ struct attr_traits<minvalue_type<T, Exact> >
+ {
+ typedef T value_type;
+ typedef value_type lambda_type;
+ typedef NullEnv env_type;
+ };
+
+ // disk traits
+ template <class I, class Exact>
+ struct attr_traits<disk_type<I, Exact> >
+ {
+ typedef unsigned value_type;
+ typedef value_type lambda_type;
+ typedef NullEnv env_type;
+ };
+
+ // dist traits
+ template <class I, class Exact>
+ struct attr_traits<dist_type<I, Exact> >
+ {
+ typedef float value_type;
+ typedef value_type lambda_type;
+ typedef NullEnv env_type;
+ };
+
+ // square traits
+ template <class I, class Exact>
+ struct attr_traits<square_type<I, Exact> >
+ {
+ typedef unsigned value_type;
+ typedef value_type lambda_type;
+ typedef NullEnv env_type;
+ };
+
+// // rectangle traits
+// tempalte <class Exact>
+// typedef unsigned value_type;
+// typedef std::pair<value_type,value_type> lambda_type;
+
+ }
+ }
+}
+
+
+/*-----------*
+ | diamond |
+ *-----------*/
+
+// FIXME: to be written...
+
+
+#endif // ndef ATTRIBUTES_HH
+
--
Giovanni Palma
EPITA - promo 2005 - membre d'EpX - LRDE
Mob. : +33 (0)6 60 97 31 74