view mt_calibrate.m @ 18:062d46712995 tip

Moved mc_global_info1 back to public folder
author samer
date Mon, 02 Apr 2012 21:50:43 +0100
parents ffd7efa3e5c0
children
line wrap: on
line source
% mt_calibrate - Set spatial calibration of melody triangle system.
%
% mt_calibrate ::
%    mt_system       ~'system to calibrate',
%    I:[[1,E]->[3]]  ~'list triangle corners being updated',
%    P:[[3,E]]       ~'X-Y coordinates of the E corners being updated'
% -> mt_system       ~'calibrated system'.

function Sys=mt_calibrate(Sys,I,PI)
	
	if nargin>2, Sys.refpoints(:,I) = PI; end
	P  = Sys.refpoints;
	fprintf('\nCalibrating for triangle vertices at:\n'); disp(P);
	p0 = P(:,1);
	[Sys.map, Sys.revmap] = info_map_fn(p0,P(:,2:3)-repmat(p0,1,2));
end

function [f,g]=info_map_fn(p0,M)
	iM=inv(M);
	f=@(p)clip_tri(iM*(p-p0));
	g=@(p)p0+M*p;
end

function x=clip_tri(x)
	if x(2)<0
		x(2)=0;
		if x(1)<0, x(1)=0;
		elseif x(1)>1, x(1)=1;
		end
	elseif x(1)<0
		x(1)=0;
		if x(2)<0, x(2)=1;
		elseif x(2)>1, x(2)=1;
		end
	else
		d = [1,1]*x - 1;
		if d>0
			x = x - d/2;
			if x(1)<0, x=[0;1];
			elseif x(2)<0, x=[1;0];
			end
		end
	end
end