Index: trunk/src/geometry_calib.m
===================================================================
--- trunk/src/geometry_calib.m	(revision 83)
+++ trunk/src/geometry_calib.m	(revision 84)
@@ -160,4 +160,6 @@
             case 'tsai'
                 set(handles.calib_type,'Value',3)
+            case 'tsai_matlab'
+                set(handles.calib_type,'Value',4)
         end
     end
@@ -255,9 +257,13 @@
 Coord_cell=get(handles.ListCoord,'String');
 Object=read_geometry_calib(Coord_cell);
-
+X=Object.Coord(:,1);
+Y=Object.Coord(:,2);
+Z=Object.Coord(:,3);
 if isequal(calib_type,'rescale')
     GeometryCalib=calib_rescale(Object.Coord);
+    Z=0;%Z not taken into account
 elseif isequal(calib_type,'linear')
     GeometryCalib=calib_linear(Object.Coord);
+    Z=0; %Z not taken into account
 elseif isequal(calib_type,'tsai_cpp')
     GeometryCalib=calib_tsai(Object.Coord);
@@ -265,4 +271,41 @@
     GeometryCalib=calib_tsai2(Object.Coord);
 end
+
+%check error
+if isfield(GeometryCalib,'dpx_dpy')
+    Calib.dpx=GeometryCalib.dpx_dpy(1);
+    Calib.dpy=GeometryCalib.dpx_dpy(2);
+end
+if isfield(GeometryCalib,'sx')
+    Calib.sx=GeometryCalib.sx;
+end
+if isfield(GeometryCalib,'Cx_Cy')
+    Calib.Cx=GeometryCalib.Cx_Cy(1);
+    Calib.Cy=GeometryCalib.Cx_Cy(2);
+end
+if isfield(GeometryCalib,'kappa1')
+    Calib.kappa1=GeometryCalib.kappa1;
+end
+if isfield(GeometryCalib,'focal')
+    Calib.f=GeometryCalib.focal;
+end
+if isfield(GeometryCalib,'Tx_Ty_Tz')
+    Calib.Tx=GeometryCalib.Tx_Ty_Tz(1);
+    Calib.Ty=GeometryCalib.Tx_Ty_Tz(2);
+    Calib.Tz=GeometryCalib.Tx_Ty_Tz(3);
+end
+if isfield(GeometryCalib,'R')
+    Calib.R=GeometryCalib.R;
+end
+x_ima=Object.Coord(:,4);
+y_ima=Object.Coord(:,5); 
+[Xpoints,Ypoints]=px_XYZ(Calib,X,Y,Z);
+GeometryCalib.ErrorRms(1)=sqrt(mean((Xpoints-x_ima).*(Xpoints-x_ima)));
+[GeometryCalib.ErrorMax(1),index(1)]=max(abs(Xpoints-x_ima));
+GeometryCalib.ErrorRms(2)=sqrt(mean((Ypoints-y_ima).*(Ypoints-y_ima)));
+[GeometryCalib.ErrorMax(2),index(2)]=max(abs(Ypoints-y_ima));
+[EM,ind_dim]=max(GeometryCalib.ErrorMax);
+index=index(ind_dim);
+
 unitlist=get(handles.CoordUnit,'String');
 unit=unitlist{get(handles.CoordUnit,'value')};
@@ -286,23 +329,26 @@
     outputfile=answer{1};
 end
-update_imadoc(GeometryCalib,outputfile)
-msgbox_uvmat('CONFIRMATION',{[outputfile ' updated with calibration data'];...
+answer=msgbox_uvmat('INPUT_Y-N',{[outputfile ' updated with calibration data'];...
     ['Error rms (along x,y)=' num2str(GeometryCalib.ErrorRms) ' pixels'];...
-    ['Error max (along x,y)=' num2str(GeometryCalib.ErrorMax) ' pixels']})
-
-%display image with new calibration in the currently opened uvmat interface
-hhh=findobj(hhuvmat.axes3,'Tag','calib_marker');% delete calib points and markers
-if ~isempty(hhh)
-    delete(hhh);
-end
-hhh=findobj(hhuvmat.axes3,'Tag','calib_points');
-if ~isempty(hhh)
-    delete(hhh);
-end
-set(hhuvmat.FixedLimits,'Value',0)% put FixedLimits option to 'off'
-set(hhuvmat.FixedLimits,'BackgroundColor',[0.7 0.7 0.7])
-uvmat('RootPath_Callback',hObject,eventdata,hhuvmat); %file input with xml reading  in uvmat
-MenuPlot_Callback(hObject, eventdata, handles)
-figure(handles.geometry_calib)
+    ['Error max (along x,y)=' num2str(GeometryCalib.ErrorMax) ' pixels']});
+if isequal(answer,'Yes')
+    update_imadoc(GeometryCalib,outputfile)
+    %display image with new calibration in the currently opened uvmat interface
+    hhh=findobj(hhuvmat.axes3,'Tag','calib_marker');% delete calib points and markers
+    if ~isempty(hhh)
+        delete(hhh);
+    end
+    hhh=findobj(hhuvmat.axes3,'Tag','calib_points');
+    if ~isempty(hhh)
+        delete(hhh);
+    end
+    set(hhuvmat.FixedLimits,'Value',0)% put FixedLimits option to 'off'
+    set(hhuvmat.FixedLimits,'BackgroundColor',[0.7 0.7 0.7])
+    uvmat('RootPath_Callback',hObject,eventdata,hhuvmat); %file input with xml reading  in uvmat
+    MenuPlot_Callback(hObject, eventdata, handles)
+    set(handles.ListCoord,'Value',index)% indicate in the list the point with max deviation (possible mistake)
+    ListCoord_Callback(hObject, eventdata, handles)
+    figure(handles.geometry_calib)
+end
 
 %------------------------------------------------------------------
@@ -395,21 +441,21 @@
 GeometryCalib.R=[px(1),0,0;0,py(1),0;0,0,1];
 
-%check error
-Calib.dpx=1;
-Calib.dpy=1;
-Calib.sx=1;
-Calib.Cx=0;
-Calib.Cy=0;
-Calib.Tz=1;
-Calib.kappa1=0;
-Calib.f=GeometryCalib.focal;
-Calib.Tx=T_x;
-Calib.Ty=T_y;
-Calib.R=GeometryCalib.R;
-[Xpoints,Ypoints]=px_XYZ(Calib,X,Y,0);
-GeometryCalib.ErrorRms(1)=sqrt(mean((Xpoints-x_ima).*(Xpoints-x_ima)));
-GeometryCalib.ErrorMax(1)=max(abs(Xpoints-x_ima));
-GeometryCalib.ErrorRms(2)=sqrt(mean((Ypoints-y_ima).*(Ypoints-y_ima)));
-GeometryCalib.ErrorMax(2)=max(abs(Ypoints-y_ima));
+% %check error
+% Calib.dpx=1;
+% Calib.dpy=1;
+% Calib.sx=1;
+% Calib.Cx=0;
+% Calib.Cy=0;
+% Calib.Tz=1;
+% Calib.kappa1=0;
+% Calib.f=GeometryCalib.focal;
+% Calib.Tx=T_x;
+% Calib.Ty=T_y;
+% Calib.R=GeometryCalib.R;
+% [Xpoints,Ypoints]=px_XYZ(Calib,X,Y,0);
+% GeometryCalib.ErrorRms(1)=sqrt(mean((Xpoints-x_ima).*(Xpoints-x_ima)));
+% GeometryCalib.ErrorMax(1)=max(abs(Xpoints-x_ima));
+% GeometryCalib.ErrorRms(2)=sqrt(mean((Ypoints-y_ima).*(Ypoints-y_ima)));
+% GeometryCalib.ErrorMax(2)=max(abs(Ypoints-y_ima));
 
 %------------------------------------------------------------------------
@@ -436,9 +482,9 @@
 GeometryCalib.R=[a_X1(2),a_X1(3),0;a_Y1(2),a_Y1(3),0;0,0,1];
 
-%check error
-GeometryCalib.ErrorRms(1)=sqrt(mean((x1-x_ima).*(x1-x_ima)));
-GeometryCalib.ErrorMax(1)=max(abs(x1-x_ima));
-GeometryCalib.ErrorRms(2)=sqrt(mean((y1-y_ima).*(y1-y_ima)));
-GeometryCalib.ErrorMax(2)=max(abs(y1-y_ima));
+% %check error
+% GeometryCalib.ErrorRms(1)=sqrt(mean((x1-x_ima).*(x1-x_ima)));
+% GeometryCalib.ErrorMax(1)=max(abs(x1-x_ima));
+% GeometryCalib.ErrorRms(2)=sqrt(mean((y1-y_ima).*(y1-y_ima)));
+% GeometryCalib.ErrorMax(2)=max(abs(y1-y_ima));
 
 %------------------------------------------------------------------------
@@ -463,5 +509,5 @@
 run(fullfile(path_UVMAT,'toolbox_calib','go_calib_optim'));
 
-GeometryCalib.CalibrationType='tsai';
+GeometryCalib.CalibrationType='tsai_matlab';
 GeometryCalib.focal=f(2);
 GeometryCalib.dpx_dpy=[1 1];
@@ -472,26 +518,26 @@
 GeometryCalib.Tx_Ty_Tz=Tc_1';
 GeometryCalib.R=Rc_1;
-Calib.dpx=GeometryCalib.dpx_dpy(1);
-Calib.dpy=GeometryCalib.dpx_dpy(2);
-Calib.sx=GeometryCalib.sx;
-Calib.Cx=GeometryCalib.Cx_Cy(1);
-Calib.Cy=GeometryCalib.Cx_Cy(2);
-Calib.kappa1=GeometryCalib.kappa1;
-Calib.f=GeometryCalib.focal;
-Calib.Tx=GeometryCalib.Tx_Ty_Tz(1);
-Calib.Ty=GeometryCalib.Tx_Ty_Tz(2);
-Calib.Tz=GeometryCalib.Tx_Ty_Tz(3);
-Calib.R=GeometryCalib.R;
-X=Coord(:,1);
-Y=Coord(:,2);
-Z=Coord(:,3);
-x_ima=Coord(:,4);
-y_ima=Coord(:,5);
-[Xpoints,Ypoints]=px_XYZ(Calib,X,Y,Z);
-
-GeometryCalib.ErrorRms(1)=sqrt(mean((Xpoints-x_ima).*(Xpoints-x_ima)));
-GeometryCalib.ErrorMax(1)=max(abs(Xpoints-x_ima));
-GeometryCalib.ErrorRms(2)=sqrt(mean((Ypoints-y_ima).*(Ypoints-y_ima)));
-GeometryCalib.ErrorMax(2)=max(abs(Ypoints-y_ima));
+% Calib.dpx=GeometryCalib.dpx_dpy(1);
+% Calib.dpy=GeometryCalib.dpx_dpy(2);
+% Calib.sx=GeometryCalib.sx;
+% Calib.Cx=GeometryCalib.Cx_Cy(1);
+% Calib.Cy=GeometryCalib.Cx_Cy(2);
+% Calib.kappa1=GeometryCalib.kappa1;
+% Calib.f=GeometryCalib.focal;
+% Calib.Tx=GeometryCalib.Tx_Ty_Tz(1);
+% Calib.Ty=GeometryCalib.Tx_Ty_Tz(2);
+% Calib.Tz=GeometryCalib.Tx_Ty_Tz(3);
+% Calib.R=GeometryCalib.R;
+% X=Coord(:,1);
+% Y=Coord(:,2);
+% Z=Coord(:,3);
+% x_ima=Coord(:,4);
+% y_ima=Coord(:,5);
+% [Xpoints,Ypoints]=px_XYZ(Calib,X,Y,Z);
+% 
+% GeometryCalib.ErrorRms(1)=sqrt(mean((Xpoints-x_ima).*(Xpoints-x_ima)));
+% [GeometryCalib.ErrorMax(1),GeometryCalib.IndexMax(1)]=max(abs(Xpoints-x_ima));
+% GeometryCalib.ErrorRms(2)=sqrt(mean((Ypoints-y_ima).*(Ypoints-y_ima)));
+% [GeometryCalib.ErrorMax(2),GeometryCalib.IndexMax(2)]=max(abs(Ypoints-y_ima));
 
 function GeometryCalib=calib_tsai(Coord)
@@ -558,47 +604,27 @@
 GeometryCalib.R=[r1,r2,r3;r4,r5,r6;r7,r8,r9];
 %erreur a caracteriser?
-%check error
-Calib.dpx=GeometryCalib.dpx_dpy(1);
-Calib.dpy=GeometryCalib.dpx_dpy(2);
-Calib.sx=GeometryCalib.sx;
-Calib.Cx=GeometryCalib.Cx_Cy(1);
-Calib.Cy=GeometryCalib.Cx_Cy(2);
-Calib.kappa1=GeometryCalib.kappa1;
-Calib.f=GeometryCalib.focal;
-Calib.Tx=GeometryCalib.Tx_Ty_Tz(1);
-Calib.Ty=GeometryCalib.Tx_Ty_Tz(2);
-Calib.Tz=GeometryCalib.Tx_Ty_Tz(3);
-Calib.R=GeometryCalib.R;
-X=Coord(:,1);
-Y=Coord(:,2);
-Z=Coord(:,3);
-x_ima=Coord(:,4);
-y_ima=Coord(:,5);
-[Xpoints,Ypoints]=px_XYZ(Calib,X,Y,Z);
-
-GeometryCalib.ErrorRms(1)=sqrt(mean((Xpoints-x_ima).*(Xpoints-x_ima)));
-GeometryCalib.ErrorMax(1)=max(abs(Xpoints-x_ima));
-GeometryCalib.ErrorRms(2)=sqrt(mean((Ypoints-y_ima).*(Ypoints-y_ima)));
-GeometryCalib.ErrorMax(2)=max(abs(Ypoints-y_ima));
-% Nfx
-% dx
-% dy
-% 5 dpx
-% 6 dpy
-% cx
-% cy
-% sx
-% f
-% kappa1
-% tx
-% ty
-% tz
-% rx
-% ry
-% rz
-% p1
-% p2
-
-%calibcoeff=str2num(calibdat)
+% %check error
+% Calib.dpx=GeometryCalib.dpx_dpy(1);
+% Calib.dpy=GeometryCalib.dpx_dpy(2);
+% Calib.sx=GeometryCalib.sx;
+% Calib.Cx=GeometryCalib.Cx_Cy(1);
+% Calib.Cy=GeometryCalib.Cx_Cy(2);
+% Calib.kappa1=GeometryCalib.kappa1;
+% Calib.f=GeometryCalib.focal;
+% Calib.Tx=GeometryCalib.Tx_Ty_Tz(1);
+% Calib.Ty=GeometryCalib.Tx_Ty_Tz(2);
+% Calib.Tz=GeometryCalib.Tx_Ty_Tz(3);
+% Calib.R=GeometryCalib.R;
+% X=Coord(:,1);
+% Y=Coord(:,2);
+% Z=Coord(:,3);
+% x_ima=Coord(:,4);
+% y_ima=Coord(:,5);
+% [Xpoints,Ypoints]=px_XYZ(Calib,X,Y,Z);
+% 
+% GeometryCalib.ErrorRms(1)=sqrt(mean((Xpoints-x_ima).*(Xpoints-x_ima)));
+% GeometryCalib.ErrorMax(1)=max(abs(Xpoints-x_ima));
+% GeometryCalib.ErrorRms(2)=sqrt(mean((Ypoints-y_ima).*(Ypoints-y_ima)));
+% GeometryCalib.ErrorMax(2)=max(abs(Ypoints-y_ima));
 
 
