My Project
2d/transform.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#ifndef mia_2d_transform_hh
22#define mia_2d_transform_hh
23
24#include <iterator>
25#include <memory>
26#include <ostream>
27
29#include <mia/core/filter.hh>
30#include <mia/2d/matrix.hh>
31#include <mia/2d/image.hh>
33
35
36
45class EXPORT_2D C2DTransformation: public Transformation<C2DImage, C2DInterpolatorFactory>
46{
47public:
49 typedef C2DImage Data;
50
52 typedef C2DBounds Size;
53
56
59
62
64 typedef std::shared_ptr<C2DTransformation > Pointer;
65
67 static const char *data_descr;
68
70 static const char *dim_descr;
71protected:
72
81 {
82 public:
84
92 iterator_impl(const C2DBounds& pos, const C2DBounds& size);
93
95 void increment();
96
98 void advance(unsigned int delta);
99
101 const C2DFVector& get_value() const;
102
104 virtual iterator_impl *clone() const __attribute__((warn_unused_result)) = 0;
105
112 bool operator == (const iterator_impl& other) const;
113
115 const C2DBounds& get_pos()const;
116
118 const C2DBounds& get_size()const;
119
125 void print(std::ostream& os) const;
126 private:
127 virtual const C2DFVector& do_get_value()const = 0;
128 virtual void do_y_increment() = 0;
129 virtual void do_x_increment() = 0;
130
131 C2DBounds m_pos;
132 C2DBounds m_size;
133
134 };
135public:
142 class const_iterator : public std::forward_iterator_tag
143 {
144 public:
145
147 typedef std::forward_iterator_tag iterator_category;
148
151
153 typedef size_t difference_type;
154
157
160
166
173
174
178 const_iterator& operator = (const const_iterator& other);
179
184
185
189 const_iterator& operator ++();
190
194 const_iterator operator ++(int);
195
202 const_iterator& operator += (unsigned int delta);
203
205 const C2DFVector& operator *() const;
206
208 const C2DFVector *operator ->() const;
209
210 const C2DBounds& pos() const;
211
212 const C2DBounds& get_size() const;
213
217 void print(std::ostream& os) const;
218 private:
219 std::unique_ptr<iterator_impl> m_holder;
220
223
224 };
225
227
232
237 void set_creator_string(const std::string& s);
238
240 const std::string& get_creator_string()const;
241
245 virtual C2DTransformation *clone() const __attribute__((warn_unused_result));
246
250 virtual C2DTransformation *invert() const __attribute__((warn_unused_result)) = 0;
251
256 virtual const_iterator begin() const = 0;
257
263 virtual const_iterator end() const = 0;
264
270 Pointer upscale(const C2DBounds& size) const;
271
276 virtual void update(float step, const C2DFVectorfield& a) = 0;
277
281 virtual size_t degrees_of_freedom() const = 0;
282
286 virtual void set_identity() = 0;
287
294 virtual C2DFMatrix derivative_at(const C2DFVector& x) const = 0;
295
303 virtual C2DFMatrix derivative_at(int x, int y) const = 0;
304
309 virtual void translate(const C2DFVectorfield& gradient, CDoubleVector& params) const = 0;
310
314 virtual CDoubleVector get_parameters() const = 0;
315
319 virtual void set_parameters(const CDoubleVector& params) = 0;
320
324 virtual float get_max_transform() const = 0;
325
330 virtual const C2DBounds& get_size() const = 0;
331
338 virtual float pertuberate(C2DFVectorfield& v) const = 0;
339
344 virtual C2DFVector apply(const C2DFVector& x) const __attribute__((deprecated))
345 {
346 return get_displacement_at(x);
347 }
348
352 virtual C2DFVector get_displacement_at(const C2DFVector& x) const = 0;
357 virtual C2DFVector operator () (const C2DFVector& x) const = 0;
358
364 virtual float get_jacobian(const C2DFVectorfield& v, float delta) const = 0;
365
366
372 virtual bool refine();
373
374 /* Attributes */
378 static constexpr const char *input_spacing_attr = "in-pixel-spacing";
379
383 static constexpr const char *output_spacing_attr = "out-pixel-spacing";
384
385
392
393private:
394
395 virtual Pointer do_upscale(const C2DBounds& size) const = 0;
396
397 std::string m_creator_string;
398 virtual C2DTransformation *do_clone() const __attribute__((warn_unused_result)) = 0;
399
400
401 P2DImage do_transform(const C2DImage& input, const C2DInterpolatorFactory& ipf) const;
402
403};
404
410
411
412
418inline C2DTransformation::const_iterator operator + (C2DTransformation::const_iterator i, size_t delta)
419{
420 i += delta;
421 return i;
422}
423
430inline std::ostream& operator << (std::ostream& os,
432{
433 i.print(os);
434 return os;
435}
436
447
448
450
451#endif
C2DImage::Pointer P2DImage
Shared pointer representation of the 2D Image.
Definition: 2d/image.hh:120
std::ostream & operator<<(std::ostream &os, const C2DTransformation::const_iterator &i)
EXPORT_2D C2DFVectorfield & operator+=(C2DFVectorfield &a, const C2DFVectorfield &b)
bool operator==(const CAttribute &a, const CAttribute &b)
Definition: attributes.hh:95
a 2D field of floating point single accuracy 2D vectors
This is the base class for 2D images that can hold generic pixel data.
Definition: 2d/image.hh:48
The factory to create an interpolator from some input data.
const C2DBounds & pos() const
C2DFVector & reference
generic name for the reference type of this iterator
std::forward_iterator_tag iterator_category
provide the STL with some typedef fro traits
C2DFVector value_type
generic name for the value type of this iterator
const C2DBounds & get_size() const
const_iterator(iterator_impl *holder)
size_t difference_type
generic name for the difference type of this iterator
const_iterator(const const_iterator &other)
void print(std::ostream &os) const
C2DFVector * pointer
generic name for the pointer type of this iterator
Base of the implementation of an iterator over the transformation domain This iterator takes care of ...
Definition: 2d/transform.hh:81
const C2DFVector & get_value() const
virtual iterator_impl * clone() const __attribute__((warn_unused_result))=0
void advance(unsigned int delta)
fast advance the position
iterator_impl(const C2DBounds &pos, const C2DBounds &size)
void increment()
increment the position
This is the generic base class for 2D transformations.
Definition: 2d/transform.hh:46
C2DFVector Vector
generic name for the vector type used by this transformation
Definition: 2d/transform.hh:55
virtual C2DBounds get_minimal_supported_image_size() const
static const char * data_descr
plug-in search path element "type"
Definition: 2d/transform.hh:67
void set_creator_string(const std::string &s)
virtual C2DFVector get_displacement_at(const C2DFVector &x) const =0
std::shared_ptr< C2DTransformation > Pointer
pointer type of this transformation
Definition: 2d/transform.hh:64
C2DBounds Size
generic name for the size type used by this transformation
Definition: 2d/transform.hh:52
virtual bool refine()
C2DInterpolatorFactory InterpolatorFactory
generic name for the interpolation factory used by this transformation
Definition: 2d/transform.hh:58
static const char * dim_descr
plug-in search path element "data"
Definition: 2d/transform.hh:70
C2DTransformation(const C2DInterpolatorFactory &ipf)
const std::string & get_creator_string() const
virtual C2DTransformation * clone() const __attribute__((warn_unused_result))
C2DImage Data
generic name for the data used by this transformation
Definition: 2d/transform.hh:49
C2DTransformation type
generic name for this transformation type
Definition: 2d/transform.hh:61
virtual float get_jacobian(const C2DFVectorfield &v, float delta) const =0
A wrapper around the c-array to provide an STL like interface for iterators.
Definition: core/vector.hh:78
generic base class for transformations
#define EXPORT_2D
Definition: defines2d.hh:37
#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
EXPORT_2D bool operator!=(const C2DTransformation::const_iterator &a, const C2DTransformation::const_iterator &b)
Compare two transformation iterators.
C2DTransformation::Pointer P2DTransformation
Pointer type for the 2D transformation.
Matrix EXPORT_GSL operator*(const Matrix &lhs, const Matrix &rhs)
A simple 2x2 matrix.
Definition: 2d/matrix.hh:36