[a5a76e]: src / hugin1 / tests / old / transforms.cpp  Maximize  Restore  History

Download this file

198 lines (170 with data), 6.5 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
// -*- c-basic-offset: 4 -*-
/** @file transforms.cpp
*
* @brief tests for transformations
*
* @author Pablo d'Angelo <pablo.dangelo@web.de>
*
* $Id: transforms.cpp 1810 2006-12-30 22:22:09Z dangelo $
*
* 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 software 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 software; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include <config.h>
#include <boost/test/unit_test.hpp>
#include <boost/test/floating_point_comparison.hpp>
#include "panoinc.h"
#include "PT/PanoToolsInterface.h"
using namespace boost::unit_test_framework;
using namespace std;
using namespace vigra;
using namespace PT;
void transforms_test()
{
int width = 2000;
int height = 2000;
VariableMap vars;
fillVariableMap(vars);
map_get(vars,"v").setValue(50.0);
map_get(vars,"a").setValue(0.0);
map_get(vars,"b").setValue(0.0);
map_get(vars,"c").setValue(0.0);
map_get(vars,"d").setValue(0.0);
map_get(vars,"e").setValue(0.0);
SpaceTransform trans;
PTools::Transform ptTrans;
trans.createTransform(Diff2D(width, height),
vars, Lens::RECTILINEAR,
Diff2D(360,180), PanoramaOptions::EQUIRECTANGULAR,
360);
ptTrans.createTransform(Diff2D(width, height),
vars, Lens::RECTILINEAR,
Diff2D(360,180), PanoramaOptions::EQUIRECTANGULAR,
360);
SpaceTransform invTrans;
PTools::Transform ptInvTrans;
invTrans.createInvTransform(Diff2D(width, height),
vars, Lens::RECTILINEAR,
Diff2D(360,180),
PanoramaOptions::EQUIRECTANGULAR,
360);
ptInvTrans.createInvTransform(Diff2D(width, height),
vars, Lens::RECTILINEAR,
Diff2D(360,180),
PanoramaOptions::EQUIRECTANGULAR,
360);
// set yaw and pitch
// transform from equirect into image
FDiff2D src(25.0,25.0);
FDiff2D dest;
FDiff2D ptdest;
std::cout << "erect: " << dest.x << "," << dest.y << std::endl;
trans.transform(dest,src);
ptTrans.transform(ptdest,src);
std::cout << "rect (img): " << dest << " pt: " << ptdest << std::endl;
BOOST_CHECK_CLOSE((double)ptdest.x, 1000.0, 1e-6);
BOOST_CHECK_CLOSE((double)ptdest.y, 1000.0, 1e-6);
BOOST_CHECK_CLOSE((double)ptdest.x, (double)dest.x, 1e-6);
BOOST_CHECK_CLOSE((double)ptdest.y, (double)dest.y, 1e-6);
src = ptdest;
// transfrom back to equirect
invTrans.transform(dest,src);
ptInvTrans.transform(ptdest,src);
std::cout << "erect (25,25): " << dest << " pt: " << ptdest << std::endl;
BOOST_CHECK_CLOSE((double)dest.x, 25.0, 1e-4);
BOOST_CHECK_CLOSE((double)dest.y, 25.0, 1e-4);
BOOST_CHECK_CLOSE((double)ptdest.x, (double)dest.x, 1e-6);
BOOST_CHECK_CLOSE((double)ptdest.y, (double)dest.y, 1e-6);
// transfrom back to equirect
trans.transform(dest,FDiff2D(0,0));
std::cout << "0, 0 -> img: " << dest.x << "," << dest.y << std::endl;
// transforms img -> dest
invTrans.transform(dest,FDiff2D(10,10));
std::cout << "10, 10 inv -> erect: " << dest.x << "," << dest.y << std::endl;
BOOST_CHECK_CLOSE((double)dest.x, 25.0, 1e-4);
BOOST_CHECK_CLOSE((double)dest.y, 25.0, 1e-4);
/*
PT::TRANSFORM::ERectToRect er2r(fl);
PT::TRANSFORM::RectToERect r2er(fl);
PT::TRANSFORM::RectToImg r2img(width, height);
PT::TRANSFORM::ImgToRect img2r(width, height);
double yaw=25;
double pitch=25;
// set yaw and pitch
FDiff2D dest(DEG_TO_RAD(yaw),DEG_TO_RAD(pitch));
std::cout << "erect: " << dest.x << "," << dest.y << std::endl;
er2r(dest,dest);
BOOST_CHECK_CLOSE((double)dest.x, 1000.0, 1e-6);
BOOST_CHECK_CLOSE((double)dest.y, 1000.0, 1e-6);
r2img(dest,dest);
std::cout << "rect (img): " << dest.x << "," << dest.y << std::endl;
BOOST_CHECK_CLOSE((double)dest.x, 2000.0, 1e-6);
BOOST_CHECK_CLOSE((double)dest.y, 0.0, 1e-6);
img2r(dest,dest);
std::cout << "rect (0,0=center): " << dest.x << "," << dest.y << std::endl;
BOOST_CHECK_CLOSE((double)dest.x, 1000.0, 1e-6);
BOOST_CHECK_CLOSE((double)dest.y, 1000.0, 1e-6);
r2er(dest,dest);
std::cout << "erect: " << dest.x << "," << dest.y << std::endl;
BOOST_CHECK_CLOSE(RAD_TO_DEG(dest.x), 25.0, 1e-4);
BOOST_CHECK_CLOSE(RAD_TO_DEG(dest.y), 25.0, 1e-4);
*/
}
void transform_img_test()
{
const int w=10;
const int h=10;
VariableMap vars;
fillVariableMap(vars);
map_get(vars,"v").setValue(50.0);
map_get(vars,"a").setValue(0.0);
map_get(vars,"b").setValue(0.0);
map_get(vars,"c").setValue(0.0);
map_get(vars,"d").setValue(0.0);
map_get(vars,"e").setValue(0.0);
SpaceTransform trans;
trans.createTransform(Diff2D(2*w, 2*h),
vars, Lens::RECTILINEAR,
Diff2D(w,h), PanoramaOptions::EQUIRECTANGULAR,
50);
cout.precision(2);
for (int x=0; x<w; x++) {
for (int y=0; y<h; y++) {
FDiff2D res;
double sx, sy;
trans.transform(res, FDiff2D(x,y));
cout << sx << "," << sy << " ";
}
cout << endl;
}
cout << endl;
cout << endl;
for (int x=0; x<w; x++) {
for (int y=0; y<h; y++) {
double sx, sy;
trans.transformImgCoord(sx, sy, x,y);
cout << sx << "," << sy << " ";
}
cout << endl;
}
}
test_suite*
init_unit_test_suite( int, char** )
{
test_suite* test= BOOST_TEST_SUITE( "transformation routine tests" );
test->add(BOOST_TEST_CASE(&transforms_test));
test->add(BOOST_TEST_CASE(&transform_img_test));
return test;
}

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks