2d/transform.hh
Go to the documentation of this file.
1 /* -*- mia-c++ -*-
2  *
3  * This file is part of MIA - a toolbox for medical image analysis
4  * Copyright (c) Leipzig, Madrid 1999-2013 Gert Wollny
5  *
6  * MIA is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with MIA; if not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 #ifndef mia_2d_transform_hh
22 #define mia_2d_transform_hh
23 
24 #include <iterator>
25 #include <memory>
26 #include <ostream>
27 
29 #include <mia/core/filter.hh>
30 #include <mia/2d/matrix.hh>
31 #include <mia/2d/image.hh>
32 #include <mia/2d/interpolator.hh>
33 
35 
36 
45 class EXPORT_2D C2DTransformation: public Transformation<C2DImage, C2DInterpolatorFactory> {
46 public:
48  typedef C2DImage Data;
49 
51  typedef C2DBounds Size;
52 
54  typedef C2DFVector Vector;
55 
58 
61 
63  typedef std::shared_ptr<C2DTransformation > Pointer;
64 
66  static const char *data_descr;
67 
69  static const char *dim_descr;
70 protected:
71 
79  class iterator_impl {
80  public:
81  iterator_impl();
82 
90  iterator_impl(const C2DBounds& pos, const C2DBounds& size);
91 
93  void increment();
94 
96  void advance(unsigned int delta);
97 
99  const C2DFVector& get_value() const;
100 
102  virtual iterator_impl * clone() const __attribute__((warn_unused_result)) = 0;
103 
110  bool operator == (const iterator_impl& other) const;
111 
113  const C2DBounds& get_pos()const;
114 
116  const C2DBounds& get_size()const;
117 
123  void print(std::ostream& os) const;
124  private:
125  virtual const C2DFVector& do_get_value()const = 0;
126  virtual void do_y_increment() = 0;
127  virtual void do_x_increment() = 0;
128 
129  C2DBounds m_pos;
130  C2DBounds m_size;
131 
132  };
133 public:
140  class const_iterator : public std::forward_iterator_tag {
141  public:
142 
144  typedef std::forward_iterator_tag iterator_category;
145 
148 
150  typedef size_t difference_type;
151 
153  typedef C2DFVector *pointer;
154 
157 
162  const_iterator();
163 
169  const_iterator(iterator_impl * holder);
170 
171 
175  const_iterator& operator = (const const_iterator& other);
176 
180  const_iterator(const const_iterator& other);
181 
182 
186  const_iterator& operator ++();
187 
191  const_iterator operator ++(int);
192 
199  const_iterator& operator += (unsigned int delta);
200 
202  const C2DFVector& operator *() const;
203 
205  const C2DFVector *operator ->() const;
206 
210  void print(std::ostream& os) const;
211  private:
212  std::unique_ptr<iterator_impl> m_holder;
213 
216 
217  };
218 
220 
225 
230  void set_creator_string(const std::string& s);
231 
233  const std::string& get_creator_string()const;
234 
238  virtual C2DTransformation *clone() const __attribute__((warn_unused_result));
239 
243  virtual C2DTransformation *invert() const __attribute__((warn_unused_result)) = 0;
244 
249  virtual const_iterator begin() const = 0;
250 
256  virtual const_iterator end() const = 0;
257 
263  Pointer upscale(const C2DBounds& size) const;
264 
269  virtual void update(float step, const C2DFVectorfield& a) = 0;
270 
274  virtual size_t degrees_of_freedom() const = 0;
275 
279  virtual void set_identity() = 0;
280 
287  virtual C2DFMatrix derivative_at(const C2DFVector& x) const = 0;
288 
296  virtual C2DFMatrix derivative_at(int x, int y) const = 0;
297 
302  virtual void translate(const C2DFVectorfield& gradient, CDoubleVector& params) const = 0;
303 
307  virtual CDoubleVector get_parameters() const = 0;
308 
312  virtual void set_parameters(const CDoubleVector& params) = 0;
313 
317  virtual float get_max_transform() const = 0;
318 
323  virtual const C2DBounds& get_size() const = 0;
324 
331  virtual float pertuberate(C2DFVectorfield& v) const = 0;
332 
337  virtual C2DFVector apply(const C2DFVector& x) const = 0;
338 
343  virtual C2DFVector operator () (const C2DFVector& x) const = 0;
344 
350  virtual float get_jacobian(const C2DFVectorfield& v, float delta) const = 0;
351 
352 
361  virtual double get_divcurl_cost(double wd, double wr, CDoubleVector& gradient) const = 0;
362 
370  virtual double get_divcurl_cost(double wd, double wr) const = 0;
371 
377  virtual bool refine();
378 
379 private:
380 
381  virtual Pointer do_upscale(const C2DBounds& size) const = 0;
382 
383  std::string m_creator_string;
384  virtual C2DTransformation *do_clone() const __attribute__((warn_unused_result)) = 0;
385 
386 
387  P2DImage do_transform(const C2DImage& input, const C2DInterpolatorFactory& ipf) const;
388 
389 };
390 
396 
397 
398 
404 inline C2DTransformation::const_iterator operator + (C2DTransformation::const_iterator i, size_t delta)
405 {
406  i += delta;
407  return i;
408 }
409 
416 inline std::ostream& operator << (std::ostream& os,
418 {
419  i.print(os);
420  return os;
421 }
422 
433 
434 
436 
437 #endif