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-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_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 
207  const C2DBounds& pos() const;
208 
209  const C2DBounds& get_size() const;
210 
214  void print(std::ostream& os) const;
215  private:
216  std::unique_ptr<iterator_impl> m_holder;
217 
220 
221  };
222 
224 
229 
234  void set_creator_string(const std::string& s);
235 
237  const std::string& get_creator_string()const;
238 
242  virtual C2DTransformation *clone() const __attribute__((warn_unused_result));
243 
247  virtual C2DTransformation *invert() const __attribute__((warn_unused_result)) = 0;
248 
253  virtual const_iterator begin() const = 0;
254 
260  virtual const_iterator end() const = 0;
261 
267  Pointer upscale(const C2DBounds& size) const;
268 
273  virtual void update(float step, const C2DFVectorfield& a) = 0;
274 
278  virtual size_t degrees_of_freedom() const = 0;
279 
283  virtual void set_identity() = 0;
284 
291  virtual C2DFMatrix derivative_at(const C2DFVector& x) const = 0;
292 
300  virtual C2DFMatrix derivative_at(int x, int y) const = 0;
301 
306  virtual void translate(const C2DFVectorfield& gradient, CDoubleVector& params) const = 0;
307 
311  virtual CDoubleVector get_parameters() const = 0;
312 
316  virtual void set_parameters(const CDoubleVector& params) = 0;
317 
321  virtual float get_max_transform() const = 0;
322 
327  virtual const C2DBounds& get_size() const = 0;
328 
335  virtual float pertuberate(C2DFVectorfield& v) const = 0;
336 
341  virtual C2DFVector apply(const C2DFVector& x) const __attribute__((deprecated)){
342  return get_displacement_at(x);
343  }
344 
348  virtual C2DFVector get_displacement_at(const C2DFVector& x) const =0;
353  virtual C2DFVector operator () (const C2DFVector& x) const = 0;
354 
360  virtual float get_jacobian(const C2DFVectorfield& v, float delta) const = 0;
361 
362 
368  virtual bool refine();
369 
370  /* Attributes */
374  static constexpr const char *input_spacing_attr = "in-pixel-spacing";
375 
379  static constexpr const char *output_spacing_attr = "out-pixel-spacing";
380 
381 
387  virtual C2DBounds get_minimal_supported_image_size() const;
388 
389 private:
390 
391  virtual Pointer do_upscale(const C2DBounds& size) const = 0;
392 
393  std::string m_creator_string;
394  virtual C2DTransformation *do_clone() const __attribute__((warn_unused_result)) = 0;
395 
396 
397  P2DImage do_transform(const C2DImage& input, const C2DInterpolatorFactory& ipf) const;
398 
399 };
400 
406 
407 
408 
414 inline C2DTransformation::const_iterator operator + (C2DTransformation::const_iterator i, size_t delta)
415 {
416  i += delta;
417  return i;
418 }
419 
426 inline std::ostream& operator << (std::ostream& os,
428 {
429  i.print(os);
430  return os;
431 }
432 
443 
444 
446 
447 #endif
C2DImage::Pointer P2DImage
Shared pointer representation of the 2D Image.
Definition: 2d/image.hh:119
bool operator==(const CAttribute &a, const CAttribute &b)
Definition: attributes.hh:93
C2DTransformation type
generic name for this transformation type
Definition: 2d/transform.hh:60
C2DFVector value_type
generic name for the value type of this iterator
A wrapper around the c-array to provide an STL like interface for iterators.
Definition: core/vector.hh:75
C2DFVector Vector
generic name for the vector type used by this transformation
Definition: 2d/transform.hh:54
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition: defines.hh:33
EXPORT_2D C2DFVectorfield & operator+=(C2DFVectorfield &a, const C2DFVectorfield &b)
C2DTransformation::Pointer P2DTransformation
Pointer type for the 2D transformation.
EXPORT_2D bool operator!=(const C2DTransformation::const_iterator &a, const C2DTransformation::const_iterator &b)
Compare two transformation iterators.
Base of the implementation of an iterator over the transformation domain This iterator takes care of ...
Definition: 2d/transform.hh:79
C2DImage Data
generic name for the data used by this transformation
Definition: 2d/transform.hh:48
C2DBounds Size
generic name for the size type used by this transformation
Definition: 2d/transform.hh:51
#define EXPORT_2D
Definition: defines2d.hh:37
a 2D field of floating point single accuracy 2D vectors
C2DFVector * pointer
generic name for the pointer type of this iterator
This is the generic base class for 2D transformations.
Definition: 2d/transform.hh:45
C2DInterpolatorFactory InterpolatorFactory
generic name for the interpolation factory used by this transformation
Definition: 2d/transform.hh:57
generic base class for transformations
void print(std::ostream &os) const
A simple 2x2 matrix.
Definition: 2d/matrix.hh:36
static const char * data_descr
plug-in search path element "type"
Definition: 2d/transform.hh:66
C2DFVector & reference
generic name for the reference type of this iterator
std::forward_iterator_tag iterator_category
provide the STL with some typedef fro traits
The factory to create an interpolator from some input data.
size_t difference_type
generic name for the difference type of this iterator
std::ostream & operator<<(std::ostream &os, const C2DTransformation::const_iterator &i)
static const char * dim_descr
plug-in search path element "data"
Definition: 2d/transform.hh:69
This is the base class for 2D images that can hold generic pixel data.
Definition: 2d/image.hh:47
std::shared_ptr< C2DTransformation > Pointer
pointer type of this transformation
Definition: 2d/transform.hh:63
Matrix EXPORT_GSL operator*(const Matrix &lhs, const Matrix &rhs)
#define NS_MIA_END
conveniance define to end the mia namespace
Definition: defines.hh:36