2006-10-23 Thierry GERAUD <theo(a)tegucigalpa.lrde.epita.fr>
Add stack morpher and remove the hack related to indexed mutable
access.
* tests/morphers/stack_morpher.cc: New.
* tests/morphers/Makefile.am: Update.
* oln/debug/track.hh: New.
* oln/core/automatic/image/mutable_image2d.hh: New.
* oln/core/automatic/image/mutable_image3d.hh: New.
* oln/core/automatic/image/mutable_image1d.hh: New.
* oln/morpher/stack.hh: New.
* oln/Makefile.am: Update.
* oln/debug/print.hh (println): Remove; too dummy.
(operator): New.
* oln/level/fill.hh (fill): New specialization for C arrays.
* oln/core/automatic/image/image1d.hh: Remove hack of 'at'.
* oln/core/automatic/image/image2d.hh: Likewise.
* oln/core/automatic/image/image3d.hh: Likewise.
* oln/core/abstract/image.hh (image, ~image): Add counting.
(include): Update.
* oln/core/abstract/image/dimension/1d.hh
(image1d): Split partially into...
(mutable_image1d): ...this new class.
(include): Update.
* oln/core/abstract/image/dimension/2d.hh: Likewise.
* oln/core/abstract/image/dimension/3d.hh: Likewise.
* oln/core/abstract/image/dimension/hierarchy.hh
(case_): Update.
* oln/core/2d/array2d.hh (memsize): Better sig.
(include): Update.
* oln/core/2d/image2d.hh (image2d): New overloading for no arg.
Index: tests/morphers/stack_morpher.cc
===================================================================
--- tests/morphers/stack_morpher.cc (revision 0)
+++ tests/morphers/stack_morpher.cc (revision 0)
@@ -0,0 +1,48 @@
+// Copyright (C) 2006 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.
+
+/// Test the stack morpher.
+
+#include <cassert>
+#include <oln/basics2d.hh>
+#include <oln/morpher/stack.hh>
+
+
+int main()
+{
+ using namespace oln;
+ typedef image2d<int> image_t;
+
+ image_t ima(3,3);
+ morpher::stack<2,image_t> ima_v = stack(ima, ima);
+
+ point2d p(2, 2);
+ ima(p) = 51;
+
+ assert(ima(p) == ima_v.image(1)(p));
+ assert(ima_v.at(2, 2) == ima_v(p));
+}
Index: tests/morphers/Makefile.am
===================================================================
--- tests/morphers/Makefile.am (revision 669)
+++ tests/morphers/Makefile.am (working copy)
@@ -22,6 +22,7 @@
identity_morpher \
add_neighborhood_morpher \
slice_morpher \
+ stack_morpher \
value_cast \
\
morphers
@@ -30,6 +31,7 @@
identity_morpher_SOURCES = identity_morpher.cc
add_neighborhood_morpher_SOURCES = add_neighborhood_morpher.cc
slice_morpher_SOURCES = slice_morpher.cc
+stack_morpher_SOURCES = stack_morpher.cc
value_cast_SOURCES = value_cast.cc
morphers_SOURCES = morphers.cc
Index: oln/debug/track.hh
===================================================================
--- oln/debug/track.hh (revision 0)
+++ oln/debug/track.hh (revision 0)
@@ -0,0 +1,47 @@
+// Copyright (C) 2006 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_TRACK_HH
+# define OLN_DEBUG_TRACK_HH
+
+# include <oln/core/abstract/image.hh>
+
+
+namespace oln
+{
+
+ namespace debug
+ {
+
+ static unsigned n_images = 0;
+
+ } // end of namespace oln::debug
+
+} // end of namespace oln
+
+
+#endif // ! OLN_DEBUG_TRACK_HH
Index: oln/debug/print.hh
===================================================================
--- oln/debug/print.hh (revision 669)
+++ oln/debug/print.hh (working copy)
@@ -48,11 +48,7 @@
template <typename I>
void print(const abstract::image<I>& input, std::ostream& ostr =
std::cout);
- /// Fwd decl.
- template <typename I>
- void println(const abstract::image<I>& input, std::ostream& ostr =
std::cout);
-
# ifndef OLN_INCLUDE_ONLY
namespace impl
@@ -111,15 +107,6 @@
impl::print(input.exact(), ostr);
}
-
- /// Facade.
- template <typename I>
- void println(const abstract::image<I>& input, std::ostream& ostr)
- {
- print(input, ostr);
- ostr << std::endl;
- }
-
# endif // ! OLN_INCLUDE_ONLY
} // end of namespace oln::debug
Index: oln/level/fill.hh
===================================================================
--- oln/level/fill.hh (revision 669)
+++ oln/level/fill.hh (working copy)
@@ -29,6 +29,8 @@
#ifndef OLN_LEVEL_FILL_HH
# define OLN_LEVEL_FILL_HH
+# include <iostream>
+
# include <mlc/assert.hh>
# include <mlc/is_a.hh>
@@ -45,14 +47,28 @@
struct FIRST_ARGUMENT_OF_oln_level_fill_IS_NOT_MUTABLE;
}
+
+ /// Fwd decl.
+ template <typename I, typename V>
+ I& operator<<(abstract::mutable_image<I>& input, const V
values[]);
+
+ /// Fwd decl.
+ template <typename I>
+ I& operator<<(abstract::mutable_image<I>& input, const
oln_value(I)& value);
+
+
namespace level
{
/// Fwd decl.
template <typename I>
- void fill(abstract::mutable_image<I>& input, const oln_value(I)& val);
+ void fill(abstract::mutable_image<I>& input, const oln_value(I)&
value);
+ /// Fwd decl.
+ template <typename I, typename V>
+ void fill(abstract::mutable_image<I>& input, const V values[]);
+
# ifndef OLN_INCLUDE_ONLY
namespace impl
@@ -60,27 +76,66 @@
/// Generic version.
template <typename I>
- void fill(abstract::mutable_image<I>& input, const oln_value(I)&
val)
+ void fill(abstract::mutable_image<I>& input, const oln_value(I)&
value)
{
oln_piter(I) p(input.topo());
for_all(p)
- input(p) = val;
+ input(p) = value;
}
+ /// Generic version.
+ template <typename I, typename V>
+ void fill(abstract::mutable_image<I>& input, const V values[])
+ {
+ oln_piter(I) p(input.topo());
+ unsigned i = 0;
+ for_all(p)
+ input(p) = values[i++];
+ }
+
} // end of namespace oln::level::fill
/// Facade.
template <typename I>
- void fill(abstract::mutable_image<I>& input, const oln_value(I)& val)
+ void fill(abstract::mutable_image<I>& input, const oln_value(I)&
value)
{
- impl::fill(input.exact(), val);
+ impl::fill(input.exact(), value);
}
+ /// Facade.
+ template <typename I, typename V>
+ void fill(abstract::mutable_image<I>& input, const V values[])
+ {
+ return impl::fill(input.exact(), values);
+ }
+
+
# endif
} // end of namespace oln::level
+
+# ifndef OLN_INCLUDE_ONLY
+
+ /// Fwd decl.
+ template <typename I, typename V>
+ I& operator<<(abstract::mutable_image<I>& input, const V values[])
+ {
+ level::fill(input, values);
+ return input.exact();
+ }
+
+ /// Fwd decl.
+ template <typename I>
+ I& operator<<(abstract::mutable_image<I>& input, const
oln_value(I)& value)
+ {
+ level::fill(input, value);
+ return input.exact();
+ }
+
+# endif
+
} // end of namespace oln
Index: oln/core/automatic/image/mutable_image2d.hh
===================================================================
--- oln/core/automatic/image/mutable_image2d.hh (revision 0)
+++ oln/core/automatic/image/mutable_image2d.hh (revision 0)
@@ -0,0 +1,82 @@
+// Copyright (C) 2006 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_AUTOMATIC_IMAGE_MUTABLE_IMAGE2D_HH
+# define OLN_CORE_AUTOMATIC_IMAGE_MUTABLE_IMAGE2D_HH
+
+# include <oln/core/automatic/impl.hh>
+# include <oln/morpher/tags.hh>
+# include <oln/core/2d/point2d.hh>
+
+
+namespace oln
+{
+ // Forward declaration.
+ namespace abstract
+ {
+ template <typename E> class mutable_image2d;
+
+ } // end of namespace oln::abstract
+
+
+ namespace automatic
+ {
+
+
+ /// Default implementation corresponding to the interface
+ /// oln::abstract::mutable_image2d.
+ template <typename E, typename tag>
+ class set_impl<abstract::mutable_image2d, tag, E> :
+ public virtual stc::any__simple<E>
+ {
+ public:
+ oln_lvalue(E) impl_at(const oln_coord(E)& row, const oln_coord(E)& col);
+ };
+
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+
+ // 1. convert (row, col) -> p then 2. call operator()(p).
+
+ template <typename E, typename tag>
+ oln_lvalue(E)
+ set_impl<abstract::mutable_image2d, tag, E>
+ ::impl_at(const oln_coord(E)& row, const oln_coord(E)& col)
+ {
+ point2d tmp(row, col);
+ return this->exact().operator()(tmp);
+ }
+
+# endif
+
+ } // end of namespace oln::automatic
+
+} // end of namespace oln
+
+#endif // ! OLN_CORE_AUTOMATIC_IMAGE_MUTABLE_IMAGE2D_HH
Index: oln/core/automatic/image/mutable_image3d.hh
===================================================================
--- oln/core/automatic/image/mutable_image3d.hh (revision 0)
+++ oln/core/automatic/image/mutable_image3d.hh (revision 0)
@@ -0,0 +1,85 @@
+// Copyright (C) 2006 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_AUTOMATIC_IMAGE_MUTABLE_IMAGE3D_HH
+# define OLN_CORE_AUTOMATIC_IMAGE_MUTABLE_IMAGE3D_HH
+
+# include <oln/core/automatic/impl.hh>
+# include <oln/morpher/tags.hh>
+# include <oln/core/3d/point3d.hh>
+
+
+namespace oln
+{
+ // Forward declaration.
+ namespace abstract
+ {
+ template <typename E> class mutable_image3d;
+
+ } // end of namespace oln::abstract
+
+
+ namespace automatic
+ {
+
+
+ /// Default implementation corresponding to the interface
+ /// oln::abstract::mutable_image3d.
+ template <typename E, typename tag>
+ class set_impl<abstract::mutable_image3d, tag, E> :
+ public virtual stc::any__simple<E>
+ {
+ public:
+ oln_lvalue(E) impl_at(const oln_coord(E)& slice,
+ const oln_coord(E)& row,
+ const oln_coord(E)& col);
+ };
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+
+ // 1. convert (slice, row, col) -> p then 2. call operator()(p).
+
+ template <typename E, typename tag>
+ oln_lvalue(E)
+ set_impl<abstract::mutable_image3d, tag, E>
+ ::impl_at(const oln_coord(E)& slice,
+ const oln_coord(E)& row,
+ const oln_coord(E)& col)
+ {
+ point3d tmp(slice, row, col);
+ return this->exact().operator()(tmp);
+ }
+
+# endif
+
+ } // end of namespace oln::automatic
+
+} // end of namespace oln
+
+#endif // ! OLN_CORE_AUTOMATIC_IMAGE_MUTABLE_IMAGE3D_HH
Index: oln/core/automatic/image/image1d.hh
===================================================================
--- oln/core/automatic/image/image1d.hh (revision 669)
+++ oln/core/automatic/image/image1d.hh (working copy)
@@ -58,35 +58,15 @@
oln_rvalue(E) impl_at(const oln_coord(E)& index) const;
// FIXME: Hack.
- oln_lvalue(E) impl_at(const oln_coord(E)& index);
bool impl_has_at(const oln_coord(E)& index) const;
};
-
- /// Implementation corresponding to the interface
- /// oln::abstract::image1d for an identity morpher.
- template <typename E>
- class set_impl<abstract::image1d, morpher::tag::identity, E> :
- public virtual stc::any__simple<E>
- {
- public:
-
- oln_rvalue(E) impl_at(const oln_coord(E)& index) const;
-
- // FIXME: Hack.
- oln_lvalue(E) impl_at(const oln_coord(E)& index);
- bool impl_has_at(const oln_coord(E)& index) const;
-
- };
-
-
-
# ifndef OLN_INCLUDE_ONLY
- // Default is: 1. convert (index) -> p then 2. call operator()(p).
+ // 1. convert (index) -> p then 2. call operator()(p).
template <typename E, typename tag>
oln_rvalue(E)
@@ -98,15 +78,6 @@
}
template <typename E, typename tag>
- oln_lvalue(E)
- set_impl<abstract::image1d, tag, E>
- ::impl_at(const oln_coord(E)& index)
- {
- point1d tmp(index);
- return this->exact().operator()(tmp);
- }
-
- template <typename E, typename tag>
bool
set_impl<abstract::image1d, tag, E>
::impl_has_at(const oln_coord(E)& index) const
@@ -115,33 +86,6 @@
return this->exact().has(tmp);
}
-
- // For morphers: delegate.
-
- template <typename E>
- oln_rvalue(E)
- set_impl<abstract::image1d, morpher::tag::identity, E>
- ::impl_at(const oln_coord(E)& index) const
- {
- return this->exact().delegate().at(index);
- }
-
- template <typename E>
- oln_lvalue(E)
- set_impl<abstract::image1d, morpher::tag::identity, E>
- ::impl_at(const oln_coord(E)& index)
- {
- return this->exact().delegate().at(index);
- }
-
- template <typename E>
- bool
- set_impl<abstract::image1d, morpher::tag::identity, E>
- ::impl_has_at(const oln_coord(E)& index) const
- {
- return this->exact().delegate().has_at(index);
- }
-
# endif
} // end of namespace oln::automatic
Index: oln/core/automatic/image/image2d.hh
===================================================================
--- oln/core/automatic/image/image2d.hh (revision 669)
+++ oln/core/automatic/image/image2d.hh (working copy)
@@ -57,36 +57,17 @@
oln_rvalue(E) impl_at(const oln_coord(E)& row, const oln_coord(E)& col)
const;
- // FIXME: Hack.
- oln_lvalue(E) impl_at(const oln_coord(E)& row, const oln_coord(E)& col);
+ // FIXME: Hack; should be elsewhere...
bool impl_has_at(const oln_coord(E)& row, const oln_coord(E)& col) const;
};
- /// Implementation corresponding to the interface
- /// oln::abstract::image2d for an identity morpher.
- template <typename E>
- class set_impl<abstract::image2d, morpher::tag::identity, E> :
- public virtual stc::any__simple<E>
- {
- public:
-
- oln_rvalue(E) impl_at(const oln_coord(E)& row, const oln_coord(E)& col)
const;
-
- // FIXME: Hack.
- oln_lvalue(E) impl_at(const oln_coord(E)& row, const oln_coord(E)& col);
- bool impl_has_at(const oln_coord(E)& row, const oln_coord(E)& col) const;
-
- };
-
-
-
# ifndef OLN_INCLUDE_ONLY
- // Default is: 1. convert (row, col) -> p then 2. call operator()(p).
+ // 1. convert (row, col) -> p then 2. call operator()(p).
template <typename E, typename tag>
oln_rvalue(E)
@@ -98,15 +79,6 @@
}
template <typename E, typename tag>
- oln_lvalue(E)
- set_impl<abstract::image2d, tag, E>
- ::impl_at(const oln_coord(E)& row, const oln_coord(E)& col)
- {
- point2d tmp(row, col);
- return this->exact().operator()(tmp);
- }
-
- template <typename E, typename tag>
bool
set_impl<abstract::image2d, tag, E>
::impl_has_at(const oln_coord(E)& row, const oln_coord(E)& col) const
@@ -115,33 +87,6 @@
return this->exact().has(tmp);
}
-
- // For morphers: delegate.
-
- template <typename E>
- oln_rvalue(E)
- set_impl<abstract::image2d, morpher::tag::identity, E>
- ::impl_at(const oln_coord(E)& row, const oln_coord(E)& col) const
- {
- return this->exact().delegate().at(row, col);
- }
-
- template <typename E>
- oln_lvalue(E)
- set_impl<abstract::image2d, morpher::tag::identity, E>
- ::impl_at(const oln_coord(E)& row, const oln_coord(E)& col)
- {
- return this->exact().delegate().at(row, col);
- }
-
- template <typename E>
- bool
- set_impl<abstract::image2d, morpher::tag::identity, E>
- ::impl_has_at(const oln_coord(E)& row, const oln_coord(E)& col) const
- {
- return this->exact().delegate().has_at(row, col);
- }
-
# endif
} // end of namespace oln::automatic
Index: oln/core/automatic/image/image3d.hh
===================================================================
--- oln/core/automatic/image/image3d.hh (revision 669)
+++ oln/core/automatic/image/image3d.hh (working copy)
@@ -60,9 +60,6 @@
const oln_coord(E)& col) const;
// FIXME: Hack.
- oln_lvalue(E) impl_at(const oln_coord(E)& slice,
- const oln_coord(E)& row,
- const oln_coord(E)& col);
bool impl_has_at(const oln_coord(E)& slice,
const oln_coord(E)& row,
const oln_coord(E)& col) const;
@@ -71,34 +68,10 @@
- /// Implementation corresponding to the interface
- /// oln::abstract::image3d for an identity morpher.
- template <typename E>
- class set_impl<abstract::image3d, morpher::tag::identity, E> :
- public virtual stc::any__simple<E>
- {
- public:
-
- oln_rvalue(E) impl_at(const oln_coord(E)& slice,
- const oln_coord(E)& row,
- const oln_coord(E)& col) const;
-
- // FIXME: Hack.
- oln_lvalue(E) impl_at(const oln_coord(E)& slice,
- const oln_coord(E)& row,
- const oln_coord(E)& col);
- bool impl_has_at(const oln_coord(E)& slice,
- const oln_coord(E)& row,
- const oln_coord(E)& col) const;
-
- };
-
-
-
# ifndef OLN_INCLUDE_ONLY
- // Default is: 1. convert (slice, row, col) -> p then 2. call operator()(p).
+ // 1. convert (slice, row, col) -> p then 2. call operator()(p).
template <typename E, typename tag>
oln_rvalue(E)
@@ -112,17 +85,6 @@
}
template <typename E, typename tag>
- oln_lvalue(E)
- set_impl<abstract::image3d, tag, E>
- ::impl_at(const oln_coord(E)& slice,
- const oln_coord(E)& row,
- const oln_coord(E)& col)
- {
- point3d tmp(slice, row, col);
- return this->exact().operator()(tmp);
- }
-
- template <typename E, typename tag>
bool
set_impl<abstract::image3d, tag, E>
::impl_has_at(const oln_coord(E)& slice,
@@ -133,39 +95,6 @@
return this->exact().has(tmp);
}
-
- // For morphers: delegate.
-
- template <typename E>
- oln_rvalue(E)
- set_impl<abstract::image3d, morpher::tag::identity, E>
- ::impl_at(const oln_coord(E)& slice,
- const oln_coord(E)& row,
- const oln_coord(E)& col) const
- {
- return this->exact().delegate().at(slice, row, col);
- }
-
- template <typename E>
- oln_lvalue(E)
- set_impl<abstract::image3d, morpher::tag::identity, E>
- ::impl_at(const oln_coord(E)& slice,
- const oln_coord(E)& row,
- const oln_coord(E)& col)
- {
- return this->exact().delegate().at(slice, row, col);
- }
-
- template <typename E>
- bool
- set_impl<abstract::image3d, morpher::tag::identity, E>
- ::impl_has_at(const oln_coord(E)& slice,
- const oln_coord(E)& row,
- const oln_coord(E)& col) const
- {
- return this->exact().delegate().has_at(slice, row, col);
- }
-
# endif
} // end of namespace oln::automatic
Index: oln/core/automatic/image/mutable_image1d.hh
===================================================================
--- oln/core/automatic/image/mutable_image1d.hh (revision 0)
+++ oln/core/automatic/image/mutable_image1d.hh (revision 0)
@@ -0,0 +1,82 @@
+// Copyright (C) 2006 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_AUTOMATIC_IMAGE_IMAGE1D_HH
+# define OLN_CORE_AUTOMATIC_IMAGE_IMAGE1D_HH
+
+# include <oln/core/automatic/impl.hh>
+# include <oln/morpher/tags.hh>
+# include <oln/core/1d/point1d.hh>
+
+
+namespace oln
+{
+ // Forward declaration.
+ namespace abstract
+ {
+ template <typename E> class image1d;
+
+ } // end of namespace oln::abstract
+
+
+ namespace automatic
+ {
+
+
+ /// Default implementation corresponding to the interface
+ /// oln::abstract::image1d.
+ template <typename E, typename tag>
+ class set_impl<abstract::image1d, tag, E> :
+ public virtual stc::any__simple<E>
+ {
+ public:
+ oln_lvalue(E) impl_at(const oln_coord(E)& index);
+ };
+
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+
+ // 1. convert (index) -> p then 2. call operator()(p).
+
+ template <typename E, typename tag>
+ oln_lvalue(E)
+ set_impl<abstract::image1d, tag, E>
+ ::impl_at(const oln_coord(E)& index)
+ {
+ point1d tmp(index);
+ return this->exact().operator()(tmp);
+ }
+
+# endif
+
+ } // end of namespace oln::automatic
+
+} // end of namespace oln
+
+#endif // ! OLN_CORE_AUTOMATIC_IMAGE_IMAGE1D_HH
Index: oln/core/abstract/image.hh
===================================================================
--- oln/core/abstract/image.hh (revision 669)
+++ oln/core/abstract/image.hh (working copy)
@@ -29,9 +29,12 @@
#ifndef OLN_CORE_ABSTRACT_IMAGE_HH
# define OLN_CORE_ABSTRACT_IMAGE_HH
+# include <cstddef>
+
# include <oln/core/typedefs.hh>
# include <oln/core/abstract/fwd_decls.hh>
# include <oln/core/automatic/image/image.hh>
+# include <oln/debug/track.hh>
namespace oln
@@ -136,12 +139,14 @@
template <typename E>
image<E>::image()
{
+ ++debug::n_images;
}
template <typename E>
image<E>::~image()
{
decl();
+ --debug::n_images;
}
template <typename E>
Index: oln/core/abstract/image/dimension/1d.hh
===================================================================
--- oln/core/abstract/image/dimension/1d.hh (revision 669)
+++ oln/core/abstract/image/dimension/1d.hh (working copy)
@@ -30,6 +30,7 @@
# include <oln/core/abstract/image.hh>
# include <oln/core/automatic/image/image1d.hh>
+# include <oln/core/automatic/image/mutable_image1d.hh>
namespace oln
@@ -49,7 +50,6 @@
oln_rvalue(E) at(const oln_coord(E)& index) const;
// FIXME: Hack (should be elsewhere)!
- oln_lvalue(E) at(const oln_coord(E)& index);
bool has_at(const oln_coord(E)& index) const;
protected:
@@ -58,8 +58,26 @@
};
+ /// Class of 1D mutable images.
+ template <typename E>
+ struct mutable_image1d :
+ public image1d<E>,
+ public automatic::get_impl<mutable_image1d, E>
+ {
+ public:
+
+ oln_lvalue(E) at(const oln_coord(E)& index);
+
+ protected:
+ /// Constructor (protected, empty).
+ mutable_image1d();
+ };
+
+
# ifndef OLN_INCLUDE_ONLY
+ // image1d
+
template <typename E>
image1d<E>::image1d()
{
@@ -73,19 +91,26 @@
}
template <typename E>
- oln_lvalue(E)
- image1d<E>::at(const oln_coord(E)& index)
+ bool
+ image1d<E>::has_at(const oln_coord(E)& index) const
{
- return this->exact().impl_at(index);
+ return this->exact().impl_has_at(index);
}
+ // mutable_image1d
+
template <typename E>
- bool
- image1d<E>::has_at(const oln_coord(E)& index) const
+ mutable_image1d<E>::mutable_image1d()
{
- return this->exact().impl_has_at(index);
}
+ template <typename E>
+ oln_lvalue(E)
+ mutable_image1d<E>::at(const oln_coord(E)& index)
+ {
+ return this->exact().impl_at(index);
+ }
+
# endif
} // end of namespace oln::abstract
Index: oln/core/abstract/image/dimension/2d.hh
===================================================================
--- oln/core/abstract/image/dimension/2d.hh (revision 669)
+++ oln/core/abstract/image/dimension/2d.hh (working copy)
@@ -30,6 +30,7 @@
# include <oln/core/abstract/image.hh>
# include <oln/core/automatic/image/image2d.hh>
+# include <oln/core/automatic/image/mutable_image2d.hh>
namespace oln
@@ -49,7 +50,6 @@
oln_rvalue(E) at(const oln_coord(E)& row, const oln_coord(E)& col) const;
// FIXME: Hack (should be elsewhere)!
- oln_lvalue(E) at(const oln_coord(E)& row, const oln_coord(E)& col);
bool has_at(const oln_coord(E)& row, const oln_coord(E)& col) const;
protected:
@@ -58,8 +58,27 @@
};
+ /// Class of 2D mutable images.
+ template <typename E>
+ struct mutable_image2d :
+ public image2d<E>,
+ public automatic::get_impl<mutable_image2d, E>
+ {
+ public:
+
+ oln_lvalue(E) at(const oln_coord(E)& row, const oln_coord(E)& col);
+
+ protected:
+ /// Constructor (protected, empty).
+ mutable_image2d();
+ };
+
+
+
# ifndef OLN_INCLUDE_ONLY
+ // image2d
+
template <typename E>
image2d<E>::image2d()
{
@@ -73,19 +92,26 @@
}
template <typename E>
- oln_lvalue(E)
- image2d<E>::at(const oln_coord(E)& row, const oln_coord(E)& col)
+ bool
+ image2d<E>::has_at(const oln_coord(E)& row, const oln_coord(E)& col)
const
{
- return this->exact().impl_at(row, col);
+ return this->exact().impl_has_at(row, col);
}
+ // mutable_image2d
+
template <typename E>
- bool
- image2d<E>::has_at(const oln_coord(E)& row, const oln_coord(E)& col)
const
+ mutable_image2d<E>::mutable_image2d()
{
- return this->exact().impl_has_at(row, col);
}
+ template <typename E>
+ oln_lvalue(E)
+ mutable_image2d<E>::at(const oln_coord(E)& row, const oln_coord(E)&
col)
+ {
+ return this->exact().impl_at(row, col);
+ }
+
# endif
} // end of namespace oln::abstract
Index: oln/core/abstract/image/dimension/3d.hh
===================================================================
--- oln/core/abstract/image/dimension/3d.hh (revision 669)
+++ oln/core/abstract/image/dimension/3d.hh (working copy)
@@ -30,6 +30,7 @@
# include <oln/core/abstract/image.hh>
# include <oln/core/automatic/image/image3d.hh>
+# include <oln/core/automatic/image/mutable_image3d.hh>
namespace oln
@@ -51,9 +52,6 @@
const oln_coord(E)& col) const;
// FIXME: Hack (should be elsewhere)!
- oln_lvalue(E) at(const oln_coord(E)& slice,
- const oln_coord(E)& row,
- const oln_coord(E)& col);
bool has_at(const oln_coord(E)& slice,
const oln_coord(E)& row,
const oln_coord(E)& col) const;
@@ -64,8 +62,29 @@
};
+
+ /// Class of 3D mutable images.
+ template <typename E>
+ struct mutable_image3d :
+ public image3d<E>,
+ public automatic::get_impl<mutable_image3d, E>
+ {
+ public:
+
+ oln_lvalue(E) at(const oln_coord(E)& slice,
+ const oln_coord(E)& row,
+ const oln_coord(E)& col);
+
+ protected:
+ /// Constructor (protected, empty).
+ mutable_image3d();
+ };
+
+
# ifndef OLN_INCLUDE_ONLY
+ // image3d
+
template <typename E>
image3d<E>::image3d()
{
@@ -81,15 +100,6 @@
}
template <typename E>
- oln_lvalue(E)
- image3d<E>::at(const oln_coord(E)& slice,
- const oln_coord(E)& row,
- const oln_coord(E)& col)
- {
- return this->exact().impl_at(slice, row, col);
- }
-
- template <typename E>
bool
image3d<E>::has_at(const oln_coord(E)& slice,
const oln_coord(E)& row,
@@ -98,6 +108,22 @@
return this->exact().impl_has_at(slice, row, col);
}
+ // mutable_image3d
+
+ template <typename E>
+ mutable_image3d<E>::mutable_image3d()
+ {
+ }
+
+ template <typename E>
+ oln_lvalue(E)
+ mutable_image3d<E>::at(const oln_coord(E)& slice,
+ const oln_coord(E)& row,
+ const oln_coord(E)& col)
+ {
+ return this->exact().impl_at(slice, row, col);
+ }
+
# endif
} // end of namespace oln::abstract
Index: oln/core/abstract/image/dimension/hierarchy.hh
===================================================================
--- oln/core/abstract/image/dimension/hierarchy.hh (revision 669)
+++ oln/core/abstract/image/dimension/hierarchy.hh (working copy)
@@ -65,7 +65,10 @@
Default case: If no known grid type is returned by `oln_type_of(I, grid)',
the entry is directly plugged to abstract::image<I>. */
+// FIXME: Figure above is obsolete because of the introduction of
+// sub-abstractions related to mutability.
+
/*-------------------------.
| Dimension abstractions. |
`-------------------------*/
@@ -90,26 +93,53 @@
/// 1D case.
+
template <typename E>
struct case_< image_hierarchy_wrt_dimension, E, 1 > :
- where_< mlc::eq_< oln_type_of(E, grid), oln::grid1d > >
+ where_< mlc::and_< mlc::eq_< oln_grid(E), oln::grid1d >,
+ mlc_is_ok(oln_lvalue(E)) > >
{
+ typedef abstract::mutable_image1d<E> ret;
+ };
+
+ template <typename E>
+ struct case_< image_hierarchy_wrt_dimension, E, 2 > :
+ where_< mlc::eq_< oln_grid(E), oln::grid1d > >
+ {
typedef abstract::image1d<E> ret;
};
/// 2D case.
+
template <typename E>
- struct case_< image_hierarchy_wrt_dimension, E, 2 > :
- where_< mlc::eq_< oln_type_of(E, grid), oln::grid2d > >
+ struct case_< image_hierarchy_wrt_dimension, E, 3 > :
+ where_< mlc::and_< mlc::eq_< oln_grid(E), oln::grid2d >,
+ mlc_is_ok(oln_lvalue(E)) > >
{
+ typedef abstract::mutable_image2d<E> ret;
+ };
+
+ template <typename E>
+ struct case_< image_hierarchy_wrt_dimension, E, 4 > :
+ where_< mlc::eq_< oln_grid(E), oln::grid2d > >
+ {
typedef abstract::image2d<E> ret;
};
/// 3D case.
+
template <typename E>
- struct case_< image_hierarchy_wrt_dimension, E, 3 > :
- where_< mlc::eq_< oln_type_of(E, grid), oln::grid3d > >
+ struct case_< image_hierarchy_wrt_dimension, E, 5 > :
+ where_< mlc::and_< mlc::eq_< oln_grid(E), oln::grid3d >,
+ mlc_is_ok(oln_lvalue(E)) > >
{
+ typedef abstract::mutable_image3d<E> ret;
+ };
+
+ template <typename E>
+ struct case_< image_hierarchy_wrt_dimension, E, 6 > :
+ where_< mlc::eq_< oln_grid(E), oln::grid3d > >
+ {
typedef abstract::image3d<E> ret;
};
Index: oln/core/2d/array2d.hh
===================================================================
--- oln/core/2d/array2d.hh (revision 669)
+++ oln/core/2d/array2d.hh (working copy)
@@ -29,7 +29,7 @@
#ifndef OLN_CORE_2D_ARRAY2D_HH
# define OLN_CORE_2D_ARRAY2D_HH
-# include <cstdlib>
+# include <cstddef>
# include <mlc/contract.hh>
@@ -55,7 +55,7 @@
bool has(coord_t i, coord_t j) const;
- size_t memsize() const;
+ std::size_t memsize() const;
protected:
Index: oln/core/2d/image2d.hh
===================================================================
--- oln/core/2d/image2d.hh (revision 669)
+++ oln/core/2d/image2d.hh (working copy)
@@ -79,6 +79,9 @@
public:
+ /// Ctor without info.
+ image2d();
+
/// Ctor using sizes.
image2d(unsigned nrows, unsigned ncols, unsigned border = 2);
@@ -107,6 +110,13 @@
# ifndef OLN_INCLUDE_ONLY
template <typename T>
+ image2d<T>::image2d()
+ : topo_(),
+ data_()
+ {
+ }
+
+ template <typename T>
image2d<T>::image2d(unsigned nrows, unsigned ncols, unsigned border)
: topo_(bbox2d(point2d(0, 0 ),
point2d(nrows - 1, ncols - 1)),
@@ -145,6 +155,7 @@
template <typename T>
T image2d<T>::impl_at(int row, int col) const
{
+ precondition(data_ != 0);
precondition(data_->has(row, col));
return data_->operator()(row, col);
}
Index: oln/Makefile.am
===================================================================
--- oln/Makefile.am (revision 669)
+++ oln/Makefile.am (working copy)
@@ -98,6 +98,9 @@
core/automatic/image/image2d.hh \
core/automatic/image/image3d.hh \
core/automatic/image/mutable_image.hh \
+ core/automatic/image/mutable_image1d.hh \
+ core/automatic/image/mutable_image2d.hh \
+ core/automatic/image/mutable_image3d.hh \
core/automatic/image/image_being_random_accessible.hh \
core/automatic/image/image_having_neighborhood.hh \
core/automatic/image/image_having_neighborhood.hh \
@@ -156,6 +159,7 @@
core/type.hh \
\
debug/print.hh \
+ debug/track.hh \
debug/typename.hh \
\
io/pnm.hh \
@@ -170,6 +174,7 @@
morpher/identity.hh \
morpher/tags.hh \
morpher/slice.hh \
+ morpher/stack.hh \
morpher/thru_fun.hh \
morpher/thru_mfun.hh \
morpher/value_cast.hh \
Index: oln/morpher/stack.hh
===================================================================
--- oln/morpher/stack.hh (revision 0)
+++ oln/morpher/stack.hh (revision 0)
@@ -0,0 +1,191 @@
+// Copyright (C) 2006 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_MORPHER_STACK_HH
+# define OLN_MORPHER_STACK_HH
+
+# include <xtd/vec.hh>
+# include <oln/morpher/internal/image_value_morpher.hh>
+
+
+
+namespace oln
+{
+
+ namespace morpher
+ {
+ // Forward declaration.
+ template <unsigned n, typename I> struct stack;
+
+ } // end of namespace oln::morpher
+
+
+ /// Super type.
+ template <unsigned n, typename I>
+ struct set_super_type< morpher::stack<n, I> >
+ {
+ typedef morpher::stack<n, I> self_t;
+ typedef morpher::internal::image_value_morpher<I, self_t> ret;
+ };
+
+ template <unsigned n, typename I>
+ struct vtypes< morpher::stack<n, I> >
+ {
+ typedef mlc::true_ is_computed_type;
+ typedef xtd::vec<n, oln_value(I)> value_type;
+ };
+
+ template <unsigned n, typename I>
+ struct single_vtype< morpher::stack<n, I>, typedef_::rvalue_type >
+ {
+ typedef xtd::vec<n, oln_value(I)> ret;
+ };
+
+
+ namespace morpher
+ {
+ /// "Stack of images" morpher.
+ template <unsigned n, typename I>
+ class stack : public internal::image_value_morpher< I, stack<n, I> >
+ {
+ private:
+
+ typedef stack<n, I> self_t;
+ typedef internal::image_value_morpher<I, self_t> super_t;
+
+ typedef oln_psite(self_t) psite_t;
+ typedef oln_rvalue(self_t) rvalue_t;
+
+ public:
+
+ stack(const xtd::vec<n, I>& images);
+
+ xtd::vec<n, oln_value(I)> impl_op_read(const psite_t& p) const;
+
+ const I& image(unsigned i) const;
+
+ protected:
+ xtd::vec<n, I> images_;
+ };
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <unsigned n, typename I>
+ stack<n, I>::stack(const xtd::vec<n, I>& images) :
+ super_t(images[0]),
+ images_(images)
+ {
+ }
+
+ template <unsigned n, typename I>
+ xtd::vec<n, oln_value(I)>
+ stack<n, I>::impl_op_read(const typename stack<n, I>::psite_t& p)
const
+ {
+ xtd::vec<n, oln_value(I)> tmp;
+ for (unsigned i = 0; i < n; ++i)
+ tmp[i] = images_[i](p);
+ return tmp;
+ }
+
+ template <unsigned n, typename I>
+ const I&
+ stack<n, I>::image(unsigned i) const
+ {
+ precondition(i < n);
+ return images_[i];
+ }
+
+# endif
+
+ } // end of namespace oln::morpher
+
+
+ template <typename I>
+ morpher::stack<2, I>
+ stack(const abstract::image<I>& image_0,
+ const abstract::image<I>& image_1);
+
+ template <typename I>
+ morpher::stack<3, I>
+ stack(const abstract::image<I>& image_0,
+ const abstract::image<I>& image_1,
+ const abstract::image<I>& image_2);
+
+ template <typename I>
+ morpher::stack<4, I>
+ stack(const abstract::image<I>& image_0,
+ const abstract::image<I>& image_1,
+ const abstract::image<I>& image_2,
+ const abstract::image<I>& image_3);
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+
+ template <typename I>
+ morpher::stack<2, I>
+ stack(const abstract::image<I>& image_0,
+ const abstract::image<I>& image_1)
+ {
+ morpher::stack<2, I> tmp(xtd::mk_vec(image_0.exact(),
+ image_1.exact()));
+ return tmp;
+ }
+
+ template <typename I>
+ morpher::stack<3, I>
+ stack(const abstract::image<I>& image_0,
+ const abstract::image<I>& image_1,
+ const abstract::image<I>& image_2)
+ {
+ morpher::stack<3, I> tmp(xtd::mk_vec(image_0.exact(),
+ image_1.exact(),
+ image_2.exact()));
+ return tmp;
+ }
+
+ template <typename I>
+ morpher::stack<4, I>
+ stack(const abstract::image<I>& image_0,
+ const abstract::image<I>& image_1,
+ const abstract::image<I>& image_2,
+ const abstract::image<I>& image_3)
+ {
+ morpher::stack<4, I> tmp(xtd::mk_vec(image_0.exact(),
+ image_1.exact(),
+ image_2.exact(),
+ image_3.exact()));
+ return tmp;
+ }
+
+# endif
+
+} // end of namespace oln
+
+
+#endif // ! OLN_MORPHER_STACK_HH