## [panotools-cvs] SF.net SVN: panotools:[993] branches/libpano_gsoc2009_mosaic

 [panotools-cvs] SF.net SVN: panotools:[993] branches/libpano_gsoc2009_mosaic From: - 2009-06-16 22:24:07 ```Revision: 993 http://panotools.svn.sourceforge.net/panotools/?rev=993&view=rev Author: dkg5 Date: 2009-06-16 22:24:05 +0000 (Tue, 16 Jun 2009) Log Message: ----------- Added MATLAB files Added Paths: ----------- branches/libpano_gsoc2009_mosaic/matlab/ branches/libpano_gsoc2009_mosaic/matlab/cart2proj.m branches/libpano_gsoc2009_mosaic/matlab/proj2cart.m branches/libpano_gsoc2009_mosaic/matlab/rot.m branches/libpano_gsoc2009_mosaic/matlab/slant.m branches/libpano_gsoc2009_mosaic/matlab/tilt.m branches/libpano_gsoc2009_mosaic/matlab/trans.m Added: branches/libpano_gsoc2009_mosaic/matlab/cart2proj.m =================================================================== --- branches/libpano_gsoc2009_mosaic/matlab/cart2proj.m (rev 0) +++ branches/libpano_gsoc2009_mosaic/matlab/cart2proj.m 2009-06-16 22:24:05 UTC (rev 993) @@ -0,0 +1,15 @@ +function [proj] = cart2proj(cart) +% USAGE: proj = cart2proj(cart) +% Converts cartesian coordinates to projective by appending 1 to end +% -Accepts "cart", vector of length 2, consisting of (x, y) +% -Returns "proj", vector of length 3, consisting of (x, y, 1). + +if ~isvector(cart) || length(cart) ~= 2 + error('ERROR! Must pass cart2proj a vector of length 2.') +end + +if size(cart,1) == 1 % cart is a row vector + proj = [cart 1]; % so append a 1 to the end of the row +else % cart is a column vector + proj = [cart; 1]; % so append 1 to the end of the column +end \ No newline at end of file Added: branches/libpano_gsoc2009_mosaic/matlab/proj2cart.m =================================================================== --- branches/libpano_gsoc2009_mosaic/matlab/proj2cart.m (rev 0) +++ branches/libpano_gsoc2009_mosaic/matlab/proj2cart.m 2009-06-16 22:24:05 UTC (rev 993) @@ -0,0 +1,15 @@ +function [cart] = proj2cart(proj) +% USAGE: cart = proj2cart(proj) +% Converts projective coordinates to cartesian by dividing by z +% -Accepts "proj", vector of length 3, consisting of (x, y, z) +% -Returns "cart", vector of length 2, consisting of (x/z, y/z) + +if ~isvector(proj) || length(proj) ~= 3 || proj(end) == 0 + error('ERROR! Must pass proj2cart a vector of length 3 with non-zero z.'); +end + +if size(proj,1) == 1 % proj is a row vector + cart = [proj(1)/proj(3) proj(2)/proj(3)]; % so cart is a row vec too +else % proj is a column vector + cart = [proj(1)/proj(3); proj(2)/proj(3)]; % so cart is a column vec +end \ No newline at end of file Added: branches/libpano_gsoc2009_mosaic/matlab/rot.m =================================================================== --- branches/libpano_gsoc2009_mosaic/matlab/rot.m (rev 0) +++ branches/libpano_gsoc2009_mosaic/matlab/rot.m 2009-06-16 22:24:05 UTC (rev 993) @@ -0,0 +1,24 @@ +function [out, rotmat] = rot(vproj, ang, ax) +% USAGE: out = rot(vproj, ang, ax) +% Rotates vproj about axis, ax, by angle, ang. +% -Accepts vproj, a projection vector of length 3. +% -Accepts ang, a rotation angle in DEGREES +% -Accepts ax, 'x' 'y' or 'z', the axis around which +% the input vproj will be rotated +% -Returns projective output vector of length 3 + +if nargin ~= 3 || ~isvector(vproj) || ~isnumeric(ang) ... + || length(vproj) ~= 3 + error('ERROR! rot() received incorrect arguments.') +end + +switch lower(ax) + case('x') + rotmat = [1 0 0; 0 cosd(ang) -sind(ang); 0 sind(ang) cosd(ang)]; + case('y') + rotmat = [cosd(ang) 0 -sind(ang); 0 1 0; sind(ang) 0 cosd(ang)]; + case('z') + rotmat = [cosd(ang) -sind(ang) 0; sind(ang) cosd(ang) 0; 0 0 1]; +end + +out = rotmat*vproj; \ No newline at end of file Added: branches/libpano_gsoc2009_mosaic/matlab/slant.m =================================================================== --- branches/libpano_gsoc2009_mosaic/matlab/slant.m (rev 0) +++ branches/libpano_gsoc2009_mosaic/matlab/slant.m 2009-06-16 22:24:05 UTC (rev 993) @@ -0,0 +1,38 @@ +function M = slant(L, ang) +% USAGE: M = slant(L, ang) +% -accepts L, a 2 element vector describing the location of the LookAtPoint +% -accepts ang, a single number in DEGREES describing the desired slant +% -returns M, the matrix equaling the product of the rotation and +% translation matrices necessary to yield the desired slant + +% Assume image plane is at unit distance from center of projection, O. +Z0 = 1; + +% If L is not at the x = 0 point, we need to slide it down to adjust +a = L(1); +Madj = eye(3); +if a ~= 0 + [v Mslide] = trans([1 1 1]', [a 0]); + Madj = Madj * Mslide +end + +% Make a rotation matrix with the angle of the slant. +% Note: [1 1 1]' is a dummy variable and output v is not used. +[v, Mslant] = rot([1 1 1]', ang, 'y') + +% Create the translation necessary to slide rotated image plane so OL, ray +% passing through center of projection, O, and original LookAtPoint, L +% passes through L'', the rotated, translated LookAtPoint. +tx = Z0 * tand(ang) + +% For non-zero L, we must adjust the translation by the ...... +alpha = atand(a/Z0); % angle between lookout point and z-axis +ta = a / cosd(ang + alpha); % adjustment to translation +tx = tx - ta + +% Make a translation matrix using the translation calculated above +% Note: [1 1 1]' is a dummy variable and output v is not used. +[v, Mtrans] = trans([1 1 1]', [tx 0]') + +% Matrix multiply to combine transformations +M = Madj * Mtrans * Mslant \ No newline at end of file Added: branches/libpano_gsoc2009_mosaic/matlab/tilt.m =================================================================== --- branches/libpano_gsoc2009_mosaic/matlab/tilt.m (rev 0) +++ branches/libpano_gsoc2009_mosaic/matlab/tilt.m 2009-06-16 22:24:05 UTC (rev 993) @@ -0,0 +1,37 @@ +function M = tilt(L, ang) +% USAGE: M = tilt(L, ang) +% -accepts L, a 2 element vector describing the location of the LookAtPoint +% -accepts ang, a single number in DEGREES describing the desired tilt +% -returns M, the matrix equaling the product of the rotation and +% translation matrices necessary to yield the desired tilt + +% Assume plane is at unit distance from center of projection, O. +Z0 = 1; + +% If L is not at the y = 0 point, we need to slide it down to adjust +b = L(2); +Madj = eye(3); +if b ~= 0 + [v Mslide] = trans([1 1 1]', [0 b]); + Madj = Madj * Mslide; +end + +% Make a rotation matrix with the angle of the tilt. +% Note: [1 1 1]' is a dummy variable and output v is not used. +[v, Mtilt] = rot([1 1 1]', ang, 'x'); + +% Create the translation necessary to slide rotated image plane so OL, ray +% passing through center of projection, O, and original LookAtPoint, L +% passes through L'', the rotated, translated LookAtPoint. +ty = Z0 * tand(ang); + +% For non-zero L, we must adjust the translation by the ...... +alpha = atand(b/Z0); % angle between lookout point and z-axis +tb = b / cosd(ang + alpha); % adjustment to translation +ty = ty - tb; + +% Make a translation matrix using the translation calculated above +% Note: [1 1 1]' is a dummy variable and output v is not used. +[v, Mtrans] = trans([1 1 1]', [0 ty]'); + +M = Madj * Mtilt * Mtrans; \ No newline at end of file Added: branches/libpano_gsoc2009_mosaic/matlab/trans.m =================================================================== --- branches/libpano_gsoc2009_mosaic/matlab/trans.m (rev 0) +++ branches/libpano_gsoc2009_mosaic/matlab/trans.m 2009-06-16 22:24:05 UTC (rev 993) @@ -0,0 +1,19 @@ +function [vout, T] = trans(vproj, vtrans) +% USAGE: out = trans(vproj, vtrans) +% Translates vproj by vector vtrans +% -Accepts vproj, a projection vector of length 3. +% -Accepts vtrans, a translation vector of length 2. +% First element is x shift. +% Second element is y shift. +% -Returns a three element projection vector of length 3. + +if nargin ~= 2 || ~isvector(vproj) || ~isvector(vtrans) ... + || length(vproj) ~= 3 || length(vtrans) ~= 2 + error('ERROR! translate() received incorrect arguments.') +end + +T = [1 0 vtrans(1);... + 0 1 vtrans(2);... + 0 0 1]; + + vout = T*vproj; \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ```

JavaScript is required for this form.

No, thanks