Index: ChangeLog
from Nicolas Ballas <ballas(a)lrde.epita.fr>
fast iterator for image 2d and 3d.
* tests/core/fiter_point1d.cc: Update test.
* tests/core/fiter_point2d.cc:,
* tests/core/fiter_point3d.cc: New test.
* tests/core/Makefile.am: Update.
* oln/core/1d/fast_iterator_1d.hh: remove a useless include.
* oln/core/2d/fast_iterator_2d.hh,
* oln/core/3d/fast_iterator_3d.hh: New fast iterator
* oln/core/2d/image2d.hh,
* oln/core/3d/image3d.hh: add fast iterator on the image
oln/core/1d/fast_iterator_1d.hh | 1
oln/core/2d/fast_iterator_2d.hh | 144 ++++++++++++++++++++++++++++++++++++++
oln/core/2d/image2d.hh | 22 +++++
oln/core/3d/fast_iterator_3d.hh | 150 ++++++++++++++++++++++++++++++++++++++++
oln/core/3d/image3d.hh | 22 +++++
tests/core/Makefile.am | 4 +
tests/core/fiter_point1d.cc | 6 +
tests/core/fiter_point2d.cc | 64 +++++++++++++++++
tests/core/fiter_point3d.cc | 61 ++++++++++++++++
9 files changed, 472 insertions(+), 2 deletions(-)
Index: tests/core/fiter_point1d.cc
--- tests/core/fiter_point1d.cc (revision 959)
+++ tests/core/fiter_point1d.cc (working copy)
@@ -28,7 +28,6 @@
#include <cassert>
#include <oln/core/1d/image1d.hh>
-
int
main()
{
@@ -52,6 +51,11 @@
*f = 5;
}
+ for_all(p)
+ {
+ assert(ima(p) == 5);
+ }
+
f.start();
assert(f.is_valid());
f.invalidate();
Index: tests/core/fiter_point2d.cc
--- tests/core/fiter_point2d.cc (revision 0)
+++ tests/core/fiter_point2d.cc (revision 0)
@@ -0,0 +1,64 @@
+// 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.
+
+#include <cassert>
+#include <oln/core/2d/image2d.hh>
+
+
+int
+main()
+{
+ using namespace oln;
+
+ image2d<int> ima(20, 20);
+
+ image2d<int>::piter p(ima.points());
+ image2d<int>::fiter f(ima);
+ int i = 0;
+
+ for_all(p)
+ {
+ ima(p) = i++;
+ }
+ i = 0;
+
+ for_all(f)
+ {
+ assert(*f == i ++);
+ *f = 5;
+ }
+
+ for_all(p)
+ {
+ assert(ima(p) == 5);
+ }
+
+ f.start();
+ assert(f.is_valid());
+ f.invalidate();
+ assert(!f.is_valid());
+}
Index: tests/core/fiter_point3d.cc
--- tests/core/fiter_point3d.cc (revision 0)
+++ tests/core/fiter_point3d.cc (revision 0)
@@ -0,0 +1,61 @@
+// 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.
+
+#include <cassert>
+#include <oln/core/3d/image3d.hh>
+
+
+int
+main()
+{
+ using namespace oln;
+
+ image3d<int> ima(20, 20, 20);
+
+ image3d<int>::piter p(ima.points());
+ image3d<int>::fiter f(ima);
+ int i = 0;
+
+ for_all(p)
+ ima(p) = i++;
+
+ i = 0;
+
+ for_all(f)
+ {
+ assert(*f == i ++);
+ *f = 5;
+ }
+
+ for_all(p)
+ assert(ima(p) == 5);
+
+ f.start();
+ assert(f.is_valid());
+ f.invalidate();
+ assert(!f.is_valid());
+}
Index: tests/core/Makefile.am
--- tests/core/Makefile.am (revision 959)
+++ tests/core/Makefile.am (working copy)
@@ -28,6 +28,8 @@
iter_point1d \
iter_point2d \
fiter_point1d \
+ fiter_point2d \
+ fiter_point3d \
neighb2d \
npoints \
point2d \
@@ -48,6 +50,8 @@
iter_point1d_SOURCES = iter_point1d.cc
iter_point2d_SOURCES = iter_point2d.cc
fiter_point1d_SOURCES = fiter_point1d.cc
+fiter_point2d_SOURCES = fiter_point2d.cc
+fiter_point3d_SOURCES = fiter_point3d.cc
neighb2d_SOURCES = neighb2d.cc
npoints_SOURCES = npoints.cc
point2d_SOURCES = point2d.cc
Index: oln/core/1d/fast_iterator_1d.hh
--- oln/core/1d/fast_iterator_1d.hh (revision 959)
+++ oln/core/1d/fast_iterator_1d.hh (working copy)
@@ -31,7 +31,6 @@
# include <cassert>
# include <oln/core/concept/fast_iterator.hh>
-# include <oln/core/1d/array1d.hh>
namespace oln
{
Index: oln/core/2d/fast_iterator_2d.hh
--- oln/core/2d/fast_iterator_2d.hh (revision 0)
+++ oln/core/2d/fast_iterator_2d.hh (revision 0)
@@ -0,0 +1,144 @@
+// 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_2D_FAST_ITERATOR_2D_HH
+# define OLN_CORE_2D_FAST_ITERATOR_2D_HH
+
+# include <cassert>
+# include <oln/core/concept/fast_iterator.hh>
+
+namespace oln
+{
+
+ // Fwd decl.
+ template <typename T> class image2d;
+ template <typename T, typename C> class fast_iterator_2d;
+
+ // Super type.
+ template <typename T, typename C>
+ struct super_trait_< fast_iterator_2d<T, C> >
+ {
+ typedef fast_iterator_2d<T, C> current;
+ typedef Fast_Iterator<current> ret;
+ };
+
+ // Virtual types.
+ template <typename T, typename C>
+ struct vtypes< fast_iterator_2d<T, C> >
+ {
+ typedef T value;
+ };
+
+ // fast iterator for image2d
+ template <typename T, typename C>
+ class fast_iterator_2d : public Fast_Iterator< fast_iterator_2d<T, C> >
+ {
+ typedef fast_iterator_2d<T, C> current;
+ typedef Fast_Iterator<current> super;
+ public:
+ stc_using(value);
+ fast_iterator_2d(image2d<T>& ima);
+
+ void impl_start();
+ void impl_next();
+ void impl_invalidate();
+ bool impl_is_valid() const;
+
+ value& impl_dereference();
+ const value& impl_dereference() const;
+
+ protected:
+ T* start_; // buffer start
+ T* current_elt_;
+ T* eoi_; // buffer end;
+ };
+
+# ifndef OLN_INCLUDE_ONLY
+
+ // initialize the fields start_ and eoi_, to image buffer start and end
+ template <typename T, typename C>
+ fast_iterator_2d<T, C>::fast_iterator_2d(image2d<T>& ima)
+ {
+ start_ = ima.img_array().buffer() + ima.img_array().imin() * ima.img_array().jmin()
+
+ ima.img_array().jmin();
+ current_elt_ = start_;
+ eoi_ = ima.img_array().buffer() + (ima.img_array().imax() - ima.img_array().imin() +
1) *
+ (ima.img_array().jmax() - ima.img_array().imin() + 1);
+ }
+
+ template <typename T, typename C>
+ void
+ fast_iterator_2d<T, C>::impl_start()
+ {
+ current_elt_ = start_;
+ }
+
+ template <typename T, typename C>
+ void
+ fast_iterator_2d<T, C>::impl_next()
+ {
+ assert(this->impl_is_valid());
+ ++current_elt_;
+ }
+
+ template <typename T, typename C>
+ void
+ fast_iterator_2d<T, C>::impl_invalidate()
+ {
+ current_elt_ = eoi_;
+ }
+
+ template <typename T, typename C>
+ bool
+ fast_iterator_2d<T, C>::impl_is_valid() const
+ {
+ return current_elt_ != eoi_;
+ }
+
+ template <typename T, typename C>
+ typename fast_iterator_2d<T, C>::value&
+ fast_iterator_2d<T, C>::impl_dereference()
+ {
+ assert(this->impl_is_valid());
+ return *current_elt_;
+ }
+
+ template <typename T, typename C>
+ const typename fast_iterator_2d<T, C>::value&
+ fast_iterator_2d<T, C>::impl_dereference() const
+ {
+ assert(this->impl_is_valid());
+ return *current_elt_;
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+} // end of namespace oln
+
+
+#endif // !OLN_CORE_2D_FAST_ITERATOR_2D_HH
Index: oln/core/2d/image2d.hh
--- oln/core/2d/image2d.hh (revision 959)
+++ oln/core/2d/image2d.hh (working copy)
@@ -33,6 +33,7 @@
# include <oln/core/internal/image_base.hh>
# include <oln/core/internal/utils.hh>
# include <oln/core/2d/array2d.hh>
+# include <oln/core/2d/fast_iterator_2d.hh>
namespace oln
@@ -60,6 +61,8 @@
typedef image2d<T> plain;
typedef image2d<pl::value> skeleton;
+
+ typedef fast_iterator_2d<value, coord> fiter;
};
@@ -81,6 +84,8 @@
typedef internal::plain_primitive_image_<current> super;
typedef array2d_<T, int> array_t;
public:
+ //FIXME (fast image concept??)
+ typedef typename vtypes< image2d<T> >::fiter fiter;
stc_using(data);
image2d();
@@ -88,6 +93,9 @@
image2d(unsigned nrows, unsigned ncols);
image2d(int min_row, int min_col, int max_row, int max_col);
+ array_t& img_array();
+ const array_t& img_array() const;
+
bool impl_owns_(const point2d& p) const;
bool impl_has_at(int row, int col) const;
@@ -150,6 +158,20 @@
}
template <typename T>
+ typename image2d<T>::array_t&
+ image2d<T>::img_array()
+ {
+ return this->data_->first;
+ }
+
+ template <typename T>
+ const typename image2d<T>::array_t&
+ image2d<T>::img_array() const
+ {
+ return this->data_->first;
+ }
+
+ template <typename T>
bool image2d<T>::impl_owns_(const point2d& p) const
{
assert(this->has_data());
Index: oln/core/3d/image3d.hh
--- oln/core/3d/image3d.hh (revision 959)
+++ oln/core/3d/image3d.hh (working copy)
@@ -33,6 +33,7 @@
# include <oln/core/internal/image_base.hh>
# include <oln/core/internal/utils.hh>
# include <oln/core/3d/array3d.hh>
+# include <oln/core/3d/fast_iterator_3d.hh>
namespace oln
@@ -60,6 +61,8 @@
typedef image3d<T> plain;
typedef image3d<pl::value> skeleton;
+
+ typedef fast_iterator_3d<value, coord> fiter;
};
@@ -81,12 +84,17 @@
typedef internal::plain_primitive_image_<current> super;
typedef array3d_<T, int> array_t;
public:
+ //FIXME (fast image concept??)
+ typedef typename vtypes< image3d<T> >::fiter fiter;
stc_using(data);
image3d();
image3d(const box3d& b);
image3d(unsigned nslis, unsigned nrows, unsigned ncols);
+ array_t& img_array();
+ const array_t& img_array() const;
+
bool impl_owns_(const point3d& p) const;
bool impl_has_at(int sli, int row, int col) const;
@@ -147,6 +155,20 @@
}
template <typename T>
+ typename image3d<T>::array_t&
+ image3d<T>::img_array()
+ {
+ return this->data_->first;
+ }
+
+ template <typename T>
+ const typename image3d<T>::array_t&
+ image3d<T>::img_array() const
+ {
+ return this->data_->first;
+ }
+
+ template <typename T>
bool image3d<T>::impl_owns_(const point3d& p) const
{
assert(this->has_data());
Index: oln/core/3d/fast_iterator_3d.hh
--- oln/core/3d/fast_iterator_3d.hh (revision 0)
+++ oln/core/3d/fast_iterator_3d.hh (revision 0)
@@ -0,0 +1,150 @@
+// 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_2D_FAST_ITERATOR_3D_HH
+# define OLN_CORE_2D_FAST_ITERATOR_3D_HH
+
+# include <cassert>
+# include <oln/core/concept/fast_iterator.hh>
+
+namespace oln
+{
+
+ // Fwd decl.
+ template <typename T> class image3d;
+ template <typename T, typename C> class fast_iterator_3d;
+
+ // Super type.
+ template <typename T, typename C>
+ struct super_trait_< fast_iterator_3d<T, C> >
+ {
+ typedef fast_iterator_3d<T, C> current;
+ typedef Fast_Iterator<current> ret;
+ };
+
+ // Virtual types.
+ template <typename T, typename C>
+ struct vtypes< fast_iterator_3d<T, C> >
+ {
+ typedef T value;
+ };
+
+ // fast iterator for image3d
+ template <typename T, typename C>
+ class fast_iterator_3d : public Fast_Iterator< fast_iterator_3d<T, C> >
+ {
+ typedef fast_iterator_3d<T, C> current;
+ typedef Fast_Iterator<current> super;
+ public:
+ stc_using(value);
+ fast_iterator_3d(image3d<T>& ima);
+
+ void impl_start();
+ void impl_next();
+ void impl_invalidate();
+ bool impl_is_valid() const;
+
+ value& impl_dereference();
+ const value& impl_dereference() const;
+
+ protected:
+ T* start_; // buffer start
+ T* current_elt_;
+ T* eoi_; // buffer end;
+ };
+
+# ifndef OLN_INCLUDE_ONLY
+
+ // initialize the fields start_ and eoi_, to image buffer start and end
+ template <typename T, typename C>
+ fast_iterator_3d<T, C>::fast_iterator_3d(image3d<T>& ima)
+ {
+ start_ = ima.img_array().buffer() +
+ ima.img_array().imin() * ima.img_array().jmin() * ima.img_array().kmin() +
+ ima.img_array().jmin() * ima.img_array().kmin() +
+ ima.img_array().kmin();
+
+ current_elt_ = start_;
+
+ eoi_ = ima.img_array().buffer() +
+ (ima.img_array().imax() - ima.img_array().imin() + 1) *
+ (ima.img_array().jmax() - ima.img_array().imin() + 1) *
+ (ima.img_array().kmax() - ima.img_array().kmin() + 1);
+ }
+
+ template <typename T, typename C>
+ void
+ fast_iterator_3d<T, C>::impl_start()
+ {
+ current_elt_ = start_;
+ }
+
+ template <typename T, typename C>
+ void
+ fast_iterator_3d<T, C>::impl_next()
+ {
+ assert(this->impl_is_valid());
+ ++current_elt_;
+ }
+
+ template <typename T, typename C>
+ void
+ fast_iterator_3d<T, C>::impl_invalidate()
+ {
+ current_elt_ = eoi_;
+ }
+
+ template <typename T, typename C>
+ bool
+ fast_iterator_3d<T, C>::impl_is_valid() const
+ {
+ return current_elt_ != eoi_;
+ }
+
+ template <typename T, typename C>
+ typename fast_iterator_3d<T, C>::value&
+ fast_iterator_3d<T, C>::impl_dereference()
+ {
+ assert(this->impl_is_valid());
+ return *current_elt_;
+ }
+
+ template <typename T, typename C>
+ const typename fast_iterator_3d<T, C>::value&
+ fast_iterator_3d<T, C>::impl_dereference() const
+ {
+ assert(this->impl_is_valid());
+ return *current_elt_;
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+} // end of namespace oln
+
+
+#endif // !OLN_CORE_3D_FAST_ITERATOR_3D_HH