* bugs/concept_and_assignment.cc: sample code of what should not
be done while assigning an image to another.
---
milena/sandbox/ChangeLog | 7 ++
milena/sandbox/bugs/concept_and_assignment.cc | 84 +++++++++++++++++++++++++
2 files changed, 91 insertions(+), 0 deletions(-)
create mode 100644 milena/sandbox/bugs/concept_and_assignment.cc
diff --git a/milena/sandbox/ChangeLog b/milena/sandbox/ChangeLog
index 0512bfc..8c7681f 100644
--- a/milena/sandbox/ChangeLog
+++ b/milena/sandbox/ChangeLog
@@ -1,3 +1,10 @@
+2009-03-16 Guillaume Lazzara <z(a)lrde.epita.fr>
+
+ Add a buggy sample case.
+
+ * bugs/concept_and_assignment.cc: sample code of what should not
+ be done while assigning an image to another.
+
2009-03-19 Fabien Freling <fabien.freling(a)lrde.epita.fr>
Add a new file translating IGR Matlab code.
diff --git a/milena/sandbox/bugs/concept_and_assignment.cc
b/milena/sandbox/bugs/concept_and_assignment.cc
new file mode 100644
index 0000000..379d17d
--- /dev/null
+++ b/milena/sandbox/bugs/concept_and_assignment.cc
@@ -0,0 +1,84 @@
+/*
+** We do NOT want to pass images as reference.
+**
+** Assigning an image to an image concept will compile but
+** will not perform anything. This is ERROR PRONE.
+**
+** Thus, if the image passed as reference is not initialized it will remain
+** uninitialized and an assertion will raised. The problem is if the image is
+** already initialized. It will FAIL SILENTLY and give wrong image values.
+**
+** Always prefer returning images.
+*/
+
+#include <mln/essential/2d.hh>
+
+namespace mln
+{
+
+ template <typename I>
+ mln_ch_value(I,value::label_8)
+ bar(const Image<I>& ima)
+ {
+ value::label_8 n;
+
+ mln_ch_value(I,value::label_8) lbl;
+ initialize(lbl, ima);
+
+ lbl = labeling::blobs(ima, c8(),n);
+ mln_assertion(lbl.is_valid());
+
+ return lbl;
+ }
+
+ // DO NOT WORK!
+ template <typename I>
+ void foo_template_and_concept(Image<I>& lbl)
+ {
+ mln_ch_value(I,bool) ima(3,4);
+
+ /// The difference is here!
+ lbl = bar(ima);
+
+ mln_assertion(exact(lbl).is_valid());
+ }
+
+ // WORK
+ template <typename I>
+ void foo_template_concept_and_exact(Image<I>& lbl)
+ {
+ mln_ch_value(I,bool) ima(3,4);
+
+ /// The difference is here!
+ exact(lbl) = bar(ima);
+
+ mln_assertion(exact(lbl).is_valid());
+ }
+
+}
+
+
+
+int main(int, char*argv[])
+{
+ using namespace mln;
+
+ image2d<bool> ima(3,4);
+
+ // WORK
+ {
+ std::cout << "template with I + concept + exact" << std::endl;
+ image2d<value::label_8> lbl;
+ foo_template_concept_and_exact(lbl);
+ mln_assertion(lbl.is_valid());
+ }
+
+ // DO NOT WORK
+ {
+ std::cout << "template with I + concept" << std::endl;
+ image2d<value::label_8> lbl;
+ foo_template_and_concept(lbl);
+ mln_assertion(lbl.is_valid());
+ }
+
+}
--
1.5.6.5