Olena-patches
Threads by month
- ----- 2025 -----
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- 9625 discussions
URL: https://svn.lrde.epita.fr/svn/scool/branches/scool-ng
ChangeLog:
2008-09-02 Maxime van Noppen <yabo(a)lrde.epita.fr>
Add tests for scool's translator.
* config: Add test configuration for Scool's translator.
* check.sh: Various fixes to properly handle multiple tests.
---
check.sh | 28 +++++++++++++++++++++-------
config | 20 +++++++++++++++++++-
2 files changed, 40 insertions(+), 8 deletions(-)
Index: branches/scool-ng/tests/config
===================================================================
--- branches/scool-ng/tests/config (revision 69)
+++ branches/scool-ng/tests/config (revision 70)
@@ -1,13 +1,31 @@
-number_of_tests=1
+number_of_tests=2
test_1 ()
{
+ desc="Scool parser"
cmd='sglri -p ../../src/scl-syn/Scool.tbl -i $input_file'
cmp='diff -EwbB -u $ref $output'
print_input_cmd='cat $input_file'
print_output_cmd='pp-aterm -i $input_file'
input_files="scool_src/*.scl"
+ input_extension=".scl"
+
ref_dir="scool_ast"
ref_extension=".aterm"
}
+
+test_2 ()
+{
+ desc="Scool AST -> C++ AST"
+ cmd='../../src/scoolt/scoolt -i $input_file'
+ cmp='diff -EwbB -u $ref $output'
+ print_input_cmd='pp-aterm -i $input_file'
+ print_output_cmd='pp-aterm -i $input_file'
+
+ input_files="scool_ast/*.aterm"
+ input_extension=".aterm"
+
+ ref_dir="cxx_ast"
+ ref_extension=".aterm"
+}
Index: branches/scool-ng/tests/check.sh
===================================================================
--- branches/scool-ng/tests/check.sh (revision 69)
+++ branches/scool-ng/tests/check.sh (revision 70)
@@ -27,19 +27,19 @@
perform_test()
{
cexit_val=0
- test_name=`basename "$1" .scl`
+ test_name=`basename "$1" "$2"`
input_file="$1"
- ref=${2}/${test_name}${3}
+ ref=${3}/${test_name}${4}
cmd_log=`mktemp`
cmd_err=`mktemp`
cmp_log=`mktemp`
cmp_err=`mktemp`
- rcmd=`echo $4 | sed s#'$input_file'#$input_file#g`
+ rcmd=`echo $5 | sed s#'$input_file'#$input_file#g`
- rcmp=`echo $5 | sed s#'$ref'#$ref#g`
+ rcmp=`echo $6 | sed s#'$ref'#$ref#g`
rcmp=`echo $rcmp | sed s#'$output'#$cmd_log#g`
indent $utest_name_indent
@@ -91,7 +91,7 @@
else echo -ne "${byell}sk";
fi
- echo -e " $bblue]"
+ echo -n -e " $bblue]"
}
print_output()
@@ -129,9 +129,12 @@
test_config="test_$testnb"
eval $test_config
+ echo -e "${bgreen} Test $testnb : $desc"
+ if [ "`echo $input_files`" = "$input_files" ]; then echo ; cd ..; return; fi
+
for input_file in `ls $input_files`
do
- perform_test "$input_file" "$ref_dir" "$ref_extension" "$cmd" "$cmp"
+ perform_test "$input_file" "$input_extension" "$ref_dir" "$ref_extension" "$cmd" "$cmp"
exit_val=$?
indent $test_result_indent
@@ -146,6 +149,7 @@
print_test_result "ko"
if [ $print_diff -eq 1 ]; then
+ echo
if [ $exit_val -eq 2 ]; then
echo -ne $grey; cat $cmd_log $cmd_err
echo -n
@@ -155,6 +159,9 @@
fi
fi
+ if [ $print_cmd -eq 1 ]; then echo -n -e ${grey} "$rcmd"; fi
+ echo
+
# Print the input if the -p option was provided
if [ $print -eq 1 ]; then
if [ $flush_sk -eq 1 ]; then
@@ -176,6 +183,7 @@
print_output $cmd_log
fi
done
+ echo
done
cd ..
@@ -192,6 +200,7 @@
-sk | --flush-skip Print the command output (if any) on successful tests
-p | --print Print the input of the command
-pa | --print-all Print all inputs
+ -pc | --print-command Prints the command used for the test
-h | --help Print this help message
"
}
@@ -200,6 +209,7 @@
gen_ref=0
flush_sk=0
print_all=0
+print_cmd=0
print=0
# Parse command line options
while [ $# -gt 0 ]
@@ -221,10 +231,14 @@
print=1
;;
- -pa | --pall)
+ -pa | --print-all)
print_all=1
;;
+ -pc | --print-command)
+ print_cmd=1
+ ;;
+
-h | --help)
print_help
exit 0
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox
Index: ChangeLog
from Ugo Jardonnet <ugo.jardonnet(a)lrde.epita.fr>
Sandbox: Update metal::array.
* jardonnet/array/array.cc: Update Test.
* jardonnet/array/array.hh: Add stc/dyn getters.
* jardonnet/array/Makefile: New.
* jardonnet/test/icp.cc: .
* jardonnet/registration/tools.hh: .
array/Makefile | 2
array/array.cc | 12 ++++
array/array.hh | 121 +++++++++++++++++++++++++++++++++++++++++++++++++-
array/old/1d.hh | 4 -
registration/tools.hh | 58 ++++++-----------------
test/icp.cc | 1
6 files changed, 151 insertions(+), 47 deletions(-)
Index: jardonnet/test/icp.cc
--- jardonnet/test/icp.cc (revision 2161)
+++ jardonnet/test/icp.cc (working copy)
@@ -3,6 +3,7 @@
#include <mln/io/pbm/load.hh>
#include <mln/io/pbm/save.hh>
#include <mln/io/ppm/save.hh>
+#include <mln/convert/to_p_array.hh>
#include <mln/norm/l2.hh>
#include <sandbox/jardonnet/registration/icp.hh>
Index: jardonnet/registration/tools.hh
--- jardonnet/registration/tools.hh (revision 2161)
+++ jardonnet/registration/tools.hh (working copy)
@@ -193,23 +193,23 @@
namespace convert
{
- // to_p_array
- template <typename I>
- inline
- p_array<mln_point(I)>
- to_p_array(const Image<I>& img_)
- {
- const I& img = exact(img_);
-
- p_array<mln_point(I)> a;
-
- mln_piter(I) p(img.domain());
- for_all(p)
- if (img(p))
- a.append(p);
+// // to_p_array
+// template <typename I>
+// inline
+// p_array<mln_point(I)>
+// to_p_array(const Image<I>& img_)
+// {
+// const I& img = exact(img_);
+
+// p_array<mln_point(I)> a;
+
+// mln_piter(I) p(img.domain());
+// for_all(p)
+// if (img(p))
+// a.append(p);
- return a;
- }
+// return a;
+// }
template < typename P >
@@ -316,32 +316,6 @@
} // end of namespace convert
- namespace algebra
- {
-
- // transpose
- template<unsigned n, unsigned m, typename T>
- mat<m,n,T>
- trans(const mat<n,m,T>& matrice)
- {
- mat<m,n,T> tmp;
- for (unsigned i = 0; i < n; ++i)
- for (unsigned j = 0; j < m; ++j)
- tmp(j,i) = matrice(i,j);
- return tmp;
- }
-
- // trace
- template<unsigned n, typename T> inline
- float tr(const mat<n,n,T>& m)
- {
- float f = 0.f;
- for (unsigned i = 0; i < n; ++i)
- f += m(i,i);
- return f;
- }
-
- } // end of namespace algebra
} // end of namespace mln
Index: jardonnet/array/array.cc
--- jardonnet/array/array.cc (revision 2161)
+++ jardonnet/array/array.cc (working copy)
@@ -1,6 +1,6 @@
#include <iostream>
-#include <mln/metal/array.hh>
+#include "array.hh"
int main(int, char **)
{
@@ -9,4 +9,14 @@
mln::metal::array1d<int, 5> c;
c = a + b;
+
+ a.get<0>() = 0;
+ a.get<1>() = 1;
+ a.get<2>() = 2;
+ a.get<3>() = 3;
+
+ for (int i = 0 ; i < a.length; i++)
+ std::cout << a[i] << " ";
+
+ std::cout << std::endl;
}
Index: jardonnet/array/array.hh
--- jardonnet/array/array.hh (revision 2161)
+++ jardonnet/array/array.hh (working copy)
@@ -28,16 +28,47 @@
#ifndef MLN_METAL_ARRAY1D_HH
# define MLN_METAL_ARRAY1D_HH
+# include <mln/core/concept/object.hh>
+
# include <mln/trait/all.hh>
+# include <mln/trait/value_.hh>
+
+# include <mln/value/ops.hh>
namespace mln
{
+ // Fwd decls.
+ namespace metal {
+ template <typename T, unsigned Size> struct array1d;
+ }
+
+ namespace trait
+ {
+
+ template <typename T, unsigned Size>
+ struct value_< mln::metal::array1d<T,Size> >
+ {
+ typedef trait::value::nature::vectorial nature;
+ typedef trait::value::kind::data kind;
+
+ enum {
+ nbits = Size * mln_nbits(T),
+ card = Size * mln_card(T)
+ };
+ typedef mln_value_quant_from_(card) quant;
+
+ typedef metal::array1d<mln_sum(T),Size> sum;
+ };
+
+ } // end of namespace mln::trait
+
+
namespace metal
{
template <typename T, unsigned Size>
- struct array1d
+ struct array1d : public Object< array1d<T,Size> >
{
//
@@ -72,11 +103,99 @@
array1d<T, Size>&
operator-=(const array1d<T, Size>& rhs);
+
+ // dynamic accessors:
+
+ T operator[](unsigned i) const
+ {
+ mln_precondition(i < Size);
+ return buffer_[i];
+ }
+ T& operator[](unsigned i)
+ {
+ mln_precondition(i < Size);
+ return buffer_[i];
+ }
+
+ // static accessor
+
+ template<unsigned i>
+ T get() const {
+ return *(buffer_ + i);
+ }
+ template<unsigned i>
+ T& get() {
+ return *(buffer_ + i);
+ }
+
+ enum { length = Size };
protected:
T buffer_[Size];
};
+ }
+
+ namespace trait
+ {
+
+ // For unary traits.
+
+ template < template <class> class Name,
+ unsigned n, typename T >
+ struct set_precise_unary_< Name, metal::array1d<T, n> >
+ {
+ typedef mln_trait_unary(Name, T) V;
+ typedef metal::array1d<V, n> ret;
+ };
+
+ // For binary traits.
+
+ template < template <class, class> class Name,
+ unsigned n, typename T,
+ typename U >
+ struct set_precise_binary_< Name,
+ metal::array1d<T, n>, metal::array1d<U, n> >
+ {
+ typedef mln_trait_binary(Name, T, U) V;
+ typedef metal::array1d<V, n> ret;
+ };
+
+ template < unsigned n, typename T,
+ typename U >
+ struct set_precise_binary_< op::times,
+ metal::array1d<T, n>, metal::array1d<U, n> >
+ {
+ typedef mln_sum_x(T,U) ret;
+ };
+
+ template < template <class, class> class Name,
+ unsigned n, typename T,
+ typename S >
+ struct set_precise_binary_< Name,
+ metal::array1d<T, n>, mln::value::scalar_<S> >
+ {
+ typedef mln_trait_binary(Name, T, S) V;
+ typedef metal::array1d<V, n> ret;
+ };
+
+ template < template<class, class> class Name,
+ unsigned n, typename T,
+ typename S >
+ struct set_binary_< Name,
+ mln::Object, metal::array1d<T, n>,
+ mln::value::Scalar, S >
+ {
+ typedef mln_trait_binary(Name, T, S) V;
+ typedef metal::array1d<T, n> ret;
+ };
+
+ } // end of namespace mln::trait
+
+
+ namespace metal
+ {
+
//
// Constructors
//
Index: jardonnet/array/Makefile
--- jardonnet/array/Makefile (revision 0)
+++ jardonnet/array/Makefile (revision 0)
@@ -0,0 +1,2 @@
+all:
+ g++ array.cc -I../../..
\ No newline at end of file
Index: jardonnet/array/old/1d.hh
--- jardonnet/array/old/1d.hh (revision 2161)
+++ jardonnet/array/old/1d.hh (working copy)
@@ -236,9 +236,7 @@
template<int i>
T get_() const {
- lesseq<-Info_::center, i>::ensure();
- lesseq<i, Info_::card - Info_::center - 1>::ensure();
- return *(buffer_ + Info_::center + i);
+ return *(buffer_ + i);
}
protected:
1
0
Re: [Olena-patches] [Olena] #32: Improve the integration of Doxygen into the (autoconfiscated) package
by Olena 01 Sep '08
by Olena 01 Sep '08
01 Sep '08
#32: Improve the integration of Doxygen into the (autoconfiscated) package
--------------------------+-------------------------------------------------
Reporter: levill_r | Owner: levill_r
Type: enhancement | Status: new
Priority: trivial | Milestone: Back-to-School 2008
Component: other | Version: 1.0
Resolution: | Keywords:
--------------------------+-------------------------------------------------
Changes (by levill_r):
* milestone: Olena 1.0 => Back-to-School 2008
--
Ticket URL: <https://trac.lrde.org/olena/ticket/32#comment:2>
Olena <http://olena.lrde.epita.fr>
Olena, a generic and efficient C++ image processing library.
1
0
#81: Olena 1.0 Reference Documentation
-----------------------+----------------------------------------------------
Reporter: levill_r | Owner: Olena Team
Type: task | Status: new
Priority: minor | Milestone: Back-to-School 2008
Component: Milena | Version: 1.0
Resolution: | Keywords: doc
-----------------------+----------------------------------------------------
Changes (by levill_r):
* milestone: Olena 1.0 => Back-to-School 2008
--
Ticket URL: <https://trac.lrde.org/olena/ticket/81#comment:2>
Olena <http://olena.lrde.epita.fr>
Olena, a generic and efficient C++ image processing library.
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox
Index: ChangeLog
from Ugo Jardonnet <jardonnet(a)lrde.epita.fr>
Sandbox: Start working on metal::array.
metal::array:
* jardonnet/array: New.
* jardonnet/array/array.cc: Test.
* jardonnet/array/array.hh: metal::array base.
* jardonnet/array/old,
* jardonnet/array/old/nd.hh,
* jardonnet/array/old/1d.hh,
* jardonnet/array/old/2d.hh,
* jardonnet/array/old/3d.hh,
* jardonnet/array/old/all.hh,
* jardonnet/array/old/1d.hxx,
* jardonnet/array/old/objs.hh,
* jardonnet/array/old/2d.hxx,
* jardonnet/array/old/3d.hxx: Olena 0.11 array type.
Minor ICP updates (old):
* jardonnet/test/icp_ref.cc,
* jardonnet/test/icp.cc,
* jardonnet/registration/icp.hh: Fix plotting.
* jardonnet/test/img/c55.pbm: New test img.
* jardonnet/test/Makefile: Clean up.
array/array.cc | 12 +
array/array.hh | 181 ++++++++++++++++++++++++++++
array/old/1d.hh | 294 +++++++++++++++++++++++++++++++++++++++++++++
array/old/1d.hxx | 237 +++++++++++++++++++++++++++++++++++++
array/old/2d.hh | 326
++++++++++++++++++++++++++++++++++++++++++++++++++
array/old/2d.hxx | 283 ++++++++++++++++++++++++++++++++++++++++++++
array/old/3d.hh | 333
++++++++++++++++++++++++++++++++++++++++++++++++++++
array/old/3d.hxx | 293 +++++++++++++++++++++++++++++++++++++++++++++
array/old/all.hh | 35 +++++
array/old/nd.hh | 50 +++++++
array/old/objs.hh | 74 +++++++++++
registration/icp.hh | 6
test/Makefile | 7 -
test/icp.cc | 10 -
test/icp_ref.cc | 2
15 files changed, 2131 insertions(+), 12 deletions(-)
Index: jardonnet/test/icp_ref.cc
--- jardonnet/test/icp_ref.cc (revision 2160)
+++ jardonnet/test/icp_ref.cc (working copy)
@@ -77,6 +77,7 @@
image2d<value::rgb8> output(convert::to_box2d(working_box), 1);
level::fill(output, literal::white);
+/* FIXME: remove or plot mu_Ck and mu_Xk
//plot mu_Ck
point3df mu_Ck = registration::center(c, c.npoints());
draw::plot(output, point2d(mu_Ck[0], mu_Ck[1]), literal::green);
@@ -84,6 +85,7 @@
//plot mu_X
point3df mu_X = registration::center(x, x.npoints());
draw::plot(output, point2d(mu_X[0], mu_X[1]), literal::black);
+*/
//to 2d : projection (FIXME:if 3d)
for (unsigned i = 0; i < c.npoints(); i++)
Index: jardonnet/test/icp.cc
--- jardonnet/test/icp.cc (revision 2160)
+++ jardonnet/test/icp.cc (working copy)
@@ -77,7 +77,7 @@
// final transform
- quat7<3> fqk = registration::final_qk(c, map, 2*stddev);
+ quat7<3> fqk = registration::final_qk2(c, map, 2*stddev);
fqk.apply_on(c, c, c.npoints());
@@ -92,7 +92,7 @@
//Xk points
point2d px(x[i][0], x[i][1]);
if (output.has(px))
- output(px) = literal::green;
+ output(px) = literal::black;
}
@@ -105,13 +105,13 @@
{
algebra::vec<3,float> xki = map(c[i]);
algebra::vec<3,float> ci = c[i];
-
+ /*
if (length[i] > 2 * stddev)
output(p) = literal::red;
else if (length[i] > stddev)
output(p) = value::rgb8(255,200,0);
- else
- output(p) = literal::black;
+ else*/
+ output(p) = literal::green;
}
}
Index: jardonnet/test/img/c55.pbm
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes on: jardonnet/test/img/c55.pbm
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Index: jardonnet/test/Makefile
--- jardonnet/test/Makefile (revision 2160)
+++ jardonnet/test/Makefile (working copy)
@@ -16,8 +16,8 @@
icpD: icp.cc +depend
g++ icp.cc -I../../.. -g -o 'icpD'
-icp: icp.o +depend
- g++ icp.o -I../../.. -O3 -DNDEBUG -o 'icp'
+icp: +depend
+ g++ icp.cc -I../../.. -O3 -DNDEBUG -o 'icp'
icp_refD: icp_ref.cc ../registration/icp_ref.hh +depend
g++ -Wall -W icp_ref.cc -I../../.. -g -o 'icp_refD'
@@ -25,9 +25,6 @@
icp_ref: icp_ref.cc ../registration/icp_ref.hh +depend
g++ icp_ref.cc -I../../.. -O3 -DNDEBUG -o 'icp_ref'
-icp.o:
- g++ -c icp.cc -I../../.. -O3 -DNDEBUG
-
bench:
ruby bench.rb
Index: jardonnet/registration/icp.hh
--- jardonnet/registration/icp.hh (revision 2160)
+++ jardonnet/registration/icp.hh (working copy)
@@ -182,7 +182,8 @@
#ifndef NDEBUG // FIXME: theo
- image2d<value::rgb8> tmp(500,500); // FIXME :
+ const box_<P> working_box = enlarge(bigger(cloud.bbox(),x.bbox()),5);
+ image2d<value::rgb8> tmp(convert::to_box2d(working_box), 1);
level::fill(tmp, literal::black);
//write X
mln_piter(p_array<P>) p(x);
@@ -203,6 +204,7 @@
l = (l<1) ? 1 : l;
impl::icp_(cloud, map, qk, l, 1e-3);
+ /*
//remove points
p_array<P> tmp;
tmp.reserve(cloud.npoints());
@@ -216,7 +218,7 @@
if (norm::l2(qci - xi) < 2 * stddev)
cloud.hook_()[i] = cloud[(i+1) % cloud.npoints()];
}
-
+ */
#ifndef NDEBUG
{
value::rgb8 c;
Index: jardonnet/array/array.cc
--- jardonnet/array/array.cc (revision 0)
+++ jardonnet/array/array.cc (revision 0)
@@ -0,0 +1,12 @@
+#include <iostream>
+
+#include <mln/metal/array.hh>
+
+int main(int, char **)
+{
+ mln::metal::array1d<int, 5> a;
+ mln::metal::array1d<int, 5> b;
+ mln::metal::array1d<int, 5> c;
+
+ c = a + b;
+}
Index: jardonnet/array/array.hh
--- jardonnet/array/array.hh (revision 0)
+++ jardonnet/array/array.hh (revision 0)
@@ -0,0 +1,181 @@
+// Copyright (C) 2008 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 MLN_METAL_ARRAY1D_HH
+# define MLN_METAL_ARRAY1D_HH
+
+# include <mln/trait/all.hh>
+
+namespace mln
+{
+
+ namespace metal
+ {
+
+ template <typename T, unsigned Size>
+ struct array1d
+ {
+
+ //
+ // Constructors
+ //
+
+ array1d();
+ array1d(T* ptr);
+
+ // Copy
+
+ array1d(const array1d<T, Size>& rhs);
+ array1d<T, Size>& operator=(const array1d<T, Size>& rhs);
+
+ // Operators
+
+ template <class U>
+ array1d<T, Size> operator*(U w);
+
+ template <class U>
+ array1d<mln_trait_op_div(T,U), Size>
+ operator/(U w);
+
+ template <typename U>
+ array1d<mln_trait_op_plus(T,U), Size>
+ operator+(const array1d<U, Size>& rhs) const;
+ array1d<T, Size>& operator+=(const array1d<T, Size>& rhs);
+
+ template <typename U>
+ array1d<mln_trait_op_minus(T,U), Size>
+ operator-(const array1d<U, Size>& rhs) const;
+ array1d<T, Size>&
+ operator-=(const array1d<T, Size>& rhs);
+
+ protected:
+
+ T buffer_[Size];
+ };
+
+ //
+ // Constructors
+ //
+
+ template <typename T, unsigned Size>
+ array1d<T,Size>::array1d()
+ {
+ }
+
+ template <typename T, unsigned Size>
+ array1d<T,Size>::array1d(T* ptr)
+ {
+ for (unsigned i = 0; i < Size; ++i)
+ buffer_[i] = *ptr++;
+ }
+
+ // Copy
+
+ template <typename T, unsigned Size>
+ array1d<T,Size>::array1d(const array1d<T, Size>& rhs)
+ {
+ for (unsigned i = 0; i < Size; ++i)
+ buffer_[i] = rhs[i];
+ }
+ template <typename T, unsigned Size>
+ array1d<T, Size>&
+ array1d<T,Size>::operator=(const array1d<T, Size>& rhs)
+ {
+ for (unsigned i = 0; i < Size; ++i)
+ buffer_[i] = rhs[i];
+ return *this;
+ }
+
+ // Operators
+
+ template <typename T, unsigned Size>
+ template <class U>
+ array1d<T, Size>
+ array1d<T,Size>::operator*(U w)
+ {
+ //fixme mln_trait_op_mult<int,U>
+ array1d<T, Size> tmp;
+ for (unsigned i = 0; i < Size; ++i)
+ tmp[i] = this->buffer_[i] * w;
+ return tmp;
+ }
+
+ template <typename T, unsigned Size>
+ template <class U>
+ array1d<mln_trait_op_div(T,U), Size>
+ array1d<T,Size>::operator/(U w)
+ {
+ array1d<T, Size> tmp;
+ for (unsigned i = 0; i < Size; ++i)
+ tmp[i] = this->buffer_[i] / w;
+ return tmp;
+ }
+
+ template <typename T, unsigned Size>
+ template <typename U>
+ array1d<mln_trait_op_plus(T,U), Size>
+ array1d<T,Size>::operator+(const array1d<U, Size>& rhs) const
+ {
+ array1d<T, Size> tmp;
+ for (unsigned i = 0; i < Size; ++i)
+ tmp[i] = this->buffer_[i] + rhs.buffer_[i];
+ return tmp;
+ }
+ template <typename T, unsigned Size>
+ array1d<T, Size>&
+ array1d<T,Size>::operator+=(const array1d<T, Size>& rhs)
+ {
+ for (unsigned i = 0; i < Size; ++i)
+ this->buffer_[i] += rhs.buffer_[i];
+ return *this;
+ }
+
+ template <typename T, unsigned Size>
+ template <typename U>
+ array1d<mln_trait_op_minus(T,U), Size>
+ array1d<T,Size>::operator-(const array1d<U, Size>& rhs) const
+ {
+ array1d<T, Size> tmp;
+ for (unsigned i = 0; i < Size; ++i)
+ tmp[i] = this->buffer_[i] - rhs.buffer_[i];
+ return tmp;
+ }
+ template <typename T, unsigned Size>
+ array1d<T, Size>&
+ array1d<T,Size>::operator-=(const array1d<T, Size>& rhs)
+ {
+ for (unsigned i = 0; i < Size; ++i)
+ this->buffer_[i] -= rhs.buffer_[i];
+ return *this;
+ }
+
+ } // end of namespace metal
+
+} // end of namespace mln
+
+#endif /* MLN_METAL_ARRAY1D_HH */
+
Index: jardonnet/array/old/nd.hh
--- jardonnet/array/old/nd.hh (revision 0)
+++ jardonnet/array/old/nd.hh (revision 0)
@@ -0,0 +1,50 @@
+// Copyright (C) 2001, 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, Inc., 51 Franklin Street, Fifth Floor,
+// Boston, MA 02110-1301, 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 METALIC_ARRAY_ND_HH
+# define METALIC_ARRAY_ND_HH
+
+
+namespace mlc
+{
+
+ namespace internal
+ {
+
+ //
+ // mlc::internal misc
+ //
+ ////////////////////////////////////////
+
+ static const unsigned max_card_ = 4096; // 64 x 64
+ static const unsigned unknown_ = max_card_ + 1;
+
+ } // end of internal
+
+} // end of namespace mlc
+
+#endif // ! METALIC_ARRAY_ND_HH
Index: jardonnet/array/old/1d.hh
--- jardonnet/array/old/1d.hh (revision 0)
+++ jardonnet/array/old/1d.hh (revision 0)
@@ -0,0 +1,294 @@
+// Copyright (C) 2001, 2002, 2003, 2004 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, Inc., 51 Franklin Street, Fifth Floor,
+// Boston, MA 02110-1301, 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 METALIC_ARRAY_1D_HH
+# define METALIC_ARRAY_1D_HH
+
+# include <mlc/contract.hh>
+# include <mlc/cmp.hh>
+# include <mlc/array/objs.hh>
+# include <ntg/basics.hh>
+# include <iostream>
+
+
+// impl
+# include <mlc/array/1d.hxx>
+
+namespace mlc
+{
+
+ template<class Info_, class T_>
+ struct array1d
+ {
+ typedef array1d self;
+ typedef T_ T;
+ typedef Info_ Info;
+
+
+ //
+ // Constructors
+ //
+
+ array1d()
+ {
+ }
+
+ array1d(T* ptr)
+ {
+ less<0, Info_::card>::ensure();
+ less< Info_::card, internal::max_card_ >::ensure();
+ for (unsigned i = 0; i < Info_::card; ++i)
+ buffer_[i] = *ptr++;
+ }
+
+ // Copy
+
+ array1d(const self& rhs)
+ {
+ for (unsigned i = 0; i < Info_::card; ++i)
+ buffer_[i] = rhs[i];
+ }
+ self& operator=(const self& rhs)
+ {
+ for (unsigned i = 0; i < Info_::card; ++i)
+ buffer_[i] = rhs[i];
+ return *this;
+ }
+
+
+ // Name
+
+ static std::string
+ name()
+ {
+ return std::string("array1d< Info, ") + ntg_name(T) + " >";
+ }
+
+
+
+ //
+ // Operations on array
+ //
+
+ // Normalize (absolute values -> relative values)
+
+ array1d<Info_, ntg::float_s>
+ normalize()
+ {
+ array1d<Info_, ntg::float_s> tmp;
+ ntg::float_s sum = 0.f;
+ const ntg::float_s epsilon = 0.01f; // FIXME : epsilon should be
global
+ unsigned i;
+ for (i = 0; i < Info_::card; ++i)
+ sum += this->buffer_[i];
+ for (i = 0; i < Info_::card; ++i)
+ tmp[i] = this->buffer_[i] / sum;
+ // security
+ sum = 0.f;
+ for (i = 0; i < Info_::card; ++i)
+ sum += tmp[i];
+ postcondition(std::abs(sum - 1) <= epsilon);
+ return tmp;
+ }
+
+ // Central symmetry
+
+ array1d<array1d_info<Info_::card,
+ Info_::card - Info_::center - 1,
+ Info_::i>, T>
+ operator-() const
+ {
+ enum { new_center = Info_::card - Info_::center - 1 };
+ array1d<array1d_info< Info_::card, new_center, Info_::i>,T> tmp;
+
+ for (unsigned i = 0; i < Info_::card; ++i)
+ tmp[Info_::card - i - 1] = this->operator[](i);
+ return tmp;
+ }
+
+
+ // Operators
+
+ // FIXME: This code should be factorized between 1d, 2d and 3d.
+ // Think of a mechanism similar to apply() and apply2().
+
+ template <class U>
+ array1d< Info, ntg_return_type(times, T, U) >
+ operator*(U w)
+ {
+ array1d< Info, ntg_return_type(times, T, U) > tmp;
+ for (unsigned i = 0; i < Info::card; ++i)
+ tmp[i] = this->buffer_[i] * w;
+ return tmp;
+ }
+
+ template <class U>
+ array1d< Info, ntg_return_type(div, T, U) >
+ operator/(U w)
+ {
+ array1d< Info, ntg_return_type(div, T, U) > tmp;
+ for (unsigned i = 0; i < Info::card; ++i)
+ tmp[i] = this->buffer_[i] / w;
+ return tmp;
+ }
+
+ self operator+(const self& rhs) const
+ {
+ self tmp;
+ for (unsigned i = 0; i < Info::card; ++i)
+ tmp[i] = this->buffer_[i] + rhs.buffer_[i];
+ return tmp;
+ }
+ self& operator+=(const self& rhs)
+ {
+ for (unsigned i = 0; i < Info::card; ++i)
+ this->buffer_[i] += rhs.buffer_[i];
+ return *this;
+ }
+
+ self operator-(const self& rhs) const
+ {
+ self tmp;
+ for (unsigned i = 0; i < Info::card; ++i)
+ tmp[i] = this->buffer_[i] - rhs.buffer_[i];
+ return tmp;
+ }
+ self& operator-=(const self& rhs)
+ {
+ for (unsigned i = 0; i < Info::card; ++i)
+ this->buffer_[i] -= rhs.buffer_[i];
+ return *this;
+ }
+
+
+ //
+ // Accessors
+ //
+
+ unsigned size() const
+ {
+ return Info_::card;
+ }
+
+ const T* buffer() const
+ {
+ return buffer_;
+ }
+
+ // dynamic accessors:
+
+ T operator[](unsigned i) const // Absolute position
+ {
+ precondition(i < Info_::card);
+ return *(buffer_ + i);
+ }
+ T& operator[](unsigned i)
+ {
+ precondition(i < Info_::card);
+ return *(buffer_ + i);
+ }
+
+ T operator()(int i) const // Relative position
+ {
+ precondition(-Info_::center <= i);
+ precondition(i <= Info_::card - Info_::center - 1);
+ return *(buffer_ + Info_::center + i);
+ }
+ T& operator()(int i)
+ {
+ precondition(-Info_::center <= i);
+ precondition(i <= Info_::card - Info_::center - 1);
+ return *(buffer_ + Info_::center + i);
+ }
+
+
+ // do not use these methods...
+
+ template<unsigned i>
+ T get_at_() const {
+ lesseq<i, Info_::card>::ensure();
+ return *(buffer_ + i);
+ }
+
+ template<int i>
+ T get_() const {
+ lesseq<-Info_::center, i>::ensure();
+ lesseq<i, Info_::card - Info_::center - 1>::ensure();
+ return *(buffer_ + Info_::center + i);
+ }
+
+ protected:
+
+ T buffer_[Info_::card];
+ };
+
+
+ // ...but these static accessors:
+
+ template<unsigned i, class Info, class T> inline
+ T get_at(const array1d<Info, T>& arr)
+ {
+ return arr.template get_at_<i>();
+ }
+
+ template<int i, class Info, class T> inline
+ T get(const array1d<Info, T>& arr)
+ {
+ return arr.template get_<i>();
+ }
+
+ // starter objects
+
+ // FIXME: what about other types? Replace this by a function
+ // returning a starter.
+
+# define array1d_starter(T) \
+ static internal::array1d_start_<T > T##s_1d =
internal::array1d_start_<T >()
+
+ array1d_starter(int); // ints_1d
+ array1d_starter(float); // floats_1d
+
+
+
+ // print
+
+ template<class Info, class T>
+ std::ostream& operator<<(std::ostream& ostr, const array1d<Info, T>& rhs)
+ {
+ for (int i = 0; i < Info::card; ++i)
+ if (i == Info::center)
+ ostr << "<" << rhs[i] << "> ";
+ else
+ ostr << rhs[i] << " ";
+ ostr << std::endl;
+
+ return ostr;
+ }
+
+} // end of mlc
+
+#endif // ! METALIC_ARRAY_1D_HH
Index: jardonnet/array/old/2d.hh
--- jardonnet/array/old/2d.hh (revision 0)
+++ jardonnet/array/old/2d.hh (revision 0)
@@ -0,0 +1,326 @@
+// Copyright (C) 2001, 2002, 2003, 2004 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, Inc., 51 Franklin Street, Fifth Floor,
+// Boston, MA 02110-1301, 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 METALIC_ARRAY_2D_HH
+# define METALIC_ARRAY_2D_HH
+
+# include <mlc/array/objs.hh>
+# include <mlc/contract.hh>
+# include <mlc/cmp.hh>
+# include <ntg/basics.hh>
+
+# include <iostream>
+
+// impl
+# include <mlc/array/2d.hxx>
+
+namespace mlc
+{
+
+ template<class Info_, class T_>
+ struct array2d
+ {
+ typedef array2d self;
+ typedef T_ T;
+ typedef Info_ Info;
+
+ //
+ // Constructors
+ //
+
+ array2d()
+ {
+ }
+
+ array2d(T* ptr)
+ {
+ less< 0, Info_::nrows >::ensure();
+ less< 0, Info_::ncols >::ensure();
+ less< Info_::card, internal::max_card_ >::ensure();
+ for (unsigned i = 0; i < Info_::card; ++i)
+ buffer_[i] = *ptr++;
+ }
+
+ // Copy
+
+ array2d(const self& rhs)
+ {
+ for (unsigned i = 0; i < Info_::card; ++i)
+ buffer_[i] = rhs[i];
+ }
+ self& operator=(const self& rhs)
+ {
+ for (unsigned i = 0; i < Info_::card; ++i)
+ buffer_[i] = rhs[i];
+ return *this;
+ }
+
+
+ // Name
+
+ static std::string
+ name()
+ {
+ return std::string("array2d< Info, ") + ntg_name(T) + " >";
+ }
+
+
+
+ //
+ // Operations on array
+ //
+
+
+ // Normalize (absolute values -> relative values)
+
+ array2d<Info_, ntg::float_s>
+ normalize()
+ {
+ array2d<Info_, ntg::float_s> tmp;
+ ntg::float_s sum = 0.f;
+ const ntg::float_s epsilon = 0.01f; // FIXME : epsilon should be
global
+ unsigned i;
+ for (i = 0; i < Info_::card; ++i)
+ sum += this->buffer_[i];
+ for (i = 0; i < Info_::card; ++i)
+ tmp[i] = this->buffer_[i] / sum;
+ // security
+ sum = 0.f;
+ for (i = 0; i < Info_::card; ++i)
+ sum += tmp[i];
+ postcondition(std::abs(sum - 1) <= epsilon);
+ return tmp;
+ }
+
+ // Central symmetry
+
+ array2d<array2d_info<Info_::nrows,
+ Info_::ncols,
+ Info_::card - Info_::center - 1,
+ Info_::i>, T>
+ operator-() const
+ {
+ enum { new_center = Info_::card - Info_::center - 1 };
+ array2d<array2d_info< Info_::nrows, Info_::ncols, new_center,
Info_::i>,T> tmp;
+
+ for (unsigned i = 0; i < Info_::card; ++i)
+ tmp[Info_::card - i - 1] = this->operator[](i);
+ return tmp;
+ }
+
+
+ // Transpose
+
+ typedef array2d<array2d_info<
+ Info_::ncols,
+ Info_::nrows,
+ (Info_::center * Info_::nrows + Info_::center / Info_::ncols) %
Info_::card,
+ Info_::i
+ >, T> transposed_array_t;
+
+ transposed_array_t transpose() const
+ {
+ transposed_array_t tmp;
+ for (int i = 0; i < Info::card; ++i)
+ tmp[i] = this->operator[]((i * Info_::ncols + i / Info_::nrows) %
Info_::card);
+ return tmp;
+ }
+
+ // Operators
+
+ // FIXME: This code should be factorized between 1d, 2d and 3d.
+ // Think of a mechanism similar to apply() and apply2().
+
+ template <class U>
+ array2d< Info, ntg_return_type(times, T, U) >
+ operator*(U w)
+ {
+ array2d< Info, ntg_return_type(times, T, U) > tmp;
+ for (unsigned i = 0; i < Info::card; ++i)
+ tmp[i] = this->buffer_[i] * w;
+ return tmp;
+ }
+
+ template <class U>
+ array2d< Info, ntg_return_type(div, T, U) >
+ operator/(U w)
+ {
+ array2d< Info, ntg_return_type(div, T, U) > tmp;
+ for (unsigned i = 0; i < Info::card; ++i)
+ tmp[i] = this->buffer_[i] / w;
+ return tmp;
+ }
+
+ self operator+(const self& rhs) const
+ {
+ self tmp;
+ for (unsigned i = 0; i < Info::card; ++i)
+ tmp[i] = this->buffer_[i] + rhs.buffer_[i];
+ return tmp;
+ }
+ self& operator+=(const self& rhs)
+ {
+ for (unsigned i = 0; i < Info::card; ++i)
+ this->buffer_[i] += rhs.buffer_[i];
+ return *this;
+ }
+
+ self operator-(const self& rhs) const
+ {
+ self tmp;
+ for (unsigned i = 0; i < Info::card; ++i)
+ tmp[i] = this->buffer_[i] - rhs.buffer_[i];
+ return tmp;
+ }
+ self& operator-=(const self& rhs)
+ {
+ for (unsigned i = 0; i < Info::card; ++i)
+ this->buffer_[i] -= rhs.buffer_[i];
+ return *this;
+ }
+
+
+ //
+ // Accessors
+ //
+
+ unsigned size() const
+ {
+ return Info_::card;
+ }
+
+ const T* buffer() const
+ {
+ return buffer_;
+ }
+
+ // dynamic accessors:
+
+ T operator[](unsigned i) const // Absolute position
+ {
+ precondition(i < Info_::card);
+ return *(buffer_ + i);
+ }
+ T& operator[](unsigned i)
+ {
+ precondition(i < Info_::card);
+ return *(buffer_ + i);
+ }
+
+
+ T operator()(int row, int col) const // Relative position
+ {
+ precondition(-Info_::center_row <= row);
+ precondition(row <= Info_::nrows - Info_::center_row - 1);
+ precondition(-Info_::center_col <= col);
+ precondition(col <= Info_::ncols - Info_::center_col - 1);
+
+ return *(buffer_ + Info_::center + (row * Info_::ncols) + col);
+ }
+ T& operator()(int row, int col)
+ {
+ precondition(-Info_::center_row <= row);
+ precondition(row <= Info_::nrows - Info_::center_row - 1);
+ precondition(-Info_::center_col <= col);
+ precondition(col <= Info_::ncols - Info_::center_col - 1);
+
+ return *(buffer_ + Info_::center + (row * Info_::ncols) + col);
+ }
+
+
+ // do not use these methods...
+
+ template<unsigned i>
+ T get_at_() const {
+ lesseq<i, Info_::card>::ensure();
+ return *(buffer_ + i);
+ }
+
+ template<int nrow, int ncol>
+ T get_() const {
+ lesseq< -Info_::center_row, nrow >::ensure();
+ lesseq< nrow, Info_::nrows - Info_::center_row - 1 >::ensure();
+ lesseq< -Info_::center_col, ncol >::ensure();
+ lesseq< ncol, Info_::ncols - Info_::center_col - 1 >::ensure();
+ return *(buffer_ + Info_::center + (nrow * Info_::ncols) + ncol);
+ }
+
+
+ protected:
+
+ T buffer_[internal::max_card_];
+ };
+
+
+ // ...but these static accessors:
+
+ template<unsigned i, class Info, class T> inline
+ T get_at(const array2d<Info, T>& arr)
+ {
+ return arr.template get_at_<i>();
+ }
+
+ template<int row, int col, class Info, class T> inline
+ T get(const array2d<Info, T>& arr)
+ {
+ return arr.template get_<row, col>();
+ }
+
+ // starter objects
+
+ // FIXME: what about other types? Replace this by a function
+ // returning a starter.
+
+# define array2d_starter(T) \
+ static internal::array2d_start_<T > T##s_2d =
internal::array2d_start_<T >()
+
+ array2d_starter(int); // ints_2d
+ array2d_starter(float); // floats_2d
+
+
+ // print
+
+ template<class Info, class T>
+ std::ostream& operator<<(std::ostream& ostr, const array2d<Info, T>& rhs)
+ {
+ for (int i = 0; i < Info::card; ++i)
+ {
+ if (i == Info::center)
+ ostr << "<" << rhs[i] << ">";
+ else
+ ostr << rhs[i];
+
+ ostr << ((i + 1) % Info::ncols == 0 ? "\n" : "\t");
+ }
+ ostr << std::flush;
+ return ostr;
+ }
+
+} // end of mlc
+
+
+#endif // ! METALIC_ARRAY_2D_HH
Index: jardonnet/array/old/3d.hh
--- jardonnet/array/old/3d.hh (revision 0)
+++ jardonnet/array/old/3d.hh (revision 0)
@@ -0,0 +1,333 @@
+// Copyright (C) 2001, 2002, 2003, 2004 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, Inc., 51 Franklin Street, Fifth Floor,
+// Boston, MA 02110-1301, 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 METALIC_ARRAY_3D_HH
+# define METALIC_ARRAY_3D_HH
+
+# include <mlc/array/objs.hh>
+# include <mlc/contract.hh>
+# include <mlc/cmp.hh>
+# include <ntg/basics.hh>
+
+# include <iostream>
+
+// impl
+# include <mlc/array/3d.hxx>
+
+namespace mlc
+{
+
+ class not_implemented_yet{}; // FIXME
+
+ template<class Info_, class T_>
+ struct array3d
+ {
+ typedef array3d self;
+ typedef T_ T;
+ typedef Info_ Info;
+
+ //
+ // Constructors
+ //
+
+ array3d()
+ {
+ }
+
+ array3d(T* ptr)
+ {
+ less< 0, Info_::nplanes >::ensure();
+ less< 0, Info_::nrows >::ensure();
+ less< 0, Info_::ncols >::ensure();
+ less< Info_::card, internal::max_card_ >::ensure();
+ for (unsigned i = 0; i < Info_::card; ++i)
+ buffer_[i] = *ptr++;
+ }
+
+ // Copy
+
+ array3d(const self& rhs)
+ {
+ for (unsigned i = 0; i < Info_::card; ++i)
+ buffer_[i] = rhs[i];
+ }
+ self& operator=(const self& rhs)
+ {
+ for (unsigned i = 0; i < Info_::card; ++i)
+ buffer_[i] = rhs[i];
+ return *this;
+ }
+
+
+ // Name
+
+ static std::string
+ name()
+ {
+ return std::string("array3d< Info, ") + ntg_name(T) + " >";
+ }
+
+
+
+ //
+ // Operations on array
+ //
+
+ // Normalize (absolute values -> relative values)
+
+ array3d<Info_, ntg::float_s>
+ normalize()
+ {
+ array3d<Info_, ntg::float_s> tmp;
+ ntg::float_s sum = 0.f;
+ const ntg::float_s epsilon = 0.01f; // FIXME : epsilon should be
global
+ unsigned i;
+ for (i = 0; i < Info_::card; ++i)
+ sum += this->buffer_[i];
+ for (i = 0; i < Info_::card; ++i)
+ tmp[i] = this->buffer_[i] / sum;
+ // security
+ sum = 0.f;
+ for (i = 0; i < Info_::card; ++i)
+ sum += tmp[i];
+ postcondition(std::abs(sum - 1) <= epsilon);
+ return tmp;
+ }
+
+ // Central symmetry
+
+ array3d<array3d_info<Info_::nplanes,
+ Info_::nrows,
+ Info_::ncols,
+ Info_::card - Info_::center - 1,
+ Info_::i>, T>
+ operator-() const
+ {
+ enum { new_center = Info_::card - Info_::center - 1 };
+ array3d<array3d_info< Info_::nplanes, Info_::nrows, Info_::ncols,
new_center, Info_::i>,T> tmp;
+
+ for (unsigned i = 0; i < Info_::card; ++i)
+ tmp[Info_::card - i - 1] = this->operator[](i);
+ return tmp;
+ }
+
+
+ // Transpose
+
+ array3d<Info, T> transpose() const // FIXME
+ {
+ std::cerr << "[31m===> 3D transposition not implemented yet.
<===[0m" << std::endl;
+ throw not_implemented_yet();
+ }
+
+
+ // Operators
+
+ // FIXME: This code should be factorized between 1d, 2d and 3d.
+ // Think of a mechanism similar to apply() and apply2().
+
+ template <class U>
+ array3d< Info, ntg_return_type(times, T, U) >
+ operator*(U w)
+ {
+ array3d< Info, ntg_return_type(times, T, U) > tmp;
+ for (unsigned i = 0; i < Info::card; ++i)
+ tmp[i] = this->buffer_[i] * w;
+ return tmp;
+ }
+
+ template <class U>
+ array3d< Info, ntg_return_type(div, T, U) >
+ operator/(U w)
+ {
+ array3d< Info, ntg_return_type(div, T, U) > tmp;
+ for (unsigned i = 0; i < Info::card; ++i)
+ tmp[i] = this->buffer_[i] / w;
+ return tmp;
+ }
+
+ self operator+(const self& rhs) const
+ {
+ self tmp;
+ for (unsigned i = 0; i < Info::card; ++i)
+ tmp[i] = this->buffer_[i] + rhs.buffer_[i];
+ return tmp;
+ }
+ self& operator+=(const self& rhs)
+ {
+ for (unsigned i = 0; i < Info::card; ++i)
+ this->buffer_[i] += rhs.buffer_[i];
+ return *this;
+ }
+
+ self operator-(const self& rhs) const
+ {
+ self tmp;
+ for (unsigned i = 0; i < Info::card; ++i)
+ tmp[i] = this->buffer_[i] - rhs.buffer_[i];
+ return tmp;
+ }
+ self& operator-=(const self& rhs)
+ {
+ for (unsigned i = 0; i < Info::card; ++i)
+ this->buffer_[i] -= rhs.buffer_[i];
+ return *this;
+ }
+
+
+
+ // template<class U> int operator,(U); // FIXME: why this?
+
+ //
+ // Accessors
+ //
+
+ unsigned size() const
+ {
+ return Info_::card;
+ }
+
+ const T* buffer() const
+ {
+ return buffer_;
+ }
+
+ // dynamic accessors:
+
+ T operator[](unsigned i) const // Absolute position
+ {
+ precondition(i < Info_::card);
+ return *(buffer_ + i);
+ }
+ T& operator[](unsigned i)
+ {
+ precondition(i < Info_::card);
+ return *(buffer_ + i);
+ }
+
+
+ T operator()(int plane, int row, int col) const // Relative position
+ {
+ precondition(-Info_::center_plane <= plane);
+ precondition(plane <= Info::nplanes - Info_::center_plane - 1);
+ precondition(-Info_::center_row <= row);
+ precondition(row <= Info_::nrows - Info_::center_row - 1);
+ precondition(-Info_::center_col <= col);
+ precondition(col <= Info_::ncols - Info_::center_col - 1);
+
+ return *(buffer_ + Info_::center + (plane * Info::nrows *
Info::ncols) + (row * Info::ncols) + col);
+ }
+
+ T& operator()(int plane, int row, int col)
+ {
+ precondition(-Info_::center_plane <= plane);
+ precondition(plane <= Info::nplanes - Info_::center_plane - 1);
+ precondition(-Info_::center_row <= row);
+ precondition(row <= Info_::nrows - Info_::center_row - 1);
+ precondition(-Info_::center_col <= col);
+ precondition(col <= Info_::ncols - Info_::center_col - 1);
+
+ return *(buffer_ + Info_::center + (plane * Info::nrows *
Info::ncols) + (row * Info::ncols) + col);
+ }
+
+
+ // do not use these methods...
+
+ template<unsigned i>
+ T get_at_() const {
+ lesseq<i, Info_::card>::ensure();
+ return *(buffer_ + i);
+ }
+
+ template<int nplane, int nrow, int ncol>
+ T get_() const {
+ lesseq< -Info_::center_plane, nplane >::ensure();
+ lesseq< nplane, Info::nplanes - Info_::center_plane - 1 >::ensure();
+ lesseq< -Info_::center_row, nrow >::ensure();
+ lesseq< nrow, Info_::nrows - Info_::center_row - 1 >::ensure();
+ lesseq< -Info_::center_col, ncol >::ensure();
+ lesseq< ncol, Info_::ncols - Info_::center_col - 1 >::ensure();
+ return *(buffer_ + Info_::center + (nplane * Info::nrows *
Info::ncols) + (nrow * Info::ncols) + ncol);
+ }
+
+
+ protected:
+
+ T buffer_[internal::max_card_];
+ };
+
+
+ // ...but these static accessors:
+
+ template<unsigned i, class Info, class T> inline
+ T get_at(const array3d<Info, T>& arr)
+ {
+ return arr.template get_at_<i>();
+ }
+
+ template<int plane, int row, int col, class Info, class T> inline
+ T get(const array3d<Info, T>& arr)
+ {
+ return arr.template get_<plane, row, col>();
+ }
+
+ // starter objects
+
+ // FIXME: what about other types? Replace this by a function
+ // returning a starter.
+
+# define array3d_starter(T) \
+ static internal::array3d_start_<T > T##s_3d =
internal::array3d_start_<T >()
+
+ array3d_starter(int); // ints_3d
+ array3d_starter(float); // floats_3d
+
+
+ // print
+
+ template<class Info, class T>
+ std::ostream& operator<<(std::ostream& ostr, const array3d<Info, T>& rhs)
+ {
+ for (int i = 0; i < Info::card; ++i)
+ {
+ if (i == Info::center)
+ ostr << "<" << rhs[i] << "> ";
+ else
+ ostr << rhs[i] << " ";
+
+ ostr << ((i + 1) % Info::ncols == 0 ? "\n" : "\t");
+ ostr << ((i + 1) % (Info::ncols * Info::nrows) == 0 ? "\n" : "");
+ }
+ ostr << std::flush;
+
+ return ostr;
+ }
+
+
+} // end of mlc
+
+#endif // ! METALIC_ARRAY_3D_HH
Index: jardonnet/array/old/all.hh
--- jardonnet/array/old/all.hh (revision 0)
+++ jardonnet/array/old/all.hh (revision 0)
@@ -0,0 +1,35 @@
+// 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, Inc., 51 Franklin Street, Fifth Floor,
+// Boston, MA 02110-1301, 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 METALIC_ARRAY__HH
+# define METALIC_ARRAY__HH
+
+# include <mlc/array/1d.hh>
+# include <mlc/array/2d.hh>
+# include <mlc/array/3d.hh>
+
+#endif // ! METALIC_ARRAY__HH
Index: jardonnet/array/old/1d.hxx
--- jardonnet/array/old/1d.hxx (revision 0)
+++ jardonnet/array/old/1d.hxx (revision 0)
@@ -0,0 +1,237 @@
+// 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, Inc., 51 Franklin Street, Fifth Floor,
+// Boston, MA 02110-1301, 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 METALIC_ARRAY_1D_HXX
+# define METALIC_ARRAY_1D_HXX
+
+# include <mlc/array/nd.hh>
+
+namespace mlc
+{
+
+ //
+ // mlc::array1d_info
+ //
+ ////////////////////////////////////////
+
+
+ // card_ -> total number of elements (1-indexed)
+
+ // center_ -> position of the central element (0-indexed)
+ // domain : [ 0, card [
+
+ // i_ -> number of elements that have been eaten yet (0-indexed)
+ // domain : [ 0, card ] -> watch out !!
+
+
+ template < unsigned card_, unsigned center_ = card_ / 2, unsigned i_
= card_>
+ struct array1d_info
+ {
+ enum {
+ card = card_,
+ center = center_,
+ i = i_,
+ well_formed = true,
+ get_real_center = center_
+ };
+
+ typedef array1d_info< card_, center_, i + 1 > next_elt;
+
+ };
+
+ template < unsigned card_, unsigned i_ >
+ struct array1d_info <card_, internal::unknown_, i_ >
+ {
+ enum {
+ card = card_,
+ center = internal::unknown_,
+ i = i_,
+ well_formed = true,
+ get_real_center = i_ / 2
+ };
+
+ typedef array1d_info< card_, internal::unknown_, i + 1 > next_elt;
+
+ };
+
+ // fwd decl
+ template<class, class> struct array1d;
+
+
+ namespace internal
+ {
+
+ // fwd decl
+
+ template<class T, class Info>
+ struct array1d_elt_;
+
+ // for error messages
+
+ template<class U>
+ struct here_a_value_is_not_of_type_;
+
+
+ //
+ // mlc::internal::array1d_start_ decl
+ //
+ ////////////////////////////////////////
+
+ template<class T>
+ struct array1d_start_ {
+
+ array1d_elt_< T, array1d_info< unknown_, unknown_, 1 > >
operator=(T val);
+ array1d_elt_< T, array1d_info< unknown_, 0, 1 > > operator=(x_<T>
val);
+ array1d_elt_< T, array1d_info< unknown_, 0, 1 > >
operator=(x_<void> val);
+
+ T ptr[max_card_]; // could be static
+ };
+
+
+
+ //
+ // mlc::internal::array1d_elt_
+ //
+ ////////////////////////////////////////
+
+ template<class T, class Info>
+ struct array1d_elt_
+ {
+ typedef array1d_elt_<T, typename Info::next_elt> next_elt_t_;
+
+ typedef array1d_elt_< T, array1d_info< Info::card, Info::i,
Info::i + 1> > eat_center_t_;
+
+ typedef array1d< array1d_info< Info::i, Info::get_real_center,
Info::i > , T> array1d_t_;
+
+ public:
+
+ // Constructor
+
+ array1d_elt_(T* ptr, array1d_start_<T>* arr) : ptr(ptr), arr(arr)
+ {
+ }
+
+
+
+ //
+ // Overloading "operator,"
+ //
+
+
+ // elt, elt
+
+ next_elt_t_ operator,(T val)
+ {
+ is_true<Info::card == unknown_>::ensure();
+ *ptr = val;
+ return next_elt_t_(ptr + 1, arr);
+ }
+
+
+ // elt, x(elt) -> center
+
+ eat_center_t_ operator,(x_<T> val)
+ {
+ is_true<Info::center == unknown_>::ensure();
+ *ptr = val.ue; // FIXME : give a *name* to this variable !!
+ return eat_center_t_(ptr+1, arr);
+ }
+
+
+ // elt, x() -> center
+
+ eat_center_t_ operator,(x_<void>)
+ {
+ is_true<Info::center == unknown_>::ensure();
+ *ptr = T(0);
+ return eat_center_t_(ptr+1, arr);
+ }
+
+
+ // elt, end
+
+ array1d_t_ operator,(end_type)
+ {
+ // array is well-formed :
+ is_true<Info::well_formed>::ensure();
+ // centering is automatic or user-defined :
+ // (commented out to allow automatic centering on even sized arrays)
+ // mlc::logical_or< mlc::eq< Info::i % 2, 1 >::ret, mlc::neq<
Info::center, unknown_ >::ret >::ensure();
+ return array1d_t_(arr->ptr);
+ }
+
+
+ // else -> error
+
+ template<class U>
+ void operator,(array1d< Info, U >);
+
+ template<class U>
+ here_a_value_is_not_of_type_<T> operator,(U u) const;
+
+ T* ptr;
+ array1d_start_<T>* arr;
+ };
+
+
+
+ //
+ // mlc::internal::array1d_start_ impl
+ //
+ ////////////////////////////////////////
+
+ template<class T> inline
+ array1d_elt_< T, array1d_info< unknown_, unknown_, 1 > >
+ array1d_start_<T>::operator=(T val)
+ {
+ ptr[0] = val;
+ return array1d_elt_< T, array1d_info< unknown_, unknown_, 1 >
>(ptr+1, this);
+ }
+
+ template<class T> inline
+ array1d_elt_< T, array1d_info< unknown_, 0, 1 > >
+ array1d_start_<T>::operator=(x_<T> val)
+ {
+ ptr[0] = val.ue;
+ // center <- 0
+ return array1d_elt_< T, array1d_info< unknown_, 0, 1 > >(ptr+1,
this);
+ }
+
+ template<class T> inline
+ array1d_elt_< T, array1d_info< unknown_, 0, 1 > >
+ array1d_start_<T>::operator=(x_<void> val)
+ {
+ ptr[0] = T(0);
+ // center <- 0
+ return array1d_elt_< T, array1d_info< unknown_, 0, 1 > >(ptr+1,this);
+ }
+
+ } // end of internal
+
+} // end of mlc
+
+#endif // ! METALIC_ARRAY_1D_HXX
Index: jardonnet/array/old/objs.hh
--- jardonnet/array/old/objs.hh (revision 0)
+++ jardonnet/array/old/objs.hh (revision 0)
@@ -0,0 +1,74 @@
+// 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, Inc., 51 Franklin Street, Fifth Floor,
+// Boston, MA 02110-1301, 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 METALIC_ARRAY_OBJS_HH
+# define METALIC_ARRAY_OBJS_HH
+
+// FIXME: rename, objs is not precise enough.
+
+//
+// Defines common objects useful for array declarations.
+//
+
+# include <mlc/objs.hh>
+
+namespace mlc
+{
+
+ namespace internal
+ {
+
+ class lbrk_ {};
+ class pbrk_ {};
+
+ template<class T>
+ struct x_ {
+ x_(T val) : ue(val) {}
+ T ue;
+ };
+ template<> struct x_<void> {};
+ template<> struct x_<lbrk_>;
+ template<> struct x_<end_type>;
+
+ } // end of internal
+
+ // cross means origin
+
+ template<class T> inline
+ internal::x_<T>
+ x(T val) { return internal::x_<T>(val); }
+
+ inline
+ internal::x_<void>
+ x() { return internal::x_<void>(); }
+
+ static const internal::lbrk_ lbrk = internal::lbrk_();
+ static const internal::pbrk_ pbrk = internal::pbrk_();
+
+} // end of mlc
+
+#endif // METALIC_ARRAY_OBJS_HH
Index: jardonnet/array/old/2d.hxx
--- jardonnet/array/old/2d.hxx (revision 0)
+++ jardonnet/array/old/2d.hxx (revision 0)
@@ -0,0 +1,283 @@
+// 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, Inc., 51 Franklin Street, Fifth Floor,
+// Boston, MA 02110-1301, 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 METALIC_ARRAY_2D_HXX
+# define METALIC_ARRAY_2D_HXX
+
+# include <mlc/array/nd.hh>
+
+namespace mlc
+{
+
+ //
+ // mlc::array2d_info
+ //
+ ////////////////////////////////////////
+
+
+ // nrows_ -> total number of rows (1-indexed)
+ // ncols_ -> total number of columns (1-indexed)
+
+ // center_ -> position of the central element (0-indexed)
+ // domain : [ 0, card [
+
+ // i_ -> number of elements that have been eaten yet (0-indexed)
+ // domain : [ 0, card ] -> watch out !!
+
+
+
+ // Center is user-defined
+
+ template < unsigned nrows_,
+ unsigned ncols_,
+ unsigned center_ = ncols_ * (nrows_ / 2) + (ncols_ / 2),
+ unsigned i_ = nrows_ * ncols_>
+ struct array2d_info
+ {
+ enum {
+ nrows = nrows_,
+ ncols = ncols_,
+ center = center_,
+ center_row = center_ / ncols_,
+ center_col = center_ % ncols_,
+ card = nrows_ * ncols_,
+ i = i_,
+ well_formed = ((i_ % ncols_) == 0),
+ get_real_center = center_
+ };
+
+ typedef array2d_info< nrows_, ncols_, center_, i + 1 > next_elt;
+
+ };
+
+ // Center is defined automatically, if nrows and ncols are both odd
+
+ template < unsigned nrows_, unsigned ncols_, unsigned i_ >
+ struct array2d_info <nrows_, ncols_, internal::unknown_, i_ >
+ {
+ enum {
+ nrows = nrows_,
+ ncols = ncols_,
+ center = internal::unknown_,
+ i = i_,
+ card = nrows_ * ncols_,
+ well_formed = ((i_ % ncols_) == 0),
+ get_real_center = i_ / 2
+ };
+
+ typedef array2d_info< nrows_, ncols_, internal::unknown_, i + 1 >
next_elt;
+
+ };
+
+ // fwd decl
+ template<class, class> struct array2d;
+
+
+ namespace internal
+ {
+
+ // fwd decl
+
+ template<class T, class Info>
+ struct array2d_elt_;
+
+ // for error messages
+
+ template<class U>
+ struct here_a_value_is_not_of_type_;
+
+
+ //
+ // mlc::internal::array2d_start_ decl
+ //
+ ////////////////////////////////////////
+
+ template<class T>
+ struct array2d_start_ {
+
+ array2d_elt_< T, array2d_info< unknown_, unknown_, unknown_, 1 > >
+ operator=(T val);
+
+ array2d_elt_< T, array2d_info< unknown_, unknown_, 0, 1 > >
+ operator=(x_<T> val);
+
+ array2d_elt_< T, array2d_info< unknown_, unknown_, 0, 1 > >
+ operator=(x_<void> val);
+
+ T ptr[max_card_]; // could be static
+ };
+
+
+ //
+ // mlc::internal::array2d_elt_
+ //
+ ////////////////////////////////////////
+
+ template<class T, class Info>
+ struct array2d_elt_
+ {
+ typedef array2d_elt_< T, typename Info::next_elt >
+ next_elt_t_;
+
+ typedef array2d_elt_< T, array2d_info< Info::nrows, Info::ncols,
Info::i, Info::i + 1> >
+ eat_center_t_;
+
+ typedef array2d_elt_< T, array2d_info< Info::nrows, Info::i,
Info::center, Info::i > >
+ eat_lbrk_t_;
+
+ typedef array2d< array2d_info< Info::i / Info::ncols, Info::ncols,
Info::get_real_center, Info::i > , T>
+ array2d_t_;
+
+ public:
+
+ // Constructor
+
+ array2d_elt_(T* ptr, array2d_start_<T>* arr) : ptr(ptr), arr(arr)
+ {
+ }
+
+
+ //
+ // Overloading "operator,"
+ //
+
+
+ // elt, elt
+
+ next_elt_t_ operator,(T val)
+ {
+ is_true<Info::nrows == unknown_>::ensure();
+ *ptr = val;
+ return next_elt_t_(ptr + 1, arr);
+ }
+
+
+ // elt, x(elt) -> center
+
+ eat_center_t_ operator,(x_<T> val)
+ {
+ is_true<Info::center == unknown_>::ensure();
+ *ptr = val.ue; // FIXME : give a *name* to this variable !!
+ return eat_center_t_(ptr + 1, arr);
+ }
+
+
+ // elt, x() -> center
+
+ eat_center_t_ operator,(x_<void>)
+ {
+ is_true<Info::center == unknown_>::ensure();
+ *ptr = T(0);
+ return eat_center_t_(ptr + 1, arr);
+ }
+
+
+ // elt, lbrk
+
+ eat_lbrk_t_ operator,(lbrk_)
+ {
+ is_true<Info::ncols == unknown_>::ensure();
+ is_true<Info::ncols != 0>::ensure();
+ return eat_lbrk_t_(ptr, arr);
+ }
+
+
+ // elt, end
+
+ array2d_t_ operator,(end_type)
+ {
+ enum { nrows = Info::i / Info::ncols };
+
+ // array is well-formed :
+ is_true<Info::well_formed == true>::ensure();
+ // centering is automatic or user-defined :
+
+ is_true<Info::ncols != unknown_>::ensure();
+
+
+ // both nrows and ncols must be odd
+ // or the center must be user-defined
+
+ is_true<
+ ((Info::ncols % 2 == 1) && (nrows % 2 == 1))
+ || (Info::center != unknown_)
+ >::ensure();
+
+ return array2d_t_(arr->ptr);
+ }
+
+
+ // else -> error
+
+ template<class U>
+ void operator,(array2d< Info, U >);
+
+ template<class U>
+ here_a_value_is_not_of_type_<T> operator,(U u) const;
+
+ T* ptr;
+ array2d_start_<T>* arr;
+ };
+
+
+
+ //
+ // mlc::internal::array2d_start_ impl
+ //
+ ////////////////////////////////////////
+
+ template<class T> inline
+ array2d_elt_< T, array2d_info< unknown_, unknown_, unknown_, 1 > >
+ array2d_start_<T>::operator=(T val)
+ {
+ ptr[0] = val;
+ return array2d_elt_< T, array2d_info< unknown_, unknown_, unknown_, 1
> >(ptr+1,this);
+ }
+
+ template<class T> inline
+ array2d_elt_< T, array2d_info< unknown_, unknown_, 0, 1 > >
+ array2d_start_<T>::operator=(x_<T> val)
+ {
+ ptr[0] = val.ue;
+ // center <- 0
+ return array2d_elt_< T, array2d_info< unknown_, unknown_, 0, 1 >
>(ptr+1,this);
+ }
+
+ template<class T> inline
+ array2d_elt_< T, array2d_info< unknown_, unknown_, 0, 1 > >
+ array2d_start_<T>::operator=(x_<void> val)
+ {
+ ptr[0] = T(0);
+ // center <- 0
+ return array2d_elt_< T, array2d_info< unknown_, unknown_, 0, 1 >
>(ptr+1,this);
+ }
+
+ } // end of internal
+
+} // end of mlc
+
+#endif // ! METALIC_ARRAY_2D_HXX
Index: jardonnet/array/old/3d.hxx
--- jardonnet/array/old/3d.hxx (revision 0)
+++ jardonnet/array/old/3d.hxx (revision 0)
@@ -0,0 +1,293 @@
+// 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, Inc., 51 Franklin Street, Fifth Floor,
+// Boston, MA 02110-1301, 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 METALIC_ARRAY_3D_HXX
+# define METALIC_ARRAY_3D_HXX
+
+# include <mlc/array/nd.hh>
+
+namespace mlc
+{
+
+ //
+ // mlc::array3d_info
+ //
+ ////////////////////////////////////////
+
+
+ // nrows_ -> total number of rows (1-indexed)
+ // ncols_ -> total number of columns (1-indexed)
+ // nplanes_ -> total number of planes (1-indexed)
+
+ // center_ -> position of the central element (0-indexed)
+ // domain : [ 0, card [
+
+ // i_ -> number of elements that have been eaten yet (0-indexed)
+ // domain : [ 0, card ] -> watch out !!
+
+ // Center is user-defined
+
+ template < unsigned nplanes_,
+ unsigned nrows_,
+ unsigned ncols_,
+ unsigned center_ = (ncols_ * nrows_) * (nplanes_ / 2) + ncols_ *
(nrows_ / 2) + (ncols_ / 2),
+ unsigned i_ = nplanes_ * nrows_ * ncols_>
+ struct array3d_info
+ {
+ enum {
+ nplanes = nplanes_,
+ nrows = nrows_,
+ ncols = ncols_,
+ center = center_,
+ center_plane = center_ / (nrows_ * ncols_),
+ center_row = (center_ % (nrows_ * ncols_)) / ncols_,
+ center_col = (center_ % (nrows_ * ncols_)) % ncols_,
+ i = i_,
+ card = nplanes_ * nrows_ * ncols_,
+ well_formed = (i_ % (ncols_ * nrows) == 0),
+ get_real_center = center_
+ };
+
+ typedef array3d_info< nplanes_, nrows_, ncols_, center_, i + 1 >
next_elt;
+
+ };
+
+ // Center is defined automatically, if nrows and ncols are both odd
+
+ template < unsigned nplanes_, unsigned nrows_, unsigned ncols_,
unsigned i_ >
+ struct array3d_info < nplanes_, nrows_, ncols_, internal::unknown_, i_ >
+ {
+ enum {
+ nplanes = nplanes_,
+ nrows = nrows_,
+ ncols = ncols_,
+ center = internal::unknown_,
+ i = i_,
+ card = nplanes_ * nrows_ * ncols_,
+ well_formed = (i_ % (ncols_ * nrows_) == 0),
+ get_real_center = i_ / 2
+ };
+
+ typedef array3d_info< nplanes_, nrows_, ncols_, internal::unknown_,
i + 1 > next_elt;
+
+ };
+
+ // fwd decl
+ template<class, class> struct array3d;
+
+ namespace internal
+ {
+
+ // fwd decl
+
+ template<class T, class Info>
+ struct array3d_elt_;
+
+ // for error messages
+
+ template<class U>
+ struct here_a_value_is_not_of_type_;
+
+
+ //
+ // mlc::internal::array3d_start_ decl
+ //
+ ////////////////////////////////////////
+
+ template<class T>
+ struct array3d_start_ {
+
+ array3d_elt_< T, array3d_info< unknown_, unknown_, unknown_,
unknown_, 1 > >
+ operator=(T val);
+
+ array3d_elt_< T, array3d_info< unknown_, unknown_, unknown_, 0, 1
> >
+ operator=(x_<T> val);
+
+ array3d_elt_< T, array3d_info< unknown_, unknown_, unknown_, 0, 1
> >
+ operator=(x_<void> val);
+
+ T ptr[max_card_]; // could be static
+ };
+
+ //
+ // mlc::internal::array3d_elt_
+ //
+ ////////////////////////////////////////
+
+ template<class T, class Info>
+ struct array3d_elt_
+ {
+ typedef array3d_elt_< T, typename Info::next_elt >
+ next_elt_t_;
+
+ typedef array3d_elt_< T, array3d_info< Info::nplanes,
Info::nrows, Info::ncols, Info::i, Info::i + 1> >
+ eat_center_t_;
+
+ typedef array3d_elt_< T, array3d_info< Info::nplanes,
Info::nrows, Info::i, Info::center, Info::i > >
+ eat_lbrk_t_;
+
+ typedef array3d_elt_< T, array3d_info< Info::nplanes, Info::i /
Info::ncols, Info::ncols, Info::center, Info::i > >
+ eat_pbrk_t_;
+
+ typedef array3d< array3d_info< Info::i / (Info::ncols *
Info::nrows), Info::nrows, Info::ncols, Info::get_real_center, Info::i >
, T>
+ array3d_t_;
+
+ public:
+
+ // Constructor
+
+ array3d_elt_(T* ptr, array3d_start_<T>* arr) : ptr(ptr), arr(arr)
+ {
+ }
+
+
+ //
+ // Overloading "operator,"
+ //
+
+
+ // elt, elt
+
+ next_elt_t_ operator,(T val)
+ {
+ is_true<Info::nplanes == unknown_>::ensure();
+ *ptr = val;
+ return next_elt_t_(ptr + 1, arr);
+ }
+
+
+ // elt, x(elt) -> center
+
+ eat_center_t_ operator,(x_<T> val)
+ {
+ is_true<Info::center == unknown_>::ensure();
+ *ptr = val.ue; // FIXME : give a *name* to this variable !!
+ return eat_center_t_(ptr + 1, arr);
+ }
+
+
+ // elt, x() -> center
+
+ eat_center_t_ operator,(x_<void>)
+ {
+ is_true<Info::center == unknown_>::ensure();
+ *ptr = T(0);
+ return eat_center_t_(ptr + 1, arr);
+ }
+
+
+ // elt, lbrk
+
+ eat_lbrk_t_ operator,(lbrk_)
+ {
+ is_true<Info::ncols == unknown_>::ensure();
+ return eat_lbrk_t_(ptr, arr);
+ }
+
+
+ // elt, pbrk
+ eat_pbrk_t_ operator,(pbrk_)
+ {
+ is_true<Info::nplanes == unknown_>::ensure();
+ return eat_pbrk_t_(ptr, arr);
+ }
+
+ // elt, end
+
+ array3d_t_ operator,(end_type)
+ {
+ enum { nplanes = (Info::i / (Info::ncols * Info::nrows)) };
+
+ // array is well-formed :
+ is_true<Info::well_formed>::ensure();
+ // centering is automatic or user-defined :
+
+ is_true<Info::ncols != unknown_>::ensure();
+ is_true<Info::nrows != unknown_>::ensure();
+
+ // all of nplanes, nrows and ncols are odd
+ // or the center is user-defined
+
+ is_true<
+ (Info::ncols % 2 == 1 && Info::nrows % 2 == 1 && nplanes % 2 == 1)
+ || (Info::center != unknown_)
+ >::ensure();
+
+ return array3d_t_(arr->ptr);
+ }
+
+
+ // else -> error
+
+ template<class U>
+ void operator,(array3d< Info, U >);
+
+ template<class U>
+ here_a_value_is_not_of_type_<T> operator,(U u) const;
+
+ T* ptr;
+ array3d_start_<T>* arr;
+ };
+
+
+ //
+ // mlc::internal::array3d_start_ impl
+ //
+ ////////////////////////////////////////
+
+ template<class T> inline
+ array3d_elt_< T, array3d_info< unknown_, unknown_, unknown_,
unknown_, 1 > >
+ array3d_start_<T>::operator=(T val)
+ {
+ ptr[0] = val;
+ return array3d_elt_< T, array3d_info< unknown_, unknown_,
unknown_, unknown_, 1 > >(ptr+1,this);
+ }
+
+ template<class T> inline
+ array3d_elt_< T, array3d_info< unknown_, unknown_, unknown_, 0, 1 > >
+ array3d_start_<T>::operator=(x_<T> val)
+ {
+ ptr[0] = val.ue;
+ // center <- 0
+ return array3d_elt_< T, array3d_info< unknown_, unknown_,
unknown_, 0, 1 > >(ptr+1,this);
+ }
+
+ template<class T> inline
+ array3d_elt_< T, array3d_info< unknown_, unknown_, unknown_, 0, 1 > >
+ array3d_start_<T>::operator=(x_<void> val)
+ {
+ ptr[0] = T(0);
+ // center <- 0
+ return array3d_elt_< T, array3d_info< unknown_, unknown_,
unknown_, 0, 1 > >(ptr+1,this);
+ }
+
+ } // end of internal
+
+} // end of mlc
+
+
+#endif // ! METALIC_ARRAY_3D_HXX
1
0
cleanup-2008 2160: Add image domain extension morphers plus the flat image.
by Thierry Geraud 01 Sep '08
by Thierry Geraud 01 Sep '08
01 Sep '08
https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add image domain extension morphers plus the flat image.
Add image domain extension morphers.
* mln/core/image/extension_ima.hh: New.
* mln/trait/ch_value.hh (ch_value_): New overload to deal with
extension_ima.
* mln/core/image/extension_fun.hh: New.
* mln/core/image/extension_val.hh: New.
* mln/core/routine: New directory.
* mln/core/routine/all.hh: New.
* mln/core/routine/extend.hh: New.
* doc/tutorial/examples/image_if.cc: Augment to test extensions.
Add the flat image type.
* mln/core/image/flat_image.hh: New.
* doc/tutorial/examples/image_flat.cc: New.
* mln/core/image/status.txt: Update.
Enforce consistency for iterator naming.
* mln/core/macros.hh
(mln_iter, mln_fwd_iter, mln_bkd_iter): Rename as...
(mln_eiter, mln_fwd_eiter, mln_bkd_eiter): ...these.
* mln/core/site_set/p_key.hh,
* mln/core/site_set/p_mutable_array_of.hh,
* mln/core/site_set/p_set_of.hh,
* mln/core/p_runs.hh,
* mln/util/set.hh,
* mln/util/array.hh: Update.
Misc.
* mln/core/image/instant.hh (file): Fix.
* sandbox/geraud/p_runs__with_dedicated_piter.hh (todo): Remove;
obsolete.
* mln/core/internal/morpher_lvalue.hh
(mln_morpher_lvalue): New macro.
* mln/core/internal/image_identity.hh: Use the new macro.
* mln/core/safe.hh: Likewise.
doc/tutorial/examples/image_flat.cc | 12 +
doc/tutorial/examples/image_if.cc | 59 ++++-
mln/core/image/extension_fun.hh | 222 ++++++++++++++++++++
mln/core/image/extension_ima.hh | 254 +++++++++++++++++++++++
mln/core/image/extension_val.hh | 240 +++++++++++++++++++++
mln/core/image/flat_image.hh | 273 +++++++++++++++++++++++++
mln/core/image/instant.hh | 2
mln/core/image/status.txt | 4
mln/core/internal/image_identity.hh | 2
mln/core/internal/morpher_lvalue.hh | 4
mln/core/macros.hh | 26 +-
mln/core/p_runs.hh | 4
mln/core/routine/all.hh | 45 ++++
mln/core/routine/extend.hh | 157 ++++++++++++++
mln/core/safe.hh | 4
mln/core/site_set/p_key.hh | 8
mln/core/site_set/p_mutable_array_of.hh | 4
mln/core/site_set/p_set_of.hh | 4
mln/trait/ch_value.hh | 7
mln/util/array.hh | 6
mln/util/set.hh | 6
sandbox/geraud/p_runs__with_dedicated_piter.hh | 4
22 files changed, 1305 insertions(+), 42 deletions(-)
Index: doc/tutorial/examples/image_if.cc
--- doc/tutorial/examples/image_if.cc (revision 2159)
+++ doc/tutorial/examples/image_if.cc (working copy)
@@ -1,10 +1,16 @@
# include <mln/core/image2d.hh>
+# include <mln/core/neighb2d.hh>
# include <mln/core/image_if.hh>
# include <mln/debug/iota.hh>
# include <mln/debug/println.hh>
# include <mln/fun/p2b/chess.hh>
+# include <mln/border/fill.hh>
+# include <mln/core/var.hh>
+# include <mln/core/routine/extend.hh>
+# include <mln/pw/all.hh>
+
template <typename It, typename S>
void ch_target(It it, const S& s)
@@ -13,21 +19,64 @@
}
+template <typename I, typename N>
+void browse(const I& ima, const N& nbh)
+{
+ // Relies on "ima.has(p)".
+ mln_fwd_piter(I) p(ima.domain());
+ mln_fwd_niter(N) n(nbh, p);
+ for_all(p)
+ {
+ std::cout << ima(p) << ": ";
+ for_all(n)
+ if (ima.has(n))
+ std::cout << ima(n) << ' ';
+ std::cout << std::endl;
+ }
+}
+
+template <typename I, typename N>
+void browse_domain(const I& ima, const N& nbh)
+{
+ // Relies on "ima.domain().has(p)".
+ mln_fwd_piter(I) p(ima.domain());
+ mln_fwd_niter(N) n(nbh, p);
+ for_all(p)
+ {
+ std::cout << ima(p) << ": ";
+ for_all(n)
+ if (ima.domain().has(n))
+ std::cout << ima(n) << ' ';
+ std::cout << std::endl;
+ }
+}
+
+
+
+
int main()
{
using namespace mln;
typedef image2d<unsigned> I;
- I ima(3, 5);
+ I ima(3, 3, 1);
+ // FIXME: border::fill(ima, 0);
debug::iota(ima);
+ mln_VAR(ima_, ima | fun::p2b::chess);
+
debug::println(ima);
- debug::println(ima | fun::p2b::chess);
+ debug::println(ima_);
- trait::image::print(ima | fun::p2b::chess);
+ trait::image::print(ima_);
+ std::cout << std::endl;
typedef pset_if<box2d, fun::p2b::chess_t> S;
+ ch_target(mln_fwd_piter_(S)(), ima_.domain());
- ch_target(mln_fwd_piter_(S)(),
- (ima | fun::p2b::chess).domain());
+ // mln_VAR(ima_e, extend(ima_, pw::value(ima)));
+ // mln_VAR(ima_e, extend(ima_, 0));
+ mln_VAR(ima_e, extend(ima_, ima));
+ debug::println(ima_e);
+ browse(ima_e, c4());
}
Index: doc/tutorial/examples/image_flat.cc
--- doc/tutorial/examples/image_flat.cc (revision 0)
+++ doc/tutorial/examples/image_flat.cc (revision 0)
@@ -0,0 +1,12 @@
+# include <mln/core/image2d.hh>
+# include <mln/core/image/flat_image.hh>
+# include <mln/debug/println.hh>
+
+
+int main()
+{
+ using namespace mln;
+
+ flat_image<unsigned, box2d> ima(3, box2d(3,3));
+ debug::println(ima);
+}
Index: mln/trait/ch_value.hh
--- mln/trait/ch_value.hh (revision 2159)
+++ mln/trait/ch_value.hh (working copy)
@@ -98,6 +98,13 @@
typedef M< P, V > ret;
};
+ template < template <class, class> class M, typename I1, typename I2,
+ typename V >
+ struct ch_value_< M< tag::image_<I1>, tag::image_<I2> >, V >
+ {
+ typedef M< mln_ch_value(I1, V), mln_ch_value(I2, V) > ret;
+ };
+
// For mln::value::stack_image<n,I>.
template < template <unsigned, class> class M, unsigned n, typename I,
typename V >
Index: mln/core/macros.hh
--- mln/core/macros.hh (revision 2159)
+++ mln/core/macros.hh (working copy)
@@ -49,10 +49,11 @@
// b
-/// Shortcuts to access the bkd_iter type associated to T.
+/// Shortcuts to access the element-backward-iterator type associated
+/// to T.
/// \{
-# define mln_bkd_iter(T) typename T::bkd_iter
-# define mln_bkd_iter_(T) T::bkd_iter
+# define mln_bkd_eiter(T) typename T::bkd_eiter
+# define mln_bkd_eiter_(T) T::bkd_eiter
/// \}
/// Shortcuts to access the bkd_niter type associated to T.
@@ -118,6 +119,12 @@
// e
+/// Shortcuts to access the element-iterator type associated to T.
+/// \{
+# define mln_eiter(T) typename T::eiter
+# define mln_eiter_(T) T::eiter
+/// \}
+
/// Shortcuts to access the element type associated to T.
/// \{
# define mln_element(T) typename T::element
@@ -139,10 +146,11 @@
// f
-/// Shortcuts to access the fwd_iter type associated to T.
+/// Shortcuts to access the element-forward-iterator type associated
+/// to T.
/// \{
-# define mln_fwd_iter(T) typename T::fwd_iter
-# define mln_fwd_iter_(T) T::fwd_iter
+# define mln_fwd_eiter(T) typename T::fwd_eiter
+# define mln_fwd_eiter_(T) T::fwd_eiter
/// \}
/// Shortcuts to access the fwd_niter type associated to T.
@@ -199,12 +207,6 @@
# define mln_invert_(T) T::invert
/// \}
-/// Shortcuts to access the iterator type associated to T.
-/// \{
-# define mln_iter(T) typename T::iter
-# define mln_iter_(T) T::iter
-/// \}
-
// l
Index: mln/core/internal/morpher_lvalue.hh
--- mln/core/internal/morpher_lvalue.hh (revision 2159)
+++ mln/core/internal/morpher_lvalue.hh (working copy)
@@ -36,6 +36,10 @@
# include <mln/core/macros.hh>
+# define mln_morpher_lvalue(I) typename internal::morpher_lvalue_<I>::ret
+
+
+
namespace mln
{
Index: mln/core/internal/image_identity.hh
--- mln/core/internal/image_identity.hh (revision 2159)
+++ mln/core/internal/image_identity.hh (working copy)
@@ -143,7 +143,7 @@
typedef mln_rvalue(I) rvalue;
/// Return type of read-write access.
- typedef typename internal::morpher_lvalue_<I>::ret lvalue;
+ typedef mln_morpher_lvalue(I) lvalue;
/// Give the set of values.
Index: mln/core/image/extension_ima.hh
--- mln/core/image/extension_ima.hh (revision 0)
+++ mln/core/image/extension_ima.hh (revision 0)
@@ -0,0 +1,254 @@
+// Copyright (C) 2008 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 MLN_CORE_IMAGE_EXTENSION_IMA_HH
+# define MLN_CORE_IMAGE_EXTENSION_IMA_HH
+
+/*!
+ * \file mln/core/image/extension_ima.hh
+ *
+ * \brief Definition of a morpher that extends the domain of an image
+ * with a function.
+ *
+ * \todo Use the 'instant' mechanism.
+ */
+
+# include <mln/core/internal/image_identity.hh>
+# include <mln/metal/converts_to.hh>
+
+
+
+namespace mln
+{
+
+ // Forward declaration.
+ template <typename I, typename J> struct extension_ima;
+
+
+ namespace internal
+ {
+
+ /// \internal Data structure for \c mln::extension_ima<I, J>.
+ template <typename I, typename J>
+ struct data< extension_ima<I, J> >
+ {
+ data(I& ima, J& ext);
+
+ I ima_;
+ J ext_;
+ };
+
+ } // end of namespace mln::internal
+
+
+ namespace trait
+ {
+
+ template <typename I, typename J>
+ struct image_< extension_ima<I, J> > : image_< I > // Same as I except...
+ {
+ // ...these changes.
+ typedef trait::image::category::identity_morpher category;
+ typedef mln_internal_trait_image_speed_from(I) speed; // Un-fastest.
+
+ // extended domain
+ typedef trait::image::ext_domain::extendable ext_domain;
+ typedef trait::image::ext_value::multiple ext_value;
+ typedef mln_trait_image_value_io(J) ext_io;
+ };
+
+ } // end of namespace mln::trait
+
+
+
+ // FIXME: Doc!
+
+ template <typename I, typename J>
+ class extension_ima
+
+ : public internal::image_identity< I, mln_pset(I), extension_ima<I, J> >,
+ private mlc_converts_to(mln_value(J), mln_value(I))::check_t
+ {
+ public:
+
+ /// Skeleton.
+ typedef extension_ima< tag::image_<I>, tag::image_<J> > skeleton;
+ // FIXME: OK when ch_value?
+
+
+ /// Return type of read-only access.
+ typedef mln_value(I) rvalue;
+
+
+ /// Constructor without argument.
+ extension_ima();
+
+ /// Constructor from an image \p ima and a function \p ext.
+ extension_ima(I& ima, J& ext);
+
+ /// Deferred initialization from an image \p ima and a function \p
+ /// ext.
+ void init(I& ima, J& ext);
+
+
+ /// Test if \p p is valid.
+ // Tech note: the 'template' allows for multiple input.
+ template <typename P>
+ bool has(const P& p) const;
+
+
+ /// Read-only access to the image value located at site \p p;
+ mln_value(I) operator()(const mln_psite(I)& p) const;
+
+ /// Read-write access to the image value located at site \p p.
+ mln_morpher_lvalue(I) operator()(const mln_psite(I)& p);
+
+
+ /// Read-only access to the extension domain (image).
+ mlc_const(J)& extension() const;
+
+ /// Mutable access to the extension domain (image). This domain
+ /// can be modified if J a read-write image type.
+ J& extension();
+ };
+
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ // internal::data< extension_ima<I,S> >
+
+ namespace internal
+ {
+
+ template <typename I, typename J>
+ inline
+ data< extension_ima<I, J> >::data(I& ima, J& ext)
+ : ima_(ima),
+ ext_(ext)
+ {
+ }
+
+ } // end of namespace mln::internal
+
+ // extension_ima<I, J>
+
+ template <typename I, typename J>
+ inline
+ extension_ima<I, J>::extension_ima()
+ {
+ }
+
+ template <typename I, typename J>
+ inline
+ extension_ima<I, J>::extension_ima(I& ima, J& ext)
+ {
+ init(ima, ext);
+ }
+
+ template <typename I, typename J>
+ inline
+ void
+ extension_ima<I, J>::init(I& ima, J& ext)
+ {
+ this->data_ = new internal::data< extension_ima<I, J> >(ima, ext);
+ }
+
+ template <typename I, typename J>
+ template <typename P>
+ inline
+ bool
+ extension_ima<I, J>::has(const P& p) const
+ {
+ mln_precondition(this->has_data());
+ mln_precondition(this->data_->ext_.has_data());
+ return
+ this->data_->ima_.domain().has(p)
+ || this->data_->ext_.has(p);
+ }
+
+ template <typename I, typename J>
+ inline
+ mln_value(I)
+ extension_ima<I, J>::operator()(const mln_psite(I)& p) const
+ {
+ mln_precondition(this->has_data());
+ mln_precondition(has(p));
+ // if-else is preferred to the ternary op to allow for the
+ // function result to convert towards the expected return type.
+ if (this->data_->ima_.domain().has(p))
+ return this->data_->ima_(p);
+ else
+ return this->data_->ext_(p);
+ }
+
+ template <typename I, typename J>
+ inline
+ mln_morpher_lvalue(I)
+ extension_ima<I, J>::operator()(const mln_psite(I)& p)
+ {
+ static mln_value(I) cpy;
+ mln_precondition(this->has_data());
+ mln_precondition(has(p));
+ // See the above comment about if-else v. ternary.
+ if (this->data_->ima_.domain().has(p))
+ return this->data_->ima_(p);
+ else
+ {
+ // This hack makes this signature valid both in the image
+ // domain and in its extension. It works even if
+ // mln_morpher_lvalue(I) is a mutable reference.
+ cpy = this->data_->ext_(p);
+ return cpy;
+ }
+ }
+
+ template <typename I, typename J>
+ inline
+ mlc_const(J)&
+ extension_ima<I, J>::extension() const
+ {
+ mln_precondition(this->has_data());
+ return this->data_->ext_;
+ }
+
+ template <typename I, typename J>
+ inline
+ J&
+ extension_ima<I, J>::extension()
+ {
+ mln_precondition(this->has_data());
+ return this->data_->ext_;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_IMAGE_EXTENSION_IMA_HH
Index: mln/core/image/status.txt
--- mln/core/image/status.txt (revision 2159)
+++ mln/core/image/status.txt (working copy)
@@ -57,6 +57,10 @@
** identity morpher
new instant
+new extension_ima
+new extension_fun
+new extension_val
+
ok plain
ok safe
Index: mln/core/image/extension_fun.hh
--- mln/core/image/extension_fun.hh (revision 0)
+++ mln/core/image/extension_fun.hh (revision 0)
@@ -0,0 +1,222 @@
+// Copyright (C) 2008 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 MLN_CORE_IMAGE_EXTENSION_FUN_HH
+# define MLN_CORE_IMAGE_EXTENSION_FUN_HH
+
+/*!
+ * \file mln/core/image/extension_fun.hh
+ *
+ * \brief Definition of a morpher that extends the domain of an image
+ * with a function.
+ *
+ * \todo Deal with two-ways functions...
+ */
+
+# include <mln/core/internal/image_identity.hh>
+# include <mln/metal/converts_to.hh>
+
+
+
+namespace mln
+{
+
+ // Forward declaration.
+ template <typename I, typename F> struct extension_fun;
+
+
+ namespace internal
+ {
+
+ /// \internal Data structure for \c mln::extension_fun<I, F>.
+ template <typename I, typename F>
+ struct data< extension_fun<I, F> >
+ {
+ data(I& ima, const F& fun);
+
+ I ima_;
+ const F fun_;
+ };
+
+ } // end of namespace mln::internal
+
+
+ namespace trait
+ {
+
+ template <typename I, typename F>
+ struct image_< extension_fun<I, F> > : image_< I > // Same as I except...
+ {
+ // ...these changes.
+ typedef trait::image::category::identity_morpher category;
+ typedef mln_internal_trait_image_speed_from(I) speed; // Un-fastest.
+
+ // extended domain
+ typedef trait::image::ext_domain::infinite ext_domain;
+ typedef trait::image::ext_value::multiple ext_value;
+ typedef trait::image::ext_io::read_only ext_io;
+ };
+
+ } // end of namespace mln::trait
+
+
+
+ // FIXME: Doc!
+
+ template <typename I, typename F>
+ class extension_fun
+
+ : public internal::image_identity< I, mln_pset(I), extension_fun<I, F> >,
+ private mlc_converts_to(mln_result(F), mln_value(I))::check_t
+ {
+ public:
+
+ /// Skeleton.
+ typedef extension_fun< tag::image_<I>, tag::function_<F> > skeleton;
+ // FIXME: OK when ch_value?
+
+
+ /// Return type of read-only access.
+ typedef mln_value(I) rvalue;
+
+
+ /// Constructor without argument.
+ extension_fun();
+
+ /// Constructor from an image \p ima and a function \p fun.
+ extension_fun(I& ima, const F& fun);
+
+ /// Deferred initialization from an image \p ima and a function \p
+ /// fun.
+ void init(I& ima, const F& fun);
+
+
+ /// Test if \p p is valid. It returns always true.
+ // Tech note: the 'template' allows for multiple input.
+ template <typename P>
+ bool has(const P& p) const;
+
+
+ /// Read-only access to the image value located at site \p p;
+ mln_value(I) operator()(const mln_psite(I)& p) const;
+
+ /// Read-write access to the image value located at site \p p.
+ mln_morpher_lvalue(I) operator()(const mln_psite(I)& p);
+ };
+
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ // internal::data< extension_fun<I,S> >
+
+ namespace internal
+ {
+
+ template <typename I, typename F>
+ inline
+ data< extension_fun<I, F> >::data(I& ima, const F& fun)
+ : ima_(ima),
+ fun_(fun)
+ {
+ }
+
+ } // end of namespace mln::internal
+
+ // extension_fun<I, F>
+
+ template <typename I, typename F>
+ inline
+ extension_fun<I, F>::extension_fun()
+ {
+ }
+
+ template <typename I, typename F>
+ inline
+ extension_fun<I, F>::extension_fun(I& ima, const F& fun)
+ {
+ init(ima, fun);
+ }
+
+ template <typename I, typename F>
+ inline
+ void
+ extension_fun<I, F>::init(I& ima, const F& fun)
+ {
+ this->data_ = new internal::data< extension_fun<I, F> >(ima, fun);
+ }
+
+ template <typename I, typename F>
+ template <typename P>
+ inline
+ bool
+ extension_fun<I, F>::has(const P&) const
+ {
+ return true;
+ }
+
+ template <typename I, typename F>
+ inline
+ mln_value(I)
+ extension_fun<I, F>::operator()(const mln_psite(I)& p) const
+ {
+ mln_precondition(this->has_data());
+ // if-else is preferred to the ternary op to allow for the
+ // function result to convert towards the expected return type.
+ if (this->data_->ima_.domain().has(p))
+ return this->data_->ima_(p);
+ else
+ return this->data_->fun_(p);
+ }
+
+ template <typename I, typename F>
+ inline
+ mln_morpher_lvalue(I)
+ extension_fun<I, F>::operator()(const mln_psite(I)& p)
+ {
+ static mln_value(I) cpy;
+ mln_precondition(this->has_data());
+ // See the above comment about if-else v. ternary.
+ if (this->data_->ima_.domain().has(p))
+ return this->data_->ima_(p);
+ else
+ {
+ // This hack makes this signature valid both in the image
+ // domain and in its extension. It works even if
+ // mln_morpher_lvalue(I) is a mutable reference.
+ cpy = this->data_->fun_(p);
+ return cpy;
+ }
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_IMAGE_EXTENSION_FUN_HH
Index: mln/core/image/flat_image.hh
--- mln/core/image/flat_image.hh (revision 0)
+++ mln/core/image/flat_image.hh (revision 0)
@@ -0,0 +1,273 @@
+// Copyright (C) 2008 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 MLN_CORE_FLAT_IMAGE_HH
+# define MLN_CORE_FLAT_IMAGE_HH
+
+/*!
+ * \file mln/core/flat_image.hh
+ *
+ * \brief Definition of a image with a signle value.
+ *
+ * \todo Zed: Address the values v. destination issue.
+ */
+
+# include <mln/core/internal/image_primary.hh>
+
+
+namespace mln
+{
+
+
+ // Forward declaration.
+ template <typename T, typename S> class flat_image;
+
+
+ namespace internal
+ {
+
+ /// \internal Data structure for \c mln::flat_image<T,S>.
+ template <typename T, typename S>
+ struct data< flat_image<T,S> >
+ {
+ data(const T& val, const S& pset);
+
+ T val_;
+ S pset_;
+ };
+
+ } // end of namespace mln::internal
+
+
+
+ namespace trait
+ {
+
+ template <typename T, typename S>
+ struct image_< flat_image<T,S> > : default_image_< T, flat_image<T,S> >
+ {
+ // misc
+ typedef trait::image::category::primary category;
+ typedef trait::image::speed::fast speed;
+ typedef trait::image::size::regular size;
+
+ // value
+ typedef trait::image::value_access::direct value_access;
+ typedef trait::image::value_storage::one_block value_storage;
+ typedef trait::image::value_browsing::site_wise_only value_browsing;
+ typedef trait::image::value_io::read_only value_io;
+
+ // site / domain
+ typedef trait::image::localization::basic_grid localization; // FIXME
+ typedef trait::image::dimension::two_d dimension; // FIXME
+
+ // extended domain
+ typedef trait::image::ext_domain::infinite ext_domain;
+ typedef trait::image::ext_value::single ext_value;
+ typedef trait::image::ext_io::read_only ext_io;
+ };
+
+ } // end of namespace mln::trait
+
+
+
+ // FIXME: Doc!
+
+ template <typename T, typename S>
+ struct flat_image : public internal::image_primary< S, flat_image<T,S> >
+ {
+ /// Skeleton.
+ typedef flat_image< tag::value_<T>, tag::pset_<S> > skeleton;
+
+
+ /// Value associated type.
+ typedef T value;
+
+ /// Return type of read-only access.
+ typedef const T& rvalue;
+
+ /// Return type of read-write access.
+ typedef const T& lvalue;
+
+
+ /// Constructor without argument.
+ flat_image();
+
+ /// Constructor.
+ flat_image(const T& val, const S& pset);
+
+ /// Initialization.
+ void init_(const T& val, const S& pset);
+
+ /// Give the definition domain.
+ const S& domain() const;
+
+ /// Test if \p p is valid: always return true.
+ bool has(const mln_psite(S)& p) const;
+
+
+ /// Read-only access to the image value located at point \p p.
+ const T& operator()(const mln_psite(S)& p) const;
+
+ /// Read-write access to the image value located at point \p p.
+ const T& operator()(const mln_psite(S)& p);
+
+
+ // FIXME: Weird...
+
+ /// Value_Set associated type.
+ typedef mln::value::set<T> vset;
+
+ /// Give the set of values of the image.
+ const mln::value::set<T>& values() const;
+
+ // end of FIXME
+
+
+ /// Change the image value.
+ void change_value(const T& val);
+ };
+
+
+
+ template <typename T, typename S, typename J>
+ void init_(tag::image_t, flat_image<T,S>& target, const J& model);
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ // init_
+
+ template <typename T, typename S, typename J>
+ inline
+ void init_(tag::image_t, flat_image<T,S>& target, const J& model)
+ {
+ S pset;
+ init_(tag::domain, pset, model);
+ T dummy;
+ target.init_(dummy, pset);
+ }
+
+
+ // internal::data< flat_image<T,S> >
+
+ namespace internal
+ {
+
+ template <typename T, typename S>
+ inline
+ data< flat_image<T,S> >::data(const T& val, const S& pset)
+ : val_(val),
+ pset_(pset)
+ {
+ }
+
+ } // end of namespace mln::internal
+
+
+ // flat_image<T,S>
+
+ template <typename T, typename S>
+ inline
+ flat_image<T,S>::flat_image()
+ {
+ }
+
+ template <typename T, typename S>
+ inline
+ flat_image<T,S>::flat_image(const T& val, const S& pset)
+ {
+ init_(val, pset);
+ }
+
+ template <typename T, typename S>
+ inline
+ void
+ flat_image<T,S>::init_(const T& val, const S& pset)
+ {
+ mln_precondition(! this->has_data());
+ this->data_ = new internal::data< flat_image<T,S> >(val, pset);
+ }
+
+ template <typename T, typename S>
+ inline
+ const S&
+ flat_image<T,S>::domain() const
+ {
+ return this->data_->pset_;
+ }
+
+ template <typename T, typename S>
+ inline
+ bool
+ flat_image<T,S>::has(const mln_psite(S)&) const
+ {
+ return true;
+ }
+
+ template <typename T, typename S>
+ inline
+ const T&
+ flat_image<T,S>::operator()(const mln_psite(S)& p) const
+ {
+ mln_precondition(this->has_data());
+ return this->data_->val_;
+ }
+
+ template <typename T, typename S>
+ inline
+ const T&
+ flat_image<T,S>::operator()(const mln_psite(S)& p)
+ {
+ mln_precondition(this->has_data());
+ return this->data_->val_;
+ }
+
+ template <typename T, typename S>
+ inline
+ const mln::value::set<T>&
+ flat_image<T,S>::values() const
+ {
+ return vset::the();
+ }
+
+ template <typename T, typename S>
+ inline
+ void
+ flat_image<T,S>::change_value(const T& val)
+ {
+ mln_precondition(this->has_data());
+ this->data_->val_ = val;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_FLAT_IMAGE_HH
Index: mln/core/image/extension_val.hh
--- mln/core/image/extension_val.hh (revision 0)
+++ mln/core/image/extension_val.hh (revision 0)
@@ -0,0 +1,240 @@
+// Copyright (C) 2008 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 MLN_CORE_IMAGE_EXTENSION_VAL_HH
+# define MLN_CORE_IMAGE_EXTENSION_VAL_HH
+
+/*!
+ * \file mln/core/image/extension_val.hh
+ *
+ * \brief Definition of a morpher that extends the domain of an image.
+ *
+ * \todo Use the 'instant' mechanism.
+ */
+
+# include <mln/core/internal/image_identity.hh>
+# include <mln/metal/converts_to.hh>
+
+
+
+namespace mln
+{
+
+ // Forward declaration.
+ template <typename I> struct extension_val;
+
+
+ namespace internal
+ {
+
+ /// \internal Data structure for \c mln::extension_val<I>.
+ template <typename I>
+ struct data< extension_val<I> >
+ {
+ data(I& ima, const mln_value(I)& val_);
+
+ I ima_;
+ mln_value(I) val_;
+ };
+
+ } // end of namespace mln::internal
+
+
+ namespace trait
+ {
+
+ template <typename I>
+ struct image_< extension_val<I> > : image_< I > // Same as I except...
+ {
+ // ...these changes.
+ typedef trait::image::category::identity_morpher category;
+ typedef mln_internal_trait_image_speed_from(I) speed; // Un-fastest.
+
+ // extended domain
+ typedef trait::image::ext_domain::infinite ext_domain;
+ typedef trait::image::ext_value::single ext_value;
+ typedef trait::image::ext_io::read_write ext_io;
+ };
+
+ } // end of namespace mln::trait
+
+
+
+ // FIXME: Doc!
+
+ template <typename I>
+ class extension_val : public internal::image_identity< I, mln_pset(I), extension_val<I> >
+ {
+ public:
+
+ /// Skeleton.
+ typedef extension_val< tag::image_<I> > skeleton;
+ // FIXME: OK when ch_value?
+
+
+ /// Return type of read-only access.
+ typedef mln_value(I) rvalue;
+
+
+ /// Constructor without argument.
+ extension_val();
+
+ /// Constructor from an image \p ima and a value \p val.
+ extension_val(I& ima, const mln_value(I)& val);
+
+ /// Deferred initialization from an image \p ima and a value \p
+ /// val.
+ void init(I& ima, const mln_value(I)& val);
+
+
+ /// Test if \p p is valid. It returns always true.
+ // Tech note: the 'template' allows for multiple input.
+ template <typename P>
+ bool has(const P& p) const;
+
+
+ /// Read-only access to the image value located at site \p p;
+ mln_value(I) operator()(const mln_psite(I)& p) const;
+
+ /// Read-write access to the image value located at site \p p.
+ mln_morpher_lvalue(I) operator()(const mln_psite(I)& p);
+
+
+ /// Read-only access to the value of the extension domain.
+ const mln_value(I)& extension_value() const;
+
+ /// Change the value of the extension domain.
+ void change_extension_value(const mln_value(I)& val);
+ };
+
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ // internal::data< extension_val<I,S> >
+
+ namespace internal
+ {
+
+ template <typename I>
+ inline
+ data< extension_val<I> >::data(I& ima, const mln_value(I)& val)
+ : ima_(ima),
+ val_(val)
+ {
+ }
+
+ } // end of namespace mln::internal
+
+ // extension_val<I>
+
+ template <typename I>
+ inline
+ extension_val<I>::extension_val()
+ {
+ }
+
+ template <typename I>
+ inline
+ extension_val<I>::extension_val(I& ima, const mln_value(I)& val)
+ {
+ init(ima, val);
+ }
+
+ template <typename I>
+ inline
+ void
+ extension_val<I>::init(I& ima, const mln_value(I)& val)
+ {
+ this->data_ = new internal::data< extension_val<I> >(ima, val);
+ }
+
+ template <typename I>
+ template <typename P>
+ inline
+ bool
+ extension_val<I>::has(const P&) const
+ {
+ return true;
+ }
+
+ template <typename I>
+ inline
+ mln_value(I)
+ extension_val<I>::operator()(const mln_psite(I)& p) const
+ {
+ mln_precondition(this->has_data());
+ // if-else is preferred to the ternary op to allow conversions.
+ if (this->data_->ima_.domain().has(p))
+ return this->data_->ima_(p);
+ else
+ return this->data_->val_;
+ }
+
+ template <typename I>
+ inline
+ mln_morpher_lvalue(I)
+ extension_val<I>::operator()(const mln_psite(I)& p)
+ {
+ static mln_value(I) cpy;
+ mln_precondition(this->has_data());
+ // See the above comment about if-else v. ternary.
+ if (this->data_->ima_.domain().has(p))
+ return this->data_->ima_(p);
+ else
+ {
+ // This hack makes the extension value non-modifiable.
+ cpy = this->data_->val_;
+ return cpy;
+ }
+ }
+
+ template <typename I>
+ inline
+ const mln_value(I)&
+ extension_val<I>::extension_value() const
+ {
+ mln_precondition(this->has_data());
+ return this->data_->val_;
+ }
+
+ template <typename I>
+ inline
+ void
+ extension_val<I>::change_extension_value(const mln_value(I)& val)
+ {
+ mln_precondition(this->has_data());
+ this->data_->val_ = val;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_IMAGE_EXTENSION_VAL_HH
Index: mln/core/image/instant.hh
--- mln/core/image/instant.hh (revision 2159)
+++ mln/core/image/instant.hh (working copy)
@@ -28,7 +28,7 @@
#ifndef MLN_CORE_IMAGE_INSTANT_HH
# define MLN_CORE_IMAGE_INSTANT_HH
-/*! \file mln/core/instant.hh
+/*! \file mln/core/image/instant.hh
*
* \brief Definition of a morpher that prevent an image from sharing
* his data.
Index: mln/core/site_set/p_key.hh
--- mln/core/site_set/p_key.hh (revision 2159)
+++ mln/core/site_set/p_key.hh (working copy)
@@ -88,12 +88,12 @@
/// Forward Site_Iterator associated type.
typedef p_double_piter<self_,
- mln_fwd_iter(util::set<K>),
+ mln_fwd_eiter(util::set<K>),
mln_fwd_piter(p_set<P>)> fwd_piter;
/// Backward Site_Iterator associated type.
typedef p_double_piter<self_,
- mln_bkd_iter(util::set<K>),
+ mln_bkd_eiter(util::set<K>),
mln_bkd_piter(p_set<P>)> bkd_piter;
/// Site_Iterator associated type.
@@ -439,7 +439,7 @@
// Update b_.
{
util::set<K> new_b;
- mln_iter(util::set<K>) k(b_);
+ mln_eiter(util::set<K>) k(b_);
for_all(k)
new_b.insert(lut[k] = f(k));
b_ = new_b;
@@ -570,7 +570,7 @@
}
unsigned n = 0;
- mln_iter(util::set<K>) key(b_);
+ mln_eiter(util::set<K>) key(b_);
for_all(key)
{
typename s_t::const_iterator k_s = s_.find(key);
Index: mln/core/site_set/p_mutable_array_of.hh
--- mln/core/site_set/p_mutable_array_of.hh (revision 2159)
+++ mln/core/site_set/p_mutable_array_of.hh (working copy)
@@ -91,12 +91,12 @@
/// Forward Site_Iterator associated type.
typedef p_double_piter<self_,
- mln_fwd_iter(array_),
+ mln_fwd_eiter(array_),
mln_fwd_piter(S)> fwd_piter;
/// Backward Site_Iterator associated type.
typedef p_double_piter<self_,
- mln_bkd_iter(array_),
+ mln_bkd_eiter(array_),
mln_bkd_piter(S)> bkd_piter;
/// Site_Iterator associated type.
Index: mln/core/site_set/p_set_of.hh
--- mln/core/site_set/p_set_of.hh (revision 2159)
+++ mln/core/site_set/p_set_of.hh (working copy)
@@ -88,12 +88,12 @@
/// Forward Site_Iterator associated type.
typedef p_double_piter<self_,
- mln_fwd_iter(set_),
+ mln_fwd_eiter(set_),
mln_fwd_piter(S)> fwd_piter;
/// Backward Site_Iterator associated type.
typedef p_double_piter<self_,
- mln_bkd_iter(set_),
+ mln_bkd_eiter(set_),
mln_bkd_piter(S)> bkd_piter;
/// Site_Iterator associated type.
Index: mln/core/safe.hh
--- mln/core/safe.hh (revision 2159)
+++ mln/core/safe.hh (working copy)
@@ -84,7 +84,6 @@
template <typename I>
class safe_image : public internal::image_identity< I, mln_pset(I), safe_image<I> >
{
- typedef internal::image_identity< I, mln_pset(I), safe_image<I> > super_;
public:
/// Skeleton.
@@ -96,8 +95,7 @@
mln_rvalue(I) operator()(const mln_psite(I)& p) const;
- typedef typename super_::lvalue lvalue;
- lvalue operator()(const mln_psite(I)& p);
+ mln_morpher_lvalue(I) operator()(const mln_psite(I)& p);
/// Const promotion via conversion.
operator safe_image<const I>() const;
Index: mln/core/routine/extend.hh
--- mln/core/routine/extend.hh (revision 0)
+++ mln/core/routine/extend.hh (revision 0)
@@ -0,0 +1,157 @@
+// Copyright (C) 2008 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 MLN_CORE_ROUTINE_EXTEND_HH
+# define MLN_CORE_ROUTINE_EXTEND_HH
+
+/*!
+ * \file mln/core/routine/extend.hh
+ *
+ * \brief Definition of a morpher that extends the domain of an image.
+ *
+ * \todo Use the 'instant' mechanism.
+ * \todo Deal with ambiguities.
+ */
+
+# include <mln/core/image/extension_ima.hh>
+# include <mln/core/image/extension_fun.hh>
+# include <mln/core/image/extension_val.hh>
+
+
+
+namespace mln
+{
+
+
+ /// Routines for domain extension with a function.
+
+ template <typename I, typename F>
+ extension_fun<const I, F>
+ extend(const Image<I>& ima, const Function_v2v<F>& fun);
+
+ template <typename I, typename F>
+ extension_fun<I, F>
+ extend(Image<I>& ima, const Function_v2v<F>& fun);
+
+
+ /// Routines for domain extension with an image.
+
+ template <typename I, typename J>
+ extension_ima<const I, const J>
+ extend(const Image<I>& ima, const Image<J>& ext);
+
+ template <typename I, typename J>
+ extension_ima<I, J>
+ extend(Image<I>& ima, Image<J>& ext);
+
+
+ /// Routines for domain extension with a value.
+
+ template <typename I>
+ extension_val<const I>
+ extend(const Image<I>& ima, const mln_value(I)& val);
+
+ template <typename I>
+ extension_val<I>
+ extend(Image<I>& ima, const mln_value(I)& val);
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ // With a function.
+
+ template <typename I, typename F>
+ inline
+ extension_fun<const I, F>
+ extend(const Image<I>& ima, const Function_v2v<F>& fun)
+ {
+ mlc_converts_to(mln_result(F), mln_value(I))::check();
+ extension_fun<const I, F> tmp(exact(ima), exact(fun));
+ return tmp;
+ }
+
+ template <typename I, typename F>
+ inline
+ extension_fun<I, F>
+ extend(Image<I>& ima, const Function_v2v<F>& fun)
+ {
+ mlc_converts_to(mln_result(F), mln_value(I))::check();
+ extension_fun<I, F> tmp(exact(ima), exact(fun));
+ return tmp;
+ }
+
+
+ // With an image.
+
+ template <typename I, typename J>
+ extension_ima<const I, const J>
+ extend(const Image<I>& ima, const Image<J>& ext)
+ {
+ mlc_converts_to(mln_value(J), mln_value(I))::check();
+ extension_ima<const I, const J> tmp(exact(ima), exact(ext));
+ return tmp;
+ }
+
+ template <typename I, typename J>
+ extension_ima<I, J>
+ extend(Image<I>& ima, Image<J>& ext)
+ {
+ mlc_converts_to(mln_value(J), mln_value(I))::check();
+ extension_ima<I, J> tmp(exact(ima), exact(ext));
+ return tmp;
+ }
+
+
+ // With a value.
+
+ template <typename I>
+ inline
+ extension_val<const I>
+ extend(const Image<I>& ima, const mln_value(I)& val)
+ {
+ extension_val<const I> tmp(exact(ima), val);
+ return tmp;
+ }
+
+ template <typename I>
+ inline
+ extension_val<I>
+ extend(Image<I>& ima, const mln_value(I)& val)
+ {
+ extension_val<I> tmp(exact(ima), val);
+ return tmp;
+ }
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_ROUTINE_EXTEND_HH
Index: mln/core/routine/all.hh
--- mln/core/routine/all.hh (revision 0)
+++ mln/core/routine/all.hh (revision 0)
@@ -0,0 +1,45 @@
+// Copyright (C) 2008 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 MLN_CORE_ROUTINE_ALL_HH
+# define MLN_CORE_ROUTINE_ALL_HH
+
+/*! \file mln/core/routine/all.hh
+ *
+ * \brief File that includes all core routines.
+ *
+ * \todo Move files, update, and activate.
+ */
+
+
+// # include <mln/core/routine/clone.hh>
+// # include <mln/core/routine/exact.hh>
+# include <mln/core/routine/extend.hh>
+// # include <mln/core/routine/initialize.hh>
+
+
+#endif // ! MLN_CORE_ROUTINE_ALL_HH
Index: mln/core/p_runs.hh
--- mln/core/p_runs.hh (revision 2159)
+++ mln/core/p_runs.hh (working copy)
@@ -99,12 +99,12 @@
/// Forward Site_Iterator associated type.
typedef p_double_piter<self_,
- mln_fwd_iter(set_),
+ mln_fwd_eiter(set_),
mln_fwd_piter(p_run<P>)> fwd_piter;
/// Backward Site_Iterator associated type.
typedef p_double_piter<self_,
- mln_bkd_iter(set_),
+ mln_bkd_eiter(set_),
mln_bkd_piter(p_run<P>)> bkd_piter;
/// Site_Iterator associated type.
Index: mln/util/set.hh
--- mln/util/set.hh (revision 2159)
+++ mln/util/set.hh (working copy)
@@ -89,13 +89,13 @@
/// Forward iterator associated type.
- typedef set_fwd_iter<T> fwd_iter;
+ typedef set_fwd_iter<T> fwd_eiter;
/// Backward iterator associated type.
- typedef set_bkd_iter<T> bkd_iter;
+ typedef set_bkd_iter<T> bkd_eiter;
/// Iterator associated type.
- typedef fwd_iter iter;
+ typedef fwd_eiter eiter;
/*! \brief Insert an element \p elt into the set.
Index: mln/util/array.hh
--- mln/util/array.hh (revision 2159)
+++ mln/util/array.hh (working copy)
@@ -74,13 +74,13 @@
/// Forward iterator associated type.
- typedef array_fwd_iter<T> fwd_iter;
+ typedef array_fwd_iter<T> fwd_eiter;
/// Backward iterator associated type.
- typedef array_bkd_iter<T> bkd_iter;
+ typedef array_bkd_iter<T> bkd_eiter;
/// Iterator associated type.
- typedef fwd_iter iter;
+ typedef fwd_eiter eiter;
/// Constructor without arguments.
Index: sandbox/geraud/p_runs__with_dedicated_piter.hh
--- sandbox/geraud/p_runs__with_dedicated_piter.hh (revision 2159)
+++ sandbox/geraud/p_runs__with_dedicated_piter.hh (working copy)
@@ -31,10 +31,6 @@
/*! \file mln/core/p_runs.hh
*
* \brief Definition of a set of point runs.
- *
- * \todo Zed: Use p_double* stuff.
- *
- * \todo Zed: Test for unicity (see FIXMEs).
*/
# include <mln/accu/bbox.hh>
1
0
cleanup-2008 2159: Move new site sets in proper place, cleanup, and bug fix.
by Thierry Geraud 28 Aug '08
by Thierry Geraud 28 Aug '08
28 Aug '08
https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Move new site sets in proper place, cleanup, and bug fix.
Move site set files that only belong to that branch
to a dedicated new directory.
* mln/core/site_set: New directory.
* mln/core/p_double.hh,
* mln/core/p_key.hh,
* mln/core/p_mutable_array_of.hh,
* mln/core/p_set_of.hh,
* mln/core/p_vaccess.hh: Move to...
* mln/core/site_set/p_double.hh,
* mln/core/site_set/p_key.hh,
* mln/core/site_set/p_mutable_array_of.hh,
* mln/core/site_set/p_set_of.hh,
* mln/core/site_set/p_vaccess.hh: ...here.
(file, guards): Update.
* mln/core/p_queue_fast.hh,
* mln/core/alias/p_runs2d.hh,
* mln/core/p_queue.hh,
* mln/core/p_priority_queue.hh,
* mln/core/p_set.hh,
* mln/core/safe.hh,
* mln/core/p_runs.hh: Update.
* doc/tutorial/examples/image_if.cc,
* doc/tutorial/examples/p_queue.cc,
* doc/tutorial/examples/p_vaccess.cc,
* doc/tutorial/examples/p_key.cc,
* doc/tutorial/examples/p_key.2.cc,
* doc/tutorial/examples/p_run.cc,
* doc/tutorial/examples/p_mutable_array_of.cc:
Update and augment.
* mln/core/site_set/all.hh: New.
* mln/trait/site_set/status.txt: Move to...
* mln/core/site_set/status.txt: ...here and update.
Bug fix.
* mln/core/p_queue_fast.hh: Fix doc.
* mln/core/site_set/p_double.hh (todo): Remove; obsolete.
(todo): New.
* mln/core/site_set/p_mutable_array_of.hh,
* mln/core/site_set/p_set_of.hh (site_set_base_):
Fix the 1st param. This base class expects a type to deduce the
site type and, in compound site sets, such type cannot be an
element (a compound).
(doc): Fix.
(has): Implement so remove FIXME.
(insert): Add missing precondition.
* mln/core/site_set/p_mutable_array_of.hh (reserve): New.
* mln/core/safe.hh (speed): Fix.
A couple of site set cleanup.
* mln/core/p_queue.hh: Revamp.
(todo): New.
* mln/core/p_image2d.hh: Copy to...
* mln/core/site_set/p_image.hh: ...this new file.
Revamp to make it generic.
* doc/tutorial/examples/p_image.cc: New.
Also move the image status file.
* mln/trait/image/status.txt: Move to...
* mln/core/image/status.txt: ...here.
doc/tutorial/examples/image_if.cc | 1
doc/tutorial/examples/p_image.cc | 52 ++++
doc/tutorial/examples/p_key.2.cc | 2
doc/tutorial/examples/p_key.cc | 2
doc/tutorial/examples/p_mutable_array_of.cc | 13 -
doc/tutorial/examples/p_queue.cc | 37 ++
doc/tutorial/examples/p_run.cc | 2
doc/tutorial/examples/p_vaccess.cc | 2
mln/core/alias/p_runs2d.hh | 2
mln/core/p_priority_queue.hh | 2
mln/core/p_queue.hh | 242 +++++++++---------
mln/core/p_queue_fast.hh | 38 +-
mln/core/p_runs.hh | 2
mln/core/p_set.hh | 5
mln/core/safe.hh | 3
mln/core/site_set/all.hh | 48 +++
mln/core/site_set/p_double.hh | 13 -
mln/core/site_set/p_image.hh | 362 ++++++++++++++--------------
mln/core/site_set/p_key.hh | 10
mln/core/site_set/p_mutable_array_of.hh | 37 ++
mln/core/site_set/p_set_of.hh | 22 -
mln/core/site_set/p_vaccess.hh | 10
mln/core/site_set/status.txt | 20 -
23 files changed, 544 insertions(+), 383 deletions(-)
Index: doc/tutorial/examples/image_if.cc
--- doc/tutorial/examples/image_if.cc (revision 2158)
+++ doc/tutorial/examples/image_if.cc (working copy)
@@ -1,6 +1,5 @@
# include <mln/core/image2d.hh>
# include <mln/core/image_if.hh>
-# include <mln/core/alias.hh>
# include <mln/debug/iota.hh>
# include <mln/debug/println.hh>
Index: doc/tutorial/examples/p_image.cc
--- doc/tutorial/examples/p_image.cc (revision 0)
+++ doc/tutorial/examples/p_image.cc (revision 0)
@@ -0,0 +1,52 @@
+# include <mln/core/image2d.hh>
+# include <mln/core/p_array.hh>
+# include <mln/core/site_set/p_image.hh>
+# include <mln/debug/println.hh>
+# include <mln/level/fill.hh>
+
+
+template <typename A>
+void picture(const A& arr)
+{
+ using namespace mln;
+
+ image2d<char> ima(5, 5);
+ level::fill(ima, '-');
+
+ unsigned i = 0;
+ mln_piter(A) p(arr);
+ for_all(p)
+ ima(p) = '0' + i++;
+
+ debug::println(ima);
+}
+
+
+
+int main()
+{
+ using namespace mln;
+
+ typedef p_array<point2d> Arr;
+ Arr arr;
+
+ {
+ point2d p(1,1);
+ arr.append(p);
+ dpoint2d dp[] = { right, right, down, down, left, left, up };
+ for (unsigned i = 0; i < 7; ++i)
+ p += dp[i], arr.append(p);
+
+ std::cout << "arr = " << arr << std::endl;
+ picture(arr);
+ }
+
+ typedef image2d<bool> I;
+ I ima(5, 5);
+ p_image<I> s(ima);
+ s += arr;
+ std::cout << "ima = " << s << std::endl;
+ picture(s);
+
+ debug::println(s.image_hook_());
+}
Index: doc/tutorial/examples/p_queue.cc
--- doc/tutorial/examples/p_queue.cc (revision 2158)
+++ doc/tutorial/examples/p_queue.cc (working copy)
@@ -1,4 +1,5 @@
# include <mln/core/image2d.hh>
+# include <mln/core/p_queue.hh>
# include <mln/core/p_queue_fast.hh>
# include <mln/debug/println.hh>
# include <mln/level/fill.hh>
@@ -25,11 +26,26 @@
-int main()
+template <typename P>
+void try_purge(mln::p_queue<P>&)
+{
+ // No-op.
+}
+
+template <typename P>
+void try_purge(mln::p_queue_fast<P>& q)
+{
+ std::cout << "purge!" << std::endl;
+ q.purge();
+ picture(q);
+}
+
+
+template <typename Q>
+void run()
{
using namespace mln;
- typedef p_queue_fast<point2d> Q;
Q q;
{
@@ -45,7 +61,7 @@
picture(q);
{
- Q::psite p(q, 0);
+ mln_psite(Q) p(q, 0);
mln_assertion(q.has(p));
p.change_index(6);
mln_assertion(q.has(p));
@@ -54,17 +70,24 @@
mln_assertion(! q.has(p));
}
- std::cout << "purge!" << std::endl;
- q.purge();
- picture(q);
+ try_purge(q);
{
typedef p_priority<unsigned, Q> PQ;
PQ pq;
- Q::piter p(q);
+ mln_piter(Q) p(q);
for_all(p)
pq.push(p.row() + p.col(), p);
std::cout << pq << std::endl;
}
}
+
+
+int main()
+{
+ using namespace mln;
+ // typedef p_queue<point2d> Q;
+ typedef p_queue_fast<point2d> Q;
+ run<Q>();
+}
Index: doc/tutorial/examples/p_vaccess.cc
--- doc/tutorial/examples/p_vaccess.cc (revision 2158)
+++ doc/tutorial/examples/p_vaccess.cc (working copy)
@@ -9,7 +9,7 @@
# include <mln/labeling/blobs.hh>
# include <mln/core/alias/p_runs2d.hh>
-# include <mln/core/p_vaccess.hh>
+# include <mln/core/site_set/p_vaccess.hh>
# include <mln/core/image_if.hh>
# include <mln/pw/all.hh>
# include <mln/convert/from_to.hh>
Index: doc/tutorial/examples/p_key.cc
--- doc/tutorial/examples/p_key.cc (revision 2158)
+++ doc/tutorial/examples/p_key.cc (working copy)
@@ -1,5 +1,5 @@
# include <mln/core/image2d.hh>
-# include <mln/core/p_key.hh>
+# include <mln/core/site_set/p_key.hh>
# include <mln/debug/println.hh>
# include <mln/level/fill.hh>
Index: doc/tutorial/examples/p_key.2.cc
--- doc/tutorial/examples/p_key.2.cc (revision 2158)
+++ doc/tutorial/examples/p_key.2.cc (working copy)
@@ -1,5 +1,5 @@
# include <mln/core/image2d.hh>
-# include <mln/core/p_key.hh>
+# include <mln/core/site_set/p_key.hh>
# include <mln/value/int_u8.hh>
# include <mln/io/pgm/load.hh>
# include <mln/io/pgm/save.hh>
Index: doc/tutorial/examples/p_run.cc
--- doc/tutorial/examples/p_run.cc (revision 2158)
+++ doc/tutorial/examples/p_run.cc (working copy)
@@ -1,6 +1,6 @@
# include <mln/core/image2d.hh>
# include <mln/core/alias/p_run2d.hh>
-# include <mln/core/p_set_of.hh>
+# include <mln/core/site_set/p_set_of.hh>
# include <mln/convert/from_to.hh>
# include <mln/debug/println.hh>
Index: doc/tutorial/examples/p_mutable_array_of.cc
--- doc/tutorial/examples/p_mutable_array_of.cc (revision 2158)
+++ doc/tutorial/examples/p_mutable_array_of.cc (working copy)
@@ -1,5 +1,5 @@
# include <mln/core/image2d.hh>
-# include <mln/core/p_mutable_array_of.hh>
+# include <mln/core/site_set/p_mutable_array_of.hh>
# include <mln/core/p_run.hh>
# include <mln/convert/from_to.hh>
@@ -46,4 +46,15 @@
display(rs);
// FIXME: Use the "mutable" feature of rs...
+
+
+ {
+ typedef p_mutable_array_of<Runs> Arr; // Array of arrays of runs.
+ Arr arr;
+ arr.insert(rs);
+ arr.insert(rs);
+ std::cout << arr << std::endl;
+ display(arr);
+ }
+
}
Index: mln/core/p_queue_fast.hh
--- mln/core/p_queue_fast.hh (revision 2158)
+++ mln/core/p_queue_fast.hh (working copy)
@@ -63,7 +63,11 @@
- /*! \brief Point queue class (based on p_array<P>).
+ /*! \brief Queue of sites class (based on p_array<P>).
+ *
+ * This container is efficient; FIXME: explain...
+ *
+ * The parameter \c P shall be a site or pseudo-site type.
*/
template <typename P>
class p_queue_fast : public internal::site_set_base_< P, p_queue_fast<P> >
@@ -87,49 +91,49 @@
typedef fwd_piter piter;
- /// Constructor.
+ /// Constructor without argument.
p_queue_fast();
/// Reserve \p n cells.
void reserve(std::size_t n);
- /// Test if \p p belongs to this point set.
+ /// Test if \p p belongs to this site set.
bool has(const psite& p) const;
- /// Test if index \p i belongs to this point set.
+ /// Test if index \p i belongs to this site set.
bool has(const util::index& i) const;
/// This set is always valid so it returns true.
bool is_valid() const;
- /// Test if \p p belongs to this point set.
+ /// Test if \p p belongs to this site set.
bool compute_has(const P& p) const;
- /// Give the number of points.
+ /// Give the number of sites.
unsigned nsites() const;
- /// Push a point \p p in the queue.
+ /// Push a site \p p in the queue.
void push(const P& p);
/// Insertion element associated type.
typedef P i_element;
- /// Insert a point \p p (equivalent as 'push').
+ /// Insert a site \p p (equivalent as 'push').
void insert(const P& p);
- /// Pop (remove) the front point \p p from the queue; \p p is the
- /// least recently inserted point.
+ /// Pop (remove) the front site \p p from the queue; \p p is the
+ /// least recently inserted site.
void pop();
- /// Give the front point \p p of the queue; \p p is the least
- /// recently inserted point.
+ /// Give the front site \p p of the queue; \p p is the least
+ /// recently inserted site.
const P& front() const;
- /// Pop (remove) the front point \p p from the queue; \p p is the
- /// least recently inserted point and give the front point \p p of
- /// the queue; \p p is the least recently inserted point.
+ /// Pop (remove) the front site \p p from the queue; \p p is the
+ /// least recently inserted site and give the front site \p p of
+ /// the queue; \p p is the least recently inserted site.
const P& pop_front();
@@ -140,10 +144,10 @@
void clear();
- /// Return the \p i-th point.
+ /// Return the \p i-th site.
const P& operator[](unsigned i) const;
- /// Return the corresponding std::vector of points.
+ /// Return the corresponding std::vector of sites.
const std::vector<P>& std_vector() const;
/// Return the size of this site set in memory.
Index: mln/core/alias/p_runs2d.hh
--- mln/core/alias/p_runs2d.hh (revision 2158)
+++ mln/core/alias/p_runs2d.hh (working copy)
@@ -34,7 +34,7 @@
*/
# include <mln/core/alias/p_run2d.hh>
-# include <mln/core/p_set_of.hh>
+# include <mln/core/site_set/p_set_of.hh>
namespace mln
Index: mln/core/p_queue.hh
--- mln/core/p_queue.hh (revision 2158)
+++ mln/core/p_queue.hh (working copy)
@@ -30,101 +30,128 @@
/*! \file mln/core/p_queue.hh
*
- * \brief Definition of a point set class based on std::deque.
+ * \brief Definition of a site set based on std::deque.
+ *
+ * \todo Rename 'front' because it is ambiguous for C++ users; we
+ * have:
+ * - 'p_queue::pop' means 'deque::pop_front'
+ * - 'p_queue::pop_front' means 'return deque::front and run
+ * deque::pop_front'
*/
-# include <vector>
# include <deque>
-# include <algorithm>
-# include <iterator>
-
-# include <mln/core/internal/site_set_base.hh>
-# include <mln/core/p_array_piter.hh>
-# include <mln/accu/bbox.hh>
+# include <mln/core/p_array.hh>
namespace mln
{
- // Fwd decls.
- template <typename P> struct p_array_fwd_piter_;
- template <typename P> struct p_array_bkd_piter_;
+ // Forward declaration.
+ template <typename P> class p_queue;
- /*! \brief Point queue class (based on std::deque).
- *
- * This is a mathematical set of points (unique insertion).
- *
- * \todo Make it work with P being a Point_Site.
- * \todo Add a parameter flag to choose another policy for "push"
- * (i.e., no-op if multiple or allow multiple insertions).
+ namespace trait
+ {
+
+ template <typename P>
+ struct site_set_< p_queue<P> >
+ {
+ typedef trait::site_set::nsites::known nsites;
+ typedef trait::site_set::bbox::unknown bbox;
+ typedef trait::site_set::contents::growing contents;
+ typedef trait::site_set::arity::multiple arity;
+ };
+
+ } // end of namespace trait
+
+
+
+ /*! \brief Queue of sites (based on std::deque).
*
- * \warning We have some troubles with point set comparison based on
- * a call to nsites() when this container is multiple.
+ * The parameter \c P shall be a site or pseudo-site type.
*/
template <typename P>
class p_queue : public internal::site_set_base_< P, p_queue<P> >
{
+ typedef p_queue<P> self_;
public:
+ /// Element associated type.
+ typedef P element;
+
+
+ /// Psite associated type.
+ typedef p_indexed_psite<self_> psite;
+
/// Forward Site_Iterator associated type.
- typedef p_array_fwd_piter_<P> fwd_piter;
+ typedef p_indexed_fwd_piter<self_> fwd_piter;
/// Backward Site_Iterator associated type.
- typedef p_array_bkd_piter_<P> bkd_piter;
+ typedef p_indexed_bkd_piter<self_> bkd_piter;
+
+ /// Site_Iterator associated type.
+ typedef fwd_piter piter;
- /// Constructor.
+
+ /// Constructor without argument.
p_queue();
- /// Test is \p p belongs to this point set.
- bool has(const P& p) const;
- /// Give the number of points.
+ /// Test if \p p belongs to this site set.
+ bool has(const psite& p) const;
+
+ /// Test if index \p i belongs to this site set.
+ bool has(const util::index& i) const;
+
+ /// This set is always valid so it returns true.
+ bool is_valid() const;
+
+
+ /// Give the number of sites.
unsigned nsites() const;
- /// Give the exact bounding box.
- const box_<P>& bbox() const;
- /// Push force a point \p p in the queue.
- p_queue<P>& push_force(const P& p);
+ /// Push a site \p p in the queue.
+ void push(const P& p);
+
+ /// Insertion element associated type.
+ typedef P i_element;
+
+ /// Insert a site \p p (equivalent as 'push').
+ void insert(const P& p);
- /// Push a point \p p in the queue.
- p_queue<P>& push(const P& p);
- /// Pop (remove) the front point \p p from the queue; \p p is the
- /// least recently inserted point.
+ /// Pop (remove) the front site \p p from the queue; \p p is the
+ /// least recently inserted site.
void pop();
- /// Give the front point \p p of the queue; \p p is the least
- /// recently inserted point.
+ /// Give the front site \p p of the queue; \p p is the least
+ /// recently inserted site.
const P& front() const;
- /// Give the front point \p p of the queue; \p p is the least
- /// recently inserted point and pop (remove) the front point \p p
- /// from the queue; \p p is the least recently inserted point.
- const P& pop_front();
+ /// Pop (remove) the front site \p p from the queue; \p p is the
+ /// least recently inserted site and give the front site \p p of
+ /// the queue; \p p is the least recently inserted site.
+ P pop_front();
+
/// Clear the queue.
void clear();
- /// Return the corresponding std::vector of points.
- const std::vector<P>& vect() const;
- /// Return the \p i-th point.
+ /// Return the \p i-th site.
const P& operator[](unsigned i) const;
- protected:
+ /// Return the corresponding std::deque of sites.
+ const std::deque<P>& std_deque() const;
- std::deque<P> q_;
+ /// Return the size of this site set in memory.
+ std::size_t memory_size() const;
- mutable std::vector<P> vect_;
- mutable bool vect_needs_update_;
- void vect_update_() const;
-
- mutable accu::bbox<P> bb_;
- mutable bool bb_needs_update_;
- void bb_update_() const;
+ protected:
+
+ std::deque<P> q_;
};
@@ -135,42 +162,35 @@
inline
p_queue<P>::p_queue()
{
- vect_needs_update_ = false;
- bb_needs_update_ = false;
}
template <typename P>
inline
- void
- p_queue<P>::vect_update_() const
+ bool
+ p_queue<P>::has(const psite& p) const
{
- vect_.clear();
- vect_.reserve(q_.size());
- std::copy(q_.begin(), q_.end(),
- std::back_inserter(vect_));
- vect_needs_update_ = false;
+ mln_precondition(p.target_() == this); // FIXME: Refine.
+ if (p.index() < 0 || unsigned(p.index()) >= nsites())
+ return false;
+ // The type of rhs below is mln_site(p_array<P>).
+ mln_invariant(p.to_site() == (*this)[p.index()]);
+ return true;
}
template <typename P>
inline
- void
- p_queue<P>::bb_update_() const
+ bool
+ p_queue<P>::has(const util::index& i) const
{
- bb_.init();
- for (unsigned i = 0; i < q_.size(); ++i)
- bb_.take(q_[i]);
- bb_needs_update_ = false;
+ return i >= 0 && unsigned(i) < nsites();
}
template <typename P>
inline
bool
- p_queue<P>::has(const P& p) const
+ p_queue<P>::is_valid() const
{
- for (unsigned i = 0; i < q_.size(); ++i)
- if (q_[i] == p)
return true;
- return false;
}
template <typename P>
@@ -183,37 +203,10 @@
template <typename P>
inline
- const box_<P>&
- p_queue<P>::bbox() const
- {
- mln_precondition(nsites() != 0);
- if (bb_needs_update_)
- bb_update_();
- return bb_.to_result();
- }
-
- template <typename P>
- inline
- p_queue<P>&
- p_queue<P>::push_force(const P& p)
- {
- q_.push_back(p);
- if (! vect_needs_update_)
- {
- vect_needs_update_ = true;
- bb_needs_update_ = true;
- }
- return *this;
- }
-
- template <typename P>
- inline
- p_queue<P>&
+ void
p_queue<P>::push(const P& p)
{
- mln_precondition(! has(p));
- // FIXME: Our choice is "error if multiple insertions"
- return this->push_force(p);
+ q_.push_back(p);
}
template <typename P>
@@ -221,12 +214,8 @@
void
p_queue<P>::pop()
{
+ mln_precondition(! this->is_empty());
q_.pop_front();
- if (! vect_needs_update_)
- {
- vect_needs_update_ = true;
- bb_needs_update_ = true;
- }
}
template <typename P>
@@ -234,17 +223,17 @@
const P&
p_queue<P>::front() const
{
- mln_precondition(! q_.empty());
+ mln_precondition(! this->is_empty());
return q_.front();
}
template <typename P>
inline
- const P&
+ P
p_queue<P>::pop_front()
{
- const P& res = this->front();
-
+ mln_precondition(! this->is_empty());
+ P res = this->front();
this->pop();
return res;
}
@@ -255,28 +244,39 @@
p_queue<P>::clear()
{
q_.clear();
- vect_.clear();
- vect_needs_update_ = false;
- bb_needs_update_ = false;
}
template <typename P>
inline
- const std::vector<P>&
- p_queue<P>::vect() const
+ const P&
+ p_queue<P>::operator[](unsigned i) const
{
- if (vect_needs_update_)
- vect_update_();
- return vect_;
+ mln_precondition(i < nsites());
+ return q_[i];
}
template <typename P>
inline
- const P&
- p_queue<P>::operator[](unsigned i) const
+ void
+ p_queue<P>::insert(const P& p)
{
- mln_precondition(i < nsites());
- return q_[i];
+ this->push(p);
+ }
+
+ template <typename P>
+ inline
+ const std::deque<P>&
+ p_queue<P>::std_deque() const
+ {
+ return q_;
+ }
+
+ template <typename P>
+ inline
+ std::size_t
+ p_queue<P>::memory_size() const
+ {
+ return sizeof(q_) + nsites() * sizeof(P);
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/core/p_priority_queue.hh
--- mln/core/p_priority_queue.hh (revision 2158)
+++ mln/core/p_priority_queue.hh (working copy)
@@ -36,7 +36,7 @@
*/
# include <map>
-# include <mln/core/p_double.hh>
+# include <mln/core/site_set/p_double.hh>
# include <mln/core/internal/site_set_base.hh>
# include <mln/util/set.hh>
Index: mln/core/p_set.hh
--- mln/core/p_set.hh (revision 2158)
+++ mln/core/p_set.hh (working copy)
@@ -63,8 +63,9 @@
/*! \brief Point set class based on util::set.
*
- * This is a mathematical set of points (not a multi-set). The
- * parameter \p P shall be a Point type.
+ * This is a mathematical set of sites (not a multi-set).
+ *
+ * The parameter \c P shall be a site or pseudo-site type.
*/
template <typename P>
class p_set : public internal::site_set_base_< P, p_set<P> >
Index: mln/core/site_set/p_image.hh
--- mln/core/site_set/p_image.hh (revision 0)
+++ mln/core/site_set/p_image.hh (working copy)
@@ -25,252 +25,262 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_CORE_P_IMAGE2D_HH
-# define MLN_CORE_P_IMAGE2D_HH
+#ifndef MLN_CORE_SITE_SET_P_IMAGE_HH
+# define MLN_CORE_SITE_SET_P_IMAGE_HH
-/*! \file mln/core/p_image2d.hh
+/*! \file mln/core/site_set/p_image.hh
*
- * \brief Definition of a point set class based on a image of booleans.
+ * \brief Definition of a site set class based on an image of
+ * Booleans.
+ *
+ * \todo Add an init method (deferred initialization).
*/
-# include <mln/core/internal/site_set_base.hh>
-# include <mln/core/box2d.hh>
-# include <mln/core/image2d.hh>
-# include <mln/core/sub_image.hh>
-
-# include <mln/accu/bbox.hh>
-# include <mln/geom/ncols.hh>
-# include <mln/accu/bbox.hh>
-# include <mln/level/fill.hh>
+# include <mln/core/pset_if.hh>
+# include <mln/fun/ops.hh>
+# include <mln/pw/value.hh>
+# include <mln/pw/cst.hh>
+# include <mln/level/fill_with_value.hh>
+
-# include <mln/level/memset_.hh>
namespace mln
{
+ // Forward declaration.
+ template <typename I> class p_image;
+
- // Fwd decls.
- template <typename P> struct p_image2d_fwd_piter_;
- template <typename P> struct p_image2d_bkd_piter_;
+ namespace trait
+ {
- template <typename P>
- class p_image2d : public internal::site_set_base_<P, p_image2d<P> >
+ template <typename I>
+ struct site_set_< p_image<I> >
{
+ typedef trait::site_set::nsites::known nsites;
+ typedef trait::site_set::bbox::unknown bbox; // FIXME
+ typedef trait::site_set::contents::free contents;
+ typedef trait::site_set::arity::unique arity;
+ };
+
+ } // end of namespace trait
+
+
+
+ template <typename I>
+ class p_image : public internal::site_set_base_< mln_psite(I), p_image<I> >
+ {
+ typedef mln_pset(I) S_;
+ typedef fun::eq_p2b_expr_< pw::value_<I>, pw::cst_<bool> > F_;
public:
- typedef image2d<bool> image_type;
+ /// Equivalent site_set type.
+ typedef pset_if<S_, F_> S;
+
+ /// Conversion towards the equivalent site set.
+ operator S() const;
+
+
+ /// Element associated type.
+ typedef mln_psite(I) element;
+
+
+ /// Psite associated type.
+ typedef mln_psite(I) psite;
/// Forward Site_Iterator associated type.
- typedef p_image2d_fwd_piter_<P> fwd_piter;
+ typedef mln_fwd_piter(S) fwd_piter;
/// Backward Site_Iterator associated type.
- typedef p_image2d_bkd_piter_<P> bkd_piter;
+ typedef mln_bkd_piter(S) bkd_piter;
+
+ /// Site_Iterator associated type.
+ typedef mln_piter(S) piter;
+
+
+ /// Constructor without argument.
+ p_image();
/// Constructor.
- p_image2d(int nrows, int ncols);
- p_image2d(const box2d& b);
+ p_image(const I& ima);
- /// Insert a point \p p.
- p_image2d<P>& insert(const P p);
- template <typename S>
- p_image2d<P>& insert(const Site_Set<S>& set);
-
- /// Remove a point \p p.
- p_image2d<P>& remove(const P p);
- template <typename S>
- p_image2d<P>& remove(const Site_Set<S>& set);
-
- /// Give the number of points.
- unsigned npoints() const;
- /// Test is \p p belongs to this point set.
- bool has(const P& p) const;
- /// Test if the set is empty.
- bool is_empty() const;
+ /// Test is the psite \p p belongs to this site set.
+ bool has(const psite&) const;
- /// Give the exact bounding box.
- const box_<mln_point(P)>& bbox();;
- /// Clear this set.
- void clear();
+ /// Test if this site set is valid, i.e., initialized.
+ bool is_valid() const;
- /// Hook to the image2d
- const image2d<bool>& image() const;
- image2d<bool>& image_non_const();
- private:
- image2d<bool> points_;
- unsigned npoints_;
- accu::bbox<P> bb_;
- bool bb_need_update_;
- };
+ /// Give the number of sites.
+ unsigned nsites() const;
-# ifndef MLN_INCLUDE_ONLY
+ /// Insertion element associated type.
+ typedef psite i_element;
- template <typename P>
- p_image2d<P>::p_image2d(int nrows, int ncols)
- : points_(nrows, ncols, 0),
- npoints_(0),
- bb_need_update_(false)
- {
- level::fill(points_, false);
- }
+ /// Insert a site \p p.
+ void insert(const psite& p);
- template <typename P>
- p_image2d<P>::p_image2d(const box2d& b)
- : points_(b),
- npoints_(0),
- bb_need_update_(false)
- {
- level::fill(points_, false);
- }
+ /// Removal element associated type.
+ typedef psite r_element;
+ /// Remove a site \p p.
+ void remove(const psite& p);
- template <typename P>
- p_image2d<P>&
- p_image2d<P>::insert(const P p)
- {
- if (points_(p) == false)
- {
- bb_.take(p);
- points_(p) = true;
- npoints_++;
- }
- return *this;
- }
- template <typename P>
- template <typename S>
- p_image2d<P>&
- p_image2d<P>::insert(const Site_Set<S>& set_)
- {
- const S& set = exact(set_);
- mln_fwd_piter(S) p(set);
- for_all(p)
- if (this->points_.has(p))
- this->insert(p);
- return *this;
- }
+ /// Change the status in/out of a site \p p.
+ void toggle(const psite& p);
- template <typename P>
- p_image2d<P>&
- p_image2d<P>::remove(const P p)
- {
- if (points_(p) == true)
- {
- points_(p) = false;
- npoints_--;
- if (npoints_ == 0)
- {
- bb_.init();
- bb_need_update_ = false;
- }
- else
- bb_need_update_ = true;
+ /// Return the size of this site set in memory.
+ std::size_t memory_size() const;
- }
- return *this;
- }
- template <typename P>
- template <typename S>
- p_image2d<P>&
- p_image2d<P>::remove(const Site_Set<S>& set_)
+ /// Clear this set.
+ void clear();
+
+
+ /// Hook to the image
+ const I& image_hook_() const;
+
+ private:
+
+ I ima_;
+ unsigned nsites_;
+ };
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename I>
+ inline
+ p_image<I>::operator S() const
{
- const S& set = exact(set_);
- if (this->is_empty())
- return *this;
- mln_fwd_piter(S) p(set);
- for_all(p)
- if (this->points_.has(p))
- this->remove(p);
+ S tmp(ima_.domain(), pw::value(ima_) == pw::cst(true));
+ return tmp;
+ }
- return *this;
+ template <typename I>
+ inline
+ p_image<I>::p_image()
+ {
+ nsites_ = 0;
}
- template <typename P>
- unsigned
- p_image2d<P>::npoints() const
+ template <typename I>
+ inline
+ p_image<I>::p_image(const I& ima)
{
- return npoints_;
+ mln_precondition(ima.has_data());
+ ima_ = ima;
+ clear();
}
- template <typename P>
+ template <typename I>
+ inline
bool
- p_image2d<P>::has(const P& p) const
+ p_image<I>::has(const psite& p) const
{
- return points_(p);
+ mln_precondition(is_valid());
+ return ima_.domain().has(p) && ima_(p) == true;
}
- template <typename P>
+ template <typename I>
+ inline
bool
- p_image2d<P>::is_empty() const
+ p_image<I>::is_valid() const
{
- return npoints_ == 0;
+ return ima_.has_data();
}
-
- template <typename P>
+ template <typename I>
inline
- const box_<mln_point(P)>&
- p_image2d<P>::bbox()
- {
- mln_precondition(npoints() != 0);
- if (bb_need_update_)
+ unsigned
+ p_image<I>::nsites() const
{
- bb_.init();
- mln_fwd_piter(p_image2d<P>) p(*this);
- for_all(p)
- bb_.take(p);
- bb_need_update_ = false;
+ return nsites_;
}
- return bb_.to_result();
+ template <typename I>
+ inline
+ void
+ p_image<I>::insert(const psite& p)
+ {
+ mln_precondition(is_valid());
+ mln_precondition(ima_.domain().has(p));
+ if (ima_(p) == true)
+ return; // No-op.
+ ima_(p) = true;
+ ++nsites_;
}
-
- template <typename P>
+ template <typename I>
+ inline
void
- p_image2d<P>::clear()
+ p_image<I>::remove(const psite& p)
{
- if (npoints_ == 0)
- return;
-
- unsigned bb_nrows = geom::nrows(bb_.to_result());
- unsigned ima_nrows = geom::nrows(points_);
+ mln_precondition(is_valid());
+ mln_precondition(ima_.domain().has(p));
+ if (ima_(p) == false)
+ return; // No-op.
+ ima_(p) = false;
+ mln_assertion(nsites_ > 0);
+ --nsites_;
+ }
- if (bb_nrows * 3 < ima_nrows * 2)
+ template <typename I>
+ inline
+ void
+ p_image<I>::toggle(const psite& p)
{
- unsigned bb_ncols = geom::ncols(bb_.to_result());
- mln_line_piter_(image2d<bool>) p(bb_.to_result());
- for_all(p)
+ mln_precondition(is_valid());
+ mln_precondition(ima_.domain().has(p));
+ if (ima_(p) == true)
+ {
+ // Removal.
+ ima_(p) = false;
+ mln_assertion(nsites_ > 0);
+ --nsites_;
+ }
+ else
{
- level::memset_(points_, p, false, bb_ncols);
+ // Insertion.
+ ima_(p) = true;
+ ++nsites_;
}
}
- else
- level::fill(inplace(points_), false);
- npoints_ = 0;
- bb_.init();
- bb_need_update_ = false;
+ template <typename I>
+ inline
+ std::size_t
+ p_image<I>::memory_size() const
+ {
+ if (! is_valid())
+ return sizeof(*this);
+ return 0; // FIXME
}
- template <typename P>
- const image2d<bool>&
- p_image2d<P>::image() const
+ template <typename I>
+ inline
+ void
+ p_image<I>::clear()
{
- return points_;
+ if (! is_valid())
+ return; // No-op.
+ nsites_ = 0;
+ level::fill_with_value(ima_, false);
}
- template <typename P>
- image2d<bool>&
- p_image2d<P>::image_non_const()
+ template <typename I>
+ inline
+ const I&
+ p_image<I>::image_hook_() const
{
- return points_;
+ mln_precondition(is_valid());
+ return ima_;
}
# endif // ! MLN_INCLUDE_ONLY
@@ -278,8 +288,4 @@
} // end of namespace mln
-# include <mln/core/p_image2d_piter.hh>
-# include <mln/core/p_image2d_pixter.hh>
-
-
-#endif // ! MLN_CORE_P_IMAGE2D_HH
+#endif // ! MLN_CORE_SITE_SET_P_IMAGE_HH
Index: mln/core/site_set/status.txt
--- mln/core/site_set/status.txt (revision 0)
+++ mln/core/site_set/status.txt (working copy)
@@ -7,7 +7,10 @@
ok p_run
ok p_set
-KO p_image2d
+new p_key
+new p_image (replacement of p_image2d)
+
+rm p_image2d
* utility
@@ -15,23 +18,25 @@
* derived
-ok p_runs -> rename as p_run_set
- => better factored as p_set_of<S>
+ok p_vaccess
+ok line2d
new p_set_of
new p_mutable_array_of
-todo p_array_of
+
+TODO p_array_of
+
+rm p_runs (use p_set_of< p_run<P> > instead)
* queue-based
+ok p_queue
ok p_queue_fast
ok p_priority_queue -> rename as p_priority
rm p_priority_queue_fast
rm p_priority_queue_fast_with_array
-KO p_queue
-
* graph-based
KO p_bgraph
@@ -40,9 +45,6 @@
* adapters
-ok p_vaccess
-ok line2d
-
rm pset_array.hh
?? pset_if
Index: mln/core/site_set/p_vaccess.hh
--- mln/core/site_set/p_vaccess.hh (revision 0)
+++ mln/core/site_set/p_vaccess.hh (working copy)
@@ -25,16 +25,16 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_CORE_P_VACCESS_HH
-# define MLN_CORE_P_VACCESS_HH
+#ifndef MLN_CORE_SITE_SET_P_VACCESS_HH
+# define MLN_CORE_SITE_SET_P_VACCESS_HH
-/*! \file mln/core/p_vaccess.hh
+/*! \file mln/core/site_set/p_vaccess.hh
*
* \todo Fix the FIXMEs.
*/
# include <utility>
-# include <mln/core/p_double.hh>
+# include <mln/core/site_set/p_double.hh>
# include <mln/core/internal/site_set_base.hh>
# include <mln/core/internal/pseudo_site_base.hh>
# include <mln/core/internal/site_set_impl.hh>
@@ -276,4 +276,4 @@
} // end of namespace mln
-#endif // ! MLN_CORE_P_VACCESS_HH
+#endif // ! MLN_CORE_SITE_SET_P_VACCESS_HH
Index: mln/core/site_set/p_key.hh
--- mln/core/site_set/p_key.hh (revision 0)
+++ mln/core/site_set/p_key.hh (working copy)
@@ -25,10 +25,10 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_CORE_P_KEY_HH
-# define MLN_CORE_P_KEY_HH
+#ifndef MLN_CORE_SITE_SET_P_KEY_HH
+# define MLN_CORE_SITE_SET_P_KEY_HH
-/*! \file mln/core/p_key.hh
+/*! \file mln/core/site_set/p_key.hh
*
* \brief Definition of a FIXME
*
@@ -38,7 +38,7 @@
# include <map>
# include <mln/core/concept/function.hh>
# include <mln/core/p_set.hh>
-# include <mln/core/p_double.hh>
+# include <mln/core/site_set/p_double.hh>
# include <mln/core/internal/site_set_base.hh>
# include <mln/util/ord.hh>
@@ -649,4 +649,4 @@
} // end of namespace mln
-#endif // ! MLN_CORE_P_KEY_HH
+#endif // ! MLN_CORE_SITE_SET_P_KEY_HH
Index: mln/core/site_set/all.hh
--- mln/core/site_set/all.hh (revision 0)
+++ mln/core/site_set/all.hh (revision 0)
@@ -0,0 +1,48 @@
+// Copyright (C) 2008 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 MLN_CORE_SITE_SET_ALL_HH
+# define MLN_CORE_SITE_SET_ALL_HH
+
+/*! \file mln/core/site_set/all.hh
+ *
+ * \brief File that includes all site_set types.
+ *
+ * \todo Make it effective after having moved image-defining files.
+ */
+
+
+// # include <mln/core/site_set/p_array_of.hh> // FIXME: Uncomment.
+# include <mln/core/site_set/p_image.hh>
+# include <mln/core/site_set/p_key.hh>
+# include <mln/core/site_set/p_mutable_array_of.hh>
+# include <mln/core/site_set/p_set_of.hh>
+# include <mln/core/site_set/p_vaccess.hh>
+// FIXME: Complete...
+
+
+#endif // ! MLN_CORE_SITE_SET_ALL_HH
Index: mln/core/site_set/p_double.hh
--- mln/core/site_set/p_double.hh (revision 0)
+++ mln/core/site_set/p_double.hh (working copy)
@@ -25,19 +25,16 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_CORE_P_DOUBLE_HH
-# define MLN_CORE_P_DOUBLE_HH
+#ifndef MLN_CORE_SITE_SET_P_DOUBLE_HH
+# define MLN_CORE_SITE_SET_P_DOUBLE_HH
-/*! \file mln/core/p_double.hh
+/*! \file mln/core/site_set/p_double.hh
*
* FIXME
*
* \todo Document!
*
- * \todo Zed: IMPORTANT FIXME: a psite shall know about both iterators
- * to be fully located. Think about an image based on
- * p_array_of<p_run<P>>: its psite has to know the first index to
- * access the associated value set.
+ * \todo Add tests about validity of compounded site sets (?)
*/
# include <mln/core/internal/pseudo_site_base.hh>
@@ -317,4 +314,4 @@
} // end of namespace mln
-#endif // ! MLN_CORE_P_DOUBLE_HH
+#endif // ! MLN_CORE_SITE_SET_P_DOUBLE_HH
Index: mln/core/site_set/p_mutable_array_of.hh
--- mln/core/site_set/p_mutable_array_of.hh (revision 0)
+++ mln/core/site_set/p_mutable_array_of.hh (working copy)
@@ -25,10 +25,10 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_CORE_P_MUTABLE_ARRAY_OF_HH
-# define MLN_CORE_P_MUTABLE_ARRAY_OF_HH
+#ifndef MLN_CORE_SITE_SET_P_MUTABLE_ARRAY_OF_HH
+# define MLN_CORE_SITE_SET_P_MUTABLE_ARRAY_OF_HH
-/*! \file mln/core/p_mutable_array_of.hh
+/*! \file mln/core/site_set/p_mutable_array_of.hh
*
* \brief Definition of a mutable array of site sets.
*
@@ -36,9 +36,11 @@
* inherit, when possible, nsites and bbox (just like in p_vaccess).
* It is a different class since such a feature is incompatible with
* the "op[] mutable".
+ *
+ * \todo Zed: Add element browsing.
*/
-# include <mln/core/p_double.hh>
+# include <mln/core/site_set/p_double.hh>
# include <mln/core/internal/site_set_base.hh>
# include <mln/util/array.hh>
@@ -72,7 +74,7 @@
* Parameter \c S is the type of the contained site sets.
*/
template <typename S>
- class p_mutable_array_of : public internal::site_set_base_< mln_element(S),
+ class p_mutable_array_of : public internal::site_set_base_< mln_site(S),
p_mutable_array_of<S> >,
private mlc_is_a(S, Site_Set)::check_t
{
@@ -105,10 +107,14 @@
p_mutable_array_of();
+ /// Reserve memory for \p n elements.
+ void reserve(unsigned n);
+
+
/// Test if \p p belongs to this point set.
- bool has(const psite&) const;
+ bool has(const psite& p) const;
- /// Test if this set of runs is valid.
+ /// Test this set validity so returns always true.
bool is_valid() const;
@@ -116,6 +122,7 @@
typedef S i_element;
/// Insert a site set \p s.
+ /// \pre \p s is valid.
void insert(const S& s);
@@ -172,11 +179,18 @@
template <typename S>
inline
+ void
+ p_mutable_array_of<S>::reserve(unsigned n)
+ {
+ arr_.reserve(n);
+ }
+
+ template <typename S>
+ inline
bool
- p_mutable_array_of<S>::has(const psite&) const
+ p_mutable_array_of<S>::has(const psite& p) const
{
- // FIXME
- return true;
+ return p.index() < arr_.nelements() && arr_[p.index()].has(p.p());
}
template <typename S>
@@ -192,6 +206,7 @@
void
p_mutable_array_of<S>::insert(const S& s)
{
+ mln_precondition(s.is_valid());
arr_.append(s);
}
@@ -283,4 +298,4 @@
} // end of namespace mln
-#endif // ! MLN_CORE_P_MUTABLE_ARRAY_OF_HH
+#endif // ! MLN_CORE_SITE_SET_P_MUTABLE_ARRAY_OF_HH
Index: mln/core/site_set/p_set_of.hh
--- mln/core/site_set/p_set_of.hh (revision 0)
+++ mln/core/site_set/p_set_of.hh (working copy)
@@ -25,15 +25,17 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_CORE_P_SET_OF_HH
-# define MLN_CORE_P_SET_OF_HH
+#ifndef MLN_CORE_SITE_SET_P_SET_OF_HH
+# define MLN_CORE_SITE_SET_P_SET_OF_HH
-/*! \file mln/core/p_set_of.hh
+/*! \file mln/core/site_set/p_set_of.hh
*
* \brief Definition of a set of site sets.
+ *
+ * \todo Zed: Add element browsing.
*/
-# include <mln/core/p_double.hh>
+# include <mln/core/site_set/p_double.hh>
# include <mln/core/internal/site_set_base.hh>
# include <mln/core/internal/site_set_impl.hh>
# include <mln/util/set.hh>
@@ -68,7 +70,7 @@
* Parameter \c S is the type of the contained site sets.
*/
template <typename S>
- class p_set_of : public internal::site_set_base_< mln_element(S),
+ class p_set_of : public internal::site_set_base_< mln_site(S),
p_set_of<S> >,
public internal::site_set_impl<S>,
private mlc_is_a(S, Site_Set)::check_t
@@ -103,7 +105,7 @@
/// Test if \p p belongs to this point set.
- bool has(const psite&) const;
+ bool has(const psite& p) const;
/// Test if this set of runs is valid.
bool is_valid() const;
@@ -164,10 +166,9 @@
template <typename S>
inline
bool
- p_set_of<S>::has(const psite&) const
+ p_set_of<S>::has(const psite& p) const
{
- // FIXME
- return true;
+ return p.index() < s_.nelements() && s_[p.index()].has(p.p());
}
template <typename S>
@@ -183,6 +184,7 @@
void
p_set_of<S>::insert(const S& s)
{
+ mln_precondition(s.is_valid());
s_.insert(s);
this->update_nsites_(s);
this->update_bbox_(s);
@@ -259,4 +261,4 @@
} // end of namespace mln
-#endif // ! MLN_CORE_P_SET_OF_HH
+#endif // ! MLN_CORE_SITE_SET_P_SET_OF_HH
Index: mln/core/safe.hh
--- mln/core/safe.hh (revision 2158)
+++ mln/core/safe.hh (working copy)
@@ -70,8 +70,9 @@
template <typename I>
struct image_< safe_image<I> > : image_< I > // Same as I except...
{
- // ...this change.
+ // ...these changes.
typedef trait::image::category::identity_morpher category;
+ typedef mln_internal_trait_image_speed_from(I) speed; // Un-fastest.
};
} // end of namespace mln::trait
Index: mln/core/p_runs.hh
--- mln/core/p_runs.hh (revision 2158)
+++ mln/core/p_runs.hh (working copy)
@@ -40,7 +40,7 @@
# include <mln/accu/bbox.hh>
# include <mln/core/p_run.hh>
-# include <mln/core/p_double.hh>
+# include <mln/core/site_set/p_double.hh>
# include <mln/core/internal/piter_adaptor.hh>
# include <mln/util/set.hh>
1
0
27 Aug '08
https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Fix a couple of bugs and augment tutorial examples.
* doc/tutorial/examples/p_array.cc: Augment with a test on p_array
update.
* doc/tutorial/examples/p_array.2.cc: Augment with index
manipulation.
* doc/tutorial/examples/p_vaccess.cc: Augment with extra output.
* mln/trait/site_set/status.txt (pset_array): Fix status.
* mln/core/p_vaccess.hh (set_1_): Fix return type.
* mln/core/p_double.hh (super): Rename that private typedef as...
(super_): ...this.
(change_target): New overriding in p_double_piter. That fixes a
bug since such iterators have to perform some extra
code (w.r.t. the inherited method) when setting the site set.
doc/tutorial/examples/p_array.2.cc | 9 +++
doc/tutorial/examples/p_array.cc | 9 +++
doc/tutorial/examples/p_vaccess.cc | 85 +++++++++++++++++++++++++++++++------
mln/core/p_double.hh | 19 ++++++--
mln/core/p_vaccess.hh | 4 -
mln/trait/site_set/status.txt | 3 -
6 files changed, 110 insertions(+), 19 deletions(-)
Index: doc/tutorial/examples/p_array.cc
--- doc/tutorial/examples/p_array.cc (revision 2157)
+++ doc/tutorial/examples/p_array.cc (working copy)
@@ -75,6 +75,7 @@
<< index_of_in(p, arr2) << " in arr2, #"
<< index_of_in(p, arr1) << " in arr1" << std::endl;
}
+ std::cout << std::endl;
}
mln_invariant(arr2 < arr1);
@@ -89,6 +90,14 @@
}
}
+ {
+ // Fun stuff:
+
+ arr1[0] = point2d(0,0);
+ picture(arr1);
+ picture(arr2);
+ }
+
}
}
Index: doc/tutorial/examples/p_array.2.cc
--- doc/tutorial/examples/p_array.2.cc (revision 2157)
+++ doc/tutorial/examples/p_array.2.cc (working copy)
@@ -81,4 +81,13 @@
// FIXME: j does NOT convert to int because index is NOT a proxy
// NOTA: make index be a proxy, so equip it with every op it needs.
+
+ for (i = 0; i < n; i = i + 1)
+ {
+ std::cout << "i=" << i << ": ";
+ for_all(j)
+ std::cout << arr[(int(j.to_site()) + n) % n] << ' ';
+ std::cout << std::endl;
+ }
+
}
Index: doc/tutorial/examples/p_vaccess.cc
--- doc/tutorial/examples/p_vaccess.cc (revision 2157)
+++ doc/tutorial/examples/p_vaccess.cc (working copy)
@@ -3,6 +3,7 @@
# include <mln/value/int_u8.hh>
# include <mln/level/fill.hh>
+# include <mln/level/paste.hh>
# include <mln/debug/println.hh>
# include <mln/util/timer.hh>
# include <mln/labeling/blobs.hh>
@@ -13,6 +14,8 @@
# include <mln/pw/all.hh>
# include <mln/convert/from_to.hh>
+# include <mln/core/var.hh>
+
template <typename I, typename S>
@@ -64,9 +67,49 @@
mlc_equal(Arr::element, p_run2d)::check();
Arr arr;
- convert::from_to(lab | (pw::value(lab) != pw::cst(0u)), arr);
+ mln_VAR(sub, lab | (pw::value(lab) != pw::cst(0u)));
+ debug::println(sub);
+
+ convert::from_to(sub, arr);
mln_assertion(arr.nsites() == n);
+ {
+ std::cout << "arr = ";
+ mln_piter_(Arr) p(arr);
+ for_all(p)
+ std::cout << p << ' ';
+ std::cout << std::endl;
+ }
+
+ std::cout << std::endl;
+
+ {
+ for (unsigned l = 0; l <= nlabels; ++l)
+ {
+ std::cout << "arr(" << l << ") = ";
+ mln_piter_(p_runs2d) p(arr(l));
+ for_all(p)
+ std::cout << p << ' ';
+ std::cout << std::endl;
+ }
+ }
+
+ std::cout << std::endl;
+
+ {
+ for (unsigned l = 0; l <= nlabels; ++l)
+ {
+ std::cout << "arr(" << l << ") = ";
+ mln_iter_(util::set<p_run2d>) r(arr(l).set_hook_());
+ for_all(r)
+ std::cout << r << ' ';
+ std::cout << std::endl;
+ }
+ }
+
+ std::cout << std::endl;
+
+ std::cout << "arr in " << arr.bbox() << std::endl;
for (unsigned l = 0; l <= nlabels; ++l)
{
std::cout << l << ": #" << arr(l).nsites();
@@ -75,22 +118,40 @@
std::cout << std::endl;
}
std::cout << std::endl;
- }
{
- p_runs2d rs;
- convert::from_to(ima, rs);
- mln_assertion(rs.bbox() == ima.bbox());
-
- image2d<int_u8> ima_(ima.domain());
+ image2d<int> ima_(arr.bbox());
level::fill(ima_, 0);
- for (unsigned r = 0; r < rs.nelements(); ++r)
- {
- mln_piter_(p_run2d) p(rs[r]);
- for_all(p)
- ima_(p) = r + 1;
+ for (unsigned l = 1; l <= nlabels; ++l)
+ for (unsigned r = 0; r < arr(l).nelements(); ++r)
+ level::paste(pw::cst(10 * l + r) | arr(l)[r], ima_);
+ debug::println(ima_);
}
+
+ {
+ image2d<int> ima_(arr.bbox());
+ level::fill(ima_, 0);
+ for (unsigned l = 1; l <= nlabels; ++l)
+ if (arr(l).nsites() > 1)
+ level::paste(pw::cst(l) | arr(l), ima_);
debug::println(ima_);
}
+ }
+
+// {
+// p_runs2d rs;
+// convert::from_to(ima, rs);
+// mln_assertion(rs.bbox() == ima.bbox());
+
+// image2d<int_u8> ima_(ima.domain());
+// level::fill(ima_, 0);
+// for (unsigned r = 0; r < rs.nelements(); ++r)
+// {
+// mln_piter_(p_run2d) p(rs[r]);
+// for_all(p)
+// ima_(p) = r + 1;
+// }
+// debug::println(ima_);
+// }
}
Index: mln/trait/site_set/status.txt
--- mln/trait/site_set/status.txt (revision 2157)
+++ mln/trait/site_set/status.txt (working copy)
@@ -43,7 +43,8 @@
ok p_vaccess
ok line2d
+rm pset_array.hh
+
?? pset_if
KO p_array_bb
-KO pset_array.hh
Index: mln/core/p_vaccess.hh
--- mln/core/p_vaccess.hh (revision 2157)
+++ mln/core/p_vaccess.hh (working copy)
@@ -140,7 +140,7 @@
std::size_t memory_size() const;
// Required by p_double-related classes.
- const V& set_1_() const;
+ const mln::value::set<V>& set_1_() const;
const S& set_2_(const V& v) const;
protected:
@@ -257,7 +257,7 @@
template <typename V, typename S>
inline
- const V&
+ const mln::value::set<V>&
p_vaccess<V,S>::set_1_() const
{
return vs_;
Index: mln/core/p_double.hh
--- mln/core/p_double.hh (revision 2157)
+++ mln/core/p_double.hh (working copy)
@@ -94,7 +94,7 @@
p_double_piter<S,I1,I2> >
{
typedef p_double_piter<S,I1,I2> self_;
- typedef internal::site_set_iterator_base<S,self_> super;
+ typedef internal::site_set_iterator_base<S,self_> super_;
public:
/// Constructor with no argument.
@@ -103,6 +103,9 @@
/// Constructor.
p_double_piter(const S& s);
+ /// Change the site set targeted by this iterator.
+ void change_target(const S& newtarget);
+
/// Test if the iterator is valid.
bool is_valid_() const;
@@ -116,8 +119,8 @@
void next_();
protected:
- using super::p_;
- using super::s_;
+ using super_::p_;
+ using super_::s_;
private:
I1 i1_;
@@ -219,7 +222,15 @@
p_double_piter<S,I1,I2>::p_double_piter(const S& s)
{
this->change_target(s);
- i1_.change_target(s.set_1_());
+ }
+
+ template <typename S, typename I1, typename I2>
+ inline
+ void
+ p_double_piter<S,I1,I2>::change_target(const S& newtarget)
+ {
+ this->super_::change_target(newtarget);
+ i1_.change_target(newtarget.set_1_());
invalidate_();
}
1
0
26 Aug '08
https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Make the 'plain' and 'safe' morphers work.
* doc/tutorial/examples/image_plain.cc: New.
* doc/tutorial/examples/image_safe.cc: New.
* mln/trait/image/status.txt: Update.
* mln/core/safe.hh (data_): Update, i.e., rename as...
(data): ...this.
(trait::image_): New.
* mln/core/plain.hh: Likewise.
(operator=): New overload for 'plain' arg.
(plain): New ctor overload for 'plain' arg.
* mln/core/concept/site_set.hh
(operator==, operator<=): Fix warning.
doc/tutorial/examples/image_plain.cc | 41 ++++++++++++
doc/tutorial/examples/image_safe.cc | 24 +++++++
mln/core/concept/site_set.hh | 4 -
mln/core/plain.hh | 118 ++++++++++++++++++++++++-----------
mln/core/safe.hh | 56 ++++++++++++----
mln/trait/image/status.txt | 4 -
6 files changed, 193 insertions(+), 54 deletions(-)
Index: doc/tutorial/examples/image_plain.cc
--- doc/tutorial/examples/image_plain.cc (revision 0)
+++ doc/tutorial/examples/image_plain.cc (revision 0)
@@ -0,0 +1,41 @@
+# include <mln/core/image2d.hh>
+# include <mln/core/plain.hh>
+# include <mln/debug/println.hh>
+# include <mln/debug/iota.hh>
+# include <mln/level/fill_with_value.hh>
+
+
+template <typename I>
+void picture(const I& ima)
+{
+ using namespace mln;
+ const unsigned
+ nr = ima.at(0,0).domain().nrows(),
+ nc = ima.at(0,0).domain().ncols();
+ for (unsigned row = 0; row < ima.nrows(); ++row)
+ for (unsigned r = 0; r < nr; ++r)
+ {
+ for (unsigned col = 0; col < ima.ncols(); ++col)
+ for (unsigned c = 0; c < nc; ++c)
+ std::cout << ima.at(row, col)(make::point2d(r,c)) << ' ';
+ std::cout << std::endl;
+ }
+}
+
+
+int main()
+{
+ using namespace mln;
+
+ typedef image2d<int> I;
+ typedef plain<I> I_;
+
+ I ima(3, 3);
+ debug::iota(ima);
+ debug::println(ima);
+
+ image2d<I_> mos(2, 2);
+ level::fill_with_value(mos, ima);
+ level::fill_with_value(mos.at(1,1), 0);
+ picture(mos);
+}
Index: doc/tutorial/examples/image_safe.cc
--- doc/tutorial/examples/image_safe.cc (revision 0)
+++ doc/tutorial/examples/image_safe.cc (revision 0)
@@ -0,0 +1,24 @@
+# include <mln/core/image2d.hh>
+# include <mln/core/line2d.hh>
+# include <mln/core/safe.hh>
+# include <mln/debug/println.hh>
+# include <mln/level/fill.hh>
+# include <mln/level/paste.hh>
+# include <mln/pw/all.hh>
+
+
+
+int main()
+{
+ using namespace mln;
+
+ typedef image2d<int> I;
+ I ima(3, 3);
+ level::fill(ima, 0);
+
+ safe_image<I> ima_(ima);
+ level::paste(pw::cst(8) | p_line2d(make::point2d(-1,-1),
+ make::point2d( 3, 3)),
+ ima_);
+ debug::println(ima);
+}
Index: mln/trait/image/status.txt
--- mln/trait/image/status.txt (revision 2156)
+++ mln/trait/image/status.txt (working copy)
@@ -57,11 +57,11 @@
** identity morpher
new instant
+ok plain
+ok safe
KO decorated_image
KO interpolated
-KO plain
-KO safe
Index: mln/core/safe.hh
--- mln/core/safe.hh (revision 2156)
+++ mln/core/safe.hh (working copy)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007 EPITA Research and Development Laboratory
+// Copyright (C) 2007, 2008 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 MLN_CORE_SAFE_HH
/*!
- * \file safe.hh
+ * \file mln/core/safe.hh
*
* \brief Definition of a morpher that makes image become accessible
* at undefined location.
*
+ * \todo Use 'instant' as the routine safe returns.
*/
-
# include <mln/core/internal/image_identity.hh>
@@ -44,17 +44,18 @@
namespace mln
{
- // Fwd decl.
+ // Forward declaration.
template <typename I> struct safe_image;
+
namespace internal
{
/// \internal Data structure for \c mln::safe_image<I>.
template <typename I>
- struct data_< safe_image<I> >
+ struct data< safe_image<I> >
{
- data_(I& ima, const mln_value(I)& default_value);
+ data(I& ima, const mln_value(I)& default_value);
I ima_;
mln_value(I) default_value_;
@@ -63,6 +64,20 @@
} // end of namespace mln::internal
+ namespace trait
+ {
+
+ template <typename I>
+ struct image_< safe_image<I> > : image_< I > // Same as I except...
+ {
+ // ...this change.
+ typedef trait::image::category::identity_morpher category;
+ };
+
+ } // end of namespace mln::trait
+
+
+
// FIXME: Doc!
template <typename I>
@@ -74,8 +89,9 @@
/// Skeleton.
typedef safe_image< tag::image_<I> > skeleton;
- safe_image(I& ima, const mln_value(I)& default_value);
safe_image();
+ safe_image(I& ima);
+ safe_image(I& ima, const mln_value(I)& default_value);
mln_rvalue(I) operator()(const mln_psite(I)& p) const;
@@ -100,14 +116,14 @@
# ifndef MLN_INCLUDE_ONLY
+ // internal::data< safe_image<I,S> >
+
namespace internal
{
- // internal::data_< safe_image<I,S> >
-
template <typename I>
inline
- data_< safe_image<I> >::data_(I& ima, const mln_value(I)& default_value)
+ data< safe_image<I> >::data(I& ima, const mln_value(I)& default_value)
: ima_(ima),
default_value_(default_value)
{
@@ -119,15 +135,22 @@
template <typename I>
inline
+ safe_image<I>::safe_image()
+ {
+ }
+
+ template <typename I>
+ inline
safe_image<I>::safe_image(I& ima, const mln_value(I)& default_value)
{
- this->data_ = new internal::data_< safe_image<I> >(ima, default_value);
+ this->data_ = new internal::data< safe_image<I> >(ima, default_value);
}
template <typename I>
inline
- safe_image<I>::safe_image()
+ safe_image<I>::safe_image(I& ima)
{
+ this->data_ = new internal::data< safe_image<I> >(ima, mln_value(I)());
}
template <typename I>
@@ -135,6 +158,7 @@
mln_rvalue(I)
safe_image<I>::operator()(const mln_psite(I)& p) const
{
+ mln_precondition(this->has_data());
if (! this->has(p))
return this->data_->default_value_;
return this->data_->ima_(p);
@@ -145,11 +169,13 @@
typename safe_image<I>::lvalue
safe_image<I>::operator()(const mln_psite(I)& p)
{
+ mln_precondition(this->has_data());
static mln_value(I) forget_it_;
- if (! this->has(p))
- // so data_->default_value_ is returned but cannot be modified
- return forget_it_ = this->data_->default_value_;
+ if (this->has(p))
return this->data_->ima_(p);
+ else
+ // A copy of data_->default_value_ is returned.
+ return forget_it_ = this->data_->default_value_;
}
template <typename I>
Index: mln/core/concept/site_set.hh
--- mln/core/concept/site_set.hh (revision 2156)
+++ mln/core/concept/site_set.hh (working copy)
@@ -316,7 +316,7 @@
template <typename Sl, typename Sr>
inline
- util::yes operator==(const Site_Set<Sl>& lhs_, const Site_Set<Sr>& rhs_)
+ util::yes operator==(const Site_Set<Sl>&, const Site_Set<Sr>&)
{
// // FIXME: Same grid!
// const Sl& lhs = exact(lhs_);
@@ -340,7 +340,7 @@
template <typename Sl, typename Sr>
inline
- util::yes operator<=(const Site_Set<Sl>& lhs_, const Site_Set<Sr>& rhs_)
+ util::yes operator<=(const Site_Set<Sl>&, const Site_Set<Sr>&)
{
// // FIXME: Same grid!
// const Sl& lhs = exact(lhs_);
Index: mln/core/plain.hh
--- mln/core/plain.hh (revision 2156)
+++ mln/core/plain.hh (working copy)
@@ -30,73 +30,86 @@
/*! \file mln/core/plain.hh
*
- * \brief Definition of a morpher that prevent an image from sharing
+ * \brief Definition of a morpher that prevents an image from sharing
* his data.
*/
-# include <cmath>
# include <mln/core/internal/image_identity.hh>
# include <mln/core/clone.hh>
+# include <mln/metal/is_not_const.hh>
namespace mln
{
- // Fwd decl.
+ // Forward declaration.
template <typename I> struct plain;
+
namespace internal
{
/// \internal Data structure for \c mln::plain<I>.
template <typename I>
- struct data_< plain<I> >
+ struct data< plain<I> >
{
- data_(const I& ima);
-
+ data(const I& ima);
I ima_;
};
} // end of namespace mln::internal
- /*! \brief FIXME
- *
- */
+
+ namespace trait
+ {
+
template <typename I>
- struct plain : public mln::internal::image_identity< I, mln_pset(I), plain<I> >
+ struct image_< plain<I> > : image_< I > // Same as I except...
{
+ // ...this change.
+ typedef trait::image::category::identity_morpher category;
+ };
- typedef mln::internal::image_identity< I, mln_pset(I), plain<I> > super_;
+ } // end of namespace mln::trait
- /// Point_Site associated type.
- typedef mln_psite(I) psite;
- /// Value associated type.
- typedef mln_value(I) value;
- /// Return type of read-write access.
- typedef mln_lvalue(I) lvalue; // FIXME: Depends on lvalue presence in I.
+ /*! \brief FIXME
+ *
+ */
+ template <typename I>
+ class plain
- /// Return type of read-only access.
- typedef mln_rvalue(I) rvalue;
+ : public mln::internal::image_identity< I, mln_pset(I), plain<I> >,
+ private mlc_is_not_const(I)::check_t
+ {
+ typedef plain<I> self_;
+ typedef mln::internal::image_identity<I, mln_pset(I), self_> super_;
+
+ public:
/// Skeleton.
typedef plain< tag::image_<I> > skeleton;
-
- /// Constructors.
- plain(const I& ima);
+ /// Constructor without argument.
plain();
- /// Read-only access of pixel value at point site \p p.
- /// Mutable access is only OK for reading (not writing).
- //using super_::operator();
+ /// Copy constructor.
+ plain(const plain<I>& rhs);
+
+ /// Copy constructor from an image \p ima.
+ plain(const I& ima);
/// Assignment operator.
- plain& operator=(const I& rhs);
+ plain<I>& operator=(const plain<I>& rhs);
+ /// Assignment operator from an image \p ima.
+ plain<I>& operator=(const I& ima);
- /// Conversion into an I image
+ /// Initialization routine.
+ void init(const I& ima);
+
+ /// Conversion into an image with type \c I.
operator I () const;
};
@@ -104,43 +117,77 @@
# ifndef MLN_INCLUDE_ONLY
+
+ // internal::data< plain<I> >
+
namespace internal
{
- // internal::data_< plain<I> >
-
template <typename I>
inline
- data_< plain<I> >::data_(const I& ima)
+ data< plain<I> >::data(const I& ima)
: ima_(clone(ima))
{
}
} // end of namespace mln::internal
+
+ // plain<I>
+
+ template <typename I>
+ inline
+ plain<I>::plain()
+ {
+ }
+
+ template <typename I>
+ inline
+ plain<I>::plain(const plain<I>& rhs)
+ : super_()
+ {
+ mln_precondition(rhs.has_data());
+ init(rhs.data_->ima_);
+ }
+
template <typename I>
inline
plain<I>::plain(const I& ima)
{
mln_precondition(ima.has_data());
- this->data_ = new internal::data_< plain<I> >(ima);
+ init(ima);
}
-
template <typename I>
inline
- plain<I>::plain()
+ void
+ plain<I>::init(const I& ima)
{
+ mln_precondition(ima.has_data());
+ this->data_ = new internal::data< plain<I> >(ima);
}
template <typename I>
inline
plain<I>&
- plain<I>::operator=(const I& rhs)
+ plain<I>::operator=(const plain<I>& rhs)
{
mln_precondition(rhs.has_data());
+ if (&rhs == this)
+ return *this;
+ this->destroy();
+ init(rhs.data_->ima_);
+ return *this;
+ }
+
+ template <typename I>
+ inline
+ plain<I>&
+ plain<I>::operator=(const I& ima)
+ {
+ mln_precondition(ima.has_data());
this->destroy();
- this->data_ = new internal::data_< plain<I> >(rhs);
+ init(ima);
return *this;
}
@@ -148,6 +195,7 @@
inline
plain<I>::operator I () const
{
+ mln_precondition(this->has_data());
return clone(this->data_->ima_);
}
1
0
https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Revamp the default ordering mechanism.
Revamp the default ordering mechanism (was util::less). It now
relies on the trait solving material so we can now factor
definitions.
* mln/trait/op/ord.hh: New.
* mln/trait/op/all.hh: Update.
* mln/util/ord.hh: New.
* mln/util/set.hh,
* mln/core/p_key.hh (util::less): Replace by...
(util::ord): ...this.
* mln/core/point.hh,
* mln/core/dpoint.hh (less_than): Remove.
* mln/algebra/vec.hh,
* mln/core/box.hh,
* mln/core/concept/gpoint.hh,
* mln/core/concept/gdpoint.hh,
* mln/core/line2d.hh,
* mln/core/p_run.hh,
* mln/core/p_runs.hh,
(set_precise_unary_): New specializations.
(util::less): Remove.
* mln/core/concept/site_set.hh
(set_precise_unary_): New specialization without
implementation.
* mln/util/less.hh: Remove.
* mln/util/less_than.hh: Remove.
Disambiguate between aliases (such as point2d) and taking a
variable (with the now obsolete mln_alias macro).
* mln/core/alias.hh: Rename as...
* mln/core/var.hh: ...this.
(mln_alias): Rename as...
(mln_VAR): ...this.
* sandbox/geraud/cs2d/kruskal.cc: Update.
* sandbox/geraud/cs2d/tuto_bis.cc: Update.
Misc.
* doc/tutorial/examples/line2d.cc: Rename as...
* doc/tutorial/examples/p_line2d.cc: ...this.
* mln/trait/all.hh: Fix (c).
* mln/util/index.hh (dindex_): Move to...
* mln/util/dindex.hh: ...this new file.
* mln/util/index.hh,
* mln/util/dindex.hh (operator<): New.
doc/tutorial/examples/p_line2d.cc | 1
mln/algebra/vec.hh | 41 +--------
mln/core/box.hh | 27 +++++-
mln/core/concept/gdpoint.hh | 6 +
mln/core/concept/gpoint.hh | 8 +
mln/core/concept/site_set.hh | 21 +++++
mln/core/dpoint.hh | 45 ----------
mln/core/line2d.hh | 22 +++++
mln/core/p_key.hh | 6 -
mln/core/p_run.hh | 54 ++++---------
mln/core/p_runs.hh | 40 ++-------
mln/core/point.hh | 52 ------------
mln/core/var.hh | 13 +--
mln/trait/all.hh | 2
mln/trait/op/all.hh | 5 -
mln/trait/op/ord.hh | 157 ++++++++++++++++++++++++++++++++++++++
mln/util/dindex.hh | 66 +++------------
mln/util/index.hh | 33 +++----
mln/util/ord.hh | 127 ++++++++++++++++++++++++++++++
mln/util/set.hh | 18 ++--
sandbox/geraud/cs2d/kruskal.cc | 14 +--
sandbox/geraud/cs2d/tuto_bis.cc | 10 +-
22 files changed, 467 insertions(+), 301 deletions(-)
Index: doc/tutorial/examples/p_line2d.cc
--- doc/tutorial/examples/p_line2d.cc (revision 2155)
+++ doc/tutorial/examples/p_line2d.cc (working copy)
@@ -4,7 +4,6 @@
# include <mln/core/line2d.hh>
# include <mln/core/p_set.hh>
-# include <mln/core/alias.hh>
# include <mln/core/sub_image.hh>
# include <mln/level/fill.hh>
# include <mln/debug/println.hh>
Index: mln/trait/all.hh
--- mln/trait/all.hh (revision 2155)
+++ mln/trait/all.hh (working copy)
@@ -1,4 +1,4 @@
-// Copyright (C) 2006 EPITA Research and Development Laboratory
+// Copyright (C) 2006, 2008 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
Index: mln/trait/op/ord.hh
--- mln/trait/op/ord.hh (revision 0)
+++ mln/trait/op/ord.hh (revision 0)
@@ -0,0 +1,157 @@
+// Copyright (C) 2008 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 MLN_TRAIT_OP_ORD_HH
+# define MLN_TRAIT_OP_ORD_HH
+
+/*! \file mln/trait/op/ord.hh
+ *
+ * \brief Declaration of an ordering operator trait.
+ */
+
+# include <mln/trait/op/decl.hh>
+
+
+
+namespace mln
+{
+
+ // Forward declarations.
+ namespace internal {
+ template <typename T> struct ord_less;
+ template <typename T> struct ord_vec;
+ }
+ namespace util {
+ template <typename T> bool ord_strict(const T& lhs, const T& rhs);
+ }
+
+
+ namespace trait
+ {
+
+ namespace op
+ {
+
+ template <typename T>
+ struct ord : public solve_unary<ord, T>
+ {
+ };
+
+ } // end of namespace mln::trait::op
+
+
+
+ template <template <class> class Category, typename T>
+ struct set_unary_< op::ord, Category, T >
+ {
+ typedef mln::internal::ord_less<T> ret;
+ };
+
+
+ } // end of namespace mln::trait
+
+
+ namespace internal
+ {
+
+ template <typename T>
+ struct ord_less
+ {
+ bool strict(const T& lhs, const T& rhs) const;
+ bool weak(const T& lhs, const T& rhs) const;
+ };
+
+ template <typename T>
+ struct ord_vec
+ {
+ bool strict(const T& lhs, const T& rhs) const;
+ bool weak(const T& lhs, const T& rhs) const;
+ };
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ // ord_less
+
+ template <typename T>
+ inline
+ bool
+ ord_less<T>::strict(const T& lhs, const T& rhs) const
+ {
+ return lhs < rhs;
+ }
+
+ template <typename T>
+ inline
+ bool
+ ord_less<T>::weak(const T& lhs, const T& rhs) const
+ {
+ return lhs <= rhs;
+ }
+
+ // ord_vec
+
+ template <typename T>
+ inline
+ bool
+ ord_vec<T>::strict(const T& lhs, const T& rhs) const
+ {
+ for (unsigned i = 0; i < T::dim; ++i)
+ {
+ if (lhs[i] == rhs[i])
+ continue;
+ return mln::util::ord_strict(lhs[i], rhs[i]);
+ }
+ return false;
+ }
+
+ template <typename T>
+ inline
+ bool
+ ord_vec<T>::weak(const T& lhs, const T& rhs) const
+ {
+ for (unsigned i = 0; i < T::dim; ++i)
+ {
+ if (lhs[i] == rhs[i])
+ continue;
+ return mln::util::ord_strict(lhs[i], rhs[i]);
+ }
+ return true;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::trait::internal
+
+} // end of namespace mln
+
+
+# include <mln/util/ord.hh>
+# include <mln/trait/solve.hh>
+
+
+#endif // ! MLN_TRAIT_OP_ORD_HH
Index: mln/trait/op/all.hh
--- mln/trait/op/all.hh (revision 2155)
+++ mln/trait/op/all.hh (working copy)
@@ -1,4 +1,4 @@
-// Copyright (C) 2006 EPITA Research and Development Laboratory
+// Copyright (C) 2006, 2008 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
@@ -76,5 +76,8 @@
# include <mln/trait/op/not.hh>
+// Ordering.
+# include <mln/trait/op/ord.hh>
+
#endif // ! MLN_TRAIT_OP_ALL_HH
Index: mln/core/point.hh
--- mln/core/point.hh (revision 2155)
+++ mln/core/point.hh (working copy)
@@ -31,8 +31,6 @@
/*! \file mln/core/point.hh
*
* \brief Definition of the generic point class mln::point_.
- *
- * \todo Try to generalize less_than with Gl and Gr.
*/
# include <mln/core/def/coord.hh>
@@ -197,38 +195,6 @@
const util::yes& cut_(const point<grid::tick,C>& p);
- namespace util
- {
-
- /*! \brief Ordering "less than" comparison between a couple of
- * points.
- *
- * The ordering is based on a lexicographical ordering over
- * coordinates.
- *
- * Both points have to be defined on the same topology.
- *
- * \warning In the general case this ordering relationship is \em
- * not bound to the way of browsing a domain with a forward point
- * iterator.
- */
- template <typename G, typename Cl, typename Cr>
- struct less_than< point<G,Cl>,
- point<G,Cr> >
- {
- /*! \brief Comparison between a couple of points \a lhs and \a
- * rhs.
- *
- * \return True if \p lhs is before \p rhs in the sense of the
- * coordinates lexicographic comparison, otherwise false.
- */
- bool operator()(const point<G,Cl>& lhs,
- const point<G,Cr>& rhs) const;
- };
-
- } // end of namespace mln::util
-
-
# ifndef MLN_INCLUDE_ONLY
template <typename G, typename C>
@@ -473,24 +439,6 @@
return *the_;
}
-
- namespace util
- {
-
- template <typename G, typename Cl, typename Cr>
- bool
- less_than< point<G,Cl>,
- point<G,Cr> >::operator()(const point<G,Cl>& lhs,
- const point<G,Cr>& rhs) const
- {
- enum { n = G::dim };
- typedef less_than< algebra::vec<n,Cl>, algebra::vec<n,Cr> > less_t;
- static const less_t op = less_t();
- return op(lhs.to_vec(), rhs.to_vec());
- }
-
- } // end of namespace mln::util
-
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln
Index: mln/core/dpoint.hh
--- mln/core/dpoint.hh (revision 2155)
+++ mln/core/dpoint.hh (working copy)
@@ -135,34 +135,6 @@
};
- namespace util
- {
-
- /*! \brief Ordering "less than" comparison between a couple of
- * delta-points.
- *
- * The ordering is based on a lexicographical ordering over
- * coordinates.
- *
- * Both delta-points have to be defined on the same topology.
- */
- template <typename G, typename Cl, typename Cr>
- struct less_than< dpoint<G,Cl>,
- dpoint<G,Cr> >
- {
- /*! \brief Comparison between a couple of delta-points \a lhs
- * and \a rhs.
- *
- * \return True if \p lhs is before \p rhs in the sense of the
- * coordinates lexicographic comparison, otherwise false.
- */
- bool operator()(const dpoint<G,Cl>& lhs,
- const dpoint<G,Cr>& rhs) const;
- };
-
- } // end of namespace mln::util
-
-
# ifndef MLN_INCLUDE_ONLY
template <typename G, typename C>
@@ -291,23 +263,6 @@
return coord_;
}
- namespace util
- {
-
- template <typename G, typename Cl, typename Cr>
- bool
- less_than< dpoint<G,Cl>,
- dpoint<G,Cr> >::operator()(const dpoint<G,Cl>& lhs,
- const dpoint<G,Cr>& rhs) const
- {
- enum { n = G::dim };
- typedef less_than< algebra::vec<n,Cl>, algebra::vec<n,Cr> > less_t;
- static const less_t op = less_t();
- return op(lhs.to_vec(), rhs.to_vec());
- }
-
- } // end of namespace mln::util
-
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln
Index: mln/core/box.hh
--- mln/core/box.hh (revision 2155)
+++ mln/core/box.hh (working copy)
@@ -39,7 +39,6 @@
# include <mln/core/internal/box_impl.hh>
# include <mln/core/point.hh>
# include <mln/literal/origin.hh>
-# include <mln/util/less.hh>
namespace mln
@@ -63,7 +62,14 @@
typedef trait::site_set::arity::unique arity;
};
- } // end of namespace trait
+ template <typename P>
+ struct set_precise_unary_< op::ord, box<P> >
+ {
+ typedef set_precise_unary_< op::ord, box<P> > ret; // Itself.
+ bool strict(const box<P>& lhs, const box<P>& rhs) const;
+ };
+
+ } // end of namespace mln::trait
/*! \brief Generic box class: site set containing points of a
@@ -169,7 +175,7 @@
{
// Validity is: for all i, pmin_[i] <= pmax_[i].
// Nota bene: a one-point box is valid.
- return util::op_less_or_equal(pmin_, pmax_);
+ return util::ord_weak(pmin_, pmax_);
}
template <typename P>
@@ -313,6 +319,21 @@
return ostr << "[" << b.pmin() << ".." << b.pmax() << ']';
}
+ namespace trait
+ {
+
+ template <typename P>
+ inline
+ bool
+ set_precise_unary_< op::ord, box<P> >::strict(const box<P>& lhs, const box<P>& rhs) const
+ {
+ // Lexicographical over "pmin then pmax".
+ return util::ord_lexi_strict(lhs.pmin(), lhs.pmax(),
+ rhs.pmin(), rhs.pmax());
+ }
+
+ } // end of namespace mln::trait
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln
Index: mln/core/p_key.hh
--- mln/core/p_key.hh (revision 2155)
+++ mln/core/p_key.hh (working copy)
@@ -40,7 +40,7 @@
# include <mln/core/p_set.hh>
# include <mln/core/p_double.hh>
# include <mln/core/internal/site_set_base.hh>
-# include <mln/util/less.hh>
+# include <mln/util/ord.hh>
namespace mln
@@ -184,11 +184,11 @@
util::set<K> b_;
// Function: key k -> set of sites {p}.
- typedef std::map<K, p_set<P>, util::less<K> > s_t;
+ typedef std::map<K, p_set<P>, util::ord<K> > s_t;
s_t s_;
// Function: site p -> key k.
- typedef std::map<P, K, util::less<P> > k_t;
+ typedef std::map<P, K, util::ord<P> > k_t;
k_t k_;
// Number of sites.
Index: mln/core/line2d.hh
--- mln/core/line2d.hh (revision 2155)
+++ mln/core/line2d.hh (working copy)
@@ -59,6 +59,13 @@
typedef trait::site_set::arity::unique arity;
};
+ template <>
+ struct set_precise_unary_< op::ord, p_line2d >
+ {
+ typedef set_precise_unary_< op::ord, p_line2d > ret; // Itself.
+ bool strict(const p_line2d& lhs, const p_line2d& rhs) const;
+ };
+
} // end of namespace trait
@@ -297,6 +304,21 @@
return arr_.memory_size() + sizeof(box2d);
}
+
+ namespace trait
+ {
+
+ inline
+ bool
+ set_precise_unary_< op::ord, p_line2d >::strict(const p_line2d& lhs,
+ const p_line2d& rhs) const
+ {
+ return util::ord_lexi_strict(lhs.begin(), lhs.end(),
+ rhs.begin(), rhs.end());
+ }
+
+ } // end of namespace mln::trait
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln
Index: mln/core/var.hh
--- mln/core/var.hh (revision 2155)
+++ mln/core/var.hh (working copy)
@@ -25,19 +25,20 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_CORE_ALIAS_HH
-# define MLN_CORE_ALIAS_HH
+#ifndef MLN_CORE_VAR_HH
+# define MLN_CORE_VAR_HH
-/*! \file mln/core/alias.hh
+/*! \file mln/core/var.hh
*
- * \brief Definition of FIXME
+ * \brief Definition of the macro mln_VAR. Warning: that macro relies
+ * on an extention of g++ (typeof) so it is NOT standard C++.
*/
-#define mln_alias(Var, Expr) \
+#define mln_VAR(Var, Expr) \
\
typeof(Expr) Var = Expr; \
typedef typeof(Expr) Var##_t
-#endif // ! MLN_CORE_ALIAS_HH
+#endif // ! MLN_CORE_VAR_HH
Index: mln/core/p_run.hh
--- mln/core/p_run.hh (revision 2155)
+++ mln/core/p_run.hh (working copy)
@@ -32,15 +32,12 @@
*
* \brief Definition of a run of points.
*
- * \todo Get rid of the index attribute in psite.
- *
* \todo Use a lazy approach (in subj) like in p_array psite.
*/
# include <mln/core/internal/site_set_base.hh>
# include <mln/core/internal/pseudo_site_base.hh>
# include <mln/util/index.hh>
-# include <mln/util/less.hh>
namespace mln
@@ -67,6 +64,13 @@
typedef trait::site_set::arity::unique arity;
};
+ template <typename P>
+ struct set_precise_unary_< op::ord, p_run<P> >
+ {
+ typedef set_precise_unary_< op::ord, p_run<P> > ret; // Itself.
+ bool strict(const p_run<P>& lhs, const p_run<P>& rhs) const;
+ };
+
} // end of namespace trait
@@ -165,19 +169,6 @@
std::ostream& operator<<(std::ostream& ostr, const p_run<P>& r);
- namespace util
- {
-
- template <typename P>
- struct less< p_run<P> >
- {
- bool operator()(const p_run<P>& lhs,
- const p_run<P>& rhs) const;
- };
-
- } // end of namespace mln::util
-
-
// p_run_psite<P>
@@ -378,24 +369,6 @@
- // Ordering.
-
- namespace util
- {
-
- template <typename P>
- inline
- bool
- less< p_run<P> >::operator()(const p_run<P>& lhs,
- const p_run<P>& rhs) const
- {
- return op_less(lhs.start(), rhs.start());
- }
-
- } // end of namespace mln::util
-
-
-
// p_run_psite<P>
template <typename P>
@@ -501,6 +474,19 @@
return *run_;
}
+ namespace trait
+ {
+
+ template <typename P>
+ inline
+ bool
+ set_precise_unary_< op::ord, p_run<P> >::strict(const p_run<P>& lhs, const p_run<P>& rhs) const
+ {
+ return util::ord_strict(lhs.start(), rhs.start());
+ }
+
+ } // end of namespace trait
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln
Index: mln/core/concept/gpoint.hh
--- mln/core/concept/gpoint.hh (revision 2155)
+++ mln/core/concept/gpoint.hh (working copy)
@@ -36,6 +36,7 @@
# include <mln/core/concept/site.hh>
# include <mln/core/concept/gdpoint.hh>
# include <mln/value/concept/scalar.hh>
+# include <mln/util/ord.hh>
namespace mln
@@ -70,6 +71,13 @@
typedef mln_delta(L) ret;
};
+
+ template <typename P>
+ struct set_unary_< op::ord, mln::Gpoint, P >
+ {
+ typedef mln::internal::ord_vec< P > ret;
+ };
+
} // end of namespace mln::trait
Index: mln/core/concept/gdpoint.hh
--- mln/core/concept/gdpoint.hh (revision 2155)
+++ mln/core/concept/gdpoint.hh (working copy)
@@ -65,6 +65,12 @@
typedef L ret;
};
+ template <typename D>
+ struct set_unary_< op::ord, mln::Gdpoint, D >
+ {
+ typedef mln::internal::ord_vec< D > ret;
+ };
+
} // end of namespace mln::trait
Index: mln/core/concept/site_set.hh
--- mln/core/concept/site_set.hh (revision 2155)
+++ mln/core/concept/site_set.hh (working copy)
@@ -42,10 +42,12 @@
# include <mln/metal/not_equal.hh>
# include <mln/metal/is_a.hh>
# include <mln/metal/is_unqualif.hh>
+# include <mln/util/ord.hh>
# include <mln/util/yes.hh> // Temporary include.
+
namespace mln
{
@@ -147,6 +149,25 @@
+ namespace trait
+ {
+
+ template <typename S>
+ struct set_unary_< op::ord, Site_Set, S >
+ {
+ // No definition here.
+
+ // That prevents from calling the inclusion operator ("op<")
+ // which is clearly not the expected ordering...
+
+ // Consequently site sets have to define the way they are
+ // ordered.
+ };
+
+ } // end of namespace mln::trait
+
+
+
# ifndef MLN_INCLUDE_ONLY
namespace internal
Index: mln/core/p_runs.hh
--- mln/core/p_runs.hh (revision 2155)
+++ mln/core/p_runs.hh (working copy)
@@ -65,6 +65,16 @@
typedef trait::site_set::arity::unique arity;
};
+ template <typename P>
+ struct set_precise_unary_< op::ord, p_run_set<P> >
+ {
+ typedef set_precise_unary_< op::ord, p_run_set<P> > ret; // Itself.
+ bool strict(const p_run_set<P>& lhs, const p_run_set<P>& rhs) const
+ {
+ return util::ord_strict(lhs.run(0), rhs.run(0));
+ }
+ };
+
} // end of namespace trait
@@ -183,20 +193,6 @@
std::ostream& operator<<(std::ostream& ostr, const p_run_set<P>& r);
- namespace util
- {
-
- template <typename P>
- struct less< p_run_set<P> >
- {
- bool operator()(const p_run_set<P>& lhs,
- const p_run_set<P>& rhs) const;
- };
-
- } // end of namespace mln::util
-
-
-
# ifndef MLN_INCLUDE_ONLY
@@ -404,22 +400,6 @@
return ostr << r.hook_();
}
-
- namespace util
- {
-
- template <typename P>
- inline
- bool
- less< p_run_set<P> >::operator()(const p_run_set<P>& lhs,
- const p_run_set<P>& rhs) const
- {
- return op_less(lhs.run(0), rhs.run(0));
- }
-
- } // end of namespace mln::util
-
-
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln
Index: mln/algebra/vec.hh
--- mln/algebra/vec.hh (revision 2155)
+++ mln/algebra/vec.hh (working copy)
@@ -42,7 +42,6 @@
# include <mln/trait/all.hh>
# include <mln/trait/value_.hh>
# include <mln/fun/i2v/all_to.hh>
-# include <mln/util/less_than.hh>
# include <mln/debug/format.hh>
# include <mln/value/ops.hh>
@@ -64,19 +63,6 @@
template <unsigned d, typename C> struct h_vec;
- namespace util
- {
-
- template <unsigned n, typename Tl, typename Tr>
- struct less_than< algebra::vec<n,Tl>,
- algebra::vec<n,Tr> >
- {
- bool operator()(const algebra::vec<n,Tl>& lhs,
- const algebra::vec<n,Tr>& rhs) const;
- };
-
- } // end of namespace mln::util
-
namespace trait
{
@@ -96,6 +82,12 @@
typedef algebra::vec<n, mln_sum(T)> sum;
};
+ template <unsigned n, typename T>
+ struct set_precise_unary_< op::ord, mln::algebra::vec<n,T> >
+ {
+ typedef mln::internal::ord_vec< mln::algebra::vec<n,T> > ret;
+ };
+
} // end of namespace mln::trait
@@ -586,27 +578,6 @@
} // end of namespace mln::algebra
- namespace util
- {
-
- template <unsigned n, typename Tl, typename Tr>
- bool
- less_than< algebra::vec<n,Tl>,
- algebra::vec<n,Tr> >::operator()(const algebra::vec<n,Tl>& lhs,
- const algebra::vec<n,Tr>& rhs) const
- {
- for (unsigned i = 0; i < n; ++i)
- {
- if (lhs[i] == rhs[i])
- continue;
- return lhs[i] < rhs[i];
- }
- return false;
- }
-
- } // end of namespace mln::util
-
-
# endif // MLN_INCLUDE_ONLY
} // end of namespace mln
Index: mln/util/ord.hh
--- mln/util/ord.hh (revision 0)
+++ mln/util/ord.hh (revision 0)
@@ -0,0 +1,127 @@
+// Copyright (C) 2008 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 MLN_UTIL_ORD_HH
+# define MLN_UTIL_ORD_HH
+
+/*! \file mln/util/ord.hh
+ *
+ * \brief Definition of an ordering type and routine.
+ */
+
+# include <mln/core/concept/object.hh>
+# include <mln/trait/op/ord.hh>
+
+
+
+namespace mln
+{
+
+ namespace util
+ {
+
+ /// Function-object that defines an ordering between objects with
+ /// type \p T.
+ template <typename T>
+ struct ord
+ {
+ bool operator()(const T& lhs, const T& rhs) const;
+ };
+
+
+
+ template <typename T>
+ bool ord_strict(const T& lhs, const T& rhs);
+
+ template <typename T>
+ bool ord_weak(const T& lhs, const T& rhs);
+
+
+ template <typename T1, typename T2>
+ bool ord_lexi_strict(const T1& lhs_1, const T2& lhs_2,
+ const T1& rhs_1, const T2& rhs_2);
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ // ord<T>
+
+ template <typename T>
+ inline
+ bool
+ ord<T>::operator()(const T& lhs, const T& rhs) const
+ {
+ typedef typename mln::trait::op::ord<T>::ret F;
+ static const F f_ord = F();
+ return f_ord.strict(lhs, rhs);
+ }
+
+ // ord_strict
+
+ template <typename T>
+ inline
+ bool
+ ord_strict(const T& lhs, const T& rhs)
+ {
+ typedef typename mln::trait::op::ord<T>::ret F;
+ static const F f_ord = F();
+ return f_ord.strict(lhs, rhs);
+ }
+
+ // ord_weak
+
+ template <typename T>
+ inline
+ bool ord_weak(const T& lhs, const T& rhs)
+ {
+ typedef typename mln::trait::op::ord<T>::ret F;
+ static const F f_ord = F();
+ return f_ord.weak(lhs, rhs);
+ }
+
+ // ord_lex_strict
+
+ template <typename T1, typename T2>
+ inline
+ bool
+ ord_lexi_strict(const T1& lhs_1, const T2& lhs_2,
+ const T1& rhs_1, const T2& rhs_2)
+ {
+ return
+ util::ord_strict(lhs_1, rhs_1) ||
+ (lhs_1 == rhs_1 && util::ord_strict(lhs_2, rhs_2));
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::util
+
+} // end of namespace mln
+
+
+#endif // ! MLN_UTIL_ORD_HH
Index: mln/util/set.hh
--- mln/util/set.hh (revision 2155)
+++ mln/util/set.hh (working copy)
@@ -44,7 +44,7 @@
# include <iostream>
# include <mln/core/concept/proxy.hh>
-# include <mln/util/less.hh>
+# include <mln/util/ord.hh>
namespace mln
@@ -74,10 +74,10 @@
* The parameter \c T is the element type, which shall not be
* const-qualified.
*
- * The unicity of set elements is handled by the mln::util::less
- * function-object.
+ * The unicity of set elements is handled by the mln::util::ord
+ * mechanism.
*
- * \see mln::util::less
+ * \see mln::util::ord
*/
template <typename T>
class set : public Object< mln::util::set<T> >
@@ -213,7 +213,7 @@
*
* This structure is always up-to-date w.r.t. the set contents.
*/
- mutable std::set< T, mln::util::less<T> > s_;
+ mutable std::set< T, util::ord<T> > s_;
/*! \brief Freeze the contents of the set (update \a v_ from \a
@@ -512,7 +512,9 @@
set<T>::v_has_(const T& elt) const
{
mln_precondition(frozen_);
- if (is_empty() || op_less(elt, v_[0]) || op_less(v_[nelements() - 1], elt))
+ if (is_empty() ||
+ util::ord_strict(elt, v_[0]) ||
+ util::ord_strict(v_[nelements() - 1], elt))
return false;
return v_[dicho_(elt, 0, nelements())] == elt;
}
@@ -527,7 +529,9 @@
if (end - beg <= 1)
return beg;
unsigned med = (beg + end) / 2;
- return op_less(elt, v_[med]) ? dicho_(elt, beg, med) : dicho_(elt, med, end);
+ return util::ord_strict(elt, v_[med])
+ ? dicho_(elt, beg, med)
+ : dicho_(elt, med, end);
}
Index: mln/util/index.hh
--- mln/util/index.hh (revision 2155)
+++ mln/util/index.hh (working copy)
@@ -46,7 +46,7 @@
namespace util
{
- // Fwd decl.
+ // Forward declaration.
template <typename Tag> struct dindex_;
@@ -56,6 +56,8 @@
template <typename Tag = void>
struct index_ // : public Object< index_<Tag> >
{
+ typedef Object<void> category;
+
typedef dindex_<Tag> dpsite;
typedef int coord;
@@ -92,30 +94,20 @@
return cpy;
}
- operator int() const { return i_; }
- };
-
- typedef index_<void> index;
-
-
- template <typename Tag = void>
- struct dindex_ // : public Object< dindex_<Tag> >
+ bool operator<(const index_& rhs) const
{
- typedef index_<Tag> psite;
- typedef index_<Tag> site;
-
- typedef int coord;
- enum { dim = 1 };
-
- int i_;
+ return i_ < rhs.i_;
+ }
- dindex_() {}
- dindex_(int i) : i_(i) {}
+ bool operator<(int i) const
+ {
+ return i_ < i;
+ }
operator int() const { return i_; }
};
- typedef dindex_<void> dindex;
+ typedef index_<void> index;
@@ -130,4 +122,7 @@
} // end of namespace mln
+# include <mln/util/dindex.hh>
+
+
#endif // ! MLN_UTIL_INDEX_HH
Index: mln/util/dindex.hh
--- mln/util/dindex.hh (revision 2155)
+++ mln/util/dindex.hh (working copy)
@@ -25,19 +25,19 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_UTIL_INDEX_HH
-# define MLN_UTIL_INDEX_HH
+#ifndef MLN_UTIL_DINDEX_HH
+# define MLN_UTIL_DINDEX_HH
-/*! \file mln/util/index.hh
+/*! \file mln/util/dindex.hh
*
- * \brief Definition of an "index" type.
+ * \brief Definition of a "delta-index" type.
*
* \todo Remove coord and dim, then make window<dindex> work.
*
* \todo Add inheritance to Object so add operators and traits.
*/
-# include <mln/core/concept/object.hh>
+# include <mln/util/index.hh>
namespace mln
@@ -50,57 +50,14 @@
template <typename Tag> struct dindex_;
- /*! \brief Index structure.
+ /*! \brief Delta-index structure.
*
*/
template <typename Tag = void>
- struct index_ // : public Object< index_<Tag> >
- {
- typedef dindex_<Tag> dpsite;
-
- typedef int coord;
- enum { dim = 1 };
-
- int i_;
-
- index_() {}
- index_(int i) : i_(i) {}
-
- index_<Tag>& operator++()
- {
- ++i_; // Pre-inc.
- return *this;
- }
-
- index_<Tag> operator++(int)
- {
- index_<Tag> cpy(i_ + 1);
- ++i_; // Post-inc.
- return cpy;
- }
-
- index_<Tag>& operator--()
- {
- --i_; // Pre-dec.
- return *this;
- }
-
- index_<Tag> operator--(int)
- {
- index_<Tag> cpy(i_ + 1);
- --i_; // Post-dec.
- return cpy;
- }
-
- operator int() const { return i_; }
- };
-
- typedef index_<void> index;
-
-
- template <typename Tag = void>
struct dindex_ // : public Object< dindex_<Tag> >
{
+ typedef Object<void> category;
+
typedef index_<Tag> psite;
typedef index_<Tag> site;
@@ -112,6 +69,11 @@
dindex_() {}
dindex_(int i) : i_(i) {}
+ bool operator<(const dindex_& rhs) const
+ {
+ return i_ < rhs.i_;
+ }
+
operator int() const { return i_; }
};
@@ -130,4 +92,4 @@
} // end of namespace mln
-#endif // ! MLN_UTIL_INDEX_HH
+#endif // ! MLN_UTIL_DINDEX_HH
Index: sandbox/geraud/cs2d/kruskal.cc
--- sandbox/geraud/cs2d/kruskal.cc (revision 2155)
+++ sandbox/geraud/cs2d/kruskal.cc (working copy)
@@ -174,7 +174,7 @@
} // mln
-#define mln_alias(Var, Expr) typeof(Expr) Var = Expr;
+#define mln_VAR(Var, Expr) typeof(Expr) Var = Expr;
template <typename DS_t, typename U>
@@ -259,7 +259,7 @@
image2d<int_u8> ima(input.nrows() * 2 - 1,
input.ncols() * 2 - 1, 0);
- mln_alias(cell, ima | is_cell);
+ mln_VAR(cell, ima | is_cell);
typedef typeof(cell) cell_t;
debug::println(cell);
@@ -270,7 +270,7 @@
cell(pc) = input(pi);
}
- mln_alias(edge, ima | is_edge);
+ mln_VAR(edge, ima | is_edge);
level::paste(morpho::gradient(edge, nbh_e2c), edge);
// ^^^^^^^
// edge -> neighboring cells
@@ -317,9 +317,9 @@
debug::println(T);
- mln_alias(is_T, pw::value(T) == pw::cst(true));
+ mln_VAR(is_T, pw::value(T) == pw::cst(true));
- mln_alias(dom, (T | is_T).domain());
+ mln_VAR(dom, (T | is_T).domain());
typedef typeof(dom) dom_t;
io::ppm::save(show_edge(T, input.nrows(), input.ncols(), 7),
@@ -332,7 +332,7 @@
// [*] See EOF.
unsigned nbasins;
- mln_alias(wst, morpho::meyer_wst(ima | is_tree, nbh_e2e, nbasins) );
+ mln_VAR(wst, morpho::meyer_wst(ima | is_tree, nbh_e2e, nbasins) );
std::cout << "nbasins : " << nbasins << std::endl;
{
@@ -352,6 +352,6 @@
// have ctor without arg so the init cannot be delayed). As a
// consequence, we cannot have the following code:
//
-// mln_alias(tree, edge | is_T);
+// mln_VAR(tree, edge | is_T);
// typedef typeof(tree) tree_t;
// morpho::meyer_wst(tree, nbh_e2e, nbasins);
Index: sandbox/geraud/cs2d/tuto_bis.cc
--- sandbox/geraud/cs2d/tuto_bis.cc (revision 2155)
+++ sandbox/geraud/cs2d/tuto_bis.cc (working copy)
@@ -128,7 +128,7 @@
-#define mln_alias(Var, Expr) \
+#define mln_VAR(Var, Expr) \
typeof(Expr) Var = Expr;
@@ -177,14 +177,14 @@
image2d<int> ima(3, 5);
- mln_alias(cell, ima | is_cell);
+ mln_VAR(cell, ima | is_cell);
level::fill(cell, fun::p2v::iota);
debug::println(cell);
// 1 2 3
//
// 4 5 6
- mln_alias(edge, ima | is_edge);
+ mln_VAR(edge, ima | is_edge);
level::paste(morpho::gradient(edge, nbh_e2c), edge);
// ^^^^^^^
// edge -> neighbooring cells
@@ -194,7 +194,7 @@
// 1 1
unsigned nbasins;
- mln_alias(wst, morpho::meyer_wst(edge, nbh_e2e, nbasins));
+ mln_VAR(wst, morpho::meyer_wst(edge, nbh_e2e, nbasins));
// ^^^^^^^
// edge -> neighbooring edges
debug::println(wst);
@@ -231,7 +231,7 @@
// YET THOSE VALUES ARE ON EDGES, NOT ON CELLS...
- mln_alias(label, wst.full());
+ mln_VAR(label, wst.full());
debug::println(label);
// 0 2 0 2 0
// 0 0 0 0 0
1
0