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-2017 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 
167  const C3DBounds& pos()const;
168 
169 
171  const C3DBounds& get_size()const;
172 
173 
174  private:
175  std::unique_ptr<iterator_impl> m_holder;
176 
179 
180  };
181 
182 
184 
189 
194  void set_creator_string(const std::string& s);
195 
197  const std::string& get_creator_string()const;
198 
202  virtual C3DTransformation *clone() const;
203 
207  virtual C3DTransformation *invert() const = 0;
208 
209 
214  virtual const_iterator begin() const = 0;
215 
221  virtual const_iterator end() const = 0;
222 
223 
228  virtual const_iterator begin_range(const C3DBounds& begin, const C3DBounds& end) const = 0;
229 
235  virtual const_iterator end_range(const C3DBounds& begin, const C3DBounds& end) const = 0;
236 
241  virtual void reinit() const;
242 
243 
249  P3DTransformation upscale(const C3DBounds& size) const;
250 
255  virtual void update(float step, const C3DFVectorfield& a) = 0;
256 
260  virtual size_t degrees_of_freedom() const = 0;
261 
265  virtual void set_identity() = 0;
266 
275  virtual C3DFMatrix derivative_at(int x, int y, int z) const = 0;
276 
283  virtual C3DFMatrix derivative_at(const C3DFVector& x) const = 0;
284 
289  virtual void translate(const C3DFVectorfield& gradient, CDoubleVector& params) const = 0;
290 
294  virtual CDoubleVector get_parameters() const = 0;
295 
299  virtual void set_parameters(const CDoubleVector& params) = 0;
300 
304  virtual float get_max_transform() const = 0;
305 
310  virtual const C3DBounds& get_size() const = 0;
311 
318  virtual float pertuberate(C3DFVectorfield& v) const = 0;
319 
324  virtual C3DFVector apply(const C3DFVector& x) const __attribute__((deprecated));
325 
332  virtual C3DFVector get_displacement_at(const C3DFVector& x) const = 0;
333 
338  virtual C3DFVector operator () (const C3DFVector& x) const = 0;
339 
345  virtual float get_jacobian(const C3DFVectorfield& v, float delta) const = 0;
346 
353  virtual bool refine();
354 
358  void set_debug();
359 
360  /* Attributes */
364  static constexpr const char *input_spacing_attr = "in-voxel-spacing";
365 
369  static constexpr const char *output_spacing_attr = "out-voxel-spacing";
370 
371 
372  virtual C3DBounds get_minimal_supported_image_size() const;
373 protected:
375  bool get_debug()const;
376 
377 private:
378  P3DImage do_transform(const C3DImage& input, const C3DInterpolatorFactory& ipf) const;
379 
380  virtual P3DTransformation do_upscale(const C3DBounds& size) const = 0;
381 
382  std::string m_creator_string;
383  virtual C3DTransformation *do_clone() const = 0;
384  bool m_debug;
385 };
386 
387 
398 
399 
401 
402 #endif
I InterpolatorFactory
type of the interpolator used by this transformation
bool operator==(const CAttribute &a, const CAttribute &b)
Definition: attributes.hh:93
C3DImage::Pointer P3DImage
define a shortcut to the 3D image shared pointer.
Definition: 3d/image.hh:134
a 3D field of floating point single accuracy 3D vectors
A wrapper around the c-array to provide an STL like interface for iterators.
Definition: core/vector.hh:75
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition: defines.hh:33
#define EXPORT_3D
Definition: defines3d.hh:44
This is the generic base class for 3D transformations.
Definition: 3d/transform.hh:53
EXPORT_3D bool operator!=(const C3DTransformation::const_iterator &a, const C3DTransformation::const_iterator &b)
Compare two transformation iterators.
generic base class for transformations
The generic base type of a 3D image.
Definition: 3d/image.hh:46
A factory to create interpolators of a given type by providing input data.
std::shared_ptr< C3DTransformation > P3DTransformation
pointer type for a 3D transformation
Definition: 3d/transform.hh:37
Matrix EXPORT_GSL operator*(const Matrix &lhs, const Matrix &rhs)
D Data
typedef for the data type to be transformed by this transformation
#define NS_MIA_END
conveniance define to end the mia namespace
Definition: defines.hh:36