https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add a slice morpher.
* mln/core/image/slice_image.hh: New.
* mln/core/image/all.hh: Update.
* tests/core/image/slice_image.cc: New.
* tests/core/image/Makefile.am: Update.
* tests/core/image/p2p_image.cc: Fix file doc.
mln/core/image/all.hh | 1
mln/core/image/slice_image.hh | 276 ++++++++++++++++++++++++++++++++++++++++
tests/core/image/Makefile.am | 2
tests/core/image/p2p_image.cc | 2
tests/core/image/slice_image.cc | 51 +++++++
5 files changed, 331 insertions(+), 1 deletion(-)
Index: mln/core/image/all.hh
--- mln/core/image/all.hh (revision 3214)
+++ mln/core/image/all.hh (working copy)
@@ -78,6 +78,7 @@
//# include <mln/core/image/rle_encode.hh>
//# include <mln/core/image/rle_image.hh>
# include <mln/core/image/safe.hh>
+# include <mln/core/image/slice_image.hh>
# include <mln/core/image/sparse_encode.hh>
# include <mln/core/image/sparse_image.hh>
# include <mln/core/image/sub_image.hh>
Index: mln/core/image/slice_image.hh
--- mln/core/image/slice_image.hh (revision 0)
+++ mln/core/image/slice_image.hh (revision 0)
@@ -0,0 +1,276 @@
+// Copyright (C) 2008 EPITA Research and Development Laboratory (LRDE)
+//
+// 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_SLICE_IMAGE_HH
+# define MLN_CORE_IMAGE_SLICE_IMAGE_HH
+
+/// \file mln/core/image/slice_image.hh
+///
+/// Definition of an image FIXME: Doc!
+///
+/// \todo Write init_.
+
+# include <mln/core/internal/image_domain_morpher.hh>
+# include <mln/core/alias/box3d.hh>
+# include <mln/core/alias/box2d.hh>
+
+
+namespace mln
+{
+
+ // Forward declaration.
+ template <typename I> struct slice_image;
+
+
+ namespace internal
+ {
+
+ /// Data structure for \c mln::slice_image<I>.
+ template <typename I>
+ struct data< slice_image<I> >
+ {
+ data(I& ima, def::coord sli);
+
+ I ima_;
+ def::coord sli_;
+ box2d b_;
+ };
+
+ } // end of namespace mln::internal
+
+
+ namespace trait
+ {
+
+ template <typename I>
+ struct image_< slice_image<I> > : default_image_morpher< I,
+ mln_value(I),
+ slice_image<I> >
+ {
+ typedef trait::image::category::domain_morpher category;
+
+ typedef trait::image::dimension::two_d dimension;
+
+// typedef trait::image::ext_domain::none ext_domain; // No extension of
domain.
+// typedef trait::image::ext_value::irrelevant ext_value;
+// typedef trait::image::ext_io::irrelevant ext_io;
+
+ typedef trait::image::vw_io::none vw_io;
+ typedef trait::image::vw_set::none vw_set;
+ typedef trait::image::value_alignement::not_aligned value_alignement;
+ typedef trait::image::value_storage::disrupted value_storage;
+ };
+
+ } // end of namespace mln::trait
+
+
+
+ /// FIXME: Doc!
+ template <typename I>
+ struct slice_image : public internal::image_domain_morpher< I,
+ box2d,
+ slice_image<I> >
+ {
+ /// Skeleton.
+ typedef slice_image< tag::image_<I> > skeleton;
+
+ /// Constructor without argument.
+ slice_image();
+
+ /// Constructor from an image \p ima and a predicate \p f.
+ slice_image(I& ima, def::coord sli);
+
+ void init_(I& ima, def::coord sli);
+
+
+ /// Give the definition domain.
+ const box2d& domain() const;
+
+ /// Give the slice number.
+ def::coord sli() const;
+
+ /// Read-only access to the image value located at point \p p.
+ mln_rvalue(I) operator()(const point2d& p) const;
+
+ /// Read-write access to the image value located at point \p p.
+ mln_morpher_lvalue(I) operator()(const point2d& p);
+ };
+
+
+
+ template <typename I>
+ slice_image<I>
+ slice(Image<I>& ima, def::coord sli);
+
+ template <typename I>
+ slice_image<const I>
+ slice(const Image<I>& ima, def::coord sli);
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+// // init_.
+
+// template <typename I, typename J>
+// void init_(tag::image_t, slice_image<I>& target, const J& model)
+// {
+// I ima;
+// init_(tag::image, ima, exact(model));
+// def::coord sli;
+// // FIXME
+// // init_(tag::???, sli, exact(model));
+// target.init_(ima, sli);
+// }
+
+
+ // internal::data< slice_image<I> >
+
+ namespace internal
+ {
+
+ template <typename I>
+ inline
+ data< slice_image<I> >::data(I& ima, def::coord sli)
+ : ima_(ima),
+ sli_(sli)
+ {
+ b_ = make::box2d(ima.domain().pmin().row(), ima.domain().pmin().col(),
+ ima.domain().pmax().row(), ima.domain().pmax().col());
+ }
+
+ }
+
+
+ // slice_image<I>
+
+ template <typename I>
+ inline
+ slice_image<I>::slice_image()
+ {
+ }
+
+ template <typename I>
+ inline
+ slice_image<I>::slice_image(I& ima, def::coord sli)
+ {
+ init_(ima, sli);
+ }
+
+ template <typename I>
+ inline
+ void
+ slice_image<I>::init_(I& ima, def::coord sli)
+ {
+ mln_precondition(! this->is_valid());
+ this->data_ = new internal::data< slice_image<I> >(ima, sli);
+ }
+
+ template <typename I>
+ inline
+ const box2d&
+ slice_image<I>::domain() const
+ {
+ mln_precondition(this->is_valid());
+ return this->data_->b_;
+ }
+
+ template <typename I>
+ inline
+ def::coord
+ slice_image<I>::sli() const
+ {
+ mln_precondition(this->is_valid());
+ return this->data_->sli_;
+ }
+
+ template <typename I>
+ inline
+ mln_rvalue(I)
+ slice_image<I>::operator()(const point2d& p) const
+ {
+ mln_precondition(this->has(p));
+ point3d p_(this->data_->sli_, p.row(), p.col());
+ mln_precondition(this->data_->ima_.has(p_));
+ return this->data_->ima_(p_);
+ }
+
+ template <typename I>
+ inline
+ mln_morpher_lvalue(I)
+ slice_image<I>::operator()(const point2d& p)
+ {
+ mln_precondition(this->has(p));
+ point3d p_(this->data_->sli_, p.row(), p.col());
+ mln_precondition(this->data_->ima_.has(p_));
+ return this->data_->ima_(p_);
+ }
+
+
+ // Routines.
+
+ template <typename I>
+ inline
+ slice_image<I>
+ slice(Image<I>& ima_, def::coord sli)
+ {
+ mlc_equal(mln_pset(I), box3d)::check();
+
+ I& ima = exact(ima_);
+ mln_precondition(ima.is_valid());
+ mln_precondition(sli >= ima.domain().pmin().sli() &&
+ sli <= ima.domain().pmax().sli());
+
+ slice_image<I> tmp(ima, sli);
+ return tmp;
+ }
+
+ template <typename I>
+ inline
+ slice_image<const I>
+ slice(const Image<I>& ima_, def::coord sli)
+ {
+ mlc_equal(mln_pset(I), box3d)::check();
+
+ I& ima = exact(ima_);
+ mln_precondition(ima.is_valid());
+ mln_precondition(sli >= ima.domain().pmin().sli() &&
+ sli <= ima.domain().pmax().sli());
+
+ slice_image<I> tmp(ima, sli);
+ return tmp;
+ }
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+
+#endif // ! MLN_CORE_IMAGE_SLICE_IMAGE_HH
Index: tests/core/image/slice_image.cc
--- tests/core/image/slice_image.cc (revision 0)
+++ tests/core/image/slice_image.cc (revision 0)
@@ -0,0 +1,51 @@
+// Copyright (C) 2008 EPITA Research and Development Laboratory (LRDE)
+//
+// 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 tests/core/image/slice_image.cc
+///
+/// Tests on mln::slice_image.
+
+#include <mln/core/image/image2d.hh>
+#include <mln/core/image/image3d.hh>
+#include <mln/core/image/slice_image.hh>
+
+#include <mln/debug/iota.hh>
+#include <mln/level/compare.hh>
+
+
+int main()
+{
+ using namespace mln;
+
+ image3d<int> ima(3, 2, 4);
+
+ for (def::coord s = 0; s < 3; ++s)
+ debug::iota(slice(ima, s).rw());
+
+ mln_assertion( slice(ima, 1) == slice(ima, 0) );
+ mln_assertion( slice(ima, 2) == slice(ima, 0) );
+}
Index: tests/core/image/p2p_image.cc
--- tests/core/image/p2p_image.cc (revision 3214)
+++ tests/core/image/p2p_image.cc (working copy)
@@ -25,7 +25,7 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/// \file tests/core/image/image2d.cc
+/// \file tests/core/image/p2p_image.cc
///
/// Tests on mln::p2p_image.
Index: tests/core/image/Makefile.am
--- tests/core/image/Makefile.am (revision 3214)
+++ tests/core/image/Makefile.am (working copy)
@@ -25,6 +25,7 @@
plain \
## rle_image \
safe_image \
+ slice_image \
## sparse_image \
sub_image \
t_image \
@@ -54,6 +55,7 @@
plain_SOURCES = plain.cc
##rle_image_SOURCES = rle_image.cc
safe_image_SOURCES = safe_image.cc
+slice_image_SOURCES = slice_image.cc
##sparse_image_SOURCES = sparse_image.cc
sub_image_SOURCES = sub_image.cc
t_image_SOURCES = t_image.cc