3d/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_3d_transform_hh
22 #define mia_3d_transform_hh
23 
24 #include <iterator>
25 #include <memory>
26 
27 #include <mia/core/vector.hh>
29 #include <mia/core/filter.hh>
30 #include <mia/3d/matrix.hh>
31 #include <mia/3d/image.hh>
32 #include <mia/3d/interpolator.hh>
33 
35 
36 
38 
43 typedef std::shared_ptr<C3DTransformation > P3DTransformation;
44 
53 class EXPORT_3D C3DTransformation: public Transformation<C3DImage, C3DInterpolatorFactory> {
54 public:
56  typedef C3DBounds Size;
57  typedef C3DImage Data;
58  typedef C3DFVector Vector;
60  typedef C3DTransformation type;
61  typedef std::shared_ptr<C3DTransformation> Pointer;
62  static const char *data_descr;
63  static const char *dim_descr;
65 protected:
69  class iterator_impl {
70  public:
71  iterator_impl();
72 
78  iterator_impl(const C3DBounds& pos, const C3DBounds& size);
79 
87  iterator_impl(const C3DBounds& pos, const C3DBounds& begin,
88  const C3DBounds& end, const C3DBounds& size);
89 
91  void increment();
92 
94  const C3DFVector& get_value() const;
95 
97  virtual iterator_impl * clone() const __attribute__((warn_unused_result)) = 0;
98 
103  bool operator == (const iterator_impl& other) const;
104 
106  const C3DBounds& get_pos()const;
107 
109  const C3DBounds& get_size()const;
110  private:
111  virtual const C3DFVector& do_get_value()const = 0;
112  virtual void do_z_increment() = 0;
113  virtual void do_y_increment() = 0;
114  virtual void do_x_increment() = 0;
115 
116  C3DBounds m_pos;
117  C3DBounds m_size;
118  C3DBounds m_start;
119  C3DBounds m_end;
120 
121 
122  };
123 public:
132  class const_iterator : public std::forward_iterator_tag {
133  public:
134 
136  typedef std::forward_iterator_tag iterator_category;
137  typedef C3DFVector value_type;
138  typedef size_t difference_type;
139  typedef C3DFVector *pointer;
140  typedef C3DFVector& reference;
142 
143  const_iterator();
144 
146  const_iterator(const const_iterator& other);
147 
149  const_iterator(iterator_impl * holder);
150 
152  const_iterator& operator = (const const_iterator& other);
153 
155  const_iterator& operator ++();
156 
158  const_iterator operator ++(int);
159 
161  const C3DFVector& operator *() const;
162 
164  const C3DFVector *operator ->() const;
165 
166  private:
167  std::unique_ptr<iterator_impl> m_holder;
168 
171 
172  };
173 
174 
176 
181 
186  void set_creator_string(const std::string& s);
187 
189  const std::string& get_creator_string()const;
190 
194  virtual C3DTransformation *clone() const;
195 
199  virtual C3DTransformation *invert() const = 0;
200 
201 
206  virtual const_iterator begin() const = 0;
207 
213  virtual const_iterator end() const = 0;
214 
215 
220  virtual const_iterator begin_range(const C3DBounds& begin, const C3DBounds& end) const = 0;
221 
227  virtual const_iterator end_range(const C3DBounds& begin, const C3DBounds& end) const = 0;
228 
233  virtual void reinit() const;
234 
235 
241  P3DTransformation upscale(const C3DBounds& size) const;
242 
247  virtual void update(float step, const C3DFVectorfield& a) = 0;
248 
252  virtual size_t degrees_of_freedom() const = 0;
253 
257  virtual void set_identity() = 0;
258 
267  virtual C3DFMatrix derivative_at(int x, int y, int z) const = 0;
268 
275  virtual C3DFMatrix derivative_at(const C3DFVector& x) const = 0;
276 
281  virtual void translate(const C3DFVectorfield& gradient, CDoubleVector& params) const = 0;
282 
286  virtual CDoubleVector get_parameters() const = 0;
287 
291  virtual void set_parameters(const CDoubleVector& params) = 0;
292 
296  virtual float get_max_transform() const = 0;
297 
302  virtual const C3DBounds& get_size() const = 0;
303 
310  virtual float pertuberate(C3DFVectorfield& v) const = 0;
311 
316  virtual C3DFVector apply(const C3DFVector& x) const = 0;
317 
322  virtual C3DFVector operator () (const C3DFVector& x) const = 0;
323 
329  virtual float get_jacobian(const C3DFVectorfield& v, float delta) const = 0;
330 
331 
340  virtual double get_divcurl_cost(double wd, double wr, CDoubleVector& gradient) const = 0;
341 
349  virtual double get_divcurl_cost(double wd, double wr) const = 0;
350 
356  virtual bool refine();
357 
361  void set_debug();
362 protected:
364  bool get_debug()const;
365 
366 private:
367  P3DImage do_transform(const C3DImage& input, const C3DInterpolatorFactory& ipf) const;
368 
369  virtual P3DTransformation do_upscale(const C3DBounds& size) const = 0;
370 
371  std::string m_creator_string;
372  virtual C3DTransformation *do_clone() const = 0;
373  bool m_debug;
374 };
375 
376 
387 
388 
390 
391 #endif