$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
graph_nbh_iter.hh
1 // Copyright (C) 2008, 2009 EPITA Research and Development Laboratory
2 // (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_UTIL_INTERNAL_GRAPH_NBH_ITER_HH
28 # define MLN_UTIL_INTERNAL_GRAPH_NBH_ITER_HH
29 
30 # include <mln/core/concept/proxy.hh>
31 # include <mln/util/internal/graph_nbh_iter_base.hh>
32 # include <mln/util/vertex.hh>
33 # include <mln/util/edge.hh>
34 
38 
39 namespace mln
40 {
41 
42  namespace internal
43  {
44 
45  /*-----------------------------`
46  | vertex_nbh_vertex_*_iterator |
47  \-----------------------------*/
48 
49  template <typename G>
51  : public nbh_iterator_base<G,
52  util::vertex<G>,
53  util::vertex<G>,
54  vertex_nbh_vertex_fwd_iterator<G> >
55  {
56  typedef util::vertex<G> V;
59 
60  public:
62  typedef V center;
64  typedef V nbh;
65 
69  template <typename C>
72 
73  protected:
74  // Manipulation.
77  bool is_valid_() const;
79 
81  unsigned start_id_() const;
82 
84  unsigned next_id_() const;
85 
86  void update_();
87 
88  friend class nbh_iterator_base<G, V, V, self_>;
89  };
90 
91  template <typename G>
93  : public nbh_iterator_base<G,
94  util::vertex<G>,
95  util::vertex<G>,
96  vertex_nbh_vertex_bkd_iterator<G> >
97  {
98  typedef util::vertex<G> V;
99 
102 
103  public:
105  typedef V center;
107  typedef V nbh;
108 
112  template <typename C>
113  vertex_nbh_vertex_bkd_iterator(const C& c);
115 
116  protected:
120  bool is_valid_() const;
122 
124  unsigned start_id_() const;
125 
127  unsigned next_id_() const;
128 
129  void update_();
130 
131  friend class nbh_iterator_base<G, V, V, self_>;
132  };
133 
134 
135  /*---------------------------`
136  | vertex_nbh_edge_*_iterator |
137  \---------------------------*/
138 
139  template <typename G>
141  : public nbh_iterator_base<G,
142  util::vertex<G>,
143  util::edge<G>,
144  vertex_nbh_edge_fwd_iterator<G> >
145  {
146  typedef util::vertex<G> V;
147  typedef util::edge<G> E;
150 
151  public:
153  typedef V center;
155  typedef E nbh;
156 
160  template <typename C>
161  vertex_nbh_edge_fwd_iterator(const C& c);
163 
164  protected:
165  // Manipulation.
168  bool is_valid_() const;
170 
172  unsigned start_id_() const;
173 
175  unsigned next_id_() const;
176 
177  void update_();
178 
179  friend class nbh_iterator_base<G, V, E, self_>;
180  };
181 
182 
183  template <typename G>
185  : public nbh_iterator_base<G,
186  util::vertex<G>,
187  util::edge<G>,
188  vertex_nbh_edge_bkd_iterator<G> >
189  {
190  typedef util::vertex<G> V;
191  typedef util::edge<G> E;
194 
195  public:
197  typedef V center;
199  typedef E nbh;
200 
204  template <typename C>
205  vertex_nbh_edge_bkd_iterator(const C& c);
207 
208  protected:
209  // Manipulation.
212  bool is_valid_() const;
214 
216  unsigned start_id_() const;
217 
219  unsigned next_id_() const;
220 
221  void update_();
222 
223  friend class nbh_iterator_base<G, V, E, self_>;
224  };
225 
226 
227  /*---------------------------`
228  | edge_nbh_edge_*_iterator |
229  \---------------------------*/
230 
231  template <typename G>
233  : public nbh_iterator_base<G,
234  util::edge<G>,
235  util::edge<G>,
236  edge_nbh_edge_fwd_iterator<G> >
237  {
238  typedef util::edge<G> E;
241 
242  public:
244  typedef E center;
246  typedef E nbh;
247 
248 
252  template <typename C>
253  edge_nbh_edge_fwd_iterator(const C& c);
255 
256  protected:
257  // Manipulation.
260  bool is_valid_() const;
262 
264  unsigned start_id_() const;
265 
267  unsigned next_id_() const;
268 
269  void update_();
270 
271  friend class nbh_iterator_base<G, E, E, self_>;
272  };
273 
274 
275  template <typename G>
277  : public nbh_iterator_base<G,
278  util::edge<G>,
279  util::edge<G>,
280  edge_nbh_edge_bkd_iterator<G> >
281  {
282  typedef util::edge<G> E;
283 
286 
287  public:
288 
290  typedef E center;
292  typedef E nbh;
293 
297  template <typename C>
298  edge_nbh_edge_bkd_iterator(const C& c);
300 
301  protected:
302  // Manipulation.
305  bool is_valid_() const;
307 
309  unsigned start_id_() const;
310 
312  unsigned next_id_() const;
313 
314  void update_();
315 
316  friend class nbh_iterator_base<G, E, E, self_>;
317  };
318 
319 # ifndef MLN_INCLUDE_ONLY
320 
321  /*-------------------------------`
322  | vertex_nbh_vertex_fwd_iterator |
323  \-------------------------------*/
324 
325  template <typename G>
326  inline
328  {
329  }
330 
331  template <typename G>
332  template <typename C>
333  inline
335  : super_(c)
336  {
337  }
338 
339  template <typename G>
340  inline
341  bool
343  {
344  return this->c_->is_valid() && this->i_ < this->c_->nmax_nbh_vertices();
345  }
346 
347  template <typename G>
348  inline
349  unsigned
351  {
352  return 0;
353  }
354 
355  template <typename G>
356  inline
357  unsigned
359  {
360  return this->i_ + 1;
361  }
362 
363  template <typename G>
364  inline
365  void
367  {
368  this->elt_.update_id(this->c_->ith_nbh_vertex(this->i_));
369  }
370 
371  /*-------------------------------`
372  | vertex_nbh_vertex_bkd_iterator |
373  \-------------------------------*/
374 
375  template <typename G>
376  inline
378  {
379  }
380 
381  template <typename G>
382  template <typename C>
383  inline
385  : super_(c)
386  {
387  }
388 
389  template <typename G>
390  inline
391  bool
393  {
394  return this->c_->is_valid() && this->i_ < this->c_->nmax_nbh_vertices();
395  }
396 
397  template <typename G>
398  inline
399  unsigned
401  {
402  return this->c_->nmax_nbh_vertices() - 1;
403  }
404 
405  template <typename G>
406  inline
407  unsigned
409  {
410  return this->i_ - 1;
411  }
412 
413  template <typename G>
414  inline
415  void
417  {
418  this->elt_.update_id(this->c_->ith_nbh_vertex(this->i_));
419  }
420 
421 
422  /*-----------------------------`
423  | vertex_nbh_edge_fwd_iterator |
424  \-----------------------------*/
425 
426  template <typename G>
427  inline
429  {
430  }
431 
432  template <typename G>
433  template <typename C>
434  inline
436  : super_(c)
437  {
438  }
439 
440  template <typename G>
441  inline
442  bool
444  {
445  return this->c_->is_valid() && this->i_ < this->c_->nmax_nbh_edges();
446  }
447 
448  template <typename G>
449  inline
450  unsigned
452  {
453  return 0;
454  }
455 
456  template <typename G>
457  inline
458  unsigned
460  {
461  return this->i_ + 1;
462  }
463 
464  template <typename G>
465  inline
466  void
468  {
469  this->elt_.update_id(this->c_->ith_nbh_edge(this->i_));
470  }
471 
472  /*-----------------------------`
473  | vertex_nbh_edge_bkd_iterator |
474  \-----------------------------*/
475 
476  template <typename G>
477  inline
479  {
480  }
481 
482  template <typename G>
483  template <typename C>
484  inline
486  : super_(c)
487  {
488  }
489 
490  template <typename G>
491  inline
492  bool
494  {
495  return this->c_->is_valid() && this->i_ < this->c_->nmax_nbh_edges();
496  }
497 
498  template <typename G>
499  inline
500  unsigned
502  {
503  return this->c_->nmax_nbh_edges() - 1;
504  }
505 
506  template <typename G>
507  inline
508  unsigned
510  {
511  return this->i_ - 1;
512  }
513 
514  template <typename G>
515  inline
516  void
518  {
519  this->elt_.update_id(this->c_->ith_nbh_edge(this->i_));
520  }
521 
522 
523 
524  /*-----------------------------`
525  | edge_nbh_edge_fwd_iterator |
526  \-----------------------------*/
527 
528  template <typename G>
529  inline
531  {
532  }
533 
534  template <typename G>
535  template <typename C>
536  inline
538  : super_(c)
539  {
540  }
541 
542  template <typename G>
543  inline
544  bool
546  {
547  return this->c_->is_valid() && this->i_ < this->c_->nmax_nbh_edges();
548  }
549 
550  template <typename G>
551  inline
552  unsigned
554  {
555  return 0;
556  }
557 
558  template <typename G>
559  inline
560  unsigned
562  {
563  return this->i_ + 1;
564  }
565 
566  template <typename G>
567  inline
568  void
570  {
571  // We shall encounter the current edge in its neighborhood
572  // since it is computed thanks to the edge neighboors of its
573  // two vertices.
574  // We do not want the current edge to be part of its neighbors.
575  util::edge_id_t e_id = this->c_->ith_nbh_edge(this->i_);
576  while (e_id == this->c_->id())
577  {
578  this->i_ = next_id_();
579  e_id = this->c_->ith_nbh_edge(this->i_);
580  }
581 
582  this->elt_.update_id(e_id);
583  }
584 
585  /*-----------------------------`
586  | edge_nbh_edge_bkd_iterator |
587  \-----------------------------*/
588 
589  template <typename G>
590  inline
592  {
593  }
594 
595  template <typename G>
596  template <typename C>
597  inline
599  : super_(c)
600  {
601  }
602 
603  template <typename G>
604  inline
605  bool
607  {
608  return this->c_->is_valid() && this->i_ < this->c_->nmax_nbh_edges();
609  }
610 
611  template <typename G>
612  inline
613  unsigned
615  {
616  return this->c_->nmax_nbh_edges() - 1;
617  }
618 
619  template <typename G>
620  inline
621  unsigned
623  {
624  return this->i_ - 1;
625  }
626 
627  template <typename G>
628  inline
629  void
631  {
632  // We shall encounter vertices which are part of the
633  // current edge.
634  // We do not want them to be part of the edge neighbors.
635  unsigned e_id = this->c_->ith_nbh_edge(this->i_);
636  while (e_id == this->c_->id())
637  {
638  this->i_ = next_id_();
639  e_id = this->c_->ith_nbh_edge(this->i_);
640  }
641 
642  this->elt_.update_id(e_id);
643  }
644 
645 # endif // !MLN_INCLUDE_ONLY
646 
647  } // End of namespace mln::internal
648 
649 } // End of namespace mln
650 
651 
652 #endif // ! MLN_UTIL_INTERNAL_GRAPH_NBH_ITER_HH