3d/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 reg3d_deformer_hh
22 #define reg3d_deformer_hh
23 
24 #include <memory>
25 #include <mia/core/parallel.hh>
26 
27 
28 #include <mia/3d/image.hh>
29 #include <mia/3d/filter.hh>
30 #include <mia/3d/interpolator.hh>
31 #include <mia/core/threadedmsg.hh>
32 
33 
35 
42 struct FDeformer3D: public TFilter<P3DImage> {
44  m_vf(vf),
45  m_ipfac(ipfac)
46  {
47  }
48  template <typename T>
49  P3DImage operator () (const T3DImage<T>& image) const {
50  T3DImage<T> *timage = new T3DImage<T>(m_vf.get_size(), image);
51  P3DImage result(timage);
52  this->operator()(image, *timage);
53  return result;
54  }
55 
56  template <typename T>
57  P3DImage operator () (const T3DImage<T>& image, T3DImage<T>& result) const {
58  assert(result.get_size() == m_vf.get_size());
59  std::unique_ptr<T3DConvoluteInterpolator<T> > interp(m_ipfac.create(image.data()));
60  const auto& rinterp = *interp;
61 
62  auto callback = [this, &rinterp, &result](const C1DParallelRange& range){
63  CThreadMsgStream thread_stream;
64  auto cache = rinterp.create_cache();
65  for (auto z = range.begin(); z != range.end();++z) {
66  auto r = result.begin_at(0,0,z);
67  auto v = m_vf.begin_at(0,0,z);
68  for (size_t y = 0; y < result.get_size().y; ++y)
69  for (size_t x = 0; x < result.get_size().x; ++x, ++r, ++v)
70  *r = rinterp(C3DFVector(x - v->x, y - v->y, z - v->z), cache);
71  }
72  };
73  pfor(C1DParallelRange(0, result.get_size().z, 1), callback);
74  return P3DImage();
75  }
76 
77 private:
78  C3DFVectorfield m_vf;
79  C3DInterpolatorFactory m_ipfac;
80 };
81 
82 
84 
85 #endif
const T3DDatafield< T > & data() const
read only access to the underlying data
Specific type of the 3D images that hold real pixel data.
Definition: 3d/image.hh:148
void pfor(Range range, const Func &f)
FDeformer3D(const C3DFVectorfield &vf, const C3DInterpolatorFactory &ipfac)
Definition: 3d/deformer.hh:43
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 filter to transform an image.
Definition: 3d/deformer.hh:42
T z
vector element
Definition: 3d/vector.hh:55
base class for all filer type functors.
Definition: core/filter.hh:70
T3DVector< float > C3DFVector
A float 3D Vector.
Definition: 3d/vector.hh:346
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition: defines.hh:33
This class is used to handle syncronizized output of logging output in a multi-threaded environment...
Definition: threadedmsg.hh:44
const_iterator begin_at(size_t x, size_t y, size_t z) const
T y
vector element
Definition: 3d/vector.hh:53
T3DConvoluteInterpolator< T > * create(const T3DDatafield< T > &src) const __attribute__((warn_unused_result))
const C3DBounds & get_size() const
virtual const C3DBounds & get_size() const
A factory to create interpolators of a given type by providing input data.
const_iterator begin_at(size_t x, size_t y, size_t z) const
constant iterator starting at the given location
Definition: 3d/image.hh:354
P3DImage operator()(const T3DImage< T > &image) const
Definition: 3d/deformer.hh:49
T x
vector element
Definition: 3d/vector.hh:51
#define NS_MIA_END
conveniance define to end the mia namespace
Definition: defines.hh:36