00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 #include <mln/core/image/image1d.hh>
00027 #include <mln/core/image/image2d.hh>
00028 #include <mln/debug/iota.hh>
00029 #include <mln/border/duplicate.hh>
00030 #include <mln/value/int_u8.hh>
00031 #include <mln/value/int_s8.hh>
00032 #include <mln/opt/element.hh>
00033 
00034 namespace mln
00035 {
00036 
00037   template <typename T>
00038   void chck1d(int cols, int border, T ref[])
00039   {
00040     int c = cols + 2 * border;
00041 
00042     image1d<T> ima(cols, border);
00043     debug::iota(ima);
00044     border::duplicate(ima);
00045 
00046     for (int i = 0; i < c; ++i)
00047       mln_assertion(opt::element(ima, i) == ref[i]);
00048   }
00049 
00050   template <typename T>
00051   void chck2d(int rows, int cols, int border, T ref[])
00052   {
00053     int r = rows + 2 * border;
00054     int c = cols + 2 * border;
00055 
00056     image2d<T> ima(rows, cols, border);
00057     debug::iota(ima);
00058     border::duplicate(ima);
00059 
00060     for (int i = 0; i < c * r; ++i)
00061       mln_assertion(opt::element(ima, i) == ref[i]);
00062   }
00063 
00064 }
00065 
00066 
00067 int
00068 main(void)
00069 {
00070   using namespace mln;
00071 
00072   std::cerr << "Tests border::duplicate:" << std::endl;
00073 
00074   {
00075     std::cerr << "  in 1d :" << std::endl;
00076 
00077     {
00078       (std::cerr << "    on int_u8 with border = 3 ... ").flush ();
00079 
00080       typedef value::int_u8 T;
00081       int border = 3;
00082       int cols = 2;
00083       T ref[8] = {1, 1, 1, 1, 2, 2, 2, 2};
00084 
00085       chck1d(cols, border, ref);
00086       std::cerr << "OK" << std::endl;
00087     }
00088 
00089     {
00090       (std::cerr << "    on    int with border = 2 ... ").flush ();
00091 
00092       typedef int T;
00093       int border = 2;
00094       int cols = 3;
00095       T ref[7] = {1, 1, 1, 2, 3, 3, 3};
00096 
00097       chck1d(cols, border, ref);
00098       std::cerr << "OK" << std::endl;
00099     }
00100 
00101     {
00102       (std::cerr << "    on int_s8 with border = 1 ... ").flush ();
00103 
00104       typedef value::int_s8 T;
00105       int border = 1;
00106       int cols = 2;
00107       T ref[4] = {1, 1, 2, 2};
00108 
00109       chck1d(cols, border, ref);
00110       std::cerr << "OK" << std::endl;
00111     }
00112 
00113     {
00114       (std::cerr << "    on    int with border = 0 ... ").flush ();
00115       typedef int T;
00116       int border = 0;
00117       int cols = 4;
00118       T ref[4] = {1, 2, 3, 4};
00119 
00120       chck1d(cols, border, ref);
00121       std::cerr << "OK" << std::endl;
00122     }
00123   } 
00124 
00125 
00126   {
00127     std::cerr << "  in 2d :" << std::endl;
00128 
00129     {
00130       (std::cerr << "    on    int with border = 3 ... ").flush ();
00131       typedef int T;
00132       int border = 3;
00133       int rows = 4;
00134       int cols = 5;
00135       T ref[110] =
00136         {
00137           1,  1,  1,  1,  2,  3,  4,  5,  5,  5,  5,
00138           1,  1,  1,  1,  2,  3,  4,  5,  5,  5,  5,
00139           1,  1,  1,  1,  2,  3,  4,  5,  5,  5,  5,
00140           1,  1,  1,  1,  2,  3,  4,  5,  5,  5,  5,
00141           6,  6,  6,  6,  7,  8,  9,  10, 10, 10, 10,
00142           11, 11, 11, 11, 12, 13, 14, 15, 15, 15, 15,
00143           16, 16, 16, 16, 17, 18, 19, 20, 20, 20, 20,
00144           16, 16, 16, 16, 17, 18, 19, 20, 20, 20, 20,
00145           16, 16, 16, 16, 17, 18, 19, 20, 20, 20, 20,
00146           16, 16, 16, 16, 17, 18, 19, 20, 20, 20, 20
00147         };
00148 
00149       chck2d(rows, cols, border, ref);
00150       std::cerr << "OK" << std::endl;
00151     }
00152 
00153     {
00154       (std::cerr << "    on int_u8 with border = 3 ... ").flush ();
00155       typedef value::int_u8 T;
00156       int border = 2;
00157       int rows = 4;
00158       int cols = 5;
00159       T ref[72] =
00160         {
00161           1,  1,  1,  2,  3,  4,  5,  5,  5,
00162           1,  1,  1,  2,  3,  4,  5,  5,  5,
00163           1,  1,  1,  2,  3,  4,  5,  5,  5,
00164           6,  6,  6,  7,  8,  9,  10, 10, 10,
00165           11, 11, 11, 12, 13, 14, 15, 15, 15,
00166           16, 16, 16, 17, 18, 19, 20, 20, 20,
00167           16, 16, 16, 17, 18, 19, 20, 20, 20,
00168           16, 16, 16, 17, 18, 19, 20, 20, 20
00169         };
00170 
00171       chck2d(rows, cols, border, ref);
00172       std::cerr << "OK" << std::endl;
00173     }
00174 
00175     {
00176       (std::cerr << "    on int_s8 with border = 1 ... ").flush ();
00177       typedef value::int_s8 T;
00178       int border = 1;
00179       int rows = 4;
00180       int cols = 5;
00181       T ref[49] =
00182         {
00183           1,  1,  2,  3,  4,  5,  5,
00184           1,  1,  2,  3,  4,  5,  5,
00185           6,  6,  7,  8,  9,  10, 10,
00186           11, 11, 12, 13, 14, 15, 15,
00187           16, 16, 17, 18, 19, 20, 20,
00188           16, 16, 17, 18, 19, 20, 20
00189         };
00190 
00191       chck2d(rows, cols, border, ref);
00192       std::cerr << "OK" << std::endl;
00193     }
00194 
00195     {
00196       (std::cerr << "    on    int with border = 0 ... ").flush ();
00197       typedef int T;
00198       int border = 0;
00199       int rows = 4;
00200       int cols = 5;
00201       T ref[20] =
00202         {
00203           1,  2,  3,  4,  5,
00204           6,  7,  8,  9,  10,
00205           11, 12, 13, 14, 15,
00206           16, 17, 18, 19, 20
00207         };
00208 
00209       chck2d(rows, cols, border, ref);
00210       std::cerr << "OK" << std::endl;
00211     }
00212 
00213   } 
00214 
00215 }