Home > . > set_grid.m

# set_grid

## PURPOSE

'set_grid':produce grid for PIV with one or two images (stereo case)

## SYNOPSIS

function varargout = set_grid(varargin)

## DESCRIPTION

    'set_grid':produce grid for PIV with one or two images (stereo case)
    ------------------------------------------------------------------------
     function varargout = set_grid(varargin)
     associated with the GUI set_grid.fig

    AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
      Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org.
    AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
         This file is part of the toolbox UVMAT.

         UVMAT is free software; you can redistribute it and/or modify
         it under the terms of the GNU General Public License as published by
         the Free Software Foundation; either version 2 of the License, or
         (at your option) any later version.

         UVMAT is distributed in the hope that it will be useful,
         but WITHOUT ANY WARRANTY; without even the implied warranty of
         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
         GNU General Public License (file UVMAT/COPYING.txt) for more details.
    AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

## CROSS-REFERENCE INFORMATION

This function calls:

- delete_object 'delete_object': delete a projection object, defined by its index in the Uvmat list or by its graphic handle
- imadoc2struct 'imadoc2struct': reads the xml file for image documentation
- msgbox_uvmat 'msgbox_uvmat': associated with GUI msgbox_uvmat.fig to display message boxes, for error, warning or input calls
- name2display 'name2display': extracts the root name and field numbers from an input filename
- px_XYZ 'px_XYZ': transform phys coordinates to image coordinates (px)
- read_set_object 'read_set_object': read the data on the 'set_object' interface
- set_title 'set_title': defines the 'TITLE' of a projection object
- update_obj 'update_obj': update the object graph representation and its projection field, record it in the uvmat interface
- uvmat 'uvmat': function associated with the GUI 'uvmat.fig' for images and data field visualization
- warndlg_uvmat 'warndlg_uvmat': display warning message (error, warning, confirmation) in a given figure

This function is called by:

- uvmat 'uvmat': function associated with the GUI 'uvmat.fig' for images and data field visualization

## SUBFUNCTIONS

- function set_grid_OpeningFcn(hObject, eventdata, handles,inputfile)
- function varargout = set_grid_OutputFcn(hObject, eventdata, handles)
- function ObjectStyle_Callback(hObject, eventdata, handles)
- function xObject_Callback(hObject, eventdata, handles)
- function yObject_Callback(hObject, eventdata, handles)
- function zObject_Callback(hObject, eventdata, handles)
- function ProjMode_Callback(hObject, eventdata, handles)
- function TITLE_Callback(hObject, eventdata, handles)
- function update_parentbutton(ParentButton,titl)
- function Phi_Callback(hObject, eventdata, handles)
- function Theta_Callback(hObject, eventdata, handles)
- function update_slider(hObject, eventdata,handles)
- function DX_Callback(hObject, eventdata, handles)
- function DY_Callback(hObject, eventdata, handles)
- function DZ_Callback(hObject, eventdata, handles)
- function import_Callback(hObject, eventdata, handles)
- function closefcn(gcbo,eventdata)
- function edit_Callback(hObject, eventdata, handles)
- function MenuCoord_Callback(hObject, eventdata, handles)
- function delete_Callback(hObject, eventdata, handles)
- function YMin_Callback(hObject, eventdata, handles)
- function ZMin_Callback(hObject, eventdata, handles)
- function ZMax_Callback(hObject, eventdata, handles)
- function YMax_Callback(hObject, eventdata, handles)
- function XMin_Callback(hObject, eventdata, handles)
- function XMax_Callback(hObject, eventdata, handles)
- function save_Callback(hObject, eventdata, handles)
- function TITLE=set_title(Style,ProjMode)
- function z_slider_Callback(hObject, eventdata, handles)
- function XObject_Callback(hObject, eventdata, handles)
- function YObject_Callback(hObject, eventdata, handles)
- function ZObject_Callback(hObject, eventdata, handles)
- function image_2_Callback(hObject, eventdata, handles)
- function image_1_Callback(hObject, eventdata, handles)
- function HELP_Callback(hObject, eventdata, handles)

## SOURCE CODE

    0001 %'set_grid':produce grid for PIV with one or two images (stereo case)
    0002 %------------------------------------------------------------------------
    0003 % function varargout = set_grid(varargin)
    0004 % associated with the GUI set_grid.fig
    0005 %
    0006 %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    0007 %  Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org.
    0008 %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    0009 %     This file is part of the toolbox UVMAT.
    0010 %
    0011 %     UVMAT is free software; you can redistribute it and/or modify
    0012 %     it under the terms of the GNU General Public License as published by
    0013 %     the Free Software Foundation; either version 2 of the License, or
    0014 %     (at your option) any later version.
    0015 %
    0016 %     UVMAT is distributed in the hope that it will be useful,
    0017 %     but WITHOUT ANY WARRANTY; without even the implied warranty of
    0018 %     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    0019 %     GNU General Public License (file UVMAT/COPYING.txt) for more details.
    0020 %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    0021
    0022 function varargout = set_grid(varargin)
    0023
    0024 % Last Modified by GUIDE v2.5 04-Feb-2008 16:05:02
    0025
    0026 % Begin initialization code - DO NOT EDIT
    0027 gui_Singleton = 1;
    0028 gui_State = struct('gui_Name',       mfilename, ...
    0029                    'gui_Singleton',  gui_Singleton, ...
    0030                    'gui_OpeningFcn', @set_grid_OpeningFcn, ...
    0031                    'gui_OutputFcn',  @set_grid_OutputFcn, ...
    0032                    'gui_LayoutFcn',  [] , ...
    0033                    'gui_Callback',   []);
    0034 if nargin & isstr(varargin{1})
    0035     gui_State.gui_Callback = str2func(varargin{1});
    0036 end
    0037
    0038 if nargout
    0039     [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
    0040 else
    0041     gui_mainfcn(gui_State, varargin{:});
    0042 end
    0043 % End initialization code - DO NOT EDIT
    0044
    0045 %-------------------------------------------------------------------
    0046 % --- Executes just before set_grid is made visible.
    0047 %INPUT:
    0048 % handles: handles of the set_grid interface elements
    0049 %'IndexObj': index of the object (on the UvData list) that set_grid will modify
    0050 %        if =[] or absent: index still undefined (create mode in uvmat)
    0051 %        if=0; no associated object (used for series), the button 'PLOT' is  then unvisible
    0052 %'data': read from an existing object selected in the interface
    0053 %      .TITLE : class of object ('POINTS','LINE',....)
    0054 %      .DX,DY,DZ; meshes for regular grids
    0055 %      .Coord: object position coordinates
    0056 %      .ParentButton: handle of the uicontrol object calling the interface
    0057 % PlotHandles: set of handles of the elements contolling the plotting of the projected field:
    0058 %  if =[] or absent, no plot (mask mode in uvmat)
    0059 % parameters on the uvmat interface (obtained by 'get_plot_handle.m')
    0060 function set_grid_OpeningFcn(hObject, eventdata, handles,inputfile)
    0061
    0062 % Choose default command line output for set_grid
    0063 handles.output = hObject;
    0064
    0065 % Update handles structure
    0066 guidata(hObject, handles);
    0067
    0068 %default
    0069 % set(hObject,'Unit','Normalized')% set the unit normalized to the screen size
    0070 % set(hObject,'Position',[0.7 0.1 0.25 0.5])%set the position of the set_grid interface
    0071 set(hObject,'DeleteFcn',@closefcn)
    0072 set(handles.TITLE,'Value',1)
    0073 set(handles.ObjectStyle,'Value',1)
    0074 set(handles.ProjMode,'Value',1)
    0075 set(handles.MenuCoord,'ListboxTop',1)
    0076 set(handles.MenuCoord,'Value',1);
    0077 set(handles.MenuCoord,'String',{'phys';'px'});
    0078 if exist('inputfile','var')& ~isempty(inputfile)
    0079    set(handles.image_1,'String',inputfile)
    0080    set(handles.image_2,'String',inputfile)
    0081 end
    0082
    0083
    0084 % --- Outputs from this function are returned to the command line.
    0085 function varargout = set_grid_OutputFcn(hObject, eventdata, handles)
    0086 % varargout  cell array for returning output args (see VARARGOUT);
    0087 % hObject    handle to figure
    0088 % eventdata  reserved - to be defined in a future version of MATLAB
    0089 % handles    structure with handles and user data (see GUIDATA)
    0090
    0091 % Get default command line output from handles structure
    0092 varargout{1} = handles.output;
    0093 varargout{2}=handles;
    0094
    0095 % --- Executes on selection change in ObjectStyle.
    0096 function ObjectStyle_Callback(hObject, eventdata, handles)
    0097
    0098 ProjMode_Callback(hObject, eventdata, handles)
    0099
    0100 %----------------------------------------------
    0101 function xObject_Callback(hObject, eventdata, handles)
    0102
    0103
    0104 function yObject_Callback(hObject, eventdata, handles)
    0105
    0106
    0107 % --- Executes on selection change in zObject.
    0108 function zObject_Callback(hObject, eventdata, handles)
    0109
    0110
    0111 %---------------------------------------------------
    0112 % --- Executes on selection change in ProjMode.
    0113 function ProjMode_Callback(hObject, eventdata, handles)
    0114 menu=get(handles.ProjMode,'String');
    0115 value=get(handles.ProjMode,'Value');
    0116 ProjMode=menu{value};
    0117 menu=get(handles.ObjectStyle,'String');
    0118 value=get(handles.ObjectStyle,'Value');
    0119 ObjectStyle=menu{value};
    0120 test3D=isequal(get(handles.ZObject,'Visible'),'on');%3D case
    0121 if isequal(ObjectStyle,'plane')||isequal(ObjectStyle,'volume')
    0122     set(handles.Phi,'Visible','on')
    0123     if test3D%3D case
    0124         set(handles.Theta,'Visible','on')
    0125         set(handles.Psi,'Visible','on')
    0126     end
    0127     set(handles.XMin,'Visible','on')
    0128     set(handles.XMax,'Visible','on')
    0129     set(handles.YMin,'Visible','on')
    0130     set(handles.YMax,'Visible','on')
    0131     if test3D
    0132         set(handles.Theta,'Visible','on')
    0133         set(handles.Psi,'Visible','on')
    0134         set(handles.ZMin,'Visible','on')
    0135         set(handles.ZMax,'Visible','on')
    0136     end
    0137 else
    0138     set(handles.Phi,'Visible','off')
    0139     set(handles.Theta,'Visible','off')
    0140     set(handles.Psi,'Visible','off')
    0141     set(handles.XMin,'Visible','off')
    0142     set(handles.XMax,'Visible','off')
    0143     set(handles.YMin,'Visible','off')
    0144     if isequal(ProjMode,'interp')
    0145         set(handles.YMax,'Visible','off')
    0146     else
    0147         set(handles.YMax,'Visible','on')
    0148     end
    0149     if isequal(ObjectStyle,'rectangle')|isequal(ObjectStyle,'ellipse')
    0150         set(handles.XMax,'Visible','on')
    0151     else
    0152        set(handles.XMax,'Visible','off')
    0153     end
    0154     set(handles.ZMin,'Visible','off')
    0155     set(handles.ZMax,'Visible','off')
    0156 end
    0157 if isequal(ProjMode,'projection')|isequal(ProjMode,'inside')|isequal(ProjMode,'outside')|isequal(ObjectStyle,'points')
    0158     set(handles.DX,'Visible','off')
    0159     set(handles.DY,'Visible','off')
    0160     set(handles.DZ,'Visible','off')
    0161 else
    0162     set(handles.DX,'Visible','on')
    0163     set(handles.DY,'Visible','on')
    0164     if test3D%3D case
    0165         set(handles.DZ,'Visible','on')
    0166     end
    0167 end
    0168
    0169 %---------------------------------------------
    0170 % --- Executes on selection change in TITLE.
    0171 function TITLE_Callback(hObject, eventdata, handles)
    0172 hsetobject=get(handles.TITLE,'parent');
    0173 SetData=get(hsetobject,'UserData');%get the hidden interface data
    0174 %      function named CALLBACK in UNTITLED.M with the given input arguments.
    0175 menu=get(handles.TITLE,'String');
    0176 value=get(handles.TITLE,'Value');
    0177 titl=menu{value};
    0178 if isequal(titl,'POINTS')
    0179      menu_style={'points'};
    0180      menu_proj={'projection';'interp';'filter';'none'};
    0181 elseif isequal(titl,'LINE')
    0182      menu_style={'line';'polyline';'rectangle';'polygon';'ellipse'};%'line' =default
    0183      menu_proj={'projection';'interp';'filter';'none'};
    0184 elseif isequal(titl,'PATCH')
    0185      menu_style={'rectangle';'polygon';'ellipse'};%'line' =default
    0186      menu_proj={'inside';'outside';'none'};
    0187  elseif isequal(titl,'PLANE')
    0188      menu_style={'plane'};
    0189      menu_proj={'projection';'interp'};
    0190 elseif isequal(titl,'VOLUME')
    0191      menu_style={'volume'};
    0192      menu_proj={'none'};
    0193
    0194 end
    0195 set(handles.ObjectStyle,'String',menu_style)
    0196 set(handles.ObjectStyle,'Value',1)
    0197 set(handles.ProjMode,'String',menu_proj)
    0198 set(handles.ProjMode,'Value',1)
    0199 if isfield(SetData,'ParentButton')
    0200     update_parentbutton(SetData.ParentButton,titl)
    0201 end
    0202 ObjectStyle_Callback(hObject, eventdata, handles)
    0203
    0204 %-----------
    0205 function update_parentbutton(ParentButton,titl)
    0206
    0207 if isstruct(ParentButton)
    0208     parentfields=fields(ParentButton);
    0209     for ibutton=1:length(parentfields)
    0210         buttonhandle=eval(['ParentButton.' parentfields{ibutton}]);
    0211         if ishandle(buttonhandle)
    0212             set(buttonhandle,'Value',0)
    0213             set(buttonhandle,'BackgroundColor',[0 1 0])%put unactivated buttons to green
    0214         end
    0215     end
    0216     if isfield(ParentButton,titl)
    0217        buttonhandle=eval(['ParentButton.' titl]);
    0218        if ishandle(buttonhandle)
    0219             set(buttonhandle,'Value',1)
    0220             set(buttonhandle,'BackgroundColor',[1 1 0])%put activated button to yellow
    0221        end
    0222     end
    0223 end
    0224 %------------
    0225 function Phi_Callback(hObject, eventdata, handles)
    0226 update_slider(hObject, eventdata,handles)
    0227
    0228 function Theta_Callback(hObject, eventdata, handles)
    0229 update_slider(hObject, eventdata,handles)
    0230
    0231 function update_slider(hObject, eventdata,handles)
    0232 %rotation angles
    0233 Phi=(pi/180)*str2num(get(handles.Phi,'String'));%first Euler angle in radian
    0234 Theta=(pi/180)*str2num(get(handles.Theta,'String'));%second Euler angle in radian
    0235
    0236 %components of the unitiy vector normal to the projection plane
    0237 NormVec_X=-sin(Phi)*sin(Theta);
    0238 NormVec_Y=cos(Phi)*sin(Theta);
    0239 NormVec_Z=cos(Theta);
    0240 huvmat=findobj('Tag','uvmat');%find the current uvmat interface handle
    0241 UvData=get(huvmat,'UserData');%Data associated to the current uvmat interface
    0242 Z=NormVec_X *(UvData.X)+NormVec_Y *(UvData.Y)+NormVec_Z *(UvData.Z);
    0243 set(handles.z_slider,'Min',min(Z))
    0244 set(handles.z_slider,'Max',max(Z))
    0245 ZMax_Callback(hObject, eventdata, handles)
    0246
    0247 function DX_Callback(hObject, eventdata, handles)
    0248
    0249
    0250 function DY_Callback(hObject, eventdata, handles)
    0251
    0252
    0253 function DZ_Callback(hObject, eventdata, handles)
    0254
    0255
    0256
    0257 %-----------------------------------------------------
    0258 % --- Executes on button press in import.
    0259 function import_Callback(hObject, eventdata, handles)
    0260 %get the object file
    0261 oldfile='';
    0262 huvmat=findobj('Tag','uvmat');
    0263 if isempty(huvmat)
    0264     huvmat=findobj(allchild(0),'Name','series');
    0265 end
    0266 hchild=get(huvmat,'Children');
    0267 hrootpath=findobj(hchild,'Tag','RootPath');
    0268 oldfile=get(hrootpath,'String');
    0269 if iscell(oldfile)
    0270     oldfile=oldfile{1};
    0271 end
    0272 %[FileName,PathName] = uigetfile('*.civ','Select a .civ file',oldfile)
    0273 [FileName, PathName, filterindex] = uigetfile( ...
    0274        {'*.xml;*.mat', ' (*.xml,*.mat)';
    0275        '*.xml',  '.xml files '; ...
    0276         '*.mat',  '.mat matlab files '}, ...
    0277         'Pick a file',oldfile);
    0278 fileinput=[PathName FileName];%complete file name
    0279 testblank=findstr(fileinput,' ');%look for blanks
    0280 if ~isempty(testblank)
    0281     errordlg('forbidden input file name: contain blanks')
    0282     return
    0283 end
    0284 sizf=size(fileinput);
    0285 if (~ischar(fileinput)|~isequal(sizf(1),1)),return;end
    0286
    0287 %read the file
    0288  t=xmltree(fileinput);
    0289  s=convert(t);
    0290 %Display title
    0291 title=set_title(s.Style,s.ProjMode);%update the title
    0292 % menu=get(handles.TITLE,'String')
    0293 % for iline=1:length(menu)
    0294 %      if isequal(menu{iline},title)
    0295 %          set(handles.TITLE,'Value',iline)
    0296 %          break
    0297 %      end
    0298 % end
    0299 % TITLE_Callback(hObject, eventdata, handles)
    0300 % teststyle=0;
    0301 % if isfield(s,'Style')
    0302 %         menu=get(handles.ObjectStyle,'String');
    0303 %         for iline=1:length(menu)
    0304 %             if isequal(menu{iline},s.Style)
    0305 %                 set(handles.ObjectStyle,'Value',iline)
    0306 %                 teststyle=1;
    0307 %                 break
    0308 %             end
    0309 %         end
    0310 % end
    0311 % if teststyle==0;
    0312 %        s.Style='points';
    0313 %        set(handles.ObjectStyle,'Value',1); %default (points)
    0314 % end
    0315 testmode=0;
    0316 if isfield(s,'ProjMode')
    0317         menu=get(handles.ProjMode,'String');
    0318         for iline=1:length(menu)
    0319             if isequal(menu{iline},s.ProjMode)
    0320                 set(handles.ProjMode,'Value',iline)
    0321                 testmode=1;
    0322                 break
    0323             end
    0324         end
    0325 end
    0326
    0327 ProjMode_Callback(hObject, eventdata, handles);%visualize the appropriate edit boxes
    0328 if isfield(s,'CoordType')
    0329     if isequal(s.CoordType,'phys')
    0330         set(handles.MenuCoord,'Value',1)
    0331     elseif isequal(s.CoordType,'px')
    0332         set(handles.MenuCoord,'Value',2)
    0333     else
    0334         warndlg('unknown CoordType (px or phys) in set_grid.m')
    0335     end
    0336 end
    0337 if isfield(s,'XMax')
    0338     set(handles.XMax,'String',s.XMax)
    0339 end
    0340 if isfield(s,'XMin')
    0341     set(handles.XMin,'String',s.XMin)
    0342 end
    0343 if isfield(s,'YMax')
    0344     set(handles.YMax,'String',s.YMax)
    0345 end
    0346 if isfield(s,'YMin')
    0347     set(handles.YMin,'String',s.YMin)
    0348 end
    0349 if isfield(s,'DX')
    0350     set(handles.DX,'String',s.DX)
    0351 end
    0352 if isfield(s,'DY')
    0353     set(handles.DY,'String',s.DY)
    0354 end
    0355 if ~isfield(s,'Coord')
    0356     XObject='0';%default
    0357     YObject='0';
    0358 elseif ischar(s.Coord)
    0359     line=str2num(s.Coord);
    0360     XObject=num2str(line(1));
    0361     YObject=num2str(line(2));
    0362 else
    0363     for i=1:length(s.Coord)
    0364         line=str2num(s.Coord{i});
    0365         XObject{i}=num2str(line(1));
    0366         YObject{i}=num2str(line(2));
    0367     end
    0368 end
    0369 set(handles.XObject,'String',XObject)
    0370 set(handles.YObject,'String',YObject)
    0371 %METTRA A JOUR ASPECT DE L'INTERFACE (COMME set_grid_Opening
    0372
    0373 %----------------------------------------------------
    0374 % executed when closing: set the parent interface button to value 0
    0375 function closefcn(gcbo,eventdata)
    0376 huvmat=findobj(allchild(0),'Name','uvmat');%find the current uvmat interface handle
    0377 parent_button=findobj(huvmat,'Tag','grid');
    0378 if ~isempty(parent_button)
    0379     set(parent_button,'Value',0)%put unactivated buttons to green
    0380     tag=get(parent_button,'Tag');
    0381     if isequal(tag,'edit')
    0382         set(parent_button,'BackgroundColor',[0.7 0.7 0.7]);
    0383     else
    0384         set(parent_button,'BackgroundColor',[0 1 0]);
    0385     end
    0386 end
    0387
    0388 %-----------------------------------------------------------------------
    0389 % --- Executes on button press in edit: PLOT the defined object and its projected field
    0390 function edit_Callback(hObject, eventdata, handles)
    0391 hsetobject=get(hObject,'parent');
    0392 SetData=get(hsetobject,'UserData');%get the hidden interface data
    0393 %IndexObj=SetData.IndexObj%index of the current projection object in the list of projection objects (UvData.ProjObject)
    0394 huvmat=findobj('Tag','uvmat');%find the current uvmat interface handle
    0395 UvData=get(huvmat,'UserData');%Data associated to the current uvmat interface
    0396 if isfield(UvData,'CuurentObjectIndex')
    0397     IndexObj=UvData.CurrentObjectIndex;
    0398 else
    0399     IndexObj=[];
    0400 end
    0401 ObjectData=read_set_grid(handles);%read the interface input parameters defining the object
    0402 [UvData,IndexObj]=update_obj(UvData,IndexObj,ObjectData,SetData.PlotHandles);
    0403 uvmat('write_plot_param',PlotHandles,UvData.Object{IndexObj}.PlotParam); %update the display of plotting parameters for the current object
    0404 SetData.IndexObj=IndexObj;
    0405 set(gcbf,'UserData',SetData)%update object index in the set_grid interface
    0406 set(huvmat,'UserData',UvData)%update the data in the uvmat interface
    0407
    0408
    0409 % --- Executes on button press in MenuCoord.
    0410 function MenuCoord_Callback(hObject, eventdata, handles)
    0411
    0412
    0413 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    0414 % --- Executes on button press in delete.
    0415 function delete_Callback(hObject, eventdata, handles)
    0416
    0417 %SetData=get(gcbf,'UserData');%get the interface data
    0418 %IndexObj=SetData.IndexObj;
    0419 huvmat=findobj('Name','uvmat');%find the current uvmat interface handle
    0420 UvData=get(huvmat,'UserData');%Data associated to the current uvmat interface
    0421 if isfield(UvData,'CurrentObjectIndex')
    0422     IndexObj=UvData.CurrentObjectIndex;
    0423 else
    0424     IndexObj=[];
    0425 end
    0426 delete_object(IndexObj);
    0427
    0428 %----------------------------------------------------
    0429 function YMin_Callback(hObject, eventdata, handles)
    0430 % hObject    handle to YMin (see GCBO)
    0431 % eventdata  reserved - to be defined in a future version of MATLAB
    0432 % handles    structure with handles and user data (see GUIDATA)
    0433
    0434 % Hints: get(hObject,'String') returns contents of YMin as text
    0435 %        str2double(get(hObject,'String')) returns contents of YMin as a double
    0436
    0437
    0438 function ZMin_Callback(hObject, eventdata, handles)
    0439
    0440
    0441 function ZMax_Callback(hObject, eventdata, handles)
    0442 DZ=str2num(get(handles.ZMax,'String'));
    0443 ZMin=get(handles.z_slider,'Min');
    0444 ZMax=get(handles.z_slider,'Max');
    0445 rel_step(1)=DZ/(ZMax-ZMin);
    0446 rel_step(2)=0.2;
    0447 set(handles.z_slider,'SliderStep',rel_step)
    0448
    0449 function YMax_Callback(hObject, eventdata, handles)
    0450
    0451
    0452 function XMin_Callback(hObject, eventdata, handles)
    0453
    0454
    0455 function XMax_Callback(hObject, eventdata, handles)
    0456
    0457
    0458 % ------------------------------------------------------
    0459 function save_Callback(hObject, eventdata, handles)
    0460 % ------------------------------------------------------
    0461 Object=read_set_object(handles);%read the set_grid interface;
    0462 DX=Object.DX;
    0463 DY=Object.DY;
    0464 RangeX=Object.RangeX;
    0465 RangeY=Object.RangeY;
    0466  array_realx=[RangeX(2):DX:RangeX(1)];
    0467  array_realy=[RangeY(2):DY:RangeY(1)];
    0468  nx_patch=length(array_realx);
    0469  ny_patch=length(array_realy);
    0470  [grid_realx,grid_realy]=meshgrid(array_realx,array_realy);
    0471  grid_real(:,1)=reshape(grid_realx,nx_patch*ny_patch,1);
    0472  grid_real(:,2)=reshape(grid_realy,nx_patch*ny_patch,1);
    0473  grid_real(:,3)=zeros(nx_patch*ny_patch,1);
    0474
    0475 imageA=get(handles.image_1,'String');
    0476 imageB=get(handles.image_2,'String');
    0477 testB=1;
    0478 if isempty(imageA) | isequal(imageA,'')
    0479     if isempty(imageB) | isequal(imageB,'')
    0480         warndlg_uvmat('at least one image file name must be introduced','ERROR')
    0481     else
    0482         imageA=imageB;
    0483         testB=0;
    0484     end
    0485 end
    0486 if isempty(imageB) || isequal(imageB,'') || isequal(imageA,imageB)
    0487     testB=0;
    0488 end
    0489
    0490 testexist=exist(imageA,'file');
    0491 if isequal(testexist,0)
    0492     warndlg_uvmat(['input image file' imageA 'does not exist'],'ERROR')
    0493     return
    0494 end
    0495 [Pathsub,RootFile,field_count,str2,str_a,str_b,ext,nom_type,subdir]=name2display(imageA);
    0496 form=imformats(ext([2:end]));
    0497 if isempty(form)% if the extension corresponds to an image format recognized by Matlab
    0498      warndlg_uvmat(['error in read_image.m: ' imageA ' is not an image name recognized by Matlab '],'ERROR')
    0499      return
    0500 end
    0501 fileAxml=[fullfile(Pathsub,RootFile) '.xml'];
    0502 [XmlDataA,error]=imadoc2struct(fileAxml);
    0503 if isfield(XmlDataA,'GeometryCalib')
    0504      tsaiA=XmlDataA.GeometryCalib;
    0505  else
    0506      msgbox_uvmat('WARNING','no geometric calibration available for image A')
    0507      tsaiA=[];
    0508  end
    0509 %[error,Heading,nom_type_read,ext_ima_read,time,TimeUnit,mode,NbSlice,...
    0510 %npxA,npyA,tsaiA]=read_imadoc(fileAxml,0);
    0511 [grid_imaA(:,1),grid_imaA(:,2)]=px_XYZ(tsaiA,grid_real(:,1),grid_real(:,2),0);
    0512 % if isempty(npxA)
    0513     A=imread(imageA);
    0514    siz=size(A);
    0515    npxA=siz(2);
    0516    npyA=siz(1);
    0517 % end
    0518 flagA=grid_imaA(:,1)>0 & grid_imaA(:,1)<npxA & grid_imaA(:,2)>0 & grid_imaA(:,2)<npyA;
    0519
    0520 if testB
    0521     testexist=exist(imageB,'file');
    0522     if isequal(testexist,0)
    0523         warndlg_uvmat(['input image file' imageB 'does not exist'],'ERROR')
    0524         return
    0525     end
    0526     [Pathsub,RootFile,field_count,str2,str_a,str_b,ext,nom_type,subdir]=name2display(imageB);
    0527     form=imformats(ext([2:end]));
    0528     if isempty(form)% if the extension corresponds to an image format recognized by Matlab
    0529          warndlg_uvmat(['error in read_image.m: ' imageB ' is not an image name recognized by Matlab '],'ERROR')
    0530          return
    0531     end
    0532     fileBxml=[fullfile(Pathsub,RootFile) '.xml'];
    0533     [XmlDataB,error]=imadoc2struct(fileBxml);
    0534     if isfield(XmlDataB,'GeometryCalib')
    0535      tsaiB=XmlDataB.GeometryCalib;
    0536     else
    0537      warndlg_uvmat('no geometric calibration available for image B','WARNING')
    0538      tsaiB=[];
    0539  end
    0540     %[error,Heading,nom_type_read,ext_ima_read,time,TimeUnit,mode,NbSlice,...
    0541     %     npxB,npyB,tsaiB]=read_imadoc(fileBxml,0);
    0542     [grid_imaB(:,1),grid_imaB(:,2)]=px_XYZ(tsaiB,grid_real(:,1),grid_real(:,2),0);
    0543 %     if isempty(npxB)|isempty(npyB)
    0544         B=imread(imageB);
    0545        siz=size(B);
    0546        npxB=siz(2);
    0547        npyB=siz(1);
    0548 %     end
    0549     flagB=grid_imaB(:,1)>0 & grid_imaB(:,1)<npxB & grid_imaB(:,2)>0 & grid_imaB(:,2)<npyB;
    0550 end
    0551 if testB
    0552     ind_good=find(flagA==1&flagB==1);
    0553     XimaB=grid_imaB(ind_good,1);
    0554     YimaB=grid_imaB(ind_good,2);
    0555 else
    0556     ind_good=find(flagA==1);
    0557 end
    0558 XimaA=grid_imaA(ind_good,1);
    0559 YimaA=grid_imaA(ind_good,2);
    0560
    0561 grid_real_x=grid_real(ind_good,1);
    0562 grid_real_y=grid_real(ind_good,2);
    0563 nx_patch_new=length(grid_real_x);
    0564 grid_real2(:,1)=grid_real_x;
    0565 grid_real2(:,2)=grid_real_y;
    0566 grid_real2(:,3)=zeros(nx_patch_new,1);
    0567 [grid_pix_A(:,1),grid_pix_A(:,2)]=px_XYZ(tsaiA,grid_real2(:,1),grid_real2(:,2));
    0568 if testB
    0569     [grid_pix_B(:,1),grid_pix_B(:,2)]=px_XYZ(tsaiB,grid_real2(:,1),grid_real2(:,2));
    0570 end
    0571
    0572  %ECRIRE FICHIERS
    0573 nbpointsA=size(grid_pix_A);
    0574 XA=grid_pix_A(:,1);
    0575 YA=grid_pix_A(:,2);
    0576 unitcolumn=32*ones(size(XA));
    0577 Xchar=num2str(XA);
    0578 blanc=char(unitcolumn);
    0579 Ychar=num2str(YA);
    0580 tete=['1 ' num2str(nbpointsA(1))];
    0581 txt=[Xchar blanc Ychar];
    0582 textgrid={tete;txt};
    0583 textout=char(textgrid);
    0584 Answer = msgbox_uvmat('INPUT_TXT','grid file name (*.grid)',fullfile(Pathsub,'gridA.grid'));
    0585 % Answer = inputdlg('grid file name (*.grid)',' ',1,{fullfile(Pathsub,'gridA.grid')},'on');
    0586 dlmwrite(Answer,textout,'');
    0587 msgbox_uvmat('CONFIRMATION',[Answer ' written as ASCII text file']);
    0588 if testB
    0589     nbpointsB=size(grid_pix_B);
    0590     XB=grid_pix_B(:,1);
    0591     YB=grid_pix_B(:,2);
    0592     unitcolumn=32*ones(size(XB));
    0593     Xchar=num2str(XB);
    0594     blanc=char(unitcolumn);
    0595     Ychar=num2str(YB);
    0596     tete=['1 ' num2str(nbpointsB(1))];
    0597     txt=[Xchar blanc Ychar];
    0598     textgrid={tete;txt};
    0599     textout=char(textgrid);
    0600     Answer = msgbox_uvmat('INPUT_TXT','grid file name (*.grid)',fullfile(Pathsub,'gridB.grid'));
    0601     dlmwrite(Answer,textout,'');
    0602     msgbox_uvmat('CONFIRMATION',[Answer ' written as ASCII text file']);
    0603 end
    0604
    0605
    0606 %------------------------------------------------
    0607 function TITLE=set_title(Style,ProjMode)
    0608 %------------------------------------------------
    0609 if isequal(Style,'points')
    0610     TITLE='POINTS';
    0611 elseif isequal(Style,'line')|isequal(Style,'polyline')
    0612     TITLE='LINE';
    0613 elseif isequal(Style,'plane')
    0614     TITLE='PLANE';
    0615 elseif isequal(Style,'volume')
    0616     TITLE='VOLUME';
    0617 elseif isequal(Style,'polygon')|isequal(Style,'rectangle')|isequal(Style,'ellipse')
    0618     if isequal(ProjMode,'inside')|isequal(ProjMode,'outside')
    0619         TITLE='PATCH';
    0620     else
    0621         TITLE='LINE';
    0622     end
    0623 end
    0624
    0625
    0626 % --- Executes on slider movement.
    0627 function z_slider_Callback(hObject, eventdata, handles)
    0628 %A ADAPTER
    0629 Z_value=get(handles.z_slider,'Value');
    0630
    0631 %rotation angles
    0632 Phi=(pi/180)*str2num(get(handles.Phi,'String'));%first Euler angle in radian
    0633 Theta=(pi/180)*str2num(get(handles.Theta,'String'));%second Euler angle in radian
    0634
    0635 %components of the unity vector normal to the projection plane
    0636 NormVec_X=-sin(Phi)*sin(Theta);
    0637 NormVec_Y=cos(Phi)*sin(Theta);
    0638 NormVec_Z=cos(Theta);
    0639
    0640 %set new plane position and update graph
    0641 set(handles.XObject,'String',num2str(NormVec_X*Z_value))
    0642 set(handles.YObject,'String',num2str(NormVec_Y*Z_value))
    0643 set(handles.ZObject,'String',num2str(NormVec_Z*Z_value))
    0644 edit_Callback(hObject, eventdata, handles)
    0645
    0646
    0647
    0648 function XObject_Callback(hObject, eventdata, handles)
    0649
    0650
    0651 function YObject_Callback(hObject, eventdata, handles)
    0652
    0653
    0654
    0655
    0656 function ZObject_Callback(hObject, eventdata, handles)
    0657
    0658
    0659 function image_2_Callback(hObject, eventdata, handles)
    0660 % hObject    handle to image_2 (see GCBO)
    0661 % eventdata  reserved - to be defined in a future version of MATLAB
    0662 % handles    structure with handles and user data (see GUIDATA)
    0663
    0664 % Hints: get(hObject,'String') returns contents of image_2 as text
    0665 %        str2double(get(hObject,'String')) returns contents of image_2 as a double
    0666
    0667
    0668
    0669 function image_1_Callback(hObject, eventdata, handles)
    0670 % hObject    handle to image_1 (see GCBO)
    0671 % eventdata  reserved - to be defined in a future version of MATLAB
    0672 % handles    structure with handles and user data (see GUIDATA)
    0673
    0674 % Hints: get(hObject,'String') returns contents of image_1 as text
    0675 %        str2double(get(hObject,'String')) returns contents of image_1 as a double
    0676
    0677
    0678 % --- Executes on button press in HELP.
    0679 function HELP_Callback(hObject, eventdata, handles)
    0680 path_to_uvmat=which ('uvmat');% check the path of uvmat
    0681 pathelp=fileparts(path_to_uvmat);
    0682 helpfile=fullfile(pathelp,'UVMAT_DOC','uvmat_doc.html');
    0683 if isempty(dir(helpfile)), errordlg('Please put the help file uvmat_doc.html in the directory UVMAT/UVMAT_DOC')
    0684 else
    0685 web([helpfile '#set_grid'])
    0686 end
    0687