My Project
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>
27
29
30
38struct 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 {
60 T2DImage<T> *timage = new T2DImage<T>(image.get_size());
61 std::shared_ptr<T2DInterpolator<T>> interp(m_ipfac.create(image.data()));
62 typename T2DImage<T>::iterator r = timage->begin();
63 C2DFVectorfield::const_iterator v = m_vf.begin();
64
65 for (size_t y = 0; y < image.get_size().y; ++y)
66 for (size_t x = 0; x < image.get_size().x; ++x, ++r, ++v) {
67 *r = (*interp)(C2DFVector(x - v->x, y - v->y));
68 }
69
70 return P2DImage(timage);
71 }
72
79 template <typename T>
80 void operator () (const T2DImage<T>& image, T2DImage<T>& result) const
81 {
82 assert(image.get_size() == result.get_size());
83 std::shared_ptr<T2DInterpolator<T>> interp(m_ipfac.create(image.data()));
84 typename T2DImage<T>::iterator r = result.begin();
85 C2DFVectorfield::const_iterator v = m_vf.begin();
86
87 for (size_t y = 0; y < image.get_size().y; ++y)
88 for (size_t x = 0; x < image.get_size().x; ++x, ++r, ++v) {
89 *r = (*interp)(C2DFVector(x - v->x, y - v->y));
90 }
91 }
92
93private:
94 C2DFVectorfield m_vf;
96};
97
99
100#endif
C2DImage::Pointer P2DImage
Shared pointer representation of the 2D Image.
Definition: 2d/image.hh:120
T2DVector< float > C2DFVector
float valued 2D vector
Definition: 2d/vector.hh:534
a 2D field of floating point single accuracy 2D vectors
const C2DBounds & get_size() const
The factory to create an interpolator from some input data.
T2DInterpolator< T > * create(const T2DDatafield< T > &src) const __attribute__((warn_unused_result))
const_iterator begin() const
This is the template version of a 2D image that is used for holding real data.
Definition: 2d/image.hh:140
const_iterator begin() const
forwarding function to access the underlying T2DDatafield
Definition: 2d/image.hh:269
const T2DDatafield< T > & data() const
get direct access to the data field
#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
FDeformer2D(const C2DFVectorfield &vf, const C2DInterpolatorFactory &ipfac)
Definition: 2d/deformer.hh:45
P2DImage operator()(const T2DImage< T > &image) const
Definition: 2d/deformer.hh:58
base class for all filer type functors.
Definition: core/filter.hh:70