URL:
https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-10-09 Guillaume Duhamel <guillaume.duhamel(a)lrde.epita.fr>
Add translate image in sandbox.
* translate_image.cc: New test for translate image.
* translate_image.hh: New image : translate image.
* color_sub.cc: Update.
---
color_sub.cc | 14 ----
translate_image.cc | 42 ++++++++++++
translate_image.hh | 176 +++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 220 insertions(+), 12 deletions(-)
Index: trunk/milena/sandbox/duhamel/translate_image.hh
===================================================================
--- trunk/milena/sandbox/duhamel/translate_image.hh (revision 0)
+++ trunk/milena/sandbox/duhamel/translate_image.hh (revision 1285)
@@ -0,0 +1,176 @@
+// 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 MLN_CORE_TRANSLATE_IMAGE_HH
+# define MLN_CORE_TRANSLATE_IMAGE_HH
+
+/*! \file mln/core/translate_image.hh
+ *
+ * \brief Definition of an image class FIXME
+ */
+
+# include <cmath>
+
+# include <mln/core/internal/image_identity.hh>
+# include <mln/core/box2d.hh>
+
+
+namespace mln
+{
+
+ // Fwd decl.
+ template <typename I> struct translate_image;
+
+ namespace internal
+ {
+
+ template <typename I>
+ struct data_< translate_image<I> >
+ {
+ data_(I& ima, const mln_dpoint(I) dp);
+
+ I ima_;
+ box2d bb_;
+ const mln_dpoint(I) dp_;
+ };
+
+ } // end of namespace mln::internal
+
+
+ /*! \brief FIXME
+ *
+ */
+ template <typename I>
+ struct translate_image : public mln::internal::image_identity_< I, mln_pset(I),
translate_image<I> >
+ {
+
+ typedef mln::internal::image_morpher_< I, mln_pset(I), translate_image<I>
> super_;
+
+ /// Return type of read-write access.
+ typedef typename internal::morpher_lvalue_<I>::ret lvalue;
+
+
+ /// Skeleton.
+ typedef translate_image< tag::image_<I> > skeleton;
+
+ /// Test if a pixel value is accessible at \p p.
+ using super_::has_data;
+
+ /// Constructors.
+ translate_image(I& ima, const mln_dpoint(I) dp);
+ translate_image();
+
+ /// FIXME: Doc!
+ const box2d& domain() const;
+
+ /// Test if a pixel value is accessible at \p p.
+ bool owns_(const mln_psite(I)& ) const;
+
+ /// Read-only access of pixel value at point site \p p.
+ mln_rvalue(I) operator()(const mln_psite(I)& p) const;
+
+ /// Read and "write if possible" access of pixel value at point site \p p.
+ lvalue operator()(const mln_psite(I)& p);
+ };
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace internal
+ {
+
+ // internal::data_< translate_image<I,S> >
+
+ template <typename I>
+ data_< translate_image<I> >::data_(I& ima, const mln_dpoint(I) dp)
+ : ima_ (ima),
+ dp_ (dp)
+ {
+ point2d start = ima.bbox ().pmin () + dp;
+ point2d end = ima.bbox ().pmax () + dp;
+ int x1 = start[0];
+ int y1 = start[1];
+ int x2 = end[0];
+ int y2 = end[1];
+
+ bb_ = make::box2d (x1, y1, x2, y2);
+ }
+
+ } // end of namespace mln::internal
+
+ template <typename I>
+ translate_image<I>::translate_image(I& ima, const mln_dpoint(I) dp)
+ {
+ mln_precondition(ima.has_data());
+ this->data_ = new internal::data_< translate_image<I> >(ima, dp);
+ }
+
+ template <typename I>
+ translate_image<I>::translate_image()
+ {
+ }
+
+ template <typename I>
+ bool translate_image<I>::owns_(const mln_psite(I)& p) const
+ {
+ mln_point(I) np = p - this->data_->dp_;
+ return this->data_->ima_.owns_(np);
+ }
+
+ template <typename I>
+ mln_rvalue(I)
+ translate_image<I>::operator()(const mln_psite(I)& p) const
+ {
+ mln_assertion(this->owns_(p));
+ mln_point(I) np = p - this->data_->dp_;
+ return this->data_->ima_(np);
+ }
+
+
+ template <typename I>
+ typename translate_image<I>::lvalue
+ translate_image<I>::operator()(const mln_psite(I)& p)
+ {
+ mln_assertion(this->owns_(p));
+ mln_point(I) np = p - this->data_->dp_;
+ return this->data_->ima_(np);
+ }
+
+ template <typename I>
+ const box2d&
+ translate_image<I>::domain() const
+ {
+ return this->data_->bb_;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_TRANSLATE_IMAGE_HH
Index: trunk/milena/sandbox/duhamel/color_sub.cc
===================================================================
--- trunk/milena/sandbox/duhamel/color_sub.cc (revision 1284)
+++ trunk/milena/sandbox/duhamel/color_sub.cc (revision 1285)
@@ -37,24 +37,14 @@
#include <mln/value/rgb8.hh>
#include <mln/level/fill.hh>
#include <mln/debug/println.hh>
-
#include <mln/core/image2d_b.hh>
-#include <mln/core/point2d.hh>
#include <mln/debug/println.hh>
-#include <mln/util/graph.hh>
#include <mln/io/ppm/save.hh>
-#include <mln/fun/p2b/chess.hh>
-
#include <mln/core/image_if_value.hh>
-#include <mln/debug/iota.hh>
-
-
-#include <mln/core/image2d_b.hh>
#include <mln/core/sub_image.hh>
#include <mln/core/image_if_value.hh>
#include <mln/core/inplace.hh>
-#include <mln/level/fill.hh>
# include <mln/debug/println.hh>
# include <mln/core/w_window2d_int.hh>
# include <mln/core/w_window2d_float.hh>
@@ -64,7 +54,7 @@
# include <mln/geom/chamfer.hh>
# include <mln/io/pbm/load.hh>
-#include "color_sub.hh"
+# include <mln/display/color_pretty.hh>
int main()
{
@@ -74,7 +64,7 @@
image2d_b<bool> input = io::pbm::load("../../img/toto.pbm");
const w_window2d_int& w_win = win_chamfer::mk_chamfer_3x3_int<2, 0> ();
image2d_b<unsigned> tmp = geom::chamfer(input, w_win, max);
- image2d_b<value::rgb8> out = color(inplace (tmp | 4));
+ image2d_b<value::rgb8> out = display::color_pretty(inplace (tmp | 4));
io::ppm::save(out, "out.ppm");
std::cout << "out.ppm generate" << std::endl;
}
Index: trunk/milena/sandbox/duhamel/translate_image.cc
===================================================================
--- trunk/milena/sandbox/duhamel/translate_image.cc (revision 0)
+++ trunk/milena/sandbox/duhamel/translate_image.cc (revision 1285)
@@ -0,0 +1,42 @@
+#include <mln/core/image2d.hh>
+#include <mln/value/int_u8.hh>
+#include <mln/debug/iota.hh>
+#include <mln/level/fill.hh>
+#include <mln/level/paste.hh>
+#include <mln/border/fill.hh>
+#include <mln/debug/println_with_border.hh>
+#include <mln/debug/println.hh>
+#include "translate_image.hh"
+
+int main ()
+{
+ using namespace mln;
+
+ typedef image2d<value::int_u8> I;
+
+ I ima (4, 2, 1);
+ debug::iota (ima);
+ translate_image<I> tmp (ima, make::point2d (0,2) - make::point2d (0,0));
+ std::cout << "orginal image domain : "
+ << ima.domain ()
+ << std::endl
+ << "translated image domain : "
+ << tmp.domain ()
+ << std::endl;
+
+ std::cout << "original image :"
+ << std::endl;
+ debug::println (ima);
+ std::cout << std::endl;
+ std::cout << "translated image :"
+ << std::endl;
+ debug::println (tmp);
+// std::cout << std::endl;
+// I out (4,4);
+// level::paste(ima, out);
+// level::paste(tmp, out);
+// std::cout << "pasted image :"
+// << std::endl;
+// debug::println (out);
+// std::cout << std::endl;
+}