* python/dynamic-image2d-misc.py, python/image2d-misc.py:
Simplify constructions.
Use iterators on domain instead of ad hoc iterations.
---
swilena/ChangeLog | 8 ++++++++
swilena/python/dynamic-image2d-misc.py | 22 ++++------------------
swilena/python/image2d-misc.py | 27 ++++++++++-----------------
3 files changed, 22 insertions(+), 35 deletions(-)
diff --git a/swilena/ChangeLog b/swilena/ChangeLog
index 07d0481..776aec3 100644
--- a/swilena/ChangeLog
+++ b/swilena/ChangeLog
@@ -1,5 +1,13 @@
2009-05-27 Roland Levillain <roland(a)lrde.epita.fr>
+ Have Swilena/Python make use of iterators.
+
+ * python/dynamic-image2d-misc.py, python/image2d-misc.py:
+ Simplify constructions.
+ Use iterators on domain instead of ad hoc iterations.
+
+2009-05-27 Roland Levillain <roland(a)lrde.epita.fr>
+
Add conversion to string to point2d.
* point2d.i (__str__): New method (extension).
diff --git a/swilena/python/dynamic-image2d-misc.py
b/swilena/python/dynamic-image2d-misc.py
index f6b73b3..941a929 100644
--- a/swilena/python/dynamic-image2d-misc.py
+++ b/swilena/python/dynamic-image2d-misc.py
@@ -1,6 +1,6 @@
#! /usr/bin/env python
-# Copyright (C) 2008 EPITA Research and Development Laboratory (LRDE)
+# Copyright (C) 2008, 2009 EPITA Research and Development Laboratory (LRDE)
#
# This file is part of the Olena Library. This library is free
# software; you can redistribute it and/or modify it under the terms
@@ -60,25 +60,11 @@ class simple_image(dyn_ima2d):
return True
-# FIXME: Why can't I use
-#
-# b = box2d(10, 10)
-#
-# directly?
-#
-# I think this is probably because SWIG's way to handle overloading in
-# Python depends just on the *number* of arguments, not their types --
-# and we already have a wrapped ctor with 2 arguments, the one taking
-# two mln::point2d's, so the second one (with two int's) is probably
-# hidden). Pay more attention to swig's warnings!
-b = box2d(point2d(0,0), point2d(9,9))
+b = box2d(10, 10)
ima = simple_image(b)
image.fill(ima, int_u8(42))
image.println(ima)
-# FIXME: Doesn't really work yet, since int_u8 is not convertible
-# to int.
-for r in range(0, 10):
- for c in range(0, 10):
- print ima(point2d(r, c))
+for p in ima.domain():
+ print ima(p)
diff --git a/swilena/python/image2d-misc.py b/swilena/python/image2d-misc.py
index 2a406a8..e0b2a91 100644
--- a/swilena/python/image2d-misc.py
+++ b/swilena/python/image2d-misc.py
@@ -1,6 +1,6 @@
#! /usr/bin/env python
-# Copyright (C) 2008 EPITA Research and Development Laboratory (LRDE)
+# Copyright (C) 2008, 2009 EPITA Research and Development Laboratory (LRDE)
#
# This file is part of the Olena Library. This library is free
# software; you can redistribute it and/or modify it under the terms
@@ -32,26 +32,19 @@ from swilena import *
ima = image2d_int.image2d_int(3, 3)
image2d_int.fill(ima, 42)
-# FIXME: For the moment, we can't write
-#
-# ima(point2d(i, j))
-#
-# but I don't know why. Anyway, eventually we'd like to be able to
-# write this:
+# FIXME: Eventually we'd like to be able to write this:
#
# for p in ima.domain():
-# print "ima(" + str(i) + ", " + str(j) + ") = " +
ima(p)
+# print "ima(" + str(p) + ") = " + ima(p)
#
# as it is generic and way closer to what we do in C++.
-for i in range(0, 3):
- for j in range(0, 3):
- p = point2d(i, j)
- # FIXME: Handling POD types (like int) as value types is not
- # transparent: ima(p) returns a pointer to int wrapped in a SWIG
- # object, and cannot be easily converted to a Python integer
- # value. Hence this explicit conversion using `intp_value'.
- v = image2d_int.intp_value(ima(p))
- print "ima(" + str(i) + ", " + str(j) + ") = " +
str(v)
+for p in ima.domain():
+ # FIXME: Handling POD types (like int) as value types is not
+ # transparent: ima(p) returns a pointer to int wrapped in a SWIG
+ # object, and cannot be easily converted to a Python integer
+ # value. Hence this explicit conversion using `intp_value'.
+ v = image2d_int.intp_value(ima(p))
+ print "ima" + str(p) + " = " + str(v)
# FIXME: This is too complicated. We should be able to write
#
--
1.6.1.2
Show replies by date