2005-04-27 Thierry GERAUD <theo(a)tegucigalpa.lrde.epita.fr>
* oln/funobj/accum.hh (min_accumulator_init): New class.
* oln/core/abstract/niter.hh (for_all_n_of_p): Fix bug.
(set_type<image,I,niter_type>): New type deduction.
(set_type<image,I,fwd_niter_type>): Likewise.
(set_type<image,I,bkd_niter_type>): Likewise.
* oln/core/abstract/neighborhood.hh
(iter, fwd_iter, bkd_iter): New properties.
* oln/core/gen/regular_neighborhood.hh: Update.
* oln/core/abstract/window.hh (operator-): New.
* oln/core/pw/image.hh (grid_type): New property.
(concrete_type): Likewise.
Index: oln/convert/nbh_to_se.hh
===================================================================
--- oln/convert/nbh_to_se.hh (revision 166)
+++ oln/convert/nbh_to_se.hh (working copy)
@@ -1,82 +0,0 @@
-// Copyright (C) 2002, 2004, 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_CONVERT_NBH_TO_SE_HH
-# define OLENA_CONVERT_NBH_TO_SE_HH
-
-# include <oln/core/abstract/neighborhood.hh>
-# include <oln/core/2d/dpoint2d.hh>
-
-
-namespace oln {
- namespace convert {
- /*! Convert a neighborhood to a window.
- **
- ** \see nbh_to_cse
- */
- template<class N>
- oln_nbh_type_of(N, window)
- nbh_to_se(const N& nbh) // FIXME: UGLY
oln::abstract::neighborhood<N>& nbh)
- {
- oln_nbh_type_of(N, window) output;
-
- for (unsigned i = 0; i < nbh.card(); i++)
- output.add(nbh.dp(i));
- return output;
- }
-
- void dpoint_zero(dpoint2d& dp)
- {
- dp.row() = 0;
- dp.col() = 0;
- }
-
- /*! Convert a neighborhood to a window and add the center.
- **
- ** \see nbh_to_cs
- */
- template<class N>
- oln_nbh_type_of(N, window)
- nbh_to_cse(const N& nbh) // FIXME: UGLY oln::abstract::neighborhood<N>&
nbh)
- {
- oln_nbh_type_of(N, window) output;
-
- for (unsigned i = 0; i < nbh.card(); i++)
- output.add(nbh.dp(i));
-
- oln_nbh_type_of(N, dpoint) zero;
- dpoint_zero(zero);
- output.add(zero);
- return output;
- }
-
-
- } // convert
-} // oln
-
-
-#endif // OLENA_CONVERT_NBH_TO_SE_HH
Index: oln/funobj/accum.hh
===================================================================
--- oln/funobj/accum.hh (revision 166)
+++ oln/funobj/accum.hh (working copy)
@@ -55,7 +55,7 @@
acc_ = t;
return;
}
- if (t > acc_)
+ if (acc_ < t)
acc_ = t;
}
@@ -73,6 +73,10 @@
};
+ // FIXME: ... Max accumulator with initialization value.
+
+
+
/// Min accumulator.
template <class T>
@@ -109,6 +113,35 @@
};
+ /// Min accumulator with initialization value.
+
+ template <class T>
+ struct min_accumulator_init
+ {
+
+ template <typename U>
+ min_accumulator_init(const U& init) :
+ acc_(init)
+ {}
+
+ void operator()(T t)
+ {
+ if (t < acc_)
+ acc_ = t;
+ }
+
+ operator T() const
+ {
+ return acc_;
+ }
+
+ private:
+
+ T acc_;
+
+ };
+
+
} // end of namespace oln::funobj
} // end of namespace oln
Index: oln/core/abstract/niter.hh
===================================================================
--- oln/core/abstract/niter.hh (revision 166)
+++ oln/core/abstract/niter.hh (working copy)
@@ -1,4 +1,4 @@
-// Copyright (C) 2001, 2002, 2003, 2004, 2005 EPITA Research and Development Laboratory
+// 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
@@ -29,14 +29,14 @@
# define OLENA_CORE_ABSTRACT_NITER_HH
# include <mlc/contract.hh>
-# include <oln/core/typedefs.hh>
+# include <oln/core/abstract/image.hh>
# include <oln/core/abstract/iter.hh>
# include <oln/core/abstract/point.hh>
# include <oln/core/abstract/neighborhood.hh>
# define for_all_n_of_p(n, p) \
- for(n.ensure_is_niter(), n.center_at(p), n.start(); n.is_valid(); n.next())
+ for(n.ensure_is_niter(), n.start_at_p(p); n.is_valid(); n.next())
# define for_all_remaining_n(n) \
for(n.ensure_is_niter(); n.is_valid(); n.next())
@@ -146,6 +146,32 @@
} // end of namespace oln::abstract
+
+
+ // From image type to niters.
+
+ template <typename I>
+ struct set_type < category::image, I, internal::typedef_::niter_type >
+ {
+ typedef oln_type_of(I, neighb) neighb_t;
+ typedef oln_nbh_type_of(neighb_t, iter) ret;
+ };
+
+ template <typename I>
+ struct set_type < category::image, I, internal::typedef_::fwd_niter_type >
+ {
+ typedef oln_type_of(I, neighb) neighb_t;
+ typedef oln_nbh_type_of(neighb_t, fwd_iter) ret;
+ };
+
+ template <typename I>
+ struct set_type < category::image, I, internal::typedef_::bkd_niter_type >
+ {
+ typedef oln_type_of(I, neighb) neighb_t;
+ typedef oln_nbh_type_of(neighb_t, bkd_iter) ret;
+ };
+
+
} // end of namespace oln
Index: oln/core/abstract/neighborhood.hh
===================================================================
--- oln/core/abstract/neighborhood.hh (revision 166)
+++ oln/core/abstract/neighborhood.hh (working copy)
@@ -50,6 +50,10 @@
typedef mlc::undefined_type dpoint_type;
typedef mlc::undefined_type size_type;
typedef mlc::undefined_type window_type;
+
+ typedef mlc::undefined_type iter_type;
+ typedef mlc::undefined_type fwd_iter_type;
+ typedef mlc::undefined_type bkd_iter_type;
};
@@ -61,14 +65,20 @@
typedef oln_nbh_type_of(N, dpoint) dpoint_type;
typedef oln_nbh_type_of(N, size) size_type;
typedef oln_nbh_type_of(N, window) window_type;
+ typedef oln_nbh_type_of(N, iter) iter_type;
+ typedef oln_nbh_type_of(N, fwd_iter) fwd_iter_type;
+ typedef oln_nbh_type_of(N, bkd_iter) bkd_iter_type;
static void echo(std::ostream& ostr)
{
ostr << "props_of( oln::category::neighborhood, " <<
mlc_to_string(N) << " ) =" << std::endl
<< "{" << std::endl
- << "\t dpoint_type = " << mlc_to_string(dpoint_type) <<
std::endl
- << "\t size_type = " << mlc_to_string(size_type) <<
std::endl
- << "\t window_type = " << mlc_to_string(window_type) <<
std::endl
+ << "\t dpoint_type = " << mlc_to_string(dpoint_type)
<< std::endl
+ << "\t size_type = " << mlc_to_string(size_type)
<< std::endl
+ << "\t window_type = " << mlc_to_string(window_type)
<< std::endl
+ << "\t iter_type = " << mlc_to_string(iter_type)
<< std::endl
+ << "\t fwd_iter_type = " << mlc_to_string(fwd_iter_type)
<< std::endl
+ << "\t bkd_iter_type = " << mlc_to_string(bkd_iter_type)
<< std::endl
<< "}" << std::endl;
}
@@ -77,6 +87,9 @@
mlc::is_ok< dpoint_type >::ensure();
mlc::is_ok< size_type >::ensure();
mlc::is_ok< window_type >::ensure();
+ mlc::is_ok< iter_type >::ensure();
+ mlc::is_ok< fwd_iter_type >::ensure();
+ mlc::is_ok< bkd_iter_type >::ensure();
}
};
Index: oln/core/abstract/window.hh
===================================================================
--- oln/core/abstract/window.hh (revision 166)
+++ oln/core/abstract/window.hh (working copy)
@@ -28,6 +28,7 @@
#ifndef OLENA_CORE_ABSTRACT_WINDOW_HH
# define OLENA_CORE_ABSTRACT_WINDOW_HH
+# include <mlc/contract.hh>
# include <oln/core/typedefs.hh>
@@ -96,6 +97,13 @@
template<class W>
struct window : public mlc::any<W>
{
+ public:
+
+ const W operator-() const
+ {
+ return this->exact().impl_op_minus();
+ }
+
protected:
window()
@@ -104,6 +112,7 @@
~window()
{
get_props<category::window, W>::ensure();
+ mlc_check_method_impl(W, const W, op_minus, , const);
}
};
Index: oln/core/pw/image.hh
===================================================================
--- oln/core/pw/image.hh (revision 166)
+++ oln/core/pw/image.hh (working copy)
@@ -36,6 +36,8 @@
# include <oln/core/pw/abstract/function.hh>
// FIXME: remove
+# include <oln/core/2d/grid2d.hh>
+# include <oln/core/2d/image2d.hh>
# include <oln/core/2d/fwd_piter2d.hh>
# include <oln/core/2d/bkd_piter2d.hh>
@@ -130,12 +132,14 @@
typedef mlc::no_type delegated_type;
- // FIXME: AWFUL we do not know if it is 2d...
+ // FIXME: EXTREMELY AWFUL!!! we do not know if it is 2d...
typedef is_a<abstract::image2d> image_dimension_type;
+ typedef grid2d grid_type;
typedef fwd_piter2d piter_type;
typedef fwd_piter2d fwd_piter_type;
typedef bkd_piter2d bkd_piter_type;
+ typedef image2d<value_type> concrete_type;
};
Index: oln/core/gen/regular_neighborhood.hh
===================================================================
--- oln/core/gen/regular_neighborhood.hh (revision 166)
+++ oln/core/gen/regular_neighborhood.hh (working copy)
@@ -36,6 +36,8 @@
// fwd decl
template <typename G> class regular_neighborhood;
+ template <typename G> class regular_fwd_niter;
+ template <typename G> class regular_bkd_niter;
// super_type
template <typename G> struct set_super_type< regular_neighborhood<G>
> { typedef abstract::neighborhood< regular_neighborhood<G> > ret; };
@@ -61,6 +63,11 @@
typedef oln_grd_type_of(G, dpoint) dpoint_type;
typedef oln_grd_type_of(G, size) size_type;
typedef typename internal::to_window<G>::ret window_type;
+
+ typedef regular_fwd_niter<G> iter_type;
+ typedef regular_fwd_niter<G> fwd_iter_type;
+ typedef regular_bkd_niter<G> bkd_iter_type;
+
};