$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
adj_lower_dim_connected_n_face_iter.hh
1 // Copyright (C) 2008, 2009, 2012 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_ADJ_LOWER_DIM_CONNECTED_N_FACE_ITER_HH
28 # define MLN_TOPO_ADJ_LOWER_DIM_CONNECTED_N_FACE_ITER_HH
29 
35 
36 # include <set>
37 
38 # include <mln/topo/internal/complex_relative_iterator_base.hh>
39 # include <mln/topo/algebraic_face.hh>
40 
41 
42 namespace mln
43 {
44 
45  namespace topo
46  {
47 
48  // Forward declarations.
49  template <unsigned D> class complex;
50  namespace internal
51  {
52  template <unsigned D> class adj_lower_dim_connected_n_face_iterator;
53  }
54 
55 
56  /*---------------------------------------------------.
57  | topo::adj_lower_dim_connected_n_face_fwd_iter<D>. |
58  `---------------------------------------------------*/
59 
67  template <unsigned D>
70  algebraic_face<D>,
71  adj_lower_dim_connected_n_face_fwd_iter<D> >,
73  {
74  // Tech note: we use topo::face to help g++-2.95.
75  private:
79  self_ > super_;
80 
81  public:
85  template <typename Fref>
86  adj_lower_dim_connected_n_face_fwd_iter(const Fref& f_ref);
88 
93  void update_adj_faces_();
94  };
95 
96 
97  /*---------------------------------------------------.
98  | topo::adj_lower_dim_connected_n_face_bkd_iter<D>. |
99  `---------------------------------------------------*/
100 
108  template <unsigned D>
111  algebraic_face<D>,
112  adj_lower_dim_connected_n_face_bkd_iter<D> >,
114  {
115  // Tech note: we use topo::face to help g++-2.95.
116  private:
120  self_ > super_;
121 
122  public:
126  template <typename Fref>
127  adj_lower_dim_connected_n_face_bkd_iter(const Fref& f_ref);
129 
134  void update_adj_faces_();
135  };
136 
137 
138  /*-------------------------------------------------------------.
139  | topo::internal::adj_lower_dim_connected_n_face_iterator<D>. |
140  `-------------------------------------------------------------*/
141 
142  namespace internal
143  {
144 
145  template <unsigned D>
147  {
148  protected:
151  void update_adj_faces__(const topo::face<D>& center,
152  std::vector< algebraic_face<D> >& adj_faces);
153  };
154 
155  } // end of namespace mln::topo::internal
156 
157 
158 
159 # ifndef MLN_INCLUDE_ONLY
160 
161  /*---------------------------------------------------.
162  | topo::adj_lower_dim_connected_n_face_fwd_iter<D>. |
163  `---------------------------------------------------*/
164 
165  template <unsigned D>
166  inline
168  {
169  }
170 
171  template <unsigned D>
172  template <typename Fref>
173  inline
175  : super_(f_ref)
176  {
177  }
178 
179  /* FIXME: Most of this code is shared by
180  adj_lower_dim_connected_n_face_{fwd,bkd}_iter<D> and
181  adj_higher_dim_connected_n_face_{fwd,bkd}_iter<D>). Find a way
182  to factor this, maybe through a common (implementation) base
183  class. */
184  template <unsigned D>
185  inline
186  void
187  adj_lower_dim_connected_n_face_fwd_iter<D>::update_adj_faces_()
188  {
189  mln_precondition(this->c_);
190  // Delegate computation to base class.
191  this->update_adj_faces__(*this->c_, this->adj_faces_);
192  }
193 
194 
195  /*---------------------------------------------------.
196  | topo::adj_lower_dim_connected_n_face_bkd_iter<D>. |
197  `---------------------------------------------------*/
198 
199  template <unsigned D>
200  inline
201  adj_lower_dim_connected_n_face_bkd_iter<D>::adj_lower_dim_connected_n_face_bkd_iter()
202  {
203  }
204 
205  template <unsigned D>
206  template <typename Fref>
207  inline
208  adj_lower_dim_connected_n_face_bkd_iter<D>::adj_lower_dim_connected_n_face_bkd_iter(const Fref& f_ref)
209  : super_(f_ref)
210  {
211  }
212 
213  template <unsigned D>
214  inline
215  void
216  adj_lower_dim_connected_n_face_bkd_iter<D>::update_adj_faces_()
217  {
218  mln_precondition(this->c_);
219  // Delegate computation to base class.
220  this->update_adj_faces__(*this->c_, this->adj_faces_);
221  }
222 
223 
224  /*-------------------------------------------------------------.
225  | topo::internal::adj_lower_dim_connected_n_face_iterator<D>. |
226  `-------------------------------------------------------------*/
227 
228  namespace internal
229  {
230 
231  /* FIXME: Factor
232  topo::internal::adj_lower_dim_connected_n_face_iterator<D> and
233  topo::internal::adj_higher_dim_connected_n_face_iterator<D>. */
234 
235  template <unsigned D>
236  inline
237  void
238  adj_lower_dim_connected_n_face_iterator<D>::update_adj_faces__(const topo::face<D>& center,
239  std::vector< algebraic_face<D> >& adj_faces)
240  {
241  // Reset the result container.
242  adj_faces.clear();
243 
244  /* A set of faces containing the same values as ADJ_FACES, used
245  to quickly check whether a candidate face has already been
246  added to the pool of adjacent faces. We use an std::set
247  because the lookup is cheaper (O(log(n)) vs O(n) for a
248  vector, where n is the size of the containers. */
249  std::set< algebraic_face<D> > faces_set;
250  typedef std::vector< algebraic_face<D> > faces_t;
251 
252  // The set of (n-1)-faces adjacent to CENTER.
253  faces_t shared_lower_faces = center.lower_dim_adj_faces();
254  for (typename faces_t::const_iterator slf = shared_lower_faces.begin();
255  slf != shared_lower_faces.end(); ++slf)
256  {
257  /* The n-faces sharing an adjacent (n-1)-face with CENTER.
258  Note that this set contains CENTER itself. */
259  faces_t adj_n_faces = slf->higher_dim_adj_faces();
260  for (typename faces_t::const_iterator af = adj_n_faces.begin();
261  af != adj_n_faces.end(); ++af)
262  {
263  /* Ensure that 1. we are not adding CENTER to the result;
264  and 2. that we are not adding an already added
265  processed face. */
266  if (*af != center &&
267  faces_set.find(*af) == faces_set.end())
268  {
269  adj_faces.push_back(*af);
270  faces_set.insert(*af);
271  }
272  }
273  }
274  }
275 
276  } // end of namespace mln::topo::internal
277 
278 # endif // ! MLN_INCLUDE_ONLY
279 
280  } // end of namespace mln::topo
281 
282 } // end of namespace mln
283 
284 #endif // ! MLN_TOPO_ADJ_LOWER_DIM_CONNECTED_N_FACE_ITER_HH