transformation.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_core_transformation_hh
#define mia_core_transformation_hh
#include <mia/core/iodata.hh>
#include <mia/core/attributes.hh>
#include <mia/core/vector.hh>
NS_MIA_BEGIN
template <typename D, typename I>
class Transformation : public CIOData, public CAttributedData
{
public:
static const char *type_descr;
virtual ~Transformation();
typedef D Data;
typedef I InterpolatorFactory;
Transformation(const I& ipf);
std::shared_ptr<D> operator () (const D& input) const;
std::shared_ptr<D> operator () (const D& input, const I& ipf_override) const;
void set_interpolator_factory(const I& ipf);
double get_energy_penalty_and_gradient(CDoubleVector& gradient) const;
double get_energy_penalty() const;
bool has_energy_penalty() const;
protected:
const I& get_interpolator_factory() const;
private:
virtual std::shared_ptr<D> do_transform(const D& input, const I& ipf) const = 0;
virtual double do_get_energy_penalty_and_gradient(CDoubleVector& gradient) const;
virtual double do_get_energy_penalty() const;
virtual bool do_has_energy_penalty() const;
I m_ipf;
};
template <typename T>
T load_transform(const std::string& MIA_PARAM_UNUSED(file))
{
static_assert(sizeof(T) == 0, "this needs to specialized for the handled type");
}
// implementation
template <typename D, typename I>
Transformation<D, I>::Transformation(const I& ipf):
m_ipf(ipf)
{
}
template <typename D, typename I>
Transformation<D, I>::~Transformation()
{
}
template <typename D, typename I>
void Transformation<D, I>::set_interpolator_factory(const I& ipf)
{
m_ipf = ipf;
}
template <typename D, typename I>
const I& Transformation<D, I>::get_interpolator_factory() const
{
return m_ipf;
}
template <typename D, typename I>
std::shared_ptr<D> Transformation<D, I>::operator () (const D& input, const I& ipf_override) const
{
return do_transform(input, ipf_override);
}
template <typename D, typename I>
std::shared_ptr<D > Transformation<D, I>::operator() (const D& input) const
{
return do_transform(input, m_ipf);
}
template <typename D, typename I>
double Transformation<D, I>::get_energy_penalty_and_gradient(CDoubleVector& gradient) const
{
return do_get_energy_penalty_and_gradient(gradient);
}
template <typename D, typename I>
double Transformation<D, I>::get_energy_penalty() const
{
return do_get_energy_penalty();
}
template <typename D, typename I>
double Transformation<D, I>::do_get_energy_penalty_and_gradient(CDoubleVector& gradient) const
{
std::fill(gradient.begin(), gradient.end(), 0.0);
return 0.0;
}
template <typename D, typename I>
double Transformation<D, I>::do_get_energy_penalty() const
{
return 0.0;
}
template <typename D, typename I>
bool Transformation<D, I>::has_energy_penalty() const
{
return do_has_energy_penalty();
}
template <typename D, typename I>
bool Transformation<D, I>::do_has_energy_penalty() const
{
return false;
}
template <typename D, typename I>
const char *Transformation<D, I>::type_descr = "transform";
NS_MIA_END
#endif
attributes.hh
CAttributedData::CAttributedData
CAttributedData()
CIOData
helper class to derive from for data that can be loaded and stored to a disk.
Definition iodata.hh:37
TCArrayWrapper::end
iterator end()
Definition core/vector.hh:188
TCArrayWrapper::begin
iterator begin()
Definition core/vector.hh:176
Transformation::get_energy_penalty
double get_energy_penalty() const
Definition transformation.hh:170
Transformation::get_energy_penalty_and_gradient
double get_energy_penalty_and_gradient(CDoubleVector &gradient) const
Definition transformation.hh:163
Transformation::InterpolatorFactory
I InterpolatorFactory
type of the interpolator used by this transformation
Definition transformation.hh:57
Transformation::get_interpolator_factory
const I & get_interpolator_factory() const
Definition transformation.hh:145
Transformation::type_descr
static const char * type_descr
interface type for plugin implementation and search
Definition transformation.hh:49
Transformation::has_energy_penalty
bool has_energy_penalty() const
Definition transformation.hh:190
Transformation::set_interpolator_factory
void set_interpolator_factory(const I &ipf)
Definition transformation.hh:139
Transformation::~Transformation
virtual ~Transformation()
Definition transformation.hh:134
Transformation::Transformation
Transformation(const I &ipf)
Definition transformation.hh:128
Transformation::Data
D Data
typedef for the data type to be transformed by this transformation
Definition transformation.hh:54
Transformation::operator()
std::shared_ptr< D > operator()(const D &input) const
Definition transformation.hh:157
CCmdOptionFlags::input
@ input
Definition cmdoptionflags.hh:31
vector.hh
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
load_transform
T load_transform(const std::string &MIA_PARAM_UNUSED(file))
template to unify transformation loading
Definition transformation.hh:121
CDoubleVector
TCArrayWrapper< double > CDoubleVector
Definition core/vector.hh:266
iodata.hh