953: Add tour3.cc and update.

https://svn.lrde.epita.fr/svn/oln/trunk/olena Index: ChangeLog from Thierry Geraud <thierry.geraud@lrde.epita.fr> Add tour3.cc and update. * doc/tour/tour3.cc: New. * oln/convert: New directory. * oln/convert/to_window.hh: New. * oln/core/internal/f_grid_to_window.hh: New. * oln/core/internal/f_image_to_window.hh: New. * doc/tour/tour2.cc: Add some text. * doc/tour/tour1_extra.cc (include): Fix missing. (at): Update. * doc/tour/tour1.cc: Change a word. * oln/debug/fill.hh (fill_): New. (fill): Update. * oln/debug/print.hh (format): Move into... * oln/debug/format.hh: ...this new file. * oln/core/1d/window1d.hh: Fix. * oln/core/1d/image1d.hh, * oln/core/2d/image2d_b.hh, * oln/core/3d/image3d.hh (init_): New. * oln/core/gen/torus_pset.hh (operator Ps): New. (torus_pset): Fix ctor. * oln/core/gen/niter_has.hh: Update. * oln/core/gen/fun_ops.hh (oln_decl_p2v_cmp_): New overload. * oln/core/concept/image.hh (dpoint): New in Image. * oln/core/internal/box.hh: Add static check. * oln/core/internal/op_image_extended_by_nbh.hh (operator I): New. * oln/core/internal/point_base.hh (point_base_): New ctor overload; decl only. * oln/core/internal/op_pset_such_as_fp2b.hh (pset_such_as_fp2b_fwd_piter_), (pset_such_as_fp2b_bkd_piter_): New ctor overload. * oln/core/internal/iterator_on_points_impl.hh (iterator_on_points_impl_base_): New. (vec): New. * oln/core/internal/iterator_on_points_base.hh (point): Disambiguate. * oln/level/local.hh: Update. * oln/level/clone.hh (clone_): New. (clone): Update. doc/tour/tour1.cc | 2 doc/tour/tour1_extra.cc | 6 doc/tour/tour2.cc | 47 +++ doc/tour/tour3.cc | 331 ++++++++++++++++++++++++++ oln/convert/to_window.hh | 76 +++++ oln/core/1d/image1d.hh | 10 oln/core/1d/window1d.hh | 2 oln/core/2d/image2d_b.hh | 25 - oln/core/3d/image3d.hh | 10 oln/core/concept/image.hh | 1 oln/core/gen/fun_ops.hh | 10 oln/core/gen/niter_has.hh | 10 oln/core/gen/torus_pset.hh | 16 - oln/core/internal/box.hh | 2 oln/core/internal/f_grid_to_window.hh | 118 +++++++++ oln/core/internal/f_image_to_window.hh | 37 ++ oln/core/internal/iterator_on_points_base.hh | 3 oln/core/internal/iterator_on_points_impl.hh | 38 ++ oln/core/internal/op_image_extended_by_nbh.hh | 7 oln/core/internal/op_pset_such_as_fp2b.hh | 17 + oln/core/internal/point_base.hh | 3 oln/debug/fill.hh | 25 + oln/debug/format.hh | 76 +++++ oln/debug/print.hh | 18 - oln/level/clone.hh | 6 oln/level/local.hh | 6 26 files changed, 840 insertions(+), 62 deletions(-) Index: doc/tour/tour2.cc --- doc/tour/tour2.cc (revision 952) +++ doc/tour/tour2.cc (working copy) @@ -29,12 +29,10 @@ #include <oln/core/2d/image2d.hh> #include <oln/core/2d/window2d.hh> -#include <oln/level/fill.hh> #include <oln/debug/println.hh> - // Note to the reader: If you do not have read the tour1.cc file, you // should have a quick look at it before proceeding with this present // file. Some important features and practices are described in the @@ -318,9 +316,52 @@ } // End of 2nd version. + std::cout << std::endl; + + + // Above, p and q behave just like points; for instance, the + // following expressions are valid: + + // int r = p.row(); + // to get the current row value, + + // bool b = img(p); + // to get the pixel value at the current point, + + // or point2d pp = p + dp; + // where dp is a delta-point to get a point nearby p. + + // Yet, p and q are "more than points" since they allow to + // browse/iterate over a set of points, respectivelly, the domain of + // 'img' and the window centered at p. + + + // The domain of 'img' is obtained with "img.points()" and is + // provided to the 'p' object so that it knows how to iterate. + + // For a "basic" image, its set of points is an n-dimensional box. + // In the 2D space, the box type is called 'box2d'. We also have + // 'box1d' and 'box3d' for other dimensions. + + box2d pts = img.points(); + std::cout << "img points are " << pts << std::endl; + // Prints: + // img points are { (0, 0) .. (3, 4) } + + // The type of iterators over a point set is obtained with the + // expression: "name_of_the_point_set_type::piter", where 'piter' + // means "point iterator" for short. + + // The same construction is available for iterators on window + // points, whose types are obtained in a similar way with + // "name_of_the_window_type::qiter". Here the 'q' in 'qiter' + // emphases the fact that a window is not really a set of points but + // "a set of dpoints and a center point". + - // This last version is: + // The second version of our example contrasts with the more + // "classical" ones; it is: // - shorter, // so it is less error-prone for the developer; Index: doc/tour/tour3.cc --- doc/tour/tour3.cc (revision 0) +++ doc/tour/tour3.cc (revision 0) @@ -0,0 +1,331 @@ +// Copyright (C) 2001, 2007 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 51 Franklin Street, Fifth Floor, +// Boston, MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +// File: tour2.cc. + +#include <oln/core/2d/image2d.hh> +#include <oln/core/2d/neighb2d.hh> + +#include <oln/core/gen/such_as.hh> +#include <oln/core/gen/torus_image.hh> +#include <oln/core/gen/pw_value.hh> +#include <oln/core/gen/fun_ops.hh> + +#include <oln/level/fill.hh> +#include <oln/debug/fill.hh> +#include <oln/debug/println.hh> + + +// Note to the reader: you should have read the files tour1.cc and +// tour2.cc before starting with this present file. + + + +// We have encapsulated an algorithm into a procedure which is forward +// declared below so that it can be used in the section 'main'. +template <typename I> void algo(const I& img); + + +// Some functions that will be useful in the following: +bool chessboard(oln::point2d p) +{ + return (p.row() + p.col()) % 2; +} + + + +int main() +{ + using namespace oln; + + // First our domain is 2d box: + box2d b(point2d(0, 0), point2d(2, 2)); + // ^^^^ ^^^^ + // from to + + // We define a binary image with values on that box. + image2d<bool> img(b); + + // With an array of Booleans (1 means true, 0 means false)... + bool vals[] = { 1, 0, 0, + 0, 1, 0, + 0, 1, 1 }; + // ...the debug::fill routine allows for manually initializing + // image data: + debug::fill(inplace(img), vals); + std::cout << "img = " << std::endl; + debug::println(img); + // img + // | - - + // - | - + // - | | + + image2d<int> ima(b); // An image of integers with the same + box2d::piter p(ima.points()); // domain as img... + int i = 0; + for_all(p) + ima(p) = i++; // ...and manually filled with values. + + std::cout << "ima = " << std::endl; + debug::println(ima); + // ima = + // 0 1 2 + // 3 4 5 + // 6 7 8 + + /* HERE + + // The algorithm defined at the end of this file is very close to + // the one of the tour former file. The major difference is that it + // does not rely on a window but on a neighborhood. + + // In image processing, we usually say that "an image has a given + // neighborhood" or that "we associate/embed a neighborhood to/into + // an image". In Olena, that is really the case: the image can + // "have" a neighborhood, meaning that a neighborhood can be added + // to an image in order to obtain an "image with a neighborhood". + + // Joining an image with a neighborhood is performed with the + // operator '+': + algo(ima + c4); // c4 is the 2D neighborhood corresponding to + // 4-connectivity; such as many classical + // neighborhoods it is provided by Olena. + // The result is given below. + + // ---input: + // 0 1 2 + // 1 2 3 + // 2 3 4 + // ---output: + // 0: 1 1 + // 1: 0 2 2 + // 2: 1 3 + // 1: 0 2 2 + // 2: 1 1 3 3 + // 3: 2 2 4 + // 2: 1 3 + // 3: 2 2 4 + // 4: 3 3 + + // That was expectable... + + + // And now for a little test: what is the result of this code? + { + image2d<int> test(ima.points()); + level::fill(inplace(test), ima); + (test + c4).at(1, 1) = 9; + debug::println(test); + } + // and can you tell why? + // The answers are given in the file tour3-test.txt + + + // Now let us start experimenting the genericity of Olena! + + + // First, imagine that you want to restrict the domain of ima to a + // subset of points, a region or whatever. For instance, the + // chessboard function takes a point as argument and returns a + // Boolean so it is like a predicate. We can want to consider only + // the points of ima "such as" this predicate is verified. The + // "such as" mathematical symbol is '|' so let's rock: + + algo((ima | chessboard) + c8); + // gives: + + // ---input: + // 1 + // 3 5 + // 7 + // ---output: + // 1: 3 5 + // 3: 1 7 + // 5: 1 7 + // 7: 3 5 + + // where the blanks in printing the input image denote that the + // corresponding points do NOT belong to the image domain. + + // Another similar example is based on the binary image created at + // the beginning of this tour: + algo((ima | img) + c8); + // which gives: + + // ---input: + // 0 + // 4 + // 7 8 + // ---output: + // 0: 4 + // 4: 0 7 8 + // 7: 4 8 + // 8: 4 7 + + + + // Second, imagine that you want your initial image to get the + // geodesy of a torus, that is, a 2D image wrapped on a torus. + // Points located at the image boundary have neighbors; for + // instance, the point denoted by the 'x' cross below has for + // 4-connectivity neighbors: t, l, r, and b (respectively for top, + // left, right, and bottom): + + // b o o o + // o o o o + // t o o o + // x r o l + + // Let us try: + algo(torus(ima) + c8); + // gives: + + // ---input: + // 0 1 2 + // 3 4 5 + // 6 7 8 + // ---output: + // 0: 8 6 7 2 1 5 3 4 + // 1: 6 7 8 0 2 3 4 5 + // 2: 7 8 6 1 0 4 5 3 + // 3: 2 0 1 5 4 8 6 7 + // 4: 0 1 2 3 5 6 7 8 + // 5: 1 2 0 4 3 7 8 6 + // 6: 5 3 4 8 7 2 0 1 + // 7: 3 4 5 6 8 0 1 2 + // 8: 4 5 3 7 6 1 2 0 + + + + // We can have both the torus geodesy and a sub-domain: + + algo(torus(ima | chessboard) + c8); + algo(torus(ima | img) + c8); + + // which respectively give: + + // ---input: + // 1 + // 3 5 + // 7 + // ---output: + // 1: 7 3 5 + // 3: 1 5 7 + // 5: 1 3 7 + // 7: 3 5 1 + + // and: + + // ---input: + // 0 + // 4 + // 7 8 + // ---output: + // 0: 8 7 4 + // 4: 0 7 8 + // 7: 4 8 0 + // 8: 4 7 0 + + + */ + + // Last, the way a predicate is defined can also rely on some image + // values. For that the user can on the fly provide an expression + // built with the "pw_value" facility, where "pw_" means + // "point-wise" for short: + + algo((ima | (pw_value(ima) < 4)) + c4); + + // In this example, "pw_value(ima)" is the function that represents + // the point-wise value of the 'ima' image, that is, the function + // "p -> ima(p)". This naturally leads to: + + // ---input: + // 0 1 2 + // 3 + // + // ---output: + // 0: 1 3 + // 1: 0 2 + // 2: 1 + // 3: 0 + + + + // From those examples, you should realize that: + + + // +-----------------------------------------------------------+ + // | | + // | The level of "genericity" provided by Olena is rather | + // | high; it means: | + // | | + // | - taking the image dimension you work on; | + // | | + // | - having the type of pixel values you need; | + // | | + // | - choosing the neighborhood you want; | + // | | + // | - changing the geodesy if you need it; | + // | | + // | - being able to restrict the image domain; | + // | | + // | - and many other features that are addressed further | + // | in the tour... | + // | | + // +-----------------------------------------------------------+ + +} + + + + + +// The algorithm 'algo': + +template <typename I> +void algo(const I& img) +{ + std::cout << "---input:" << std::endl; + oln::debug::print(img); + std::cout << "---output:" << std::endl; + + oln_piter(I) p(img.points()); // p iterates on img points + oln_niter(I) n(img, p); // n iterates in img on neighbors of p + + for_all(p) + { + std::cout << oln::debug::format(img(p)) + << ':'; + for_all(n) + std::cout << ' ' + << oln::debug::format(img(n)); + std::cout << std::endl; + } + + std::cout << std::endl; +} Index: doc/tour/tour1_extra.cc --- doc/tour/tour1_extra.cc (revision 952) +++ doc/tour/tour1_extra.cc (working copy) @@ -29,6 +29,8 @@ #include <oln/core/1d/image1d.hh> #include <oln/arith/plus.hh> +#include <oln/debug/println.hh> + int main() @@ -91,7 +93,7 @@ { image1d<int> orig(5); // An original image. for (int i = 0; i < 5; ++i) - orig(i) = i; + orig.at(i) = i; debug::println(orig); // 0 1 2 3 4 @@ -160,7 +162,7 @@ { image1d<int> ima(5); for (int i = 0; i < 5; ++i) - ima(i) = i; + ima.at(i) = i; debug::println(ima); // 0 1 2 3 4 Index: doc/tour/tour1.cc --- doc/tour/tour1.cc (revision 952) +++ doc/tour/tour1.cc (working copy) @@ -311,7 +311,7 @@ // Indeed, the loops above depict the "classical" way to iterate - // over the contents of a 1D image. The next tour file explains + // over the contents of a 1D image. The next tour file introduces // the solution provided by Olena to write better loops... Index: oln/convert/to_window.hh --- oln/convert/to_window.hh (revision 0) +++ oln/convert/to_window.hh (revision 0) @@ -0,0 +1,76 @@ +// Copyright (C) 2007 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 51 Franklin Street, Fifth Floor, +// Boston, MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +#ifndef OLN_CONVERT_TO_WINDOW_HH +# define OLN_CONVERT_TO_WINDOW_HH + +# include <oln/core/concept/image.hh> +# include <oln/core/internal/f_image_to_window.hh> + + +namespace oln +{ + + namespace convert + { + + // Fwd decl. + + template <typename I> + oln_f_image_to_window(I) + to_window(const Binary_Image<I>& input); + + +# ifndef OLN_INCLUDE_ONLY + + // Generic version. + + template <typename I> + oln_f_image_to_window(I) + to_window(const Binary_Image<I>& input) + { + oln_f_image_to_window(I) tmp; + oln_dpoint(I) dp; + oln_piter(I) p(input.points()); + for_all(p) + if (input(p) = true) + { + dp.vec() = p.vec(); + // FIXME: Better s.a. dp = p.to_dpoint(); + tmp.take(dp); + } + return tmp; + } + +# endif // ! OLN_INCLUDE_ONLY + + } // end of namespace oln::convert + +} // end of namespace oln + + +#endif // ! OLN_CONVERT_TO_WINDOW_HH Index: oln/debug/fill.hh --- oln/debug/fill.hh (revision 952) +++ oln/debug/fill.hh (working copy) @@ -39,26 +39,37 @@ { template <typename I, typename V> - void fill(Mutable_Image<I>& in_out, const V values[]); - - template <typename I, typename V> void fill(inplace_<I> in_out, const V values[]); # ifndef OLN_INCLUDE_ONLY - template <typename I> - void fill(Mutable_Image<I>& in_out, const oln_value(I)& value) + namespace impl + { + + template <typename I, typename V> + void fill_(Mutable_Image<I>& in_out, const V values[]) { + unsigned i = 0; oln_piter(I) p(in_out.points()); for_all(p) - in_out(p) = value; + in_out(p) = values[i++]; } + } // end of namespace oln::impl + template <typename I, typename V> void fill(inplace_<I> in_out, const V values[]) { - fill(in_out.unwrap(), values); + impl::fill_(in_out.unwrap(), values); + } + + // Guard. + + template <typename I, typename V> + void fill(const Image<I>&, const V[]) + { + mlc::abort_<I>::check(); // FIXME: Add err msg. } # endif // ! OLN_INCLUDE_ONLY Index: oln/debug/format.hh --- oln/debug/format.hh (revision 0) +++ oln/debug/format.hh (revision 0) @@ -0,0 +1,76 @@ +// Copyright (C) 2006, 2007 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 51 Franklin Street, Fifth Floor, +// Boston, MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +#ifndef OLN_DEBUG_FORMAT_HH +# define OLN_DEBUG_FORMAT_HH + + +namespace oln +{ + + namespace debug + { + + // Fwd decls. + + template <typename T> + const T& + format(const T& value); + + unsigned + format(const unsigned char& value); + + char + format(bool value); + + +# ifndef OLN_INCLUDE_ONLY + + template <typename T> + const T& format(const T& value) + { + return value; + } + + unsigned format(const unsigned char& value) + { + return value; + } + + char format(bool value) + { + return value ? '|' : '-'; + } + +# endif // ! OLN_INCLUDE_ONLY + + } // end of namespace oln::debug + +} // end of namespace oln + + +#endif // ! OLN_DEBUG_FORMAT_HH Index: oln/debug/print.hh --- oln/debug/print.hh (revision 952) +++ oln/debug/print.hh (working copy) @@ -30,6 +30,7 @@ # include <iostream> # include <oln/core/concept/image.hh> +# include <oln/debug/format.hh> # ifdef OLN_ENV_2D # include <oln/core/2d/point2d.hh> @@ -53,23 +54,6 @@ namespace impl { - template <typename T> - const T& format(const T& value) - { - return value; - } - - unsigned format(const unsigned char& value) - { - return value; - } - - char format(bool value) - { - return value ? '|' : '-'; - } - - /// Generic version. template <typename I> Index: oln/core/1d/image1d.hh --- oln/core/1d/image1d.hh (revision 952) +++ oln/core/1d/image1d.hh (working copy) @@ -108,6 +108,9 @@ template <typename T, typename D> bool prepare(image1d<T>& target, with_t, const D& dat); + template <typename T> + bool init_(box1d* this_, const image1d<T>& data); + # ifndef OLN_INCLUDE_ONLY @@ -242,6 +245,13 @@ return box_ok; } + template <typename T> + bool init_(box1d* this_, const image1d<T>& data) + { + *this_ = data.bbox(); + return true; + } + # endif // ! OLN_INCLUDE_ONLY Index: oln/core/1d/window1d.hh --- oln/core/1d/window1d.hh (revision 952) +++ oln/core/1d/window1d.hh (working copy) @@ -36,7 +36,7 @@ { // FIXME: window1d should be an actual type, not an alias... - typedef window_<dpoint1d> window1d; + typedef gen_window<dpoint1d> window1d; } // end of namespace oln Index: oln/core/2d/image2d_b.hh --- oln/core/2d/image2d_b.hh (revision 952) +++ oln/core/2d/image2d_b.hh (working copy) @@ -114,12 +114,12 @@ std::size_t pad(const dpoint2d& dp) const; }; -// template <typename T, typename D> -// bool init_(image2d_b<T>* this_, const D& dat); - template <typename T, typename D> bool prepare(image2d_b<T>& target, with_t, const D& dat); + template <typename T> + bool init_(box2d* this_, const image2d_b<T>& data); + # ifndef OLN_INCLUDE_ONLY @@ -239,18 +239,6 @@ return this->data_->first.i_pad() * dp.row() + dp.col(); } -// template <typename T, typename D> -// bool init_(image2d_b<T>* this_, const D& dat) -// { -// precondition(not this_->has_data()); -// box2d b; -// bool box_ok = init(b, with, dat); -// postcondition(box_ok); -// unsigned border = 2; // FIXME: Use init! -// this_->data__() = new typename image2d_b<T>::data(b.pmin(), b.pmax(), border); -// return box_ok; -// } - template <typename T, typename D> bool prepare(image2d_b<T>& target, with_t, const D& dat) { @@ -267,6 +255,13 @@ return box_ok; } + template <typename T> + bool init_(box2d* this_, const image2d_b<T>& data) + { + *this_ = data.bbox(); + return true; + } + # endif // ! OLN_INCLUDE_ONLY } // end of namespace oln Index: oln/core/3d/image3d.hh --- oln/core/3d/image3d.hh (revision 952) +++ oln/core/3d/image3d.hh (working copy) @@ -109,6 +109,9 @@ template <typename T, typename D> bool prepare(image3d<T>& target, with_t, const D& dat); + template <typename T> + bool init_(box3d* this_, const image3d<T>& data); + # ifndef OLN_INCLUDE_ONLY @@ -240,6 +243,13 @@ return box_ok; } + template <typename T> + bool init_(box3d* this_, const image3d<T>& data) + { + *this_ = data.bbox(); + return true; + } + # endif // ! OLN_INCLUDE_ONLY } // end of namespace oln Index: oln/core/gen/torus_pset.hh --- oln/core/gen/torus_pset.hh (revision 952) +++ oln/core/gen/torus_pset.hh (working copy) @@ -76,6 +76,8 @@ torus_pset(const Ps& pset); void init_pset(const Ps& pset); + operator Ps() const; + point relocate(const point& p) const; bool impl_has(const point& p) const; @@ -105,9 +107,9 @@ : super(pset) { mlc::assert_< mlc_is_a(Ps, Point_Set) >::check(); - this->pmin_ = pset.pmin(); + this->pmin_ = pset.bbox().pmin(); dpoint unit; unit.set_all(1); - this->size_ = pset.pmax() - pset.pmin() + unit; + this->size_ = pset.bbox().pmax() - pset.bbox().pmin() + unit; } template <typename Ps> @@ -115,9 +117,15 @@ current::init_pset(const Ps& pset) { this->ps_ = pset; - this->pmin_ = pset.pmin(); + this->pmin_ = pset.bbox().pmin(); dpoint unit; unit.set_all(1); - this->size_ = pset.pmax() - pset.pmin() + unit; + this->size_ = pset.bbox().pmax() - pset.bbox().pmin() + unit; + } + + template <typename Ps> + current::operator Ps() const + { + return this->ps_; } template <typename Ps> Index: oln/core/gen/niter_has.hh --- oln/core/gen/niter_has.hh (revision 952) +++ oln/core/gen/niter_has.hh (working copy) @@ -69,8 +69,8 @@ { public: - template <typename Pl, typename I> - niter_has_(const Generalized_Point<Pl>& p, const Image_with_Nbh<I>& ima); + template <typename I, typename Pl> + niter_has_(const Image_with_Nbh<I>& ima, const Generalized_Point<Pl>& p); void impl_start(); void impl_next(); @@ -87,10 +87,10 @@ # ifndef OLN_INCLUDE_ONLY template <typename It, typename Ps> - template <typename Pl, typename I> - current::niter_has_(const Generalized_Point<Pl>& p, const Image_with_Nbh<I>& ima) + template <typename I, typename Pl> + current::niter_has_(const Image_with_Nbh<I>& ima, const Generalized_Point<Pl>& p) : - super( It(p, ima) ), + super( It(ima, p) ), pset_( ima.points() ) { } Index: oln/core/gen/fun_ops.hh --- oln/core/gen/fun_ops.hh (revision 952) +++ oln/core/gen/fun_ops.hh (working copy) @@ -76,6 +76,16 @@ return tmp; \ } \ \ + template <typename L> \ + p2v_##Name##_<L, lit_p2v_<oln_argument(L), oln_result(L)> > \ + operator Sym (const Function_p2v<L>& left, const oln_result(L)& right) \ + { \ + mlc::assert_< mlc_is_a(oln_argument(L), Point) >::check(); \ + lit_p2v_<oln_argument(L), oln_result(L)> right_(right); \ + p2v_##Name##_<L, lit_p2v_<oln_argument(L), oln_result(L)> > tmp(left, right_); \ + return tmp; \ + } \ + \ struct e_n_d___w_i_t_h___s_e_m_i_c_o_l_u_m_n Index: oln/core/concept/image.hh --- oln/core/concept/image.hh (revision 952) +++ oln/core/concept/image.hh (working copy) @@ -127,6 +127,7 @@ stc_typename(box); stc_typename(pset); + stc_typename(dpoint); // stc_typename(output); // FIXME: Uncomment! stc_typename(plain); Index: oln/core/internal/box.hh --- oln/core/internal/box.hh (revision 952) +++ oln/core/internal/box.hh (working copy) @@ -306,6 +306,7 @@ box_fwd_piter_<B>::box_fwd_piter_(const Point_Set<Ps>& ps) : b_(ps.bbox()) { + mlc::assert_< mlc_is_a(B, Point_Set) >::check(); // FIXME: Add err msg. nop_ = b_.pmax(); ++nop_[0]; p_ = nop_; @@ -371,6 +372,7 @@ box_bkd_piter_<B>::box_bkd_piter_(const Point_Set<Ps>& ps) : b_(ps.bbox()) { + mlc::assert_< mlc_is_a(B, Point_Set) >::check(); // FIXME: Add err msg. nop_ = b_.pmin(); --nop_[0]; p_ = nop_; Index: oln/core/internal/op_image_extended_by_nbh.hh --- oln/core/internal/op_image_extended_by_nbh.hh (revision 952) +++ oln/core/internal/op_image_extended_by_nbh.hh (working copy) @@ -108,6 +108,8 @@ const nbh& impl_nbhood() const; nbh& impl_nbhood(); + operator I() const; + protected: special_op_(); special_op_(I& ima, N& n); @@ -150,6 +152,11 @@ namespace internal { + template <typename I, typename N> + current::operator I() const + { + return this->image(); + } template <typename I, typename N> current::special_op_() Index: oln/core/internal/point_base.hh --- oln/core/internal/point_base.hh (revision 952) +++ oln/core/internal/point_base.hh (working copy) @@ -97,8 +97,11 @@ vec_t& vec(); void set_all(const coord& c); + // FIXME: Add 'static const Exact& zero();' + protected: point_base_(); + point_base_(coord val); vec_t v_; }; Index: oln/core/internal/f_grid_to_window.hh --- oln/core/internal/f_grid_to_window.hh (revision 0) +++ oln/core/internal/f_grid_to_window.hh (revision 0) @@ -0,0 +1,118 @@ +// Copyright (C) 2007 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 51 Franklin Street, Fifth Floor, +// Boston, MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +#ifndef OLN_CORE_INTERNAL_F_GRID_TO_WINDOW_HH +# define OLN_CORE_INTERNAL_F_GRID_TO_WINDOW_HH + +# include <oln/core/concept/grid.hh> +# include <oln/core/gen/window.hh> + + +#define oln_f_grid_to_window(G) typename oln::internal::f_grid_to_window_< G >::ret + + +namespace oln +{ + + /// \{ + /// Forward declarations. + + // Grid types. + + struct grid1d; + struct grid2d; + struct grid2d_hex; + struct grid2d_tri; + struct grid3d; + // ... + + // Dpoint types. + struct dpoint1d; + struct dpoint2d; + struct dpoint3d; + // ... + + // Window types. + + typedef gen_window<dpoint1d> window1d; + typedef gen_window<dpoint2d> window2d; + typedef gen_window<dpoint3d> window3d; + // ... + + /// \} + + + + namespace internal + { + + // Fwd decl. + + template <typename G> struct f_grid_to_; + + + /// \{ + /// Definitions. + + template <typename G> + struct grid_to_window__; + + template <> + struct grid_to_window__< grid1d > + { + typedef window1d ret; + }; + + template <> + struct grid_to_window__< grid2d > + { + typedef window2d ret; + }; + + // FIXME: 2D hex/tri... + + template <> + struct grid_to_window__< grid3d > + { + typedef window3d ret; + }; + + /// \} + + + template <typename G> + struct f_grid_to_window_ : private mlc::assert_< mlc_is_a(G, Grid) >, + public grid_to_window__< G > + { + }; + + } // end of namespace oln::internal + +} // end of namespace oln + + +#endif // ! OLN_CORE_INTERNAL_F_GRID_TO_WINDOW_HH Index: oln/core/internal/op_pset_such_as_fp2b.hh --- oln/core/internal/op_pset_such_as_fp2b.hh (revision 952) +++ oln/core/internal/op_pset_such_as_fp2b.hh (working copy) @@ -209,7 +209,7 @@ { public: - pset_such_as_fp2b_fwd_piter_(); + pset_such_as_fp2b_fwd_piter_(const op_<S, such_as, F>& pset); pset_such_as_fp2b_fwd_piter_(const Point_Set< op_<S, such_as, F> >& pset); void impl_start(); @@ -224,6 +224,13 @@ # ifndef OLN_INCLUDE_ONLY template <typename S, typename F> + current::pset_such_as_fp2b_fwd_piter_(const op_<S, such_as, F>& pset) + : super(pset.adapted_()), + f_(pset.fun_()) + { + } + + template <typename S, typename F> current::pset_such_as_fp2b_fwd_piter_(const Point_Set< op_<S, such_as, F> >& pset) : super(exact(pset).adapted_()), f_(exact(pset).fun_()) @@ -285,6 +292,7 @@ { public: + pset_such_as_fp2b_bkd_piter_(const op_<S, such_as, F>& pset); pset_such_as_fp2b_bkd_piter_(const Point_Set< op_<S, such_as, F> >& pset); void impl_start(); @@ -299,6 +307,13 @@ # ifndef OLN_INCLUDE_ONLY template <typename S, typename F> + current::pset_such_as_fp2b_bkd_piter_(const op_<S, such_as, F>& pset) + : super(pset.adapted_()), + f_(pset.fun_()) + { + } + + template <typename S, typename F> current::pset_such_as_fp2b_bkd_piter_(const Point_Set< op_<S, such_as, F> >& pset) : super(exact(pset).adapted_()), f_(exact(pset).fun_()) Index: oln/core/internal/iterator_on_points_impl.hh --- oln/core/internal/iterator_on_points_impl.hh (revision 952) +++ oln/core/internal/iterator_on_points_impl.hh (working copy) @@ -37,6 +37,22 @@ namespace internal { + // base impl + + template <typename Exact> + struct iterator_on_points_impl_base_ + { + private: + stc_typename(point); + typedef typename point::vec_t vec_t; + public: + const vec_t& vec() const; + vec_t& vec(); + }; + + + // no-d impl is empty + template <unsigned n, typename Exact> struct iterator_on_points_impl_ { @@ -45,6 +61,8 @@ // 1d impl template <typename Exact> struct iterator_on_points_impl_< 1, Exact > + : + public iterator_on_points_impl_base_<Exact> { private: stc_typename(coord); @@ -55,6 +73,8 @@ // 2d impl template <typename Exact> struct iterator_on_points_impl_< 2, Exact > + : + public iterator_on_points_impl_base_<Exact> { private: stc_typename(coord); @@ -66,6 +86,8 @@ // 3d impl template <typename Exact> struct iterator_on_points_impl_< 3, Exact > + : + public iterator_on_points_impl_base_<Exact> { private: stc_typename(coord); @@ -77,6 +99,22 @@ # ifndef OLN_INCLUDE_ONLY + // base impl + + template <typename Exact> + const typename iterator_on_points_impl_base_<Exact>::vec_t& + iterator_on_points_impl_base_<Exact>::vec() const + { + return static_cast<const Exact&>(*this).to_point().vec(); + } + + template <typename Exact> + typename iterator_on_points_impl_base_<Exact>::vec_t& + iterator_on_points_impl_base_<Exact>::vec() + { + return static_cast<const Exact&>(*this).to_point().vec(); + } + // 1d impl template <typename Exact> Index: oln/core/internal/iterator_on_points_base.hh --- oln/core/internal/iterator_on_points_base.hh (revision 952) +++ oln/core/internal/iterator_on_points_base.hh (working copy) @@ -69,6 +69,9 @@ : public Iterator_on_Points<Exact>, public internal::iterator_on_points_impl_<mlc_value(stc_deferred(dim)), Exact> { + public: + // Disambiguate. + stc_using_from(Iterator_on_Points, point); protected: iterator_on_points_base_(); }; Index: oln/core/internal/f_image_to_window.hh --- oln/core/internal/f_image_to_window.hh (revision 0) +++ oln/core/internal/f_image_to_window.hh (revision 0) @@ -0,0 +1,37 @@ +// Copyright (C) 2007 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 51 Franklin Street, Fifth Floor, +// Boston, MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +#ifndef OLN_CORE_INTERNAL_F_IMAGE_TO_WINDOW_HH +# define OLN_CORE_INTERNAL_F_IMAGE_TO_WINDOW_HH + +# include <oln/core/internal/f_grid_to_window.hh> + + +#define oln_f_image_to_window(I) oln_f_grid_to_window(oln_grid(I)) + + +#endif // ! OLN_CORE_INTERNAL_F_IMAGE_TO_WINDOW_HH Index: oln/level/local.hh --- oln/level/local.hh (revision 952) +++ oln/level/local.hh (working copy) @@ -68,7 +68,7 @@ const oln_point(I)& p) { f.init_with(input(p)); - oln_niter(I) n(p, input); + oln_niter(I) n(input, p); for_all(n) f(input(n)); return f.value(); @@ -85,7 +85,7 @@ f.init_with(input(p)); if (f.value() = true) return true; - oln_niter(I) n(p, input); + oln_niter(I) n(input, p); for_all(n) { f(input(n)); // FIXME: Change to f.take(input(n))? @@ -104,7 +104,7 @@ const oln_point(I)& p) { f.init_with(input(p)); - oln_niter(I) n(p, input); + oln_niter(I) n(input, p); for_all(n) { f(input(n)); // FIXME: Change to f.take(input(n))? Index: oln/level/clone.hh --- oln/level/clone.hh (revision 952) +++ oln/level/clone.hh (working copy) @@ -50,11 +50,11 @@ // Generic version. template <typename I> - oln_plain(I) clone(const Image<I>& input) + oln_plain(I) clone_(const Image<I>& input) { oln_plain(I) output; prepare(output, with, input); - level::fill(output, input); + level::fill(inplace(output), input); return output; } @@ -65,7 +65,7 @@ template <typename I> oln_plain(I) clone(const Image<I>& input) { - return impl::clone(input); + return impl::clone_(input); } # endif // ! OLN_INCLUDE_ONLY
participants (1)
-
Thierry Geraud