$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
utils.hh
1 // Copyright (C) 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_MORPHO_TREE_UTILS_HH
27 # define MLN_MORPHO_TREE_UTILS_HH
28 
34 
35 # include <mln/core/concept/image.hh>
36 # include <mln/core/site_set/p_array.hh>
37 
38 
39 namespace mln
40 {
41 
42  namespace morpho
43  {
44 
45  namespace tree
46  {
47 
48  template <typename T, typename I>
49  bool
50  is_root(const Image<T>& parent, const mln_psite(T)& p,
51  const Image<I>& f);
52 
53 
54  template <typename T, typename I>
55  bool
56  is_a_node(const Image<T>& parent, const mln_psite(T)& p,
57  const Image<I>& f);
58 
59 
60 
61  template <typename T, typename I, typename S>
62  p_array<mln_psite(T)>
63  nodes(const Image<T>& parent, const Image<I>& f, const Site_Set<S>& s);
64 
65 
66 # ifndef MLN_INCLUDE_ONLY
67 
68 
69  template <typename T, typename I>
70  inline
71  bool
72  is_root(const Image<T>& parent_, const mln_psite(T)& p,
73  const Image<I>& f_)
74  {
75  mlc_equal(mln_value(T), mln_psite(T))::check();
76 
77  const T& parent = exact(parent_);
78  const I& f = exact(f_);
79 
80  mln_precondition(parent.is_valid());
81  mln_precondition(f.is_valid());
82  mln_precondition(parent.domain() == f.domain());
83 
84  return parent(p) == p;
85  }
86 
87 
88  template <typename T, typename I>
89  inline
90  bool
91  is_a_node(const Image<T>& parent_, const mln_psite(T)& p,
92  const Image<I>& f_)
93  {
94  mlc_equal(mln_value(T), mln_psite(T))::check();
95 
96  const T& parent = exact(parent_);
97  const I& f = exact(f_);
98 
99  mln_precondition(parent.is_valid());
100  mln_precondition(f.is_valid());
101  mln_precondition(parent.domain() == f.domain());
102 
103  return parent(p) == p || f(parent(p)) != f(p);
104  }
105 
106 
107  template <typename T, typename I, typename S>
108  inline
109  p_array<mln_psite(T)>
110  nodes(const Image<T>& parent_, const Image<I>& f_, const Site_Set<S>& s_)
111  {
112  mlc_equal(mln_value(T), mln_psite(T))::check();
113 
114  const T& parent = exact(parent_);
115  const I& f = exact(f_);
116  const S& s = exact(s_);
117 
118  mln_precondition(parent.is_valid());
119  mln_precondition(f.is_valid());
120  mln_precondition(f.domain() == parent.domain());
121  mln_precondition(s == f.domain());
122 
123  p_array<mln_psite(T)> arr;
124  mln_bkd_piter(S) p(exact(s));
125  for_all(p)
126  if (is_a_node(parent, p, f))
127  arr.insert(p);
128 
129  return arr;
130  }
131 
132 # endif // ! MLN_INCLUDE_ONLY
133 
134  } // end of namespace mln::morpho::tree
135 
136  } // end of namespace mln::morpho
137 
138 } // end of namespace mln
139 
140 
141 #endif // ! MLN_MORPHO_TREE_UTILS_HH