https://svn.lrde.epita.fr/svn/oln/trunk/olena
Draft Draft.
Index: ChangeLog
from Ugo Jardonnet <ugo.jardonnet(a)lrde.epita.fr>
Histogramm : Draft.
* oln/histo: New.
* oln/histo/histo_median.hh: New.
* oln/histo/histo_min.hh: New.
* oln/histo/histogram.hh: New.
canvas/two_pass.hh | 6 +--
histo/histo_median.hh | 85 ++++++++++++++++++++++++++++++++++++++++++++++
histo/histo_min.hh | 90 +++++++++++++++++++++++++++++++++++++++++++++++++
histo/histogram.hh | 69 +++++++++++++++++++++++++++++++++++++
morpho/cc_tarjan_v1.hh | 1
5 files changed, 247 insertions(+), 4 deletions(-)
Index: oln/histo/histo_median.hh
--- oln/histo/histo_median.hh (revision 0)
+++ oln/histo/histo_median.hh (revision 0)
@@ -0,0 +1,85 @@
+// Copyright (C) 2007 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, 51 Franklin Street, Fifth Floor,
+// 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 OLN_HISTO_MEDIAN_HH
+# define OLN_HISTO_MEDIAN_HH
+
+# include <oln/histo/histogram.hh>
+
+
+namespace oln
+{
+
+ namespace histo_median
+ {
+
+ template <typename T>
+ struct histo_median : public Histogram< histo_median<T> >
+ {
+ histo_median() : imed(this.ival) {}
+
+ void slide(T i)
+ {
+ int last_i = take(i);
+ untake();
+ if (imed == -1)
+ compute_median();
+ else
+ compute_median();
+ }
+
+ void compute_median()
+ {
+ T total = 0;
+ for (int i = 0; i < this.v.size; i++)
+ total += this.v[i];
+
+ imed = 0;
+ T sum = this.v[imed];
+ while (sum < total/2)
+ {
+ ++imed;
+ sum += this.v[imed];
+ }
+ }
+
+ T median() { return this.v[imed]; }
+ private:
+ int& imed;
+ T rest;
+ };
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::histo_median
+
+} // end of namespace oln
+
+#endif // ! OLN_HISTO_MEDIAN_HH
Index: oln/histo/histo_min.hh
--- oln/histo/histo_min.hh (revision 0)
+++ oln/histo/histo_min.hh (revision 0)
@@ -0,0 +1,90 @@
+// Copyright (C) 2007 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, 51 Franklin Street, Fifth Floor,
+// 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 OLN_HISTO_HISTO_MIN_HH
+# define OLN_HISTO_HISTO_MIN_HH
+
+# include <oln/histo/histogram.hh>
+# include <oln/core/internal/max_value.hh>
+
+namespace oln
+{
+
+ namespace histo_min
+ {
+
+ template <typename T>
+ struct histo_min : public Histogram< histo_min<T> >
+ {
+ histo_min() : imin(this.ival) {}
+
+ template <typename L>
+ void init(L line)
+ {
+ int i;
+ for (i = 0; i < line.norme; i++)
+ take(oln_max(T));
+ imin = i/2;
+ }
+
+ void slide(T i)
+ {
+ int last_i = take(i);
+ untake();
+ if (imin == -1)
+ compute_min();
+ else if (i < this.v[imin])
+ imin = last_i;
+ }
+
+ void compute_min()
+ {
+ imin = 0;
+ for (int i = 1; i < this.v.size; i++)
+ if (this.v[i] < this.v[imin])
+ imin = i;
+ }
+
+ T min() { return this.v[imin]; }
+ private:
+ int& imin;
+ };
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::histo_min
+
+} // end of namespace oln
+
+#endif // ! OLN_HISTO_HISTO_MIN_HH
+
+
+
+
Index: oln/histo/histogram.hh
--- oln/histo/histogram.hh (revision 0)
+++ oln/histo/histogram.hh (revision 0)
@@ -0,0 +1,69 @@
+// Copyright (C) 2007 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, 51 Franklin Street, Fifth Floor,
+// 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 OLN_HISTO_HISTOGRAM_HH
+# define OLN_HISTO_HISTOGRAM_HH
+
+namespace oln
+{
+
+ /// Concept-class "Histogram".
+
+ template <typename T>
+ struct Histogram
+ {
+ void take(T t)
+ {
+ v.insert(v.begin(), t);
+ if (ival > 0)
+ ival++;
+ return 0;
+ }
+
+ void untake()
+ {
+ if (this.ival == v.size)
+ ival = -1;
+ T ret = v.back();
+ v.pop_back();
+ return ret;
+ }
+
+ T operator()(int i) { return v[i]; }
+ void clean() { v.clear(); }
+
+ protected:
+ Histogram() : ival(-1) {}
+
+ std::vector<unsigned> v;
+ int ival;
+ }; // end of oln::Histogram<Exact>
+
+
+} // end of namespace oln
+
+#endif // ! OLN_HISTO_HISTOGRAM_HH
Index: oln/core/2d/line2d.hh
Index: oln/morpho/cc_tarjan_v1.hh
--- oln/morpho/cc_tarjan_v1.hh (revision 999)
+++ oln/morpho/cc_tarjan_v1.hh (working copy)
@@ -33,7 +33,6 @@
# include <oln/level/fill.hh>
# include <oln/core/internal/f_ch_value.hh>
-
namespace oln
{
Index: oln/canvas/two_pass.hh
--- oln/canvas/two_pass.hh (revision 999)
+++ oln/canvas/two_pass.hh (working copy)
@@ -37,9 +37,9 @@
namespace canvas
{
- namespace v1
+ namespace v1 // Data owned by f.
{
- template <typename F> // Data owned by f.
+ template <typename F>
void two_pass(F& fun)
{
@@ -109,7 +109,7 @@
}
- namespace v4 // Via Inheritance.
+ namespace v4 // Via static Inheritens.
{
template <typename I, typename Exact>
struct two_pass : public virtual Any<Exact>