2d/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_2d_transform_hh
#define mia_2d_transform_hh
#include <iterator>
#include <memory>
#include <ostream>
#include <mia/core/transformation.hh>
#include <mia/core/filter.hh>
#include <mia/2d/matrix.hh>
#include <mia/2d/image.hh>
#include <mia/2d/interpolator.hh>
NS_MIA_BEGIN
class EXPORT_2D C2DTransformation: public Transformation<C2DImage, C2DInterpolatorFactory>
{
public:
typedef C2DImage Data;
typedef C2DBounds Size;
typedef C2DFVector Vector;
typedef C2DInterpolatorFactory InterpolatorFactory;
typedef C2DTransformation type;
typedef std::shared_ptr<C2DTransformation > Pointer;
static const char *data_descr;
static const char *dim_descr;
protected:
class iterator_impl
{
public:
iterator_impl();
iterator_impl(const C2DBounds& pos, const C2DBounds& size);
void increment();
void advance(unsigned int delta);
const C2DFVector& get_value() const;
virtual iterator_impl *clone() const __attribute__((warn_unused_result)) = 0;
bool operator == (const iterator_impl& other) const;
const C2DBounds& get_pos()const;
const C2DBounds& get_size()const;
void print(std::ostream& os) const;
private:
virtual const C2DFVector& do_get_value()const = 0;
virtual void do_y_increment() = 0;
virtual void do_x_increment() = 0;
C2DBounds m_pos;
C2DBounds m_size;
};
public:
class const_iterator : public std::forward_iterator_tag
{
public:
typedef std::forward_iterator_tag iterator_category;
typedef C2DFVector value_type;
typedef size_t difference_type;
typedef C2DFVector *pointer;
typedef C2DFVector& reference;
const_iterator();
const_iterator(iterator_impl *holder);
const_iterator& operator = (const const_iterator& other);
const_iterator(const const_iterator& other);
const_iterator& operator ++();
const_iterator operator ++(int);
const_iterator& operator += (unsigned int delta);
const C2DFVector& operator *() const;
const C2DFVector *operator ->() const;
const C2DBounds& pos() const;
const C2DBounds& get_size() const;
void print(std::ostream& os) const;
private:
std::unique_ptr<iterator_impl> m_holder;
friend EXPORT_2D bool operator == (const C2DTransformation::const_iterator& a,
const C2DTransformation::const_iterator& b);
};
using Transformation<C2DImage, C2DInterpolatorFactory>::operator ();
C2DTransformation(const C2DInterpolatorFactory& ipf);
void set_creator_string(const std::string& s);
const std::string& get_creator_string()const;
virtual C2DTransformation *clone() const __attribute__((warn_unused_result));
virtual C2DTransformation *invert() const __attribute__((warn_unused_result)) = 0;
virtual const_iterator begin() const = 0;
virtual const_iterator end() const = 0;
Pointer upscale(const C2DBounds& size) const;
virtual void update(float step, const C2DFVectorfield& a) = 0;
virtual size_t degrees_of_freedom() const = 0;
virtual void set_identity() = 0;
virtual C2DFMatrix derivative_at(const C2DFVector& x) const = 0;
virtual C2DFMatrix derivative_at(int x, int y) const = 0;
virtual void translate(const C2DFVectorfield& 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 C2DBounds& get_size() const = 0;
virtual float pertuberate(C2DFVectorfield& v) const = 0;
virtual C2DFVector apply(const C2DFVector& x) const __attribute__((deprecated))
{
return get_displacement_at(x);
}
virtual C2DFVector get_displacement_at(const C2DFVector& x) const = 0;
virtual C2DFVector operator () (const C2DFVector& x) const = 0;
virtual float get_jacobian(const C2DFVectorfield& v, float delta) const = 0;
virtual bool refine();
/* Attributes */
static constexpr const char *input_spacing_attr = "in-pixel-spacing";
static constexpr const char *output_spacing_attr = "out-pixel-spacing";
virtual C2DBounds get_minimal_supported_image_size() const;
private:
virtual Pointer do_upscale(const C2DBounds& size) const = 0;
std::string m_creator_string;
virtual C2DTransformation *do_clone() const __attribute__((warn_unused_result)) = 0;
P2DImage do_transform(const C2DImage& input, const C2DInterpolatorFactory& ipf) const;
};
typedef C2DTransformation::Pointer P2DTransformation;
inline C2DTransformation::const_iterator operator + (C2DTransformation::const_iterator i, size_t delta)
{
i += delta;
return i;
}
inline std::ostream& operator << (std::ostream& os,
const C2DTransformation::const_iterator& i)
{
i.print(os);
return os;
}
EXPORT_2D bool operator != (const C2DTransformation::const_iterator& a,
const C2DTransformation::const_iterator& b);
NS_MIA_END
#endif
image.hh
P2DImage
C2DImage::Pointer P2DImage
Shared pointer representation of the 2D Image.
Definition 2d/image.hh:120
operator!=
bool operator!=(const C2DImage &a, const C2DImage &b)
Definition 2d/image.hh:413
interpolator.hh
matrix.hh
C2DFMatrix
T2DMatrix< float > C2DFMatrix
a simple 2x2 matrix
Definition 2d/matrix.hh:153
C2DBounds
T2DVector< unsigned int > C2DBounds
unsigned int valued 2D vector - used as 2D size parameter
Definition 2d/vector.hh:540
C2DFVector
T2DVector< float > C2DFVector
float valued 2D vector
Definition 2d/vector.hh:534
operator+=
EXPORT_2D C2DFVectorfield & operator+=(C2DFVectorfield &a, const C2DFVectorfield &b)
operator==
bool operator==(const CAttribute &a, const CAttribute &b)
Definition attributes.hh:95
operator<<
std::ostream & operator<<(std::ostream &os, const CAttribute &attr)
Definition attributes.hh:89
C2DFVectorfield
a 2D field of floating point single accuracy 2D vectors
Definition 2d/vectorfield.hh:80
C2DImage
This is the base class for 2D images that can hold generic pixel data.
Definition 2d/image.hh:48
C2DInterpolatorFactory
The factory to create an interpolator from some input data.
Definition 2d/interpolator.hh:190
C2DTransformation::const_iterator
Definition 2d/transform.hh:143
C2DTransformation::const_iterator::pos
const C2DBounds & pos() const
C2DTransformation::const_iterator::reference
C2DFVector & reference
generic name for the reference type of this iterator
Definition 2d/transform.hh:159
C2DTransformation::const_iterator::iterator_category
std::forward_iterator_tag iterator_category
provide the STL with some typedef fro traits
Definition 2d/transform.hh:147
C2DTransformation::const_iterator::value_type
C2DFVector value_type
generic name for the value type of this iterator
Definition 2d/transform.hh:150
C2DTransformation::const_iterator::get_size
const C2DBounds & get_size() const
C2DTransformation::const_iterator::const_iterator
const_iterator(iterator_impl *holder)
C2DTransformation::const_iterator::difference_type
size_t difference_type
generic name for the difference type of this iterator
Definition 2d/transform.hh:153
C2DTransformation::const_iterator::const_iterator
const_iterator(const const_iterator &other)
C2DTransformation::const_iterator::print
void print(std::ostream &os) const
C2DTransformation::const_iterator::const_iterator
const_iterator()
C2DTransformation::const_iterator::pointer
C2DFVector * pointer
generic name for the pointer type of this iterator
Definition 2d/transform.hh:156
C2DTransformation::iterator_impl
Base of the implementation of an iterator over the transformation domain This iterator takes care of ...
Definition 2d/transform.hh:81
C2DTransformation::iterator_impl::get_pos
const C2DBounds & get_pos() const
C2DTransformation::iterator_impl::get_value
const C2DFVector & get_value() const
C2DTransformation::iterator_impl::clone
virtual iterator_impl * clone() const __attribute__((warn_unused_result))=0
C2DTransformation::iterator_impl::advance
void advance(unsigned int delta)
fast advance the position
C2DTransformation::iterator_impl::get_size
const C2DBounds & get_size() const
C2DTransformation::iterator_impl::print
void print(std::ostream &os) const
C2DTransformation::iterator_impl::iterator_impl
iterator_impl(const C2DBounds &pos, const C2DBounds &size)
C2DTransformation::iterator_impl::iterator_impl
iterator_impl()
C2DTransformation::iterator_impl::increment
void increment()
increment the position
C2DTransformation
This is the generic base class for 2D transformations.
Definition 2d/transform.hh:46
C2DTransformation::Vector
C2DFVector Vector
generic name for the vector type used by this transformation
Definition 2d/transform.hh:55
C2DTransformation::get_max_transform
virtual float get_max_transform() const =0
C2DTransformation::begin
virtual const_iterator begin() const =0
C2DTransformation::get_minimal_supported_image_size
virtual C2DBounds get_minimal_supported_image_size() const
C2DTransformation::derivative_at
virtual C2DFMatrix derivative_at(const C2DFVector &x) const =0
C2DTransformation::translate
virtual void translate(const C2DFVectorfield &gradient, CDoubleVector &params) const =0
C2DTransformation::input_spacing_attr
static constexpr const char * input_spacing_attr
Definition 2d/transform.hh:378
C2DTransformation::data_descr
static const char * data_descr
plug-in search path element "type"
Definition 2d/transform.hh:67
C2DTransformation::set_creator_string
void set_creator_string(const std::string &s)
C2DTransformation::get_displacement_at
virtual C2DFVector get_displacement_at(const C2DFVector &x) const =0
C2DTransformation::get_size
virtual const C2DBounds & get_size() const =0
C2DTransformation::Pointer
std::shared_ptr< C2DTransformation > Pointer
pointer type of this transformation
Definition 2d/transform.hh:64
C2DTransformation::end
virtual const_iterator end() const =0
C2DTransformation::Size
C2DBounds Size
generic name for the size type used by this transformation
Definition 2d/transform.hh:52
C2DTransformation::refine
virtual bool refine()
C2DTransformation::InterpolatorFactory
C2DInterpolatorFactory InterpolatorFactory
generic name for the interpolation factory used by this transformation
Definition 2d/transform.hh:58
C2DTransformation::update
virtual void update(float step, const C2DFVectorfield &a)=0
C2DTransformation::apply
virtual C2DFVector apply(const C2DFVector &x) const __attribute__((deprecated))
Definition 2d/transform.hh:344
C2DTransformation::get_parameters
virtual CDoubleVector get_parameters() const =0
C2DTransformation::dim_descr
static const char * dim_descr
plug-in search path element "data"
Definition 2d/transform.hh:70
C2DTransformation::pertuberate
virtual float pertuberate(C2DFVectorfield &v) const =0
C2DTransformation::output_spacing_attr
static constexpr const char * output_spacing_attr
Definition 2d/transform.hh:383
C2DTransformation::set_identity
virtual void set_identity()=0
C2DTransformation::degrees_of_freedom
virtual size_t degrees_of_freedom() const =0
C2DTransformation::C2DTransformation
C2DTransformation(const C2DInterpolatorFactory &ipf)
C2DTransformation::get_creator_string
const std::string & get_creator_string() const
C2DTransformation::clone
virtual C2DTransformation * clone() const __attribute__((warn_unused_result))
C2DTransformation::Data
C2DImage Data
generic name for the data used by this transformation
Definition 2d/transform.hh:49
C2DTransformation::type
C2DTransformation type
generic name for this transformation type
Definition 2d/transform.hh:61
C2DTransformation::invert
virtual C2DTransformation * invert() const __attribute__((warn_unused_result))=0
C2DTransformation::upscale
Pointer upscale(const C2DBounds &size) const
C2DTransformation::get_jacobian
virtual float get_jacobian(const C2DFVectorfield &v, float delta) const =0
C2DTransformation::set_parameters
virtual void set_parameters(const CDoubleVector &params)=0
Pointer
const_iterator
Transformation< C2DImage, C2DInterpolatorFactory >::Transformation
Transformation(const C2DInterpolatorFactory &ipf)
Definition transformation.hh:128
CCmdOptionFlags::input
@ input
Definition cmdoptionflags.hh:31
filter.hh
EXPORT_2D
#define EXPORT_2D
Definition defines2d.hh:37
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
P2DTransformation
C2DTransformation::Pointer P2DTransformation
Pointer type for the 2D transformation.
Definition 2d/transform.hh:409
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