Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
geom/complex_geometry.hh
1 // Copyright (C) 2008, 2009 EPITA Research and Development Laboratory (LRDE)
2 //
3 // This file is part of Olena.
4 //
5 // Olena is free software: you can redistribute it and/or modify it under
6 // the terms of the GNU General Public License as published by the Free
7 // Software Foundation, version 2 of the License.
8 //
9 // Olena is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
16 //
17 // As a special exception, you may use this file as part of a free
18 // software project without restriction. Specifically, if other files
19 // instantiate templates or use macros or inline functions from this
20 // file, or you compile this file and link it with other files to produce
21 // an executable, this file does not by itself cause the resulting
22 // executable to be covered by the GNU General Public License. This
23 // exception does not however invalidate any other reasons why the
24 // executable file might be covered by the GNU General Public License.
25 
26 #ifndef MLN_GEOM_COMPLEX_GEOMETRY_HH
27 # define MLN_GEOM_COMPLEX_GEOMETRY_HH
28 
34 
35 # include <vector>
36 # include <set>
37 
38 # include <mln/topo/face.hh>
39 # include <mln/topo/adj_m_face_iter.hh>
40 
41 # include <mln/util/multi_site.hh>
42 # include <mln/util/tracked_ptr.hh>
43 
44 
45 /* FIXME: Also provide functors where the locations are computed using
46  a function (useful for a complex on a regular grid/support. */
47 
48 /* FIXME: This class could probably be turned into something more
49  generic, usable for other other purpose, e.g. attaching sites to
50  graphs. */
51 
52 /* FIXME: Also provide another geometry type where everything is
53  stored even for n-face with n > 0. */
54 
55 
56 namespace mln
57 {
58 
59  namespace geom
60  {
61 
62  // Forward declaration.
63  namespace internal
64  {
65  template <typename P> struct complex_geometry_data;
66  }
67 
68 
87  template <unsigned D, typename P>
89  {
90  public:
91  typedef P location;
92  typedef util::multi_site<P> site;
93 
94  public:
97 
98  public:
104  unsigned add_location(const P& p);
105 
107  site operator()(const mln::topo::face<D>& f) const;
108 
109  private:
111  };
112 
113 
114  namespace internal
115  {
119  template <typename P>
120  struct complex_geometry_data
121  {
122  std::vector<P> zero_faces_geom;
123  };
124  }
125 
126 
127 
128 # ifndef MLN_INCLUDE_ONLY
129 
130  template <unsigned D, typename P>
131  inline
133  : data_(new internal::complex_geometry_data<P>())
134  {
135  }
136 
137  template <unsigned D, typename P>
138  inline
139  unsigned
141  {
142  mln_precondition(data_);
143  // FIXME: These two lines are not thread safe.
144  data_->zero_faces_geom.push_back(p);
145  return data_->zero_faces_geom.size();
146  }
147 
148  template <unsigned D, typename P>
149  inline
150  util::multi_site<P>
152  {
153  mln_precondition(data_);
154  site s;
155  s.reserve(1);
156  if (f.n() == 0)
157  {
158  // F is a 0-face.
159  mln_assertion(f.face_id() < data_->zero_faces_geom.size());
160  s.push_back(data_->zero_faces_geom[f.face_id()]);
161  }
162  else
163  {
164  /* F is an n-face, with n > 0.
165  Compute the set of 0-faces transitively adjacent to F. */
167  for_all(g)
168  s.push_back(data_->zero_faces_geom[g.subject().face_id()]);
169  }
170  return s;
171  }
172 
173 # endif // ! MLN_INCLUDE_ONLY
174 
175  } // end of mln::geom
176 
177 } // end of mln
178 
179 #endif // ! MLN_GEOM_COMPLEX_GEOMETRY_HH