$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
dpoints_pixter.cc
1 // Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE)
2 //
3 // This file is part of Olena.
4 //
5 // Olena is free software: you can redistribute it and/or modify it under
6 // the terms of the GNU General Public License as published by the Free
7 // Software Foundation, version 2 of the License.
8 //
9 // Olena is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
16 //
17 // As a special exception, you may use this file as part of a free
18 // software project without restriction. Specifically, if other files
19 // instantiate templates or use macros or inline functions from this
20 // file, or you compile this file and link it with other files to produce
21 // an executable, this file does not by itself cause the resulting
22 // executable to be covered by the GNU General Public License. This
23 // exception does not however invalidate any other reasons why the
24 // executable file might be covered by the GNU General Public License.
25 
26 #include <mln/core/image/image1d.hh>
27 #include <mln/core/image/image2d.hh>
28 #include <mln/core/image/image3d.hh>
29 
30 #include <mln/win/segment1d.hh>
31 #include <mln/win/rectangle2d.hh>
32 #include <mln/win/cuboid3d.hh>
33 
34 #include <mln/make/pixel.hh>
35 
36 
37 template <typename I, typename W>
38 void test_fill(I& ima, const W& win, unsigned nsites)
39 {
40  mln_piter(I) p(ima.domain());
41  mln_fwd_qixter(I, W) fq(ima, win, p);
42  for_all(p)
43  {
44  unsigned i = 0;
45  for_all(fq)
46  ++i, fq.val() = 51;
47  mln_assertion(i == nsites);
48  }
49  mln_bkd_qixter(I, W) bq(ima, win, p);
50  for_all(p)
51  {
52  unsigned i = 0;
53  for_all(bq)
54  ++i, bq.val() = 42;
55  mln_assertion(i == nsites);
56  }
57 }
58 
59 // FIXME: Test promotion and other constructions.
60 
61 template <typename P, typename W>
62 void test_pixel(const P& pxl, const W& win)
63 {
64  mln_fwd_qixter(mln_image(P), W) fq(pxl, win);
65  for_all(fq)
66  fq.val() = 2 * fq.val();
67  mln_bkd_qixter(mln_image(P), W) bq(pxl, win);
68  for_all(bq)
69  bq.val() = bq.val() + 1;
70 }
71 
72 int main()
73 {
74  using namespace mln;
75 
77 
78  // 1-D case.
79  {
80  typedef image1d<int> I;
81  I ima(6);
82 
83  win::segment1d seg(3);
84  point1d p = point1d(3);
85 
86  test_fill(ima, seg, 3);
87  test_pixel(make::pixel(ima, p), seg);
88  }
89 
90  // 2-D case.
91  {
92  typedef image2d<int> I;
93  I ima(5, 5);
94 
95  win::rectangle2d rect(3, 3);
96  point2d p = point2d(1, 1);
97 
98  test_fill(ima, rect, 3 * 3);
99  test_pixel(make::pixel(ima, p), rect);
100  }
101 
102  // 3-D case.
103  {
104  typedef image3d<int> I;
105  I ima(3, 4, 5);
106 
107  win::cuboid3d cuboid(3, 3, 3);
108  point3d p = point3d(2, 1, 3);
109 
110  test_fill(ima, cuboid, 3 * 3 * 3);
111  test_pixel(make::pixel(ima, p), cuboid);
112  }
113 
114 }