26 #ifndef MLN_CORE_IMAGE_COMPLEX_IMAGE_HH
27 # define MLN_CORE_IMAGE_COMPLEX_IMAGE_HH
35 # include <mln/trait/images.hh>
37 # include <mln/core/internal/image_primary.hh>
38 # include <mln/metal/vec.hh>
39 # include <mln/core/site_set/p_complex.hh>
40 # include <mln/core/site_set/complex_psite.hh>
41 # include <mln/value/set.hh>
46 # define mlc_unbool(V) \
47 typename mln::internal::unbool<V>::ret
60 bool_proxy(
bool b) : b_(b) {}
61 bool& operator=(
bool b) { b_ = b;
return *
this; }
63 operator bool&() {
return b_; }
64 operator const bool&()
const {
return b_; }
66 bool operator==(
const bool_proxy& rhs) {
return b_ == rhs.b_; }
67 bool operator< (
const bool_proxy& rhs) {
return b_ < rhs.b_; }
74 template <
typename V>
struct unbool {
typedef V ret; };
75 template <>
struct unbool<bool> {
typedef bool_proxy ret; };
92 template <
unsigned D,
typename G,
typename V>
class complex_image;
98 template <
unsigned D,
typename G,
typename V>
99 struct data< complex_image<D, G, V> >
101 data(
const p_complex<D, G>& pc,
102 const metal::vec< D + 1, std::vector<V> >& values);
104 metal::vec< D + 1, std::vector< mlc_unbool(V) > > values_;
105 const p_complex<D, G> pc_;
114 template <
unsigned D,
typename G,
typename V>
115 struct image_< complex_image<D, G, V> >
116 : default_image_< V, complex_image<D, G, V> >
118 typedef trait::image::category::primary category;
121 typedef trait::image::speed::fast speed;
122 typedef trait::image::size::regular size;
125 typedef trait::image::value_access::direct value_access;
129 typedef trait::image::vw_io::none vw_io;
130 typedef trait::image::vw_set::none vw_set;
131 typedef trait::image::value_storage::disrupted value_storage;
132 typedef trait::image::value_browsing::site_wise_only value_browsing;
133 typedef trait::image::value_alignment::irrelevant value_alignment;
134 typedef trait::image::value_io::read_write value_io;
137 typedef trait::image::pw_io::read_write pw_io;
138 typedef trait::image::localization::space localization;
143 typedef typename trait::image::dimension::none dimension;
146 typedef trait::image::ext_domain::none ext_domain;
147 typedef trait::image::ext_value::irrelevant ext_value;
148 typedef trait::image::ext_io::irrelevant ext_io;
163 template <
unsigned D,
typename G,
typename V>
165 :
public internal::image_primary< V, p_complex<D, G>,
166 complex_image<D, G, V> >
170 static const unsigned dim = D;
191 const metal::vec< D + 1, std::vector<V> >&
values);
196 const metal::vec< D + 1, std::vector<V> >&
values);
209 const metal::vec<D + 1, std::vector< mlc_unbool(V) > >&
values()
const;
214 template <
unsigned D,
typename G,
typename V,
typename W>
215 void init_(tag::image_t,
220 # ifndef MLN_INCLUDE_ONLY
226 template <
unsigned D,
typename G,
typename V,
typename W>
228 void init_(tag::image_t,
232 metal::vec<D + 1, std::vector<V> > values;
233 for (
unsigned i = 0; i <= D; ++i)
234 values[i].resize(model.
domain().nfaces_of_dim(i));
235 target.init_(model.
domain(), values);
244 template <
unsigned D,
typename G,
typename V>
247 const metal::vec< D + 1, std::vector<V> >& values)
252 for (
unsigned i = 0; i <= D; ++i)
254 values_[i].reserve(values[i].size());
255 values_[i].insert(values_[i].begin(),
256 values[i].begin(), values[i].end());
263 for (
unsigned i = 0; i < D; ++i)
264 mln_precondition(pc.nfaces_of_dim(i) == values[i].size());
274 template <
unsigned D,
typename G,
typename V>
280 template <
unsigned D,
typename G,
typename V>
284 metal::vec<D + 1, std::vector<V> > values;
285 for (
unsigned i = 0; i <= D; ++i)
290 template <
unsigned D,
typename G,
typename V>
292 complex_image<D, G, V>::complex_image(
const p_complex<D, G>& pc,
293 const metal::vec< D + 1,
294 std::vector<V> >& values)
299 template <
unsigned D,
typename G,
typename V>
302 complex_image<D, G, V>::init_(
const p_complex<D, G>& pc,
303 const metal::vec< D + 1, std::vector<V> >& values)
305 mln_precondition(! this->is_valid());
307 new internal::data< complex_image<D, G, V> >(pc, values);
314 template <
unsigned D,
typename G,
typename V>
316 typename complex_image<D, G, V>::rvalue
319 mln_precondition(this->data_->pc_.has(p));
320 return this->data_->values_[p.
n()][p.
face_id()];
323 template <
unsigned D,
typename G,
typename V>
328 mln_precondition(this->data_->pc_.has(p));
329 return this->data_->values_[p.
n()][p.
face_id()];
332 template <
unsigned D,
typename G,
typename V>
334 const metal::vec< D + 1, std::vector< mlc_unbool(V) > >&
337 return this->data_->values_;
340 template <
unsigned D,
typename G,
typename V>
345 mln_precondition(this->is_valid());
346 return this->data_->pc_;
349 # endif // ! MLN_INCLUDE_ONLY
355 #endif // ! MLN_CORE_IMAGE_COMPLEX_IMAGE_HH