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>
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 {
46 public:
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 
92  double get_energy_penalty_and_gradient(CDoubleVector& gradient) const;
93 
95  double get_energy_penalty() const;
96 
98  bool has_energy_penalty() const;
99 protected:
100 
102  const I& get_interpolator_factory() const;
103 private:
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 
120 template <typename T>
121 T 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
127 template <typename D, typename I>
129  m_ipf(ipf)
130 {
131 }
132 
133 template <typename D, typename I>
135 {
136 }
137 
138 template <typename D, typename I>
140 {
141  m_ipf = ipf;
142 }
143 
144 template <typename D, typename I>
146 {
147  return m_ipf;
148 }
149 
150 template <typename D, typename I>
151 std::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 
156 template <typename D, typename I>
157 std::shared_ptr<D > Transformation<D, I>::operator() (const D& input) const
158 {
159  return do_transform(input, m_ipf);
160 }
161 
162 template <typename D, typename I>
164 {
165  return do_get_energy_penalty_and_gradient(gradient);
166 }
167 
168 
169 template <typename D, typename I>
171 {
172  return do_get_energy_penalty();
173 }
174 
175 template <typename D, typename I>
177 {
178  std::fill(gradient.begin(), gradient.end(), 0.0);
179  return 0.0;
180 }
181 
182 
183 template <typename D, typename I>
185 {
186  return 0.0;
187 }
188 
189 template <typename D, typename I>
191 {
192  return do_has_energy_penalty();
193 }
194 
195 
196 template <typename D, typename I>
198 {
199  return false;
200 }
201 
202 template <typename D, typename I>
203 const char *Transformation<D, I>::type_descr = "transform";
204 
206 
207 
208 #endif
Transformation::get_energy_penalty_and_gradient
double get_energy_penalty_and_gradient(CDoubleVector &gradient) const
Definition: transformation.hh:163
iodata.hh
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
NS_MIA_BEGIN
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition: defines.hh:33
TCArrayWrapper::begin
iterator begin()
Definition: core/vector.hh:176
Transformation::get_energy_penalty
double get_energy_penalty() const
Definition: transformation.hh:170
Transformation
generic base class for transformations
Definition: transformation.hh:44
NS_MIA_END
#define NS_MIA_END
conveniance define to end the mia namespace
Definition: defines.hh:36
Transformation::~Transformation
virtual ~Transformation()
Definition: transformation.hh:134
Transformation::type_descr
static const char * type_descr
interface type for plugin implementation and search
Definition: transformation.hh:49
vector.hh
Transformation::operator()
std::shared_ptr< D > operator()(const D &input) const
Definition: transformation.hh:157
CAttributedData
A collection of attributes.
Definition: attributes.hh:259
Transformation::set_interpolator_factory
void set_interpolator_factory(const I &ipf)
Definition: transformation.hh:139
Transformation::has_energy_penalty
bool has_energy_penalty() const
Definition: transformation.hh:190
load_transform
T load_transform(const std::string &file)
template to unify transformation loading
Definition: transformation.hh:121
attributes.hh
CIOData
helper class to derive from for data that can be loaded and stored to a disk.
Definition: iodata.hh:36
TCArrayWrapper::end
iterator end()
Definition: core/vector.hh:188
TCArrayWrapper
A wrapper around the c-array to provide an STL like interface for iterators.
Definition: core/vector.hh:77
CCmdOptionFlags::input
@ input
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