3d/transform.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 mia_3d_transform_hh
#define mia_3d_transform_hh
#include <iterator>
#include <memory>
#include <mia/core/vector.hh>
#include <mia/core/transformation.hh>
#include <mia/core/filter.hh>
#include <mia/3d/matrix.hh>
#include <mia/3d/image.hh>
#include <mia/3d/interpolator.hh>
NS_MIA_BEGIN
class C3DTransformation;
typedef std::shared_ptr<C3DTransformation > P3DTransformation;
class EXPORT_3D C3DTransformation: public Transformation<C3DImage, C3DInterpolatorFactory>
{
public:
typedef C3DBounds Size;
typedef C3DImage Data;
typedef C3DFVector Vector;
typedef C3DInterpolatorFactory InterpolatorFactory;
typedef C3DTransformation type;
typedef std::shared_ptr<C3DTransformation> Pointer;
static const char *data_descr;
static const char *dim_descr;
protected:
class iterator_impl
{
public:
iterator_impl();
iterator_impl(const C3DBounds& pos, const C3DBounds& size);
iterator_impl(const C3DBounds& pos, const C3DBounds& begin,
const C3DBounds& end, const C3DBounds& size);
void increment();
const C3DFVector& get_value() const;
virtual iterator_impl *clone() const __attribute__((warn_unused_result)) = 0;
bool operator == (const iterator_impl& other) const;
const C3DBounds& get_pos()const;
const C3DBounds& get_size()const;
private:
virtual const C3DFVector& do_get_value()const = 0;
virtual void do_z_increment() = 0;
virtual void do_y_increment() = 0;
virtual void do_x_increment() = 0;
C3DBounds m_pos;
C3DBounds m_size;
C3DBounds m_start;
C3DBounds m_end;
};
public:
class const_iterator : public std::forward_iterator_tag
{
public:
typedef std::forward_iterator_tag iterator_category;
typedef C3DFVector value_type;
typedef size_t difference_type;
typedef C3DFVector *pointer;
typedef C3DFVector& reference;
const_iterator();
const_iterator(const const_iterator& other);
const_iterator(iterator_impl *holder);
const_iterator& operator = (const const_iterator& other);
const_iterator& operator ++();
const_iterator operator ++(int);
const C3DFVector& operator *() const;
const C3DFVector *operator ->() const;
const C3DBounds& pos()const;
const C3DBounds& get_size()const;
private:
std::unique_ptr<iterator_impl> m_holder;
friend EXPORT_3D bool operator == (const C3DTransformation::const_iterator& a,
const C3DTransformation::const_iterator& b);
};
using Transformation<C3DImage, C3DInterpolatorFactory>::operator ();
C3DTransformation(const C3DInterpolatorFactory& ipf);
void set_creator_string(const std::string& s);
const std::string& get_creator_string()const;
virtual C3DTransformation *clone() const;
virtual C3DTransformation *invert() const = 0;
virtual const_iterator begin() const = 0;
virtual const_iterator end() const = 0;
virtual const_iterator begin_range(const C3DBounds& begin, const C3DBounds& end) const = 0;
virtual const_iterator end_range(const C3DBounds& begin, const C3DBounds& end) const = 0;
virtual void reinit() const;
P3DTransformation upscale(const C3DBounds& size) const;
virtual void update(float step, const C3DFVectorfield& a) = 0;
virtual size_t degrees_of_freedom() const = 0;
virtual void set_identity() = 0;
virtual C3DFMatrix derivative_at(int x, int y, int z) const = 0;
virtual C3DFMatrix derivative_at(const C3DFVector& x) const = 0;
virtual void translate(const C3DFVectorfield& gradient, CDoubleVector& params) const = 0;
virtual CDoubleVector get_parameters() const = 0;
virtual void set_parameters(const CDoubleVector& params) = 0;
virtual float get_max_transform() const = 0;
virtual const C3DBounds& get_size() const = 0;
virtual float pertuberate(C3DFVectorfield& v) const = 0;
virtual C3DFVector apply(const C3DFVector& x) const __attribute__((deprecated));
virtual C3DFVector get_displacement_at(const C3DFVector& x) const = 0;
virtual C3DFVector operator () (const C3DFVector& x) const = 0;
virtual float get_jacobian(const C3DFVectorfield& v, float delta) const = 0;
virtual bool refine();
void set_debug();
/* Attributes */
static constexpr const char *input_spacing_attr = "in-voxel-spacing";
static constexpr const char *output_spacing_attr = "out-voxel-spacing";
virtual C3DBounds get_minimal_supported_image_size() const;
protected:
bool get_debug()const;
private:
P3DImage do_transform(const C3DImage& input, const C3DInterpolatorFactory& ipf) const;
virtual P3DTransformation do_upscale(const C3DBounds& size) const = 0;
std::string m_creator_string;
virtual C3DTransformation *do_clone() const = 0;
bool m_debug;
};
EXPORT_3D bool operator != (const C3DTransformation::const_iterator& a,
const C3DTransformation::const_iterator& b);
NS_MIA_END
#endif
operator!=
bool operator!=(const C2DImage &a, const C2DImage &b)
Definition 2d/image.hh:413
image.hh
P3DImage
C3DImage::Pointer P3DImage
define a shortcut to the 3D image shared pointer.
Definition 3d/image.hh:135
interpolator.hh
matrix.hh
C3DFMatrix
T3DMatrix< float > C3DFMatrix
a simple 3x3 matrix with single precision floating point values
Definition 3d/matrix.hh:226
C3DBounds
T3DVector< unsigned int > C3DBounds
A unsinged int 3D Vector (used for 3D field sizes).
Definition 3d/vector.hh:415
C3DFVector
T3DVector< float > C3DFVector
A float 3D Vector.
Definition 3d/vector.hh:409
operator==
bool operator==(const CAttribute &a, const CAttribute &b)
Definition attributes.hh:95
C3DFVectorfield
a 3D field of floating point single accuracy 3D vectors
Definition 3d/vectorfield.hh:103
C3DImage
The generic base type of a 3D image.
Definition 3d/image.hh:47
C3DInterpolatorFactory
A factory to create interpolators of a given type by providing input data.
Definition 3d/interpolator.hh:175
C3DTransformation::const_iterator
Definition 3d/transform.hh:135
C3DTransformation::const_iterator::const_iterator
const_iterator()
C3DTransformation::const_iterator::pos
const C3DBounds & pos() const
return the current position in 3D space
C3DTransformation::const_iterator::const_iterator
const_iterator(iterator_impl *holder)
initialize the iterator with the actual worker object
C3DTransformation::const_iterator::get_size
const C3DBounds & get_size() const
C3DTransformation::const_iterator::const_iterator
const_iterator(const const_iterator &other)
Copy constructor.
C3DTransformation::iterator_impl
Definition 3d/transform.hh:71
C3DTransformation::iterator_impl::get_pos
const C3DBounds & get_pos() const
C3DTransformation::iterator_impl::iterator_impl
iterator_impl()
C3DTransformation::iterator_impl::clone
virtual iterator_impl * clone() const __attribute__((warn_unused_result))=0
C3DTransformation::iterator_impl::get_size
const C3DBounds & get_size() const
C3DTransformation::iterator_impl::get_value
const C3DFVector & get_value() const
C3DTransformation::iterator_impl::increment
void increment()
move to next position
C3DTransformation::iterator_impl::iterator_impl
iterator_impl(const C3DBounds &pos, const C3DBounds &begin, const C3DBounds &end, const C3DBounds &size)
C3DTransformation::iterator_impl::iterator_impl
iterator_impl(const C3DBounds &pos, const C3DBounds &size)
C3DTransformation
This is the generic base class for 3D transformations.
Definition 3d/transform.hh:54
C3DTransformation::output_spacing_attr
static constexpr const char * output_spacing_attr
Definition 3d/transform.hh:372
C3DTransformation::input_spacing_attr
static constexpr const char * input_spacing_attr
Definition 3d/transform.hh:367
C3DTransformation::get_jacobian
virtual float get_jacobian(const C3DFVectorfield &v, float delta) const =0
C3DTransformation::C3DTransformation
C3DTransformation(const C3DInterpolatorFactory &ipf)
C3DTransformation::apply
virtual C3DFVector apply(const C3DFVector &x) const __attribute__((deprecated))
C3DTransformation::update
virtual void update(float step, const C3DFVectorfield &a)=0
C3DTransformation::pertuberate
virtual float pertuberate(C3DFVectorfield &v) const =0
C3DTransformation::set_parameters
virtual void set_parameters(const CDoubleVector &params)=0
C3DTransformation::begin
virtual const_iterator begin() const =0
C3DTransformation::get_max_transform
virtual float get_max_transform() const =0
C3DTransformation::upscale
P3DTransformation upscale(const C3DBounds &size) const
C3DTransformation::set_creator_string
void set_creator_string(const std::string &s)
C3DTransformation::get_minimal_supported_image_size
virtual C3DBounds get_minimal_supported_image_size() const
C3DTransformation::invert
virtual C3DTransformation * invert() const =0
C3DTransformation::set_identity
virtual void set_identity()=0
C3DTransformation::derivative_at
virtual C3DFMatrix derivative_at(int x, int y, int z) const =0
C3DTransformation::refine
virtual bool refine()
C3DTransformation::derivative_at
virtual C3DFMatrix derivative_at(const C3DFVector &x) const =0
C3DTransformation::set_debug
void set_debug()
C3DTransformation::reinit
virtual void reinit() const
C3DTransformation::get_parameters
virtual CDoubleVector get_parameters() const =0
C3DTransformation::degrees_of_freedom
virtual size_t degrees_of_freedom() const =0
C3DTransformation::get_debug
bool get_debug() const
C3DTransformation::translate
virtual void translate(const C3DFVectorfield &gradient, CDoubleVector &params) const =0
C3DTransformation::get_creator_string
const std::string & get_creator_string() const
C3DTransformation::end
virtual const_iterator end() const =0
C3DTransformation::get_size
virtual const C3DBounds & get_size() const =0
C3DTransformation::end_range
virtual const_iterator end_range(const C3DBounds &begin, const C3DBounds &end) const =0
C3DTransformation::begin_range
virtual const_iterator begin_range(const C3DBounds &begin, const C3DBounds &end) const =0
C3DTransformation::clone
virtual C3DTransformation * clone() const
C3DTransformation::get_displacement_at
virtual C3DFVector get_displacement_at(const C3DFVector &x) const =0
type
Pointer
Size
Transformation< C3DImage, C3DInterpolatorFactory >::InterpolatorFactory
C3DInterpolatorFactory InterpolatorFactory
Definition transformation.hh:57
Transformation< C3DImage, C3DInterpolatorFactory >::Transformation
Transformation(const C3DInterpolatorFactory &ipf)
Definition transformation.hh:128
Transformation< C3DImage, C3DInterpolatorFactory >::Data
C3DImage Data
Definition transformation.hh:54
CCmdOptionFlags::input
@ input
Definition cmdoptionflags.hh:31
filter.hh
vector.hh
EXPORT_3D
#define EXPORT_3D
Definition defines3d.hh:45
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
CDoubleVector
TCArrayWrapper< double > CDoubleVector
Definition core/vector.hh:266
P3DTransformation
std::shared_ptr< C3DTransformation > P3DTransformation
pointer type for a 3D transformation
Definition 3d/transform.hh:43
std
Definition gsl_iterator.hh:324
operator*
F operator*(const typename TSparseSolver< F >::A_mult_x &A, const F &x)
Definition sparse_solver.hh:182
transformation.hh