[go: up one dir, main page]

Menu

[r699]: / mia2 / mia / 2d / transform.cc  Maximize  Restore  History

Download this file

101 lines (80 with data), 2.8 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
/* -*- mia-c++ -*-
*
* Copyright (c) 2007 Gert Wollny <gert dot wollny at acm dot org>
*
* This program 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 2 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 this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include <mia/2d/transform.hh>
#include <mia/2d/deformer.hh>
NS_MIA_BEGIN
C2DGridTransformation::C2DGridTransformation(const C2DBounds& size, P2DInterpolatorFactory ipf):
_M_field(size),
_M_ipf(ipf)
{
}
C2DFVectorfield& C2DGridTransformation::field()
{
return _M_field;
}
P2DInterpolatorFactory C2DGridTransformation::get_ipf()
{
return _M_ipf;
}
C2DGridTransformation& C2DGridTransformation::operator += (const C2DGridTransformation& other)
{
_M_field = (*this + other).field();
return *this;
}
C2DGridTransformation C2DGridTransformation::operator + (const C2DGridTransformation& other)
{
assert(_M_field.get_size() == other._M_field.get_size());
C2DGridTransformation tmp(_M_field.get_size(), _M_ipf);
C2DFVectorfield::iterator itmp = tmp._M_field.begin();
C2DFVectorfield::const_iterator ib = other._M_field.begin();
for (size_t y = 0; y < _M_field.get_size().y; ++y) {
for (size_t x = 0; x < _M_field.get_size().x; ++x, ++itmp, ++ib) {
C2DFVector xi = C2DFVector(x, y) - *ib;
*itmp = _M_field.get_interpol_val_at(xi) + *ib;
}
}
return tmp;
}
void C2DGridTransformation::apply(const C2DImage& input, C2DImage& output) const
{
FDeformer2D deformer(_M_field, *_M_ipf);
output = *mia::filter(deformer, input);
}
C2DGridTransformation C2DGridTransformation::upscale(const C2DBounds& size)
{
C2DGridTransformation result(size, _M_ipf);
// initial upscale
if (_M_field.get_size().x == 0 || _M_field.get_size().y == 0)
return result;
float x_mult = float(size.x) / (float)_M_field.get_size().x;
float y_mult = float(size.y) / (float)_M_field.get_size().y;
float ix_mult = 1.0f / x_mult;
float iy_mult = 1.0f / y_mult;
C2DFVectorfield::iterator i = result._M_field.begin();
for (unsigned int y = 0; y < size.y; y++){
for (unsigned int x = 0; x < size.x; x++,++i){
C2DFVector help(ix_mult * x, iy_mult * y);
C2DFVector val = _M_field.get_interpol_val_at(help);
*i = C2DFVector(val.x * x_mult,val.y * y_mult);
}
}
return result;
}
NS_MIA_END