https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add a new border computation mode and change image_if meaning.
* mln/metal/is.hh: Fix typo.
* mln/metal/is_not.hh: New.
* tests/metal_is.cc: Augment.
* mln/core/internal/image_if_base.hh: Change semantics; now
access to outside domain is OK.
(owns_): New.
(border): Explicit delegation to I in trait::.
* tests/trait_images.cc: Augment.
* tests/border_get.cc: New.
* mln/border/get.hh: .
* mln/border/find.hh: New.
* mln/core/init.hh (init_): Use border::find instead of
border::get.
* mln/core/concept/doc/image.hh: Fix type.
* mln/core/image2d.hh (swap_): Shorten code.
mln/border/find.hh | 28 ++++++------
mln/border/get.hh | 29 ++++++------
mln/core/concept/doc/image.hh | 2
mln/core/image2d.hh | 26 +----------
mln/core/init.hh | 7 ++-
mln/core/internal/image_if_base.hh | 14 ++++++
mln/metal/is.hh | 2
mln/metal/is_not.hh | 63 +++++++++++++++++++++++++++
tests/border_get.cc | 84 +++++++++++++++++++++++++++++++++++++
tests/metal_is.cc | 5 ++
tests/trait_images.cc | 8 +++
11 files changed, 211 insertions(+), 57 deletions(-)
Index: tests/metal_is.cc
--- tests/metal_is.cc (revision 1310)
+++ tests/metal_is.cc (working copy)
@@ -31,6 +31,7 @@
*/
#include <mln/metal/is.hh>
+#include <mln/metal/is_not.hh>
@@ -79,4 +80,8 @@
metal::is<int, float>::check_not();
metal::is<from_1, dest>::check_not();
metal::is<from_2, dest>::check_not();
+
+ metal::is_not<int, float>::check();
+ metal::is_not<from_1, dest>::check();
+ metal::is_not<from_2, dest>::check();
}
Index: tests/trait_images.cc
--- tests/trait_images.cc (revision 1310)
+++ tests/trait_images.cc (working copy)
@@ -46,11 +46,17 @@
std::cout << "image2d: ";
mln::trait::image::print<I>(std::cout);
+ typedef sub_image<I, box2d> Isub;
std::cout << std::endl
<< "sub_image< image2d >: ";
- mln::trait::image::print< sub_image<I, box2d> >(std::cout);
+ mln::trait::image::print< Isub >(std::cout);
std::cout << std::endl
<< "image_if< image2d >: ";
mln::trait::image::print< image_if<I, fun::p2b::chess_t> >(std::cout);
+
+
+ std::cout << std::endl
+ << "image_if< sub_image< image2d > >: ";
+ mln::trait::image::print< image_if<Isub, fun::p2b::chess_t> >(std::cout);
}
Index: tests/border_get.cc
--- tests/border_get.cc (revision 0)
+++ tests/border_get.cc (revision 0)
@@ -0,0 +1,84 @@
+// 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.
+
+/*! \file tests/border_get.cc
+ *
+ * \brief Tests on mln::border::get.
+ */
+
+#include <mln/core/image2d.hh>
+#include <mln/core/sub_image.hh>
+#include <mln/core/image_if.hh>
+#include <mln/fun/p2b/chess.hh>
+
+#include <mln/border/get.hh>
+#include <mln/literal/origin.hh>
+
+
+struct my_box2d : mln::Function_p2b< my_box2d >
+{
+ my_box2d(const mln::box2d& b)
+ : b_(b)
+ {
+ }
+ mln::box2d b_;
+ bool operator()(const mln::point2d& p) const
+ {
+ return b_.has(p);
+ }
+};
+
+
+
+int main()
+{
+ using namespace mln;
+
+ typedef image2d<int> I;
+
+ box2d b(literal::origin, point2d(1,1));
+ I ima(3,3, 51);
+
+// mln_assertion(border::get(ima) = 51);
+// mln_assertion( ima.has(point2d(2,2)) = true );
+
+// sub_image<I, box2d> sub(ima, b);
+// mln_assertion( sub.has (point2d(2,2)) = false &&
+// sub.owns_(point2d(2,2)) = false );
+// mln_assertion(border::get(sub) = 0);
+
+ my_box2d f_b(b);
+ image_if<I, my_box2d> imaif(ima, f_b);
+ mln_assertion( imaif.has (point2d(2,2)) = false &&
+ imaif.owns_(point2d(2,2)) = true );
+ mln_assertion(border::get(imaif) = 51);
+
+
+// std::cout << std::endl
+// << "image_if< image2d >: ";
+// mln::trait::image::print< image_if<I, fun::p2b::chess_t> >(std::cout);
+}
Index: mln/core/internal/image_if_base.hh
--- mln/core/internal/image_if_base.hh (revision 1310)
+++ mln/core/internal/image_if_base.hh (working copy)
@@ -84,6 +84,8 @@
typedef mlc_if( I_data_are_linear_,
trait::image::data::stored, // if linear then just stored
I_data_ ) data; // otherwise like I
+
+ typedef mln_trait_image_border(I) border;
};
} // end of namespace mln::trait
@@ -105,6 +107,10 @@
void init_(I& ima, const F& f);
+ /// Test if the image owns the point site \p p.
+ /// The result is the same than over the underlying image.
+ bool owns_(const mln_psite(I)& p) const; // Overload the def "owns_ ->
has".
+
protected:
/// Constructor from an image \p ima and a predicate \p f.
@@ -158,6 +164,14 @@
}
template <typename I, typename F, typename E>
+ bool
+ image_if_base_<I,F,E>::owns_(const mln_psite(I)& p) const
+ {
+ mln_precondition(this->has_data());
+ return this->data_->ima_.owns_(p);
+ }
+
+ template <typename I, typename F, typename E>
void
image_if_base_<I,F,E>::init_(I& ima, const F& f)
{
Index: mln/core/init.hh
--- mln/core/init.hh (revision 1310)
+++ mln/core/init.hh (working copy)
@@ -35,7 +35,7 @@
# include <mln/tag/init.hh>
# include <mln/geom/bbox.hh>
-# include <mln/border/get.hh>
+# include <mln/border/find.hh>
@@ -81,7 +81,10 @@
template <typename I>
void init_(tag::border_t, unsigned& bdr, const Image<I>& ima)
{
- bdr = border::get(ima);
+ // 'Find' means that we want a value; this is not always the
+ // border thickness of 'ima', but it can be the thickness of
+ // a morphed / underlying image over which ima is constructed.
+ bdr = border::find(ima);
}
template <typename I>
Index: mln/core/concept/doc/image.hh
--- mln/core/concept/doc/image.hh (revision 1310)
+++ mln/core/concept/doc/image.hh (working copy)
@@ -75,7 +75,7 @@
*/
bool has_data() const;
- /*! \brief Test if the image owns the poinst site \p p.
+ /*! \brief Test if the image owns the point site \p p.
*
* \return True if accessing the image value at \p p is
* possible, that is, does not abort the execution.
Index: mln/core/image2d.hh
--- mln/core/image2d.hh (revision 1310)
+++ mln/core/image2d.hh (working copy)
@@ -318,29 +318,9 @@
void
data_< image2d<T> >::swap_(data_< image2d<T> >& other_)
{
-
- T* sw_buffer_ = this->buffer_;
- this->buffer_ = other_.buffer_;
- other_.buffer_ = sw_buffer_;
-
- T** sw_array_ = this->array_;
- this->array_ = other_.array_;
- other_.array_ = sw_array_;
-
- unsigned sw_bdr_ = this->bdr_;
- this->bdr_ = other_.bdr_;
- other_.bdr_ = sw_bdr_;
-
- /// box2d vb_ virtual box, i.e., box including the virtual border
- box2d sw_vb_ = this->vb_;
- this->vb_ = other_.vb_;
- other_.vb_ = sw_vb_;
-
- /// box2d b_ theoretical box
- box2d sw_b_ = this->b_;
- this->b_ = other_.b_;
- other_.b_ = sw_b_;
-
+ data_< image2d<T> > self_ = *this;
+ *this = other_;
+ other_ = self_;
}
template <typename T>
Index: mln/metal/is_not.hh
--- mln/metal/is_not.hh (revision 0)
+++ mln/metal/is_not.hh (revision 0)
@@ -0,0 +1,63 @@
+// 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_METAL_IS_NOT_HH
+# define MLN_CORE_METAL_IS_NOT_HH
+
+/*! \file mln/metal/is_not.hh
+ *
+ * \brief Definition of a type that means "is not".
+ */
+
+# include <mln/metal/is.hh>
+
+
+# define mlc_is_not(T, U) mln::metal::is_not< T, U >
+
+
+
+namespace mln
+{
+
+ namespace metal
+ {
+
+ /*! \brief "is_not" check.
+ *
+ * FIXME: Doc!
+ */
+ template <typename T, typename U>
+ struct is_not : not_< is<T, U> >::eval
+ {
+ };
+
+ } // end of namespace mln::metal
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_METAL_IS_NOT_HH
Index: mln/metal/is.hh
--- mln/metal/is.hh (revision 1310)
+++ mln/metal/is.hh (working copy)
@@ -30,7 +30,7 @@
/*! \file mln/metal/is.hh
*
- * \brief Definition of a type that means "converts to".
+ * \brief Definition of a type that means "is".
*/
# include <mln/metal/is_a.hh>
Index: mln/border/get.hh
--- mln/border/get.hh (revision 1310)
+++ mln/border/get.hh (working copy)
@@ -33,7 +33,7 @@
* \brief FIXME.
*/
-# include <mln/core/internal/image_morpher.hh>
+# include <mln/border/find.hh>
namespace mln
@@ -56,28 +56,26 @@
namespace impl
{
- template <typename I, typename S, typename E>
- unsigned get__(const mln::internal::image_morpher_<I,S,E>& ima)
- {
- return border::get(*ima.delegatee_());
- }
-
- template <typename S, typename E>
- unsigned get__(const mln::internal::image_base_<S,E>&)
+ template <typename I>
+ unsigned get_(trait::image::border::any, trait::image::category::primary,
+ const I& ima)
{
- return 0;
+ return ima.border();
}
template <typename I>
- unsigned get_(trait::image::speed::any, const I& ima)
+ unsigned get_(trait::image::border::any, trait::image::category::morpher,
+ const I& ima)
{
- return border::impl::get__(ima);
+ return border::get( *ima.delegatee_() );
}
+
template <typename I>
- unsigned get_(trait::image::speed::fastest, const I& ima)
+ unsigned get_(trait::image::border::none, trait::image::category::any,
+ const I& ima)
{
- return ima.border();
+ return 0;
}
} // end of namespace mln::border::impl
@@ -89,7 +87,8 @@
unsigned get(const Image<I>& ima)
{
mln_precondition(exact(ima).has_data());
- return border::impl::get_(mln_trait_image_speed(I)(), exact(ima));
+ return border::impl::get_(mln_trait_image_border(I)(),
mln_trait_image_category(I)(),
+ exact(ima));
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/border/find.hh
--- mln/border/find.hh (revision 1310)
+++ mln/border/find.hh (working copy)
@@ -25,10 +25,10 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_BORDER_GET_HH
-# define MLN_BORDER_GET_HH
+#ifndef MLN_BORDER_FIND_HH
+# define MLN_BORDER_FIND_HH
-/*! \file mln/border/get.hh
+/*! \file mln/border/find.hh
*
* \brief FIXME.
*/
@@ -42,13 +42,13 @@
namespace border
{
- /*! Get the virtual (outer) border thickness of image \p ima.
+ /*! Find the virtual (outer) border thickness of image \p ima.
*
* \param[in] ima The image.
* \result The border thickness (0 if there is no border).
*/
template <typename I>
- unsigned get(const Image<I>& ima);
+ unsigned find(const Image<I>& ima);
# ifndef MLN_INCLUDE_ONLY
@@ -57,25 +57,25 @@
{
template <typename I, typename S, typename E>
- unsigned get__(const mln::internal::image_morpher_<I,S,E>& ima)
+ unsigned find__(const mln::internal::image_morpher_<I,S,E>& ima)
{
- return border::get(*ima.delegatee_());
+ return border::find(*ima.delegatee_());
}
template <typename S, typename E>
- unsigned get__(const mln::internal::image_base_<S,E>&)
+ unsigned find__(const mln::internal::image_base_<S,E>&)
{
return 0;
}
template <typename I>
- unsigned get_(trait::image::speed::any, const I& ima)
+ unsigned find_(trait::image::speed::any, const I& ima)
{
- return border::impl::get__(ima);
+ return border::impl::find__(ima);
}
template <typename I>
- unsigned get_(trait::image::speed::fastest, const I& ima)
+ unsigned find_(trait::image::speed::fastest, const I& ima)
{
return ima.border();
}
@@ -86,10 +86,10 @@
// Facade.
template <typename I>
- unsigned get(const Image<I>& ima)
+ unsigned find(const Image<I>& ima)
{
mln_precondition(exact(ima).has_data());
- return border::impl::get_(mln_trait_image_speed(I)(), exact(ima));
+ return border::impl::find_(mln_trait_image_speed(I)(), exact(ima));
}
# endif // ! MLN_INCLUDE_ONLY
@@ -99,4 +99,4 @@
} // end of namespace mln
-#endif // ! MLN_BORDER_GET_HH
+#endif // ! MLN_BORDER_FIND_HH