Index: /trunk/src/geometry_calib.m
===================================================================
--- /trunk/src/geometry_calib.m	(revision 541)
+++ /trunk/src/geometry_calib.m	(revision 542)
@@ -861,5 +861,5 @@
 %------------------------------------------------------------------------
 huvmat=findobj(allchild(0),'Name','uvmat');%find the current uvmat interface handle
-hplot=findobj(huvmat,'Tag','axes3');%main plotting axis of uvmat
+hplot=findobj(huvmat,'Tag','PlotAxes');%main plotting axis of uvmat
 hhh=findobj(hplot,'Tag','calib_marker');
 Coord_cell=get(handles.ListCoord,'String');
@@ -876,5 +876,5 @@
     return
 end
-%fill the edit boxex
+%fill the edit boxe
 set(handles.XObject,'String',coord_str(1:k(1)-1))
 set(handles.YObject,'String',coord_str(k(1)+3:k(2)-1))
Index: /trunk/src/mouse_motion.m
===================================================================
--- /trunk/src/mouse_motion.m	(revision 541)
+++ /trunk/src/mouse_motion.m	(revision 542)
@@ -104,4 +104,5 @@
                     text_displ_3='';
                     text_displ_4='';
+                    text_displ_5='';
                     ivec=[];
                     xName='';
@@ -140,7 +141,7 @@
                                         elseif (isfield(CellInfo{icell},'VarIndex_vector_x') && isequal(ivar,CellInfo{icell}.VarIndex_vector_x))||isequal(ivar,CellInfo{icell}.VarIndex_vector_y)||...
                                                 (isfield(CellInfo{icell},'VarIndex_vector_z') && isequal(ivar,CellInfo{icell}.VarIndex_vector_z))
-                                            text_displ_3=[text_displ_3 var_text];
+                                            text_displ_4=[text_displ_4 var_text];
                                         else
-                                            text_displ_4=[text_displ_4 var_text];
+                                            text_displ_5=[text_displ_5 var_text];
                                         end
                                     end
@@ -168,5 +169,5 @@
                                             VarVal=Field.(VarName)(indy0,indx0,:);
                                             var_text=[VarName '=' num2str(VarVal) ','];
-                                            text_displ_2=[text_displ_2 var_text];
+                                            text_displ_4=[text_displ_4 var_text];
                                         end
                                     end
@@ -175,5 +176,5 @@
                         end
                     end
-              % display the current x,y coordinates in the absence of detected vector
+              % display the current x,y plot coordinates in the absence of detected vector
                     if isempty(ivec)
                         if isempty(xName)
@@ -183,26 +184,21 @@
                         text_displ_1=[xName '=' num2str(xy(1,1),4) ', ' yName '=' num2str(xy(1,2),4) ','];
                     end
-              %display the z coordinate if defined by the projection plane
-                    if isfield(Field,'PlaneCoord') 
-%                             ZIndex=Field.ZIndex;
-                        if size(Field.PlaneCoord)>=[1 3]
-                            z=Field.PlaneCoord(1,3);
-                            if isfield(Field,'PlaneAngle')&&~isequal(Field.PlaneAngle,[0 0 0])
-                                om=norm(Field.PlaneAngle);%norm of rotation angle in radians
-                                OmAxis=Field.PlaneAngle/om; %unit vector marking the rotation axis
-                                cos_om=cos(pi*om/180);
-                                sin_om=sin(pi*om/180);
-                                coeff=OmAxis(3)*(1-cos_om);
-                                norm_plane(1)=OmAxis(1)*coeff+OmAxis(2)*sin_om;
-                                norm_plane(2)=OmAxis(2)*coeff-OmAxis(1)*sin_om;
-                                norm_plane(3)=OmAxis(3)*coeff+cos_om;
-                                Z0=norm_plane*Field.PlaneCoord'/norm_plane(3);
-                                z=Z0-norm_plane(1)*xy(1,1)/norm_plane(3)-norm_plane(2)*xy(1,2)/norm_plane(3);
-                            end
+                    %display the z coordinate if defined by the projection plane
+                    if isfield(Field,'ObjectCoord') && length(Field.ObjectCoord)>=3
+                        pos=[xy(1,1) xy(1,2) 0];
+                        if isfield(Field,'ObjectAngle')&&~isequal(Field.ObjectAngle,[0 0 0])
+                            om=norm(Field.ObjectAngle);%norm of rotation angle in radians
+                            OmAxis=Field.ObjectAngle/om; %unit vector marking the rotation axis
+                            cos_om=cos(pi*om/180);
+                            sin_om=sin(pi*om/180);
+                            pos=[xy(1,1) xy(1,2) 0];
+                            pos=cos_om*pos+sin_om*cross(OmAxis,pos)+(1-cos_om)*(OmAxis*pos')*OmAxis;
                         end
+                        pos=pos+Field.ObjectCoord;
+                        text_displ_3=[text_displ_3 'x,y,z=' num2str(pos,4)];
                     end
-                    if ~isempty(z)
-                        text_displ_1=[text_displ_1 ' z=' num2str(z,4)];
-                    end
+%                     if ~isempty(z)
+%                         text_displ_1=[text_displ_1 ' z=' num2str(z,4)];
+%                     end
                % case of PIV correlation display
                     if test_piv
@@ -242,5 +238,5 @@
                         [Data,errormsg,result_conv]= civ_matlab(Param);
                         if ~isempty(errormsg)
-                            text_displ_4=errormsg;
+                            text_displ_5=errormsg;
                         else
                             rangx(1)=-(isx2-ibx2)+shiftx;
@@ -281,5 +277,10 @@
 end
 if ~isempty(text_displ_1)
-set(handles.text_display,'String',[{text_displ_1};{text_displ_2};{text_displ_3};{text_displ_4}])
+    text_displ=[{text_displ_1};{text_displ_2};{text_displ_3};{text_displ_4};{text_displ_5}];
+    ind_blank=find(strcmp('',text_displ));
+    if ~isempty(ind_blank)
+        text_displ(ind_blank)=[];
+    end
+    set(handles.text_display,'String',text_displ)
 else
    set(handles.text_display,'String',get(handles.text_display,'UserData'))
Index: /trunk/src/proj_field.m
===================================================================
--- /trunk/src/proj_field.m	(revision 541)
+++ /trunk/src/proj_field.m	(revision 542)
@@ -94,5 +94,5 @@
 if ~isfield(ObjectData,'Coord')||isempty(ObjectData.Coord)
     if strcmp(ObjectData.Type,'plane')
-        ObjectData.Coord=[0 0 0];%default
+        ObjectData.Coord=[0 0];%default
     else
         return
@@ -948,4 +948,26 @@
 %% initiate Matlab  structure for physical field
 [ProjData,errormsg]=proj_heading(FieldData,ObjectData);
+
+%% reproduce initial plane position and angle
+if isfield(FieldData,'PlaneCoord')&&length(FieldData.PlaneCoord)==3
+   if length(ProjData.ObjectCoord)==3% if the projection plane has a z coordinate
+       if ~isequal(ProjData.PlaneCoord(3),ProjData.ObjectCoord) %check the consistency with the z coordinate of the field plane (set by calibration)
+           errormsg='inconsistent z position for field and projection plane';
+           return
+       end
+   else % the z coordinate is set only by the field plane (by calibration)
+       ProjData.ObjectCoord(3)=FieldData.PlaneCoord(3);
+   end
+   if isfield(FieldData,'PlaneAngle')
+       if isfield(ProjData,'ObjectAngle')
+           if ~isequal(FieldData.PlaneAngle,ProjData.ObjectAngle) %check the consistency with the z coordinate of the field plane (set by calibration)
+           errormsg='inconsistent plane angle for field and projection plane';
+           return
+           end
+       else
+        ProjData.ObjectAngle=FieldData.PlaneAngle;
+       end
+    end
+end
 ProjData.NbDim=2;
 ProjData.ListVarName={};
@@ -2206,5 +2228,5 @@
     AttrName=ProjData.ListGlobalAttribute{iattr};
     if isfield(FieldData,AttrName)
-        eval(['ProjData.' AttrName '=FieldData.' AttrName ';']);
+        ProjData.(AttrName)=FieldData.(AttrName);
     end
 end
@@ -2224,9 +2246,10 @@
 for ilist=1:length(ListObject)
     if isfield(ObjectData,ListObject{ilist})
-        eval(['val=ObjectData.' ListObject{ilist} ';'])
+        val=ObjectData.(ListObject{ilist});
         if ~isempty(val)
-            eval(['ProjData.Object' ListObject{ilist} '=val;']);
+            ProjData.(['Object' ListObject{ilist}])=val;
             ProjData.ListGlobalAttribute=[ProjData.ListGlobalAttribute {['Object' ListObject{ilist}]}];
         end
     end   
 end
+
Index: /trunk/src/px_XYZ.m
===================================================================
--- /trunk/src/px_XYZ.m	(revision 541)
+++ /trunk/src/px_XYZ.m	(revision 542)
@@ -11,11 +11,4 @@
 
 function [X,Y]=px_XYZ(Calib,Xphys,Yphys,Zphys)
-% if exist('Z','var')& isequal(Z,round(Z))& Z>0 & isfield(Calib,'PlanePos')&length(Calib.PlanePos)>=Z
-%     Zindex=Z;
-%     planepos=Calib.PlanePos{Zindex};
-%     zphys=planepos(3);%A GENERALISER CAS AVEC ANGLE
-% else
-%     zphys=0;
-% end
 if ~exist('Zphys','var')
     Zphys=0;
@@ -27,28 +20,28 @@
      Calib.Tx_Ty_Tz=[0 0 1];
 end
-% if ~isfield(Calib,'kappa1')
-%     Calib.kappa1=0;
-% end
-% if ~isfield(Calib,'sx')
-%     Calib.sx=1;
-% end
-% if ~isfield(Calib,'dpx')
-%     Calib.dpx=1;
-% end
-% if ~isfield(Calib,'dpy')
-%     Calib.dpy=1;
-% end
 
 %%%%%%%%%%%%%
+% general case
 if isfield(Calib,'R')
     R=(Calib.R)';
+    %correct z for refraction if needed
+    if isfield(Calib,'InterfaceCoord') && isfield(Calib,'RefractionIndex')
+        H=Calib.InterfaceCoord(3);
+        if H>Zphys
+            Zphys=H-(H-Zphys)/Calib.RefractionIndex; %corrected z (virtual object)
+            test_refraction=1;
+        end
+    end
+    
     %camera coordinates
     xc=R(1)*Xphys+R(2)*Yphys+R(3)*Zphys+Calib.Tx_Ty_Tz(1);
     yc=R(4)*Xphys+R(5)*Yphys+R(6)*Zphys+Calib.Tx_Ty_Tz(2);
     zc=R(7)*Xphys+R(8)*Yphys+R(9)*Zphys+Calib.Tx_Ty_Tz(3);
-%undistorted image coordinates
+    
+    %undistorted image coordinates
     Xu=xc./zc;
     Yu=yc./zc;
-%radial quadratic correction factor
+    
+    %radial quadratic correction factor
     if ~isfield(Calib,'kc')
         r2=1; %no quadratic distortion
@@ -56,22 +49,14 @@
         r2=1+Calib.kc*(Xu.*Xu+Yu.*Yu);
     end
-%pixel coordinates
+    
+    %pixel coordinates
     if ~isfield(Calib,'Cx_Cy')
         Calib.Cx_Cy=[0 0];%default value
     end
     X=Calib.fx_fy(1)*Xu.*r2+Calib.Cx_Cy(1);
-    Y=Calib.fx_fy(2)*Yu.*r2+Calib.Cx_Cy(2);    
-%OLD CONVENTION (Wilson)undistorted image coordinates
-%     Xu=Calib.f*xc./zc;
-%     Yu=Calib.f*yc./zc;    
-% %distorted image coordinates 
-%     distortion=(Calib.kappa1)*(Xu.*Xu+Yu.*Yu)+1; %A REVOIR
-% % distortion=1;
-%     Xd=Xu./distortion;
-%     Yd=Yu./distortion;
-% %pixel coordinates
-%     X=Xd*Calib.sx/Calib.dpx+Calib.Cx;
-%     Y=Yd/Calib.dpy+Calib.Cy;
-else %case 'rescale'
+    Y=Calib.fx_fy(2)*Yu.*r2+Calib.Cx_Cy(2);  
+    
+%case 'rescale'    
+else 
     X=Calib.fx_fy(1)*(Xphys+Calib.Tx_Ty_Tz(1));
     Y=Calib.fx_fy(2)*(Yphys+Calib.Tx_Ty_Tz(2));  
Index: /trunk/src/uvmat.m
===================================================================
--- /trunk/src/uvmat.m	(revision 541)
+++ /trunk/src/uvmat.m	(revision 542)
@@ -1332,8 +1332,11 @@
     else
         %read mask image
-        Mask.AName='image';
-        Mask.A=imread(MaskName);
+        [Mask,tild,errormsg] = read_field(MaskName,'image');
+%         Mask.AName='image';
+%         Mask.A=imread(MaskName);
+        if ~isempty(errormsg)
+            return
+        end
         npxy=size(Mask.A);
-        test_error=0;
         if length(npxy)>2
             errormsg=[MaskName ' is not a grey scale image'];
@@ -1343,7 +1346,7 @@
             return
         end
-        Mask.AX=[0.5 npxy(2)-0.5];
-        Mask.AY=[npxy(1)-0.5 0.5 ];
-        Mask.CoordUnit='pixel';
+%         Mask.AX=[0.5 npxy(2)-0.5];
+%         Mask.AY=[npxy(1)-0.5 0.5 ];
+%         Mask.CoordUnit='pixel';
         if isequal(get(handles.slices,'Value'),1)
            NbSlice=str2num(get(handles.num_NbSlice,'String'));
@@ -4609,5 +4612,4 @@
     return
 else
-%     set(handles.ListObject,'Max',2);%allow multiple selection
     set(handles.ListObject,'Value',val);
     flag=1;
@@ -4634,5 +4636,18 @@
                         Y=ObjectData.Coord(:,2);
                         if testphys
-                            [X,Y]=px_XYZ(Calib,X,Y,0);% to generalise with 3D cases
+                            pos=[X Y zeros(size(X))];
+                            if isfield(Calib,'SliceCoord') && length(Calib.SliceCoord)>=3
+                                if isfield(Calib,'SliceAngle')&&~isequal(Calib.SliceAngle,[0 0 0])
+                                    om=norm(Calib.SliceAngle);%norm of rotation angle in radians
+                                    OmAxis=Calib.SliceAngle/om; %unit vector marking the rotation axis
+                                    cos_om=cos(pi*om/180);
+                                    sin_om=sin(pi*om/180);
+                                    pos=cos_om*pos+sin_om*cross(OmAxis,pos)+(1-cos_om)*(OmAxis*pos')*OmAxis;
+                                end
+                                pos(:,1)=pos(:,1)+Calib.SliceCoord(1);
+                                pos(:,2)=pos(:,2)+Calib.SliceCoord(2);
+                                pos(:,3)=pos(:,3)+Calib.SliceCoord(3);
+                            end                           
+                            [X,Y]=px_XYZ(Calib,pos(:,1),pos(:,2),pos(:,3));
                         end
                         flagobj=~inpolygon(Xi,Yi,X',Y');%=0 inside the polygon, 1 outside
@@ -4671,5 +4686,4 @@
         RootFile(1)=[];
     end
-   % filebase=fullfile(RootPath,RootFile);
     list=get(handles.masklevel,'String');
     masknumber=num2str(length(list));
