2d/deformer.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_deformer_hh
22 #define mia_2d_deformer_hh
23 
24 #include <mia/2d/image.hh>
25 #include <mia/2d/filter.hh>
26 #include <mia/2d/interpolator.hh>
27 
29 
30 
38 struct FDeformer2D: public TFilter<P2DImage> {
39 
46  m_vf(vf),
47  m_ipfac(ipfac)
48  {
49  }
50 
57  template <typename T>
58  P2DImage operator () (const T2DImage<T>& image) const {
59  T2DImage<T> *timage = new T2DImage<T>(image.get_size());
60 
61  std::shared_ptr<T2DInterpolator<T> > interp(m_ipfac.create(image.data()));
62 
63  typename T2DImage<T>::iterator r = timage->begin();
64  C2DFVectorfield::const_iterator v = m_vf.begin();
65 
66  for (size_t y = 0; y < image.get_size().y; ++y)
67  for (size_t x = 0; x < image.get_size().x; ++x, ++r, ++v) {
68  *r = (*interp)(C2DFVector(x - v->x, y - v->y));
69  }
70  return P2DImage(timage);
71  }
72 
79  template <typename T>
80  void operator () (const T2DImage<T>& image, T2DImage<T>& result) const {
81  assert(image.get_size() == result.get_size());
82 
83  std::shared_ptr<T2DInterpolator<T> > interp(m_ipfac.create(image.data()));
84 
85  typename T2DImage<T>::iterator r = result.begin();
86  C2DFVectorfield::const_iterator v = m_vf.begin();
87 
88  for (size_t y = 0; y < image.get_size().y; ++y)
89  for (size_t x = 0; x < image.get_size().x; ++x, ++r, ++v) {
90  *r = (*interp)(C2DFVector(x - v->x, y - v->y));
91  }
92  }
93 
94 private:
95  C2DFVectorfield m_vf;
96  C2DInterpolatorFactory m_ipfac;
97 };
98 
100 
101 #endif
T2DInterpolator< T > * create(const T2DDatafield< T > &src) const __attribute__((warn_unused_result))
P2DImage operator()(const T2DImage< T > &image) const
Definition: 2d/deformer.hh:58
C2DImage::Pointer P2DImage
Shared pointer representation of the 2D Image.
Definition: 2d/image.hh:119
const_iterator begin() const
const_iterator begin() const
forwarding function to access the underlying T2DDatafield
Definition: 2d/image.hh:261
base class for all filer type functors.
Definition: core/filter.hh:70
T y
second element
Definition: 2d/vector.hh:56
This is the template version of a 2D image that is used for holding real data.
Definition: 2d/image.hh:138
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition: defines.hh:33
a 2D field of floating point single accuracy 2D vectors
The factory to create an interpolator from some input data.
T2DVector< float > C2DFVector
float valued 2D vector
Definition: 2d/vector.hh:490
const T2DDatafield< T > & data() const
get direct access to the data field
const C2DBounds & get_size() const
FDeformer2D(const C2DFVectorfield &vf, const C2DInterpolatorFactory &ipfac)
Definition: 2d/deformer.hh:45
T x
first element
Definition: 2d/vector.hh:53
#define NS_MIA_END
conveniance define to end the mia namespace
Definition: defines.hh:36