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