URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-10-10 Matthieu Garrigues <garrigues(a)lrde.epita.fr>
Add int_s16 test.
* mln/value/int_s16.hh: New, signed int on 16bits.
* tests/value_int_s16.cc: New, tests.
---
mln/value/int_s16.hh | 55 ++++++++++++
tests/value_int_s16.cc | 213 +++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 268 insertions(+)
Index: trunk/milena/tests/value_int_s16.cc
===================================================================
--- trunk/milena/tests/value_int_s16.cc (revision 0)
+++ trunk/milena/tests/value_int_s16.cc (revision 1302)
@@ -0,0 +1,213 @@
+// 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.
+
+/*! \file tests/value_int_s16.cc
+ *
+ * \brief Tests on mln::value::int_s16.
+ */
+
+#include <mln/value/int_s16.hh>
+
+#define test_operator(T, OP, V1, V2) \
+ \
+{ \
+ T i = V1; \
+ T j = V2; \
+ \
+ i = i OP j; \
+ mln_assertion(i == (V1 OP V2)); \
+ mln_assertion(j == V2); \
+ \
+ i OP##= i; \
+ mln_assertion(i == (((V1 OP V2) OP (V1 OP V2)))); \
+}
+
+#define test_interop(T1, T2, OP, V1, V2) \
+ \
+{ \
+ T1 i = V1; \
+ T2 j = V2; \
+ \
+ i = i OP j; \
+ mln_assertion(i == (V1 OP V2)); \
+ mln_assertion(j == V2); \
+ \
+ i OP##= i; \
+ mln_assertion(i == (((V1 OP V2) OP (V1 OP V2)))); \
+}
+
+
+// test_operator
+
+int main()
+{
+ using namespace mln;
+ using value::int_s16;
+
+ int_s16 i = 3, j;
+
+ // Assignment.
+ {
+ i = 51;
+ mln_assertion(i == 51);
+
+ i = 51u;
+ mln_assertion(i == 51);
+
+ signed char c = 51;
+ i = c;
+ mln_assertion(i == 51);
+
+ j = i;
+ mln_assertion(j == 51);
+
+ i = 3;
+ mln_assertion(3.0f == i);
+ mln_assertion(i != 2.99f);
+
+ // Error at run-time as expected :-)
+ // i = 256;
+ // i = -1;
+ // i = 255, ++i;
+ }
+
+
+ // Comparaison
+ {
+ int_s16 i = 42;
+ int_s16 j = 51;
+
+ mln_assertion(i < j);
+ mln_assertion(j > i);
+ mln_assertion(i < 12345);
+ mln_assertion(12345 > i);
+
+ mln_assertion(i != j);
+ mln_assertion(i == 42);
+ mln_assertion(42 == i);
+ mln_assertion(i != 69);
+ mln_assertion(69 != i);
+
+ }
+
+ // Addition.
+ {
+ test_operator(int_s16, +, -5, 1);
+ test_interop(int_s16, int, +, 5, -1);
+ test_interop(int_s16, char, +, -4, 2);
+ test_interop(int_s16, unsigned char, +, 4, 2);
+
+ int_s16 i = 234;
+
+ i++;
+ mln_assertion(i == 235);
+
+ ++i;
+ mln_assertion(i == 236);
+
+ i = +i;
+ mln_assertion(i == 236);
+
+ }
+
+ // Soustraction
+ {
+ test_operator(int_s16, -, 100, 5);
+ test_interop(int_s16, int, -, 100, 5);
+ test_interop(int_s16, char, -, 100, 5);
+ test_interop(int_s16, unsigned char, -, 100, 5);
+
+ int_s16 c = 255;
+ c -= c;
+
+ mln_assertion(c == 0);
+
+ int_s16 i = 236;
+
+ i--;
+ mln_assertion(i == 235);
+
+ --i;
+ mln_assertion(i == 234);
+
+ mln_assertion(-i == -234);
+ }
+
+ // Multiplication
+ {
+ test_operator(int_s16, *, 5, 1);
+ test_interop(int_s16, int, *, 5, 1);
+ test_interop(int_s16, char, *, 4, 2);
+ test_interop(int_s16, unsigned char, *, 4, 2);
+
+ int_s16 c = 255;
+
+ c *= 0;
+ mln_assertion(c == 0);
+
+ i *= 2;
+ int k; k *= i;
+
+ unsigned char d = 0;
+ i *= d;
+ mln_assertion(i == 0);
+
+ // Error at run-time as expected :-)
+ // i = 128;
+ // i *= 2;
+
+ }
+
+ // Division
+ {
+ test_operator(int_s16, /, 5, 1);
+ test_interop(int_s16, int, /, 5, 1);
+ test_interop(int_s16, char, /, 4, 2);
+ test_interop(int_s16, unsigned char, /, 4, 2);
+
+ int_s16 c = 200;
+
+ c /= 1;
+ mln_assertion(c == 200);
+ c /= 2;
+ mln_assertion(c == 100);
+
+ int_s16 d = 2;
+ c /= 2;
+ mln_assertion(c == 50);
+
+ }
+
+
+ // Modulo
+ {
+ test_operator(int_s16, %, 5, 10);
+ test_interop(int_s16, int, %, 5, 10);
+ test_interop(int_s16, char, %, 4, 20);
+ test_interop(int_s16, unsigned char, %, 4, 20);
+ }
+}
Index: trunk/milena/mln/value/int_s16.hh
===================================================================
--- trunk/milena/mln/value/int_s16.hh (revision 0)
+++ trunk/milena/mln/value/int_s16.hh (revision 1302)
@@ -0,0 +1,55 @@
+// 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 MLN_VALUE_INT_S16_HH
+# define MLN_VALUE_INT_S16_HH
+
+/*! \file mln/value/int_s16.hh
+ *
+ * \brief Define the alias value::int_s16.
+ */
+
+# include <mln/value/int_s.hh>
+
+
+namespace mln
+{
+
+ namespace value
+ {
+
+
+ /// Alias for signed 16 bit integers.
+ typedef int_s<16> int_s16;
+
+
+ } // end of namespace mln::value
+
+} // end of namespace mln
+
+
+#endif // ! MLN_VALUE_INT_S16_HH
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-10-10 Guillaume Duhamel <guillaume.duhamel(a)lrde.epita.fr>
Add convert/to_tiles.hh.
* to_tiles.hh: Create an image from vector of image.
---
to_tiles.hh | 97 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 97 insertions(+)
Index: trunk/milena/mln/convert/to_tiles.hh
===================================================================
--- trunk/milena/mln/convert/to_tiles.hh (revision 0)
+++ trunk/milena/mln/convert/to_tiles.hh (revision 1295)
@@ -0,0 +1,97 @@
+// 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 MLN_CONVERT_TO_TILES_HH
+# define MLN_CONVERT_TO_TILES_HH
+
+/*! \file mln/convert/to_tiles.hh
+ *
+ * \brief Conversion of a vector of image2d into a tiled image with ratio.
+ */
+
+# include <mln/core/translate_image.hh>
+# include <mln/level/paste.hh>
+# include <mln/geom/nrows.hh>
+# include <mln/geom/ncols.hh>
+
+namespace mln
+{
+
+ namespace convert
+ {
+
+ /// FIXME : Run only for image2d
+ /// Convert a vector of image2d into a tiled image with ratio.
+ template <typename I>
+ I to_tiles (std::vector<I>& vec, float ratio);
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename I>
+ I
+ to_tiles (std::vector<I>& vec, float ratio)
+ {
+ /// Test if vec is not empty.
+ mln_precondition(!vec.empty ());
+
+ unsigned size = vec.size ();
+ unsigned nrows = geom::nrows(vec[0]);
+ unsigned ncols = geom::ncols(vec[0]);
+
+ /// Compute output size.
+ int size_c = (int) ceil(sqrt(size * ratio));
+ int size_r = (int) ceil(sqrt(size / ratio));
+
+ I output (size_r * nrows, size_c * ncols);
+
+ for (unsigned i = 0; i < size; ++i)
+ {
+ /// Check if current image has good dimension.
+ mln_precondition(geom::nrows(vec[i]) == nrows);
+ mln_precondition(geom::ncols(vec[i]) == ncols);
+
+ /// Compute the delta point of translation.
+ dpoint2d dp = make::dpoint2d(i / size_c * nrows, i % size_c * ncols);
+
+ /// Convert current image in translate image with its delta point.
+ translate_image<I> tr_ima (vec[i], dp);
+
+ /// Paste translated image into output.
+ level::paste (tr_ima, output);
+ }
+
+ return output;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::convert
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CONVERT_TO_TILES_HH