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>
26 #include <mia/core/attributes.hh>
27 #include <mia/core/vector.hh>
28 
30 
31 
43 template <typename D, typename I>
44 class Transformation :public CIOData, public CAttributedData {
45 public:
46 
48  static const char *type_descr;
49 
50  virtual ~Transformation();
51 
53  typedef D Data;
54 
56  typedef I InterpolatorFactory;
57 
62  Transformation(const I& ipf);
63 
68  std::shared_ptr<D> operator () (const D& input) const;
69 
75  std::shared_ptr<D> operator () (const D& input, const I& ipf_override) const;
76 
81  void set_interpolator_factory(const I& ipf);
82 
83 
91  double get_energy_penalty_and_gradient(CDoubleVector& gradient) const;
92 
94  double get_energy_penalty() const;
95 
97  bool has_energy_penalty() const;
98 protected:
99 
101  const I& get_interpolator_factory() const;
102 private:
103  virtual std::shared_ptr<D> do_transform(const D& input, const I& ipf) const = 0;
104  virtual double do_get_energy_penalty_and_gradient(CDoubleVector& gradient) const;
105  virtual double do_get_energy_penalty() const;
106  virtual bool do_has_energy_penalty() const;
107 
108  I m_ipf;
109 
110 };
111 
119 template <typename T>
120 T load_transform(const std::string& MIA_PARAM_UNUSED(file)) {
121  static_assert(sizeof(T) == 0, "this needs to specialized for the handled type");
122 }
123 
124 // implementation
125 template <typename D, typename I>
127  m_ipf(ipf)
128 {
129 
130 }
131 
132 template <typename D, typename I>
134 {
135 }
136 
137 template <typename D, typename I>
139 {
140  m_ipf = ipf;
141 }
142 
143 template <typename D, typename I>
145 {
146  return m_ipf;
147 }
148 
149 template <typename D, typename I>
150 std::shared_ptr<D> Transformation<D,I>::operator () (const D& input, const I& ipf_override) const
151 {
152  return do_transform(input, ipf_override);
153 }
154 
155 template <typename D, typename I>
156 std::shared_ptr<D > Transformation<D,I>::operator() (const D& input) const
157 {
158  return do_transform(input, m_ipf);
159 }
160 
161 template <typename D, typename I>
163 {
164  return do_get_energy_penalty_and_gradient(gradient);
165 }
166 
167 
168 template <typename D, typename I>
170 {
171  return do_get_energy_penalty();
172 }
173 
174 template <typename D, typename I>
176 {
177  std::fill(gradient.begin(), gradient.end(), 0.0);
178  return 0.0;
179 }
180 
181 
182 template <typename D, typename I>
184 {
185  return 0.0;
186 }
187 
188 template <typename D, typename I>
190 {
191  return do_has_energy_penalty();
192 }
193 
194 
195 template <typename D, typename I>
197 {
198  return false;
199 }
200 
201 template <typename D, typename I>
202 const char *Transformation<D, I>::type_descr = "transform";
203 
205 
206 
207 #endif
I InterpolatorFactory
type of the interpolator used by this transformation
iterator begin()
Definition: core/vector.hh:171
std::shared_ptr< D > operator()(const D &input) const
A wrapper around the c-array to provide an STL like interface for iterators.
Definition: core/vector.hh:75
const I & get_interpolator_factory() const
void set_interpolator_factory(const I &ipf)
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition: defines.hh:33
A collection of attributes.
Definition: attributes.hh:255
double get_energy_penalty_and_gradient(CDoubleVector &gradient) const
generic base class for transformations
T load_transform(const std::string &file)
template to unify transformation loading
helper class to derive from for data that can be loaded and stored to a disk.
Definition: iodata.hh:36
double get_energy_penalty() const
iterator end()
Definition: core/vector.hh:182
bool has_energy_penalty() const
Transformation(const I &ipf)
static const char * type_descr
interface type for plugin implementation and search
D Data
typedef for the data type to be transformed by this transformation
virtual ~Transformation()
#define NS_MIA_END
conveniance define to end the mia namespace
Definition: defines.hh:36