27 #include <hugin_config.h>
40 namespace HuginBase {
namespace PTools {
53 const vigra::Diff2D & destSize,
55 const std::vector<double> & destProjParam,
65 srcVars, srcProj,
true);
74 if (srcSize.x == 0 && srcSize.y == 0) {
92 vars.insert(make_pair(std::string(
"v"),
Variable(std::string(
"v"), src.getHFOV())));
93 vars.insert(make_pair(std::string(
"a"),
Variable(
"a", src.getRadialDistortion()[0])));
94 vars.insert(make_pair(std::string(
"b"),
Variable(
"b", src.getRadialDistortion()[1])));
95 vars.insert(make_pair(std::string(
"c"),
Variable(
"c", src.getRadialDistortion()[2])));
96 vars.insert(make_pair(std::string(
"d"),
Variable(
"d", src.getRadialDistortionCenterShift().x)));
97 vars.insert(make_pair(std::string(
"e"),
Variable(
"e", src.getRadialDistortionCenterShift().y)));
98 vars.insert(make_pair(std::string(
"g"),
Variable(
"g", src.getShear().x)));
99 vars.insert(make_pair(std::string(
"t"),
Variable(
"t", src.getShear().y)));
101 vars.insert(make_pair(std::string(
"r"),
Variable(
"r", src.getRoll())));
102 vars.insert(make_pair(std::string(
"p"),
Variable(
"p", src.getPitch())));
103 vars.insert(make_pair(std::string(
"y"),
Variable(
"y", src.getYaw())));
105 vars.insert(make_pair(std::string(
"TrX"),
Variable(
"TrX", src.getX())));
106 vars.insert(make_pair(std::string(
"TrY"),
Variable(
"TrY", src.getY())));
107 vars.insert(make_pair(std::string(
"TrZ"),
Variable(
"TrZ", src.getZ())));
109 vars.insert(make_pair(std::string(
"Tpy"),
Variable(
"Tpy", src.getTranslationPlaneYaw())));
110 vars.insert(make_pair(std::string(
"Tpp"),
Variable(
"Tpp", src.getTranslationPlanePitch())));
127 vars.insert(make_pair(std::string(
"v"),
Variable(std::string(
"v"), src.getHFOV())));
128 vars.insert(make_pair(std::string(
"a"),
Variable(
"a", src.getRadialDistortion()[0])));
129 vars.insert(make_pair(std::string(
"b"),
Variable(
"b", src.getRadialDistortion()[1])));
130 vars.insert(make_pair(std::string(
"c"),
Variable(
"c", src.getRadialDistortion()[2])));
131 vars.insert(make_pair(std::string(
"d"),
Variable(
"d", src.getRadialDistortionCenterShift().x)));
132 vars.insert(make_pair(std::string(
"e"),
Variable(
"e", src.getRadialDistortionCenterShift().y)));
133 vars.insert(make_pair(std::string(
"g"),
Variable(
"g", src.getShear().x)));
134 vars.insert(make_pair(std::string(
"t"),
Variable(
"t", src.getShear().y)));
136 vars.insert(make_pair(std::string(
"r"),
Variable(
"r", src.getRoll())));
137 vars.insert(make_pair(std::string(
"p"),
Variable(
"p", src.getPitch())));
138 vars.insert(make_pair(std::string(
"y"),
Variable(
"y", src.getYaw())));
140 vars.insert(make_pair(std::string(
"TrX"),
Variable(
"TrX", src.getX())));
141 vars.insert(make_pair(std::string(
"TrY"),
Variable(
"TrY", src.getY())));
142 vars.insert(make_pair(std::string(
"TrZ"),
Variable(
"TrZ", src.getZ())));
144 vars.insert(make_pair(std::string(
"Tpy"),
Variable(
"Tpy", src.getTranslationPlaneYaw())));
145 vars.insert(make_pair(std::string(
"Tpp"),
Variable(
"Tpp", src.getTranslationPlanePitch())));
161 const vigra::Diff2D &destSize,
163 const std::vector<double> & destProjParam,
165 const vigra::Diff2D & originalSrcSize)
174 if (originalSrcSize.x != 0 && originalSrcSize.y != 0) {
175 double rx = srcSize.x / (double)originalSrcSize.x;
176 double ry = srcSize.y / (
double)originalSrcSize.y;
177 map_get(srcVars,
"d").setValue(
map_get(srcVars,
"d").getValue() * rx );
178 map_get(srcVars,
"e").setValue(
map_get(srcVars,
"e").getValue() * ry );
182 destSize, destProj, destProjParam, destHFOV);
192 if (srcSize.x == 0 && srcSize.y == 0) {
209 const vigra::Diff2D & destSize,
211 const std::vector<double> & destProjParam,
213 const vigra::Diff2D & originalSrcSize)
222 if (originalSrcSize.x != 0 && originalSrcSize.y != 0) {
223 double rx = srcSize.x / (double)originalSrcSize.x;
224 double ry = srcSize.y / (
double)originalSrcSize.y;
225 map_get(srcVars,
"d").setValue(
map_get(srcVars,
"d").getValue() * rx );
226 map_get(srcVars,
"e").setValue(
map_get(srcVars,
"e").getValue() * ry );
239 double x_src,
double y_src)
const
241 void * params= (
void *) (&
m_stack);
242 return execute_stack_new(x_src, y_src, &x_dest, &y_dest, params) != 0;
248 double x_dest, y_dest;
249 void * params= (
void *) (&
m_stack);
250 bool ok = execute_stack_new(src.
x, src.
y, &x_dest, &y_dest, params) != 0;
260 double x_src,
double y_src)
const
265 void * params= (
void *) (&
m_stack);
266 bool ok = execute_stack_new(x_src, y_src, &x_dest, &y_dest, params) != 0;
289 for (
int i = 0; i < gl.numIm; i++) {
291 vars.insert(make_pair(std::string(
"TrX"),
Variable(
"TrX", gl.im[i].cP.trans_x)));
292 vars.insert(make_pair(std::string(
"TrY"),
Variable(
"TrY", gl.im[i].cP.trans_y)));
293 vars.insert(make_pair(std::string(
"TrZ"),
Variable(
"TrZ", gl.im[i].cP.trans_z)));
294 vars.insert(make_pair(std::string(
"Tpy"),
Variable(
"Tpy", gl.im[i].cP.trans_yaw)));
295 vars.insert(make_pair(std::string(
"Tpp"),
Variable(
"Tpp", gl.im[i].cP.trans_pitch)));
297 vars.insert(make_pair(std::string(
"v"),
Variable(
"v", gl.im[i].hfov)));
298 vars.insert(make_pair(std::string(
"y"),
Variable(
"y", gl.im[i].yaw)));
299 vars.insert(make_pair(std::string(
"r"),
Variable(
"r", gl.im[i].roll)));
300 vars.insert(make_pair(std::string(
"p"),
Variable(
"p", gl.im[i].pitch)));
301 vars.insert(make_pair(std::string(
"a"),
Variable(
"a", gl.im[i].cP.radial_params[0][3])));
302 vars.insert(make_pair(std::string(
"b"),
Variable(
"b", gl.im[i].cP.radial_params[0][2])));
303 vars.insert(make_pair(std::string(
"c"),
Variable(
"c", gl.im[i].cP.radial_params[0][1])));
305 vars.insert(make_pair(std::string(
"e"),
Variable(
"e", gl.im[i].cP.vertical_params[0])));
306 vars.insert(make_pair(std::string(
"d"),
Variable(
"d", gl.im[i].cP.horizontal_params[0])));
309 vars.insert(make_pair(std::string(
"g"),
Variable(
"g", gl.im[i].cP.shear_x)));
310 vars.insert(make_pair(std::string(
"t"),
Variable(
"t", gl.im[i].cP.shear_y)));
323 for (
int i = 0; i < gl.numPts; i++) {
324 ControlPoint pnt(gl.cpt[i].num[0], gl.cpt[i].x[0], gl.cpt[i].y[0],
326 pnt.
error = sqrt(distSquared(i));
327 result.push_back(pnt);
335 unsigned char * imageData,
337 const std::vector<double> & projParams,
340 SetImageDefaults(&image);
341 image.width = size.x;
342 image.height = size.y;
343 image.bytesPerLine = image.width*3;
344 image.bitsPerPixel = 24;
345 image.dataSize = image.height * image.bytesPerLine;
352 pano_projection_features projd;
353 if (panoProjectionFeaturesQuery((
int) format, &projd)) {
354 image.format = projd.internalFormat;
356 image.format = _equirectangular;
359 image.formatParamCount = projd.numberOfParameters;
360 assert(image.formatParamCount == (
int) projParams.size());
361 for (
int i=0; i < projd.numberOfParameters; i++) {
362 image.formatParam[i] = projParams[i];
363 DEBUG_DEBUG(
"projection parameter " << i <<
": " << image.formatParam[i]);
365 image.hfov = destHFOV;
372 SetCorrectDefaults(&p);
378 if (a != 0.0 || b != 0.0 || c != 0) {
380 p.radial_params[0][3] = p.radial_params[1][3] = p.radial_params[2][3] = a;
381 p.radial_params[0][2] = p.radial_params[1][2] = p.radial_params[2][2] = b;
382 p.radial_params[0][1] = p.radial_params[1][1] = p.radial_params[2][1] = c;
383 double d = 1.0 - (a+b+c);
384 p.radial_params[0][0] = p.radial_params[1][0] = p.radial_params[2][0] = d;
392 p.vertical_params[0] = p.vertical_params[1] = p.vertical_params[2] = val;
395 p.vertical_params[0] = p.vertical_params[1] = p.vertical_params[2] = 0;
401 p.horizontal_params[0] = p.horizontal_params[1] = p.horizontal_params[2] = val;
403 p.horizontal = FALSE;
404 p.horizontal_params[0] = p.horizontal_params[1] = p.horizontal_params[2] = 0;
410 if (p.trans_x != 0 || p.trans_y != 0 || p.trans_z != 0)
427 if (val2 != 0.0 || val != 0.0) {
440 SetCorrectionRadius(&p);
445 unsigned char * imageData,
const VariableMap & vars,
447 bool correctDistortions)
449 SetImageDefaults(&image);
450 image.width = size.x;
451 image.height = size.y;
452 image.bytesPerLine = image.width*3;
453 image.bitsPerPixel = 24;
454 image.dataSize = image.height * image.bytesPerLine;
458 image.data = (
unsigned char**)malloc(
sizeof(
unsigned char*) );
459 if(image.data == NULL) {
462 *(image.data) = imageData;
467 image.dataformat = _RGB;
470 image.format = _rectilinear;
473 image.format = _panorama;
476 image.format = _fisheye_circ;
479 image.format = _fisheye_ff;
482 image.format = _equirectangular;
485 image.format = _orthographic;
488 image.format = _stereographic;
491 image.format = _equisolid;
494 image.format = _thoby;
502 if (correctDistortions) {
509 image.selection.top = 0;
510 image.selection.left = 0;
511 image.selection.right = image.width;
512 image.selection.bottom = image.height;
522 trf.src = (Image *) malloc(
sizeof(Image));
523 SetImageDefaults(trf.src);
524 trf.dest = (Image *) malloc(
sizeof(Image));
525 SetImageDefaults(trf.dest);
528 trf.mode = _destSupplied | _honor_valid;
530 trf.interpolator = _nn;
538 myfree((
void**)img.data);
PanoramaOptions::ProjectionFormat getProjection() const
virtual const VariableMap getImageVariables(unsigned int imgNr) const =0
get variables of an image
Somewhere to specify what variables belong to what.
unsigned int getHeight() const
get panorama height
a variable has a value and a name.
int getHeight() const
Get the height of the image in pixels.
represents a control point
const Map::mapped_type & const_map_get(const Map &m, const typename Map::key_type &key)
std::vector< VariableMap > VariableMapVector
Map::mapped_type & map_get(Map &m, const typename Map::key_type &key)
get a map element.
int getWidth() const
Get the width of the image in pixels.
OptimizeMode
minimize x,y or both.
virtual const SrcPanoImage & getImage(std::size_t nr) const =0
get a panorama image, counting starts with 0
std::map< std::string, Variable > VariableMap
unsigned int getWidth() const
const std::vector< double > & getProjectionParameters() const
Get the optional projection parameters.
std::vector< ControlPoint > CPVector
ProjectionFormat
Projection of final panorama.
All variables of a source image.
vigra::Size2D getSize() const
get size of output image
BaseSrcPanoImage::Projection LensProjectionFormat