dynamic_image2d.i 8.73 KB
Newer Older
1
//						       		-*- C++ -*-
2
3
// Copyright (C) 2008, 2009, 2014 EPITA Research and Development
// Laboratory (LRDE).
4
//
5
// This file is part of Olena.
6
//
7
8
9
10
11
// Olena is free software: you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation, version 2 of the License.
//
// Olena is distributed in the hope that it will be useful,
12
13
14
15
16
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
17
18
19
20
21
22
23
24
25
26
// along with Olena.  If not, see <http://www.gnu.org/licenses/>.
//
// As a special exception, you may use this file as part of a free
// software project without restriction.  Specifically, if other files
// instantiate templates or use macros or inline functions from this
// file, or you compile this file and link it with other files to produce
// an executable, this file does not by itself cause the resulting
// executable to be covered by the GNU General Public License.  This
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44

/// \file dynamic_image2d
/// \brief A dynamic version of image2d, extendable in the target language.


%module(directors="1") dynamic_image2d

%import "point2d.i"
%import "box2d.i"

%import "int_u8.i"
// FIXME: The import directive does not include the `%{ ... %}' clauses.
%{
#include "mln/value/int_u8.hh"
%}

%{
# include <mln/core/concept/image.hh>
Roland Levillain's avatar
Roland Levillain committed
45
46
# include <mln/core/alias/box2d.hh>
# include <mln/core/routine/init.hh>
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72

# include <mln/value/set.hh>
%}

// Shortcuts macros.
%include "mln/core/macros.hh"

// Concept.
%include "mln/core/concept/image.hh"

%feature("director");

%inline %{
namespace mln
{

  // FIXME: Separate interface and implementation (and/or move the C++
  // code into its own file).

  // Fwd decl.
  template <typename T> struct dynamic_image2d;


  namespace trait
  {

Roland Levillain's avatar
Roland Levillain committed
73
74
75
    // These traits actually depend on the exact (here dynamic) type
    // of the image, therefore we should provide several entry points
    // (dynamic_image_ implementations.
76
77
78
79
    template <typename T>
    struct image_< dynamic_image2d<T> >
      : default_image_< T, dynamic_image2d<T> >
    {
Roland Levillain's avatar
Roland Levillain committed
80
      // misc
81
      typedef trait::image::category::primary category;
Roland Levillain's avatar
Roland Levillain committed
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
      typedef trait::image::speed::slow       speed;
      typedef trait::image::size::regular     size;

      // value
      typedef trait::image::vw_io::none                    vw_io;
      typedef trait::image::vw_set::none                   vw_set;
      typedef trait::image::value_access::indirect         value_access;
      typedef trait::image::value_storage::disrupted       value_storage;
      typedef trait::image::value_browsing::site_wise_only value_browsing;
      typedef trait::image::value_alignment::with_grid     value_alignment;
      typedef trait::image::value_io::read_write           value_io;

      // site / domain
      typedef trait::image::pw_io::read_write        pw_io;
      typedef trait::image::localization::basic_grid localization;
      typedef trait::image::dimension::two_d         dimension;

      // extended domain
      typedef trait::image::ext_domain::none      ext_domain;
      typedef trait::image::ext_value::irrelevant ext_value;
      typedef trait::image::ext_io::irrelevant    ext_io;
103
104
105
106
107
108
    };

  } // end of namespace mln::trait


  /* FIXME: Inherit from internal::image_base to factor methods (see
Roland Levillain's avatar
Roland Levillain committed
109
110
     below)?  Probably not, as internal::image_base contains data
     (through a tracked_ptr).  */
111
112
113
114
115
116
117
118
  // \brief A semi-abstract class that serves as an entry point
  // (called  director  by SWIG) for Python code.
  //
  // This class is not really abstract in the C++ sense, but it lacks
  // methods to be a real image class.
  template <typename T>
  struct dynamic_image2d : Image< dynamic_image2d<T> >
  {
Roland Levillain's avatar
Roland Levillain committed
119
120
    typedef box2d domain_t;
    typedef point2d site;
121
122
123
124
    typedef point2d psite;
    typedef dpoint2d dpoint;
    typedef mln_fwd_piter(box2d) fwd_piter;
    typedef mln_bkd_piter(box2d) bkd_piter;
Roland Levillain's avatar
Roland Levillain committed
125
    typedef fwd_piter piter;
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155

    /// Value associated type.
    typedef T         value;

    /// Return type of read-only access.
    typedef const T& rvalue;

    /// Return type of read-write access.
    typedef T&       lvalue;


    /// Skeleton.
    typedef dynamic_image2d< tag::value_<T> > skeleton;


    /// Value_Set associated type.
    typedef mln::value::set<T> vset;


    /// Constructor without argument.
    dynamic_image2d();

    /// Constructor with the numbers of rows and columns and the
    /// border thickness.
    dynamic_image2d(int nrows, int ncols);

    /// Constructor with a box and the border thickness (default is
    /// 3).
    dynamic_image2d(const box2d& b);

156
    virtual ~dynamic_image2d();
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178

    /// Initialize an empty image.
    virtual void init_(const box2d& b);


    /// Give the set of values of the image.
    virtual const vset& values() const;

    /// Give the definition domain.
    virtual const box2d& domain() const;

    /// Read-only access to the image value located at point \p p.
    virtual const T& operator()(const point2d& p) const;

    /// Read-write access to the image value located at point \p p.
    virtual T& operator()(const point2d& p);


    /// Test if \p p belongs to the image domain.
    virtual bool has(const psite& p) const;
    /// Give a bounding box of the image domain.
    virtual const box2d& bbox() const;
Roland Levillain's avatar
Roland Levillain committed
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194

    /// Is this image valid?  (dummy method).
    virtual bool is_valid() const;

    /// Eligible-value-set associated type.
    typedef mln::value::set<T> t_eligible_values_set;

    // Return the set of the image eligigle values
    const t_eligible_values_set& values_eligible() const;

    /// Value space associated type.
    typedef mln::value::set<
      typename mln::value::super_value<T>::ret > t_values_space;

    /// Return the value space of the image.
    const t_values_space& values_space() const;
195
196
197

    // We can set domain_ to protected, otherwise Python subclasses
    // won't see it.
Roland Levillain's avatar
Roland Levillain committed
198
    domain_t domain_;
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
  };


  template <typename T, typename J>
  inline
  void init_(tag::image_t, dynamic_image2d<T>& target, const J& model)
  {
    box2d b;
    init_(tag::bbox, b, model);
    target.init_(b);
  }


  template <typename T>
  inline
  dynamic_image2d<T>::dynamic_image2d()
  {
  }

  template <typename T>
  inline
  dynamic_image2d<T>::dynamic_image2d(int nrows, int ncols)
  {
    init_(make::box2d(nrows, ncols));
  }

  template <typename T>
  inline
  dynamic_image2d<T>::dynamic_image2d(const box2d& b)
  {
    init_(b);
  }

232
233
234
235
236
237
  template <typename T>
  inline
  dynamic_image2d<T>::~dynamic_image2d()
  {
  }

238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
  template <typename T>
  inline
  void
  dynamic_image2d<T>::init_(const box2d& b)
  {
    domain_ = b;
  }

  template <typename T>
  inline
  const typename dynamic_image2d<T>::vset&
  dynamic_image2d<T>::values() const
  {
    return vset::the();
  }

  template <typename T>
  inline
  const box2d&
  dynamic_image2d<T>::domain() const
  {
Roland Levillain's avatar
Roland Levillain committed
259
    mln_precondition(this->is_valid());
260
261
262
263
264
265
266
267
    return domain_;
  }

  // Dummy implementation, provided to have swig wrap the class (swig won't
  // wrap an abstract class).
  template <typename T>
  inline
  const T&
268
  dynamic_image2d<T>::operator()(const point2d&) const
269
  {
270
271
272
    abort();
    static T v;
    return v;
273
274
275
276
277
278
279
  }

  // Dummy implementation, provided to have swig wrap the class (swig won't
  // wrap an abstract class).
  template <typename T>
  inline
  T&
280
  dynamic_image2d<T>::operator()(const point2d&)
281
  {
282
283
284
    abort();
    static T v;
    return v;
285
286
287
288
289
290
291
  }

  template <typename T>
  inline
  bool
  dynamic_image2d<T>::has(const psite& p) const
  {
Roland Levillain's avatar
Roland Levillain committed
292
    mln_precondition(this->is_valid());
293
294
295
296
297
298
299
300
    return exact(this)->domain().has(p);
  }

  template <typename T>
  inline
  const box2d&
  dynamic_image2d<T>::bbox() const
  {
Roland Levillain's avatar
Roland Levillain committed
301
    mln_precondition(this->is_valid());
302
303
304
305
306
    return exact(this)->domain().bbox();
  }

  template <typename T>
  inline
Roland Levillain's avatar
Roland Levillain committed
307
308
  bool
  dynamic_image2d<T>::is_valid() const
309
  {
Roland Levillain's avatar
Roland Levillain committed
310
311
    // Dummy.
    return false;
312
313
314
315
  }

  template <typename T>
  inline
Roland Levillain's avatar
Roland Levillain committed
316
317
318
319
320
321
322
323
324
325
  const typename dynamic_image2d<T>::t_eligible_values_set&
  dynamic_image2d<T>::values_eligible() const
  {
    return t_eligible_values_set::the();
  }

  template <typename T>
  inline
  const typename dynamic_image2d<T>::t_values_space&
  dynamic_image2d<T>::values_space() const
326
  {
Roland Levillain's avatar
Roland Levillain committed
327
    return t_values_space::the();
328
329
330
331
332
333
334
335
336
337
  }

} // end of namespace mln
%}


%template(dynamic_image2d_int_u8) mln::dynamic_image2d< mln::value::int_u<8> >;


%include "fill.ixx"
Roland Levillain's avatar
Roland Levillain committed
338
%template(fill) mln::data::fill< mln::dynamic_image2d< mln::value::int_u<8> > >;
339
340
341

%include "println.ixx"
%template(println) mln::debug::println< mln::dynamic_image2d< mln::value::int_u<8> > >;