Index: ChangeLog
from Nicolas Ballas <ballas(a)lrde.epita.fr>
fast_iterator for image1d.
* tests/core/fiter_point1d.cc: New test.
* tests/core/3dtorle.cc: Update test (it was too long).
* tests/core/Makefile.am: Update.
* oln/core/1d/image1d.hh: new fiter type.
* oln/core/1d/fast_iterator_1d.hh: New, fast iterator for image 1d.
* oln/core/concept/fast_iterator.hh: New concept (operator* for fast iterators).
oln/core/1d/fast_iterator_1d.hh | 143 ++++++++++++++++++++++++++++++++++++++
oln/core/1d/image1d.hh | 22 +++++
oln/core/concept/fast_iterator.hh | 87 +++++++++++++++++++++++
tests/core/3dtorle.cc | 19 ++---
tests/core/Makefile.am | 2
tests/core/fiter_point1d.cc | 59 +++++++++++++++
6 files changed, 322 insertions(+), 10 deletions(-)
Index: tests/core/fiter_point1d.cc
--- tests/core/fiter_point1d.cc (revision 0)
+++ tests/core/fiter_point1d.cc (revision 0)
@@ -0,0 +1,59 @@
+// 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/1d/image1d.hh>
+
+
+int
+main()
+{
+ using namespace oln;
+
+ image1d<int> ima(10);
+
+ image1d<int>::piter p(ima.points());
+ image1d<int>::fiter f(ima);
+ int i = 0;
+
+ for_all(p)
+ {
+ ima(p) = i++;
+ }
+ i = 0;
+
+ for_all(f)
+ {
+ assert(*f == i ++);
+ *f = 5;
+ }
+
+ f.start();
+ assert(f.is_valid());
+ f.invalidate();
+ assert(!f.is_valid());
+}
Index: tests/core/3dtorle.cc
--- tests/core/3dtorle.cc (revision 958)
+++ tests/core/3dtorle.cc (working copy)
@@ -46,7 +46,7 @@
using namespace oln;
// Fill a 3D image with a cos.
- image3d<float> ima3d(100, 100, 100);
+ image3d<float> ima3d(20, 20, 20);
level::fill(inplace(ima3d), my_sinus);
@@ -55,7 +55,7 @@
// value < 0 => -1
// value > 0 => 1
// value next to 0 => 0
- image3d<short> ima3s(100, 100, 100);
+ image3d<short> ima3s(20, 20, 20);
image3d<float>::piter p(ima3d.points());
for_all(p)
{
@@ -79,13 +79,12 @@
ima3rle = rle_encode(ima3s);
rle_image<point3d, short>::piter p1(ima3rle.points());
-// std::cout << "start test" << std::endl;
-// for_all(p1)
-// {
-// // std::cout << "point: " << p1.to_point() <<
std::endl;
-// // std::cout << "3s : " << ima3s(p1) << std::endl;
-// // std::cout << "rle: " << ima3rle(p1) <<
std::endl;
-// assert(ima3s(p1) == ima3rle(p1));
-// }
+ for_all(p1)
+ {
+// if (ima3rle(p1))
+// ima3rle(p1) = 42;
+ // this test is too long
+ assert(ima3s(p1) == ima3rle(p1));
+ }
}
Index: tests/core/Makefile.am
--- tests/core/Makefile.am (revision 958)
+++ tests/core/Makefile.am (working copy)
@@ -27,6 +27,7 @@
image2d \
iter_point1d \
iter_point2d \
+ fiter_point1d \
neighb2d \
npoints \
point2d \
@@ -46,6 +47,7 @@
image2d_SOURCES = image2d.cc
iter_point1d_SOURCES = iter_point1d.cc
iter_point2d_SOURCES = iter_point2d.cc
+fiter_point1d_SOURCES = fiter_point1d.cc
neighb2d_SOURCES = neighb2d.cc
npoints_SOURCES = npoints.cc
point2d_SOURCES = point2d.cc
Index: oln/core/1d/image1d.hh
--- oln/core/1d/image1d.hh (revision 958)
+++ oln/core/1d/image1d.hh (working copy)
@@ -33,6 +33,7 @@
# include <oln/core/internal/image_base.hh>
# include <oln/core/internal/utils.hh>
# include <oln/core/1d/array1d.hh>
+# include <oln/core/1d/fast_iterator_1d.hh>
namespace oln
@@ -60,6 +61,8 @@
typedef image1d<T> plain;
typedef image1d<pl::value> skeleton;
+
+ typedef fast_iterator_1d<value, coord> fiter;
};
@@ -81,6 +84,8 @@
typedef internal::plain_primitive_image_<current> super;
typedef array1d_<T, int> array_t;
public:
+ //FIXME (fast image concept??)
+ typedef typename vtypes< image1d<T> >::fiter fiter;
stc_using(data);
image1d();
@@ -89,6 +94,9 @@
image1d(int imin, int imax);
image1d(unsigned n);
+ array_t& img_array();
+ const array_t& img_array() const;
+
bool impl_owns_(const point1d& p) const;
const T& impl_read(const point1d& p) const;
@@ -153,6 +161,20 @@
}
template <typename T>
+ typename image1d<T>::array_t&
+ image1d<T>::img_array()
+ {
+ return this->data_->first;
+ }
+
+ template <typename T>
+ const typename image1d<T>::array_t&
+ image1d<T>::img_array() const
+ {
+ return this->data_->first;
+ }
+
+ template <typename T>
bool image1d<T>::impl_owns_(const point1d& p) const
{
assert(this->has_data());
Index: oln/core/1d/fast_iterator_1d.hh
--- oln/core/1d/fast_iterator_1d.hh (revision 0)
+++ oln/core/1d/fast_iterator_1d.hh (revision 0)
@@ -0,0 +1,143 @@
+// 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_1D_FAST_ITERATOR_1D_HH
+# define OLN_CORE_1D_FAST_ITERATOR_1D_HH
+
+# include <cassert>
+# include <oln/core/concept/fast_iterator.hh>
+# include <oln/core/1d/array1d.hh>
+
+namespace oln
+{
+ // Fwd decl.
+ template <typename T> class image1d;
+ template <typename T, typename C> class fast_iterator_1d;
+
+ // Super type.
+ template <typename T, typename C>
+ struct super_trait_< fast_iterator_1d<T, C> >
+ {
+ typedef fast_iterator_1d<T, C> current;
+ typedef Fast_Iterator<current> ret;
+ };
+
+ // Virtual types.
+ template <typename T, typename C>
+ struct vtypes< fast_iterator_1d<T, C> >
+ {
+ typedef T value;
+ };
+
+ // Fast iterator for image in one dimension
+ template <typename T, typename C>
+ class fast_iterator_1d : public Fast_Iterator< fast_iterator_1d<T, C> >
+ {
+ typedef fast_iterator_1d<T, C> current;
+ typedef Fast_Iterator<current> super;
+ public:
+ stc_using(value);
+
+ fast_iterator_1d(image1d<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_1d<T, C>::fast_iterator_1d(image1d<T>& ima)
+ {
+ start_ = ima.img_array().buffer() + ima.img_array().imin();
+ current_elt_ = start_;
+ eoi_ = ima.img_array().buffer() + ima.img_array().imax() + 1;
+ }
+
+ template <typename T, typename C>
+ void
+ fast_iterator_1d<T, C>::impl_start()
+ {
+ current_elt_ = start_;
+ }
+
+ template <typename T, typename C>
+ void
+ fast_iterator_1d<T, C>::impl_next()
+ {
+ assert(this->impl_is_valid());
+ ++current_elt_;
+ }
+
+ template <typename T, typename C>
+ void
+ fast_iterator_1d<T, C>::impl_invalidate()
+ {
+ current_elt_ = eoi_;
+ }
+
+ template <typename T, typename C>
+ bool
+ fast_iterator_1d<T, C>::impl_is_valid() const
+ {
+ return current_elt_ != eoi_;
+ }
+
+ template <typename T, typename C>
+ typename fast_iterator_1d<T, C>::value&
+ fast_iterator_1d<T, C>::impl_dereference()
+ {
+ assert(this->impl_is_valid());
+ return *current_elt_;
+ }
+
+ template <typename T, typename C>
+ const typename fast_iterator_1d<T, C>::value&
+ fast_iterator_1d<T, C>::impl_dereference() const
+ {
+ assert(this->impl_is_valid());
+ return *current_elt_;
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+} // end of namespace oln
+
+#endif // OLN_CORE_1D_FAST_ITERATOR_1D_HH
+
Index: oln/core/concept/fast_iterator.hh
--- oln/core/concept/fast_iterator.hh (revision 0)
+++ oln/core/concept/fast_iterator.hh (revision 0)
@@ -0,0 +1,87 @@
+// 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_CONCEPT_FAST_ITERATOR_HH
+# define OLN_CORE_CONCEPT_FAST_ITERATOR_HH
+
+# include <oln/core/concept/iterator.hh>
+
+namespace oln
+{
+
+ // Concept-class "Fast_Iterator".
+ template <typename Exact>
+ struct Fast_Iterator : public Iterator<Exact>
+ {
+ stc_typename(value);
+
+ value& operator* ();
+ const value& operator*() const;
+
+ protected:
+ Fast_Iterator();
+
+ private:
+ void check__() const;
+ };
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename Exact>
+ Fast_Iterator<Exact>::Fast_Iterator()
+ {
+ }
+
+ template <typename Exact>
+ typename Fast_Iterator<Exact>::value&
+ Fast_Iterator<Exact>::operator* ()
+ {
+ return exact(this)->impl_dereference();
+ }
+
+ template <typename Exact>
+ const typename Fast_Iterator<Exact>::value&
+ Fast_Iterator<Exact>::operator* () const
+ {
+ return exact(this)->impl_dereference();
+ }
+
+ template <typename Exact>
+ void Fast_Iterator<Exact>::check__() const
+ {
+ // FIXME
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+} // end of namespace oln
+
+
+
+#endif // ! OLN_CORE_CONCEPT_FAST_ITERATOR_HH