En regardant oln/core/abstract/image_dimension.hh, je me suis demandé
si ce ne devrait pas être le rôle des classes oln::abstract::image1d,
oln::abstract::image2d et oln::abstract::image3d de définir
operator(), point_type, etc., au lieu de oln::image1d, oln::image2d et
oln::image3d (comme c'était grosso modo le cas dans Olena 0.10, dans
oln::abstract::image_with_dim)).
https://svn.lrde.epita.fr/svn/oln/prototypes/proto-1.0
ChangeLog | 24 ++++++++++++++++++++++
oln/core/1d/image1d.hh | 18 ++++++++++++++++
oln/core/2d/image2d.hh | 19 +++++++++++++++++
oln/core/3d/image3d.hh | 20 ++++++++++++++++++
oln/core/abstract/image.hh | 4 +--
oln/utils/clone.hh | 2 -
tests/arith/Makefile.am | 5 ----
tests/arith/tests/max | 25 -----------------------
tests/arith/tests/min | 27 -------------------------
tests/level/tests/max | 5 ++--
tests/level/tests/min | 5 ++--
tests/pw/tests/arith-image | 48 +++++++++++++++++++++++++++++++++++++++++++++
tests/pw/tests/arith-value | 28 ++++++++++++++++++++++++++
13 files changed, 166 insertions(+), 64 deletions(-)
Index: olena/ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Add operator()'s on oln::image1d, oln::image2d and oln::image3d.
* oln/core/abstract/image.hh
(operator[](const point_type&) const): Return a value_box<const D>
instead of a value_box<D>.
(operator[](const point_type&)): Return a value_box<D> instead of
a value_box<const D>.
* oln/core/1d/image1d.hh (operator()(coord_t) const)
(operator()(coord_t))
* oln/core/2d/image2d.hh (operator()(coord_t, coord_t) const)
(operator()(coord_t, coord_t))
* oln/core/3d/image3d.hh
(operator()(coord_t, coord_t, coord_t) const)
(operator()(coord_t, coord_t, coord_t)): New operators.
* oln/utils/clone.hh (clone): Adjust comment.
* tests/arith: Remove directory.
* tests/pw/tests/arith-value, tests/pw/tests/arith-image: New
tests.
* tests/level/tests/min, tests/level/tests/max: New
tests (not yet working).
Index: olena/tests/pw/tests/arith-value
--- olena/tests/pw/tests/arith-value (revision 0)
+++ olena/tests/pw/tests/arith-value (revision 0)
@@ -0,0 +1,28 @@
+ // -*- C++ -*-
+#include <iostream>
+#include <cmath>
+
+#include <oln/core/pw/arith.hh>
+#include <oln/core/pw/literal.hh>
+#include <oln/core/pw/value.hh>
+#include <oln/core/any/point.hh>
+
+using namespace oln;
+
+// Check arith operators on pw::value's.
+bool check()
+{
+ any_point p;
+ pw::literal<int> pv1(p_literal(42));
+ pw::literal<int> pv2(p_literal(51));
+
+ int res_min = min(pv1, pv2)(p);
+ if (res_min != 42)
+ return true;
+
+ int res_max = max(pv1, pv2)(p);
+ if (res_max != 51)
+ return true;
+
+ return false;
+}
Index: olena/tests/pw/tests/arith-image
--- olena/tests/pw/tests/arith-image (revision 0)
+++ olena/tests/pw/tests/arith-image (revision 0)
@@ -0,0 +1,48 @@
+ // -*- C++ -*-
+#include <iostream>
+#include <cmath>
+
+#include <oln/core/pw/arith.hh>
+#include <oln/core/pw/literal.hh>
+#include <oln/core/pw/value.hh>
+#include <oln/core/2d/image2d.hh>
+#include <oln/core/2d/point2d.hh>
+
+using namespace oln;
+
+// Check arith operators on pw::images's.
+bool check()
+{
+ typedef image2d<int> ima_type;
+
+ // ima1 =
+ // 1 2 3
+ // 4 5 6
+ // 7 8 9
+ ima_type ima1(3, 3);
+ ima1(0, 0) = 1; ima1(0, 1) = 2; ima1(0, 2) = 3;
+ ima1(1, 0) = 4; ima1(1, 1) = 5; ima1(1, 2) = 6;
+ ima1(2, 0) = 7; ima1(2, 1) = 8; ima1(2, 2) = 9;
+
+ // ima2 =
+ // 1 2 3
+ // 4 5 6
+ // 7 8 9
+ ima_type ima2(3, 3);
+ ima2(0, 0) = 9; ima2(0, 1) = 8; ima2(0, 2) = 7;
+ ima2(1, 0) = 6; ima2(1, 1) = 5; ima2(1, 2) = 4;
+ ima2(2, 0) = 3; ima2(2, 1) = 2; ima2(2, 2) = 1;
+
+ pw::value<ima_type> pv1(pw_value(ima1));
+ pw::value<ima_type> pv2(pw_value(ima2));
+
+ point2d p1(0, 1);
+ if (min(pv1, pv2)(p1) != 2)
+ return true;
+
+ point2d p2(2, 0);
+ if (max(pv1, pv2)(p2) != 7)
+ return true;
+
+ return false;
+}
Index: olena/tests/level/tests/min
--- olena/tests/level/tests/min (revision 181)
+++ olena/tests/level/tests/min (working copy)
@@ -1,5 +1,6 @@
+ // -*- C++ -*-
#include <oln/basics2d.hh>
-#include <oln/arith/min.hh>
+#include <oln/level/arith.hh>
#include <oln/level/fill.hh>
#include <oln/level/compare.hh>
#include <ntg/int.hh>
@@ -16,7 +17,7 @@
oln::image2d<ntg::int_u8> ima;
- ima = oln::arith::min(ima1, ima2);
+ ima = oln::level::min(ima1, ima2);
if (oln::level::is_equal(ima, ima1))
return false;
Index: olena/tests/level/tests/max
--- olena/tests/level/tests/max (revision 181)
+++ olena/tests/level/tests/max (working copy)
@@ -1,5 +1,6 @@
+ // -*- C++ -*-
#include <oln/basics2d.hh>
-#include <oln/arith/max.hh>
+#include <oln/level/arith.hh>
#include <oln/level/fill.hh>
#include <oln/level/compare.hh>
#include <ntg/int.hh>
@@ -16,7 +17,7 @@
oln::image2d<ntg::int_u8> ima;
- ima = oln::arith::max(ima1, ima2);
+ ima = oln::level::max(ima1, ima2);
if (oln::level::is_equal(ima, ima2))
return false;
Index: olena/tests/arith/tests/min
--- olena/tests/arith/tests/min (revision 185)
+++ olena/tests/arith/tests/min (working copy)
@@ -1,27 +0,0 @@
-#include <oln/basics2d.hh>
-#include <oln/arith/min.hh>
-#include <oln/level/fill.hh>
-#include <oln/level/compare.hh>
-#include <ntg/int.hh>
-
-
-
-bool check()
-{
- oln::image2d<ntg::int_u8> ima1(10, 10);
- oln::image2d<ntg::int_u8> ima2(10, 10);
-
- oln::level::fill(ima1, 10);
- oln::level::fill(ima2, 20);
-
- oln::image2d<ntg::int_u8> ima;
-
- ima = oln::arith::min(ima1, ima2);
-
- if (oln::level::is_equal(ima, ima1))
- return false;
- return true;
-}
-
-
-
Index: olena/tests/arith/tests/max
--- olena/tests/arith/tests/max (revision 185)
+++ olena/tests/arith/tests/max (working copy)
@@ -1,25 +0,0 @@
-#include <oln/basics2d.hh>
-#include <oln/arith/max.hh>
-#include <oln/level/fill.hh>
-#include <oln/level/compare.hh>
-#include <ntg/int.hh>
-
-
-
-bool check()
-{
- oln::image2d<ntg::int_u8> ima1(10, 10);
- oln::image2d<ntg::int_u8> ima2(10, 10);
-
- oln::level::fill(ima1, 10);
- oln::level::fill(ima2, 20);
-
- oln::image2d<ntg::int_u8> ima;
-
- ima = oln::arith::max(ima1, ima2);
-
- if (oln::level::is_equal(ima, ima2))
- return false;
- return true;
-}
-
Index: olena/tests/arith/Makefile.am
--- olena/tests/arith/Makefile.am (revision 185)
+++ olena/tests/arith/Makefile.am (working copy)
@@ -1,5 +0,0 @@
-include ../check/Makefile.runtests
-include ../check/Makefile.check
-
-
-check-local: check-runtests
Index: olena/oln/core/abstract/image.hh
--- olena/oln/core/abstract/image.hh (revision 185)
+++ olena/oln/core/abstract/image.hh (working copy)
@@ -443,13 +443,13 @@
return this->delegate().hold_large(p);
}
- value_box<D> operator[](const point_type& p) const
+ value_box<const D> operator[](const point_type& p) const
{
precondition(this->hold_large(p));
return this->delegate().operator[](p);
}
- value_box<const D> operator[](const point_type& p)
+ value_box<D> operator[](const point_type& p)
{
precondition(this->hold_large(p));
return this->delegate().operator[](p);
Index: olena/oln/core/1d/image1d.hh
--- olena/oln/core/1d/image1d.hh (revision 185)
+++ olena/oln/core/1d/image1d.hh (working copy)
@@ -129,6 +129,24 @@
this->exact_ptr = this;
}
+ public:
+
+ /*! Return a reference to the value stored at coordinate \a index
+ ** in the current (const) image.
+ */
+ value_box< const image1d<T> > operator()(coord_t index) const
+ {
+ return (*this)[point1d(index)];
+ }
+
+ /*! Return a reference to the value stored at coordinate \a index
+ ** in the current image.
+ */
+ value_box< image1d<T> > operator()(coord_t index)
+ {
+ return (*this)[point1d(index)];
+ }
+
};
Index: olena/oln/core/2d/image2d.hh
--- olena/oln/core/2d/image2d.hh (revision 185)
+++ olena/oln/core/2d/image2d.hh (working copy)
@@ -202,6 +202,25 @@
// without impl
image2d(const image2d&);
+
+ public:
+
+ /*! Return a reference to the value stored at coordinate
+ ** (\a row, \a col) in the current (const) image.
+ */
+ value_box< const image2d<T> > operator()(coord_t row, coord_t col) const
+ {
+ return (*this)[point2d(row, col)];
+ }
+
+ /*! Return a reference to the value stored at coordinate
+ ** (\a row, \a col) in the current image.
+ */
+ value_box< image2d<T> > operator()(coord_t row, coord_t col)
+ {
+ return (*this)[point2d(row, col)];
+ }
+
};
Index: olena/oln/core/3d/image3d.hh
--- olena/oln/core/3d/image3d.hh (revision 185)
+++ olena/oln/core/3d/image3d.hh (working copy)
@@ -129,6 +129,26 @@
this->exact_ptr = this;
}
+ public:
+
+ /*! Return a reference to the value stored at coordinate
+ ** (\a slice, \a row, \a col) in the current (const) image.
+ */
+ value_box< const image3d<T> >
+ operator()(coord_t slice, coord_t row, coord_t col) const
+ {
+ return (*this)[point3d(slice, row, col)];
+ }
+
+ /*! Return a reference to the value stored at coordinate
+ ** (\a slice, \a row, \a col) in the current image.
+ */
+ value_box< image3d<T> >
+ operator()(coord_t slice, coord_t row, coord_t col)
+ {
+ return (*this)[point3d(slice, row, col)];
+ }
+
};
Index: olena/oln/utils/clone.hh
--- olena/oln/utils/clone.hh (revision 185)
+++ olena/oln/utils/clone.hh (working copy)
@@ -35,7 +35,7 @@
namespace oln
{
- // Fwd decl of erosion's facade.
+ // Fwd decl of clone's facade.
template <typename I>
oln_type_of(I, concrete) clone(const abstract::image<I>& input);