3d/deformer.hh
Go to the documentation of this file.
/* -*- mia-c++ -*-
*
* This file is part of MIA - a toolbox for medical image analysis
* Copyright (c) Leipzig, Madrid 1999-2017 Gert Wollny
*
* MIA is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MIA; if not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef reg3d_deformer_hh
#define reg3d_deformer_hh
#include <memory>
#include <mia/core/parallel.hh>
#include <mia/3d/image.hh>
#include <mia/3d/filter.hh>
#include <mia/3d/interpolator.hh>
#include <mia/core/threadedmsg.hh>
NS_MIA_BEGIN
struct FDeformer3D: public TFilter<P3DImage> {
FDeformer3D(const C3DFVectorfield& vf, const C3DInterpolatorFactory& ipfac):
m_vf(vf),
m_ipfac(ipfac)
{
}
template <typename T>
P3DImage operator () (const T3DImage<T>& image) const
{
T3DImage<T> *timage = new T3DImage<T>(m_vf.get_size(), image);
P3DImage result(timage);
this->operator()(image, *timage);
return result;
}
template <typename T>
P3DImage operator () (const T3DImage<T>& image, T3DImage<T>& result) const
{
assert(result.get_size() == m_vf.get_size());
std::unique_ptr<T3DConvoluteInterpolator<T>> interp(m_ipfac.create(image.data()));
const auto& rinterp = *interp;
auto callback = [this, &rinterp, &result](const C1DParallelRange & range) {
CThreadMsgStream thread_stream;
auto cache = rinterp.create_cache();
for (auto z = range.begin(); z != range.end(); ++z) {
auto r = result.begin_at(0, 0, z);
auto v = m_vf.begin_at(0, 0, z);
for (size_t y = 0; y < result.get_size().y; ++y)
for (size_t x = 0; x < result.get_size().x; ++x, ++r, ++v)
*r = rinterp(C3DFVector(x - v->x, y - v->y, z - v->z), cache);
}
};
pfor(C1DParallelRange(0, result.get_size().z, 1), callback);
return P3DImage();
}
private:
C3DFVectorfield m_vf;
C3DInterpolatorFactory m_ipfac;
};
NS_MIA_END
#endif
filter.hh
image.hh
P3DImage
C3DImage::Pointer P3DImage
define a shortcut to the 3D image shared pointer.
Definition 3d/image.hh:135
interpolator.hh
C3DFVector
T3DVector< float > C3DFVector
A float 3D Vector.
Definition 3d/vector.hh:409
C1DParallelRange
Definition parallelcxx11.hh:84
C3DFVectorfield
a 3D field of floating point single accuracy 3D vectors
Definition 3d/vectorfield.hh:103
C3DInterpolatorFactory
A factory to create interpolators of a given type by providing input data.
Definition 3d/interpolator.hh:175
CThreadMsgStream
This class is used to handle syncronizized output of logging output in a multi-threaded environment.
Definition threadedmsg.hh:45
T3DImage
Specific type of the 3D images that hold real pixel data.
Definition 3d/image.hh:150
T3DImage::begin_at
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:372
T3DImage::get_size
virtual const C3DBounds & get_size() const
T3DImage::data
const T3DDatafield< T > & data() const
read only access to the underlying data
T3DVector::z
T z
vector element
Definition 3d/vector.hh:56
NS_MIA_BEGIN
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition defines.hh:33
NS_MIA_END
#define NS_MIA_END
conveniance define to end the mia namespace
Definition defines.hh:36
parallel.hh
pfor
void pfor(Range range, const Func &f)
Definition parallelcxx11.hh:159
FDeformer3D::operator()
P3DImage operator()(const T3DImage< T > &image) const
Definition 3d/deformer.hh:49
FDeformer3D::FDeformer3D
FDeformer3D(const C3DFVectorfield &vf, const C3DInterpolatorFactory &ipfac)
Definition 3d/deformer.hh:43
TFilter
base class for all filer type functors.
Definition core/filter.hh:70
threadedmsg.hh