From: <da...@us...> - 2009-02-02 21:29:31
|
Revision: 934 http://panotools.svn.sourceforge.net/panotools/?rev=934&view=rev Author: dangelo Date: 2009-02-02 21:29:28 +0000 (Mon, 02 Feb 2009) Log Message: ----------- equirect -> rectilinear transform: reject points behind the camera applied patch with biplane and triplane projections. Modified Paths: -------------- trunk/libpano/ChangeLog trunk/libpano/math.c Modified: trunk/libpano/ChangeLog =================================================================== --- trunk/libpano/ChangeLog 2009-02-02 20:39:35 UTC (rev 933) +++ trunk/libpano/ChangeLog 2009-02-02 21:29:28 UTC (rev 934) @@ -1,3 +1,10 @@ +2009-02-02 22:24 dangelo + + * math.c: rect_erect: equirect -> rectilinear projection: reject + points behind the camera (fixes some problems with hugins fast + preview). Applied dualplane and triplane projection patch (by unknown + author). + 2009-02-01 23:34 brunopostle * tools/PTmasker.c: fix for invalid format specification, bug Modified: trunk/libpano/math.c =================================================================== --- trunk/libpano/math.c 2009-02-02 20:39:35 UTC (rev 933) +++ trunk/libpano/math.c 2009-02-02 21:29:28 UTC (rev 934) @@ -575,7 +575,19 @@ *x_src = distanceparam * tan(phi); *y_src = distanceparam / (tan( theta ) * cos(phi)); #endif - return 1; + // normalize phi to be in the -PI, PI range + while(phi <= -PI) + phi += 2*PI; + while(phi > PI) + phi -= 2*PI; + + // check if the point is "in front" of the camera + if (phi < -PI/2.0 || phi > PI/2.0) { + // behind, transform considered invalid + return 0; + } else + return 1; + } // This is the cylindrical projection int pano_erect( double x_dest,double y_dest, double* x_src, double* y_src, void* params) @@ -1545,7 +1557,150 @@ return 1; } +/** convert from erect to biplane */ +int biplane_erect ( double x_dest,double y_dest, double* x_src, double* y_src, void* params ) +{ + double x,offset; + if (fabs(x_dest / mp->distance) > mp->pn->precomputedValue[0]+DEG_TO_RAD(89)) + { + *x_src = 0; + *y_src = 0; + return 0; + } + if(x_dest<0) + { + x = x_dest + mp->pn->precomputedValue[0] * mp->distance; + offset = -mp->pn->precomputedValue[1]; + } + else + { + x = x_dest - mp->pn->precomputedValue[0] * mp->distance; + offset = mp->pn->precomputedValue[1]; + } + rect_erect(x,y_dest,x_src,y_src,&mp->distance); + *x_src += offset; + return 1; +} +/** convert from biplane to erect */ +int erect_biplane ( double x_dest,double y_dest, double* x_src, double* y_src, void* params ) +{ + double x, offset; + if(fabs(x_dest)>mp->pn->precomputedValue[1]+mp->distance*57) // 57 = tan(89) + { + *x_src = 0; + *y_src = 0; + return 0; + } + if(x_dest<0) + { + x=x_dest + mp->pn->precomputedValue[1]; + offset = - mp->pn->precomputedValue[0]; + } + else + { + x=x_dest - mp->pn->precomputedValue[1]; + offset = mp->pn->precomputedValue[0]; + } + erect_rect(x,y_dest,x_src,y_src,&mp->distance); + *x_src += offset * mp->distance; + return 1; +} + + +int biplane_distance ( double width, double b, void* params ) +{ + if(mp->pn->formatParamCount==0) + { + mp->pn->formatParamCount = 1; + mp->pn->formatParam[0] = 45; + }; + mp->pn->formatParam[0]= max( min(mp->pn->formatParam[0], 179), 1); + + mp->pn->precomputedCount = 2; + mp->pn->precomputedValue[0] = DEG_TO_RAD(mp->pn->formatParam[0]) / 2; // angle in rad + mp->distance = (double) width / (2.0 * (tan(mp->pn->precomputedValue[0])+tan(b/2.0 - mp->pn->precomputedValue[0]))); + mp->pn->precomputedValue[1]=mp->distance*tan(mp->pn->precomputedValue[0]); // offset + return 1; +} + +int triplane_erect ( double x_dest,double y_dest, double* x_src, double* y_src, void* params ) +{ + double x,offset; + if(fabs(x_dest / mp->distance)> mp->pn->precomputedValue[0] + DEG_TO_RAD(89)) + { + *x_src = 0; + *y_src = 0; + return 0; + }; + if(x_dest < -mp->pn->precomputedValue[0] / 2) + { + x=x_dest -mp->pn->precomputedValue[0] * mp->distance; + offset = mp->pn->precomputedValue[1]; + } + else if (x_dest < mp->pn->precomputedValue[0] / 2) + { + x=x_dest; + offset=0; + } + else + { + x=x_dest + mp->pn->precomputedValue[0] * mp->distance; + offset = - mp->pn->precomputedValue[1]; + } + rect_erect(x,y_dest,x_src,y_src,&mp->distance); + *x_src += offset; + return 1; +} + +int erect_triplane ( double x_dest,double y_dest, double* x_src, double* y_src, void* params ) +{ + double x, offset; + if(fabs(x_dest) > 2* mp->pn->precomputedValue[1] + 57 * mp->distance ) + { + *x_src = 0; + *y_src = 0; + return 0; + }; + if(x_dest < -mp->pn->precomputedValue[1]) + { + x=x_dest + 2 * mp->pn->precomputedValue[1]; + offset = - mp->pn->precomputedValue[0]; + } + else if (x_dest < mp->pn->precomputedValue[1]) + { + x=x_dest; + offset=0; + } + else + { + x=x_dest - 2 * mp->pn->precomputedValue[1]; + offset = + mp->pn->precomputedValue[0]; + } + erect_rect(x,y_dest,x_src ,y_src,&mp->distance); + *x_src += offset * mp->distance; + return 1; +} + +int triplane_distance ( double width, double b, void* params ) +{ + if(mp->pn->formatParamCount==0) + { + mp->pn->formatParamCount = 1; + mp->pn->formatParam[0] = 45; + }; + mp->pn->formatParam[0] = max( min(mp->pn->formatParam[0], 120), 1); + + mp->pn->precomputedCount = 2; + mp->pn->precomputedValue[0] = DEG_TO_RAD(mp->pn->formatParam[0]); // angle in rad + mp->distance = (double) width / (4.0 * tan(mp->pn->precomputedValue[0]/2.0) + 2 * tan(b/2.0 - mp->pn->precomputedValue[0])); + mp->pn->precomputedValue[1]=mp->distance*tan(mp->pn->precomputedValue[0]/2.0); // offset + return 1; +} + + + + int erect_sphere_tp( double x_dest,double y_dest, double* x_src, double* y_src, void* params) { // params: double distanceparam This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |