$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
tree_to_image.hh
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 #ifndef MLN_UTIL_TREE_TO_IMAGE_HH
27 # define MLN_UTIL_TREE_TO_IMAGE_HH
28 
33 
34 # include <mln/core/concept/image.hh>
35 # include <mln/core/image/image2d.hh>
36 # include <mln/util/tree.hh>
37 # include <mln/core/site_set/p_set.hh>
38 # include <mln/data/fill.hh>
39 
40 namespace mln
41 {
42 
43  namespace data
44  {
45  template <typename I, typename D>
46  void fill(Image<I>& ima, const D& data);
47 
48  }
49 
50  namespace util
51  {
52 
58  template <typename T, typename I>
59  void
60  tree_to_image(tree<T>& tree, Image<I>& output_);
61 
67  template <typename I, typename J>
68  void
69  display_tree(const Image<J>& ima_, tree<I>& tree);
70 
71 
77  template <typename I, typename J>
78  void
79  display_branch(const Image<J>& ima_, tree_node<I>* tree_node);
80 
81 # ifndef MLN_INCLUDE_ONLY
82 
83  namespace impl
84  {
85 
86  template <typename T, typename I>
87  inline
88  void
89  tree_to_image_rec(tree_node<T>* tree_node, Image<I>& output_)
90  {
91  mln_trace("util::impl::tree_to_image_rec");
92 
93  I& output = exact(output_);
94 
95  mln_piter(p_set<point2d>) p(tree_node->elt().points);
96 
97  for_all(p)
98  output(p) = tree_node->elt().value;
99 
100  typename std::vector< util::tree_node<T>* >::const_iterator it = tree_node->children().begin();
101 
102  for (int i = 0;
103  it != tree_node->children().end();
104  ++it, ++i)
105  {
106  if (*it)
107  tree_to_image_rec((*it), output);
108  }
109  }
110 
111  template <typename T, typename J>
112  inline
113  void
114  display_tree_rec(const Image<J>& ima_, tree_node<T>* tree_node, int level)
115  {
116  mln_trace("util::impl::display_tree_rec");
117 
118  const J& ima = exact(ima_);
119  display_set(ima, tree_node->elt().points);
120  typename mln::util::tree_node<T>::children_t::iterator it = tree_node->children().begin();
121  for (;
122  it != tree_node->children().end(); ++it)
123  display_tree_rec(ima, (*it), level + 1);
124 
125  }
126 
127 
128  template <typename T, typename J, typename K>
129  inline
130  void
131  display_branch_rec(const Image<J>& ima_, tree_node<T>* tree_node, Image<K>& output_)
132  {
133  mln_trace("util::impl::display_branch_rec");
134 
135  K& output = exact(output_);
136  const J& ima = exact(ima_);
137 
138  mln_piter(p_set<point2d>) p(tree_node->elt().points);
139  for_all(p)
140  output(p) = true;
141  typename mln::util::tree_node<T>::children_t::iterator it = tree_node->children().begin();
142  for (;
143  it != tree_node->children().end(); ++it)
144  display_branch_rec(ima, (*it), output);
145 
146  }
147 
148 
149  template <typename P, typename J>
150  inline
151  void
152  display_set(const Image<J>& ima_, p_set<P>& s)
153  {
154  mln_trace("util::impl::display_set");
155 
156  const J& ima = exact(ima_);
157  image2d<bool> out(ima.bbox());
158 
159  data::fill(out, false);
160  mln_piter(p_set<P>) p(s);
161  for_all(p)
162  out(p) = true;
163 
164  }
165 
166 
167  } // end of namespace mln::util::impl
168 
169 
170 
171  template <typename T, typename I>
172  inline
173  void
174  tree_to_image(tree<T>& tree, Image<I>& output_)
175  {
176  mln_trace("util::tree_to_image");
177 
178  I& output = exact(output_);
179  impl::tree_to_image_rec(tree.root(), output);
180 
181  }
182 
183 
184  template <typename I, typename J>
185  inline
186  void
187  display_tree(const Image<J>& ima_, tree<I>& tree)
188  {
189  mln_trace("util::display_tree");
190 
191  mln_precondition(tree.root());
192 
193  const J& ima = exact(ima_);
194  int level = 0;
195 
196  impl::display_tree_rec(ima, tree.root(), level);
197 
198  }
199 
200 
201  template <typename I, typename J>
202  inline
203  void
204  display_branch(const Image<J>& ima_, tree_node<I>* tree_node)
205  {
206  mln_trace("util::display_branch");
207 
208  mln_assertion(tree_node);
209 
210  const J& ima = exact(ima_);
211 
212  image2d<bool> output(ima.domain());
213  data::fill(output, false);
214  impl::display_branch_rec(ima, tree_node, output);
215 
216  }
217 
218 
219 # endif // ! MLN_INCLUDE_ONLY
220 
221  } // end of namespace mln::util
222 
223 } // end of namespace mln
224 
225 #endif // ! MLN_UTIL_TREE_TO_IMAGE_HH