My Project
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 
37 class C3DTransformation;
38 
43 typedef std::shared_ptr<C3DTransformation > P3DTransformation;
44 
53 class EXPORT_3D C3DTransformation: public Transformation<C3DImage, C3DInterpolatorFactory>
54 {
55 public:
57  typedef C3DBounds Size;
58  typedef C3DImage Data;
59  typedef C3DFVector Vector;
61  typedef C3DTransformation type;
62  typedef std::shared_ptr<C3DTransformation> Pointer;
63  static const char *data_descr;
64  static const char *dim_descr;
66 protected:
71  {
72  public:
74 
80  iterator_impl(const C3DBounds& pos, const C3DBounds& size);
81 
89  iterator_impl(const C3DBounds& pos, const C3DBounds& begin,
90  const C3DBounds& end, const C3DBounds& size);
91 
93  void increment();
94 
96  const C3DFVector& get_value() const;
97 
99  virtual iterator_impl *clone() const __attribute__((warn_unused_result)) = 0;
100 
105  bool operator == (const iterator_impl& other) const;
106 
108  const C3DBounds& get_pos()const;
109 
111  const C3DBounds& get_size()const;
112  private:
113  virtual const C3DFVector& do_get_value()const = 0;
114  virtual void do_z_increment() = 0;
115  virtual void do_y_increment() = 0;
116  virtual void do_x_increment() = 0;
117 
118  C3DBounds m_pos;
119  C3DBounds m_size;
120  C3DBounds m_start;
121  C3DBounds m_end;
122 
123 
124  };
125 public:
134  class const_iterator : public std::forward_iterator_tag
135  {
136  public:
137 
139  typedef std::forward_iterator_tag iterator_category;
140  typedef C3DFVector value_type;
141  typedef size_t difference_type;
142  typedef C3DFVector *pointer;
143  typedef C3DFVector& reference;
145 
147 
150 
153 
155  const_iterator& operator = (const const_iterator& other);
156 
158  const_iterator& operator ++();
159 
161  const_iterator operator ++(int);
162 
164  const C3DFVector& operator *() const;
165 
167  const C3DFVector *operator ->() const;
168 
170  const C3DBounds& pos()const;
171 
172 
174  const C3DBounds& get_size()const;
175 
176 
177  private:
178  std::unique_ptr<iterator_impl> m_holder;
179 
182 
183  };
184 
185 
187 
192 
197  void set_creator_string(const std::string& s);
198 
200  const std::string& get_creator_string()const;
201 
205  virtual C3DTransformation *clone() const;
206 
210  virtual C3DTransformation *invert() const = 0;
211 
212 
217  virtual const_iterator begin() const = 0;
218 
224  virtual const_iterator end() const = 0;
225 
226 
231  virtual const_iterator begin_range(const C3DBounds& begin, const C3DBounds& end) const = 0;
232 
238  virtual const_iterator end_range(const C3DBounds& begin, const C3DBounds& end) const = 0;
239 
244  virtual void reinit() const;
245 
246 
252  P3DTransformation upscale(const C3DBounds& size) const;
253 
258  virtual void update(float step, const C3DFVectorfield& a) = 0;
259 
263  virtual size_t degrees_of_freedom() const = 0;
264 
268  virtual void set_identity() = 0;
269 
278  virtual C3DFMatrix derivative_at(int x, int y, int z) const = 0;
279 
286  virtual C3DFMatrix derivative_at(const C3DFVector& x) const = 0;
287 
292  virtual void translate(const C3DFVectorfield& gradient, CDoubleVector& params) const = 0;
293 
297  virtual CDoubleVector get_parameters() const = 0;
298 
302  virtual void set_parameters(const CDoubleVector& params) = 0;
303 
307  virtual float get_max_transform() const = 0;
308 
313  virtual const C3DBounds& get_size() const = 0;
314 
321  virtual float pertuberate(C3DFVectorfield& v) const = 0;
322 
327  virtual C3DFVector apply(const C3DFVector& x) const __attribute__((deprecated));
328 
335  virtual C3DFVector get_displacement_at(const C3DFVector& x) const = 0;
336 
341  virtual C3DFVector operator () (const C3DFVector& x) const = 0;
342 
348  virtual float get_jacobian(const C3DFVectorfield& v, float delta) const = 0;
349 
356  virtual bool refine();
357 
361  void set_debug();
362 
363  /* Attributes */
367  static constexpr const char *input_spacing_attr = "in-voxel-spacing";
368 
372  static constexpr const char *output_spacing_attr = "out-voxel-spacing";
373 
374 
376 protected:
378  bool get_debug()const;
379 
380 private:
381  P3DImage do_transform(const C3DImage& input, const C3DInterpolatorFactory& ipf) const;
382 
383  virtual P3DTransformation do_upscale(const C3DBounds& size) const = 0;
384 
385  std::string m_creator_string;
386  virtual C3DTransformation *do_clone() const = 0;
387  bool m_debug;
388 };
389 
390 
401 
402 
404 
405 #endif
C3DImage::Pointer P3DImage
define a shortcut to the 3D image shared pointer.
Definition: 3d/image.hh:135
bool operator==(const CAttribute &a, const CAttribute &b)
Definition: attributes.hh:95
a 3D field of floating point single accuracy 3D vectors
The generic base type of a 3D image.
Definition: 3d/image.hh:47
A factory to create interpolators of a given type by providing input data.
const C3DBounds & get_size() const
const C3DBounds & pos() const
return the current position in 3D space
const_iterator(iterator_impl *holder)
initialize the iterator with the actual worker object
const_iterator(const const_iterator &other)
Copy constructor.
virtual iterator_impl * clone() const __attribute__((warn_unused_result))=0
const C3DFVector & get_value() const
void increment()
move to next position
iterator_impl(const C3DBounds &pos, const C3DBounds &begin, const C3DBounds &end, const C3DBounds &size)
iterator_impl(const C3DBounds &pos, const C3DBounds &size)
This is the generic base class for 3D transformations.
Definition: 3d/transform.hh:54
virtual C3DTransformation * clone() const
virtual float get_jacobian(const C3DFVectorfield &v, float delta) const =0
C3DTransformation(const C3DInterpolatorFactory &ipf)
virtual C3DFVector apply(const C3DFVector &x) const __attribute__((deprecated))
virtual const C3DBounds & get_size() const =0
virtual void update(float step, const C3DFVectorfield &a)=0
virtual float pertuberate(C3DFVectorfield &v) const =0
virtual void set_parameters(const CDoubleVector &params)=0
virtual const_iterator begin() const =0
virtual float get_max_transform() const =0
virtual C3DTransformation * invert() const =0
P3DTransformation upscale(const C3DBounds &size) const
void set_creator_string(const std::string &s)
virtual C3DBounds get_minimal_supported_image_size() const
const std::string & get_creator_string() const
virtual void set_identity()=0
virtual C3DFMatrix derivative_at(int x, int y, int z) const =0
virtual bool refine()
virtual C3DFMatrix derivative_at(const C3DFVector &x) const =0
virtual void reinit() const
virtual CDoubleVector get_parameters() const =0
virtual size_t degrees_of_freedom() const =0
bool get_debug() const
virtual void translate(const C3DFVectorfield &gradient, CDoubleVector &params) const =0
virtual const_iterator end() const =0
virtual const_iterator end_range(const C3DBounds &begin, const C3DBounds &end) const =0
virtual const_iterator begin_range(const C3DBounds &begin, const C3DBounds &end) const =0
virtual C3DFVector get_displacement_at(const C3DFVector &x) const =0
A wrapper around the c-array to provide an STL like interface for iterators.
Definition: core/vector.hh:78
generic base class for transformations
I InterpolatorFactory
type of the interpolator used by this transformation
D Data
typedef for the data type to be transformed by this transformation
#define EXPORT_3D
Definition: defines3d.hh:45
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition: defines.hh:33
#define NS_MIA_END
conveniance define to end the mia namespace
Definition: defines.hh:36
EXPORT_3D bool operator!=(const C3DTransformation::const_iterator &a, const C3DTransformation::const_iterator &b)
Compare two transformation iterators.
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)