$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
is_simple_point3d.hh
1 // Copyright (C) 2010, 2011, 2014 EPITA Research and Development
2 // Laboratory (LRDE).
3 //
4 // This file is part of Olena.
5 //
6 // Olena is free software: you can redistribute it and/or modify it under
7 // the terms of the GNU General Public License as published by the Free
8 // Software Foundation, version 2 of the License.
9 //
10 // Olena is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
17 //
18 // As a special exception, you may use this file as part of a free
19 // software project without restriction. Specifically, if other files
20 // instantiate templates or use macros or inline functions from this
21 // file, or you compile this file and link it with other files to produce
22 // an executable, this file does not by itself cause the resulting
23 // executable to be covered by the GNU General Public License. This
24 // exception does not however invalidate any other reasons why the
25 // executable file might be covered by the GNU General Public License.
26 
27 #ifndef MLN_TOPO_IS_SIMPLE_POINT3D_HH
28 # define MLN_TOPO_IS_SIMPLE_POINT3D_HH
29 
34 
35 # include <mln/core/concept/function.hh>
36 # include <mln/core/concept/image.hh>
37 # include <mln/core/concept/neighborhood.hh>
38 
39 # include <mln/topo/connectivity_number_3d.hh>
40 
41 
42 namespace mln
43 {
44 
45  namespace topo
46  {
47 
50  template <typename I, typename N>
51  class is_simple_point3d : public Function_v2b< is_simple_point3d<I, N> >
52  {
53  public:
55  typedef bool result;
56 
61  is_simple_point3d(const Neighborhood<N>& nbh_fg,
62  const Neighborhood<N>& nbh_bg);
63 
69  is_simple_point3d(const Neighborhood<N>& nbh_fg,
70  const Neighborhood<N>& nbh_bg,
71  const Image<I>& ima);
72 
74  void set_image(const Image<I>& ima);
75 
79  bool operator()(const mln_psite(I)& p) const;
80 
81  private:
84  void init_();
85 
86  private:
88  const N& nbh_fg_;
90  const N& nbh_bg_;
92  const I* ima_;
93 
96  typedef conn_number_t (*connectivity_number_fun_t)(const Image<I>&,
97  const mln_psite(I)&,
98  bool);
101  connectivity_number_fun_t connectivity_number_fg_;
104  connectivity_number_fun_t connectivity_number_bg_;
105  };
106 
107 
108 
109 # ifndef MLN_INCLUDE_ONLY
110 
111  template <typename I, typename N>
112  inline
114  const Neighborhood<N>& nbh_bg)
115  : nbh_fg_(exact(nbh_fg)), nbh_bg_(exact(nbh_bg)),
116  ima_(0),
117  connectivity_number_fg_(0), connectivity_number_bg_(0)
118  {
119  init_();
120  }
121 
122  template <typename I, typename N>
123  inline
125  const Neighborhood<N>& nbh_bg,
126  const Image<I>& ima)
127  : nbh_fg_(exact(nbh_fg)), nbh_bg_(exact(nbh_bg)),
128  ima_(exact(&ima)),
129  connectivity_number_fg_(0), connectivity_number_bg_(0)
130  {
131  init_();
132  }
133 
134  template <typename I, typename N>
135  inline
136  void
137  is_simple_point3d<I, N>::init_()
138  {
139  if (nbh_fg_ == c6() && nbh_bg_ == c26())
140  {
141  // (6, 26) case.
142  connectivity_number_fg_ = connectivity_number_3d_c6<I>;
143  connectivity_number_bg_ = connectivity_number_3d_c26<I>;
144  }
145  else if (nbh_fg_ == c26() && nbh_bg_ == c6())
146  {
147  // (26, 6) case.
148  connectivity_number_fg_ = connectivity_number_3d_c26<I>;
149  connectivity_number_bg_ = connectivity_number_3d_c6<I>;
150  }
151  else if (nbh_fg_ == c6() && nbh_bg_ == c18())
152  {
153  // (6+, 18) case.
154  connectivity_number_fg_ = connectivity_number_3d_c6p<I>;
155  connectivity_number_bg_ = connectivity_number_3d_c18<I>;
156  }
157  else if (nbh_fg_ == c18() && nbh_bg_ == c6())
158  {
159  // (18, 6+) case.
160  connectivity_number_fg_ = connectivity_number_3d_c18<I>;
161  connectivity_number_bg_ = connectivity_number_3d_c6p<I>;
162  }
163  }
164 
165  template <typename I, typename N>
166  inline
167  void
168  is_simple_point3d<I, N>::set_image(const Image<I>& ima)
169  {
170  ima_ = exact(&ima);
171  }
172 
173  template <typename I, typename N>
174  inline
175  bool
176  is_simple_point3d<I, N>::operator()(const mln_psite(I)& p) const
177  {
178  mln_precondition(ima_);
179  const I& ima = *ima_;
180 
181  return
182  connectivity_number_fg_(ima, p, true) == 1 &&
183  connectivity_number_bg_(ima, p, false) == 1;
184  }
185 
186 # endif // MLN_INCLUDE_ONLY
187 
188  } // end of namespace mln::topo
189 
190 } // end of namespace mln
191 
192 #endif // ! MLN_TOPO_IS_SIMPLE_POINT2D_HH