$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
run_image.hh
1 // Copyright (C) 2007, 2008, 2009, 2012, 2013 EPITA Research and
2 // Development 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_CORE_INTERNAL_RUN_IMAGE_HH
28 # define MLN_CORE_INTERNAL_RUN_IMAGE_HH
29 
35 # include <mln/core/internal/image_primary.hh>
36 # include <mln/core/site_set/p_run.hh>
37 # include <mln/core/site_set/p_set_of.hh>
38 
39 namespace mln
40 {
41 
42  namespace internal
43  {
44 
52  template <typename T, typename P, typename E>
53  class run_image_ : public internal::image_primary< P, p_set_of< p_run<P> >, E >
54  {
55  protected:
56  run_image_();
57 
58  public:
67  float compression() const;
68 
74  void finalize();
75 
83  P point_at(const mln_psite(p_set_of< p_run<P> >)& ps) const;
84 
89  bool has(const mln_psite(p_set_of< p_run<P> >)& ps) const;
90  };
91 
92 # ifndef MLN_INCLUDE_ONLY
93 
94  template <typename T, typename P, typename E>
95  inline
97  {
98  }
99 
100  template <typename T, typename P, typename E>
101  inline
102  float
104  {
105  return float(exact(this)->data_->memory_size()) /
106  float (sizeof(T) * exact(this)->data_->domain_.bbox().nsites());
107  }
108 
109  template <typename T, typename P, typename E>
110  inline
111  void
113  {
114  exact(this)->data_->finalize();
115  }
116 
117  template <typename T, typename P, typename E>
118  inline
119  P
120  run_image_<T, P, E>::point_at(const mln_psite(p_set_of< p_run<P> >)& ps) const
121  {
122  const E* ima = exact(this);
123  mln_precondition(ps.index() < ima->data_->domain_.nsites());
124  mln_precondition(ps.p().index() < ima->data_->domain_[ps.index()].length());
125  return ima->data_->domain_[ps.index()][ps.p().index()];
126  }
127 
128  template <typename T, typename P, typename E>
129  inline
130  bool
131  run_image_<T, P, E>::has(const mln_psite(p_set_of< p_run<P> >)& ps) const
132  {
133  const E* ima = exact(this);
134  if (!ima->is_valid())
135  return false;
136  else
137  return (ps.index() < ima->data_->domain_.nsites()
138  && ps.p().index() < ima->data_->domain_[ps.index()].length()
139  && ima->data_->domain_[ps.index()][ps.p().index()] == ps);
140  }
141 
142 # endif // ! MLN_INCLUDE_ONLY
143 
144  } // end of namespace internal
145 
146 } // end of namespace mln
147 
148 
149 #endif // ! MLN_CORE_INTERNAL_RUN_IMAGE_HH