$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
geom/complex_geometry.hh
1 // Copyright (C) 2008, 2009, 2011, 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_GEOM_COMPLEX_GEOMETRY_HH
28 # define MLN_GEOM_COMPLEX_GEOMETRY_HH
29 
35 
36 # include <vector>
37 # include <set>
38 
39 # include <mln/topo/face.hh>
40 # include <mln/topo/adj_m_face_iter.hh>
41 
42 # include <mln/util/multi_site.hh>
43 # include <mln/util/tracked_ptr.hh>
44 
45 
46 /* FIXME: Also provide functors where the locations are computed using
47  a function (useful for a complex on a regular grid/support). */
48 
49 /* FIXME: This class could probably be turned into something more
50  generic, usable for other other purpose, e.g. attaching sites to
51  graphs. */
52 
53 /* FIXME: Also provide another geometry type where everything is
54  stored even for n-face with n > 0. */
55 
56 
57 namespace mln
58 {
59 
60  namespace geom
61  {
62 
63  // Forward declaration.
64  namespace internal
65  {
66  template <typename P> struct complex_geometry_data;
67  }
68 
69 
88  template <unsigned D, typename P>
90  {
91  public:
92  typedef P location;
94 
95  public:
98 
99  public:
105  unsigned add_location(const P& p);
106 
108  site operator()(const mln::topo::face<D>& f) const;
109 
111  void reserve(size_t n);
112 
113  private:
115  };
116 
117 
118  namespace internal
119  {
126  template <typename P>
128  {
129  std::vector<P> zero_faces_geom;
130  };
131  }
132 
133 
134 
135 # ifndef MLN_INCLUDE_ONLY
136 
137  template <unsigned D, typename P>
138  inline
140  : data_(new internal::complex_geometry_data<P>())
141  {
142  }
143 
144  template <unsigned D, typename P>
145  inline
146  unsigned
147  complex_geometry<D, P>::add_location(const P& p)
148  {
149  mln_precondition(data_);
150  // FIXME: These two lines are not thread safe.
151  data_->zero_faces_geom.push_back(p);
152  return data_->zero_faces_geom.size();
153  }
154 
155  template <unsigned D, typename P>
156  inline
157  util::multi_site<P>
158  complex_geometry<D, P>::operator()(const mln::topo::face<D>& f) const
159  {
160  mln_precondition(data_);
161  site s;
162  s.reserve(1);
163  if (f.n() == 0)
164  {
165  // F is a 0-face.
166  mln_assertion(f.face_id() < data_->zero_faces_geom.size());
167  s.push_back(data_->zero_faces_geom[f.face_id()]);
168  }
169  else
170  {
171  /* F is an n-face, with n > 0.
172  Compute the set of 0-faces transitively adjacent to F. */
173  topo::adj_m_face_fwd_iter<D> g(f, 0);
174  for_all(g)
175  s.push_back(data_->zero_faces_geom[g.subject().face_id()]);
176  }
177  return s;
178  }
179 
180  template <unsigned D, typename P>
181  inline
182  void
183  complex_geometry<D, P>::reserve(size_t n)
184  {
185  mln_precondition(data_);
186  data_->zero_faces_geom.reserve(n);
187  }
188 
189 # endif // ! MLN_INCLUDE_ONLY
190 
191  } // end of mln::geom
192 
193 } // end of mln
194 
195 #endif // ! MLN_GEOM_COMPLEX_GEOMETRY_HH