My Project
transformation.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
22#ifndef mia_core_transformation_hh
23#define mia_core_transformation_hh
24
25#include <mia/core/iodata.hh>
27#include <mia/core/vector.hh>
28
30
31
43template <typename D, typename I>
45{
46public:
47
49 static const char *type_descr;
50
51 virtual ~Transformation();
52
54 typedef D Data;
55
58
63 Transformation(const I& ipf);
64
69 std::shared_ptr<D> operator () (const D& input) const;
70
76 std::shared_ptr<D> operator () (const D& input, const I& ipf_override) const;
77
82 void set_interpolator_factory(const I& ipf);
83
84
93
95 double get_energy_penalty() const;
96
98 bool has_energy_penalty() const;
99protected:
100
102 const I& get_interpolator_factory() const;
103private:
104 virtual std::shared_ptr<D> do_transform(const D& input, const I& ipf) const = 0;
105 virtual double do_get_energy_penalty_and_gradient(CDoubleVector& gradient) const;
106 virtual double do_get_energy_penalty() const;
107 virtual bool do_has_energy_penalty() const;
108
109 I m_ipf;
110
111};
112
120template <typename T>
121T load_transform(const std::string& MIA_PARAM_UNUSED(file))
122{
123 static_assert(sizeof(T) == 0, "this needs to specialized for the handled type");
124}
125
126// implementation
127template <typename D, typename I>
129 m_ipf(ipf)
130{
131}
132
133template <typename D, typename I>
137
138template <typename D, typename I>
140{
141 m_ipf = ipf;
142}
143
144template <typename D, typename I>
146{
147 return m_ipf;
148}
149
150template <typename D, typename I>
151std::shared_ptr<D> Transformation<D, I>::operator () (const D& input, const I& ipf_override) const
152{
153 return do_transform(input, ipf_override);
154}
155
156template <typename D, typename I>
157std::shared_ptr<D > Transformation<D, I>::operator() (const D& input) const
158{
159 return do_transform(input, m_ipf);
160}
161
162template <typename D, typename I>
164{
165 return do_get_energy_penalty_and_gradient(gradient);
166}
167
168
169template <typename D, typename I>
171{
172 return do_get_energy_penalty();
173}
174
175template <typename D, typename I>
177{
178 std::fill(gradient.begin(), gradient.end(), 0.0);
179 return 0.0;
180}
181
182
183template <typename D, typename I>
185{
186 return 0.0;
187}
188
189template <typename D, typename I>
191{
192 return do_has_energy_penalty();
193}
194
195
196template <typename D, typename I>
198{
199 return false;
200}
201
202template <typename D, typename I>
203const char *Transformation<D, I>::type_descr = "transform";
204
206
207
208#endif
A collection of attributes.
helper class to derive from for data that can be loaded and stored to a disk.
Definition iodata.hh:37
A wrapper around the c-array to provide an STL like interface for iterators.
iterator end()
iterator begin()
generic base class for transformations
double get_energy_penalty() const
double get_energy_penalty_and_gradient(CDoubleVector &gradient) const
I InterpolatorFactory
type of the interpolator used by this transformation
const I & get_interpolator_factory() const
static const char * type_descr
interface type for plugin implementation and search
bool has_energy_penalty() const
void set_interpolator_factory(const I &ipf)
virtual ~Transformation()
Transformation(const I &ipf)
D Data
typedef for the data type to be transformed by this transformation
std::shared_ptr< D > operator()(const D &input) const
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition defines.hh:33
#define NS_MIA_END
conveniance define to end the mia namespace
Definition defines.hh:36
T load_transform(const std::string &file)
template to unify transformation loading