| 1 | %'uvmat': function associated with the GUI 'uvmat.fig' for images and data field visualization |
|---|
| 2 | %------------------------------------------------------------------------ |
|---|
| 3 | % function huvmat=uvmat(input) |
|---|
| 4 | % |
|---|
| 5 | %OUTPUT |
|---|
| 6 | % huvmat=current handles of the GUI uvmat.fig |
|---|
| 7 | %% |
|---|
| 8 | % |
|---|
| 9 | %INPUT: |
|---|
| 10 | % input: input file name (if character chain), or input image matrix to |
|---|
| 11 | % visualize, or Matlab structure representing netcdf fieldname (with fieldname |
|---|
| 12 | % ListVarName....) |
|---|
| 13 | % |
|---|
| 14 | %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA |
|---|
| 15 | % Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, joel.sommeria@legi.grenoble-inp.fr. |
|---|
| 16 | %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA |
|---|
| 17 | % This open is part of the toolbox UVMAT. |
|---|
| 18 | % |
|---|
| 19 | % UVMAT is free software; you can redistribute it and/or modify |
|---|
| 20 | % it under the terms of the GNU General Public License as published by |
|---|
| 21 | % the Free Software Foundation; either version 2 of the License, or |
|---|
| 22 | % (at your option) any later version. |
|---|
| 23 | % |
|---|
| 24 | % UVMAT is distributed in the hope that it will be useful, |
|---|
| 25 | % but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 26 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 27 | % GNU General Public License (open UVMAT/COPYING.txt) for more details. |
|---|
| 28 | %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA |
|---|
| 29 | % |
|---|
| 30 | % Information stored on the interface:(use 'Export/field in workspace' in |
|---|
| 31 | % the menu bar of uvmat to retrieve it) |
|---|
| 32 | % .OpenParam: structure containing parameters defined when uvmat is opened |
|---|
| 33 | % .PosColorbar: position (1x4 vector)of the colorbar (relative to the fig uvmat) |
|---|
| 34 | % .PosGeometryCalib: size of set_object |
|---|
| 35 | % .NbBuiltin: nbre of functions always displayed in TransformName menu |
|---|
| 36 | % .ProjObject: cell array of structures representing the current projection objects, as produced by 'set_object.m'={[]} by default |
|---|
| 37 | % .NewSeries: =0/1 flag telling whether a new field series has been opened |
|---|
| 38 | % .FileName_1: name of the current second field (used to detect a constant field during file scanning) |
|---|
| 39 | % .FileType: current file type, as defined by the fct get_file_type.m) |
|---|
| 40 | % .i1_series,.i2_series,.j1_series,.j1_series: series of i1,i2,j1,j2 indices detected in the input dir,set by the fct find_file_series |
|---|
| 41 | % .MovieObject: current movie object |
|---|
| 42 | % .TimeUnit: unit for time |
|---|
| 43 | % .XmlData: cell array of 1 or 2 structures representing the xml files associated with the input fieldname (containing timing and geometry calibration) |
|---|
| 44 | % .Field: cell array of 1 or 2 structures representing the current input field(s) |
|---|
| 45 | % .PlotAxes: field structure representing the current field plotted on the main axes (used for mouse operations) |
|---|
| 46 | % .HistoAxes: idem for histogram axes |
|---|
| 47 | |
|---|
| 48 | % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DATA FLOW (for REFRESH_Callback) %%%%%%%%%%%%%%%%%%%%: |
|---|
| 49 | % |
|---|
| 50 | % |
|---|
| 51 | % 1) Input filenames are determined by MenuBrowse (first field), MenuBrowseCampaign |
|---|
| 52 | % (second field), or by the stored file name .FileName_1, or as an input of uvmat. |
|---|
| 53 | % 2) These functions call 'uvmat/display_file_name.m' which detects the file series, and fills the file index boxes |
|---|
| 54 | % 3) Then 'uvmat/update_rootinfo.m' Updates information about a new field series (indices to scan, timing, calibration from an xml file) |
|---|
| 55 | % 4) Then fieldname are opened and visualised by the main sub-function 'uvmat/refresh_field.m' |
|---|
| 56 | % The function first reads the name of the input file(s) (one or two) from the edit boxes of the GUI |
|---|
| 57 | % It then reads the input file(s) with the function read_field.m and perform the following list of operations: |
|---|
| 58 | % |
|---|
| 59 | % %%%%%%%% structure of uvmat/refresh_field.m %%%%%%%% |
|---|
| 60 | % |
|---|
| 61 | % Main input open second input open_1 |
|---|
| 62 | % | | |
|---|
| 63 | % read_field.m read_field.m |
|---|
| 64 | % | | |
|---|
| 65 | % Field{1} Field{2} |
|---|
| 66 | % | | |
|---|
| 67 | % --->transform fct<--- transform (e.g. phys.m) and combine input fieldname |
|---|
| 68 | % | |
|---|
| 69 | % (tps_coeff_field.m) calculate tps coefficients (for filter projection or spatial derivatives). |
|---|
| 70 | % | |
|---|
| 71 | % UvData.Field-------------->histogram |
|---|
| 72 | % _____________|____________ |
|---|
| 73 | % | | |
|---|
| 74 | % proj_field.m proj_field.m project the field on the projection objects (use set_field_list.m) |
|---|
| 75 | % | | |
|---|
| 76 | % UvData.PlotAxes ViewData.PlotAxes (on view_field) |
|---|
| 77 | % | | |
|---|
| 78 | % plot_field.m (uvmat) plot_field.m (view_field) plot the projected fieldname |
|---|
| 79 | % |
|---|
| 80 | % |
|---|
| 81 | %%%%%%%%%%%%%% SCALARS: %%%%%%%%%%%%??%%% |
|---|
| 82 | % scalars are displayed either as an image or countour plot, either as a color of |
|---|
| 83 | % velocity vectors. The scalar values in the first case is represented by |
|---|
| 84 | % UvData.Field.A, and by UvData.Field.C in the second case. The corresponding set of X |
|---|
| 85 | % and Y axes are represented by UvData.Field.Coord_x and UvData.Field.Coord_y, and .X and |
|---|
| 86 | % .Y for C (the same as velocity vectors). If A is a nxxny matrix (scalar |
|---|
| 87 | % on a regtular grid), then .Coord_x andf.Coord_y contains only two elements, represneting the |
|---|
| 88 | % axes of the four image corners. The scalar name is represented by |
|---|
| 89 | % the strings .AName and/or .CName. |
|---|
| 90 | % If the scalar exists in an input open (image or scalar stored under its |
|---|
| 91 | % name in a netcdf open), it is directly read at the level of Field{1}or Field{2}. |
|---|
| 92 | % Else only its name AName is recorded in Field{i}, and its field is then calculated |
|---|
| 93 | %by the fuction calc_scal after the coordinate transform or after projection on an CheckEditObject |
|---|
| 94 | |
|---|
| 95 | % Properties attached to plotting figures (standard Matlab properties): |
|---|
| 96 | % 'CurrentAxes'= gca or get(gcf,'CurrentAxes'); |
|---|
| 97 | % 'CurrentPoint'=get(gcf,'CurrentPoint'): figure axes of the point over which the mouse is positioned |
|---|
| 98 | % 'CurrentCharacter'=get(gcf,'CurrentCharacter'): last character typed over the figure where the mouse is positioned |
|---|
| 99 | % 'WindowButtonMotionFcn': function permanently called by mouse motion over the figure |
|---|
| 100 | % 'KeyPressFcn': function called by pressing a key on the key board |
|---|
| 101 | % 'WindowButtonDownFcn': function called by pressing the mouse over the figure |
|---|
| 102 | % 'WindowButtonUpFcn': function called by releasing the mouse pressure over the figure |
|---|
| 103 | |
|---|
| 104 | % Properties attached to plotting axes: |
|---|
| 105 | % 'CurrentPoint'=get(gca,'CurrentPoint'); (standard Matlab) same as for the figure, but position in plot axes. |
|---|
| 106 | % AxeData:=get(gca,'UserData'); |
|---|
| 107 | % AxeData.Drawing = create: create a new object |
|---|
| 108 | % = deform: modify an existing object by moving its defining create |
|---|
| 109 | % = off: no current drawing action |
|---|
| 110 | % = translate: translate an existing object |
|---|
| 111 | % = calibration: move a calibration point |
|---|
| 112 | % = CheckZoom: isolate a subregion for CheckZoom in=1 if an object is being currently drawn, 0 else (set to 0 by releasing mouse button) |
|---|
| 113 | % .CurrentOrigin: Origin of a curently drawn CheckEditObject |
|---|
| 114 | % .CurrentLine: currently drawn menuline (A REVOIR) |
|---|
| 115 | % .CurrentObject: handle of the currently drawn CheckEditObject |
|---|
| 116 | % .CurrentRectZoom: current rectangle used for CheckZoom |
|---|
| 117 | |
|---|
| 118 | % Properties attached to projection objects (create, menuline, menuplane...): |
|---|
| 119 | % 'Tag'='proj_object': for all projection objects |
|---|
| 120 | % ObjectData.Type=...: style of projection object: |
|---|
| 121 | % .ProjMode |
|---|
| 122 | % .Coordinates: defines the position of the object |
|---|
| 123 | % .XMin,YMin.... |
|---|
| 124 | % .XMax,YMax.... |
|---|
| 125 | % .DX,DY,DZ |
|---|
| 126 | % .Phi, .Theta, .Psi : Euler angles |
|---|
| 127 | % .X,.Y,.U,.V.... : field data projected on the object |
|---|
| 128 | % .IndexObj: index in the list of UvData.ProjObject |
|---|
| 129 | %during plotting |
|---|
| 130 | % .plotaxes: handles of the current axes used to plot the result of field projection on the object |
|---|
| 131 | % .plothandle: vector of handle(s) of the object graphic represnetation in all the opened plotting axes |
|---|
| 132 | % To each projection object #iobj, corresponds an axis |
|---|
| 133 | % Object{iobj}.plotaxes and nbobj representation graphs Object{iobj}.plothandles(:) (where nbobj is the |
|---|
| 134 | % nbre of current objects opened in uvmat. Note that Object{iobj}.plothandles(iobj)=[] : an object is not represented in its own projection field; |
|---|
| 135 | |
|---|
| 136 | %------------------------------------------------------------------------ |
|---|
| 137 | %------------------------------------------------------------------------ |
|---|
| 138 | % I - MAIN FUNCTION uvmat |
|---|
| 139 | %------------------------------------------------------------------------ |
|---|
| 140 | %------------------------------------------------------------------------ |
|---|
| 141 | function varargout = uvmat(varargin) |
|---|
| 142 | |
|---|
| 143 | % Begin initialization code - DO NOT EDIT |
|---|
| 144 | gui_Singleton = 1; |
|---|
| 145 | gui_State = struct('gui_Name', mfilename, ... |
|---|
| 146 | 'gui_Singleton', gui_Singleton, ... |
|---|
| 147 | 'gui_OpeningFcn', @uvmat_OpeningFcn, ... |
|---|
| 148 | 'gui_OutputFcn', @uvmat_OutputFcn, ... |
|---|
| 149 | 'gui_LayoutFcn', [], ... |
|---|
| 150 | 'gui_Callback', []); |
|---|
| 151 | if nargin && ischar(varargin{1})&& ~isempty(regexp(varargin{1},'_Callback','once')) |
|---|
| 152 | gui_State.gui_Callback = str2func(varargin{1}); |
|---|
| 153 | end |
|---|
| 154 | |
|---|
| 155 | if nargout |
|---|
| 156 | varargout{1:nargout} = gui_mainfcn(gui_State, varargin{:}); |
|---|
| 157 | else |
|---|
| 158 | gui_mainfcn(gui_State, varargin{:}); |
|---|
| 159 | end |
|---|
| 160 | % End initialization code - DO NOT EDIT |
|---|
| 161 | |
|---|
| 162 | %------------------------------------------------------------------------ |
|---|
| 163 | % --- Executes just before the GUI uvmat is made visible. |
|---|
| 164 | function uvmat_OpeningFcn(hObject, eventdata, handles, input ) |
|---|
| 165 | %------------------------------------------------------------------------ |
|---|
| 166 | |
|---|
| 167 | %% Choose default command menuline output for uvmat (standard GUI) |
|---|
| 168 | handles.output = hObject; |
|---|
| 169 | |
|---|
| 170 | %% Update handles structure (standard GUI) |
|---|
| 171 | guidata(hObject, handles); |
|---|
| 172 | |
|---|
| 173 | %% add the path to uvmat (useful if uvmat has been opened in the working directory and a working directory change occured) |
|---|
| 174 | path_uvmat=fileparts(which('uvmat')); |
|---|
| 175 | |
|---|
| 176 | %% set the position of the GUI, colorbar and ancillary GUIs: |
|---|
| 177 | set(hObject,'Units','pixels')% |
|---|
| 178 | set(0,'Units','pixels'); |
|---|
| 179 | ScreenSize=get(0,'ScreenSize');%size of the current screen |
|---|
| 180 | Width=1050; |
|---|
| 181 | Height=700; |
|---|
| 182 | %adjust to screen size (reduced by a min margin) |
|---|
| 183 | RescaleFactor=min((ScreenSize(3)-80)/Width,(ScreenSize(4)-80)/Height); |
|---|
| 184 | if RescaleFactor>1 |
|---|
| 185 | RescaleFactor=RescaleFactor/2+1/2; %reduce the rescale factor to provide an increased margin for a big screen |
|---|
| 186 | end |
|---|
| 187 | Width=Width*RescaleFactor; |
|---|
| 188 | Height=Height*RescaleFactor; |
|---|
| 189 | LeftX=80*RescaleFactor;%position of the left fig side, in pixels (put to the left side, with some margin) |
|---|
| 190 | LowY=round(ScreenSize(4)/2-Height/2); % put at the middle height on the screen |
|---|
| 191 | set(hObject,'Position',[LeftX LowY Width Height]) |
|---|
| 192 | UvData.PosColorbar=[0.80 0.02 0.018 0.445]; |
|---|
| 193 | AxeData.LimEditBox=1; %initialise AxeData |
|---|
| 194 | set(handles.PlotAxes,'UserData',AxeData) |
|---|
| 195 | |
|---|
| 196 | %% set functions for the mouse and keyboard |
|---|
| 197 | set(hObject,'WindowKeyPressFcn',{'keyboard_callback',handles})%set keyboard action function |
|---|
| 198 | set(hObject,'WindowButtonMotionFcn',{'mouse_motion',handles})%set mouse action functio |
|---|
| 199 | set(hObject,'WindowButtonDownFcn',{'mouse_down'})%set mouse click action function |
|---|
| 200 | set(hObject,'WindowButtonUpFcn',{'mouse_up',handles}) |
|---|
| 201 | set(hObject,'DeleteFcn',{@closefcn})% |
|---|
| 202 | set(hObject,'ResizeFcn',{@ResizeFcn,handles})% |
|---|
| 203 | |
|---|
| 204 | %% initialisation |
|---|
| 205 | set(handles.FieldName,'Value',1) |
|---|
| 206 | set(handles.FieldName,'string',{''}) |
|---|
| 207 | UvData.ProjObject={[]}; |
|---|
| 208 | |
|---|
| 209 | %% TRANSFORM menu: builtin fcts |
|---|
| 210 | transform_menu={'';'sub_field';'phys';'phys_polar'}; |
|---|
| 211 | UvData.OpenParam.NbBuiltin=numel(transform_menu); %number of functions |
|---|
| 212 | transform_path=fullfile(path_uvmat,'transform_field'); |
|---|
| 213 | path_list=cell(UvData.OpenParam.NbBuiltin,1); |
|---|
| 214 | path_list{1}=''; |
|---|
| 215 | for ilist=2:UvData.OpenParam.NbBuiltin |
|---|
| 216 | path_list{ilist}=transform_path; % set transform_path to the path_list |
|---|
| 217 | end |
|---|
| 218 | |
|---|
| 219 | %% load the list of previously browsed files in menus Open, Open_1 and TransformName |
|---|
| 220 | dir_perso=prefdir; % path to the directory .matlab containing the personal data of the current user |
|---|
| 221 | profil_perso=fullfile(dir_perso,'uvmat_perso.mat');% personal data file uvmat_perso.mat' in .matlab |
|---|
| 222 | if exist(profil_perso,'file')% if the file exists |
|---|
| 223 | h=load (profil_perso); % open the personal file |
|---|
| 224 | if isfield(h,'MenuFile')% load the saved menu of previously opened files |
|---|
| 225 | for ifile=1:min(length(h.MenuFile),5) |
|---|
| 226 | set(handles.(['MenuFile_' num2str(ifile)]),'Label',h.MenuFile{ifile}); |
|---|
| 227 | end |
|---|
| 228 | end |
|---|
| 229 | if isfield(h,'MenuCampaign')% load the saved menu of previously opened campaigns |
|---|
| 230 | for ifile=1:min(length(h.MenuCampaign),5) |
|---|
| 231 | set(handles.(['MenuCampaign_' num2str(ifile)]),'Label',h.MenuCampaign{ifile}); |
|---|
| 232 | end |
|---|
| 233 | end |
|---|
| 234 | if isfield(h,'RootPath') |
|---|
| 235 | set(handles.RootPath,'UserData',h.RootPath); %store the previous campaign in the UserData of RootPath |
|---|
| 236 | end |
|---|
| 237 | if isfield(h,'transform_fct') && iscell(h.transform_fct) % load the menu of transform fct set by user |
|---|
| 238 | for ilist=1:length(h.transform_fct); |
|---|
| 239 | if exist(h.transform_fct{ilist},'file') |
|---|
| 240 | [path,file]=fileparts(h.transform_fct{ilist}); |
|---|
| 241 | transform_menu=[transform_menu; {file}]; |
|---|
| 242 | path_list=[path_list; {path}]; |
|---|
| 243 | end |
|---|
| 244 | end |
|---|
| 245 | end |
|---|
| 246 | end |
|---|
| 247 | transform_menu=[transform_menu;{'more...'}];%append the option more.. to the menu |
|---|
| 248 | set(handles.TransformName,'String',transform_menu)% display the menu of transform fcts |
|---|
| 249 | set(handles.TransformName,'UserData',path_list)% store the corresponding list of path in UserData of uicontrol transform_fct |
|---|
| 250 | set(handles.TransformPath,'String','') |
|---|
| 251 | set(handles.TransformPath,'UserData',[]) |
|---|
| 252 | |
|---|
| 253 | %% case of an input argument for uvmat |
|---|
| 254 | testinputfield=0; |
|---|
| 255 | inputfile=[]; |
|---|
| 256 | Field=[]; |
|---|
| 257 | if exist('input','var') |
|---|
| 258 | if ishandle(handles.UVMAT_title) |
|---|
| 259 | delete(handles.UVMAT_title) |
|---|
| 260 | end |
|---|
| 261 | if isstruct(input) |
|---|
| 262 | if isfield(input,'InputFile') |
|---|
| 263 | inputfile=input.InputFile; |
|---|
| 264 | end |
|---|
| 265 | if isfield(input,'TimeIndex') |
|---|
| 266 | set(handles.i1,num2str(input.TimeIndex)) |
|---|
| 267 | end |
|---|
| 268 | if isfield(input,'FieldsString') |
|---|
| 269 | UvData.FieldsString=input.FieldsString; |
|---|
| 270 | end |
|---|
| 271 | elseif ischar(input)% file name introduced as input |
|---|
| 272 | inputfile=input; |
|---|
| 273 | elseif isnumeric(input)%simple matrix introduced as input |
|---|
| 274 | sizinput=size(input); |
|---|
| 275 | if sizinput(1)<=1 || sizinput(2)<=1 |
|---|
| 276 | msgbox_uvmat('ERROR','bad input for uvmat: file name, structure or numerical matrix accepted') |
|---|
| 277 | return |
|---|
| 278 | end |
|---|
| 279 | UvData.Field.ListVarName={'A','coord_y','coord_x'}; |
|---|
| 280 | UvData.Field.VarDimName={{'coord_y','coord_x'},'cord_y','coord_x'}; |
|---|
| 281 | UvData.Field.A=input; |
|---|
| 282 | UvData.Field.coord_x=[0.5 size(input,2)-0.5]; |
|---|
| 283 | UvData.Field.coord_y=[size(input,1)-0.5 0.5]; |
|---|
| 284 | testinputfield=1; |
|---|
| 285 | end |
|---|
| 286 | else |
|---|
| 287 | %% check the path and date of modification of all functions in uvmat |
|---|
| 288 | path_to_uvmat=which ('uvmat');% check the path detected for source file uvmat |
|---|
| 289 | [infomsg,date_str,svn_info]=check_files;%check the path of the functions called by uvmat.m |
|---|
| 290 | date_str=['last modification: ' date_str]; |
|---|
| 291 | if ishandle(handles.UVMAT_title) |
|---|
| 292 | set(handles.UVMAT_title,'String',... |
|---|
| 293 | [{'Copyright LEGI UMR 5519 /CNRS-UJF-Grenoble INP, 2010'};... |
|---|
| 294 | {'GNU General Public License'};... |
|---|
| 295 | {path_to_uvmat};... |
|---|
| 296 | {date_str};... |
|---|
| 297 | infomsg]); |
|---|
| 298 | end |
|---|
| 299 | end |
|---|
| 300 | set(handles.uvmat,'UserData',UvData) |
|---|
| 301 | if ~isempty(inputfile) |
|---|
| 302 | %%%%% display the input field %%%%%%% |
|---|
| 303 | display_file_name(handles,inputfile) |
|---|
| 304 | %%%%%%% |
|---|
| 305 | end |
|---|
| 306 | |
|---|
| 307 | set_vec_col_bar(handles) %update the display of color code for vectors |
|---|
| 308 | |
|---|
| 309 | %------------------------------------------------------------------------ |
|---|
| 310 | % --- Outputs from this function are returned to the command menuline. |
|---|
| 311 | function varargout = uvmat_OutputFcn(hObject, eventdata, handles) |
|---|
| 312 | %------------------------------------------------------------------------ |
|---|
| 313 | varargout{1} = handles.output;% the only output argument is the handle to the GUI figure |
|---|
| 314 | |
|---|
| 315 | %------------------------------------------------------------------------ |
|---|
| 316 | % --- executed when closing uvmat: delete or desactivate the associated figures if exist |
|---|
| 317 | function closefcn(gcbo,eventdata) |
|---|
| 318 | %------------------------------------------------------------------------ |
|---|
| 319 | % delete GUI 'view_field' if detected |
|---|
| 320 | hh=findobj(allchild(0),'tag','view_field'); |
|---|
| 321 | if ~isempty(hh) |
|---|
| 322 | delete(hh) |
|---|
| 323 | end |
|---|
| 324 | % delete GUI 'geometry_calib' if detected |
|---|
| 325 | hh=findobj(allchild(0),'tag','geometry_calib'); |
|---|
| 326 | if ~isempty(hh) |
|---|
| 327 | delete(hh) |
|---|
| 328 | end |
|---|
| 329 | % desable set_object editing action if detected |
|---|
| 330 | hh=findobj(allchild(0),'name','set_object'); |
|---|
| 331 | if ~isempty(hh) |
|---|
| 332 | hhh=findobj(hh,'tag','PLOT'); |
|---|
| 333 | set(hhh,'enable','off') |
|---|
| 334 | end |
|---|
| 335 | %delete the bowser if detected |
|---|
| 336 | hh=findobj(allchild(0),'tag','browser'); |
|---|
| 337 | if ~isempty(hh) |
|---|
| 338 | delete(hh) |
|---|
| 339 | end |
|---|
| 340 | |
|---|
| 341 | %------------------------------------------------------------------------ |
|---|
| 342 | %--- activated when resizing the GUI view_field |
|---|
| 343 | function ResizeFcn(gcbo,eventdata,handles) |
|---|
| 344 | %------------------------------------------------------------------------ |
|---|
| 345 | set(handles.uvmat,'Units','pixels') |
|---|
| 346 | size_fig=get(handles.uvmat,'Position'); |
|---|
| 347 | ColumnWidth=max(150,0.18*size_fig(3)); |
|---|
| 348 | ColumnWidth=min(ColumnWidth,250); % width of the right side display column, between 150 and 250, depending on the fig width |
|---|
| 349 | |
|---|
| 350 | %% position of panel InputFile |
|---|
| 351 | set(handles.InputFile,'Units','pixels') |
|---|
| 352 | pos_InputFile=get(handles.InputFile,'Position');% [lower x lower y width height] for text_display |
|---|
| 353 | pos_InputFile(1)=0; |
|---|
| 354 | pos_InputFile(2)=size_fig(4)-pos_InputFile(4); % set frame InputFile to the top of the fig |
|---|
| 355 | pos_InputFile(3)=size_fig(3); |
|---|
| 356 | set(handles.InputFile,'Position',pos_InputFile);% [lower x lower y width height] for text_display |
|---|
| 357 | |
|---|
| 358 | %% reset position of text_display and TableDisplay |
|---|
| 359 | % if strcmp(get(handles.TableDisplay,'Visible'),'off') |
|---|
| 360 | set(handles.text_display,'Units','pixels') |
|---|
| 361 | pos_1=get(handles.text_display,'Position');% [lower x lower y width height] for text_display |
|---|
| 362 | pos_1(3)=1.2*ColumnWidth; |
|---|
| 363 | pos_1(1)=size_fig(3)-pos_1(3); % set text display to the right of the fig |
|---|
| 364 | pos_1(2)=size_fig(4)-pos_InputFile(4)-pos_1(4); % set text display to the top of the fig |
|---|
| 365 | set(handles.text_display,'Position',pos_1) |
|---|
| 366 | % reset position of TableDisplay |
|---|
| 367 | % else |
|---|
| 368 | % set(handles.TableDisplay,'Units','pixels') |
|---|
| 369 | % pos_1=get(handles.TableDisplay,'Position'); |
|---|
| 370 | % pos_1(3)=1.2*ColumnWidth; |
|---|
| 371 | % pos_1(1)=size_fig(3)-pos_1(3); |
|---|
| 372 | % pos_1(2)=size_fig(4)-pos_InputFile(4)-pos_1(4); |
|---|
| 373 | set(handles.TableDisplay,'Position',pos_1) |
|---|
| 374 | % reset position of CheckTable |
|---|
| 375 | set(handles.CheckTable,'Units','pixels') |
|---|
| 376 | pos_CheckTable=get(handles.CheckTable,'Position');% [lower x lower y width height] for CheckHold |
|---|
| 377 | pos_CheckTable(1)=pos_1(1)-pos_CheckTable(3); % set 'CheckHold' to the right of the fig |
|---|
| 378 | pos_CheckTable(2)=pos_InputFile(2)-pos_CheckTable(4); % set 'CheckHold' to the lower edge of text display |
|---|
| 379 | set(handles.CheckTable,'Position',pos_CheckTable) |
|---|
| 380 | % end |
|---|
| 381 | |
|---|
| 382 | %% reset position of CheckHold |
|---|
| 383 | % pos_CheckHold=get(handles.CheckHold,'Position');% [lower x lower y width height] for CheckHold |
|---|
| 384 | % pos_CheckHold(1)=size_fig(3)-pos_CheckHold(3); % set 'CheckHold' to the right of the fig |
|---|
| 385 | % pos_CheckHold(2)=pos_1(2)-pos_CheckHold(4); % set 'CheckHold' to the lower edge of text display |
|---|
| 386 | % set(handles.CheckHold,'Position',pos_CheckHold) |
|---|
| 387 | |
|---|
| 388 | %% reset position of Coordinates panel |
|---|
| 389 | set(handles.Coordinates,'Units','pixels') |
|---|
| 390 | pos_2=get(handles.Coordinates,'Position');% [lower x lower y width height] for frame 'Coordinates' |
|---|
| 391 | pos_2(3)=ColumnWidth; |
|---|
| 392 | pos_2(1)=size_fig(3)-pos_2(3); % set 'Coordinates' to the right of the fig |
|---|
| 393 | pos_2(2)=pos_1(2)-pos_2(4); % set 'Coordinates' to the lower edge of text display, allowing a margin for CheckHold |
|---|
| 394 | set(handles.Coordinates,'Position',pos_2) |
|---|
| 395 | |
|---|
| 396 | %% reset position of Axes panel |
|---|
| 397 | set(handles.Axes,'Units','pixels') |
|---|
| 398 | pos_3=get(handles.Axes,'Position');% [lower x lower y width height] for frame 'Coordinates' |
|---|
| 399 | pos_3(3)=ColumnWidth; |
|---|
| 400 | pos_3(1)=size_fig(3)-pos_3(3); % set 'Coordinates' to the right of the fig |
|---|
| 401 | pos_3(2)=pos_2(2)-pos_3(4); % set 'Coordinates' to the lower edge of text display, allowing a margin for CheckHold |
|---|
| 402 | set(handles.Axes,'Position',pos_3) |
|---|
| 403 | |
|---|
| 404 | %% reset position of Scalar |
|---|
| 405 | set(handles.Scalar,'Units','pixels') |
|---|
| 406 | pos_4=get(handles.Scalar,'Position'); % [lower x lower y width height] for frame 'Scalar' |
|---|
| 407 | pos_4(3)=ColumnWidth; |
|---|
| 408 | pos_4(1)=size_fig(3)-pos_4(3); % set 'Scalar' to the right of the fig |
|---|
| 409 | if strcmp(get(handles.Scalar,'Visible'),'on') |
|---|
| 410 | pos_4(2)=pos_3(2)-pos_4(4); % set 'Scalar' to the lower edge of frame 'Coordinates' if visible |
|---|
| 411 | else |
|---|
| 412 | pos_4(2)=pos_3(2);% set 'Scalar' to the lower edge of frame 'text display' if unvisible |
|---|
| 413 | end |
|---|
| 414 | set(handles.Scalar,'Position',pos_4) |
|---|
| 415 | |
|---|
| 416 | %% reset position of Vectors |
|---|
| 417 | set(handles.Vectors,'Units','pixels') |
|---|
| 418 | pos_5=get(handles.Vectors,'Position'); |
|---|
| 419 | pos_5(3)=ColumnWidth; |
|---|
| 420 | pos_5(1)=size_fig(3)-pos_5(3); |
|---|
| 421 | if strcmp(get(handles.Vectors,'visible'),'on') |
|---|
| 422 | pos_5(2)=pos_4(2)-pos_5(4); |
|---|
| 423 | else |
|---|
| 424 | pos_5(2)=pos_4(2); |
|---|
| 425 | end |
|---|
| 426 | set(handles.Vectors,'Position',pos_5) |
|---|
| 427 | |
|---|
| 428 | %% reset position and scale of axis |
|---|
| 429 | pos(1)=0.2*size_fig(3)+35; |
|---|
| 430 | pos(2)=35; |
|---|
| 431 | pos(3)=0.77*size_fig(3)-1.2*ColumnWidth; |
|---|
| 432 | pos(4)=size_fig(4)-60; |
|---|
| 433 | set(handles.PlotAxes,'Units','pixels') |
|---|
| 434 | set(handles.PlotAxes,'Position',pos) |
|---|
| 435 | set(handles.PlotAxes,'Units','normalized') |
|---|
| 436 | |
|---|
| 437 | |
|---|
| 438 | %------------------------------------------------------------------------ |
|---|
| 439 | %------------------------------------------------------------------------ |
|---|
| 440 | % II - FUNCTIONS FOR INTRODUCING THE INPUT FILES |
|---|
| 441 | % automatically sets the global properties when the rootfile name is introduced |
|---|
| 442 | % then activate the view-field action if selected |
|---|
| 443 | % it is activated either by clicking on the RootPath window or by the |
|---|
| 444 | % browser |
|---|
| 445 | %------------------------------------------------------------------------ |
|---|
| 446 | %------------------------------------------------------------------------ |
|---|
| 447 | % --- Executes on the menu Open/Browse... |
|---|
| 448 | % search the files, recognize their type according to their name and fill the rootfile input windows |
|---|
| 449 | function MenuBrowse_Callback(hObject, eventdata, handles) |
|---|
| 450 | [RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes(handles); |
|---|
| 451 | oldfile=[fullfile(RootPath,SubDir,RootFile) FileIndices FileExt]; |
|---|
| 452 | if isempty(oldfile) %loads the previously stored file name and set it as default in the file_input box |
|---|
| 453 | oldfile=get(handles.RootPath,'UserData'); |
|---|
| 454 | end |
|---|
| 455 | fileinput=uigetfile_uvmat('pick an input file',oldfile); |
|---|
| 456 | hh=dir(fileinput); |
|---|
| 457 | if numel(hh)>1 |
|---|
| 458 | msgbox_uvmat('ERROR','invalid input, probably a broken link'); |
|---|
| 459 | else |
|---|
| 460 | |
|---|
| 461 | %% display the selected field and related information |
|---|
| 462 | if ~isempty(fileinput) |
|---|
| 463 | set(handles.SubField,'Value',0) |
|---|
| 464 | desable_subfield(handles) |
|---|
| 465 | display_file_name(handles,fileinput) |
|---|
| 466 | end |
|---|
| 467 | end |
|---|
| 468 | |
|---|
| 469 | % ----------------------------------------------------------------------- |
|---|
| 470 | % --- Open again the file whose name has been recorded in MenuFile_1 |
|---|
| 471 | function MenuFile_Callback(hObject, eventdata, handles) |
|---|
| 472 | %------------------------------------------------------------------------ |
|---|
| 473 | fileinput=get(hObject,'Label'); |
|---|
| 474 | set(handles.SubField,'Value',0) |
|---|
| 475 | desable_subfield(handles) |
|---|
| 476 | errormsg=display_file_name( handles,fileinput); |
|---|
| 477 | if ~isempty(errormsg) |
|---|
| 478 | set(hObject,'Label','') |
|---|
| 479 | MenuFile=[{get(handles.MenuFile_1,'Label')};{get(handles.MenuFile_2,'Label')};... |
|---|
| 480 | {get(handles.MenuFile_3,'Label')};{get(handles.MenuFile_4,'Label')};{get(handles.MenuFile_5,'Label')}]; |
|---|
| 481 | str_find=strcmp(get(hObject,'Label'),MenuFile); |
|---|
| 482 | MenuFile(str_find)=[];% suppress the input file to the list |
|---|
| 483 | for ifile=1:numel(MenuFile) |
|---|
| 484 | set(handles.(['MenuFile_' num2str(ifile)]),'Label',MenuFile{ifile}); |
|---|
| 485 | end |
|---|
| 486 | end |
|---|
| 487 | |
|---|
| 488 | % ----------------------------------------------------------------------- |
|---|
| 489 | % --- Executes on the menu Open/Browse campaign... |
|---|
| 490 | % --- search the file inside a campaign, using the GUI browse_data |
|---|
| 491 | % ----------------------------------------------------------------------- |
|---|
| 492 | function MenuBrowseCampaign_Callback(hObject, eventdata, handles) |
|---|
| 493 | set(handles.MenuOpenCampaign,'ForegroundColor',[1 1 0]) |
|---|
| 494 | drawnow |
|---|
| 495 | RootPath=get(handles.RootPath,'String'); |
|---|
| 496 | if isempty(RootPath) |
|---|
| 497 | RootPath=get(handles.RootPath,'UserData');%use Rootpath recored from the personal file at uvmat opening |
|---|
| 498 | end |
|---|
| 499 | CampaignPath=fileparts(fileparts(RootPath)); |
|---|
| 500 | DirFull=uigetfile_uvmat('define this path as the Campaign folder:',CampaignPath,'uigetdir'); |
|---|
| 501 | %DirFull = uigetdir(CampaignPath,'Select a Campaign dir, then press OK'); |
|---|
| 502 | if isempty(DirFull) |
|---|
| 503 | return |
|---|
| 504 | end |
|---|
| 505 | OutPut=browse_data(DirFull);% open the GUI browse_data to get select a campaign dir, experiment and device |
|---|
| 506 | if ~isfield(OutPut,'Campaign') |
|---|
| 507 | return |
|---|
| 508 | end |
|---|
| 509 | fileinput=uigetfile_uvmat('pick an input file',fullfile(OutPut.Campaign,OutPut.Experiment{1},OutPut.DataSeries{1})); |
|---|
| 510 | hh=dir(fileinput); |
|---|
| 511 | if numel(hh)>1 |
|---|
| 512 | msgbox_uvmat('ERROR','invalid input, probably a broken link'); |
|---|
| 513 | return |
|---|
| 514 | end |
|---|
| 515 | |
|---|
| 516 | % |
|---|
| 517 | % DirName=fullfile(OutPut.Campaign,OutPut.Experiment{1},OutPut.DataSeries{1}); |
|---|
| 518 | % ListStruct=dir(DirName); %list files and the dir DataSeries |
|---|
| 519 | % % select the first appropriate file in the dir |
|---|
| 520 | % FileName=''; |
|---|
| 521 | % for ilist=1:numel(ListStruct) |
|---|
| 522 | % if ~isequal(ListStruct(ilist).isdir,1)%look for files, not dir |
|---|
| 523 | % FileName=ListStruct(ilist).name; |
|---|
| 524 | % FileType=get_file_type(fullfile(DirName,FileName)); |
|---|
| 525 | % switch FileType |
|---|
| 526 | % case {'image','multimage','civx','civdata','netcdf'} |
|---|
| 527 | % break |
|---|
| 528 | % end |
|---|
| 529 | % end |
|---|
| 530 | % end |
|---|
| 531 | % if isempty(FileName) |
|---|
| 532 | % msgbox_uvmat('ERROR',['no appropriate input file in the DataSeries folder ' fullfile(DirName)]) |
|---|
| 533 | % return |
|---|
| 534 | % end |
|---|
| 535 | |
|---|
| 536 | %% update the list of campaigns in the menubar |
|---|
| 537 | MenuCampaign=[{get(handles.MenuCampaign_1,'Label')};{get(handles.MenuCampaign_2,'Label')};... |
|---|
| 538 | {get(handles.MenuCampaign_3,'Label')};{get(handles.MenuCampaign_4,'Label')};{get(handles.MenuCampaign_5,'Label')}]; |
|---|
| 539 | check_dir=isempty(find(strcmp(DirFull,MenuCampaign))); |
|---|
| 540 | if check_dir %insert the new campaign in the list if it is not found |
|---|
| 541 | MenuCampaign(end)=[]; %suppress the last item |
|---|
| 542 | MenuCampaign=[{DirFull};MenuCampaign];%insert the new campaign |
|---|
| 543 | for ilist=1:numel(MenuCampaign) |
|---|
| 544 | set(handles.(['MenuCampaign_' num2str(ilist)]),'Label',MenuCampaign{ilist}) |
|---|
| 545 | end |
|---|
| 546 | % save the list for future opening: |
|---|
| 547 | dir_perso=prefdir; |
|---|
| 548 | profil_perso=fullfile(dir_perso,'uvmat_perso.mat'); |
|---|
| 549 | if exist(profil_perso,'file') |
|---|
| 550 | save (profil_perso,'MenuCampaign','RootPath','-append'); %store the file names for future opening of uvmat |
|---|
| 551 | else |
|---|
| 552 | save (profil_perso,'MenuCampaign','RootPath','-V6'); %store the file names for future opening of uvmat |
|---|
| 553 | end |
|---|
| 554 | end |
|---|
| 555 | |
|---|
| 556 | %% display the selected field and related information |
|---|
| 557 | %display_file_name( handles,fullfile(DirName,FileName)) |
|---|
| 558 | display_file_name( handles,fileinput) |
|---|
| 559 | set(handles.MenuOpenCampaign,'ForegroundColor',[0 0 0]) |
|---|
| 560 | |
|---|
| 561 | % ----------------------------------------------------------------------- |
|---|
| 562 | % --- Open again as second field the file whose name has been recorded in MenuFile_1 |
|---|
| 563 | % ----------------------------------------------------------------------- |
|---|
| 564 | function MenuCampaign_Callback(hObject, eventdata, handles) |
|---|
| 565 | |
|---|
| 566 | set(handles.MenuOpenCampaign,'ForegroundColor',[1 1 0]) |
|---|
| 567 | OutPut=browse_data(get(hObject,'Label'));% open the GUI browse_data to get select a campaign dir, experiment and device |
|---|
| 568 | if ~isfield(OutPut,'Campaign') |
|---|
| 569 | return |
|---|
| 570 | end |
|---|
| 571 | DirName=fullfile(OutPut.Campaign,OutPut.Experiment{1},OutPut.DataSeries{1}); |
|---|
| 572 | fileinput=uigetfile_uvmat('pick an input file',fullfile(OutPut.Campaign,OutPut.Experiment{1},OutPut.DataSeries{1})); |
|---|
| 573 | hh=dir(fileinput); |
|---|
| 574 | if numel(hh)>1 |
|---|
| 575 | msgbox_uvmat('ERROR','invalid input, probably a broken link'); |
|---|
| 576 | return |
|---|
| 577 | end |
|---|
| 578 | % |
|---|
| 579 | % hdir=dir(DirName); %list files and dirs |
|---|
| 580 | % FileName=''; |
|---|
| 581 | % for ilist=1:numel(hdir) |
|---|
| 582 | % if ~isequal(hdir(ilist).isdir,1)%look for files, not dir |
|---|
| 583 | % FileName=hdir(ilist).name; |
|---|
| 584 | % FileType=get_file_type(fullfile(DirName,FileName)); |
|---|
| 585 | % switch FileType |
|---|
| 586 | % case {'image','multimage','civx','civdata','netcdf'} |
|---|
| 587 | % break |
|---|
| 588 | % end |
|---|
| 589 | % end |
|---|
| 590 | % end |
|---|
| 591 | % if isempty(FileName) |
|---|
| 592 | % msgbox_uvmat('ERROR','no valid input file in the selected directory') |
|---|
| 593 | % else |
|---|
| 594 | display_file_name(handles,fileinput) |
|---|
| 595 | % end |
|---|
| 596 | set(handles.MenuOpenCampaign,'ForegroundColor',[0 0 0]) |
|---|
| 597 | |
|---|
| 598 | %------------------------------------------------------------------------ |
|---|
| 599 | % --- Called by action in FileIndex edit box |
|---|
| 600 | function FileIndex_Callback(hObject, eventdata, handles) |
|---|
| 601 | %------------------------------------------------------------------------ |
|---|
| 602 | [tild,tild,tild,i1,i2,j1,j2]=fileparts_uvmat(get(handles.FileIndex,'String')); |
|---|
| 603 | set(handles.i1,'String',num2str(i1));%update the counters |
|---|
| 604 | set(handles.i2,'String',num2str(i2)); |
|---|
| 605 | set(handles.j1,'String',num2str(j1)); |
|---|
| 606 | set(handles.j2,'String',num2str(j2)); |
|---|
| 607 | |
|---|
| 608 | |
|---|
| 609 | %------------------------------------------------------------------------ |
|---|
| 610 | % --- Called by action in NomType edit box |
|---|
| 611 | function NomType_Callback(hObject, eventdata, handles) |
|---|
| 612 | %------------------------------------------------------------------------ |
|---|
| 613 | i1=str2num(get(handles.i1,'String')); |
|---|
| 614 | i2=str2num(get(handles.i2,'String')); |
|---|
| 615 | j1=str2num(get(handles.j1,'String')); |
|---|
| 616 | j2=str2num(get(handles.j2,'String')); |
|---|
| 617 | FileIndex=fullfile_uvmat('','','','',get(handles.NomType,'String'),i1,i2,j1,j2); |
|---|
| 618 | set(handles.FileIndex,'String',FileIndex) |
|---|
| 619 | % refresh the current settings and refresh the field view |
|---|
| 620 | RootPath_Callback(hObject,eventdata,handles) |
|---|
| 621 | |
|---|
| 622 | %------------------------------------------------------------------------ |
|---|
| 623 | % --- Called by action in NomType edit box |
|---|
| 624 | function NomType_1_Callback(hObject, eventdata, handles) |
|---|
| 625 | %------------------------------------------------------------------------ |
|---|
| 626 | i1=str2num(get(handles.i1,'String')); |
|---|
| 627 | i2=str2num(get(handles.i2,'String')); |
|---|
| 628 | j1=str2num(get(handles.j1,'String')); |
|---|
| 629 | j2=str2num(get(handles.j2,'String')); |
|---|
| 630 | FileIndex=fullfile_uvmat('','','','',get(handles.NomType_1,'String'),i1,i2,j1,j2); |
|---|
| 631 | set(handles.FileIndex_1,'String',FileIndex) |
|---|
| 632 | % inputfilerefresh the current settings and inputfilerefresh the field view |
|---|
| 633 | RootPath_1_Callback(hObject,eventdata,handles) |
|---|
| 634 | |
|---|
| 635 | %------------------------------------------------------------------------ |
|---|
| 636 | % --- Executes on button press in InputFileREFRESH. |
|---|
| 637 | function InputFileREFRESH_Callback(hObject, eventdata, handles) |
|---|
| 638 | %------------------------------------------------------------------------ |
|---|
| 639 | set(handles.InputFileREFRESH,'BackgroundColor',[1 1 0])% set button color to yellow to indicate that refresh is under action |
|---|
| 640 | set(handles.uvmat,'Pointer','watch') % set the mouse pointer to 'watch' |
|---|
| 641 | drawnow |
|---|
| 642 | % read the current input file name: |
|---|
| 643 | [RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes(handles); |
|---|
| 644 | % detect the file type, get the movie object if relevant, and look for the corresponding file series: |
|---|
| 645 | [RootPath,SubDir,RootFile,i1_series,i2_series,j1_series,j2_series,tild,FileType,FileInfo,MovieObject]=find_file_series(fullfile(RootPath,SubDir),[RootFile FileIndices FileExt]); |
|---|
| 646 | if isempty(i1_series) |
|---|
| 647 | fileinput=uigetfile_uvmat('pick an input file',fullfile(RootPath,SubDir)); |
|---|
| 648 | hh=dir(fileinput); |
|---|
| 649 | if numel(hh)>1 |
|---|
| 650 | msgbox_uvmat('ERROR','invalid input, probably a broken link'); |
|---|
| 651 | else |
|---|
| 652 | %% display the selected field and related information |
|---|
| 653 | if isempty(fileinput) |
|---|
| 654 | errormsg='aborted'; |
|---|
| 655 | else |
|---|
| 656 | display_file_name(handles,fileinput,1) |
|---|
| 657 | end |
|---|
| 658 | end |
|---|
| 659 | else |
|---|
| 660 | % initiate the input file series and refresh the current field view: |
|---|
| 661 | errormsg=update_rootinfo(handles,i1_series,i2_series,j1_series,j2_series,FileInfo,MovieObject,1); |
|---|
| 662 | end |
|---|
| 663 | |
|---|
| 664 | %% refresh the second series if relevant |
|---|
| 665 | if ~isempty(errormsg) && get(handles.SubField,'Value') |
|---|
| 666 | [RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes_1(handles); |
|---|
| 667 | % detect the file type, get the movie object if relevant, and look for the corresponding file series: |
|---|
| 668 | [RootPath,SubDir,RootFile,i1_series,i2_series,j1_series,j2_series,tild,FileType,FileInfo,MovieObject]=find_file_series(fullfile(RootPath,SubDir),[RootFile FileIndices FileExt]); |
|---|
| 669 | if isempty(i1_series) |
|---|
| 670 | fileinput=uigetfile_uvmat('pick an input file for the second line',fullfile(RootPath,SubDir)); |
|---|
| 671 | hh=dir(fileinput); |
|---|
| 672 | if numel(hh)>1 |
|---|
| 673 | msgbox_uvmat('ERROR','invalid input, probably a broken link'); |
|---|
| 674 | else |
|---|
| 675 | %% display the selected field and related information |
|---|
| 676 | if isempty(fileinput) |
|---|
| 677 | errormsg='aborted'; |
|---|
| 678 | else |
|---|
| 679 | display_file_name(handles,fileinput,2) |
|---|
| 680 | end |
|---|
| 681 | end |
|---|
| 682 | else |
|---|
| 683 | % initiate the input file series and inputfilerefresh the current field view: |
|---|
| 684 | errormsg=update_rootinfo(handles,i1_series,i2_series,j1_series,j2_series,FileInfo,MovieObject,2); |
|---|
| 685 | end |
|---|
| 686 | end |
|---|
| 687 | if ~isempty(errormsg) |
|---|
| 688 | set(handles.InputFileREFRESH,'BackgroundColor',[1 0 1])% put back button color to magenta, input not succesfull |
|---|
| 689 | end |
|---|
| 690 | set(handles.uvmat,'Pointer','arrow')% set back the mouse pointer to arrow |
|---|
| 691 | |
|---|
| 692 | %------------------------------------------------------------------------ |
|---|
| 693 | % --- Fills the edit boxes RootPath, RootFile,NomType...from an input file name 'fileinput' |
|---|
| 694 | function errormsg=display_file_name(handles,fileinput,index) |
|---|
| 695 | %------------------------------------------------------------------------ |
|---|
| 696 | %% look for the input file existence |
|---|
| 697 | errormsg='';%default |
|---|
| 698 | if ~exist(fileinput,'file') |
|---|
| 699 | errormsg=['input file ' fileinput ' does not exist']; |
|---|
| 700 | msgbox_uvmat('ERROR',errormsg) |
|---|
| 701 | return |
|---|
| 702 | end |
|---|
| 703 | |
|---|
| 704 | %% define the relevant handles for the first field series (index=1) or the second file series (index=2) |
|---|
| 705 | if ~exist('index','var') |
|---|
| 706 | index=1; |
|---|
| 707 | end |
|---|
| 708 | if index==1 |
|---|
| 709 | handles_RootPath=handles.RootPath; |
|---|
| 710 | handles_SubDir=handles.SubDir; |
|---|
| 711 | handles_RootFile=handles.RootFile; |
|---|
| 712 | handles_FileIndex=handles.FileIndex; |
|---|
| 713 | handles_NomType=handles.NomType; |
|---|
| 714 | handles_FileExt=handles.FileExt; |
|---|
| 715 | elseif index==2 |
|---|
| 716 | handles_RootPath=handles.RootPath_1; |
|---|
| 717 | handles_SubDir=handles.SubDir_1; |
|---|
| 718 | handles_RootFile=handles.RootFile_1; |
|---|
| 719 | handles_FileIndex=handles.FileIndex_1; |
|---|
| 720 | handles_NomType=handles.NomType_1; |
|---|
| 721 | handles_FileExt=handles.FileExt_1; |
|---|
| 722 | set(handles.RootPath_1,'Visible','on') |
|---|
| 723 | set(handles.RootFile_1,'Visible','on') |
|---|
| 724 | set(handles.SubDir_1,'Visible','on'); |
|---|
| 725 | set(handles.FileIndex_1,'Visible','on'); |
|---|
| 726 | set(handles.FileExt_1,'Visible','on'); |
|---|
| 727 | set(handles.NomType_1,'Visible','on'); |
|---|
| 728 | set(handles.TimeName_1,'Visible','on') |
|---|
| 729 | set(handles.TimeValue_1,'Visible','on') |
|---|
| 730 | end |
|---|
| 731 | set(handles.InputFileREFRESH,'BackgroundColor',[1 1 0])% paint REFRESH button to yellow to visualise root file input |
|---|
| 732 | set(handles.uvmat,'Pointer','watch') % set the mouse pointer to 'watch' |
|---|
| 733 | drawnow |
|---|
| 734 | |
|---|
| 735 | %% detect root name, nomenclature and indices in the input file name: |
|---|
| 736 | [FilePath,FileName,FileExt]=fileparts(fileinput); |
|---|
| 737 | % detect the file type, get the movie object if relevant, and look for the corresponding file series: |
|---|
| 738 | % the root name and indices may be corrected by including the first index i1 if a corresponding xml file exists |
|---|
| 739 | [RootPath,SubDir,RootFile,i1_series,i2_series,j1_series,j2_series,NomType,FileType,FileInfo,MovieObject,i1,i2,j1,j2]=find_file_series(FilePath,[FileName FileExt]); |
|---|
| 740 | |
|---|
| 741 | if strcmp(FileType,'txt') |
|---|
| 742 | try |
|---|
| 743 | edit(fileinput) |
|---|
| 744 | catch ME |
|---|
| 745 | msgbox_uvmat('ERROR','invalid intput file') |
|---|
| 746 | end |
|---|
| 747 | return |
|---|
| 748 | elseif strcmp(FileType,'xml') |
|---|
| 749 | editxml(fileinput) |
|---|
| 750 | return |
|---|
| 751 | elseif strcmp(FileType,'figure') |
|---|
| 752 | open(fileinput) |
|---|
| 753 | return |
|---|
| 754 | end |
|---|
| 755 | |
|---|
| 756 | %% open the file or fill the GUI uvmat according to the detected file type |
|---|
| 757 | switch FileType |
|---|
| 758 | case '' |
|---|
| 759 | msgbox_uvmat('ERROR','invalid input file type') |
|---|
| 760 | case 'txt' |
|---|
| 761 | edit(fileinput) |
|---|
| 762 | case 'figure' %display matlab figure |
|---|
| 763 | hfig=open(fileinput); |
|---|
| 764 | set(hfig,'WindowButtonMotionFcn','mouse_motion')%set mouse action functio |
|---|
| 765 | set(hfig,'WindowButtonUpFcn','mouse_up')%set mouse click action function |
|---|
| 766 | set(hfig,'WindowButtonUpFcn','mouse_down')%set mouse click action function |
|---|
| 767 | case 'xml' % edit xml files |
|---|
| 768 | t=xmltree(fileinput); |
|---|
| 769 | % the xml file marks a project or project link, open datatree_browser |
|---|
| 770 | if strcmp(get(t,1,'name'),'Project')&& exist(regexprep(fileinput,'.xml$',''),'dir') |
|---|
| 771 | datatree_browser(fileinput) |
|---|
| 772 | else % other xml file, open the xml editor |
|---|
| 773 | editxml(fileinput); |
|---|
| 774 | end |
|---|
| 775 | case 'xls'% Excel file opended by editxml |
|---|
| 776 | editxml(fileinput); |
|---|
| 777 | otherwise |
|---|
| 778 | set(handles_RootPath,'String',RootPath); |
|---|
| 779 | rootname=fullfile(RootPath,SubDir,RootFile); |
|---|
| 780 | set(handles_SubDir,'String',['/' SubDir]); |
|---|
| 781 | set(handles_RootFile,'String',['/' RootFile]); %display the separator |
|---|
| 782 | indices=fileinput(length(rootname)+1:end); |
|---|
| 783 | indices(end-length(FileExt)+1:end)=[]; %remove extension |
|---|
| 784 | set(handles_FileIndex,'String',indices); |
|---|
| 785 | set(handles_NomType,'String',NomType); |
|---|
| 786 | set(handles_FileExt,'String',FileExt); |
|---|
| 787 | if index==1 |
|---|
| 788 | % fill file index counters if the first file series is opened |
|---|
| 789 | set(handles.i1,'String',num2str(i1)); |
|---|
| 790 | set(handles.i2,'String',num2str(i2)); |
|---|
| 791 | set(handles.j1,'String',num2stra(j1,NomType)); |
|---|
| 792 | set(handles.j2,'String',num2stra(j2,NomType)); |
|---|
| 793 | else %read the current field index to synchronise with the first series |
|---|
| 794 | i1_s=str2num(get(handles.i1,'String')); |
|---|
| 795 | i2_0=str2num(get(handles.i2,'String')); |
|---|
| 796 | if ~isempty(i2_0) |
|---|
| 797 | i2_s=i2_0; |
|---|
| 798 | else |
|---|
| 799 | i2_s=i2; |
|---|
| 800 | end |
|---|
| 801 | j1_0=stra2num(get(handles.j1,'String')); |
|---|
| 802 | if ~isempty(j1_0) |
|---|
| 803 | j1_s=j1_0; |
|---|
| 804 | else |
|---|
| 805 | j1_s=j1; |
|---|
| 806 | end |
|---|
| 807 | j2_0=stra2num(get(handles.j2,'String')); |
|---|
| 808 | if ~isempty(j2_0) |
|---|
| 809 | j2_s=j2_0; |
|---|
| 810 | else |
|---|
| 811 | j2_s=j2; |
|---|
| 812 | end |
|---|
| 813 | end |
|---|
| 814 | |
|---|
| 815 | % synchronise indices of the second input file if it exists |
|---|
| 816 | if get(handles.SubField,'Value')==1% if the subfield button is activated, update the field numbers |
|---|
| 817 | Input=read_GUI(handles.InputFile); |
|---|
| 818 | if ~isfield(Input,'RootPath_1')||strcmp(Input.RootPath_1,'"') |
|---|
| 819 | Input.RootPath_1=Input.RootPath; |
|---|
| 820 | end |
|---|
| 821 | if ~isfield(Input,'SubDir_1')||strcmp(Input.SubDir_1,'"') |
|---|
| 822 | Input.SubDir_1=Input.SubDir; |
|---|
| 823 | end |
|---|
| 824 | if ~isfield(Input,'RootFile_1')||strcmp(Input.RootFile_1,'"') |
|---|
| 825 | Input.RootFile_1=Input.RootFile; |
|---|
| 826 | end |
|---|
| 827 | if ~isfield(Input,'FileExt_1')||strcmp(Input.FileExt_1,'"') |
|---|
| 828 | Input.FileExt_1=Input.FileExt; |
|---|
| 829 | end |
|---|
| 830 | if ~isfield(Input,'NomType_1')||strcmp(Input.NomType_1,'"') |
|---|
| 831 | Input.NomType_1=Input.NomType; |
|---|
| 832 | end |
|---|
| 833 | %updtate the indices of the second field series to correspond to the newly opened one |
|---|
| 834 | FileName_1=fullfile_uvmat(Input.RootPath_1,Input.SubDir_1,Input.RootFile_1,Input.FileExt_1,Input.NomType_1,i1_s,i2_s,j1_s,j2_s); |
|---|
| 835 | if exist(FileName_1,'file') |
|---|
| 836 | FileIndex_1=fullfile_uvmat('','','','',Input.NomType_1,i1_s,i2_s,j1_s,j2_s); |
|---|
| 837 | else |
|---|
| 838 | FileIndex_1=fullfile_uvmat('','','','',Input.NomType_1,i1,i2,j1,j2); |
|---|
| 839 | msgbox_uvmat('WARNING','unable to synchronise the indices of the two series') |
|---|
| 840 | end |
|---|
| 841 | set(handles.FileIndex_1,'String',FileIndex_1) |
|---|
| 842 | end |
|---|
| 843 | |
|---|
| 844 | %enable other menus |
|---|
| 845 | set(handles.MenuOpenCampaign,'Enable','on') |
|---|
| 846 | set(handles.MenuExport,'Enable','on') |
|---|
| 847 | set(handles.MenuExportFigure,'Enable','on') |
|---|
| 848 | set(handles.MenuExportMovie,'Enable','on') |
|---|
| 849 | set(handles.MenuTools,'Enable','on') |
|---|
| 850 | |
|---|
| 851 | % initiate input file series and inputfilerefresh the current field view: |
|---|
| 852 | update_rootinfo(handles,i1_series,i2_series,j1_series,j2_series,FileInfo,MovieObject,index); |
|---|
| 853 | |
|---|
| 854 | end |
|---|
| 855 | |
|---|
| 856 | %% update list of recent files in the menubar and save it for future opening |
|---|
| 857 | MenuFile=[{get(handles.MenuFile_1,'Label')};{get(handles.MenuFile_2,'Label')};... |
|---|
| 858 | {get(handles.MenuFile_3,'Label')};{get(handles.MenuFile_4,'Label')};{get(handles.MenuFile_5,'Label')}]; |
|---|
| 859 | str_find=strcmp(fileinput,MenuFile); |
|---|
| 860 | if isempty(find(str_find,1)) |
|---|
| 861 | MenuFile=[{fileinput};MenuFile];%insert the current file if not already in the list |
|---|
| 862 | end |
|---|
| 863 | for ifile=1:min(length(MenuFile),5) |
|---|
| 864 | set(handles.(['MenuFile_' num2str(ifile)]),'Label',MenuFile{ifile}); |
|---|
| 865 | %set(handles.(['MenuFile_' num2str(ifile) '_1']),'Label',MenuFile{ifile}); |
|---|
| 866 | end |
|---|
| 867 | dir_perso=prefdir; |
|---|
| 868 | profil_perso=fullfile(dir_perso,'uvmat_perso.mat'); |
|---|
| 869 | if exist(profil_perso,'file') |
|---|
| 870 | save (profil_perso,'MenuFile','RootPath','-append'); %store the file names for future opening of uvmat |
|---|
| 871 | else |
|---|
| 872 | save (profil_perso,'MenuFile','RootPath','-V6'); %store the file names for future opening of uvmat |
|---|
| 873 | end |
|---|
| 874 | |
|---|
| 875 | set(handles.InputFileREFRESH,'BackgroundColor',[1 0 0])% paint back button to red to indicate update is finished |
|---|
| 876 | set(handles.uvmat,'Pointer','arrow')% set back the mouse pointer to arrow |
|---|
| 877 | |
|---|
| 878 | |
|---|
| 879 | %------------------------------------------------------------------------ |
|---|
| 880 | % --- Update information about a new field series (indices to scan, timing, |
|---|
| 881 | % calibration from an xml file, then inputfilerefresh current plots |
|---|
| 882 | function errormsg=update_rootinfo(handles,i1_series,i2_series,j1_series,j2_series,FileInfo,VideoObject,index) |
|---|
| 883 | %------------------------------------------------------------------------ |
|---|
| 884 | errormsg=''; %default error msg |
|---|
| 885 | %% define the relevant handles depending on the index (1=first file series, 2= second file series) |
|---|
| 886 | if ~exist('index','var') |
|---|
| 887 | index=1; |
|---|
| 888 | end |
|---|
| 889 | if index==1 |
|---|
| 890 | handles_Fields=handles.FieldName; |
|---|
| 891 | elseif index==2 |
|---|
| 892 | handles_Fields=handles.FieldName_1; |
|---|
| 893 | end |
|---|
| 894 | |
|---|
| 895 | set(handles.FieldName,'UserData',[])% reinialize data from uvmat opening |
|---|
| 896 | UvData=get(handles.uvmat,'UserData');%huvmat=handles of the uvmat interface |
|---|
| 897 | UvData.NewSeries=1; %flag for REFRESH: begin a new series |
|---|
| 898 | UvData.FileName_1='';% name of the current second field (used to detect a constant field during file scanning) |
|---|
| 899 | UvData.FileType{index}=FileInfo.FileType; |
|---|
| 900 | UvData.FileInfo{index}=FileInfo; |
|---|
| 901 | UvData.i1_series{index}=i1_series; |
|---|
| 902 | UvData.i2_series{index}=i2_series; |
|---|
| 903 | UvData.j1_series{index}=j1_series; |
|---|
| 904 | UvData.j2_series{index}=j2_series; |
|---|
| 905 | set(handles.FixVelType,'Value',0); %desactivate fixed veltype |
|---|
| 906 | if index==1 |
|---|
| 907 | [RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes(handles); |
|---|
| 908 | else |
|---|
| 909 | [RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes_1(handles); |
|---|
| 910 | end |
|---|
| 911 | FileName=[fullfile(RootPath,SubDir,RootFile) FileIndices FileExt]; |
|---|
| 912 | FileBase=fullfile(RootPath,RootFile); |
|---|
| 913 | if ~exist(FileName,'file') |
|---|
| 914 | errormsg=['input file ' FileName ' not found']; |
|---|
| 915 | msgbox_uvmat('ERROR',errormsg); |
|---|
| 916 | return |
|---|
| 917 | end |
|---|
| 918 | |
|---|
| 919 | %% read timing and total frame number from the current file (movie files) !! may be overrid by xml file |
|---|
| 920 | TimeUnit='';%default |
|---|
| 921 | TimeName='';%default |
|---|
| 922 | XmlData.Time=[];%default |
|---|
| 923 | imainfo=[]; |
|---|
| 924 | ColorType='falsecolor'; %default |
|---|
| 925 | UvData.MovieObject{index}=VideoObject; |
|---|
| 926 | if ~isempty(VideoObject)% case of video data |
|---|
| 927 | imainfo=get(VideoObject); |
|---|
| 928 | TimeUnit='s'; |
|---|
| 929 | if isempty(j1_series); %frame index along i |
|---|
| 930 | XmlData.Time=zeros(imainfo.NumberOfFrames+1,2); |
|---|
| 931 | XmlData.Time(:,2)=(0:1/imainfo.FrameRate:(imainfo.NumberOfFrames)/imainfo.FrameRate)'; |
|---|
| 932 | else |
|---|
| 933 | XmlData.Time=[0;ones(size(i1_series,3)-1,1)]*(0:1/imainfo.FrameRate:(imainfo.NumberOfFrames)/imainfo.FrameRate); |
|---|
| 934 | end |
|---|
| 935 | %set(handles.Dt_txt,'String',['Dt=' num2str(1000/imainfo.FrameRate) 'ms']);%display the elementary time interval in millisec |
|---|
| 936 | TimeName='video'; |
|---|
| 937 | ColorType='truecolor'; |
|---|
| 938 | elseif ~isempty(FileExt(2:end))&&(~isempty(imformats(FileExt(2:end))) || isequal(FileExt,'.vol'))%&& isequal(NomType,'*')% multi-frame image |
|---|
| 939 | if ~isequal(SubDir,'') |
|---|
| 940 | imainfo=imfinfo([fullfile(RootPath,SubDir,RootFile) FileIndices FileExt]); |
|---|
| 941 | else |
|---|
| 942 | imainfo=imfinfo([FileBase FileIndices FileExt]); |
|---|
| 943 | end |
|---|
| 944 | ColorType=imainfo.ColorType;%='truecolor' for color images |
|---|
| 945 | end |
|---|
| 946 | if isfield(imainfo,'Width') && isfield(imainfo,'Height') |
|---|
| 947 | if length(imainfo)>1 |
|---|
| 948 | set(handles.num_Npx,'String',num2str(imainfo(1).Width));%fills nbre of pixels x box |
|---|
| 949 | set(handles.num_Npy,'String',num2str(imainfo(1).Height));%fills nbre of pixels x box |
|---|
| 950 | else |
|---|
| 951 | set(handles.num_Npx,'String',num2str(imainfo.Width));%fills nbre of pixels x box |
|---|
| 952 | set(handles.num_Npy,'String',num2str(imainfo.Height));%fills nbre of pixels x box |
|---|
| 953 | end |
|---|
| 954 | else |
|---|
| 955 | set(handles.num_Npx,'String','');%fills nbre of pixels x box |
|---|
| 956 | set(handles.num_Npy,'String','');%fills nbre of pixels x box |
|---|
| 957 | end |
|---|
| 958 | set(handles.CheckBW,'Value',strcmp(ColorType,'grayscale'))% select handles.CheckBW if grayscale image |
|---|
| 959 | |
|---|
| 960 | %% read parameters (time, geometric calibration..) from a documentation file (.xml advised) |
|---|
| 961 | XmlData.GeometryCalib=[];%default |
|---|
| 962 | XmlFileName=find_imadoc(RootPath,SubDir,RootFile,FileExt); |
|---|
| 963 | [tild,tild,DocExt]=fileparts(XmlFileName); |
|---|
| 964 | warntext='';%default warning message |
|---|
| 965 | NbSlice=1;%default |
|---|
| 966 | ImaDoc_str=''; |
|---|
| 967 | if ~isempty(XmlFileName) |
|---|
| 968 | set(handles.view_xml,'Visible','on') |
|---|
| 969 | set(handles.view_xml,'BackgroundColor',[1 1 0])% paint to yellow color to indicate reading of the xml file |
|---|
| 970 | set(handles.view_xml,'String','view .xml') |
|---|
| 971 | drawnow |
|---|
| 972 | [XmlDataRead,warntext]=imadoc2struct(XmlFileName); |
|---|
| 973 | if ~isempty(warntext) |
|---|
| 974 | msgbox_uvmat('WARNING',warntext) |
|---|
| 975 | end |
|---|
| 976 | if ~isempty(XmlDataRead) |
|---|
| 977 | ImaDoc_str=['view ' DocExt]; % DocExt= '.xml' or .civ (obsolete case) |
|---|
| 978 | %XmlData=XmlDataRead; |
|---|
| 979 | if isfield(XmlDataRead,'TimeUnit')&& ~isempty(XmlDataRead.TimeUnit) |
|---|
| 980 | TimeUnit=XmlDataRead.TimeUnit; |
|---|
| 981 | end |
|---|
| 982 | if isfield(XmlDataRead,'Time')&& ~isempty(XmlDataRead.Time) |
|---|
| 983 | XmlData.Time=XmlDataRead.Time; |
|---|
| 984 | end |
|---|
| 985 | set(handles.view_xml,'BackgroundColor',[1 1 1])% paint back to white |
|---|
| 986 | drawnow |
|---|
| 987 | if isfield(XmlDataRead, 'GeometryCalib') && ~isempty(XmlDataRead.GeometryCalib) |
|---|
| 988 | XmlData.GeometryCalib=XmlDataRead.GeometryCalib; |
|---|
| 989 | if isfield(XmlData.GeometryCalib,'CheckVolumeScan') && isequal(XmlData.GeometryCalib.CheckVolumeScan,1) |
|---|
| 990 | set (handles.slices,'String','volume') |
|---|
| 991 | end |
|---|
| 992 | % check whether the GUI geometry_calib is opened |
|---|
| 993 | hgeometry_calib=findobj('tag','geometry_calib'); |
|---|
| 994 | if ~isempty(hgeometry_calib) % check whether the display of the GUI geometry_calib is consistent with the current calib param |
|---|
| 995 | GUserData=get(hgeometry_calib,'UserData'); |
|---|
| 996 | if ~(isfield(GUserData,'XmlInputFile') && strcmp(GUserData.XmlInputFile,XmlFileName)) |
|---|
| 997 | answer=msgbox_uvmat('INPUT_Y-N','refresh the display of the GUI geometry_calib with the new input data?'); |
|---|
| 998 | if strcmp(answer,'Yes') |
|---|
| 999 | geometry_calib(XmlFileName);%diplay the new calibration points and parameters in geometry_calib |
|---|
| 1000 | end |
|---|
| 1001 | end |
|---|
| 1002 | end |
|---|
| 1003 | end |
|---|
| 1004 | end |
|---|
| 1005 | end |
|---|
| 1006 | if isempty(ImaDoc_str) |
|---|
| 1007 | set(handles.view_xml,'Visible','off') % no .xml (or .civ) file detected |
|---|
| 1008 | else |
|---|
| 1009 | set(handles.view_xml,'String',ImaDoc_str)% indicate that a xml file has been detected |
|---|
| 1010 | end |
|---|
| 1011 | |
|---|
| 1012 | %% Define timing |
|---|
| 1013 | % time not set by the input file: images or civ data: indicate that time is read from the xml file |
|---|
| 1014 | FileType=FileInfo.FileType; |
|---|
| 1015 | if isfield(XmlData,'Time')&& ~isempty(XmlData.Time) && ... |
|---|
| 1016 | (strcmp(FileType,'image')|| strcmp(FileType,'multimage'))%||strcmp(FileType,'civdata')||strcmp(FileType,'civx')) |
|---|
| 1017 | TimeName='xml'; |
|---|
| 1018 | elseif strcmp(FileType,'civdata') |
|---|
| 1019 | TimeName='civdata'; |
|---|
| 1020 | elseif strcmp(FileType,'civx') |
|---|
| 1021 | TimeName='civx'; |
|---|
| 1022 | end |
|---|
| 1023 | if index==1 |
|---|
| 1024 | set(handles.TimeName,'String',TimeName) |
|---|
| 1025 | else |
|---|
| 1026 | set(handles.TimeName_1,'String',TimeName) |
|---|
| 1027 | set(handles.TimeName_1,'Visible','on') |
|---|
| 1028 | end |
|---|
| 1029 | |
|---|
| 1030 | %% store last index in handles.MaxIndex_i and .MaxIndex_j |
|---|
| 1031 | nbfield=max(max(max(i2_series))); |
|---|
| 1032 | if isempty(nbfield) |
|---|
| 1033 | nbfield=max(max(max(i1_series))); |
|---|
| 1034 | end |
|---|
| 1035 | nbfield_j=max(max(max(j2_series))); |
|---|
| 1036 | if isempty(nbfield_j) |
|---|
| 1037 | nbfield_j=max(max(max(j1_series))); |
|---|
| 1038 | end |
|---|
| 1039 | if isfield(XmlData,'Time')&& ~isempty(XmlData.Time) |
|---|
| 1040 | %transform .Time to a column vector if it is a line vector the nomenclature uses a single index |
|---|
| 1041 | if isequal(size(XmlData.Time,1),1) |
|---|
| 1042 | XmlData.Time=(XmlData.Time)'; |
|---|
| 1043 | end |
|---|
| 1044 | end |
|---|
| 1045 | last_i_cell=get(handles.MaxIndex_i,'String'); |
|---|
| 1046 | if isempty(nbfield) |
|---|
| 1047 | last_i_cell{index}=''; |
|---|
| 1048 | else |
|---|
| 1049 | last_i_cell{index}=num2str(nbfield); |
|---|
| 1050 | end |
|---|
| 1051 | set(handles.MaxIndex_i,'String',last_i_cell) |
|---|
| 1052 | last_j_cell=get(handles.MaxIndex_j,'String'); |
|---|
| 1053 | if isempty(nbfield_j) |
|---|
| 1054 | last_j_cell{index}=''; |
|---|
| 1055 | else |
|---|
| 1056 | last_j_cell{index}=num2str(nbfield_j); |
|---|
| 1057 | end |
|---|
| 1058 | set(handles.MaxIndex_j,'String',last_j_cell); |
|---|
| 1059 | |
|---|
| 1060 | %% store geometric calibration in UvData |
|---|
| 1061 | if isfield(XmlData,'GeometryCalib') |
|---|
| 1062 | GeometryCalib=XmlData.GeometryCalib; |
|---|
| 1063 | if isempty(GeometryCalib) |
|---|
| 1064 | set(handles.pxcmx,'String','') |
|---|
| 1065 | set(handles.pxcmy,'String','') |
|---|
| 1066 | set(handles.pxcmx,'Visible','off') |
|---|
| 1067 | set(handles.pxcmy,'Visible','off') |
|---|
| 1068 | set(handles.TransformName,'Value',1); % no transform by default |
|---|
| 1069 | else |
|---|
| 1070 | set(handles.pxcmx,'Visible','on') |
|---|
| 1071 | set(handles.pxcmy,'Visible','on') |
|---|
| 1072 | if (isfield(GeometryCalib,'R')&& ~isequal(GeometryCalib.R(2,1),0) && ~isequal(GeometryCalib.R(1,2),0)) ||... |
|---|
| 1073 | (isfield(GeometryCalib,'kappa1')&& ~isequal(GeometryCalib.kappa1,0)) |
|---|
| 1074 | set(handles.pxcmx,'String','var') |
|---|
| 1075 | set(handles.pxcmy,'String','var') |
|---|
| 1076 | elseif isfield(GeometryCalib,'fx_fy') |
|---|
| 1077 | pixcmx=GeometryCalib.fx_fy(1);%*GeometryCalib.R(1,1)*GeometryCalib.sx/(GeometryCalib.Tz*GeometryCalib.dpx); |
|---|
| 1078 | pixcmy=GeometryCalib.fx_fy(2);%*GeometryCalib.R(2,2)/(GeometryCalib.Tz*GeometryCalib.dpy); |
|---|
| 1079 | set(handles.pxcmx,'String',num2str(pixcmx)) |
|---|
| 1080 | set(handles.pxcmy,'String',num2str(pixcmy)) |
|---|
| 1081 | end |
|---|
| 1082 | if ~get(handles.CheckFixLimits,'Value') |
|---|
| 1083 | set(handles.TransformName,'Value',3); % phys transform by default if fixedLimits is off |
|---|
| 1084 | end |
|---|
| 1085 | if isfield(GeometryCalib,'SliceCoord') |
|---|
| 1086 | siz=size(GeometryCalib.SliceCoord); |
|---|
| 1087 | if siz(1)>1 |
|---|
| 1088 | NbSlice=siz(1); |
|---|
| 1089 | set(handles.slices,'Visible','on') |
|---|
| 1090 | set(handles.slices,'Value',1) |
|---|
| 1091 | end |
|---|
| 1092 | if isfield(GeometryCalib,'CheckVolumeScan') && isequal(GeometryCalib.CheckVolumeScan,1) |
|---|
| 1093 | set(handles.num_NbSlice,'Visible','off') |
|---|
| 1094 | else |
|---|
| 1095 | set(handles.num_NbSlice,'Visible','on') |
|---|
| 1096 | set(handles.num_NbSlice,'String',num2str(NbSlice)) |
|---|
| 1097 | end |
|---|
| 1098 | slices_Callback([],[], handles) |
|---|
| 1099 | end |
|---|
| 1100 | end |
|---|
| 1101 | end |
|---|
| 1102 | |
|---|
| 1103 | %% update the data attached to the uvmat interface |
|---|
| 1104 | if ~isempty(TimeUnit) |
|---|
| 1105 | if index==2 && isfield(UvData,'TimeUnit') && ~strcmp(UvData.TimeUnit,TimeUnit) |
|---|
| 1106 | msgbox_uvmat('WARNING',['time unit for second file series ' TimeUnit ' inconsistent with first series']) |
|---|
| 1107 | else |
|---|
| 1108 | UvData.TimeUnit=TimeUnit; |
|---|
| 1109 | end |
|---|
| 1110 | end |
|---|
| 1111 | UvData.XmlData{index}=XmlData; |
|---|
| 1112 | UvData.NewSeries=1; |
|---|
| 1113 | |
|---|
| 1114 | %display warning message |
|---|
| 1115 | if ~isequal(warntext,'') |
|---|
| 1116 | msgbox_uvmat('WARNING',warntext); |
|---|
| 1117 | end |
|---|
| 1118 | |
|---|
| 1119 | %% set default options in menu 'FieldName' |
|---|
| 1120 | switch FileType |
|---|
| 1121 | case {'civx','civdata'} |
|---|
| 1122 | [FieldList,ColorList]=set_field_list('U','V','C'); |
|---|
| 1123 | set(handles_Fields,'String',[{'image'};FieldList;{'get_field...'}]);%standard menu for civx data |
|---|
| 1124 | set(handles_Fields,'Value',2) % set menu to 'velocity |
|---|
| 1125 | if index==1 |
|---|
| 1126 | set(handles.FieldName_1,'Value',1); |
|---|
| 1127 | set(handles.FieldName_1,'String',[{''};{'image'};FieldList;{'get_field...'}]);%standard menu for civx data reproduced for the second field |
|---|
| 1128 | end |
|---|
| 1129 | set(handles.ColorScalar,'Value',1) |
|---|
| 1130 | set(handles.ColorScalar,'String',ColorList) |
|---|
| 1131 | set(handles.Vectors,'Visible','on') |
|---|
| 1132 | %set(handles.Coord_x,'Value',1); |
|---|
| 1133 | set(handles.Coord_x,'String','X'); |
|---|
| 1134 | set(handles.Coord_y,'String','Y'); |
|---|
| 1135 | case 'netcdf' |
|---|
| 1136 | set(handles_Fields,'Value',1) |
|---|
| 1137 | set(handles_Fields,'String',{'get_field...'}) |
|---|
| 1138 | if index==1 |
|---|
| 1139 | FieldName_Callback([],[], handles) |
|---|
| 1140 | else |
|---|
| 1141 | FieldName_1_Callback([],[], handles) |
|---|
| 1142 | end |
|---|
| 1143 | otherwise |
|---|
| 1144 | set(handles_Fields,'Value',1) % set menu to 'image' |
|---|
| 1145 | set(handles_Fields,'String',{'image'}) |
|---|
| 1146 | %set(handles.Coord_x,'Value',1); |
|---|
| 1147 | set(handles.Coord_x,'String','Coord_x'); |
|---|
| 1148 | set(handles.Coord_y,'String','Coord_y'); |
|---|
| 1149 | end |
|---|
| 1150 | set(handles.uvmat,'UserData',UvData) |
|---|
| 1151 | |
|---|
| 1152 | %% set index navigation options |
|---|
| 1153 | scan_option='i';%default |
|---|
| 1154 | state_j='off'; %default |
|---|
| 1155 | if index==2 |
|---|
| 1156 | if get(handles.scan_j,'Value') |
|---|
| 1157 | scan_option='j'; %keep the scan option for the second file series |
|---|
| 1158 | end |
|---|
| 1159 | if strcmp(get(handles.j1,'Visible'),'on') |
|---|
| 1160 | state_j='on'; |
|---|
| 1161 | end |
|---|
| 1162 | end |
|---|
| 1163 | [ref_j,ref_i]=find(squeeze(i1_series(1,:,:))); |
|---|
| 1164 | if ~isempty(j1_series) |
|---|
| 1165 | state_j='on'; |
|---|
| 1166 | if index==1 |
|---|
| 1167 | if isequal(ref_i,ref_i(1)*ones(size(ref_j)))% if ref_i is always equal to its first value |
|---|
| 1168 | scan_option='j'; %scan j indext |
|---|
| 1169 | end |
|---|
| 1170 | end |
|---|
| 1171 | end |
|---|
| 1172 | if isequal(scan_option,'i') |
|---|
| 1173 | diff_ref_i=diff(ref_i,1); |
|---|
| 1174 | if isempty(diff_ref_i) |
|---|
| 1175 | diff_ref_i=1; |
|---|
| 1176 | end |
|---|
| 1177 | if isequal (diff_ref_i,diff_ref_i(1)*ones(size(diff_ref_i))) |
|---|
| 1178 | set(handles.num_IndexIncrement,'String',num2str(diff_ref_i(1))) |
|---|
| 1179 | end |
|---|
| 1180 | set(handles.scan_i,'Value',1) |
|---|
| 1181 | scan_i_Callback([],[], handles); |
|---|
| 1182 | else |
|---|
| 1183 | diff_ref_j=diff(ref_j); |
|---|
| 1184 | if isempty(diff_ref_j) |
|---|
| 1185 | diff_ref_j=1; |
|---|
| 1186 | end |
|---|
| 1187 | if isequal (diff_ref_j,diff_ref_j(1)*ones(size(diff_ref_j))) |
|---|
| 1188 | set(handles.num_IndexIncrement,'String',num2str(diff_ref_j(1))) |
|---|
| 1189 | end |
|---|
| 1190 | set(handles.scan_j,'Value',1) |
|---|
| 1191 | scan_j_Callback([],[], handles); |
|---|
| 1192 | end |
|---|
| 1193 | set(handles.scan_j,'Visible',state_j) |
|---|
| 1194 | set(handles.j1,'Visible',state_j) |
|---|
| 1195 | set(handles.j2,'Visible',state_j) |
|---|
| 1196 | set(handles.MaxIndex_j,'Visible',state_j); |
|---|
| 1197 | set(handles.j_text,'Visible',state_j); |
|---|
| 1198 | if ~isempty(i2_series)||~isempty(j2_series) |
|---|
| 1199 | set(handles.CheckFixPair,'Visible','on') |
|---|
| 1200 | elseif index==1 |
|---|
| 1201 | set(handles.CheckFixPair,'Visible','off') |
|---|
| 1202 | end |
|---|
| 1203 | |
|---|
| 1204 | %% apply the effect of the transform fct and view the field |
|---|
| 1205 | transform=get(handles.TransformPath,'UserData'); |
|---|
| 1206 | if index==2 && (~isa(transform,'function_handle')||nargin(transform)<3) |
|---|
| 1207 | set(handles.TransformName,'value',2); % set transform to sub_field if the current fct doe not accept two input fields |
|---|
| 1208 | end |
|---|
| 1209 | set(handles.InputFileREFRESH,'BackgroundColor',[1 0 0])% set button color to red to indicate that refresh has been updated |
|---|
| 1210 | TransformName_Callback([],[],handles)% callback for the selection of transform function, then refresh the current plot |
|---|
| 1211 | mask_test=get(handles.CheckMask,'value'); |
|---|
| 1212 | if mask_test |
|---|
| 1213 | MaskData=get(handles.CheckMask,'UserData'); |
|---|
| 1214 | if isfield(MaskData,'maskhandle') && ishandle(MaskData.maskhandle) |
|---|
| 1215 | delete(MaskData.maskhandle) %delete old mask |
|---|
| 1216 | end |
|---|
| 1217 | CheckMask_Callback([],[],handles) |
|---|
| 1218 | end |
|---|
| 1219 | |
|---|
| 1220 | %------------------------------------------------------------------------ |
|---|
| 1221 | % --- switch file index scanning options scan_i and scan_j in an exclusive way |
|---|
| 1222 | %------------------------------------------------------------------------ |
|---|
| 1223 | function scan_i_Callback(hObject, eventdata, handles) |
|---|
| 1224 | |
|---|
| 1225 | if get(handles.scan_i,'Value')==1 |
|---|
| 1226 | set(handles.scan_j,'Value',0) |
|---|
| 1227 | else |
|---|
| 1228 | set(handles.scan_j,'Value',1) |
|---|
| 1229 | end |
|---|
| 1230 | scan_j_Callback(hObject, eventdata, handles) |
|---|
| 1231 | |
|---|
| 1232 | %------------------------------------------------------------------------ |
|---|
| 1233 | % --- switch file index scanning options scan_i and scan_j in an exclusive way |
|---|
| 1234 | %------------------------------------------------------------------------ |
|---|
| 1235 | function scan_j_Callback(hObject, eventdata, handles) |
|---|
| 1236 | |
|---|
| 1237 | if get(handles.scan_j,'Value')==1 |
|---|
| 1238 | set(handles.scan_i,'Value',0) |
|---|
| 1239 | else |
|---|
| 1240 | set(handles.scan_i,'Value',1) |
|---|
| 1241 | set(handles.CheckFixPair,'Visible','off') |
|---|
| 1242 | end |
|---|
| 1243 | |
|---|
| 1244 | %------------------------------------------------------------------------ |
|---|
| 1245 | function i1_Callback(hObject, eventdata, handles) |
|---|
| 1246 | %------------------------------------------------------------------------ |
|---|
| 1247 | update_ij(handles,1) |
|---|
| 1248 | |
|---|
| 1249 | %------------------------------------------------------------------------ |
|---|
| 1250 | function i2_Callback(hObject, eventdata, handles) |
|---|
| 1251 | %------------------------------------------------------------------------ |
|---|
| 1252 | update_ij(handles,2) |
|---|
| 1253 | |
|---|
| 1254 | %------------------------------------------------------------------------ |
|---|
| 1255 | function j1_Callback(hObject, eventdata, handles) |
|---|
| 1256 | %------------------------------------------------------------------------ |
|---|
| 1257 | update_ij(handles,3) |
|---|
| 1258 | |
|---|
| 1259 | %------------------------------------------------------------------------ |
|---|
| 1260 | function j2_Callback(hObject, eventdata, handles) |
|---|
| 1261 | %------------------------------------------------------------------------ |
|---|
| 1262 | update_ij(handles,4) |
|---|
| 1263 | |
|---|
| 1264 | %------------------------------------------------------------------------ |
|---|
| 1265 | %--- update the index display after action on edit boxes i1, i2, j1 or j2 |
|---|
| 1266 | %------------------------------------------------------------------------ |
|---|
| 1267 | function update_ij(handles,index_rank) |
|---|
| 1268 | |
|---|
| 1269 | NomType=get(handles.NomType,'String'); |
|---|
| 1270 | indices=get(handles.FileIndex,'String'); |
|---|
| 1271 | [tild,tild,tild,i1,i2,j1,j2]=fileparts_uvmat(indices);% the indices for the second series taken from FileIndex |
|---|
| 1272 | switch index_rank |
|---|
| 1273 | case 1 |
|---|
| 1274 | indices=fullfile_uvmat('','','','',NomType,stra2num(get(handles.i1,'String')),i2,j1,j2); |
|---|
| 1275 | % set(handles.i1,'BackgroundColor',[0.7 0.7 0.7])% mark the edit box in grey, then RUN0 will mark it in white for confirmation |
|---|
| 1276 | case 2 |
|---|
| 1277 | indices=fullfile_uvmat('','','','',NomType,i1,stra2num(get(handles.i2,'String')),j1,j2); |
|---|
| 1278 | % set(handles.i2,'BackgroundColor',[0.7 0.7 0.7])% mark the edit box in grey, then RUN0 will mark it in white for confirmation |
|---|
| 1279 | case 3 |
|---|
| 1280 | indices=fullfile_uvmat('','','','',NomType,i1,i2,stra2num(get(handles.j1,'String')),j2); |
|---|
| 1281 | % set(handles.j1,'BackgroundColor',[0.7 0.7 0.7])% mark the edit box in grey, then RUN0 will mark it in white for confirmation |
|---|
| 1282 | case 4 |
|---|
| 1283 | indices=fullfile_uvmat('','','','',NomType,i1,i2,j1,stra2num(get(handles.j2,'String'))); |
|---|
| 1284 | % set(handles.j2,'BackgroundColor',[0.7 0.7 0.7])% mark the edit box in grey, then RUN0 will mark it in white for confirmation |
|---|
| 1285 | end |
|---|
| 1286 | set(handles.FileIndex,'String',indices) |
|---|
| 1287 | %set(handles.FileIndex,'BackgroundColor',[0.7 0.7 0.7])% mark the edit box in grey, then RUN0 will mark it in white for confirmation |
|---|
| 1288 | % update the second index if relevant |
|---|
| 1289 | if strcmp(get(handles.FileIndex_1,'Visible'),'on') |
|---|
| 1290 | NomType_1=get(handles.NomType_1,'String'); |
|---|
| 1291 | indices_1=get(handles.FileIndex_1,'String'); |
|---|
| 1292 | [tild,tild,tild,i1_1,i2_1,j1_1,j2_1]=fileparts_uvmat(indices_1);% the indices for the second series taken from FileIndex_1 |
|---|
| 1293 | switch index_rank |
|---|
| 1294 | case 1 |
|---|
| 1295 | indices_1=fullfile_uvmat('','','','',NomType_1,stra2num(get(handles.i1,'String')),i2_1,j1_1,j2_1); |
|---|
| 1296 | case 2 |
|---|
| 1297 | indices_1=fullfile_uvmat('','','','',NomType_1,i1_1,stra2num(get(handles.i2,'String')),j1_1,j2_1); |
|---|
| 1298 | case 3 |
|---|
| 1299 | indices_1=fullfile_uvmat('','','','',NomType_1,i1_1,i2_1,stra2num(get(handles.j1,'String')),j2_1); |
|---|
| 1300 | case 4 |
|---|
| 1301 | indices_1=fullfile_uvmat('','','','',NomType_1,i1_1,i2_1,j1_1,stra2num(get(handles.j2,'String'))); |
|---|
| 1302 | end |
|---|
| 1303 | set(handles.FileIndex_1,'String',indices_1) |
|---|
| 1304 | set(handles.FileIndex_1,'BackgroundColor',[0.7 0.7 0.7])% mark the edit box in grey, then RUN0 will mark it in white for confirmation |
|---|
| 1305 | end |
|---|
| 1306 | |
|---|
| 1307 | %------------------------------------------------------------------------ |
|---|
| 1308 | |
|---|
| 1309 | %------------------------------------------------------------------------ |
|---|
| 1310 | function slices_Callback(hObject, eventdata, handles) |
|---|
| 1311 | %------------------------------------------------------------------------ |
|---|
| 1312 | if strcmp(get(handles.slices,'String'),'slices') |
|---|
| 1313 | if get(handles.slices,'Value')==1 |
|---|
| 1314 | set(handles.num_NbSlice,'Visible','on') |
|---|
| 1315 | set(handles.z_text,'Visible','on') |
|---|
| 1316 | set(handles.z_index,'Visible','on') |
|---|
| 1317 | num_NbSlice_Callback(hObject, eventdata, handles) |
|---|
| 1318 | else |
|---|
| 1319 | set(handles.num_NbSlice,'Visible','off') |
|---|
| 1320 | set(handles.z_text,'Visible','off') |
|---|
| 1321 | set(handles.z_index,'Visible','off') |
|---|
| 1322 | set(handles.masklevel,'Value',1) |
|---|
| 1323 | set(handles.masklevel,'String',{'1'}) |
|---|
| 1324 | end |
|---|
| 1325 | end |
|---|
| 1326 | |
|---|
| 1327 | %------------------------------------------------------------------------ |
|---|
| 1328 | function num_NbSlice_Callback(hObject, eventdata, handles) |
|---|
| 1329 | %------------------------------------------------------------------------ |
|---|
| 1330 | mode=get(handles.slices,'String'); |
|---|
| 1331 | nb_slice_str=get(handles.num_NbSlice,'String'); |
|---|
| 1332 | if strcmp(mode,'volume') |
|---|
| 1333 | z=stra2num(get(handles.j1,'String')); |
|---|
| 1334 | else |
|---|
| 1335 | num=str2double(get(handles.i1,'String')); |
|---|
| 1336 | nbslice=str2double(get(handles.num_NbSlice,'String')); |
|---|
| 1337 | z=mod(num-1,nbslice)+1; |
|---|
| 1338 | end |
|---|
| 1339 | set(handles.z_index,'String',num2str(z)) |
|---|
| 1340 | for ilist=1:nbslice |
|---|
| 1341 | list_index{ilist,1}=num2str(ilist); |
|---|
| 1342 | end |
|---|
| 1343 | set(handles.masklevel,'String',list_index) |
|---|
| 1344 | set(handles.masklevel,'Value',z) |
|---|
| 1345 | |
|---|
| 1346 | %------------------------------------------------------------------------ |
|---|
| 1347 | % --- Executes on button press in view_xml. |
|---|
| 1348 | %------------------------------------------------------------------------ |
|---|
| 1349 | function view_xml_Callback(hObject, eventdata, handles) |
|---|
| 1350 | |
|---|
| 1351 | % if TimeName defined, open the xml file corresponding to the first file |
|---|
| 1352 | % series, else open the xml file corresponding to the second series |
|---|
| 1353 | if isempty(get(handles.TimeName,'String'))% open the xml file corresponding to the secodn file series |
|---|
| 1354 | [RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes_1(handles); |
|---|
| 1355 | else |
|---|
| 1356 | [RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes(handles); |
|---|
| 1357 | end |
|---|
| 1358 | option=get(handles.view_xml,'String'); |
|---|
| 1359 | if isequal(option,'view .xml') |
|---|
| 1360 | FileXml=fullfile(RootPath,[SubDir '.xml']); |
|---|
| 1361 | if ~exist(FileXml,'file')% case of civ files , removes the extension for subdir |
|---|
| 1362 | FileXml=fullfile(RootPath,[regexprep(SubDir,'\..+$','') '.xml']); |
|---|
| 1363 | end |
|---|
| 1364 | heditxml=editxml(FileXml); |
|---|
| 1365 | end |
|---|
| 1366 | |
|---|
| 1367 | %------------------------------------------------------------------------ |
|---|
| 1368 | % --- Executes on button press in CheckMask. |
|---|
| 1369 | function CheckMask_Callback(hObject, eventdata, handles) |
|---|
| 1370 | %------------------------------------------------------------------------ |
|---|
| 1371 | %case of view mask selection |
|---|
| 1372 | if isequal(get(handles.CheckMask,'Value'),1) |
|---|
| 1373 | [RootPath,SubDir]=read_file_boxes(handles); |
|---|
| 1374 | MaskSubDir=regexprep(SubDir,'\..*','');%take the root part of SubDir, before the first dot '.' |
|---|
| 1375 | MaskPath=fullfile(RootPath,[MaskSubDir '.mask']); |
|---|
| 1376 | mdetect=0; |
|---|
| 1377 | if exist(MaskPath,'dir') |
|---|
| 1378 | ListStruct=dir(MaskPath);%look for a mask file |
|---|
| 1379 | ListCells=struct2cell(ListStruct);% transform dir struct to a cell arrray |
|---|
| 1380 | check_dir=cell2mat(ListCells(4,:));% =1 for directories, =0 for files |
|---|
| 1381 | ListFiles=ListCells(1,:);%list of file and dri names |
|---|
| 1382 | ListFiles=ListFiles(~check_dir);%list of file names (excluding dir) |
|---|
| 1383 | if ~isempty(ListFiles) |
|---|
| 1384 | for ifile=1:numel(ListFiles) |
|---|
| 1385 | [tild,tild,MaskExt]=fileparts(ListFiles{1}); |
|---|
| 1386 | [tild,tild,MaskFile{ifile},i1_series,i2_series,j1_series,j2_series,MaskNomType,MaskFileType]=find_file_series(MaskPath,ListFiles{ifile},0); |
|---|
| 1387 | if strcmp(MaskFileType,'image') && isempty(i2_series) && isempty(j2_series) |
|---|
| 1388 | mdetect=1; |
|---|
| 1389 | end |
|---|
| 1390 | if ~strcmp(MaskFile{ifile},MaskFile{1}) |
|---|
| 1391 | mdetect=0;% cancel detection test in case of multiple masks, use the brower for selection |
|---|
| 1392 | break |
|---|
| 1393 | end |
|---|
| 1394 | end |
|---|
| 1395 | end |
|---|
| 1396 | RootPath=MaskPath; |
|---|
| 1397 | end |
|---|
| 1398 | if mdetect==0 |
|---|
| 1399 | MaskFullName=uigetfile_uvmat('pick a mask image file:',RootPath,'image'); |
|---|
| 1400 | if isempty(MaskFullName) |
|---|
| 1401 | set(handles.CheckMask,'Value',0) |
|---|
| 1402 | end |
|---|
| 1403 | [MaskPath,MaskName,MaskExt]=fileparts(MaskFullName); |
|---|
| 1404 | [tild,tild,MaskFile,i1_series,i2_series,j1_series,j2_series,MaskNomType]=find_file_series(MaskPath,[MaskName MaskExt],0); |
|---|
| 1405 | if ~(isempty(i2_series) && isempty(j2_series)) |
|---|
| 1406 | MaskNomType='*'; |
|---|
| 1407 | end |
|---|
| 1408 | end |
|---|
| 1409 | Mask.Path=MaskPath; |
|---|
| 1410 | if isempty(MaskFile) |
|---|
| 1411 | Mask.File=''; |
|---|
| 1412 | elseif ischar(MaskFile) |
|---|
| 1413 | Mask.File=MaskFile; |
|---|
| 1414 | else |
|---|
| 1415 | Mask.File=MaskFile{1}; |
|---|
| 1416 | end |
|---|
| 1417 | Mask.Ext=MaskExt; |
|---|
| 1418 | Mask.NomType=MaskNomType; |
|---|
| 1419 | set(handles.CheckMask,'UserData',Mask); |
|---|
| 1420 | errormsg=update_mask(handles); |
|---|
| 1421 | else % desactivate mask display |
|---|
| 1422 | MaskData=get(handles.CheckMask,'UserData'); |
|---|
| 1423 | if isfield(MaskData,'maskhandle') && ishandle(MaskData.maskhandle) |
|---|
| 1424 | delete(MaskData.maskhandle) |
|---|
| 1425 | end |
|---|
| 1426 | set(handles.CheckMask,'UserData',[]) |
|---|
| 1427 | UvData=get(handles.uvmat,'UserData'); |
|---|
| 1428 | if isfield(UvData,'MaskName') |
|---|
| 1429 | UvData=rmfield(UvData,'MaskName'); |
|---|
| 1430 | set(handles.uvmat,'UserData',UvData) |
|---|
| 1431 | end |
|---|
| 1432 | set(handles.CheckMask,'BackgroundColor',[0.7 0.7 0.7]) |
|---|
| 1433 | end |
|---|
| 1434 | |
|---|
| 1435 | %------------------------------------------------------------------------ |
|---|
| 1436 | function errormsg=update_mask(handles) |
|---|
| 1437 | %------------------------------------------------------------------------ |
|---|
| 1438 | errormsg=[];%default |
|---|
| 1439 | Mask=get(handles.CheckMask,'UserData'); |
|---|
| 1440 | MaskIndex=1; |
|---|
| 1441 | if strcmp(get(handles.z_index,'Visible'),'on') |
|---|
| 1442 | MaskIndex=str2num(get(handles.z_index,'String')); |
|---|
| 1443 | end |
|---|
| 1444 | if isfield(Mask,'maskhandle')&& ishandle(Mask.maskhandle) |
|---|
| 1445 | uistack(Mask.maskhandle,'top'); |
|---|
| 1446 | end |
|---|
| 1447 | MaskName=fullfile_uvmat(Mask.Path,'',Mask.File,Mask.Ext,Mask.NomType,MaskIndex); |
|---|
| 1448 | UvData=get(handles.uvmat,'UserData'); |
|---|
| 1449 | |
|---|
| 1450 | %% update mask image if the mask is new |
|---|
| 1451 | if ~ (isfield(UvData,'MaskName') && isequal(UvData.MaskName,MaskName)) |
|---|
| 1452 | UvData.MaskName=MaskName; %update the recorded name on UvData |
|---|
| 1453 | set(handles.uvmat,'UserData',UvData); |
|---|
| 1454 | if ~exist(MaskName,'file') |
|---|
| 1455 | if isfield(Mask,'maskhandle')&& ishandle(Mask.maskhandle) |
|---|
| 1456 | delete(Mask.maskhandle) |
|---|
| 1457 | end |
|---|
| 1458 | else |
|---|
| 1459 | %read mask image |
|---|
| 1460 | [MaskField,tild,errormsg] = read_field(MaskName,'image'); |
|---|
| 1461 | if ~isempty(errormsg) |
|---|
| 1462 | return |
|---|
| 1463 | end |
|---|
| 1464 | npxy=size(MaskField.A); |
|---|
| 1465 | if length(npxy)>2 |
|---|
| 1466 | errormsg=[MaskName ' is not a grey scale image']; |
|---|
| 1467 | return |
|---|
| 1468 | elseif ~isa(MaskField.A,'uint8') |
|---|
| 1469 | errormsg=[MaskName ' is not a 8 bit grey level image']; |
|---|
| 1470 | return |
|---|
| 1471 | end |
|---|
| 1472 | MaskField.ZIndex=MaskIndex; |
|---|
| 1473 | %px to phys or other transform on field |
|---|
| 1474 | menu_transform=get(handles.TransformName,'String'); |
|---|
| 1475 | choice_value=get(handles.TransformName,'Value'); |
|---|
| 1476 | transform_name=menu_transform{choice_value};%name of the transform fct given by the menu 'transform_fct' |
|---|
| 1477 | transform=get(handles.TransformPath,'UserData'); |
|---|
| 1478 | if ~isequal(transform_name,'') && ~isequal(transform_name,'px') |
|---|
| 1479 | if isfield(UvData,'XmlData') && isfield(UvData.XmlData{1},'GeometryCalib')%use geometry calib recorded from the ImaDoc xml file as first priority |
|---|
| 1480 | Calib=UvData.XmlData{1}.GeometryCalib; |
|---|
| 1481 | MaskField=transform(MaskField,UvData.XmlData{1}); |
|---|
| 1482 | end |
|---|
| 1483 | end |
|---|
| 1484 | flagmask=MaskField.A < 200; |
|---|
| 1485 | |
|---|
| 1486 | %make brown color image |
|---|
| 1487 | imflag(:,:,1)=0.9*flagmask; |
|---|
| 1488 | imflag(:,:,2)=0.7*flagmask; |
|---|
| 1489 | imflag(:,:,3)=zeros(size(flagmask)); |
|---|
| 1490 | |
|---|
| 1491 | %update mask image |
|---|
| 1492 | hmask=[]; %default |
|---|
| 1493 | if isfield(Mask,'maskhandle')&& ishandle(Mask.maskhandle) |
|---|
| 1494 | hmask=Mask.maskhandle; |
|---|
| 1495 | end |
|---|
| 1496 | if ~isempty(hmask) |
|---|
| 1497 | set(hmask,'CData',imflag) |
|---|
| 1498 | set(hmask,'AlphaData',flagmask*0.6) |
|---|
| 1499 | set(hmask,'XData',MaskField.Coord_x); |
|---|
| 1500 | set(hmask,'YData',MaskField.Coord_y); |
|---|
| 1501 | % uistack(hmask,'top') |
|---|
| 1502 | else |
|---|
| 1503 | axes(handles.PlotAxes) |
|---|
| 1504 | hold on |
|---|
| 1505 | Mask.maskhandle=image(MaskField.Coord_x,MaskField.Coord_y,imflag,'Tag','mask','HitTest','off','AlphaData',0.6*ones(size(flagmask))); |
|---|
| 1506 | set(handles.CheckMask,'UserData',Mask) |
|---|
| 1507 | end |
|---|
| 1508 | end |
|---|
| 1509 | end |
|---|
| 1510 | |
|---|
| 1511 | %------------------------------------------------------------------------ |
|---|
| 1512 | %------------------------------------------------------------------------ |
|---|
| 1513 | % III - MAIN InputFileREFRESH FUNCTIONS : 'FRAME PLOT' |
|---|
| 1514 | %------------------------------------------------------------------------ |
|---|
| 1515 | |
|---|
| 1516 | %------------------------------------------------------------------------ |
|---|
| 1517 | % --- Executes on button press in runplus: make one step forward and call |
|---|
| 1518 | % --- InputFileREFRESH. The step forward is along the fieldname series 1 or 2 depending on |
|---|
| 1519 | % --- the scan_i and scan_j check box (exclusive each other) |
|---|
| 1520 | function runplus_Callback(hObject, eventdata, handles) |
|---|
| 1521 | %------------------------------------------------------------------------ |
|---|
| 1522 | |
|---|
| 1523 | set(handles.runplus,'BackgroundColor',[1 1 0])%paint the command button in yellow |
|---|
| 1524 | drawnow |
|---|
| 1525 | increment=str2double(get(handles.num_IndexIncrement,'String')); %get the field increment d |
|---|
| 1526 | if isnan(increment)% case of free increment: move to next available field index |
|---|
| 1527 | increment='+'; |
|---|
| 1528 | end |
|---|
| 1529 | errormsg=runpm(hObject,eventdata,handles,increment); |
|---|
| 1530 | if ~isempty(errormsg) |
|---|
| 1531 | msgbox_uvmat('ERROR',errormsg); |
|---|
| 1532 | end |
|---|
| 1533 | |
|---|
| 1534 | %------------------------------------------------------------------------ |
|---|
| 1535 | % --- Executes on button press in runmin: make one step backward and call |
|---|
| 1536 | % --- InputFileREFRESH. The step backward is along the fieldname series 1 or 2 depending on |
|---|
| 1537 | % --- the scan_i and scan_j check box (exclusive each other) |
|---|
| 1538 | function runmin_Callback(hObject, eventdata, handles) |
|---|
| 1539 | %------------------------------------------------------------------------ |
|---|
| 1540 | |
|---|
| 1541 | set(handles.runmin,'BackgroundColor',[1 1 0])%paint the command button in yellow |
|---|
| 1542 | drawnow |
|---|
| 1543 | increment=-str2double(get(handles.num_IndexIncrement,'String')); %get the field increment d |
|---|
| 1544 | if isnan(increment)% case of free increment: move to previous available field index |
|---|
| 1545 | increment='-'; |
|---|
| 1546 | end |
|---|
| 1547 | errormsg=runpm(hObject,eventdata,handles,increment); |
|---|
| 1548 | if ~isempty(errormsg) |
|---|
| 1549 | msgbox_uvmat('ERROR',errormsg); |
|---|
| 1550 | end |
|---|
| 1551 | |
|---|
| 1552 | %------------------------------------------------------------------------ |
|---|
| 1553 | % -- Executes on button press in Movie: make a series of +> steps |
|---|
| 1554 | function Movie_Callback(hObject, eventdata, handles) |
|---|
| 1555 | %------------------------------------------------------------------------ |
|---|
| 1556 | |
|---|
| 1557 | set(handles.Movie,'BackgroundColor',[1 1 0])%paint the command button in yellow |
|---|
| 1558 | drawnow |
|---|
| 1559 | increment=str2double(get(handles.num_IndexIncrement,'String')); %get the field increment d |
|---|
| 1560 | if isnan(increment)% case of free increment: move to next available field index |
|---|
| 1561 | increment='+'; |
|---|
| 1562 | end |
|---|
| 1563 | set(handles.STOP,'Visible','on') |
|---|
| 1564 | set(handles.speed,'Visible','on') |
|---|
| 1565 | set(handles.speed_txt,'Visible','on') |
|---|
| 1566 | set(handles.Movie,'BusyAction','queue') |
|---|
| 1567 | UvData=get(handles.uvmat,'UserData'); |
|---|
| 1568 | |
|---|
| 1569 | while get(handles.Movie,'Value')==1 && get(handles.speed,'Value')~=0 && isequal(get(handles.Movie,'BusyAction'),'queue') % enable STOP command |
|---|
| 1570 | errormsg=runpm(hObject,eventdata,handles,increment); |
|---|
| 1571 | if ~isempty(errormsg) |
|---|
| 1572 | set(handles.Movie,'BackgroundColor',[1 0 0])%paint the command buttonback to red |
|---|
| 1573 | return |
|---|
| 1574 | end |
|---|
| 1575 | pause(1.02-get(handles.speed,'Value'))% wait for next image |
|---|
| 1576 | end |
|---|
| 1577 | if isfield(UvData,'aviobj') && ~isempty( UvData.aviobj), |
|---|
| 1578 | UvData.aviobj=close(UvData.aviobj); |
|---|
| 1579 | set(handles.uvmat,'UserData',UvData); |
|---|
| 1580 | end |
|---|
| 1581 | set(handles.Movie,'BackgroundColor',[1 0 0])%paint the command buttonback to red |
|---|
| 1582 | |
|---|
| 1583 | %------------------------------------------------------------------------ |
|---|
| 1584 | % -- Executes on button press in Movie: make a series of <- steps |
|---|
| 1585 | function MovieBackward_Callback(hObject, eventdata, handles) |
|---|
| 1586 | %------------------------------------------------------------------------ |
|---|
| 1587 | set(handles.MovieBackward,'BackgroundColor',[1 1 0])%paint the command button in yellow |
|---|
| 1588 | drawnow |
|---|
| 1589 | increment=-str2double(get(handles.num_IndexIncrement,'String')); %get the field increment d |
|---|
| 1590 | if isnan(increment)% case of free increment: move to next available field index |
|---|
| 1591 | increment='-'; |
|---|
| 1592 | end |
|---|
| 1593 | set(handles.STOP,'Visible','on') |
|---|
| 1594 | set(handles.speed,'Visible','on') |
|---|
| 1595 | set(handles.speed_txt,'Visible','on') |
|---|
| 1596 | set(handles.MovieBackward,'BusyAction','queue') |
|---|
| 1597 | UvData=get(handles.uvmat,'UserData'); |
|---|
| 1598 | |
|---|
| 1599 | while get(handles.MovieBackward,'Value')==1 && get(handles.speed,'Value')~=0 && isequal(get(handles.MovieBackward,'BusyAction'),'queue') % enable STOP command |
|---|
| 1600 | errormsg=runpm(hObject,eventdata,handles,increment); |
|---|
| 1601 | if ~isempty(errormsg) |
|---|
| 1602 | set(handles.MovieBackward,'BackgroundColor',[1 0 0])%paint the command buttonback to red |
|---|
| 1603 | return |
|---|
| 1604 | end |
|---|
| 1605 | pause(1.02-get(handles.speed,'Value'))% wait for next image |
|---|
| 1606 | end |
|---|
| 1607 | if isfield(UvData,'aviobj') && ~isempty( UvData.aviobj), |
|---|
| 1608 | UvData.aviobj=close(UvData.aviobj); |
|---|
| 1609 | set(handles.uvmat,'UserData',UvData); |
|---|
| 1610 | end |
|---|
| 1611 | set(handles.MovieBackward,'BackgroundColor',[1 0 0])%paint the command buttonback to red |
|---|
| 1612 | |
|---|
| 1613 | %------------------------------------------------------------------------ |
|---|
| 1614 | function STOP_Callback(hObject, eventdata, handles) |
|---|
| 1615 | %------------------------------------------------------------------------ |
|---|
| 1616 | set(handles.movie_pair,'BusyAction','Cancel') |
|---|
| 1617 | set(handles.movie_pair,'value',0) |
|---|
| 1618 | set(handles.Movie,'BusyAction','Cancel') |
|---|
| 1619 | set(handles.MovieBackward,'BusyAction','Cancel') |
|---|
| 1620 | set(handles.MenuExportMovie,'BusyAction','Cancel') |
|---|
| 1621 | %set(handles.movie_pair,'BackgroundColor',[1 0 0])%paint the command buttonback to red |
|---|
| 1622 | set(handles.Movie,'BackgroundColor',[1 0 0])%paint the command buttonback to red |
|---|
| 1623 | set(handles.MovieBackward,'BackgroundColor',[1 0 0])%paint the command buttonback to red |
|---|
| 1624 | |
|---|
| 1625 | %------------------------------------------------------------------------ |
|---|
| 1626 | % --- function activated by runplus and run minus |
|---|
| 1627 | function errormsg=runpm(hObject,eventdata,handles,increment) |
|---|
| 1628 | %------------------------------------------------------------------------ |
|---|
| 1629 | errormsg='';%default |
|---|
| 1630 | %% check for movie pair status |
|---|
| 1631 | movie_status=get(handles.movie_pair,'Value'); |
|---|
| 1632 | if movie_status |
|---|
| 1633 | STOP_Callback(hObject, eventdata, handles)%interrupt movie pair if active |
|---|
| 1634 | end |
|---|
| 1635 | |
|---|
| 1636 | %% read the current input file name(s) and field indices |
|---|
| 1637 | InputFile=read_GUI(handles.InputFile); |
|---|
| 1638 | InputFile.RootFile=regexprep(InputFile.RootFile,'^[\\/]|[\\/]$','');%suppress possible / or \ separator at the beginning or the end of the string |
|---|
| 1639 | InputFile.SubDir=regexprep(InputFile.SubDir,'^[\\/]|[\\/]$','');%suppress possible / or \ separator at the beginning or the end of the string |
|---|
| 1640 | FileExt=InputFile.FileExt; |
|---|
| 1641 | NomType=InputFile.NomType; |
|---|
| 1642 | [tild,tild,tild,i1,i2,j1,j2]=fileparts_uvmat(InputFile.FileIndex);% check back the indices used |
|---|
| 1643 | if isempty(i1) |
|---|
| 1644 | i1=str2num(get(handles.i1,'String'));%read the field indices (for movie, it is not given by the file name) |
|---|
| 1645 | elseif isempty(j1) && strcmp(get(handles.j1,'Visible'),'on') |
|---|
| 1646 | j1=str2num(get(handles.j1,'String'));%case of indexed movie |
|---|
| 1647 | end |
|---|
| 1648 | if movie_status% we read the second index from the edit box |
|---|
| 1649 | i2=str2num(get(handles.i2,'String'));%read the field indices (for movie, it is not given by the file name) |
|---|
| 1650 | if strcmp(get(handles.j2,'Visible'),'on') |
|---|
| 1651 | j2=str2num(get(handles.j2,'String'));% |
|---|
| 1652 | end |
|---|
| 1653 | end |
|---|
| 1654 | sub_value= get(handles.SubField,'Value'); |
|---|
| 1655 | if sub_value % a second input file has been entered |
|---|
| 1656 | [InputFile.RootPath_1,InputFile.SubDir_1,InputFile.RootFile_1,InputFile.FileIndex_1,InputFile.FileExt_1,InputFile.NomType_1]=read_file_boxes_1(handles); |
|---|
| 1657 | [tild,tild,tild,i1_1,i2_1,j1_1,j2_1]=fileparts_uvmat(InputFile.FileIndex_1);% the indices for the second series taken from FileIndex_1 |
|---|
| 1658 | if isempty(i1_1) |
|---|
| 1659 | i1_1=str2num(get(handles.i1,'String'));%read the field indices (for movie, it is not given by the file name) |
|---|
| 1660 | elseif isempty(j1_1) && strcmp(get(handles.j1,'Visible'),'on') |
|---|
| 1661 | j1_1=str2num(get(handles.j1,'String'));%case of indexed movie |
|---|
| 1662 | end |
|---|
| 1663 | else |
|---|
| 1664 | filename_1=[]; |
|---|
| 1665 | end |
|---|
| 1666 | |
|---|
| 1667 | %% increment (or decrement) the field indices and update the input filename(s) |
|---|
| 1668 | if ~isnumeric(increment)% undefined increment value |
|---|
| 1669 | set(handles.CheckFixPair,'Value',0) |
|---|
| 1670 | end |
|---|
| 1671 | CheckFixPair=get(handles.CheckFixPair,'Value')||(isempty(i2)&&isempty(j2)); |
|---|
| 1672 | |
|---|
| 1673 | % the pair i1-i2 or j1-j2 is imposed (check box CheckFixPair selected) |
|---|
| 1674 | if CheckFixPair && isnumeric(increment) |
|---|
| 1675 | if get(handles.scan_i,'Value')==1% case of scanning along index i |
|---|
| 1676 | i1=i1+increment; |
|---|
| 1677 | i2=i2+increment; |
|---|
| 1678 | if sub_value |
|---|
| 1679 | i1_1=i1_1+increment; |
|---|
| 1680 | i2_1=i2_1+increment; |
|---|
| 1681 | end |
|---|
| 1682 | else % case of scanning along index j (burst numbers) |
|---|
| 1683 | j1=j1+increment; |
|---|
| 1684 | j2=j2+increment; |
|---|
| 1685 | if sub_value |
|---|
| 1686 | j1_1=j1_1+increment; |
|---|
| 1687 | j2_1=j2_1+increment; |
|---|
| 1688 | end |
|---|
| 1689 | end |
|---|
| 1690 | |
|---|
| 1691 | % the pair i1-i2 or j1-j2 is free (check box CheckFixPair not selected): the list of existing indices recorded in UvData is used |
|---|
| 1692 | else |
|---|
| 1693 | UvData=get(handles.uvmat,'UserData'); |
|---|
| 1694 | ref_i=i1; |
|---|
| 1695 | if ~isempty(i2) |
|---|
| 1696 | ref_i=floor((i1+i2)/2);% current reference index i |
|---|
| 1697 | end |
|---|
| 1698 | ref_j=1; |
|---|
| 1699 | if ~isempty(j1) |
|---|
| 1700 | ref_j=j1; |
|---|
| 1701 | if ~isempty(j2) |
|---|
| 1702 | ref_j=floor((j1+j2)/2);% current reference index j |
|---|
| 1703 | end |
|---|
| 1704 | end |
|---|
| 1705 | if isnumeric(increment) |
|---|
| 1706 | if get(handles.scan_i,'Value')==1% case of scanning along index i |
|---|
| 1707 | ref_i=ref_i+increment;% increment the current reference index i |
|---|
| 1708 | else % case of scanning along index j (burst numbers) |
|---|
| 1709 | ref_j=ref_j+increment;% increment the current reference index j if scan_j option is used |
|---|
| 1710 | end |
|---|
| 1711 | else % free increment |
|---|
| 1712 | % runaction=get(gcbo,'tag'); |
|---|
| 1713 | if strcmp(increment,'+')% if runplus or movie is activated |
|---|
| 1714 | step=1; |
|---|
| 1715 | else |
|---|
| 1716 | step=-1; |
|---|
| 1717 | end |
|---|
| 1718 | if get(handles.scan_i,'Value')==1% case of scanning along index i |
|---|
| 1719 | ref_i=ref_i+step; |
|---|
| 1720 | while ref_i>=0 && size(UvData.i1_series{1},3)>=ref_i+1 && UvData.i1_series{1}(1,ref_j+1,ref_i+1)==0 |
|---|
| 1721 | ref_i=ref_i+step; |
|---|
| 1722 | end |
|---|
| 1723 | else % case of scanning along index j (burst numbers) |
|---|
| 1724 | ref_j=ref_j+step; |
|---|
| 1725 | while ref_j>=0 && size(UvData.i1_series{1},2)>=ref_j+1 && UvData.i1_series{1}(1,ref_j+1,ref_i+1)==0 |
|---|
| 1726 | ref_j=ref_j+step; |
|---|
| 1727 | end |
|---|
| 1728 | end |
|---|
| 1729 | end |
|---|
| 1730 | if ref_i<0 |
|---|
| 1731 | errormsg='minimum i index reached'; |
|---|
| 1732 | elseif ref_j<0 |
|---|
| 1733 | errormsg='minimum j index reached'; |
|---|
| 1734 | elseif ref_i+1>size(UvData.i1_series{1},3) |
|---|
| 1735 | errormsg='maximum i index reached (reload the input file to update the index bound)'; |
|---|
| 1736 | elseif ref_j+1>size(UvData.i1_series{1},2) |
|---|
| 1737 | errormsg='maximum j index reached (reload the input file to update the index bound)'; |
|---|
| 1738 | end |
|---|
| 1739 | if ~isempty(errormsg),return,end |
|---|
| 1740 | siz=size(UvData.i1_series{1}); |
|---|
| 1741 | ref_indices=ref_i*siz(1)*siz(2)+ref_j*siz(1)+1:ref_i*siz(1)*siz(2)+(ref_j+1)*siz(1); |
|---|
| 1742 | i1_subseries=UvData.i1_series{1}(ref_indices); |
|---|
| 1743 | ref_indices=ref_indices(i1_subseries>0); |
|---|
| 1744 | if isempty(ref_indices)% case of pairs (free index i) |
|---|
| 1745 | ref_indices=ref_i*siz(1)*siz(2)+1:(ref_i+1)*siz(1)*siz(2); |
|---|
| 1746 | i1_subseries=UvData.i1_series{1}(ref_indices); |
|---|
| 1747 | ref_indices=ref_indices(i1_subseries>0); |
|---|
| 1748 | end |
|---|
| 1749 | if isempty(ref_indices),errormsg='no next frame: set num_IndexIncrement =''*'' to reach the next existing file';return |
|---|
| 1750 | end |
|---|
| 1751 | i1=UvData.i1_series{1}(ref_indices(end)); |
|---|
| 1752 | if ~isempty(UvData.i2_series{1}) |
|---|
| 1753 | i2=UvData.i2_series{1}(ref_indices(end)); |
|---|
| 1754 | end |
|---|
| 1755 | if ~isempty(UvData.j1_series{1}) |
|---|
| 1756 | j1=UvData.j1_series{1}(ref_indices(end)); |
|---|
| 1757 | end |
|---|
| 1758 | if ~isempty(UvData.j2_series{1}) |
|---|
| 1759 | j2=UvData.j2_series{1}(ref_indices(end)); |
|---|
| 1760 | end |
|---|
| 1761 | |
|---|
| 1762 | % case of a second file series |
|---|
| 1763 | if sub_value |
|---|
| 1764 | ref_i_1=i1_1; |
|---|
| 1765 | if ~isempty(i2_1) |
|---|
| 1766 | ref_i_1=floor((i1_1+i2_1)/2);% current reference index i |
|---|
| 1767 | end |
|---|
| 1768 | ref_j_1=1; |
|---|
| 1769 | if ~isempty(j1_1) |
|---|
| 1770 | ref_j_1=j1_1; |
|---|
| 1771 | if ~isempty(j2_1) |
|---|
| 1772 | ref_j_1=floor((j1_1+j2_1)/2);% current reference index j |
|---|
| 1773 | end |
|---|
| 1774 | end |
|---|
| 1775 | if isnumeric(increment) |
|---|
| 1776 | if get(handles.scan_i,'Value')==1% case of scanning along index i |
|---|
| 1777 | ref_i_1=ref_i_1+increment;% increment the current reference index i |
|---|
| 1778 | else % case of scanning along index j (burst numbers) |
|---|
| 1779 | ref_j_1=ref_j_1+increment;% increment the current reference index j if scan_j option is used |
|---|
| 1780 | end |
|---|
| 1781 | else % free increment, synchronise the ref indices with the first series |
|---|
| 1782 | ref_i_1=ref_i; |
|---|
| 1783 | ref_j_1=ref_j; |
|---|
| 1784 | end |
|---|
| 1785 | if numel(UvData.i1_series)==1 |
|---|
| 1786 | UvData.i1_series{2}=UvData.i1_series{1}; |
|---|
| 1787 | UvData.j1_series{2}=UvData.j1_series{1}; |
|---|
| 1788 | UvData.i2_series{2}=UvData.i2_series{1}; |
|---|
| 1789 | UvData.j2_series{2}=UvData.j2_series{1}; |
|---|
| 1790 | end |
|---|
| 1791 | if ref_i_1<0 |
|---|
| 1792 | errormsg='minimum i index reached'; |
|---|
| 1793 | elseif ref_j_1<0 |
|---|
| 1794 | errormsg='minimum j index reached'; |
|---|
| 1795 | elseif ref_i_1+1>size(UvData.i1_series{2},3) |
|---|
| 1796 | errormsg='maximum i index reached for the second series (reload the input file to update the index bound)'; |
|---|
| 1797 | elseif ref_j_1+1>size(UvData.i1_series{2},2) |
|---|
| 1798 | errormsg='maximum j index reached for the second series(reload the input file to update the index bound)'; |
|---|
| 1799 | end |
|---|
| 1800 | if ~isempty(errormsg),return,end |
|---|
| 1801 | siz=size(UvData.i1_series{2}); |
|---|
| 1802 | ref_indices=ref_i_1*siz(1)*siz(2)+ref_j_1*siz(1)+1:ref_i_1*siz(1)*siz(2)+(ref_j_1+1)*siz(1); |
|---|
| 1803 | i1_subseries=UvData.i1_series{2}(ref_indices); |
|---|
| 1804 | ref_indices=ref_indices(i1_subseries>0); |
|---|
| 1805 | if isempty(ref_indices)% case of pairs (free index i) |
|---|
| 1806 | ref_indices=ref_i_1*siz(1)*siz(2)+1:(ref_i_1+1)*siz(1)*siz(2); |
|---|
| 1807 | i1_subseries=UvData.i1_series{2}(ref_indices); |
|---|
| 1808 | ref_indices=ref_indices(i1_subseries>0); |
|---|
| 1809 | end |
|---|
| 1810 | i1_1=UvData.i1_series{2}(ref_indices(end)); |
|---|
| 1811 | if ~isempty(UvData.i2_series{2}) |
|---|
| 1812 | i2_1=UvData.i2_series{2}(ref_indices(end)); |
|---|
| 1813 | end |
|---|
| 1814 | if ~isempty(UvData.j1_series{2}) |
|---|
| 1815 | j1_1=UvData.j1_series{2}(ref_indices(end)); |
|---|
| 1816 | end |
|---|
| 1817 | if ~isempty(UvData.j2_series{2}) |
|---|
| 1818 | j2_1=UvData.j2_series{1}(ref_indices(end)); |
|---|
| 1819 | end |
|---|
| 1820 | else% the second series (if needed) is the same file as the first |
|---|
| 1821 | i1_1=i1; |
|---|
| 1822 | i2_1=i2; |
|---|
| 1823 | j1_1=j1; |
|---|
| 1824 | j2_1=j2; |
|---|
| 1825 | end |
|---|
| 1826 | end |
|---|
| 1827 | filename=fullfile_uvmat(InputFile.RootPath,InputFile.SubDir,InputFile.RootFile,FileExt,NomType,i1,i2,j1,j2); |
|---|
| 1828 | |
|---|
| 1829 | %% refresh plots |
|---|
| 1830 | if sub_value |
|---|
| 1831 | filename_1=fullfile_uvmat(InputFile.RootPath_1,InputFile.SubDir_1,InputFile.RootFile_1,InputFile.FileExt_1,InputFile.NomType_1,i1_1,i2_1,j1_1,j2_1); |
|---|
| 1832 | errormsg=refresh_field(handles,filename,filename_1,i1,i2,j1,j2,i1_1,i2_1,j1_1,j2_1); |
|---|
| 1833 | else |
|---|
| 1834 | errormsg=refresh_field(handles,filename,filename_1,i1,i2,j1,j2); |
|---|
| 1835 | end |
|---|
| 1836 | set(handles.InputFileREFRESH,'BackgroundColor',[1 0 0]) |
|---|
| 1837 | set(handles.runplus,'BackgroundColor',[1 0 0]) |
|---|
| 1838 | set(handles.runmin,'BackgroundColor',[1 0 0]) |
|---|
| 1839 | |
|---|
| 1840 | %% update the index counters if the index move is successfull |
|---|
| 1841 | |
|---|
| 1842 | if isempty(errormsg) |
|---|
| 1843 | set(handles.i1,'String',num2stra(i1,NomType,1)); |
|---|
| 1844 | if isequal(i2,i1) |
|---|
| 1845 | set(handles.i2,'String',''); |
|---|
| 1846 | else |
|---|
| 1847 | set(handles.i2,'String',num2stra(i2,NomType,1)); |
|---|
| 1848 | end |
|---|
| 1849 | set(handles.j1,'String',num2stra(j1,NomType,2)); |
|---|
| 1850 | if isequal(j2,j1) |
|---|
| 1851 | set(handles.j2,'String',''); |
|---|
| 1852 | else |
|---|
| 1853 | set(handles.j2,'String',num2stra(j2,NomType,2)); |
|---|
| 1854 | end |
|---|
| 1855 | indices=fullfile_uvmat('','','','',NomType,i1,i2,j1,j2); |
|---|
| 1856 | set(handles.FileIndex,'String',indices); |
|---|
| 1857 | if ~isempty(filename_1) |
|---|
| 1858 | indices_1=fullfile_uvmat('','','','',InputFile.NomType_1,i1_1,i2_1,j1_1,j2_1); |
|---|
| 1859 | set(handles.FileIndex_1,'String',indices_1); |
|---|
| 1860 | end |
|---|
| 1861 | if isequal(movie_status,1) |
|---|
| 1862 | set(handles.movie_pair,'Value',1) |
|---|
| 1863 | movie_pair_Callback(hObject, eventdata, handles); %reactivate moviepair if it was activated |
|---|
| 1864 | else |
|---|
| 1865 | if isempty(i2), set(handles.i2,'String',''); end % suppress the second index display if not used |
|---|
| 1866 | if isempty(j2), set(handles.j2,'String',''); end |
|---|
| 1867 | end |
|---|
| 1868 | end |
|---|
| 1869 | |
|---|
| 1870 | %------------------------------------------------------------------------ |
|---|
| 1871 | % --- Executes on button press in movie_pair: create an alternating movie with two view |
|---|
| 1872 | function movie_pair_Callback(hObject, eventdata, handles) |
|---|
| 1873 | %------------------------------------------------------------------------ |
|---|
| 1874 | |
|---|
| 1875 | %% stop movie action if the movie_pair button is off |
|---|
| 1876 | if ~get(handles.movie_pair,'value') |
|---|
| 1877 | set(handles.movie_pair,'BusyAction','Cancel')%stop movie pair if button is 'off' |
|---|
| 1878 | set(handles.i2,'String','')% the second i index display is suppressed |
|---|
| 1879 | set(handles.j2,'String','')% the second j index display is suppressed |
|---|
| 1880 | set(handles.Dt_txt,'String','')% the time interval indication is suppressed |
|---|
| 1881 | return |
|---|
| 1882 | end |
|---|
| 1883 | |
|---|
| 1884 | %% check the input file indexing: |
|---|
| 1885 | [RootPath,SubDir,RootFile,FileIndex,FileExt]=read_file_boxes(handles); |
|---|
| 1886 | NomType=get(handles.NomType,'String'); |
|---|
| 1887 | if ~isempty(find(regexp(NomType,'-'))) |
|---|
| 1888 | msgbox_uvmat('ERROR','The movie pair requires file series with a single index on the first input line') |
|---|
| 1889 | return |
|---|
| 1890 | end |
|---|
| 1891 | filename=[fullfile(RootPath,SubDir,RootFile) FileIndex FileExt];% build the input file name (first line) |
|---|
| 1892 | |
|---|
| 1893 | set(handles.movie_pair,'BusyAction','queue')% |
|---|
| 1894 | set(handles.CheckFixPair,'Value',1)% impose fixed pair (needed for function runpm) |
|---|
| 1895 | set(handles.REFRESH,'BackgroundColor',[1 1 0])%paint the command button in yellow to indicate its activity |
|---|
| 1896 | set(handles.movie_pair,'BackgroundColor',[1 1 0])%paint the command button in yellow to indicate its activity |
|---|
| 1897 | drawnow |
|---|
| 1898 | % list_fields=get(handles.FieldName,'String');% list menu fields |
|---|
| 1899 | % index_fields=get(handles.FieldName,'Value');% selected string index |
|---|
| 1900 | % FieldName=list_fields{index_fields}; % selected field |
|---|
| 1901 | |
|---|
| 1902 | |
|---|
| 1903 | % if isequal(FieldName,'image') |
|---|
| 1904 | % index=1; |
|---|
| 1905 | |
|---|
| 1906 | % else |
|---|
| 1907 | % list_fields=get(handles.FieldName_1,'String');% list menu fields |
|---|
| 1908 | % index_fields=get(handles.FieldName_1,'Value');% selected string index |
|---|
| 1909 | % FieldName=list_fields{index_fields}; % selected field |
|---|
| 1910 | % if isequal(FieldName,'image') |
|---|
| 1911 | % index=2; |
|---|
| 1912 | % [RootPath,SubDir,RootFile,FileIndex_1,Ext,NomType]=read_file_boxes_1(handles);% get info from the second input line |
|---|
| 1913 | % else |
|---|
| 1914 | % msgbox_uvmat('ERROR','an image or movie must be first introduced as input') |
|---|
| 1915 | % set(handles.movie_pair,'BackgroundColor',[1 0 0])%paint the command button in red |
|---|
| 1916 | % set(handles.movie_pair,'Value',0) |
|---|
| 1917 | % return |
|---|
| 1918 | % end |
|---|
| 1919 | % end |
|---|
| 1920 | num_i1=str2num(get(handles.i1,'String')); |
|---|
| 1921 | num_j1=stra2num(get(handles.j1,'String')); |
|---|
| 1922 | num_i2=str2num(get(handles.i2,'String')); |
|---|
| 1923 | num_j2=stra2num(get(handles.j2,'String')); |
|---|
| 1924 | |
|---|
| 1925 | %% determine the name 'imaname_1' of the second file in the pair |
|---|
| 1926 | imaname_1=''; |
|---|
| 1927 | if isempty(num_j2)% no second j index indicated |
|---|
| 1928 | if isempty(num_i2) |
|---|
| 1929 | if strcmp(get(handles.j2,'Visible'),'on') %if the j box is visible |
|---|
| 1930 | imaname_1=fullfile_uvmat(RootPath,SubDir,RootFile,FileExt,NomType,num_i1,[],num_j1+1); |
|---|
| 1931 | end |
|---|
| 1932 | if exist(imaname_1,'file') |
|---|
| 1933 | num_j2=num_j1+1;% look by default for the next j index as the second file |
|---|
| 1934 | set(handles.j2,'String',num2stra(num_j2,NomType)); |
|---|
| 1935 | else |
|---|
| 1936 | imaname_1=fullfile_uvmat(RootPath,SubDir,RootFile,FileExt,NomType,num_i1+1,[],num_j1); |
|---|
| 1937 | if exist(imaname_1,'file') |
|---|
| 1938 | num_i2=num_i1+1; |
|---|
| 1939 | set(handles.i2,'String',num2str(num_i2)); |
|---|
| 1940 | else |
|---|
| 1941 | msgbox_uvmat('ERROR', 'a second image index i2 or j2 is needed to show the pair as a movie') |
|---|
| 1942 | set(handles.movie_pair,'BackgroundColor',[1 0 0])%paint the command button in red |
|---|
| 1943 | set(handles.movie_pair,'Value',0) |
|---|
| 1944 | return |
|---|
| 1945 | end |
|---|
| 1946 | end |
|---|
| 1947 | else |
|---|
| 1948 | num_j2=num_j1;%repeat the index i1 by default |
|---|
| 1949 | end |
|---|
| 1950 | end |
|---|
| 1951 | if isempty(num_i2) |
|---|
| 1952 | num_i2=num_i1;%repeat the index i1 by default |
|---|
| 1953 | end |
|---|
| 1954 | if isempty(num_j1) |
|---|
| 1955 | num_j1=1; |
|---|
| 1956 | end |
|---|
| 1957 | if isempty(num_j2) |
|---|
| 1958 | num_j2=num_j1;%repeat the index i1 by default |
|---|
| 1959 | end |
|---|
| 1960 | imaname_1=fullfile_uvmat(RootPath,SubDir,RootFile,FileExt,NomType,num_i2,[],num_j2); |
|---|
| 1961 | if strcmp(NomType,'*') |
|---|
| 1962 | num_frame=num_i2; |
|---|
| 1963 | else |
|---|
| 1964 | num_frame=num_j2; |
|---|
| 1965 | end |
|---|
| 1966 | if ~exist(imaname_1,'file') |
|---|
| 1967 | msgbox_uvmat('ERROR',['second input open (-) ' imaname_1 ' not found']); |
|---|
| 1968 | set(handles.movie_pair,'BackgroundColor',[1 0 0])%paint the command button in red |
|---|
| 1969 | set(handles.movie_pair,'Value',0) |
|---|
| 1970 | return |
|---|
| 1971 | end |
|---|
| 1972 | |
|---|
| 1973 | %% display the first field in the pair (including possibly a background field from second line input filename_1) |
|---|
| 1974 | filename_1='';%default |
|---|
| 1975 | FileIndex_1=''; |
|---|
| 1976 | if get(handles.SubField,'Value') |
|---|
| 1977 | [RootPath_1,SubDir_1,RootFile_1,FileIndex_1,FileExt_1]=read_file_boxes_1(handles); |
|---|
| 1978 | filename_1=[fullfile(RootPath_1,SubDir_1,RootFile_1) FileIndex_1 FileExt_1]; |
|---|
| 1979 | end |
|---|
| 1980 | % num_i1=stra2num(get(handles.i1,'String')); |
|---|
| 1981 | % num_i2=stra2num(get(handles.i2,'String')); |
|---|
| 1982 | % num_j1=stra2num(get(handles.j1,'String')); |
|---|
| 1983 | % num_j2=stra2num(get(handles.j2,'String')); |
|---|
| 1984 | [tild,tild,tild,i1_1,i2_1,j1_1,j2_1]=fileparts_uvmat(FileIndex_1);% get the indices of the second series from the string FileIndex_1 |
|---|
| 1985 | if isempty(j1_1)% case of movies, the index is not given by file index |
|---|
| 1986 | j1_1=num_j1; |
|---|
| 1987 | end |
|---|
| 1988 | |
|---|
| 1989 | errormsg=refresh_field(handles,filename,filename_1,num_i1,num_i2,num_j1,num_j2,i1_1,i2_1,j1_1,j2_1); |
|---|
| 1990 | |
|---|
| 1991 | if isempty(errormsg) |
|---|
| 1992 | set(handles.REFRESH,'BackgroundColor',[1 0 0])% set button color to red, update successfull |
|---|
| 1993 | else |
|---|
| 1994 | msgbox_uvmat('ERROR',errormsg); |
|---|
| 1995 | set(handles.REFRESH,'BackgroundColor',[1 0 1])% keep button color magenta, input not succesfull |
|---|
| 1996 | end |
|---|
| 1997 | UvData=get(handles.uvmat,'UserData'); |
|---|
| 1998 | Field_a=UvData.Field;% movie on the field defined by the second input line |
|---|
| 1999 | |
|---|
| 2000 | %% display time interval for the image pair |
|---|
| 2001 | if isfield(UvData,'XmlData')&&isfield(UvData.XmlData{1},'Time')... |
|---|
| 2002 | && size(UvData.XmlData{1}.Time,1)>=num_i2+1 && size(UvData.XmlData{1}.Time,2)>=num_j2+1 |
|---|
| 2003 | dt=(UvData.XmlData{1}.Time(num_i2+1,num_j2+1)-UvData.XmlData{1}.Time(num_i1+1,num_j1+1)); |
|---|
| 2004 | if isfield(UvData,'TimeUnit') |
|---|
| 2005 | set(handles.Dt_txt,'String',['Dt=' num2str(1000*dt,3) ' m' UvData.TimeUnit] ) |
|---|
| 2006 | else |
|---|
| 2007 | set(handles.Dt_txt,'String',['Dt=' num2str(1000*dt,3) ' 10^(-3)'] ) |
|---|
| 2008 | end |
|---|
| 2009 | else |
|---|
| 2010 | set(handles.Dt_txt,'String','') |
|---|
| 2011 | end |
|---|
| 2012 | |
|---|
| 2013 | %% read the second field |
|---|
| 2014 | if isempty(UvData.MovieObject) |
|---|
| 2015 | [Field_b,ParamOut,errormsg] = read_field(imaname_1,UvData.FileType{index},[],num_frame); |
|---|
| 2016 | else |
|---|
| 2017 | [Field_b,ParamOut,errormsg] = read_field(imaname_1,UvData.FileType{1},UvData.MovieObject{1},num_frame); |
|---|
| 2018 | end |
|---|
| 2019 | if ~isempty(errormsg) |
|---|
| 2020 | msgbox_uvmat('ERROR',['Error in reading second image: ' errormsg]) |
|---|
| 2021 | return |
|---|
| 2022 | end |
|---|
| 2023 | |
|---|
| 2024 | %% apply phys or other transform on the two input fields |
|---|
| 2025 | transform=get(handles.TransformPath,'UserData'); |
|---|
| 2026 | if ~isempty(transform) |
|---|
| 2027 | if isfield(UvData,'XmlData') && ~isempty(UvData.XmlData) %use geometry calib recorded from the ImaDoc xml file as first priority |
|---|
| 2028 | if nargin(transform)>=2 |
|---|
| 2029 | Field_b=transform(Field_b,UvData.XmlData{1}); |
|---|
| 2030 | else |
|---|
| 2031 | Field_b=transform(Field_b); |
|---|
| 2032 | end |
|---|
| 2033 | end |
|---|
| 2034 | end |
|---|
| 2035 | |
|---|
| 2036 | %% make movie until movie speed is set to 0 or STOP is activated |
|---|
| 2037 | hima=findobj(handles.PlotAxes,'Tag','ima');% %handles.PlotAxes =main plotting window (A GENERALISER) |
|---|
| 2038 | set(handles.STOP,'Visible','on') |
|---|
| 2039 | set(handles.speed,'Visible','on') |
|---|
| 2040 | set(handles.speed_txt,'Visible','on') |
|---|
| 2041 | while get(handles.speed,'Value')~=0 && isequal(get(handles.movie_pair,'BusyAction'),'queue') % enable STOP command |
|---|
| 2042 | % read and plot the series of images in non erase mode |
|---|
| 2043 | set(hima,'CData',Field_b.A); %TODO: generalise to other kinds of fields |
|---|
| 2044 | pause(1.02-get(handles.speed,'Value'));% wait for next image |
|---|
| 2045 | set(hima,'CData',Field_a.A); |
|---|
| 2046 | pause(1.02-get(handles.speed,'Value'));% wait for next image |
|---|
| 2047 | end |
|---|
| 2048 | set(handles.movie_pair,'BackgroundColor',[1 0 0])%paint the command button in red |
|---|
| 2049 | set(handles.movie_pair,'Value',0) |
|---|
| 2050 | set(handles.Dt_txt,'String','') |
|---|
| 2051 | |
|---|
| 2052 | %------------------------------------------------------------------------ |
|---|
| 2053 | % --- Executes on button press in InputFileREFRESH. |
|---|
| 2054 | function REFRESH_Callback(hObject, eventdata, handles) |
|---|
| 2055 | %------------------------------------------------------------------------ |
|---|
| 2056 | set(handles.REFRESH,'BackgroundColor',[1 1 0])%paint the REFRESH button in yellow to indicate its activity |
|---|
| 2057 | drawnow |
|---|
| 2058 | [RootPath,SubDir,RootFile,FileIndex,FileExt]=read_file_boxes(handles);%read the features of the input file name (first line) |
|---|
| 2059 | [tild,tild,tild,i1,i2,j1,j2]=fileparts_uvmat(FileIndex);% check back the indices used |
|---|
| 2060 | if isempty(i2), set(handles.i2,'String',''); end % suppress the second i index display if not used |
|---|
| 2061 | if isempty(j2), set(handles.j2,'String',''); end % suppress the second j index display if not used |
|---|
| 2062 | filename=[fullfile(RootPath,SubDir,RootFile) FileIndex FileExt];% build the input file name (first line) |
|---|
| 2063 | filename_1='';%default second file name |
|---|
| 2064 | FileIndex_1=''; |
|---|
| 2065 | if get(handles.SubField,'Value')% if a second file is introduced |
|---|
| 2066 | [RootPath_1,SubDir_1,RootFile_1,FileIndex_1,FileExt_1]=read_file_boxes_1(handles);%read the features of the input file name (second line) |
|---|
| 2067 | filename_1=[fullfile(RootPath_1,SubDir_1,RootFile_1) FileIndex_1 FileExt_1]; %build the input file name (second line) |
|---|
| 2068 | end |
|---|
| 2069 | num_i1=stra2num(get(handles.i1,'String')); |
|---|
| 2070 | num_i2=stra2num(get(handles.i2,'String')); |
|---|
| 2071 | num_j1=stra2num(get(handles.j1,'String')); |
|---|
| 2072 | num_j2=stra2num(get(handles.j2,'String')); |
|---|
| 2073 | [tild,tild,tild,i1_1,i2_1,j1_1,j2_1]=fileparts_uvmat(FileIndex_1);% get the indices of the second series from the string FileIndex_1 |
|---|
| 2074 | if isempty(j1_1)% case of movies, the index is not given by file index |
|---|
| 2075 | j1_1=num_j1; |
|---|
| 2076 | end |
|---|
| 2077 | % in case of movies the index is set by edit boxes i1 or j1 (case of movies indexed by index i) |
|---|
| 2078 | errormsg=refresh_field(handles,filename,filename_1,num_i1,num_i2,num_j1,num_j2,i1_1,i2_1,j1_1,j2_1); |
|---|
| 2079 | ResizeFcn(handles.uvmat,[],handles) |
|---|
| 2080 | if isempty(errormsg) |
|---|
| 2081 | set(handles.REFRESH,'BackgroundColor',[1 0 0])% set button color to red, update successfull |
|---|
| 2082 | else |
|---|
| 2083 | msgbox_uvmat('ERROR',errormsg); |
|---|
| 2084 | set(handles.REFRESH,'BackgroundColor',[1 0 1])% keep button color magenta, input not succesfull |
|---|
| 2085 | end |
|---|
| 2086 | |
|---|
| 2087 | %------------------------------------------------------------------------ |
|---|
| 2088 | % --- read the input files and inputfilerefresh all the plots, including projection. |
|---|
| 2089 | % OUTPUT: |
|---|
| 2090 | % errormsg: error message char string =[] by default |
|---|
| 2091 | % INPUT: |
|---|
| 2092 | % FileName: first input file (=[] in the absence of input file) |
|---|
| 2093 | % FileName_1: second input file (=[] in the asbsence of second input file) |
|---|
| 2094 | % num_i1,num_i2,num_j1,num_j2; frame indices |
|---|
| 2095 | % i1_1,i2_1,j1_1,j2_1: frame indices for the second input file (needed if FileName_1 is not empty) |
|---|
| 2096 | %------------------------------------------------------------------------ |
|---|
| 2097 | function errormsg=refresh_field(handles,FileName,FileName_1,num_i1,num_i2,num_j1,num_j2,i1_1,i2_1,j1_1,j2_1) |
|---|
| 2098 | %------------------------------------------------------------------------ |
|---|
| 2099 | |
|---|
| 2100 | %% initialisation |
|---|
| 2101 | pointer=get(handles.uvmat,'Pointer'); |
|---|
| 2102 | if strcmp(pointer,'watch')% reinitialise the mouse if stuck to 'watch' |
|---|
| 2103 | set(handles.CheckZoom,'Value',0) |
|---|
| 2104 | pointer='arrow'; |
|---|
| 2105 | end |
|---|
| 2106 | set(handles.uvmat,'Pointer','watch') |
|---|
| 2107 | drawnow |
|---|
| 2108 | if ~exist('Field','var') |
|---|
| 2109 | Field={}; |
|---|
| 2110 | end |
|---|
| 2111 | UvData=get(handles.uvmat,'UserData'); |
|---|
| 2112 | if ishandle(handles.UVMAT_title) %remove title panel on uvmat |
|---|
| 2113 | delete(handles.UVMAT_title) |
|---|
| 2114 | end |
|---|
| 2115 | |
|---|
| 2116 | %% determine the main input file information for action |
|---|
| 2117 | if ~exist(FileName,'file') |
|---|
| 2118 | errormsg=['input file ' FileName ' does not exist']; |
|---|
| 2119 | return |
|---|
| 2120 | end |
|---|
| 2121 | NomType=get(handles.NomType,'String'); |
|---|
| 2122 | NomType_1=''; |
|---|
| 2123 | if strcmp(get(handles.NomType_1,'Visible'),'on') |
|---|
| 2124 | NomType_1=get(handles.NomType_1,'String'); |
|---|
| 2125 | end |
|---|
| 2126 | %update the z position index |
|---|
| 2127 | mode_slice=get(handles.slices,'String'); |
|---|
| 2128 | if strcmp(mode_slice,'volume') |
|---|
| 2129 | z_index=num_j1; |
|---|
| 2130 | set(handles.z_index,'String',num2str(z_index)) |
|---|
| 2131 | else |
|---|
| 2132 | nbslice=str2num(get(handles.num_NbSlice,'String')); |
|---|
| 2133 | z_index=mod(num_i1-1,nbslice)+1; |
|---|
| 2134 | set(handles.z_index,'String',num2str(z_index)) |
|---|
| 2135 | end |
|---|
| 2136 | % inputfilerefresh menu for save_mask if relevant |
|---|
| 2137 | masknumber=get(handles.masklevel,'String'); |
|---|
| 2138 | if length(masknumber)>=z_index |
|---|
| 2139 | set(handles.masklevel,'Value',z_index) |
|---|
| 2140 | end |
|---|
| 2141 | |
|---|
| 2142 | %% test for need of tps |
|---|
| 2143 | check_proj_tps=0; |
|---|
| 2144 | if (strcmp(UvData.FileType{1},'civdata')||strcmp(UvData.FileType{1},'civx')) |
|---|
| 2145 | for iobj=1:numel(UvData.ProjObject) |
|---|
| 2146 | if isfield(UvData.ProjObject{iobj},'ProjMode')&& strcmp(UvData.ProjObject{iobj}.ProjMode,'interp_tps') |
|---|
| 2147 | check_proj_tps=1; |
|---|
| 2148 | break |
|---|
| 2149 | end |
|---|
| 2150 | end |
|---|
| 2151 | end |
|---|
| 2152 | |
|---|
| 2153 | %% read the first input field |
|---|
| 2154 | ParamIn.ColorVar='';%default variable name for vector color |
|---|
| 2155 | frame_index=1;%default |
|---|
| 2156 | FieldName='';%default |
|---|
| 2157 | VelType='';%default |
|---|
| 2158 | switch UvData.FileType{1} |
|---|
| 2159 | case {'civx','civdata','netcdf'}; |
|---|
| 2160 | list_fields=get(handles.FieldName,'String');% list menu fields |
|---|
| 2161 | FieldName= list_fields{get(handles.FieldName,'Value')}; % selected field |
|---|
| 2162 | if ~strcmp(FieldName,'get_field...') |
|---|
| 2163 | if get(handles.FixVelType,'Value') |
|---|
| 2164 | VelTypeList=get(handles.VelType,'String'); |
|---|
| 2165 | VelType=VelTypeList{get(handles.VelType,'Value')}; |
|---|
| 2166 | end |
|---|
| 2167 | end |
|---|
| 2168 | % case of input vector field, get the scalar used for vector color |
|---|
| 2169 | if ~isempty(regexp(FieldName,'^vec(')) |
|---|
| 2170 | list_code=get(handles.ColorCode,'String');% list menu fields |
|---|
| 2171 | index_code=get(handles.ColorCode,'Value');% selected string index |
|---|
| 2172 | if ~strcmp(list_code{index_code},'black') && ~strcmp(list_code{index_code},'white') |
|---|
| 2173 | list_code=get(handles.ColorScalar,'String');% list menu fields |
|---|
| 2174 | index_code=get(handles.ColorScalar,'Value');% selected string index |
|---|
| 2175 | ParamIn.ColorVar= list_code{index_code}; % selected field |
|---|
| 2176 | end |
|---|
| 2177 | end |
|---|
| 2178 | case {'video','mmreader'} |
|---|
| 2179 | ParamIn=UvData.MovieObject{1}; % movie object |
|---|
| 2180 | if strcmp(NomType,'*') |
|---|
| 2181 | frame_index=num_i1;%frame index from a single movies or multimage |
|---|
| 2182 | else |
|---|
| 2183 | frame_index=num_j1;% frame index from a set of indexed movies |
|---|
| 2184 | end |
|---|
| 2185 | case 'multimage' |
|---|
| 2186 | if ~strcmp(NomType,'*') |
|---|
| 2187 | frame_index=num_j1;%frame index for movies or multimage |
|---|
| 2188 | else |
|---|
| 2189 | frame_index=num_i1; |
|---|
| 2190 | end |
|---|
| 2191 | case 'vol' %TODO: update |
|---|
| 2192 | if isfield(UvData.XmlData,'Npy') && isfield(UvData.XmlData,'Npx') |
|---|
| 2193 | ParamIn.Npy=UvData.XmlData.Npy; |
|---|
| 2194 | ParamIn.Npx=UvData.XmlData.Npx; |
|---|
| 2195 | else |
|---|
| 2196 | errormsg='Npx and Npy need to be defined in the xml file for volume images .vol'; |
|---|
| 2197 | return |
|---|
| 2198 | end |
|---|
| 2199 | end |
|---|
| 2200 | if isstruct (ParamIn) |
|---|
| 2201 | ParamIn.FieldName=FieldName; |
|---|
| 2202 | ParamIn.VelType=VelType; |
|---|
| 2203 | ParamIn.Coord_x=get(handles.Coord_x,'String'); |
|---|
| 2204 | ParamIn.Coord_y=get(handles.Coord_y,'String'); |
|---|
| 2205 | ParamIn.Coord_z=get(handles.Coord_z,'String'); |
|---|
| 2206 | TimeName=get(handles.TimeName,'String'); |
|---|
| 2207 | r=regexp(TimeName,'^(?<type>(dim:)|(var:))','names');%look for 'var:' or 'dim:' at the beginning of time name |
|---|
| 2208 | if ~isempty(r) |
|---|
| 2209 | frame_index=num_i1;%time index chosen by i1 |
|---|
| 2210 | if strcmp(r.type,'dim:') |
|---|
| 2211 | ParamIn.TimeDimName=TimeName(5:end); |
|---|
| 2212 | elseif strcmp(r.type,'var:') |
|---|
| 2213 | ParamIn.TimeVarName=TimeName(5:end); |
|---|
| 2214 | end |
|---|
| 2215 | end |
|---|
| 2216 | end |
|---|
| 2217 | % check_tps = 0; |
|---|
| 2218 | % if strcmp(UvData.FileType{1},'civdata')&&~strcmp(ParamIn.FieldName,'velocity')&&~strcmp(ParamIn.FieldName,'get_field...') |
|---|
| 2219 | % check_tps=1;%tps needed to get the requested field |
|---|
| 2220 | % end |
|---|
| 2221 | [Field{1},ParamOut,errormsg] = read_field(FileName,UvData.FileType{1},ParamIn,frame_index); |
|---|
| 2222 | if ~isempty(errormsg) |
|---|
| 2223 | errormsg=['uvmat / refresh_field / read_field( ' FileName ') / ' errormsg]; |
|---|
| 2224 | return |
|---|
| 2225 | end |
|---|
| 2226 | if isfield(ParamOut,'Npx')&& isfield(ParamOut,'Npy') |
|---|
| 2227 | set(handles.num_Npx,'String',num2str(ParamOut.Npx));% display image size on the interface |
|---|
| 2228 | set(handles.num_Npy,'String',num2str(ParamOut.Npy)); |
|---|
| 2229 | end |
|---|
| 2230 | Field{1}.ZIndex=z_index; %used for multiplane 3D calibration |
|---|
| 2231 | |
|---|
| 2232 | %% choose and read a second field FileName_1 if defined |
|---|
| 2233 | VelType_1=[];%default |
|---|
| 2234 | FieldName_1=[]; |
|---|
| 2235 | ParamIn_1=[]; |
|---|
| 2236 | ParamOut_1=[]; |
|---|
| 2237 | frame_index_1=1; |
|---|
| 2238 | if ~isempty(FileName_1) |
|---|
| 2239 | if ~exist(FileName_1,'file') |
|---|
| 2240 | errormsg=['second file ' FileName_1 ' does not exist']; |
|---|
| 2241 | return |
|---|
| 2242 | end |
|---|
| 2243 | switch UvData.FileType{2} |
|---|
| 2244 | case {'civx','civdata','netcdf'}; |
|---|
| 2245 | list_fields=get(handles.FieldName_1,'String');% list menu fields |
|---|
| 2246 | if ischar(list_fields),list_fields={list_fields};end |
|---|
| 2247 | FieldName_1= list_fields{get(handles.FieldName_1,'Value')}; % selected field |
|---|
| 2248 | if ~strcmp(FieldName,'get_field...') |
|---|
| 2249 | if get(handles.FixVelType,'Value') |
|---|
| 2250 | VelTypeList=get(handles.VelType_1,'String'); |
|---|
| 2251 | VelType_1=VelTypeList{get(handles.VelType_1,'Value')};% read the velocity type. |
|---|
| 2252 | end |
|---|
| 2253 | end |
|---|
| 2254 | if strcmp(FieldName_1,'velocity')&& strcmp(get(handles.ColorCode,'Visible'),'on') |
|---|
| 2255 | list_code=get(handles.ColorCode,'String');% list menu fields |
|---|
| 2256 | index_code=get(handles.ColorCode,'Value');% selected string index |
|---|
| 2257 | if ~strcmp(list_code{index_code},'black') && ~strcmp(list_code{index_code},'white') |
|---|
| 2258 | list_code=get(handles.ColorScalar,'String');% list menu fields |
|---|
| 2259 | index_code=get(handles.ColorScalar,'Value');% selected string index |
|---|
| 2260 | ParamIn_1.ColorVar= list_code{index_code}; % selected field for vector color display |
|---|
| 2261 | end |
|---|
| 2262 | end |
|---|
| 2263 | case {'video','mmreader'} |
|---|
| 2264 | ParamIn_1=UvData.MovieObject{2}; |
|---|
| 2265 | if ~strcmp(NomType_1,'*') |
|---|
| 2266 | frame_index_1=j1_1;%frame index for movies or multimage |
|---|
| 2267 | else |
|---|
| 2268 | frame_index_1=i1_1; |
|---|
| 2269 | end |
|---|
| 2270 | case 'multimage' |
|---|
| 2271 | if strcmp(NomType_1,'*')%frame index for movies or multimage |
|---|
| 2272 | frame_index_1=i1_1; |
|---|
| 2273 | else |
|---|
| 2274 | frame_index_1=j1_1; |
|---|
| 2275 | end |
|---|
| 2276 | case 'vol' %TODO: update |
|---|
| 2277 | if isfield(UvData.XmlData,'Npy') && isfield(UvData.XmlData,'Npx') |
|---|
| 2278 | ParamIn_1.Npy=UvData.XmlData.Npy; |
|---|
| 2279 | ParamIn_1.Npx=UvData.XmlData.Npx; |
|---|
| 2280 | else |
|---|
| 2281 | errormsg='Npx and Npy need to be defined in the xml file for volume images .vol'; |
|---|
| 2282 | return |
|---|
| 2283 | end |
|---|
| 2284 | end |
|---|
| 2285 | if isequal(get(handles.NomType_1,'Visible'),'on') |
|---|
| 2286 | NomType_1=get(handles.NomType_1,'String'); |
|---|
| 2287 | else |
|---|
| 2288 | NomType_1=get(handles.NomType,'String'); |
|---|
| 2289 | end |
|---|
| 2290 | test_keepdata_1=0;% test for keeping the previous stored data if the input files are unchanged |
|---|
| 2291 | if ~isequal(NomType_1,'*')&& isfield(UvData,'FileName_1') |
|---|
| 2292 | test_keepdata_1= strcmp(FileName_1,UvData.FileName_1) ; |
|---|
| 2293 | end |
|---|
| 2294 | if test_keepdata_1 |
|---|
| 2295 | Field{2}=UvData.Field_1;% keep the stored field |
|---|
| 2296 | ParamOut_1=UvData.ParamOut_1; |
|---|
| 2297 | else |
|---|
| 2298 | if isempty(ParamIn_1) || isstruct(ParamIn_1) |
|---|
| 2299 | ParamIn_1.FieldName=FieldName_1; |
|---|
| 2300 | ParamIn_1.VelType=VelType_1; |
|---|
| 2301 | ParamIn_1.Coord_x=get(handles.Coord_x,'String'); |
|---|
| 2302 | ParamIn_1.Coord_y=get(handles.Coord_y,'String'); |
|---|
| 2303 | end |
|---|
| 2304 | [Field{2},ParamOut_1,errormsg] = read_field(FileName_1,UvData.FileType{2},ParamIn_1,frame_index_1); |
|---|
| 2305 | if ~isempty(errormsg) |
|---|
| 2306 | errormsg=['error in reading ' FieldName_1 ' in ' FileName_1 ': ' errormsg]; |
|---|
| 2307 | return |
|---|
| 2308 | end |
|---|
| 2309 | if isstruct(ParamOut_1)&&~strcmp(ParamOut_1.FieldName,'get_field...')&& (strcmp(UvData.FileType{2},'civdata')||strcmp(UvData.FileType{2},'civx'))... |
|---|
| 2310 | &&~strcmp(ParamOut_1.FieldName,'velocity') && ~strcmp(ParamOut_1.FieldName,'get_field...') |
|---|
| 2311 | if ~check_proj_tps |
|---|
| 2312 | end |
|---|
| 2313 | end |
|---|
| 2314 | end |
|---|
| 2315 | Field{2}.ZIndex=z_index;%used for multi-plane 3D calibration |
|---|
| 2316 | end |
|---|
| 2317 | |
|---|
| 2318 | %% update uvmat interface |
|---|
| 2319 | if isfield(ParamOut,'Npx') |
|---|
| 2320 | set(handles.num_Npx,'String',num2str(ParamOut.Npx));% display image size on the interface |
|---|
| 2321 | set(handles.num_Npy,'String',num2str(ParamOut.Npy)); |
|---|
| 2322 | elseif isfield(ParamOut_1,'Npx') |
|---|
| 2323 | set(handles.num_Npx,'String',num2str(ParamOut_1.Npx));% display image size on the interface |
|---|
| 2324 | set(handles.num_Npy,'String',num2str(ParamOut_1.Npy)); |
|---|
| 2325 | end |
|---|
| 2326 | |
|---|
| 2327 | %% update the display menu for the first velocity type (first menuline) |
|---|
| 2328 | test_veltype=0; |
|---|
| 2329 | if (strcmp(UvData.FileType{1},'civx')||strcmp(UvData.FileType{1},'civdata'))&& ~strcmp(FieldName,'get_field...') |
|---|
| 2330 | test_veltype=1; |
|---|
| 2331 | set(handles.VelType,'Visible','on') |
|---|
| 2332 | set(handles.VelType_1,'Visible','on') |
|---|
| 2333 | set(handles.FixVelType,'Visible','on') |
|---|
| 2334 | menu=set_veltype_display(ParamOut.CivStage,UvData.FileType{1}); |
|---|
| 2335 | index_menu=strcmp(ParamOut.VelType,menu);%look for VelType in the menu |
|---|
| 2336 | index_val=find(index_menu,1); |
|---|
| 2337 | if isempty(index_val) |
|---|
| 2338 | index_val=1; |
|---|
| 2339 | end |
|---|
| 2340 | set(handles.VelType,'Value',index_val) |
|---|
| 2341 | if ~get(handles.SubField,'value') |
|---|
| 2342 | set(handles.VelType,'String',menu) |
|---|
| 2343 | set(handles.VelType_1,'Value',1) |
|---|
| 2344 | set(handles.VelType_1,'String',[{''};menu]) |
|---|
| 2345 | end |
|---|
| 2346 | else |
|---|
| 2347 | set(handles.VelType,'Visible','off') |
|---|
| 2348 | end |
|---|
| 2349 | |
|---|
| 2350 | %% update the display menu for the second velocity type (second menuline) |
|---|
| 2351 | test_veltype_1=0; |
|---|
| 2352 | if isempty(FileName_1) |
|---|
| 2353 | elseif ~test_keepdata_1 |
|---|
| 2354 | if (strcmp(UvData.FileType{2},'civx')||strcmp(UvData.FileType{2},'civdata'))&& ~strcmp(FieldName_1,'get_field...') |
|---|
| 2355 | test_veltype_1=1; |
|---|
| 2356 | set(handles.VelType_1,'Visible','on') |
|---|
| 2357 | menu=set_veltype_display(ParamOut_1.CivStage,UvData.FileType{2}); |
|---|
| 2358 | index_menu=strcmp(ParamOut_1.VelType,menu); |
|---|
| 2359 | set(handles.VelType_1,'Value',1+find(index_menu,1)) |
|---|
| 2360 | set(handles.VelType_1,'String',[{''};menu]) |
|---|
| 2361 | else |
|---|
| 2362 | set(handles.VelType_1,'Visible','off') |
|---|
| 2363 | end |
|---|
| 2364 | % update the second field menu: the same quantity |
|---|
| 2365 | if isstruct(ParamOut_1) |
|---|
| 2366 | % display the FieldName menu from the input file and pick the selected one: |
|---|
| 2367 | FieldList=get(handles.FieldName_1,'String'); |
|---|
| 2368 | field_index=strcmp(ParamOut_1.FieldName,FieldList); |
|---|
| 2369 | if ~isempty(field_index) |
|---|
| 2370 | set(handles.FieldName_1,'Value',find(field_index,1)) |
|---|
| 2371 | end |
|---|
| 2372 | end |
|---|
| 2373 | end |
|---|
| 2374 | if test_veltype||test_veltype_1 |
|---|
| 2375 | set(handles.FixVelType,'Visible','on') |
|---|
| 2376 | else |
|---|
| 2377 | set(handles.FixVelType,'Visible','off') |
|---|
| 2378 | end |
|---|
| 2379 | |
|---|
| 2380 | %% introduce w as background image by default for a new series (only for nbdim=2) |
|---|
| 2381 | if ~isfield(UvData,'NewSeries') |
|---|
| 2382 | UvData.NewSeries=1; |
|---|
| 2383 | end |
|---|
| 2384 | %put W as background image by default if NbDim=2: |
|---|
| 2385 | if UvData.NewSeries && isequal(get(handles.SubField,'Value'),0) && isfield(Field{1},'W') && ~isempty(Field{1}.W) && ~isequal(Field{1}.NbDim,3); |
|---|
| 2386 | set(handles.SubField,'Value',1); |
|---|
| 2387 | set(handles.RootPath_1,'String','"') |
|---|
| 2388 | set(handles.RootFile_1,'String','"') |
|---|
| 2389 | set(handles.SubDir_1,'String','"'); |
|---|
| 2390 | indices=fullfile_uvmat('','','','',NomType,num_i1,num_i2,num_j1,num_j2); |
|---|
| 2391 | set(handles.FileIndex_1,'String',indices) |
|---|
| 2392 | set(handles.FileExt_1,'String','"'); |
|---|
| 2393 | set(handles.FieldName_1,'Visible','on'); |
|---|
| 2394 | set(handles.FieldName_1,'Visible','on'); |
|---|
| 2395 | set(handles.RootPath_1,'Visible','on') |
|---|
| 2396 | set(handles.RootFile_1,'Visible','on') |
|---|
| 2397 | set(handles.SubDir_1,'Visible','on'); |
|---|
| 2398 | set(handles.FileIndex_1,'Visible','on'); |
|---|
| 2399 | set(handles.FileExt_1,'Visible','on'); |
|---|
| 2400 | set(handles.FieldName_1,'Visible','on'); |
|---|
| 2401 | Field{1}.AName='w'; |
|---|
| 2402 | end |
|---|
| 2403 | |
|---|
| 2404 | %% display time value of the current file |
|---|
| 2405 | abstime=[];%default inputs |
|---|
| 2406 | dt=[]; |
|---|
| 2407 | TimeUnit=''; |
|---|
| 2408 | if isfield(UvData,'TimeUnit') |
|---|
| 2409 | TimeUnit=UvData.TimeUnit;%retrieve info from update_rootinfo |
|---|
| 2410 | end |
|---|
| 2411 | TimeName=get(handles.TimeName,'String'); |
|---|
| 2412 | |
|---|
| 2413 | % time from xml file or video movie |
|---|
| 2414 | if strcmp(TimeName,'xml')||strcmp(TimeName,'video') |
|---|
| 2415 | if isempty(num_i2)||isnan(num_i2) |
|---|
| 2416 | num_i2=num_i1; |
|---|
| 2417 | end |
|---|
| 2418 | if isempty(num_j1)||isnan(num_j1) |
|---|
| 2419 | num_j1=1; |
|---|
| 2420 | end |
|---|
| 2421 | if isempty(num_j2)||isnan(num_j2) |
|---|
| 2422 | num_j2=num_j1; |
|---|
| 2423 | end |
|---|
| 2424 | siz=size(UvData.XmlData{1}.Time); |
|---|
| 2425 | if ~isempty(num_i1)&& ~isempty(num_i2) && num_i1>=0 &&siz(1)>=max(num_i1+1,num_i2+1) && siz(2)>=max(num_j1+1,num_j2+1) |
|---|
| 2426 | abstime=(UvData.XmlData{1}.Time(num_i1+1,num_j1+1)+UvData.XmlData{1}.Time(num_i2+1,num_j2+1))/2;%overset the time read from files |
|---|
| 2427 | dt=(UvData.XmlData{1}.Time(num_i2+1,num_j2+1)-UvData.XmlData{1}.Time(num_i1+1,num_j1+1)); |
|---|
| 2428 | Field{1}.Dt=dt; |
|---|
| 2429 | if isfield(UvData.XmlData{1},'TimeUnit') |
|---|
| 2430 | TimeUnit=UvData.XmlData{1}.TimeUnit; |
|---|
| 2431 | end |
|---|
| 2432 | end |
|---|
| 2433 | end |
|---|
| 2434 | |
|---|
| 2435 | % time in the input file, not defined in a xml file or movie |
|---|
| 2436 | if isempty(abstime) |
|---|
| 2437 | if strcmp(TimeName,'civdata')||strcmp(TimeName,'civx') |
|---|
| 2438 | abstime=Field{1}.Time; |
|---|
| 2439 | elseif ~isempty(regexp(TimeName,'^att:', 'once')) |
|---|
| 2440 | abstime=Field{1}.(TimeName(5:end));%the time is an attribute selected by get_file |
|---|
| 2441 | if isfield(Field{1},[TimeName(5:end) 'Unit']) |
|---|
| 2442 | TimeUnit=Field{1}.([TimeName(5:end) 'Unit']); |
|---|
| 2443 | else |
|---|
| 2444 | TimeUnit=''; |
|---|
| 2445 | end |
|---|
| 2446 | elseif ~isempty(regexp(TimeName,'^var:')) |
|---|
| 2447 | abstime=Field{1}.(TimeName(5:end));%the time is a variale selected by get_file |
|---|
| 2448 | % TODO: look for time unit attribute |
|---|
| 2449 | elseif ~isempty(regexp(TimeName,'^dim:')) |
|---|
| 2450 | abstime=str2num(get(handles.i1,'String')); |
|---|
| 2451 | TimeUnit='index'; |
|---|
| 2452 | end |
|---|
| 2453 | if isfield(Field{1},'Dt') |
|---|
| 2454 | dt=Field{1}.Dt;%dt read from the netcdf input file |
|---|
| 2455 | elseif numel(Field)==2 && isfield(Field{2},'Dt')%dt obtained from the second field if not defined in the first |
|---|
| 2456 | dt=Field{2}.Dt;%dt read from the netcdf input file |
|---|
| 2457 | end |
|---|
| 2458 | end |
|---|
| 2459 | set(handles.TimeValue,'String',num2str(abstime)) |
|---|
| 2460 | |
|---|
| 2461 | %% display time value of the second current file if relevant |
|---|
| 2462 | abstime_1=[]; |
|---|
| 2463 | if ~isempty(FileName_1) |
|---|
| 2464 | TimeName_1=get(handles.TimeName_1,'String');% indicate whether time is from xml or video |
|---|
| 2465 | % time from xml file or video movie as a second file series |
|---|
| 2466 | if strcmp(TimeName_1,'xml')||strcmp(TimeName_1,'video') |
|---|
| 2467 | if numel(UvData.XmlData)==2 |
|---|
| 2468 | if isempty(i2_1) |
|---|
| 2469 | i2_1=num_i1; |
|---|
| 2470 | end |
|---|
| 2471 | if isempty(j1_1) |
|---|
| 2472 | j1_1=1; |
|---|
| 2473 | end |
|---|
| 2474 | if isempty(j2_1) |
|---|
| 2475 | j2_1=j1_1; |
|---|
| 2476 | end |
|---|
| 2477 | siz=size(UvData.XmlData{2}.Time); |
|---|
| 2478 | if ~isempty(i1_1) && siz(1)>=max(i1_1+1,i2_1+1) && siz(2)>=max(j1_1+1,j2_1+1) |
|---|
| 2479 | abstime_1=(UvData.XmlData{2}.Time(i1_1+1,j1_1+1)+UvData.XmlData{2}.Time(i2_1+1,j2_1+1))/2;%overset the time read from files |
|---|
| 2480 | Field{2}.Dt=(UvData.XmlData{2}.Time(i2_1+1,j2_1+1)-UvData.XmlData{2}.Time(i1_1+1,j1_1+1)); |
|---|
| 2481 | end |
|---|
| 2482 | end |
|---|
| 2483 | end |
|---|
| 2484 | |
|---|
| 2485 | % get time in the input file of the second series, not defined in a xml file or movie |
|---|
| 2486 | if isempty(abstime_1) && numel(Field)==2 |
|---|
| 2487 | if strcmp(TimeName_1,'civdata')||strcmp(TimeName_1,'civx') |
|---|
| 2488 | abstime_1=Field{2}.Time; |
|---|
| 2489 | elseif ~isempty(regexp(TimeName_1,'^att:')) ||~isempty(regexp(TimeName_1,'^dim:'))||~isempty(regexp(TimeName_1,'^var:')) |
|---|
| 2490 | abstime_1=Field{2}.(TimeName_1(5:end));%the time is an attribute or variale selected by get_file |
|---|
| 2491 | end |
|---|
| 2492 | end |
|---|
| 2493 | set(handles.TimeValue_1,'String',num2str(abstime_1,5)) |
|---|
| 2494 | end |
|---|
| 2495 | |
|---|
| 2496 | if isempty(dt)||isequal(dt,0) |
|---|
| 2497 | set(handles.Dt_txt,'String','') |
|---|
| 2498 | else |
|---|
| 2499 | if isempty(TimeUnit) |
|---|
| 2500 | set(handles.Dt_txt,'String',['Dt=' num2str(1000*dt,3) ' 10^(-3)'] ) |
|---|
| 2501 | else |
|---|
| 2502 | set(handles.Dt_txt,'String',['Dt=' num2str(1000*dt,3) ' m' TimeUnit] ) |
|---|
| 2503 | end |
|---|
| 2504 | end |
|---|
| 2505 | |
|---|
| 2506 | %% Time title with unit |
|---|
| 2507 | if isempty(abstime)&&isempty(abstime_1) |
|---|
| 2508 | Time_title=''; |
|---|
| 2509 | else |
|---|
| 2510 | Time_title='Time'; |
|---|
| 2511 | if ~isempty(TimeUnit) |
|---|
| 2512 | Time_title=['Time (' TimeUnit ')']; |
|---|
| 2513 | end |
|---|
| 2514 | end |
|---|
| 2515 | set(handles.Time_title,'String',Time_title) |
|---|
| 2516 | |
|---|
| 2517 | %% store the current open names, fieldname and vel types in uvmat interface |
|---|
| 2518 | UvData.FileName_1=FileName_1; |
|---|
| 2519 | UvData.ParamOut_1=ParamOut_1; |
|---|
| 2520 | if numel(Field)==2 |
|---|
| 2521 | UvData.Field_1=Field{2}; %store the second field for possible use at next RUN |
|---|
| 2522 | end |
|---|
| 2523 | |
|---|
| 2524 | %% apply coordinate transform or other user fct |
|---|
| 2525 | transform=get(handles.TransformPath,'UserData'); |
|---|
| 2526 | if isempty(transform) |
|---|
| 2527 | UvData.Field=Field{1}; |
|---|
| 2528 | else |
|---|
| 2529 | XmlData=[];%default |
|---|
| 2530 | XmlData_1=[];%default |
|---|
| 2531 | if isfield(UvData,'XmlData')%use geometry calib recorded from the ImaDoc xml file as first priority |
|---|
| 2532 | XmlData=UvData.XmlData{1}; |
|---|
| 2533 | if numel(UvData.XmlData)==2 |
|---|
| 2534 | XmlData_1=UvData.XmlData{2}; |
|---|
| 2535 | end |
|---|
| 2536 | end |
|---|
| 2537 | switch nargin(transform) |
|---|
| 2538 | case 4 |
|---|
| 2539 | if length(Field)==2 |
|---|
| 2540 | UvData.Field=transform(Field{1},XmlData,Field{2},XmlData_1); |
|---|
| 2541 | else |
|---|
| 2542 | UvData.Field=transform(Field{1},XmlData); |
|---|
| 2543 | end |
|---|
| 2544 | case 3 |
|---|
| 2545 | if length(Field)==2 |
|---|
| 2546 | UvData.Field=transform(Field{1},XmlData,Field{2}); |
|---|
| 2547 | else |
|---|
| 2548 | UvData.Field=transform(Field{1},XmlData); |
|---|
| 2549 | end |
|---|
| 2550 | case 2 |
|---|
| 2551 | UvData.Field=transform(Field{1},XmlData); |
|---|
| 2552 | case 1 |
|---|
| 2553 | UvData.Field=transform(Field{1}); |
|---|
| 2554 | end |
|---|
| 2555 | end |
|---|
| 2556 | |
|---|
| 2557 | %% calculate tps coefficients if needed |
|---|
| 2558 | UvData.Field=tps_coeff_field(UvData.Field,check_proj_tps); |
|---|
| 2559 | |
|---|
| 2560 | %% get bounds and dimensions of the input field |
|---|
| 2561 | UvData.Field=find_field_bounds(UvData.Field); |
|---|
| 2562 | |
|---|
| 2563 | testnewseries=UvData.NewSeries; |
|---|
| 2564 | UvData.NewSeries=0;% put to 0 the test for a new field series (set by RootPath_callback) |
|---|
| 2565 | |
|---|
| 2566 | %% reset the min and max of scalar if only the mask is displayed(TODO: check the need) |
|---|
| 2567 | % if isfield(UvData,'Mask')&& ~isfield(UvData,'A') |
|---|
| 2568 | % set(handles.num_MinA,'String','0') |
|---|
| 2569 | % set(handles.num_MaxA,'String','255') |
|---|
| 2570 | % end |
|---|
| 2571 | |
|---|
| 2572 | %% usual 1D (x,y) plots |
|---|
| 2573 | if UvData.Field.NbDim<=1 |
|---|
| 2574 | set(handles.Objects,'Visible','off') |
|---|
| 2575 | [PlotType,PlotParamOut]=plot_field(UvData.Field,handles.PlotAxes,read_GUI(handles.uvmat)); |
|---|
| 2576 | errormsg=fill_GUI(PlotParamOut,handles.uvmat); |
|---|
| 2577 | for list={'Scalar','Vectors'} |
|---|
| 2578 | if ~isfield(PlotParamOut,list{1}) |
|---|
| 2579 | set(handles.(list{1}),'Visible','off') |
|---|
| 2580 | end |
|---|
| 2581 | end |
|---|
| 2582 | set(handles.uvmat,'UserData',UvData) |
|---|
| 2583 | %% 2D or 3D fieldname are generally projected |
|---|
| 2584 | else |
|---|
| 2585 | set(handles.Objects,'Visible','on') |
|---|
| 2586 | |
|---|
| 2587 | %% Plot the projections on the selected projection objects |
|---|
| 2588 | %if no projection object exists, create a default one |
|---|
| 2589 | if isempty(UvData.ProjObject{1}) |
|---|
| 2590 | set(handles.ListObject,'Value',1) |
|---|
| 2591 | set(handles.ListObject,'String',{'plane'}) |
|---|
| 2592 | UvData.ProjObject{1}.Type='plane';%main plotting plane |
|---|
| 2593 | UvData.ProjObject{1}.ProjMode='projection';%main plotting plane |
|---|
| 2594 | UvData.ProjObject{1}.DisplayHandle.uvmat=[]; %plane not visible in uvmat |
|---|
| 2595 | UvData.ProjObject{1}.DisplayHandle.view_field=[]; %plane not visible in uvmat |
|---|
| 2596 | set(handles.ListObject_1,'Value',1) |
|---|
| 2597 | set(handles.ListObject_1,'String',{'plane'}) |
|---|
| 2598 | if UvData.Field.NbDim==3 %3D case |
|---|
| 2599 | % ZBounds(1)=UvData.Field.ZMin; %minimum for the Z slider |
|---|
| 2600 | % ZBounds(2)=UvData.Field.ZMax;%maximum for the Z slider |
|---|
| 2601 | UvData.ProjObject{1}.NbDim=3;%test for 3D objects |
|---|
| 2602 | UvData.ProjObject{1}.RangeZ=UvData.Field.CoordMesh;%main plotting plane |
|---|
| 2603 | UvData.ProjObject{1}.Coord(1,3)=(UvData.Field.ZMin+UvData.Field.ZMax)/2;%section at a middle plane chosen |
|---|
| 2604 | UvData.ProjObject{1}.Angle=[0 0 0]; |
|---|
| 2605 | elseif isfield(UvData,'Z') |
|---|
| 2606 | %multilevel case (single menuplane in a 3D space) |
|---|
| 2607 | if isfield(UvData,'CoordType')&& isequal(UvData.CoordType,'phys') && isfield(UvData,'XmlData') |
|---|
| 2608 | XmlData=UvData.XmlData{1}; |
|---|
| 2609 | if isfield(XmlData,'PlanePos') |
|---|
| 2610 | UvData.ProjObject{1}.Coord=XmlData.PlanePos(UvData.ZIndex,:); |
|---|
| 2611 | end |
|---|
| 2612 | if isfield(XmlData,'PlaneAngle') |
|---|
| 2613 | siz=size(XmlData.PlaneAngle); |
|---|
| 2614 | indangle=min(siz(1),UvData.ZIndex);%take first angle if a single angle is defined (translating scanning) |
|---|
| 2615 | UvData.ProjObject{1}.PlaneAngle=XmlData.PlaneAngle(indangle,:); |
|---|
| 2616 | end |
|---|
| 2617 | elseif isfield(UvData,'ZIndex') |
|---|
| 2618 | UvData.ProjObject{1}.ZObject=UvData.ZIndex; |
|---|
| 2619 | end |
|---|
| 2620 | end |
|---|
| 2621 | end |
|---|
| 2622 | IndexObj=get(handles.ListObject_1,'Value');%selected projection object for main view |
|---|
| 2623 | if IndexObj> numel(UvData.ProjObject) |
|---|
| 2624 | IndexObj=1;%select the first object if the selected one does not exist |
|---|
| 2625 | set(handles.ListObject_1,'Value',1) |
|---|
| 2626 | end |
|---|
| 2627 | if get(handles.CheckViewField,'Value') |
|---|
| 2628 | IndexObj_2=get(handles.ListObject,'Value');%selected projection object for view_field |
|---|
| 2629 | if ~isequal(IndexObj_2,IndexObj(1)) |
|---|
| 2630 | IndexObj(2)=IndexObj_2; |
|---|
| 2631 | end |
|---|
| 2632 | end |
|---|
| 2633 | plot_handles{1}=handles; |
|---|
| 2634 | if isfield(UvData,'plotaxes')%case of movies |
|---|
| 2635 | haxes(1)=UvData.plotaxes; |
|---|
| 2636 | else |
|---|
| 2637 | haxes(1)=handles.PlotAxes; |
|---|
| 2638 | end |
|---|
| 2639 | PlotParam{1}=read_GUI(handles.uvmat); |
|---|
| 2640 | %default settings if vectors not visible |
|---|
| 2641 | if ~isfield(PlotParam{1},'Vectors') |
|---|
| 2642 | PlotParam{1}.Vectors.MaxVec=1; |
|---|
| 2643 | PlotParam{1}.Vectors.MinVec=0; |
|---|
| 2644 | PlotParam{1}.Vectors.CheckFixVecColor=1; |
|---|
| 2645 | PlotParam{1}.Vectors.ColCode1=0.33; |
|---|
| 2646 | PlotParam{1}.Vectors.ColCode2=0.66; |
|---|
| 2647 | PlotParam{1}.Vectors.ColorScalar={''}; |
|---|
| 2648 | PlotParam{1}.Vectors.ColorCode= {'rgb'}; |
|---|
| 2649 | end |
|---|
| 2650 | %PosColorbar{1}=UvData.OpenParam.PosColorbar;%prescribe the colorbar position on the uvmat interface |
|---|
| 2651 | |
|---|
| 2652 | %% second projection object (view_field display) |
|---|
| 2653 | if length( IndexObj)==2 |
|---|
| 2654 | view_field_handle=findobj(allchild(0),'tag','view_field');%handles of the view_field GUI |
|---|
| 2655 | if ~isempty(view_field_handle) |
|---|
| 2656 | plot_handles{2}=guidata(view_field_handle); |
|---|
| 2657 | haxes(2)=plot_handles{2}.PlotAxes; |
|---|
| 2658 | PlotParam{2}=read_GUI(view_field_handle); |
|---|
| 2659 | %PosColorbar{2}='*'; %TODO: deal with colorbar position on view_field |
|---|
| 2660 | end |
|---|
| 2661 | end |
|---|
| 2662 | |
|---|
| 2663 | %% loop on the projection objects: one or two |
|---|
| 2664 | |
|---|
| 2665 | for imap=1:numel(IndexObj) |
|---|
| 2666 | iobj=IndexObj(imap); |
|---|
| 2667 | if numel(UvData.ProjObject)<iobj |
|---|
| 2668 | break |
|---|
| 2669 | end |
|---|
| 2670 | if UvData.Field.NbDim==3 |
|---|
| 2671 | UvData.ProjObject{iobj}.NbDim=3;%test for 3D objects |
|---|
| 2672 | if ~isfield(UvData.ProjObject{iobj},'RangeZ') |
|---|
| 2673 | UvData.ProjObject{iobj}.RangeZ=UvData.Field.CoordMesh;%main plotting plane |
|---|
| 2674 | end |
|---|
| 2675 | if ~(isfield(UvData.ProjObject{iobj},'Coord') && UvData.ProjObject{iobj}.Coord(1,3)<UvData.Field.ZMax && UvData.ProjObject{iobj}.Coord(1,3)>UvData.Field.ZMin) |
|---|
| 2676 | UvData.ProjObject{iobj}.Coord(1,3)=(UvData.Field.ZMin+UvData.Field.ZMax)/2;%section at a middle plane chosen |
|---|
| 2677 | end |
|---|
| 2678 | end |
|---|
| 2679 | [ObjectData,errormsg]=proj_field(UvData.Field,UvData.ProjObject{iobj});% project field on the object |
|---|
| 2680 | if ~isempty(errormsg) |
|---|
| 2681 | return |
|---|
| 2682 | end |
|---|
| 2683 | if testnewseries |
|---|
| 2684 | PlotParam{imap}.Scalar.CheckBW=[]; %B/W option depends on the input field (image or scalar) |
|---|
| 2685 | if isfield(ObjectData,'CoordUnit') |
|---|
| 2686 | PlotParam{imap}.Axes.CheckFixAspectRatio=1;% set x and y scaling equal if CoordUnit is defined (common unit for x and y) |
|---|
| 2687 | PlotParam{imap}.Axes.AspectRatio=1; %set aspect ratio to 1 |
|---|
| 2688 | end |
|---|
| 2689 | end |
|---|
| 2690 | %use of mask (TODO: check) |
|---|
| 2691 | if isfield(ObjectData,'NbDim') && isequal(ObjectData.NbDim,2) && isfield(ObjectData,'Mask') && isfield(ObjectData,'A') |
|---|
| 2692 | flag_mask=double(ObjectData.Mask>200);%=0 for masked regions |
|---|
| 2693 | Coord_x=ObjectData.Coord_x;%x coordiantes for the scalar field |
|---|
| 2694 | Coord_y=ObjectData.Coord_y;%y coordinates for the scalar field |
|---|
| 2695 | MaskX=ObjectData.MaskX;%x coordiantes for the mask |
|---|
| 2696 | MaskY=ObjectData.MaskY;%y coordiantes for the mask |
|---|
| 2697 | if ~isequal(MaskX,Coord_x)||~isequal(MaskY,Coord_y) |
|---|
| 2698 | nxy=size(flag_mask); |
|---|
| 2699 | sizpx=(ObjectData.MaskX(end)-ObjectData.MaskX(1))/(nxy(2)-1);%size of a mask pixel |
|---|
| 2700 | sizpy=(ObjectData.MaskY(1)-ObjectData.MaskY(end))/(nxy(1)-1); |
|---|
| 2701 | x_mask=ObjectData.MaskX(1):sizpx:ObjectData.MaskX(end); % pixel x coordinates for image display |
|---|
| 2702 | y_mask=ObjectData.MaskY(1):-sizpy:ObjectData.MaskY(end);% pixel x coordinates for image display |
|---|
| 2703 | %project on the positions of the scalar |
|---|
| 2704 | npxy=size(ObjectData.A); |
|---|
| 2705 | dxy(1)=(ObjectData.Coord_y(end)-ObjectData.Coord_y(1))/(npxy(1)-1);%grid mesh in y |
|---|
| 2706 | dxy(2)=(ObjectData.Coord_x(end)-ObjectData.Coord_x(1))/(npxy(2)-1);%grid mesh in x |
|---|
| 2707 | xi=ObjectData.Coord_x(1):dxy(2):ObjectData.Coord_x(end); |
|---|
| 2708 | yi=ObjectData.Coord_y(1):dxy(1):ObjectData.Coord_y(end); |
|---|
| 2709 | [XI,YI]=meshgrid(xi,yi);% creates the matrix of regular coordinates |
|---|
| 2710 | flag_mask = interp2(x_mask,y_mask,flag_mask,XI,YI); |
|---|
| 2711 | end |
|---|
| 2712 | AClass=class(ObjectData.A); |
|---|
| 2713 | ObjectData.A=flag_mask.*double(ObjectData.A); |
|---|
| 2714 | ObjectData.A=feval(AClass,ObjectData.A); |
|---|
| 2715 | end |
|---|
| 2716 | set(handles.uvmat,'UserData',UvData) |
|---|
| 2717 | if ~isempty(ObjectData) |
|---|
| 2718 | %PlotType='none'; %default |
|---|
| 2719 | if imap==2 && isempty(view_field_handle) |
|---|
| 2720 | view_field(ObjectData) |
|---|
| 2721 | else |
|---|
| 2722 | [PlotType,PlotParamOut]=plot_field(ObjectData,haxes(imap),PlotParam{imap}); |
|---|
| 2723 | if imap==1 |
|---|
| 2724 | errormsg=fill_GUI(PlotParamOut,handles.uvmat); |
|---|
| 2725 | else |
|---|
| 2726 | errormsg=fill_GUI(PlotParamOut,view_field_handle); |
|---|
| 2727 | end |
|---|
| 2728 | for list={'Scalar','Vectors'} |
|---|
| 2729 | if ~isfield(PlotParamOut,list{1}) |
|---|
| 2730 | set(plot_handles{imap}.(list{1}),'Visible','off') |
|---|
| 2731 | end |
|---|
| 2732 | end |
|---|
| 2733 | if isfield(Field,'CoordMesh')&&~isempty(Field.CoordMesh) |
|---|
| 2734 | ObjectData.CoordMesh=Field.CoordMesh; % gives an estimated mesh size (useful for mouse action on the plot) |
|---|
| 2735 | end |
|---|
| 2736 | end |
|---|
| 2737 | end |
|---|
| 2738 | end |
|---|
| 2739 | |
|---|
| 2740 | %% update the mask |
|---|
| 2741 | if isequal(get(handles.CheckMask,'Value'),1)%if the mask option is on |
|---|
| 2742 | update_mask(handles); |
|---|
| 2743 | end |
|---|
| 2744 | |
|---|
| 2745 | %% prepare the menus of histograms and plot them (histogram of the whole volume in 3D case) |
|---|
| 2746 | menu_histo=(UvData.Field.ListVarName)';%list of field variables to be displayed for the menu of histogram display |
|---|
| 2747 | ind_skip=[]; |
|---|
| 2748 | % nb_histo=1; |
|---|
| 2749 | Ustring=''; |
|---|
| 2750 | Vstring=''; |
|---|
| 2751 | % suppress axes from the histogram menu |
|---|
| 2752 | for ivar=1:numel(menu_histo)%l loop on field variables: |
|---|
| 2753 | if isfield(UvData.Field,'VarAttribute') && numel(UvData.Field.VarAttribute)>=ivar && isfield(UvData.Field.VarAttribute{ivar},'Role') |
|---|
| 2754 | Role=UvData.Field.VarAttribute{ivar}.Role; |
|---|
| 2755 | switch Role |
|---|
| 2756 | case {'coord_x','coord_y','coord_z','dimvar'} |
|---|
| 2757 | ind_skip=[ind_skip ivar]; |
|---|
| 2758 | case {'vector_x'} |
|---|
| 2759 | Ustring=UvData.Field.ListVarName{ivar}; |
|---|
| 2760 | ind_skip=[ind_skip ivar]; |
|---|
| 2761 | case {'vector_y'} |
|---|
| 2762 | Vstring=UvData.Field.ListVarName{ivar}; |
|---|
| 2763 | ind_skip=[ind_skip ivar]; |
|---|
| 2764 | end |
|---|
| 2765 | end |
|---|
| 2766 | DimCell=UvData.Field.VarDimName{ivar}; |
|---|
| 2767 | DimName=''; |
|---|
| 2768 | if ischar(DimCell) |
|---|
| 2769 | DimName=DimCell; |
|---|
| 2770 | elseif iscell(DimCell)&& numel(DimCell)==1 |
|---|
| 2771 | DimName=DimCell{1}; |
|---|
| 2772 | end |
|---|
| 2773 | if strcmp(DimName,menu_histo{ivar}) |
|---|
| 2774 | ind_skip=[ind_skip ivar]; |
|---|
| 2775 | end |
|---|
| 2776 | end |
|---|
| 2777 | menu_histo(ind_skip)=[];% remove skipped items |
|---|
| 2778 | if ~isempty(Ustring) |
|---|
| 2779 | menu_histo=[{[Ustring ',' Vstring]};menu_histo];% add U, V at the beginning if they exist |
|---|
| 2780 | end |
|---|
| 2781 | |
|---|
| 2782 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 2783 | % display menus and plot histograms |
|---|
| 2784 | test_v=0; |
|---|
| 2785 | if ~isempty(menu_histo) |
|---|
| 2786 | set(handles.histo1_menu,'Value',1) |
|---|
| 2787 | set(handles.histo1_menu,'String',menu_histo) |
|---|
| 2788 | histo1_menu_Callback(handles.histo1_menu, [], handles)% plot first histogram |
|---|
| 2789 | end |
|---|
| 2790 | end |
|---|
| 2791 | |
|---|
| 2792 | if UvData.Field.NbDim==3 |
|---|
| 2793 | set(handles.CheckEditObject,'Value',1) |
|---|
| 2794 | CheckEditObject_Callback(handles.uvmat, [], handles) |
|---|
| 2795 | end |
|---|
| 2796 | %ResizeFcn(handles.uvmat,[],handles) |
|---|
| 2797 | set(handles.uvmat,'Pointer',pointer) |
|---|
| 2798 | |
|---|
| 2799 | %------------------------------------------------------------------------ |
|---|
| 2800 | function histo1_menu_Callback(hObject, eventdata, handles) |
|---|
| 2801 | %-------------------------------------------- |
|---|
| 2802 | %% get the current field stored in uvmat user data |
|---|
| 2803 | UvData=get(handles.uvmat,'UserData'); |
|---|
| 2804 | Field=UvData.Field; |
|---|
| 2805 | |
|---|
| 2806 | %% get from the menu 'histo1_menu' the name(s) of the fields to use |
|---|
| 2807 | histo_menu=get(handles.histo1_menu,'String'); |
|---|
| 2808 | histo_value=get(handles.histo1_menu,'Value'); |
|---|
| 2809 | FieldName=histo_menu{histo_value}; |
|---|
| 2810 | r=regexp(FieldName,'(?<var1>.*)(?<sep>,)(?<var2>.*)','names'); |
|---|
| 2811 | FieldName_2=''; |
|---|
| 2812 | if ~isempty(r) |
|---|
| 2813 | FieldName=r.var1;% name of first variable |
|---|
| 2814 | FieldName_2=r.var2;% name of second variable |
|---|
| 2815 | end |
|---|
| 2816 | if ~isfield(UvData.Field,FieldName) |
|---|
| 2817 | msgbox_uvmat('ERROR',['no field ' FieldName ' for histogram']) |
|---|
| 2818 | return |
|---|
| 2819 | end |
|---|
| 2820 | |
|---|
| 2821 | %% extract the fields to use |
|---|
| 2822 | % eliminate false data if relevant (false flag FF exists) |
|---|
| 2823 | check_false=0; |
|---|
| 2824 | if isfield(Field,'FF') && ~isempty(Field.FF) && isequal(size(Field.FF),size(Field.(FieldName))) |
|---|
| 2825 | indsel=find(Field.FF==0);%find values marked as false |
|---|
| 2826 | if ~isempty(indsel) |
|---|
| 2827 | FieldHisto=Field.(FieldName)(indsel);%field of the first variable (U) |
|---|
| 2828 | if ~isempty(FieldName_2) |
|---|
| 2829 | if isfield(Field,'NbDim') && Field.NbDim==3 |
|---|
| 2830 | FieldHisto(:,:,:,2)=Field.(FieldName_2)(indsel);%field of the second variable (U) |
|---|
| 2831 | else |
|---|
| 2832 | FieldHisto(:,:,2)=Field.(FieldName_2)(indsel);%field of the second variable (U) |
|---|
| 2833 | end |
|---|
| 2834 | end |
|---|
| 2835 | check_false=1; |
|---|
| 2836 | end |
|---|
| 2837 | end |
|---|
| 2838 | % no false data |
|---|
| 2839 | if ~check_false |
|---|
| 2840 | FieldHisto=Field.(FieldName);%field of the first variable (U) |
|---|
| 2841 | if ~isempty(FieldName_2) |
|---|
| 2842 | if isfield(Field,'NbDim') && Field.NbDim==3 |
|---|
| 2843 | FieldHisto(:,:,:,2)=Field.(FieldName_2);%field of the second variable (V) |
|---|
| 2844 | else |
|---|
| 2845 | FieldHisto(:,:,2)=Field.(FieldName_2);%field of the second variable (V) |
|---|
| 2846 | end |
|---|
| 2847 | end |
|---|
| 2848 | end |
|---|
| 2849 | |
|---|
| 2850 | %% calculate and plot histogram |
|---|
| 2851 | if isempty(Field) |
|---|
| 2852 | msgbox_uvmat('ERROR',['empty field ' FieldName]) |
|---|
| 2853 | else |
|---|
| 2854 | nxy=size(FieldHisto); |
|---|
| 2855 | Amin=double(min(min(min(min(FieldHisto)))));%min of field value |
|---|
| 2856 | Amax=double(max(max(max(max(FieldHisto)))));%max of field value |
|---|
| 2857 | if isequal(Amin,Amax) |
|---|
| 2858 | cla(handles.HistoAxes) |
|---|
| 2859 | else |
|---|
| 2860 | Histo.ListVarName={FieldName,'histo'}; |
|---|
| 2861 | if isfield(Field,'NbDim') && isequal(Field.NbDim,3) |
|---|
| 2862 | Histo.VarDimName={FieldName,FieldName}; %dimensions for the histogram |
|---|
| 2863 | else |
|---|
| 2864 | if numel(nxy)==2 |
|---|
| 2865 | Histo.VarDimName={FieldName,FieldName}; %dimensions for the histogram |
|---|
| 2866 | else |
|---|
| 2867 | Histo.VarDimName={FieldName,{FieldName,'component'}}; %dimensions for the histogram |
|---|
| 2868 | end |
|---|
| 2869 | end |
|---|
| 2870 | %unit |
|---|
| 2871 | units=[]; %default |
|---|
| 2872 | for ivar=1:numel(Field.ListVarName) |
|---|
| 2873 | if strcmp(Field.ListVarName{ivar},FieldName) |
|---|
| 2874 | if isfield(Field,'VarAttribute') && numel(Field.VarAttribute)>=ivar && isfield(Field.VarAttribute{ivar},'units') |
|---|
| 2875 | units=Field.VarAttribute{ivar}.units; |
|---|
| 2876 | break |
|---|
| 2877 | end |
|---|
| 2878 | end |
|---|
| 2879 | end |
|---|
| 2880 | if ~isempty(units) |
|---|
| 2881 | Histo.VarAttribute{1}.units=units; |
|---|
| 2882 | end |
|---|
| 2883 | Histo.(FieldName)=linspace(Amin,Amax,50); %absissa values for histo |
|---|
| 2884 | if isfield(Field,'NbDim') && isequal(Field.NbDim,3) |
|---|
| 2885 | C=reshape(double(FieldHisto),1,[]);% reshape in a vector |
|---|
| 2886 | Histo.histo(:,1)=hist(C, Histo.(FieldName)); %calculate histogram |
|---|
| 2887 | else |
|---|
| 2888 | for col=1:size(FieldHisto,3) |
|---|
| 2889 | B=FieldHisto(:,:,col); |
|---|
| 2890 | C=reshape(double(B),1,nxy(1)*nxy(2));% reshape in a vector |
|---|
| 2891 | Histo.histo(:,col)=hist(C, Histo.(FieldName)); %calculate histogram |
|---|
| 2892 | end |
|---|
| 2893 | end |
|---|
| 2894 | plot_field(Histo,handles.HistoAxes); |
|---|
| 2895 | hlegend=legend; |
|---|
| 2896 | if isempty(FieldName_2) |
|---|
| 2897 | set(hlegend,'String',FieldName) |
|---|
| 2898 | else |
|---|
| 2899 | set(hlegend,'String',{FieldName;FieldName_2}) |
|---|
| 2900 | end |
|---|
| 2901 | end |
|---|
| 2902 | end |
|---|
| 2903 | |
|---|
| 2904 | %------------------------------------------------------------------------ |
|---|
| 2905 | % --- translate coordinate to matrix index |
|---|
| 2906 | %------------------------------------------------------------------------ |
|---|
| 2907 | function [indx,indy]=pos2ind(x0,rangx0,nxy) |
|---|
| 2908 | indx=1+round((nxy(2)-1)*(x0-rangx0(1))/(rangx0(2)-rangx0(1)));% index x of pixel |
|---|
| 2909 | indy=1+round((nxy(1)-1)*(y12-rangy0(1))/(rangy0(2)-rangy0(1)));% index y of pixel |
|---|
| 2910 | |
|---|
| 2911 | %------------------------------------------------------------------------ |
|---|
| 2912 | % --- Executes on button press in 'CheckZoom'. |
|---|
| 2913 | %------------------------------------------------------------------------ |
|---|
| 2914 | function CheckZoom_Callback(hObject, eventdata, handles) |
|---|
| 2915 | |
|---|
| 2916 | if get(handles.CheckZoom,'Value') |
|---|
| 2917 | set(handles.CheckFixLimits,'Value',1)% propose by default fixed limits for the plotting axes |
|---|
| 2918 | set(handles.CheckZoomFig,'Value',0)%desactivate zoom fig |
|---|
| 2919 | end |
|---|
| 2920 | |
|---|
| 2921 | |
|---|
| 2922 | %------------------------------------------------------------------------ |
|---|
| 2923 | % --- Executes on button press in CheckZoomFig. |
|---|
| 2924 | %------------------------------------------------------------------------ |
|---|
| 2925 | function CheckZoomFig_Callback(hObject, eventdata, handles) |
|---|
| 2926 | |
|---|
| 2927 | if get(handles.CheckZoomFig,'Value') |
|---|
| 2928 | set(handles.CheckZoom,'value',0) |
|---|
| 2929 | end |
|---|
| 2930 | |
|---|
| 2931 | %------------------------------------------------------------------------ |
|---|
| 2932 | % --- Executes on button press in 'CheckFixLimits'. |
|---|
| 2933 | %------------------------------------------------------------------------ |
|---|
| 2934 | function CheckFixLimits_Callback(hObject, eventdata, handles) |
|---|
| 2935 | |
|---|
| 2936 | if ~get(handles.CheckFixLimits,'Value') |
|---|
| 2937 | update_plot(handles) |
|---|
| 2938 | set(handles.CheckZoom,'Value',0) |
|---|
| 2939 | end |
|---|
| 2940 | |
|---|
| 2941 | %------------------------------------------------------------------------ |
|---|
| 2942 | % --- Executes on button press in CheckFixAspectRatio. |
|---|
| 2943 | function CheckFixAspectRatio_Callback(hObject, eventdata, handles) |
|---|
| 2944 | %------------------------------------------------------------------------ |
|---|
| 2945 | update_plot(handles); |
|---|
| 2946 | |
|---|
| 2947 | %------------------------------------------------------------------------ |
|---|
| 2948 | function num_AspectRatio_Callback(hObject, eventdata, handles) |
|---|
| 2949 | %------------------------------------------------------------------------ |
|---|
| 2950 | set(handles.CheckFixAspectRatio,'Value',1)% select the fixed aspect ratio button |
|---|
| 2951 | update_plot(handles); |
|---|
| 2952 | |
|---|
| 2953 | %------------------------------------------------------------------------ |
|---|
| 2954 | %----Executes on button press in 'record': records the current flags of manual correction. |
|---|
| 2955 | %------------------------------------------------------------------------ |
|---|
| 2956 | function record_Callback(hObject, eventdata, handles) |
|---|
| 2957 | |
|---|
| 2958 | [RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes(handles); |
|---|
| 2959 | FileName=[fullfile(RootPath,SubDir,RootFile) FileIndices FileExt]; |
|---|
| 2960 | [erread,message]=fileattrib(FileName); |
|---|
| 2961 | if ~isempty(message) && ~isequal(message.UserWrite,1) |
|---|
| 2962 | msgbox_uvmat('ERROR',['no writting access to ' FileName]) |
|---|
| 2963 | return |
|---|
| 2964 | end |
|---|
| 2965 | MenuVelType=get(handles.VelType,'String'); |
|---|
| 2966 | test_civ2=strcmp(MenuVelType{get(handles.VelType,'Value')},'civ2'); |
|---|
| 2967 | test_civ1=strcmp(MenuVelType{get(handles.VelType,'Value')},'civ1'); |
|---|
| 2968 | if ~test_civ2 && ~test_civ1 |
|---|
| 2969 | msgbox_uvmat('ERROR','manual correction only possible for CIV1 or CIV2 velocity fields') |
|---|
| 2970 | end |
|---|
| 2971 | if test_civ2 |
|---|
| 2972 | nbname='nb_vec_2'; |
|---|
| 2973 | flagname='Civ2_FF'; |
|---|
| 2974 | CivStage=5; |
|---|
| 2975 | end |
|---|
| 2976 | if test_civ1 |
|---|
| 2977 | nbname='nb_vec_1'; |
|---|
| 2978 | flagname='Civ1_FF'; |
|---|
| 2979 | CivStage=2; |
|---|
| 2980 | end |
|---|
| 2981 | %write fix flags in the netcdf file |
|---|
| 2982 | UvData=get(handles.uvmat,'UserData'); |
|---|
| 2983 | hhh=which('netcdf.open');% look for built-in matlab netcdf library |
|---|
| 2984 | if ~isequal(hhh,'')% case of builtin Matlab netcdf library |
|---|
| 2985 | nc=netcdf.open(FileName,'NC_WRITE'); |
|---|
| 2986 | netcdf.reDef(nc); |
|---|
| 2987 | netcdf.putAtt(nc,netcdf.getConstant('NC_GLOBAL'),'CivStage',CivStage); |
|---|
| 2988 | dimid = netcdf.inqDimID(nc,nbname); |
|---|
| 2989 | try |
|---|
| 2990 | varid = netcdf.inqVarID(nc,flagname);% look for already existing fixflag variable |
|---|
| 2991 | catch |
|---|
| 2992 | varid=netcdf.defVar(nc,flagname,'double',dimid);%create fixflag variable if it does not exist |
|---|
| 2993 | end |
|---|
| 2994 | netcdf.endDef(nc); |
|---|
| 2995 | netcdf.putVar(nc,varid,UvData.PlotAxes.FF); |
|---|
| 2996 | netcdf.close(nc); |
|---|
| 2997 | else %old netcdf library |
|---|
| 2998 | netcdf_toolbox(FileName,AxeData,attrname,nbname,flagname) |
|---|
| 2999 | end |
|---|
| 3000 | |
|---|
| 3001 | %------------------------------------------------------------------- |
|---|
| 3002 | %----Correct the netcdf file, using toolbox (old versions of Matlab). |
|---|
| 3003 | %------------------------------------------------------------------- |
|---|
| 3004 | function netcdf_toolbox(FileName,AxeData,attrname,nbname,flagname) |
|---|
| 3005 | nc=netcdf(FileName,'write'); %open netcdf file |
|---|
| 3006 | result=redef(nc); |
|---|
| 3007 | eval(['nc.' attrname '=1;']); |
|---|
| 3008 | theDim=nc(nbname) ;% get the number of velocity vectors |
|---|
| 3009 | nb_vectors=size(theDim); |
|---|
| 3010 | var_FixFlag=ncvar(flagname,nc);% var_FixFlag will be written as the netcdf variable vec_FixFlag |
|---|
| 3011 | var_FixFlag(1:nb_vectors)=AxeData.FF;% |
|---|
| 3012 | fin=close(nc); |
|---|
| 3013 | |
|---|
| 3014 | %----------------------------------------------------------------------- |
|---|
| 3015 | % --- Executes on button press in SubField |
|---|
| 3016 | %----------------------------------------------------------------------- |
|---|
| 3017 | function SubField_Callback(hObject, eventdata, handles) |
|---|
| 3018 | |
|---|
| 3019 | if get(handles.SubField,'Value')==0% if the subfield button is desactivated |
|---|
| 3020 | desable_subfield(handles) |
|---|
| 3021 | transform_fct_list=get(handles.TransformName,'String'); |
|---|
| 3022 | transform_fct=transform_fct_list(get(handles.TransformName,'Value')); |
|---|
| 3023 | if strcmp(transform_fct,'sub_field') |
|---|
| 3024 | set(handles.TransformName,'Value',1)%suppress the sub_field transform |
|---|
| 3025 | TransformName_Callback(hObject, eventdata, handles); |
|---|
| 3026 | else |
|---|
| 3027 | REFRESH_Callback(hObject, eventdata, handles) |
|---|
| 3028 | end |
|---|
| 3029 | else |
|---|
| 3030 | fileinput_1=uigetfile_uvmat('select a second input file:',get(handles.RootPath,'String')); |
|---|
| 3031 | if isempty(fileinput_1) |
|---|
| 3032 | set(handles.SubField,'Value',0) |
|---|
| 3033 | else |
|---|
| 3034 | % refresh the current displayed field |
|---|
| 3035 | display_file_name(handles,fileinput_1,2) |
|---|
| 3036 | |
|---|
| 3037 | %update list of recent files in the menubar |
|---|
| 3038 | MenuFile_1=fileinput_1; |
|---|
| 3039 | MenuFile_2=get(handles.MenuFile_1,'Label'); |
|---|
| 3040 | MenuFile_3=get(handles.MenuFile_2,'Label'); |
|---|
| 3041 | MenuFile_4=get(handles.MenuFile_3,'Label'); |
|---|
| 3042 | MenuFile_5=get(handles.MenuFile_4,'Label'); |
|---|
| 3043 | set(handles.MenuFile_1,'Label',MenuFile_1) |
|---|
| 3044 | set(handles.MenuFile_2,'Label',MenuFile_2) |
|---|
| 3045 | set(handles.MenuFile_3,'Label',MenuFile_3) |
|---|
| 3046 | set(handles.MenuFile_4,'Label',MenuFile_4) |
|---|
| 3047 | set(handles.MenuFile_5,'Label',MenuFile_5) |
|---|
| 3048 | end |
|---|
| 3049 | end |
|---|
| 3050 | |
|---|
| 3051 | %----------------------------------------------------------------------- |
|---|
| 3052 | % --- desactivate display used for a second file series |
|---|
| 3053 | %----------------------------------------------------------------------- |
|---|
| 3054 | function desable_subfield(handles) |
|---|
| 3055 | |
|---|
| 3056 | set(handles.RootPath_1,'String','') |
|---|
| 3057 | set(handles.RootFile_1,'String','') |
|---|
| 3058 | set(handles.SubDir_1,'String',''); |
|---|
| 3059 | set(handles.FileIndex_1,'String',''); |
|---|
| 3060 | set(handles.FileExt_1,'String',''); |
|---|
| 3061 | set(handles.RootPath_1,'Visible','off') |
|---|
| 3062 | set(handles.RootFile_1,'Visible','off') |
|---|
| 3063 | set(handles.SubDir_1,'Visible','off'); |
|---|
| 3064 | set(handles.NomType_1,'Visible','off'); |
|---|
| 3065 | set(handles.FileIndex_1,'Visible','off'); |
|---|
| 3066 | set(handles.FileExt_1,'Visible','off'); |
|---|
| 3067 | set(handles.TimeName_1,'String',''); |
|---|
| 3068 | set(handles.TimeName_1,'Visible','off'); |
|---|
| 3069 | set(handles.TimeValue_1,'String',''); |
|---|
| 3070 | set(handles.TimeValue_1,'Visible','off'); |
|---|
| 3071 | set(handles.FieldName_1,'Value',1);%set to blank state |
|---|
| 3072 | set(handles.VelType_1,'Value',1);%set to blank state |
|---|
| 3073 | set(handles.num_Opacity,'String','')% desactivate opacity setting |
|---|
| 3074 | FieldList=get(handles.FieldName,'String'); |
|---|
| 3075 | if numel(FieldList)>1 % if a choice of fields exists |
|---|
| 3076 | set(handles.FieldName_1,'Value',1)% set second field choice to blank |
|---|
| 3077 | set(handles.FieldName_1,'String',[{''};FieldList])% reproduce the menu FieldName plus a blank option |
|---|
| 3078 | else |
|---|
| 3079 | set(handles.FieldName_1,'String',{''})% set second field choice to blank |
|---|
| 3080 | end |
|---|
| 3081 | if ~strcmp(get(handles.VelType,'Visible'),'on') |
|---|
| 3082 | set(handles.VelType_1,'Visible','off') |
|---|
| 3083 | end |
|---|
| 3084 | UvData=get(handles.uvmat,'UserData'); |
|---|
| 3085 | if isfield(UvData,'XmlData_1') |
|---|
| 3086 | UvData=rmfield(UvData,'XmlData_1'); |
|---|
| 3087 | end |
|---|
| 3088 | set(handles.uvmat,'UserData',UvData); |
|---|
| 3089 | |
|---|
| 3090 | %------------------------------------------------------------------------ |
|---|
| 3091 | % --- read the data displayed for the input rootfile windows (new): TODO use read_GUI |
|---|
| 3092 | %------------------------------------------------------------------------ |
|---|
| 3093 | function [RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes(handles) |
|---|
| 3094 | |
|---|
| 3095 | InputFile=read_GUI(handles.InputFile); |
|---|
| 3096 | RootPath=InputFile.RootPath; |
|---|
| 3097 | SubDir=regexprep(InputFile.SubDir,'/|\',''); |
|---|
| 3098 | RootFile=regexprep(InputFile.RootFile,'/|\',''); |
|---|
| 3099 | FileIndices=InputFile.FileIndex; |
|---|
| 3100 | FileExt=InputFile.FileExt; |
|---|
| 3101 | |
|---|
| 3102 | |
|---|
| 3103 | %------------------------------------------------------------------------ |
|---|
| 3104 | % ---- read the data displayed for the second input rootfile windows |
|---|
| 3105 | %------------------------------------------------------------------------ |
|---|
| 3106 | function [RootPath_1,SubDir_1,RootFile_1,FileIndex_1,FileExt_1,NomType_1]=read_file_boxes_1(handles) |
|---|
| 3107 | |
|---|
| 3108 | RootPath_1=get(handles.RootPath_1,'String'); % read the data from the file1_input window |
|---|
| 3109 | if isequal(get(handles.RootPath_1,'Visible'),'off') || isequal(RootPath_1,'"') |
|---|
| 3110 | RootPath_1=get(handles.RootPath,'String'); |
|---|
| 3111 | end; |
|---|
| 3112 | SubDir_1=get(handles.SubDir_1,'String'); |
|---|
| 3113 | if isequal(get(handles.SubDir_1,'Visible'),'off')|| isequal(SubDir_1,'"') |
|---|
| 3114 | SubDir_1=get(handles.SubDir,'String'); |
|---|
| 3115 | end |
|---|
| 3116 | SubDir_1=regexprep(SubDir_1,'\<[\\/]|[\\/]\>','');%suppress possible / or \ separator at the beginning or the end of the string |
|---|
| 3117 | RootFile_1=get(handles.RootFile_1,'String'); |
|---|
| 3118 | if isequal(get(handles.RootFile_1,'Visible'),'off') || isequal(RootFile_1,'"') |
|---|
| 3119 | RootFile_1=get(handles.RootFile,'String'); |
|---|
| 3120 | end |
|---|
| 3121 | RootFile_1=regexprep(RootFile_1,'\<[\\/]|[\\/]\>','');%suppress possible / or \ separator at the beginning or the end of the string |
|---|
| 3122 | FileIndex_1=get(handles.FileIndex_1,'String'); |
|---|
| 3123 | if isequal(get(handles.FileIndex_1,'Visible'),'off')|| isequal(FileIndex_1,'"') |
|---|
| 3124 | FileIndex_1=get(handles.FileIndex,'String'); |
|---|
| 3125 | end |
|---|
| 3126 | FileExt_1=get(handles.FileExt_1,'String'); |
|---|
| 3127 | if isequal(get(handles.FileExt_1,'Visible'),'off') || isequal(FileExt_1,'"') |
|---|
| 3128 | FileExt_1=get(handles.FileExt,'String');%read FileExt by default |
|---|
| 3129 | end |
|---|
| 3130 | NomType_1=get(handles.NomType_1,'String'); |
|---|
| 3131 | if isequal(get(handles.NomType_1,'Visible'),'off') || isequal(NomType_1,'"') |
|---|
| 3132 | NomType_1=get(handles.NomType,'String');%read FileExt by default |
|---|
| 3133 | end |
|---|
| 3134 | %------------------------------------------------------------------------ |
|---|
| 3135 | % --- Executes on menu selection FieldName |
|---|
| 3136 | |
|---|
| 3137 | function FieldName_Callback(hObject, eventdata, handles) |
|---|
| 3138 | %------------------------------------------------------------------------ |
|---|
| 3139 | |
|---|
| 3140 | %% read data from uvmat |
|---|
| 3141 | UvData=get(handles.uvmat,'UserData'); |
|---|
| 3142 | list_fields=get(handles.FieldName,'String');% list menu fields |
|---|
| 3143 | index_fields=get(handles.FieldName,'Value');% selected string index |
|---|
| 3144 | field= list_fields{index_fields(1)}; % selected string |
|---|
| 3145 | [RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes(handles); |
|---|
| 3146 | FileName=[fullfile(RootPath,SubDir,RootFile) FileIndices FileExt]; |
|---|
| 3147 | [tild,tild,tild,i1,i2,j1,j2,tild,NomType]=fileparts_uvmat(['xxx' get(handles.FileIndex,'String') FileExt]); |
|---|
| 3148 | |
|---|
| 3149 | switch field |
|---|
| 3150 | case 'get_field...' |
|---|
| 3151 | %% fill the axes and variables from selections in get_field |
|---|
| 3152 | ParamIn.Title='get_field: choose input field for display in uvmat' ; |
|---|
| 3153 | % in case of civ data, we use the civ choice as default input for the GUI get_field |
|---|
| 3154 | if strcmp(get(handles.VelType,'Visible'),'on') |
|---|
| 3155 | ParamIn.SwitchVarIndexTime='attribute'; |
|---|
| 3156 | ListVelType=get(handles.VelType,'String'); |
|---|
| 3157 | VelType=ListVelType{get(handles.VelType,'Value')}; |
|---|
| 3158 | switch VelType |
|---|
| 3159 | case 'civ1' |
|---|
| 3160 | ParamIn.TimeAttrName='Civ1_Time'; |
|---|
| 3161 | ParamIn.vector_x='Civ1_U'; |
|---|
| 3162 | ParamIn.vector_y='Civ1_V'; |
|---|
| 3163 | ParamIn.vec_color='Civ1_C'; |
|---|
| 3164 | case 'filter1' |
|---|
| 3165 | ParamIn.TimeAttrName='Civ1_Time'; |
|---|
| 3166 | ParamIn.vector_x='Civ1_U_smooth'; |
|---|
| 3167 | ParamIn.vector_y='Civ1_V_smooth'; |
|---|
| 3168 | case 'civ2' |
|---|
| 3169 | ParamIn.TimeAttrName='Civ2_Time'; |
|---|
| 3170 | ParamIn.vector_x='Civ2_U'; |
|---|
| 3171 | ParamIn.vector_y='Civ2_V'; |
|---|
| 3172 | case 'filter2' |
|---|
| 3173 | ParamIn.TimeAttrName='Civ2_Time'; |
|---|
| 3174 | ParamIn.vector_x='Civ2_U_smooth'; |
|---|
| 3175 | ParamIn.vector_y='Civ2_V_smooth'; |
|---|
| 3176 | ParamIn.vec_color='Civ2_C'; |
|---|
| 3177 | end |
|---|
| 3178 | end |
|---|
| 3179 | |
|---|
| 3180 | % VelType menu desactivated |
|---|
| 3181 | set(handles.FixVelType,'visible','off') |
|---|
| 3182 | set(handles.VelType,'Visible','off') |
|---|
| 3183 | |
|---|
| 3184 | %read selection from get_field |
|---|
| 3185 | [RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes(handles); |
|---|
| 3186 | FileName=[fullfile(RootPath,SubDir,RootFile) FileIndices FileExt]; |
|---|
| 3187 | GetFieldData=get_field(FileName,ParamIn);% inport field names from the GUI get_field |
|---|
| 3188 | FieldList={}; |
|---|
| 3189 | VecColorList={''}; |
|---|
| 3190 | ZName=''; |
|---|
| 3191 | switch GetFieldData.FieldOption |
|---|
| 3192 | case 'vectors' |
|---|
| 3193 | UName=GetFieldData.PanelVectors.vector_x; |
|---|
| 3194 | VName=GetFieldData.PanelVectors.vector_y; |
|---|
| 3195 | YName=GetFieldData.Coordinates.Coord_y; |
|---|
| 3196 | if isfield(GetFieldData.Coordinates,'Coord_z') |
|---|
| 3197 | ZName=GetFieldData.Coordinates.Coord_z; |
|---|
| 3198 | end |
|---|
| 3199 | CName=GetFieldData.PanelVectors.vec_color; |
|---|
| 3200 | FieldList={['vec(' UName ',' VName ')'];... |
|---|
| 3201 | ['norm(' UName ',' VName ')'];... |
|---|
| 3202 | UName;VName}; |
|---|
| 3203 | VecColorList={['norm(' UName ',' VName ')'];... |
|---|
| 3204 | UName;VName}; |
|---|
| 3205 | if ~isempty(CName) |
|---|
| 3206 | VecColorList=[{CName};VecColorList]; |
|---|
| 3207 | end |
|---|
| 3208 | case 'scalar' |
|---|
| 3209 | AName=GetFieldData.PanelScalar.scalar; |
|---|
| 3210 | YName=GetFieldData.Coordinates.Coord_y; |
|---|
| 3211 | if isfield(GetFieldData.Coordinates,'Coord_z') |
|---|
| 3212 | ZName=GetFieldData.Coordinates.Coord_z; |
|---|
| 3213 | end |
|---|
| 3214 | FieldList={AName}; |
|---|
| 3215 | case '1D plot' |
|---|
| 3216 | YName=GetFieldData.PanelOrdinate.ordinate; |
|---|
| 3217 | case 'civdata...'%reinitiate input, return to automatic civ data reading |
|---|
| 3218 | display_file_name(handles,FileName,1) |
|---|
| 3219 | end |
|---|
| 3220 | % get time as file index, attribute, variable or matrix index |
|---|
| 3221 | if ~strcmp(GetFieldData.FieldOption,'civdata...') |
|---|
| 3222 | XName=GetFieldData.Coordinates.Coord_x; |
|---|
| 3223 | TimeNameStr=GetFieldData.Time.SwitchVarIndexTime; |
|---|
| 3224 | switch TimeNameStr |
|---|
| 3225 | case 'file index' |
|---|
| 3226 | set(handles.TimeName,'String',''); |
|---|
| 3227 | case 'attribute' |
|---|
| 3228 | set(handles.TimeName,'String',['att:' GetFieldData.Time.TimeName]); |
|---|
| 3229 | case 'variable' |
|---|
| 3230 | set(handles.TimeName,'String',['var:' GetFieldData.Time.TimeName]) |
|---|
| 3231 | set(handles.NomType,'String','*') |
|---|
| 3232 | set(handles.RootFile,'String',[get(handles.RootFile,'String') get(handles.FileIndex,'String')]) |
|---|
| 3233 | set(handles.i1,'String','1')% set counter to 1 (now the time index in the input matrix) |
|---|
| 3234 | MaxIndex_i=get(handles.MaxIndex_i,'String'); |
|---|
| 3235 | MaxIndex_i{1}=num2str(GetFieldData.Time.TimeDimension); |
|---|
| 3236 | set(handles.MaxIndex_i,'String',MaxIndex_i)%TODO: record time unit |
|---|
| 3237 | UvData=get(handles.uvmat,'UserData'); |
|---|
| 3238 | UvData.TimeUnit=GetFieldData.Time.TimeUnit; |
|---|
| 3239 | set(handles.uvmat,'UserData',UvData); |
|---|
| 3240 | set(handles.FileIndex,'String','') |
|---|
| 3241 | ParamIn.TimeVarName=GetFieldData.Time.TimeName; |
|---|
| 3242 | case 'matrix index' |
|---|
| 3243 | set(handles.TimeName,'String',['dim:' GetFieldData.Time.TimeName]); |
|---|
| 3244 | set(handles.NomType,'String','*') |
|---|
| 3245 | set(handles.RootFile,'String',[get(handles.RootFile,'String') get(handles.FileIndex,'String')]) |
|---|
| 3246 | set(handles.i1,'String','1')% set counter to 1 (now the time index in the input matrix) |
|---|
| 3247 | MaxIndex_i=get(handles.MaxIndex_i,'String'); |
|---|
| 3248 | MaxIndex_i{1}=num2str(GetFieldData.Time.TimeDimension); |
|---|
| 3249 | set(handles.MaxIndex_i,'String',MaxIndex_i)%TODO: record time unit |
|---|
| 3250 | UvData=get(handles.uvmat,'UserData'); |
|---|
| 3251 | UvData.TimeUnit=GetFieldData.Time.TimeUnit; |
|---|
| 3252 | set(handles.uvmat,'UserData',UvData); |
|---|
| 3253 | set(handles.FileIndex,'String','') |
|---|
| 3254 | ParamIn.TimeDimName=GetFieldData.Time.TimeName; |
|---|
| 3255 | end |
|---|
| 3256 | set(handles.Coord_x,'String',XName) |
|---|
| 3257 | % if ischar(YName) |
|---|
| 3258 | % YName={YName}; |
|---|
| 3259 | % end |
|---|
| 3260 | set(handles.Coord_y,'String',YName) |
|---|
| 3261 | set(handles.Coord_z,'String',ZName) |
|---|
| 3262 | set(handles.FieldName,'Value',1) |
|---|
| 3263 | set(handles.FieldName,'String',[FieldList; {'get_field...'}]); |
|---|
| 3264 | set(handles.ColorScalar,'Value',1) |
|---|
| 3265 | set(handles.ColorScalar,'String',VecColorList); |
|---|
| 3266 | UvData.FileType{1}='netcdf'; |
|---|
| 3267 | set(handles.uvmat,'UserData',UvData) |
|---|
| 3268 | REFRESH_Callback(hObject, eventdata, handles) |
|---|
| 3269 | end |
|---|
| 3270 | |
|---|
| 3271 | case 'image' |
|---|
| 3272 | %% look for image corresponding to civ data |
|---|
| 3273 | if isfield(UvData.Field,'Civ2_ImageA')%get the corresponding input image in the netcdf file |
|---|
| 3274 | imagename=UvData.Field.Civ2_ImageA; |
|---|
| 3275 | elseif isfield(UvData.Field,'Civ1_ImageA')% |
|---|
| 3276 | imagename=UvData.Field.Civ1_ImageA; |
|---|
| 3277 | else |
|---|
| 3278 | SubDirBase=regexprep(SubDir,'\..*','');%take the root part of SubDir, before the first dot '.' |
|---|
| 3279 | imagename=fullfile_uvmat(RootPath,SubDirBase,RootFile,'.png',NomType,i1,[],j1,[]); |
|---|
| 3280 | end |
|---|
| 3281 | if ~exist(imagename,'file') |
|---|
| 3282 | imagename=uigetfile_uvmat('Pick an image file',imagename,'image'); |
|---|
| 3283 | if isempty(imagename) |
|---|
| 3284 | return |
|---|
| 3285 | end |
|---|
| 3286 | end |
|---|
| 3287 | % display the selected field and related information |
|---|
| 3288 | display_file_name(handles,imagename)%display the image |
|---|
| 3289 | otherwise |
|---|
| 3290 | REFRESH_Callback(hObject, eventdata, handles) |
|---|
| 3291 | end |
|---|
| 3292 | |
|---|
| 3293 | %---------------------------------------------------------------- |
|---|
| 3294 | % --- Executes on menu selection FieldName |
|---|
| 3295 | function FieldName_1_Callback(hObject, eventdata, handles) |
|---|
| 3296 | %------------------------------------------------- |
|---|
| 3297 | |
|---|
| 3298 | %%%%%% TODO: modify like FieldName_Callback |
|---|
| 3299 | %% read input data |
|---|
| 3300 | check_new=~get(handles.SubField,'Value'); %check_new=1 if a second field was not previously entered |
|---|
| 3301 | UvData=get(handles.uvmat,'UserData'); |
|---|
| 3302 | if check_new && isfield(UvData,'XmlData') |
|---|
| 3303 | UvData.XmlData{2}=UvData.XmlData{1}; |
|---|
| 3304 | end |
|---|
| 3305 | if isfield(UvData,'Field_1') |
|---|
| 3306 | UvData=rmfield(UvData,'Field_1');% remove the stored second field (a new one needs to be read) |
|---|
| 3307 | end |
|---|
| 3308 | UvData.FileName_1='';% desactivate the use of a constant second file |
|---|
| 3309 | list_fields=get(handles.FieldName,'String');% list menu fields |
|---|
| 3310 | field= list_fields{get(handles.FieldName,'Value')}; % selected string |
|---|
| 3311 | list_fields=get(handles.FieldName_1,'String');% list menu fields |
|---|
| 3312 | field_1= list_fields{get(handles.FieldName_1,'Value')}; % selected string for the second field |
|---|
| 3313 | if isempty(field_1)%||(numel(UvData.FileType)>=2 && strcmp(UvData.FileType{2},'image')) |
|---|
| 3314 | set(handles.SubField,'Value',0) |
|---|
| 3315 | SubField_Callback(hObject, eventdata, handles) |
|---|
| 3316 | return |
|---|
| 3317 | else |
|---|
| 3318 | set(handles.SubField,'Value',1)%state that a second field is now entered |
|---|
| 3319 | end |
|---|
| 3320 | |
|---|
| 3321 | %% read the rootfile input display |
|---|
| 3322 | [RootPath_1,SubDir_1,RootFile_1,FileIndex_1,FileExt_1]=read_file_boxes_1(handles); |
|---|
| 3323 | FileName_1=[fullfile(RootPath_1,SubDir_1,RootFile_1) FileIndex_1 FileExt_1]; |
|---|
| 3324 | [tild,tild,tild,i1,i2,j1,j2]=fileparts_uvmat(get(handles.FileIndex,'String')); |
|---|
| 3325 | switch field_1 |
|---|
| 3326 | case 'get_field...' |
|---|
| 3327 | %% fill the axes and variables from selections in get_field |
|---|
| 3328 | ParamIn=[]; |
|---|
| 3329 | % in case of civ data, we use the civ choice as default input for the GUI get_field |
|---|
| 3330 | if strcmp(get(handles.VelType_1,'Visible'),'on') |
|---|
| 3331 | ParamIn.SwitchVarIndexTime='attribute'; |
|---|
| 3332 | ListVelType=get(handles.VelType_1,'String'); |
|---|
| 3333 | VelType=ListVelType{get(handles.VelType_1,'Value')}; |
|---|
| 3334 | switch VelType |
|---|
| 3335 | case 'civ1' |
|---|
| 3336 | ParamIn.TimeAttrName='Civ1_Time'; |
|---|
| 3337 | ParamIn.vector_x='Civ1_U'; |
|---|
| 3338 | ParamIn.vector_y='Civ1_V'; |
|---|
| 3339 | ParamIn.vec_color='Civ1_C'; |
|---|
| 3340 | case 'filter1' |
|---|
| 3341 | ParamIn.TimeAttrName='Civ1_Time'; |
|---|
| 3342 | ParamIn.vector_x='Civ1_U_smooth'; |
|---|
| 3343 | ParamIn.vector_y='Civ1_V_smooth'; |
|---|
| 3344 | case 'civ2' |
|---|
| 3345 | ParamIn.TimeAttrName='Civ2_Time'; |
|---|
| 3346 | ParamIn.vector_x='Civ2_U'; |
|---|
| 3347 | ParamIn.vector_y='Civ2_V'; |
|---|
| 3348 | case 'filter2' |
|---|
| 3349 | ParamIn.TimeAttrName='Civ2_Time'; |
|---|
| 3350 | ParamIn.vector_x='Civ2_U_smooth'; |
|---|
| 3351 | ParamIn.vector_y='Civ2_V_smooth'; |
|---|
| 3352 | ParamIn.vec_color='Civ2_C'; |
|---|
| 3353 | end |
|---|
| 3354 | end |
|---|
| 3355 | |
|---|
| 3356 | % VelType menu desactivated |
|---|
| 3357 | set(handles.FixVelType,'visible','off') |
|---|
| 3358 | set(handles.VelType,'Visible','off') |
|---|
| 3359 | |
|---|
| 3360 | %read selection from get_field |
|---|
| 3361 | [RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes_1(handles); |
|---|
| 3362 | FileName=[fullfile(RootPath,SubDir,RootFile) FileIndices FileExt]; |
|---|
| 3363 | GetFieldData=get_field(FileName,ParamIn);% inport field names from the GUI get_field |
|---|
| 3364 | FieldList={}; |
|---|
| 3365 | VecColorList={}; |
|---|
| 3366 | switch GetFieldData.FieldOption |
|---|
| 3367 | case 'vectors' |
|---|
| 3368 | UName=GetFieldData.PanelVectors.vector_x; |
|---|
| 3369 | VName=GetFieldData.PanelVectors.vector_y; |
|---|
| 3370 | YName=GetFieldData.Coordinates.Coord_y; |
|---|
| 3371 | CName=GetFieldData.PanelVectors.vec_color; |
|---|
| 3372 | FieldList={['vec(' UName ',' VName ')'];... |
|---|
| 3373 | ['norm(' UName ',' VName ')'];... |
|---|
| 3374 | UName;VName}; |
|---|
| 3375 | VecColorList={['norm(' UName ',' VName ')'];... |
|---|
| 3376 | UName;VName}; |
|---|
| 3377 | if ~isempty(CName) |
|---|
| 3378 | VecColorList=[{CName};VecColorList]; |
|---|
| 3379 | end |
|---|
| 3380 | case 'scalar' |
|---|
| 3381 | AName=GetFieldData.PanelScalar.scalar; |
|---|
| 3382 | YName=GetFieldData.Coordinates.Coord_y; |
|---|
| 3383 | FieldList={AName}; |
|---|
| 3384 | case '1D plot' |
|---|
| 3385 | YName=GetFieldData.PanelOrdinate.ordinate; |
|---|
| 3386 | case 'civdata...'%reinitiate input, return to automatic civ data reading |
|---|
| 3387 | display_file_name(handles,FileName,1) |
|---|
| 3388 | end |
|---|
| 3389 | if ~strcmp(GetFieldData.FieldOption,'civdata...') |
|---|
| 3390 | XName=GetFieldData.Coordinates.Coord_x; |
|---|
| 3391 | TimeNameStr=GetFieldData.Time.SwitchVarIndexTime; |
|---|
| 3392 | switch TimeNameStr |
|---|
| 3393 | case 'file index' |
|---|
| 3394 | set(handles.TimeName_1,'String',''); |
|---|
| 3395 | case 'attribute' |
|---|
| 3396 | set(handles.TimeName_1,'String',['att:' GetFieldData.Time.TimeName]); |
|---|
| 3397 | case 'variable' |
|---|
| 3398 | set(handles.TimeName_1,'String',['var:' GetFieldData.Time.TimeName]) |
|---|
| 3399 | set(handles.NomType_1,'String','*') |
|---|
| 3400 | set(handles.RootFile_1,'String',[get(handles.RootFile,'String') get(handles.FileIndex,'String')]) |
|---|
| 3401 | set(handles.FileIndex_1,'String','') |
|---|
| 3402 | ParamIn.TimeVarName=GetFieldData.Time.TimeName; |
|---|
| 3403 | case 'matrix_index' |
|---|
| 3404 | set(handles.TimeName_1,'String',['dim:' GetFieldData.Time.TimeName]); |
|---|
| 3405 | set(handles.NomType_1,'String','*') |
|---|
| 3406 | set(handles.RootFile_1,'String',[get(handles.RootFile,'String') get(handles.FileIndex,'String')]) |
|---|
| 3407 | set(handles.FileIndex_1,'String','') |
|---|
| 3408 | ParamIn.TimeDimName_1=GetFieldData.Time.TimeName; |
|---|
| 3409 | end |
|---|
| 3410 | set(handles.Coord_x,'String',XName) |
|---|
| 3411 | % if ischar(YName) |
|---|
| 3412 | % YName={YName}; |
|---|
| 3413 | % end |
|---|
| 3414 | set(handles.Coord_y,'String',YName) |
|---|
| 3415 | set(handles.FieldName_1,'Value',1) |
|---|
| 3416 | set(handles.FieldName_1,'String',[FieldList; {'get_field...'}]); |
|---|
| 3417 | set(handles.ColorScalar,'Value',1) |
|---|
| 3418 | set(handles.ColorScalar,'String',VecColorList); |
|---|
| 3419 | UvData.FileType{2}='netcdf'; |
|---|
| 3420 | set(handles.uvmat,'UserData',UvData) |
|---|
| 3421 | REFRESH_Callback(hObject, eventdata, handles) |
|---|
| 3422 | end |
|---|
| 3423 | |
|---|
| 3424 | % set_veltype_display(0) % no veltype display |
|---|
| 3425 | % hget_field=findobj(allchild(0),'name','get_field_1'); |
|---|
| 3426 | % if ~isempty(hget_field) |
|---|
| 3427 | % delete(hget_field) |
|---|
| 3428 | % end |
|---|
| 3429 | % hget_field=get_field(FileName_1); |
|---|
| 3430 | % set(hget_field,'name','get_field_1') |
|---|
| 3431 | % hhget_field=guidata(hget_field); |
|---|
| 3432 | % set(hhget_field.list_fig,'Value',1) |
|---|
| 3433 | % set(hhget_field.list_fig,'String',{'uvmat'}) |
|---|
| 3434 | % if check_new |
|---|
| 3435 | % UvData.FileType{2}=UvData.FileType{1}; |
|---|
| 3436 | % set(handles.FileIndex_1,'String',get(handles.FileIndex,'String')) |
|---|
| 3437 | % set(handles.uvmat,'UserData',UvData) |
|---|
| 3438 | % end |
|---|
| 3439 | case 'image' |
|---|
| 3440 | %% look for image corresponding to civ data |
|---|
| 3441 | imagename=''; |
|---|
| 3442 | if isfield(UvData.Field,'Civ2_ImageA')%get the corresponding input image in the netcdf file |
|---|
| 3443 | imagename=UvData.Field.Civ2_ImageA; |
|---|
| 3444 | elseif isfield(UvData.Field,'Civ1_ImageA')% |
|---|
| 3445 | imagename=UvData.Field.Civ1_ImageA; |
|---|
| 3446 | else |
|---|
| 3447 | SubDirBase=regexprep(SubDir,'\..*','');%take the root part of SubDir, before the first dot '.' |
|---|
| 3448 | imagename=fullfile_uvmat(RootPath,SubDirBase,RootFile,'.png',NomType,i1,[],j1,[]); |
|---|
| 3449 | end |
|---|
| 3450 | if ~exist(imagename,'file') |
|---|
| 3451 | imagename=uigetfile_uvmat('Pick an image file',imagename,'image'); |
|---|
| 3452 | |
|---|
| 3453 | end |
|---|
| 3454 | if isempty(imagename) |
|---|
| 3455 | set(handles.SubField,'Value',0) |
|---|
| 3456 | return |
|---|
| 3457 | else |
|---|
| 3458 | display_file_name(handles,imagename,2)%display the image as second field |
|---|
| 3459 | end |
|---|
| 3460 | otherwise |
|---|
| 3461 | check_refresh=1; |
|---|
| 3462 | if check_new% if a second field was not previously entered, we just read another field in the first input file |
|---|
| 3463 | set(handles.FileIndex_1,'String',get(handles.FileIndex,'String')) |
|---|
| 3464 | set(handles.FileExt_1,'String',get(handles.FileExt,'String')) |
|---|
| 3465 | |
|---|
| 3466 | UvData.FileType{2}=UvData.FileType{1}; |
|---|
| 3467 | UvData.XmlData{2}= UvData.XmlData{1}; |
|---|
| 3468 | transform=get(handles.TransformPath,'UserData'); |
|---|
| 3469 | if (~isa(transform,'function_handle')||nargin(transform)<3) |
|---|
| 3470 | set(handles.uvmat,'UserData',UvData) |
|---|
| 3471 | set(handles.TransformName,'value',2); % set transform fct to 'sub_field' if the current fct does not accept two input fields |
|---|
| 3472 | TransformName_Callback(hObject, eventdata, handles)% activate transform_fct_Callback and refresh current plot |
|---|
| 3473 | check_refresh=0; |
|---|
| 3474 | end |
|---|
| 3475 | end |
|---|
| 3476 | if ~isequal(field,'image') |
|---|
| 3477 | set(handles.TitleNpxy,'Visible','off')% visible npx,pxcm... buttons |
|---|
| 3478 | set(handles.num_Npx,'Visible','off') |
|---|
| 3479 | set(handles.num_Npy,'Visible','off') |
|---|
| 3480 | end |
|---|
| 3481 | set(handles.uvmat,'UserData',UvData) |
|---|
| 3482 | |
|---|
| 3483 | if check_refresh && ~(isfield(UvData,'NewSeries')&&isequal(UvData.NewSeries,1)) |
|---|
| 3484 | REFRESH_Callback(hObject, eventdata, handles) |
|---|
| 3485 | end |
|---|
| 3486 | end |
|---|
| 3487 | |
|---|
| 3488 | %------------------------------------------------------------------------ |
|---|
| 3489 | % --- set the visibility of relevant velocity type menus: |
|---|
| 3490 | function menu=set_veltype_display(Civ,FileType) |
|---|
| 3491 | %------------------------------------------------------------------------ |
|---|
| 3492 | if ~exist('FileType','var') |
|---|
| 3493 | FileType='civx'; |
|---|
| 3494 | end |
|---|
| 3495 | switch FileType |
|---|
| 3496 | case 'civx' |
|---|
| 3497 | menu={'civ1';'interp1';'filter1';'civ2';'interp2';'filter2'}; |
|---|
| 3498 | if isequal(Civ,0) |
|---|
| 3499 | imax=0; |
|---|
| 3500 | elseif isequal(Civ,1) || isequal(Civ,2) |
|---|
| 3501 | imax=1; |
|---|
| 3502 | elseif isequal(Civ,3) |
|---|
| 3503 | imax=3; |
|---|
| 3504 | elseif isequal(Civ,4) || isequal(Civ,5) |
|---|
| 3505 | imax=4; |
|---|
| 3506 | elseif isequal(Civ,6) %patch2 |
|---|
| 3507 | imax=6; |
|---|
| 3508 | end |
|---|
| 3509 | case 'civdata' |
|---|
| 3510 | menu={'civ1';'filter1';'civ2';'filter2'}; |
|---|
| 3511 | if isequal(Civ,0) |
|---|
| 3512 | imax=0; |
|---|
| 3513 | elseif isequal(Civ,1) || isequal(Civ,2) |
|---|
| 3514 | imax=1; |
|---|
| 3515 | elseif isequal(Civ,3) |
|---|
| 3516 | imax=2; |
|---|
| 3517 | elseif isequal(Civ,4) || isequal(Civ,5) |
|---|
| 3518 | imax=3; |
|---|
| 3519 | elseif isequal(Civ,6) %patch2 |
|---|
| 3520 | imax=4; |
|---|
| 3521 | end |
|---|
| 3522 | end |
|---|
| 3523 | menu=menu(1:imax); |
|---|
| 3524 | |
|---|
| 3525 | %------------------------------------------------------------------------ |
|---|
| 3526 | % --- Executes on button press in FixVelType. |
|---|
| 3527 | function FixVelType_Callback(hObject, eventdata, handles) |
|---|
| 3528 | %------------------------------------------------------------------------ |
|---|
| 3529 | % inputfilerefresh the current plot if the fixed veltype is unselected |
|---|
| 3530 | if ~get(handles.FixVelType,'Value') |
|---|
| 3531 | REFRESH_Callback(hObject, eventdata, handles) |
|---|
| 3532 | end |
|---|
| 3533 | |
|---|
| 3534 | %------------------------------------------------------------------------ |
|---|
| 3535 | % --- Executes on button press in VelType. |
|---|
| 3536 | function VelType_Callback(hObject, eventdata, handles) |
|---|
| 3537 | %------------------------------------------------------------------------ |
|---|
| 3538 | set(handles.FixVelType,'Value',1) |
|---|
| 3539 | REFRESH_Callback(hObject, eventdata, handles) |
|---|
| 3540 | |
|---|
| 3541 | %------------------------------------------------------------------------ |
|---|
| 3542 | % --- Executes on choice selection in VelType_1. |
|---|
| 3543 | function VelType_1_Callback(hObject, eventdata, handles) |
|---|
| 3544 | %------------------------------------------------------------------------ |
|---|
| 3545 | set(handles.FixVelType,'Value',1)% the velocity type is now imposed by the GUI (not automatic) |
|---|
| 3546 | UvData=get(handles.uvmat,'UserData'); |
|---|
| 3547 | set(handles.InputFileREFRESH,'BackgroundColor',[1 1 0])%paint REFRESH button in yellow to indicate its activation |
|---|
| 3548 | drawnow |
|---|
| 3549 | InputFile=read_GUI(handles.InputFile);% read the input file parameters |
|---|
| 3550 | [RootPath,SubDir,RootFile,FileIndex,FileExt]=read_file_boxes(handles); |
|---|
| 3551 | [RootPath_1,SubDir_1,RootFile_1,FileIndex_1,FileExt_1]=read_file_boxes_1(handles); |
|---|
| 3552 | FileName=[fullfile(RootPath,SubDir,RootFile) FileIndex FileExt];% name of the first input file |
|---|
| 3553 | |
|---|
| 3554 | check_refresh=0; |
|---|
| 3555 | if isempty(InputFile.VelType_1) |
|---|
| 3556 | FileName_1='';% we plot the first input field without the second field |
|---|
| 3557 | set(handles.SubField,'Value',0) |
|---|
| 3558 | SubField_Callback(hObject, eventdata, handles)% activate SubField_Callback and refresh current plot, removing the second field |
|---|
| 3559 | elseif get(handles.SubField,'Value')% if subfield is already 'on' |
|---|
| 3560 | FileName_1=[fullfile(RootPath_1,SubDir_1,RootFile_1) FileIndex_1 FileExt_1];% name of the second input file |
|---|
| 3561 | check_refresh=1;%will refresh the current plot |
|---|
| 3562 | else% we introduce the same file (with a different field) for the second series |
|---|
| 3563 | FileName_1=FileName;% we compare two fields in the same file |
|---|
| 3564 | UvData.FileType{2}=UvData.FileType{1}; |
|---|
| 3565 | UvData.XmlData{2}= UvData.XmlData{1}; |
|---|
| 3566 | set(handles.SubField,'Value',1) |
|---|
| 3567 | transform=get(handles.TransformPath,'UserData'); |
|---|
| 3568 | if (~isa(transform,'function_handle')||nargin(transform)<3) |
|---|
| 3569 | set(handles.uvmat,'UserData',UvData) |
|---|
| 3570 | set(handles.TransformName,'value',2); % set transform fct to 'sub_field' if the current fct does not accept two input fields |
|---|
| 3571 | TransformName_Callback(hObject, eventdata, handles)% activate transform_fct_Callback and refresh current plot |
|---|
| 3572 | else |
|---|
| 3573 | check_refresh=1; |
|---|
| 3574 | end |
|---|
| 3575 | end |
|---|
| 3576 | |
|---|
| 3577 | % inputfilerefresh the current plot if it has not been done previously |
|---|
| 3578 | if check_refresh |
|---|
| 3579 | UvData.FileName_1='';% desactivate the use of a constant second file |
|---|
| 3580 | set(handles.uvmat,'UserData',UvData) |
|---|
| 3581 | num_i1=stra2num(get(handles.i1,'String')); |
|---|
| 3582 | num_i2=stra2num(get(handles.i2,'String')); |
|---|
| 3583 | num_j1=stra2num(get(handles.j1,'String')); |
|---|
| 3584 | num_j2=stra2num(get(handles.j2,'String')); |
|---|
| 3585 | [tild,tild,tild,i1_1,i2_1,j1_1,j2_1]=fileparts_uvmat(['xx' FileIndex_1]); |
|---|
| 3586 | errormsg=refresh_field(handles,FileName,FileName_1,num_i1,num_i2,num_j1,num_j2,i1_1,i2_1,j1_1,j2_1); |
|---|
| 3587 | if ~isempty(errormsg) |
|---|
| 3588 | msgbox_uvmat('ERROR',errormsg); |
|---|
| 3589 | else |
|---|
| 3590 | % set(handles.i1,'BackgroundColor',[1 1 1]) |
|---|
| 3591 | % set(handles.i2,'BackgroundColor',[1 1 1]) |
|---|
| 3592 | % set(handles.j1,'BackgroundColor',[1 1 1]) |
|---|
| 3593 | % set(handles.j2,'BackgroundColor',[1 1 1]) |
|---|
| 3594 | % set(handles.FileIndex,'BackgroundColor',[1 1 1]) |
|---|
| 3595 | % set(handles.FileIndex_1,'BackgroundColor',[1 1 1]) |
|---|
| 3596 | end |
|---|
| 3597 | set(handles.InputFileREFRESH,'BackgroundColor',[1 0 0]) |
|---|
| 3598 | end |
|---|
| 3599 | |
|---|
| 3600 | |
|---|
| 3601 | %------------------------------------------------------------------------ |
|---|
| 3602 | % --- reset civ buttons |
|---|
| 3603 | function reset_vel_type(handles_civ0,handle1) |
|---|
| 3604 | %------------------------------------------------------------------------ |
|---|
| 3605 | for ibutton=1:length(handles_civ0) |
|---|
| 3606 | set(handles_civ0(ibutton),'BackgroundColor',[0.831 0.816 0.784]) |
|---|
| 3607 | set(handles_civ0(ibutton),'Value',0) |
|---|
| 3608 | end |
|---|
| 3609 | if exist('handle1','var')%handles of selected button |
|---|
| 3610 | set(handle1,'BackgroundColor',[1 1 0]) |
|---|
| 3611 | end |
|---|
| 3612 | |
|---|
| 3613 | %----------------------------------------------------------------------- |
|---|
| 3614 | % --- Executes on button press in MENUVOLUME. |
|---|
| 3615 | function VOLUME_Callback(hObject, eventdata, handles) |
|---|
| 3616 | %----------------------------------------------------------------------- |
|---|
| 3617 | %errordlg('command VOL not implemented yet') |
|---|
| 3618 | if ishandle(handles.UVMAT_title) |
|---|
| 3619 | delete(handles.UVMAT_title) |
|---|
| 3620 | end |
|---|
| 3621 | UvData=get(handles.uvmat,'UserData');%read UvData properties stored on the uvmat interface |
|---|
| 3622 | if isequal(get(handles.VOLUME,'Value'),1) |
|---|
| 3623 | set(handles.CheckZoom,'Value',0) |
|---|
| 3624 | % set(handles.CheckZoom,'BackgroundColor',[0.7 0.7 0.7]) |
|---|
| 3625 | set(handles.edit_vect,'Value',0) |
|---|
| 3626 | edit_vect_Callback(hObject, eventdata, handles) |
|---|
| 3627 | set(handles.CheckEditObject,'Value',0) |
|---|
| 3628 | % set(handles.CheckEditObject,'BackgroundColor',[0.7 0.7 0.7]) |
|---|
| 3629 | % set(handles.cal,'Value',0) |
|---|
| 3630 | % set(handles.cal,'BackgroundColor',[0 1 0]) |
|---|
| 3631 | set(handles.edit_vect,'Value',0) |
|---|
| 3632 | edit_vect_Callback(hObject, eventdata, handles) |
|---|
| 3633 | %initiate set_object GUI |
|---|
| 3634 | data.Name='VOLUME'; |
|---|
| 3635 | if isfield(UvData,'CoordType') |
|---|
| 3636 | data.CoordType=UvData.CoordType; |
|---|
| 3637 | end |
|---|
| 3638 | if isfield(UvData.Field,'CoordMesh')&~isempty(UvData.Field.CoordMesh) |
|---|
| 3639 | data.RangeX=[UvData.Field.XMin UvData.Field.XMax]; |
|---|
| 3640 | data.RangeY=[UvData.Field.YMin UvData.Field.YMax]; |
|---|
| 3641 | data.DX=UvData.Field.CoordMesh; |
|---|
| 3642 | data.DY=UvData.Field.CoordMesh; |
|---|
| 3643 | elseif isfield(UvData.Field,'Coord_x')&isfield(UvData.Field,'Coord_y')& isfield(UvData.Field,'A')%only image |
|---|
| 3644 | np=size(UvData.Field.A); |
|---|
| 3645 | meshx=(UvData.Field.Coord_x(end)-UvData.Field.Coord_x(1))/np(2); |
|---|
| 3646 | meshy=abs(UvData.Field.Coord_y(end)-UvData.Field.Coord_y(1))/np(1); |
|---|
| 3647 | data.RangeY=max(meshx,meshy); |
|---|
| 3648 | data.RangeX=max(meshx,meshy); |
|---|
| 3649 | data.DX=max(meshx,meshy); |
|---|
| 3650 | end |
|---|
| 3651 | data.ParentButton=handles.VOLUME; |
|---|
| 3652 | PlotHandles=get_plot_handles(handles);%get the handles of the interface elements setting the plotting parameters |
|---|
| 3653 | [hset_object,UvData.sethandles]=set_object(data,PlotHandles);% call the set_object interface with action on haxes, |
|---|
| 3654 | % associate the set_object interface handle to the plotting axes |
|---|
| 3655 | set(hset_object,'name','set_object') |
|---|
| 3656 | UvData.MouseAction='create_object'; |
|---|
| 3657 | else |
|---|
| 3658 | set(handles.VOLUME,'BackgroundColor',[0 1 0]) |
|---|
| 3659 | end |
|---|
| 3660 | set(handles.uvmat,'UserData',UvData) |
|---|
| 3661 | |
|---|
| 3662 | %------------------------------------------------------- |
|---|
| 3663 | function edit_vect_Callback(hObject, eventdata, handles) |
|---|
| 3664 | %------------------------------------------------------- |
|---|
| 3665 | % |
|---|
| 3666 | if isequal(get(handles.edit_vect,'Value'),1) |
|---|
| 3667 | VelTypeMenu=get(handles.VelType,'String'); |
|---|
| 3668 | VelType=VelTypeMenu{get(handles.VelType,'Value')}; |
|---|
| 3669 | if ~strcmp(VelType,'civ2') && ~strcmp(VelType,'civ1') |
|---|
| 3670 | msgbox_uvmat('ERROR','manual correction only possible for CIV1 or CIV2 velocity fields') |
|---|
| 3671 | end |
|---|
| 3672 | set(handles.record,'Visible','on') |
|---|
| 3673 | set(handles.edit_vect,'BackgroundColor',[1 1 0]) |
|---|
| 3674 | set(handles.CheckEditObject,'Value',0) |
|---|
| 3675 | set(handles.CheckZoom,'Value',0) |
|---|
| 3676 | set(gcf,'Pointer','arrow') |
|---|
| 3677 | else |
|---|
| 3678 | set(handles.record,'Visible','off') |
|---|
| 3679 | set(handles.edit_vect,'BackgroundColor',[0.7 0.7 0.7]) |
|---|
| 3680 | end |
|---|
| 3681 | |
|---|
| 3682 | %---------------------------------------------- |
|---|
| 3683 | function save_mask_Callback(hObject, eventdata, handles) |
|---|
| 3684 | %----------------------------------------------------------------------- |
|---|
| 3685 | UvData=get(handles.uvmat,'UserData'); |
|---|
| 3686 | |
|---|
| 3687 | flag=1; |
|---|
| 3688 | npx=size(UvData.Field.A,2); |
|---|
| 3689 | npy=size(UvData.Field.A,1); |
|---|
| 3690 | xi=0.5:npx-0.5; |
|---|
| 3691 | yi=0.5:npy-0.5; |
|---|
| 3692 | [Xi,Yi]=meshgrid(xi,yi); |
|---|
| 3693 | if isfield(UvData,'ProjObject') |
|---|
| 3694 | for iobj=1:length(UvData.ProjObject) |
|---|
| 3695 | ObjectData=UvData.ProjObject{iobj}; |
|---|
| 3696 | if isfield(ObjectData,'ProjMode') &&(isequal(ObjectData.ProjMode,'mask_inside')||isequal(ObjectData.ProjMode,'mask_outside')); |
|---|
| 3697 | flagobj=1; |
|---|
| 3698 | testphys=0; %coordinates in pixels by default |
|---|
| 3699 | if isfield(ObjectData,'CoordType') && isequal(ObjectData.CoordType,'phys') |
|---|
| 3700 | if isfield(UvData,'XmlData')&& isfield(UvData.XmlData{1},'GeometryCalib') |
|---|
| 3701 | Calib=UvData.XmlData{1}.GeometryCalib; |
|---|
| 3702 | testphys=1; |
|---|
| 3703 | end |
|---|
| 3704 | end |
|---|
| 3705 | if isfield(ObjectData,'Coord')& isfield(ObjectData,'Style') |
|---|
| 3706 | if isequal(ObjectData.Type,'polygon') |
|---|
| 3707 | X=ObjectData.Coord(:,1); |
|---|
| 3708 | Y=ObjectData.Coord(:,2); |
|---|
| 3709 | if testphys |
|---|
| 3710 | [X,Y]=px_XYZ(Calib,X,Y,0);% to generalise with 3D cases |
|---|
| 3711 | end |
|---|
| 3712 | flagobj=~inpolygon(Xi,Yi,X',Y');%=0 inside the polygon, 1 outside |
|---|
| 3713 | elseif isequal(ObjectData.Type,'ellipse') |
|---|
| 3714 | if testphys |
|---|
| 3715 | %[X,Y]=px_XYZ(Calib,X,Y,0);% TODO:create a polygon boundary and transform to phys |
|---|
| 3716 | end |
|---|
| 3717 | RangeX=max(ObjectData.RangeX); |
|---|
| 3718 | RangeY=max(ObjectData.RangeY); |
|---|
| 3719 | X2Max=RangeX*RangeX; |
|---|
| 3720 | Y2Max=RangeY*RangeY; |
|---|
| 3721 | distX=(Xi-ObjectData.Coord(1,1)); |
|---|
| 3722 | distY=(Yi-ObjectData.Coord(1,2)); |
|---|
| 3723 | flagobj=(distX.*distX/X2Max+distY.*distY/Y2Max)>1; |
|---|
| 3724 | elseif isequal(ObjectData.Type,'rectangle') |
|---|
| 3725 | if testphys |
|---|
| 3726 | %[X,Y]=px_XYZ(Calib,X,Y,0);% TODO:create a polygon boundary and transform to phys |
|---|
| 3727 | end |
|---|
| 3728 | distX=abs(Xi-ObjectData.Coord(1,1)); |
|---|
| 3729 | distY=abs(Yi-ObjectData.Coord(1,2)); |
|---|
| 3730 | flagobj=distX>max(ObjectData.RangeX) | distY>max(ObjectData.RangeY); |
|---|
| 3731 | end |
|---|
| 3732 | if isequal(ObjectData.ProjMode,'mask_outside') |
|---|
| 3733 | flagobj=~flagobj; |
|---|
| 3734 | end |
|---|
| 3735 | flag=flag & flagobj; |
|---|
| 3736 | end |
|---|
| 3737 | end |
|---|
| 3738 | end |
|---|
| 3739 | end |
|---|
| 3740 | % flag=~flag; |
|---|
| 3741 | %mask name |
|---|
| 3742 | RootPath=get(handles.RootPath,'String'); |
|---|
| 3743 | RootFile=get(handles.RootFile,'String'); |
|---|
| 3744 | RootFile=regexprep(RootFile,'\<[\\/]|[\\/]\>','');%suppress possible / or \ separator at the beginning or the end of the string |
|---|
| 3745 | filebase=fullfile(RootPath,RootFile); |
|---|
| 3746 | list=get(handles.masklevel,'String'); |
|---|
| 3747 | masknumber=num2str(length(list)); |
|---|
| 3748 | maskindex=get(handles.masklevel,'Value'); |
|---|
| 3749 | mask_name=fullfile_uvmat(RootPath,SubDir,[RootFile '_' masknumber 'mask'],'.png','_1',maskindex); |
|---|
| 3750 | %mask_name=name_generator([filebase '_' masknumber 'mask'],maskindex,1,'.png','_i'); |
|---|
| 3751 | imflag=uint8(255*(0.392+0.608*flag));% =100 for flag=0 (vectors not computed when 20<imflag<200) |
|---|
| 3752 | imflag=flipdim(imflag,1); |
|---|
| 3753 | % imflag=uint8(255*flag);% =0 for flag=0 (vectors=0 when 20<imflag<200) |
|---|
| 3754 | msgbox_uvmat('CONFIRMATION',[mask_name ' saved']) |
|---|
| 3755 | imwrite(imflag,mask_name,'BitDepth',8); |
|---|
| 3756 | |
|---|
| 3757 | %display the mask |
|---|
| 3758 | figure; |
|---|
| 3759 | vec=linspace(0,1,256);%define a linear greyscale colormap |
|---|
| 3760 | map=[vec' vec' vec']; |
|---|
| 3761 | colormap(map) |
|---|
| 3762 | |
|---|
| 3763 | image(imflag); |
|---|
| 3764 | |
|---|
| 3765 | %------------------------------------------------------------------------ |
|---|
| 3766 | %------------------------------------------------------------------------ |
|---|
| 3767 | % - FUNCTIONS FOR SETTING PLOTTING PARAMETERS |
|---|
| 3768 | |
|---|
| 3769 | %------------------------------------------------------------------------ |
|---|
| 3770 | %------------------------------------------------------------------------ |
|---|
| 3771 | % --- Executes on selection change in TransformName. |
|---|
| 3772 | |
|---|
| 3773 | function TransformName_Callback(hObject, eventdata, handles) |
|---|
| 3774 | %------------------------------------------------------------------------ |
|---|
| 3775 | set(handles.TransformName,'backgroundColor',[1 1 0])% indicate activation of the menu |
|---|
| 3776 | drawnow |
|---|
| 3777 | UvData=get(handles.uvmat,'UserData'); |
|---|
| 3778 | menu=get(handles.TransformName,'String');%refresh |
|---|
| 3779 | ichoice=get(handles.TransformName,'Value');%item number in the menu |
|---|
| 3780 | transform_name=menu{ichoice};% choice of the transform fct |
|---|
| 3781 | list_path=get(handles.TransformName,'UserData'); |
|---|
| 3782 | |
|---|
| 3783 | %% handles visibility of the path to the transform function |
|---|
| 3784 | if isempty(transform_name) |
|---|
| 3785 | set(handles.TransformPath,'Visible','off') |
|---|
| 3786 | else |
|---|
| 3787 | set(handles.TransformPath,'Visible','on') |
|---|
| 3788 | end |
|---|
| 3789 | |
|---|
| 3790 | %% add a new item to the menu if the option 'more...' has been selected |
|---|
| 3791 | prev_path=fullfile(get(handles.TransformPath,'String')); |
|---|
| 3792 | if ~exist(prev_path,'dir') |
|---|
| 3793 | prev_path=fullfile(fileparts(which('uvmat')),'transform_field'); |
|---|
| 3794 | end |
|---|
| 3795 | if strcmp(transform_name,'more...'); |
|---|
| 3796 | transform_fct_chosen=uigetfile_uvmat('Pick the transform function',prev_path,'.m'); |
|---|
| 3797 | if ~isempty(transform_fct_chosen) |
|---|
| 3798 | [PathName,transform_name]=fileparts(transform_fct_chosen); |
|---|
| 3799 | ichoice=find(strcmp(transform_name,menu),1);%look for the selected fct in the existing menu |
|---|
| 3800 | if isempty(ichoice)% if the item is not found, add it to the menu (before 'more...' and select it) |
|---|
| 3801 | menu=[menu(1:end-1);{transform_name};{'more...'}]; |
|---|
| 3802 | ichoice=numel(menu)-1; |
|---|
| 3803 | end |
|---|
| 3804 | list_path{ichoice}=PathName;%update the list fo fct paths |
|---|
| 3805 | set(handles.TransformName,'String',menu) |
|---|
| 3806 | set(handles.TransformName,'Value',ichoice) |
|---|
| 3807 | |
|---|
| 3808 | % save the new menu in the personal file 'uvmat_perso.mat' |
|---|
| 3809 | dir_perso=prefdir;%personal Matalb directory |
|---|
| 3810 | profil_perso=fullfile(dir_perso,'uvmat_perso.mat'); |
|---|
| 3811 | if exist(profil_perso,'file') |
|---|
| 3812 | nb_builtin=UvData.OpenParam.NbBuiltin;% number of 'builtin' (basic) transform fcts in uvmat |
|---|
| 3813 | if nb_builtin<numel(list_path) |
|---|
| 3814 | for ilist=nb_builtin+1:numel(list_path) |
|---|
| 3815 | transform_fct{ilist-nb_builtin}=[fullfile(list_path{ilist},menu{ilist}) '.m']; |
|---|
| 3816 | end |
|---|
| 3817 | save (profil_perso,'transform_fct','-append'); %store the root name for future opening of uvmat |
|---|
| 3818 | end |
|---|
| 3819 | end |
|---|
| 3820 | end |
|---|
| 3821 | end |
|---|
| 3822 | |
|---|
| 3823 | %% create the function handle of the selected fct |
|---|
| 3824 | if isempty(list_path{ichoice})% case of no selected fct |
|---|
| 3825 | transform_handle=[]; |
|---|
| 3826 | else |
|---|
| 3827 | if ~exist(list_path{ichoice},'dir') |
|---|
| 3828 | msgbox_uvmat('ERROR','invalid fct path: select the transform fct again with the option more...') |
|---|
| 3829 | return |
|---|
| 3830 | end |
|---|
| 3831 | current_dir=pwd;%current working dir |
|---|
| 3832 | cd(list_path{ichoice}) |
|---|
| 3833 | transform_handle=str2func(transform_name); |
|---|
| 3834 | cd(current_dir) |
|---|
| 3835 | end |
|---|
| 3836 | set(handles.TransformPath,'String',list_path{ichoice}) |
|---|
| 3837 | set(handles.TransformPath,'UserData',transform_handle) |
|---|
| 3838 | set(handles.TransformName,'UserData',list_path) |
|---|
| 3839 | |
|---|
| 3840 | %% update the ToolTip string of the menu TransformName with the first line of the selected fct file |
|---|
| 3841 | if isempty(list_path{ichoice})% case of no selected fct |
|---|
| 3842 | set(handles.TransformName,'ToolTipString','transform_fct:choose a transform function') |
|---|
| 3843 | else |
|---|
| 3844 | try |
|---|
| 3845 | [fid,errormsg] =fopen([fullfile(list_path{ichoice},transform_name) '.m']); |
|---|
| 3846 | InputText=textscan(fid,'%s',1,'delimiter','\n'); |
|---|
| 3847 | fclose(fid); |
|---|
| 3848 | set(handles.TransformName,'ToolTipString',['transform_fct: ' InputText{1}{1}])% put the first line of the selected function as tooltip help |
|---|
| 3849 | end |
|---|
| 3850 | end |
|---|
| 3851 | |
|---|
| 3852 | %% adapt the GUI to the input/output conditions of the selected transform fct |
|---|
| 3853 | CoordUnit=''; |
|---|
| 3854 | CoordUnitPrev=''; |
|---|
| 3855 | if isfield(UvData,'Field')&&isfield(UvData.Field,'CoordUnit') |
|---|
| 3856 | CoordUnitPrev=UvData.Field.CoordUnit; |
|---|
| 3857 | end |
|---|
| 3858 | if ~isempty(list_path{ichoice}) |
|---|
| 3859 | if nargin(transform_handle)>1 %&& isfield(UvData,'XmlData')&&~isempty(UvData.XmlData) |
|---|
| 3860 | XmlData=[]; |
|---|
| 3861 | if isfield(UvData,'XmlData')&&~isempty(UvData.XmlData) |
|---|
| 3862 | XmlData=UvData.XmlData{1}; |
|---|
| 3863 | end |
|---|
| 3864 | UvData.Field.Action.RUN=0;% indicate that the transform fct is called only to get input param |
|---|
| 3865 | DataOut=feval(transform_handle,UvData.Field,XmlData);% execute the transform fct to get the required conditions |
|---|
| 3866 | if isfield(DataOut,'CoordUnit')% set the requested coord unit (info used to possibly delete the current projection objects) |
|---|
| 3867 | CoordUnit=DataOut.CoordUnit; |
|---|
| 3868 | end |
|---|
| 3869 | if isfield(DataOut,'InputFieldType')% to be used to impose a type of input file (eg. for image transform) |
|---|
| 3870 | UvData.InputFieldType=DataOut.InputFieldType; |
|---|
| 3871 | end |
|---|
| 3872 | if isfield(DataOut,'TransformInput')% used to add transform parameters at selection of the transform fct |
|---|
| 3873 | UvData.XmlData{1}.TransformInput=DataOut.TransformInput; |
|---|
| 3874 | end |
|---|
| 3875 | end |
|---|
| 3876 | end |
|---|
| 3877 | |
|---|
| 3878 | %% delete drawn objects if the output CooordUnit is different from the previous one |
|---|
| 3879 | if ~strcmp(CoordUnit,CoordUnitPrev) |
|---|
| 3880 | set(handles.CheckFixLimits,'Value',0) |
|---|
| 3881 | hother=findobj('Tag','proj_object');%find all the proj objects |
|---|
| 3882 | for iobj=1:length(hother) |
|---|
| 3883 | delete_object(hother(iobj)) |
|---|
| 3884 | end |
|---|
| 3885 | hother=findobj('Tag','DeformPoint');%find all the proj objects |
|---|
| 3886 | for iobj=1:length(hother) |
|---|
| 3887 | delete_object(hother(iobj)) |
|---|
| 3888 | end |
|---|
| 3889 | hh=findobj('Tag','calib_points'); |
|---|
| 3890 | if ~isempty(hh) |
|---|
| 3891 | delete(hh) |
|---|
| 3892 | end |
|---|
| 3893 | hhh=findobj('Tag','calib_marker'); |
|---|
| 3894 | if ~isempty(hhh) |
|---|
| 3895 | delete(hhh) |
|---|
| 3896 | end |
|---|
| 3897 | set(handles.ListObject,'Value',1) |
|---|
| 3898 | set(handles.ListObject,'String',{''}) |
|---|
| 3899 | set(handles.ListObject_1,'Value',1) |
|---|
| 3900 | set(handles.ListObject_1,'String',{''}) |
|---|
| 3901 | set(handles.CheckViewObject,'value',0) |
|---|
| 3902 | CheckViewObject_Callback(hObject, eventdata, handles) |
|---|
| 3903 | set(handles.CheckViewField,'value',0) |
|---|
| 3904 | CheckViewField_Callback(hObject, eventdata, handles) |
|---|
| 3905 | set(handles.CheckEditObject,'Value',0) |
|---|
| 3906 | CheckEditObject_Callback(hObject, eventdata, handles) |
|---|
| 3907 | UvData.ProjObject={[]}; |
|---|
| 3908 | end |
|---|
| 3909 | set(handles.uvmat,'UserData',UvData) |
|---|
| 3910 | set(handles.TransformName,'backgroundColor',[1 1 1])% indicate desactivation of the menu |
|---|
| 3911 | drawnow |
|---|
| 3912 | |
|---|
| 3913 | %% inputfilerefresh the current plot |
|---|
| 3914 | if isempty(list_path{ichoice}) || nargin(transform_handle)<3 |
|---|
| 3915 | set(handles.SubField,'Value',0) |
|---|
| 3916 | SubField_Callback(hObject, eventdata, handles) |
|---|
| 3917 | else |
|---|
| 3918 | REFRESH_Callback(hObject, eventdata, handles) |
|---|
| 3919 | end |
|---|
| 3920 | |
|---|
| 3921 | %------------------------------------------------ |
|---|
| 3922 | %CALLBACKS FOR PLOTTING PARAMETERS |
|---|
| 3923 | %------------------------------------------------- |
|---|
| 3924 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 3925 | % Plot axes |
|---|
| 3926 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 3927 | %------------------------------------------------------------------------ |
|---|
| 3928 | function num_MinX_Callback(hObject, eventdata, handles) |
|---|
| 3929 | %------------------------------------------------------------------------ |
|---|
| 3930 | set(handles.CheckFixLimits,'Value',1) %suppress auto mode |
|---|
| 3931 | % set(handles.CheckFixLimits,'BackgroundColor',[1 1 0]) |
|---|
| 3932 | update_plot(handles); |
|---|
| 3933 | |
|---|
| 3934 | %------------------------------------------------------------------------ |
|---|
| 3935 | function num_MaxX_Callback(hObject, eventdata, handles) |
|---|
| 3936 | %------------------------------------------------------------------------ |
|---|
| 3937 | set(handles.CheckFixLimits,'Value',1) %suppress auto mode |
|---|
| 3938 | % set(handles.CheckFixLimits,'BackgroundColor',[1 1 0]) |
|---|
| 3939 | update_plot(handles); |
|---|
| 3940 | |
|---|
| 3941 | %------------------------------------------------------------------------ |
|---|
| 3942 | function num_MinY_Callback(hObject, eventdata, handles) |
|---|
| 3943 | %------------------------------------------ |
|---|
| 3944 | set(handles.CheckFixLimits,'Value',1) %suppress auto mode |
|---|
| 3945 | % set(handles.CheckFixLimits,'BackgroundColor',[1 1 0]) |
|---|
| 3946 | update_plot(handles); |
|---|
| 3947 | |
|---|
| 3948 | %------------------------------------------------------------------------ |
|---|
| 3949 | function num_MaxY_Callback(hObject, eventdata, handles) |
|---|
| 3950 | %------------------------------------------------------------------------ |
|---|
| 3951 | set(handles.CheckFixLimits,'Value',1) %suppress auto mode |
|---|
| 3952 | % set(handles.CheckFixLimits,'BackgroundColor',[1 1 0]) |
|---|
| 3953 | update_plot(handles); |
|---|
| 3954 | |
|---|
| 3955 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 3956 | % Scalar or image representation |
|---|
| 3957 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 3958 | %------------------------------------------------------------------------ |
|---|
| 3959 | function num_MinA_Callback(hObject, eventdata, handles) |
|---|
| 3960 | %------------------------------------------ |
|---|
| 3961 | set(handles.CheckFixScalar,'Value',1) %suppress auto mode |
|---|
| 3962 | % set(handles.CheckFixScalar,'BackgroundColor',[1 1 0]) |
|---|
| 3963 | MinA=str2double(get(handles.num_MinA,'String')); |
|---|
| 3964 | MaxA=str2double(get(handles.num_MaxA,'String')); |
|---|
| 3965 | if MinA>MaxA% switch minA and maxA in case of error |
|---|
| 3966 | MinA_old=MinA; |
|---|
| 3967 | MinA=MaxA; |
|---|
| 3968 | MaxA=MinA_old; |
|---|
| 3969 | set(handles.num_MinA,'String',num2str(MinA,5)); |
|---|
| 3970 | set(handles.num_MaxA,'String',num2str(MaxA,5)); |
|---|
| 3971 | end |
|---|
| 3972 | update_plot(handles); |
|---|
| 3973 | |
|---|
| 3974 | %------------------------------------------------------------------------ |
|---|
| 3975 | function num_MaxA_Callback(hObject, eventdata, handles) |
|---|
| 3976 | %------------------------------------------------------------------------ |
|---|
| 3977 | set(handles.CheckFixScalar,'Value',1) %suppress auto mode |
|---|
| 3978 | % set(handles.CheckFixScalar,'BackgroundColor',[1 1 0]) |
|---|
| 3979 | MinA=str2double(get(handles.num_MinA,'String')); |
|---|
| 3980 | MaxA=str2double(get(handles.num_MaxA,'String')); |
|---|
| 3981 | if MinA>MaxA% switch minA and maxA in case of error |
|---|
| 3982 | MinA_old=MinA; |
|---|
| 3983 | MinA=MaxA; |
|---|
| 3984 | MaxA=MinA_old; |
|---|
| 3985 | set(handles.num_MinA,'String',num2str(MinA,5)); |
|---|
| 3986 | set(handles.num_MaxA,'String',num2str(MaxA,5)); |
|---|
| 3987 | end |
|---|
| 3988 | update_plot(handles); |
|---|
| 3989 | |
|---|
| 3990 | %------------------------------------------------------------------------ |
|---|
| 3991 | function CheckFixScalar_Callback(hObject, eventdata, handles) |
|---|
| 3992 | %------------------------------------------------------------------------ |
|---|
| 3993 | test=get(handles.CheckFixScalar,'Value'); |
|---|
| 3994 | if test |
|---|
| 3995 | % set(handles.CheckFixScalar,'BackgroundColor',[1 1 0]) |
|---|
| 3996 | else |
|---|
| 3997 | % set(handles.CheckFixScalar,'BackgroundColor',[0.7 0.7 0.7]) |
|---|
| 3998 | update_plot(handles); |
|---|
| 3999 | end |
|---|
| 4000 | |
|---|
| 4001 | %------------------------------------------------------------------- |
|---|
| 4002 | function CheckBW_Callback(hObject, eventdata, handles) |
|---|
| 4003 | %------------------------------------------------------------------- |
|---|
| 4004 | update_plot(handles); |
|---|
| 4005 | |
|---|
| 4006 | %------------------------------------------------------------------- |
|---|
| 4007 | function num_Opacity_Callback(hObject, eventdata, handles) |
|---|
| 4008 | update_plot(handles); |
|---|
| 4009 | %------------------------------------------------------------------- |
|---|
| 4010 | |
|---|
| 4011 | %------------------------------------------------------------------- |
|---|
| 4012 | function ListContour_Callback(hObject, eventdata, handles) |
|---|
| 4013 | %------------------------------------------------------------------- |
|---|
| 4014 | val=get(handles.ListContour,'Value'); |
|---|
| 4015 | if val==2% option 'contours' |
|---|
| 4016 | set(handles.interval_txt,'Visible','on') |
|---|
| 4017 | set(handles.num_IncrA,'Visible','on') |
|---|
| 4018 | set(handles.num_IncrA,'String','')% refresh contour interval |
|---|
| 4019 | % set(handles.opacity_txt,'Visible','off') |
|---|
| 4020 | % set(handles.num_Opacity,'Visible','off') |
|---|
| 4021 | else % option 'image' |
|---|
| 4022 | set(handles.interval_txt,'Visible','off') |
|---|
| 4023 | set(handles.num_IncrA,'Visible','off') |
|---|
| 4024 | % set(handles.opacity_txt,'Visible','on') |
|---|
| 4025 | % set(handles.num_Opacity,'Visible','on') |
|---|
| 4026 | end |
|---|
| 4027 | update_plot(handles); |
|---|
| 4028 | |
|---|
| 4029 | %------------------------------------------------------------------- |
|---|
| 4030 | function num_IncrA_Callback(hObject, eventdata, handles) |
|---|
| 4031 | %------------------------------------------------------------------- |
|---|
| 4032 | update_plot(handles); |
|---|
| 4033 | |
|---|
| 4034 | |
|---|
| 4035 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 4036 | % Vector representation |
|---|
| 4037 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 4038 | %------------------------------------------------------------------- |
|---|
| 4039 | function CheckHideWarning_Callback(hObject, eventdata, handles) |
|---|
| 4040 | %------------------------------------------------------------------- |
|---|
| 4041 | update_plot(handles); |
|---|
| 4042 | |
|---|
| 4043 | %------------------------------------------------------------------- |
|---|
| 4044 | function CheckHideFalse_Callback(hObject, eventdata, handles) |
|---|
| 4045 | %------------------------------------------------------------------- |
|---|
| 4046 | update_plot(handles); |
|---|
| 4047 | |
|---|
| 4048 | %------------------------------------------------------------------- |
|---|
| 4049 | function num_VecScale_Callback(hObject, eventdata, handles) |
|---|
| 4050 | %------------------------------------------------------------------- |
|---|
| 4051 | set(handles.CheckFixVectors,'Value',1); |
|---|
| 4052 | %set(handles.CheckFixVectors,'BackgroundColor',[1 1 0]) |
|---|
| 4053 | update_plot(handles); |
|---|
| 4054 | |
|---|
| 4055 | %------------------------------------------------------------------- |
|---|
| 4056 | function CheckFixVectors_Callback(hObject, eventdata, handles) |
|---|
| 4057 | %------------------------------------------------------------------- |
|---|
| 4058 | if ~get(handles.CheckFixVectors,'Value') |
|---|
| 4059 | update_plot(handles); |
|---|
| 4060 | end |
|---|
| 4061 | |
|---|
| 4062 | %------------------------------------------------------------------------ |
|---|
| 4063 | % --- Executes on selection change in CheckDecimate4 (nb_vec/4). |
|---|
| 4064 | %------------------------------------------------------------------------ |
|---|
| 4065 | function CheckDecimate4_Callback(hObject, eventdata, handles) |
|---|
| 4066 | |
|---|
| 4067 | if isequal(get(handles.CheckDecimate4,'Value'),1) |
|---|
| 4068 | set(handles.CheckDecimate16,'Value',0) |
|---|
| 4069 | end |
|---|
| 4070 | update_plot(handles); |
|---|
| 4071 | |
|---|
| 4072 | %------------------------------------------------------------------------ |
|---|
| 4073 | % --- Executes on selection change in CheckDecimate16 (nb_vec/16). |
|---|
| 4074 | %------------------------------------------------------------------------ |
|---|
| 4075 | function CheckDecimate16_Callback(hObject, eventdata, handles) |
|---|
| 4076 | |
|---|
| 4077 | if isequal(get(handles.CheckDecimate16,'Value'),1) |
|---|
| 4078 | set(handles.CheckDecimate4,'Value',0) |
|---|
| 4079 | end |
|---|
| 4080 | update_plot(handles); |
|---|
| 4081 | |
|---|
| 4082 | %------------------------------------------------------------------------ |
|---|
| 4083 | % --- Executes on selection change in ColorCode menu |
|---|
| 4084 | function ColorCode_Callback(hObject, eventdata, handles) |
|---|
| 4085 | %------------------------------------------------------------------------ |
|---|
| 4086 | % edit the choice for color code |
|---|
| 4087 | update_color_code_boxes(handles); |
|---|
| 4088 | update_plot(handles); |
|---|
| 4089 | |
|---|
| 4090 | %------------------------------------------------------------------------ |
|---|
| 4091 | function update_color_code_boxes(handles) |
|---|
| 4092 | %------------------------------------------------------------------------ |
|---|
| 4093 | list_code=get(handles.ColorCode,'String');% list menu fields |
|---|
| 4094 | colcode= list_code{get(handles.ColorCode,'Value')}; % selected field |
|---|
| 4095 | enable_slider='off';%default |
|---|
| 4096 | enable_bounds='off';%default |
|---|
| 4097 | enable_scalar='off';%default |
|---|
| 4098 | switch colcode |
|---|
| 4099 | case {'rgb','bgr'} |
|---|
| 4100 | enable_slider='on'; |
|---|
| 4101 | enable_bounds='on'; |
|---|
| 4102 | enable_scalar='on'; |
|---|
| 4103 | case '64 colors' |
|---|
| 4104 | enable_bounds='on'; |
|---|
| 4105 | enable_scalar='on'; |
|---|
| 4106 | end |
|---|
| 4107 | set(handles.Slider1,'Visible',enable_slider) |
|---|
| 4108 | set(handles.Slider2,'Visible', enable_slider) |
|---|
| 4109 | set(handles.num_ColCode1,'Visible',enable_slider) |
|---|
| 4110 | set(handles.num_ColCode2,'Visible',enable_slider) |
|---|
| 4111 | set(handles.TitleColCode1,'Visible',enable_slider) |
|---|
| 4112 | set(handles.TitleColCode2,'Visible',enable_slider) |
|---|
| 4113 | set(handles.CheckFixVecColor,'Visible',enable_bounds) |
|---|
| 4114 | set(handles.num_MinVec,'Visible',enable_bounds) |
|---|
| 4115 | set(handles.num_MaxVec,'Visible',enable_bounds) |
|---|
| 4116 | set(handles.ColorScalar,'Visible',enable_scalar) |
|---|
| 4117 | set_vec_col_bar(handles) |
|---|
| 4118 | |
|---|
| 4119 | %------------------------------------------------------------------ |
|---|
| 4120 | % --- Executes on selection change in ColorScalar: choice of the color code. |
|---|
| 4121 | function ColorScalar_Callback(hObject, eventdata, handles) |
|---|
| 4122 | %------------------------------------------------------------------ |
|---|
| 4123 | % edit the choice for color code |
|---|
| 4124 | list_scalar=get(handles.ColorScalar,'String');% list menu fields |
|---|
| 4125 | col_scalar= list_scalar{get(handles.ColorScalar,'Value')}; % selected field |
|---|
| 4126 | if isequal(col_scalar,'ima_cor') |
|---|
| 4127 | set(handles.CheckFixVecColor,'Value',1)%fixed scale by default |
|---|
| 4128 | ColorCode='rgb'; |
|---|
| 4129 | set(handles.num_MinVec,'String','0') |
|---|
| 4130 | set(handles.num_MaxVec,'String','1') |
|---|
| 4131 | set(handles.num_ColCode1,'String','0.333') |
|---|
| 4132 | set(handles.num_ColCode2,'String','0.666') |
|---|
| 4133 | else |
|---|
| 4134 | set(handles.CheckFixVecColor,'Value',0)%auto scale between min,max by default |
|---|
| 4135 | ColorCode='64 colors'; |
|---|
| 4136 | end |
|---|
| 4137 | ColorCodeList=get(handles.ColorCode,'String'); |
|---|
| 4138 | ichoice=find(strcmp(ColorCode,ColorCodeList),1); |
|---|
| 4139 | set(handles.ColorCode,'Value',ichoice)% set color code in the menu |
|---|
| 4140 | |
|---|
| 4141 | update_color_code_boxes(handles); |
|---|
| 4142 | %replot the current graph |
|---|
| 4143 | REFRESH_Callback(hObject, eventdata, handles) |
|---|
| 4144 | |
|---|
| 4145 | %---------------------------------------------------------------- |
|---|
| 4146 | % -- Executes on slider movement to set the color code |
|---|
| 4147 | % |
|---|
| 4148 | function Slider1_Callback(hObject, eventdata, handles) |
|---|
| 4149 | %------------------------------------------------------------------ |
|---|
| 4150 | slider1=get(handles.Slider1,'Value'); |
|---|
| 4151 | min_val=str2num(get(handles.num_MinVec,'String')); |
|---|
| 4152 | max_val=str2num(get(handles.num_MaxVec,'String')); |
|---|
| 4153 | col=min_val+(max_val-min_val)*slider1; |
|---|
| 4154 | set(handles.num_ColCode1,'String',num2str(col)) |
|---|
| 4155 | if(get(handles.Slider2,'Value') < col)%move also the second slider at the same value if needed |
|---|
| 4156 | set(handles.Slider2,'Value',col) |
|---|
| 4157 | set(handles.num_ColCode2,'String',num2str(col)) |
|---|
| 4158 | end |
|---|
| 4159 | set_vec_col_bar(handles) |
|---|
| 4160 | update_plot(handles); |
|---|
| 4161 | |
|---|
| 4162 | %---------------------------------------------------------------- |
|---|
| 4163 | % Executes on slider movement to set the color code |
|---|
| 4164 | %---------------------------------------------------------------- |
|---|
| 4165 | function Slider2_Callback(hObject, eventdata, handles) |
|---|
| 4166 | slider2=get(handles.Slider2,'Value'); |
|---|
| 4167 | min_val=str2num(get(handles.num_MinVec,'String')); |
|---|
| 4168 | max_val=str2num(get(handles.num_MaxVec,'String')); |
|---|
| 4169 | col=min_val+(max_val-min_val)*slider2; |
|---|
| 4170 | set(handles.num_ColCode2,'String',num2str(col)) |
|---|
| 4171 | if(get(handles.Slider1,'Value') > col)%move also the first slider at the same value if needed |
|---|
| 4172 | set(handles.Slider1,'Value',col) |
|---|
| 4173 | set(handles.num_ColCode1,'String',num2str(col)) |
|---|
| 4174 | end |
|---|
| 4175 | set_vec_col_bar(handles) |
|---|
| 4176 | update_plot(handles); |
|---|
| 4177 | |
|---|
| 4178 | %---------------------------------------------------------------- |
|---|
| 4179 | % --- Execute on return carriage on the edit box corresponding to slider 1 |
|---|
| 4180 | %---------------------------------------------------------------- |
|---|
| 4181 | function num_ColCode1_Callback(hObject, eventdata, handles) |
|---|
| 4182 | set_vec_col_bar(handles) |
|---|
| 4183 | update_plot(handles); |
|---|
| 4184 | |
|---|
| 4185 | %---------------------------------------------------------------- |
|---|
| 4186 | % --- Execute on return carriage on the edit box corresponding to slider 2 |
|---|
| 4187 | %---------------------------------------------------------------- |
|---|
| 4188 | function num_ColCode2_Callback(hObject, eventdata, handles) |
|---|
| 4189 | set_vec_col_bar(handles) |
|---|
| 4190 | update_plot(handles); |
|---|
| 4191 | %------------------------------------------------------------------------ |
|---|
| 4192 | %------------------------------------------------------- |
|---|
| 4193 | % --- Executes on button press in CheckFixVecColor. |
|---|
| 4194 | %------------------------------------------------------- |
|---|
| 4195 | function VecColBar_Callback(hObject, eventdata, handles) |
|---|
| 4196 | set_vec_col_bar(handles) |
|---|
| 4197 | |
|---|
| 4198 | %------------------------------------------------------------------------ |
|---|
| 4199 | % --- Executes on button press in CheckFixVecColor. |
|---|
| 4200 | function CheckFixVecColor_Callback(hObject, eventdata, handles) |
|---|
| 4201 | %------------------------------------------------------------------------ |
|---|
| 4202 | if ~get(handles.CheckFixVecColor,'Value') |
|---|
| 4203 | update_plot(handles); |
|---|
| 4204 | end |
|---|
| 4205 | |
|---|
| 4206 | %------------------------------------------------------------------------ |
|---|
| 4207 | % --- Executes on selection change in num_MaxVec. |
|---|
| 4208 | function num_MinVec_Callback(hObject, eventdata, handles) |
|---|
| 4209 | %------------------------------------------------------------------------ |
|---|
| 4210 | num_MaxVec_Callback(hObject, eventdata, handles) |
|---|
| 4211 | |
|---|
| 4212 | %------------------------------------------------------------------------ |
|---|
| 4213 | % --- Executes on selection change in num_MaxVec. |
|---|
| 4214 | function num_MaxVec_Callback(hObject, eventdata, handles) |
|---|
| 4215 | %------------------------------------------------------------------------ |
|---|
| 4216 | set(handles.CheckFixVecColor,'Value',1) |
|---|
| 4217 | CheckFixVecColor_Callback(hObject, eventdata, handles) |
|---|
| 4218 | min_val=str2num(get(handles.num_MinVec,'String')); |
|---|
| 4219 | max_val=str2num(get(handles.num_MaxVec,'String')); |
|---|
| 4220 | slider1=get(handles.Slider1,'Value'); |
|---|
| 4221 | slider2=get(handles.Slider2,'Value'); |
|---|
| 4222 | colcode1=min_val+(max_val-min_val)*slider1; |
|---|
| 4223 | colcode2=min_val+(max_val-min_val)*slider2; |
|---|
| 4224 | set(handles.num_ColCode1,'String',num2str(colcode1)) |
|---|
| 4225 | set(handles.num_ColCode2,'String',num2str(colcode2)) |
|---|
| 4226 | update_plot(handles); |
|---|
| 4227 | |
|---|
| 4228 | %------------------------------------------------------------------------ |
|---|
| 4229 | % --- update the display of color code for vectors (on vecColBar) |
|---|
| 4230 | function set_vec_col_bar(handles) |
|---|
| 4231 | %------------------------------------------------------------------------ |
|---|
| 4232 | %get the image of the color display button 'VecColBar' in pixels |
|---|
| 4233 | set(handles.VecColBar,'Units','pixel'); |
|---|
| 4234 | pos_vert=get(handles.VecColBar,'Position'); |
|---|
| 4235 | set(handles.VecColBar,'Units','Normalized'); |
|---|
| 4236 | width=ceil(pos_vert(3)); |
|---|
| 4237 | height=ceil(pos_vert(4)); |
|---|
| 4238 | |
|---|
| 4239 | %get slider indications |
|---|
| 4240 | list=get(handles.ColorCode,'String'); |
|---|
| 4241 | ichoice=get(handles.ColorCode,'Value'); |
|---|
| 4242 | colcode.ColorCode=list{ichoice}; |
|---|
| 4243 | colcode.MinVec=str2num(get(handles.num_MinVec,'String')); |
|---|
| 4244 | colcode.MaxVec=str2num(get(handles.num_MaxVec,'String')); |
|---|
| 4245 | test3color=strcmp(colcode.ColorCode,'rgb') || strcmp(colcode.ColorCode,'bgr'); |
|---|
| 4246 | if test3color |
|---|
| 4247 | colcode.ColCode1=str2num(get(handles.num_ColCode1,'String')); |
|---|
| 4248 | colcode.ColCode2=str2num(get(handles.num_ColCode2,'String')); |
|---|
| 4249 | end |
|---|
| 4250 | vec_C=colcode.MinVec+(colcode.MaxVec-colcode.MinVec)*(0.5:width-0.5)/width;%sample of vec_C values from min to max |
|---|
| 4251 | [colorlist,col_vec]=set_col_vec(colcode,vec_C); |
|---|
| 4252 | oneheight=ones(1,height); |
|---|
| 4253 | A1=colorlist(col_vec,1)*oneheight; |
|---|
| 4254 | A2=colorlist(col_vec,2)*oneheight; |
|---|
| 4255 | A3=colorlist(col_vec,3)*oneheight; |
|---|
| 4256 | A(:,:,1)=A1'; |
|---|
| 4257 | A(:,:,2)=A2'; |
|---|
| 4258 | A(:,:,3)=A3'; |
|---|
| 4259 | set(handles.VecColBar,'Cdata',A) |
|---|
| 4260 | |
|---|
| 4261 | %------------------------------------------------------------------- |
|---|
| 4262 | function update_plot(handles) |
|---|
| 4263 | %------------------------------------------------------------------- |
|---|
| 4264 | set(handles.REFRESH,'BackgroundColor',[1 1 0]);% display plot activity by yellow color |
|---|
| 4265 | drawnow |
|---|
| 4266 | UvData=get(handles.uvmat,'UserData'); |
|---|
| 4267 | AxeData=UvData.PlotAxes;% retrieve the current plotted data |
|---|
| 4268 | PlotParam=read_GUI(handles.uvmat); |
|---|
| 4269 | [tild,PlotParamOut]= plot_field(AxeData,handles.PlotAxes,PlotParam); |
|---|
| 4270 | errormsg=fill_GUI(PlotParamOut,handles.uvmat); |
|---|
| 4271 | if isempty(errormsg) |
|---|
| 4272 | set(handles.REFRESH,'BackgroundColor',[1 0 0]);% operation finished, back to red color |
|---|
| 4273 | else |
|---|
| 4274 | msgbox_uvmat('ERROR',errormsg) |
|---|
| 4275 | set(handles.REFRESH,'BackgroundColor',[1 0 1]);% magenta color: graph still needs to be updated |
|---|
| 4276 | end |
|---|
| 4277 | |
|---|
| 4278 | |
|---|
| 4279 | %------------------------------------------------------------------------ |
|---|
| 4280 | %------------------------------------------------------------------------ |
|---|
| 4281 | % SELECTION AND EDITION OF PROJECTION OBJECTS |
|---|
| 4282 | %------------------------------------------------------------------------ |
|---|
| 4283 | %------------------------------------------------------------------------ |
|---|
| 4284 | |
|---|
| 4285 | % --- Executes on selection change in ListObject_1. |
|---|
| 4286 | function ListObject_1_Callback(hObject, eventdata, handles) |
|---|
| 4287 | list_str=get(handles.ListObject,'String'); |
|---|
| 4288 | UvData=get(handles.uvmat,'UserData'); |
|---|
| 4289 | ObjectData=UvData.ProjObject{get(handles.ListObject_1,'Value')}; |
|---|
| 4290 | |
|---|
| 4291 | %% update the projection plot on uvmat |
|---|
| 4292 | ProjData= proj_field(UvData.Field,ObjectData);%project the current input field on object ObjectData |
|---|
| 4293 | plot_field(ProjData,handles.PlotAxes,read_GUI(handles.uvmat));% plot the projected field; |
|---|
| 4294 | %replot all the objects within the new projected field |
|---|
| 4295 | for IndexObj=1:numel(list_str) |
|---|
| 4296 | hobject=UvData.ProjObject{IndexObj}.DisplayHandle.uvmat; |
|---|
| 4297 | if isempty(hobject) || ~ishandle(hobject) |
|---|
| 4298 | hobject=handles.PlotAxes; |
|---|
| 4299 | end |
|---|
| 4300 | if isequal(IndexObj,get(handles.ListObject,'Value')) |
|---|
| 4301 | objectcolor='m'; %paint in magenta the currently selected object in ListObject |
|---|
| 4302 | else |
|---|
| 4303 | objectcolor='b'; |
|---|
| 4304 | end |
|---|
| 4305 | UvData.ProjObject{IndexObj}.DisplayHandle.uvmat=plot_object(UvData.ProjObject{IndexObj},ObjectData,hobject,objectcolor);%draw the object in uvmat |
|---|
| 4306 | end |
|---|
| 4307 | set(handles.uvmat,'UserData',UvData) |
|---|
| 4308 | |
|---|
| 4309 | %% display the object parameters if the GUI set_object is already opened |
|---|
| 4310 | if ~get(handles.CheckViewObject,'Value') |
|---|
| 4311 | ZBounds=0; % default |
|---|
| 4312 | if isfield(UvData.Field,'ZMin') && isfield(UvData.Field,'ZMax') |
|---|
| 4313 | ZBounds(1)=UvData.Field.ZMin; %minimum for the Z slider |
|---|
| 4314 | ZBounds(2)=UvData.Field.ZMax;%maximum for the Z slider |
|---|
| 4315 | end |
|---|
| 4316 | ObjectData.Name=list_str{get(handles.ListObject_1,'Value')}; |
|---|
| 4317 | hset_object=set_object(ObjectData,[],ZBounds); |
|---|
| 4318 | set(hset_object,'name','set_object') |
|---|
| 4319 | set(handles.CheckViewObject,'Value',1)% show that the selected object in ListObject_1 is currently visualised |
|---|
| 4320 | end |
|---|
| 4321 | |
|---|
| 4322 | % desactivate the edit object mode |
|---|
| 4323 | set(handles.CheckEditObject,'Value',0) |
|---|
| 4324 | % set(handles.CheckEditObject,'BackgroundColor',[0.7,0.7,0.7]) |
|---|
| 4325 | |
|---|
| 4326 | %------------------------------------------------------------------------ |
|---|
| 4327 | % --- Executes on selection change in ListObject. |
|---|
| 4328 | function ListObject_Callback(hObject, eventdata, handles) |
|---|
| 4329 | %------------------------------------------------------------------------ |
|---|
| 4330 | list_str=get(handles.ListObject,'String'); |
|---|
| 4331 | IndexObj=get(handles.ListObject,'Value');%present object selection |
|---|
| 4332 | UvData=get(handles.uvmat,'UserData'); |
|---|
| 4333 | if numel(UvData.ProjObject)<IndexObj |
|---|
| 4334 | return |
|---|
| 4335 | end |
|---|
| 4336 | ObjectData=UvData.ProjObject{IndexObj}; |
|---|
| 4337 | ZBounds=0; % default |
|---|
| 4338 | if isfield(UvData.Field,'ZMin') && isfield(UvData.Field,'ZMax') |
|---|
| 4339 | ZBounds(1)=UvData.Field.ZMin; %minimum for the Z slider |
|---|
| 4340 | ZBounds(2)=UvData.Field.ZMax;%maximum for the Z slider |
|---|
| 4341 | end |
|---|
| 4342 | |
|---|
| 4343 | %% show object features if view_object isselected |
|---|
| 4344 | if get(handles.CheckViewObject,'value') |
|---|
| 4345 | hset_object=set_object(ObjectData,[],ZBounds); |
|---|
| 4346 | set(hset_object,'name','set_object') |
|---|
| 4347 | end |
|---|
| 4348 | |
|---|
| 4349 | %% desactivate the edit object mode for security |
|---|
| 4350 | set(handles.CheckEditObject,'Value',0) |
|---|
| 4351 | |
|---|
| 4352 | %% update the plot on view_field if view_field is already openened |
|---|
| 4353 | hview_field=findobj(allchild(0),'tag','view_field'); |
|---|
| 4354 | if isempty(hview_field) |
|---|
| 4355 | hhview_field.PlotAxes=[]; |
|---|
| 4356 | else |
|---|
| 4357 | Data=get(hview_field,'UserData'); |
|---|
| 4358 | hhview_field=guidata(hview_field); |
|---|
| 4359 | ProjData= proj_field(UvData.Field,ObjectData);%project the current interface field on ObjectData |
|---|
| 4360 | [PlotType,PlotParam]=plot_field(ProjData,hhview_field.PlotAxes,read_GUI(hview_field));%read plotting parameters on the uvmat interface |
|---|
| 4361 | haxes=findobj(hview_field,'tag','axes3'); |
|---|
| 4362 | pos=get(hview_field,'Position'); |
|---|
| 4363 | if strcmp(get(haxes,'Visible'),'off')%sempty(PlotParam.Axes)% case of no plot display (pure text table) |
|---|
| 4364 | h_TableDisplay=findobj(hview_field,'tag','TableDisplay'); |
|---|
| 4365 | pos_table=get(h_TableDisplay,'Position'); |
|---|
| 4366 | set(hview_field,'Position',[pos(1)+pos(3)-pos_table(3) pos(2)+pos(4)-pos_table(4) pos_table(3) pos_table(4)]) |
|---|
| 4367 | drawnow% needed to change position before the next command |
|---|
| 4368 | set(hview_field,'UserData',Data);% restore the previously stored GUI position after GUI resizing |
|---|
| 4369 | else |
|---|
| 4370 | % set(hview_field,'Position',Data.GUISize)% return to the previously stored GUI position and size |
|---|
| 4371 | end |
|---|
| 4372 | end |
|---|
| 4373 | |
|---|
| 4374 | %% update the color of the graphic object representation: the selected object in magenta, others in blue |
|---|
| 4375 | update_object_color(handles.PlotAxes,hhview_field.PlotAxes,UvData.ProjObject{IndexObj}.DisplayHandle.uvmat) |
|---|
| 4376 | |
|---|
| 4377 | %------------------------------------------------------------------------ |
|---|
| 4378 | %--- update the color representation of objects (indicating the selected ones) |
|---|
| 4379 | function update_object_color(axes_uvmat,axes_view_field,DisplayHandle) |
|---|
| 4380 | %------------------------------------------------------------------------ |
|---|
| 4381 | if isempty(axes_view_field)% case with no view_field plot |
|---|
| 4382 | hother=[findobj(axes_uvmat,'Tag','proj_object');findobj(axes_uvmat,'Tag','DeformPoint')];%find all the proj object and deform point representations |
|---|
| 4383 | else |
|---|
| 4384 | hother=[findobj(axes_uvmat,'Tag','proj_object') ;findobj(axes_view_field,'Tag','proj_object');... %find all the proj object representations |
|---|
| 4385 | findobj(axes_uvmat,'Tag','DeformPoint'); findobj(axes_view_field,'Tag','DeformPoint')];%find all the deform point representations |
|---|
| 4386 | end |
|---|
| 4387 | for iobj=1:length(hother) |
|---|
| 4388 | if isequal(get(hother(iobj),'Type'),'rectangle')||isequal(get(hother(iobj),'Type'),'patch') |
|---|
| 4389 | set(hother(iobj),'EdgeColor','b') |
|---|
| 4390 | if isequal(get(hother(iobj),'FaceColor'),'m') |
|---|
| 4391 | set(hother(iobj),'FaceColor','b') |
|---|
| 4392 | end |
|---|
| 4393 | elseif isequal(get(hother(iobj),'Type'),'image') |
|---|
| 4394 | Acolor=get(hother(iobj),'CData'); |
|---|
| 4395 | Acolor(:,:,1)=zeros(size(Acolor,1),size(Acolor,2)); |
|---|
| 4396 | set(hother(iobj),'CData',Acolor); |
|---|
| 4397 | else |
|---|
| 4398 | set(hother(iobj),'Color','b') |
|---|
| 4399 | end |
|---|
| 4400 | set(hother(iobj),'Selected','off') |
|---|
| 4401 | end |
|---|
| 4402 | if ishandle(DisplayHandle) |
|---|
| 4403 | linetype=get(DisplayHandle,'Type'); |
|---|
| 4404 | if isequal(linetype,'line') |
|---|
| 4405 | set(DisplayHandle,'Color','m'); %set the selected object to magenta color |
|---|
| 4406 | elseif isequal(linetype,'rectangle') |
|---|
| 4407 | set(DisplayHandle,'EdgeColor','m'); %set the selected object to magenta color |
|---|
| 4408 | elseif isequal(linetype,'patch') |
|---|
| 4409 | set(DisplayHandle,'FaceColor','m'); %set the selected object to magenta color |
|---|
| 4410 | end |
|---|
| 4411 | SubObjectData=get(DisplayHandle,'UserData'); |
|---|
| 4412 | if isfield(SubObjectData,'SubObject') & ishandle(SubObjectData.SubObject) |
|---|
| 4413 | for iobj=1:length(SubObjectData.SubObject) |
|---|
| 4414 | hsub=SubObjectData.SubObject(iobj); |
|---|
| 4415 | if isequal(get(hsub,'Type'),'rectangle') |
|---|
| 4416 | set(hsub,'EdgeColor','m'); %set the selected object to magenta color |
|---|
| 4417 | elseif isequal(get(hsub,'Type'),'image') |
|---|
| 4418 | Acolor=get(hsub,'CData'); |
|---|
| 4419 | Acolor(:,:,1)=Acolor(:,:,3); |
|---|
| 4420 | set(hsub,'CData',Acolor); |
|---|
| 4421 | else |
|---|
| 4422 | set(hsub,'Color','m') |
|---|
| 4423 | end |
|---|
| 4424 | end |
|---|
| 4425 | end |
|---|
| 4426 | if isfield(SubObjectData,'DeformPoint') & ishandle(SubObjectData.DeformPoint) |
|---|
| 4427 | set(SubObjectData.DeformPoint,'Color','m') |
|---|
| 4428 | end |
|---|
| 4429 | end |
|---|
| 4430 | |
|---|
| 4431 | %------------------------------------------------------------------- |
|---|
| 4432 | % --- Executes on selection change in CheckEditObject. |
|---|
| 4433 | function CheckEditObject_Callback(hObject, eventdata, handles) |
|---|
| 4434 | %------------------------------------------------------------------- |
|---|
| 4435 | hset_object=findobj(allchild(0),'Tag','set_object'); |
|---|
| 4436 | if get(handles.CheckEditObject,'Value') |
|---|
| 4437 | %suppress the other options |
|---|
| 4438 | set(handles.MenuObject,'checked','off') |
|---|
| 4439 | set(handles.CheckZoom,'Value',0) |
|---|
| 4440 | CheckZoom_Callback(hObject, eventdata, handles) |
|---|
| 4441 | hgeometry_calib=findobj(allchild(0),'tag','geometry_calib'); |
|---|
| 4442 | if ishandle(hgeometry_calib) |
|---|
| 4443 | hhgeometry_calib=guidata(hgeometry_calib); |
|---|
| 4444 | set(hhgeometry_calib.CheckEnableMouse,'Value',0)% desactivate mouse action in geometry_calib |
|---|
| 4445 | set(hhgeometry_calib.CheckEnableMouse,'BackgroundColor',[0.7 0.7 0.7]) |
|---|
| 4446 | end |
|---|
| 4447 | set(handles.CheckViewObject,'value',1) |
|---|
| 4448 | CheckViewObject_Callback(hObject, eventdata, handles) |
|---|
| 4449 | else % desactivate object edit mode |
|---|
| 4450 | if ~isempty(hset_object)% open the |
|---|
| 4451 | set(get(hset_object,'children'),'Enable','off') |
|---|
| 4452 | hSAVE=findobj(hset_object,'Tag','SAVE'); |
|---|
| 4453 | set(hSAVE,'Enable','on') |
|---|
| 4454 | end |
|---|
| 4455 | end |
|---|
| 4456 | |
|---|
| 4457 | |
|---|
| 4458 | %------------------------------------------------------------------------ |
|---|
| 4459 | % --- Executes on button press in CheckViewObject. |
|---|
| 4460 | function CheckViewObject_Callback(hObject, eventdata, handles) |
|---|
| 4461 | %------------------------------------------------------------------------ |
|---|
| 4462 | check_view=get(handles.CheckViewObject,'Value'); |
|---|
| 4463 | |
|---|
| 4464 | if check_view %activate set_object |
|---|
| 4465 | IndexObj=get(handles.ListObject,'Value'); |
|---|
| 4466 | list_object=get(handles.ListObject,'String'); |
|---|
| 4467 | UvData=get(handles.uvmat,'UserData');%read UvData properties stored on the uvmat interface |
|---|
| 4468 | UvData.ProjObject{IndexObj}.Name=list_object{IndexObj}; |
|---|
| 4469 | if numel(UvData.ProjObject)<IndexObj;% error in UvData |
|---|
| 4470 | msgbox_uvmat('ERROR','invalid object list') |
|---|
| 4471 | return |
|---|
| 4472 | end |
|---|
| 4473 | ZBounds=0; % default |
|---|
| 4474 | if isfield(UvData.Field,'ZMin') && isfield(UvData.Field,'ZMax') |
|---|
| 4475 | ZBounds(1)=UvData.Field.ZMin; %minimum for the Z slider |
|---|
| 4476 | ZBounds(2)=UvData.Field.ZMax;%maximum for the Z slider |
|---|
| 4477 | end |
|---|
| 4478 | data=UvData.ProjObject{IndexObj}; |
|---|
| 4479 | if ~isfield(data,'Type')% default plane |
|---|
| 4480 | data.Type='plane'; |
|---|
| 4481 | end |
|---|
| 4482 | hset_object=set_object(data,[],ZBounds); |
|---|
| 4483 | set(hset_object,'name','set_object') |
|---|
| 4484 | hhset_object=guidata(hset_object); |
|---|
| 4485 | if get(handles.CheckEditObject,'Value')% edit mode |
|---|
| 4486 | set(get(hset_object,'children'),'Enable','on') |
|---|
| 4487 | else |
|---|
| 4488 | set(get(hset_object,'children'),'Enable','off')% deactivate the GUI except SAVE |
|---|
| 4489 | set(hhset_object.SAVE,'Enable','on') |
|---|
| 4490 | end |
|---|
| 4491 | else |
|---|
| 4492 | hset_object=findobj(allchild(0),'tag','set_object'); |
|---|
| 4493 | if ~isempty(hset_object) |
|---|
| 4494 | delete(hset_object)% delete existing version of set_object |
|---|
| 4495 | end |
|---|
| 4496 | end |
|---|
| 4497 | |
|---|
| 4498 | |
|---|
| 4499 | %------------------------------------------------------------------------ |
|---|
| 4500 | % --- Executes on button press in CheckViewField. |
|---|
| 4501 | function CheckViewField_Callback(hObject, eventdata, handles) |
|---|
| 4502 | %------------------------------------------------------------------------ |
|---|
| 4503 | check_view=get(handles.CheckViewField,'Value'); |
|---|
| 4504 | |
|---|
| 4505 | if check_view |
|---|
| 4506 | IndexObj=get(handles.ListObject,'Value'); |
|---|
| 4507 | UvData=get(handles.uvmat,'UserData');%read UvData properties stored on the uvmat interface |
|---|
| 4508 | if numel(UvData.ProjObject)<IndexObj(end);% error in UvData |
|---|
| 4509 | msgbox_uvmat('ERROR','invalid object list') |
|---|
| 4510 | return |
|---|
| 4511 | end |
|---|
| 4512 | ZBounds=0; % default |
|---|
| 4513 | if isfield(UvData.Field,'ZMin') && isfield(UvData.Field,'ZMax') |
|---|
| 4514 | ZBounds(1)=UvData.Field.ZMin; %minimum for the Z slider |
|---|
| 4515 | ZBounds(2)=UvData.Field.ZMax;%maximum for the Z slider |
|---|
| 4516 | end |
|---|
| 4517 | set(handles.ListObject,'Value',IndexObj);%restore ListObject selection after set_object deletion |
|---|
| 4518 | if ~isfield(UvData.ProjObject{IndexObj(1)},'Type')% default plane |
|---|
| 4519 | UvData.ProjObject{IndexObj(1)}.Type='plane'; |
|---|
| 4520 | end |
|---|
| 4521 | list_object=get(handles.ListObject,'String'); |
|---|
| 4522 | UvData.ProjObject{IndexObj(end)}.Name=list_object{IndexObj(end)}; |
|---|
| 4523 | |
|---|
| 4524 | %% show the projection of the selected object on view_field |
|---|
| 4525 | ProjData= proj_field(UvData.Field,UvData.ProjObject{IndexObj});%project the current field on ObjectData |
|---|
| 4526 | hview_field=findobj(allchild(0),'tag','view_field'); |
|---|
| 4527 | if isempty(hview_field) |
|---|
| 4528 | hview_field=view_field; |
|---|
| 4529 | end |
|---|
| 4530 | hhview_field=guidata(hview_field); |
|---|
| 4531 | [PlotType,PlotParam]=plot_field(ProjData,hhview_field.PlotAxes,read_GUI(hview_field));%read plotting parameters on the GUI view_field); |
|---|
| 4532 | errormsg=fill_GUI(PlotParam,hview_field); |
|---|
| 4533 | for list={'Scalar','Vectors'} |
|---|
| 4534 | if ~isfield(PlotParam,list{1}) |
|---|
| 4535 | set(hhview_field.(list{1}),'Visible','off') |
|---|
| 4536 | end |
|---|
| 4537 | end |
|---|
| 4538 | haxes=findobj(hview_field,'tag','axes3'); |
|---|
| 4539 | pos=get(hview_field,'Position'); |
|---|
| 4540 | if strcmp(get(haxes,'Visible'),'off')%sempty(PlotParam.Axes)% case of no plot display (pure text table) |
|---|
| 4541 | h_TableDisplay=findobj(hview_field,'tag','TableDisplay'); |
|---|
| 4542 | pos_table=get(h_TableDisplay,'Position'); |
|---|
| 4543 | set(hview_field,'Position',[pos(1)+pos(3)-pos_table(3) pos(2)+pos(4)-pos_table(4) pos_table(3) pos_table(4)]) |
|---|
| 4544 | else |
|---|
| 4545 | Data=get(hview_field,'UserData'); |
|---|
| 4546 | end |
|---|
| 4547 | else |
|---|
| 4548 | hview_field=findobj(allchild(0),'tag','view_field'); |
|---|
| 4549 | if ~isempty(hview_field) |
|---|
| 4550 | delete(hview_field)% delete existing version of set_object |
|---|
| 4551 | end |
|---|
| 4552 | end |
|---|
| 4553 | |
|---|
| 4554 | |
|---|
| 4555 | %------------------------------------------------------------------------ |
|---|
| 4556 | % --- Executes on button press in DeleteObject. |
|---|
| 4557 | %------------------------------------------------------------------------ |
|---|
| 4558 | function DeleteObject_Callback(hObject, eventdata, handles) |
|---|
| 4559 | |
|---|
| 4560 | IndexObj=get(handles.ListObject,'Value');%projection object selected for view_field |
|---|
| 4561 | IndexObj_1=get(handles.ListObject_1,'Value');%projection object selected for uvmat plot |
|---|
| 4562 | if IndexObj>1 && ~isequal(IndexObj,IndexObj_1) % do not delete the object used for the uvmat plot |
|---|
| 4563 | delete_object(IndexObj) |
|---|
| 4564 | end |
|---|
| 4565 | |
|---|
| 4566 | %'DeleteObject': delete a projection object, defined by its index in the Uvmat list or by its graphic handle |
|---|
| 4567 | %------------------------------------------------------------------------ |
|---|
| 4568 | % function DeleteObject(hObject) |
|---|
| 4569 | % |
|---|
| 4570 | % INPUT: |
|---|
| 4571 | % hObject: object index (if integer) or handle of the graphic object. If |
|---|
| 4572 | % hObject is a subobject, the parent object is detected and deleted. |
|---|
| 4573 | |
|---|
| 4574 | function delete_object(IndexObj) |
|---|
| 4575 | |
|---|
| 4576 | huvmat=findobj('tag','uvmat');%handles of the uvmat interface |
|---|
| 4577 | UvData=get(huvmat,'UserData'); |
|---|
| 4578 | hlist_object=findobj(huvmat,'Tag','ListObject');%handles of the object list in the uvmat interface |
|---|
| 4579 | list_str=get(hlist_object,'String');%objet list |
|---|
| 4580 | if ~isempty(UvData) && isfield(UvData, 'ProjObject') && length(UvData.ProjObject)>=IndexObj |
|---|
| 4581 | if isfield(UvData.ProjObject{IndexObj},'DisplayHandle') && isfield(UvData.ProjObject{IndexObj}.DisplayHandle,'uvmat') |
|---|
| 4582 | hdisplay=UvData.ProjObject{IndexObj}.DisplayHandle.uvmat;%handle of the object graphic representation in uvmat |
|---|
| 4583 | for iview=1:length(hdisplay) |
|---|
| 4584 | if ishandle(hdisplay(iview)) && ~isequal(hdisplay(iview),0) |
|---|
| 4585 | ObjectData=get(hdisplay(iview),'UserData'); |
|---|
| 4586 | if isfield(ObjectData,'SubObject') && ~isempty(ObjectData.SubObject) |
|---|
| 4587 | delete(ObjectData.SubObject(ishandle(ObjectData.SubObject)));% delete the graphic 'sub-objects (e.g. projection bounds) |
|---|
| 4588 | end |
|---|
| 4589 | if isfield(ObjectData,'DeformPoint')&& ~isempty(ObjectData.DeformPoint) |
|---|
| 4590 | delete(ObjectData.DeformPoint(ishandle(ObjectData.DeformPoint)));% delete the graphic deformation points |
|---|
| 4591 | delete(hdisplay(iview))% delete the main graphic representation of the object |
|---|
| 4592 | end |
|---|
| 4593 | end |
|---|
| 4594 | ishandle(hdisplay(iview)) |
|---|
| 4595 | end |
|---|
| 4596 | for iobj=IndexObj+1:length(UvData.ProjObject) |
|---|
| 4597 | hdisplay=UvData.ProjObject{iobj}.DisplayHandle.uvmat; |
|---|
| 4598 | for iview=1:length(hdisplay) |
|---|
| 4599 | if ishandle(hdisplay(iview)) && ~isequal(hdisplay(iview),0) |
|---|
| 4600 | PlotData=get(hdisplay(iview),'UserData'); |
|---|
| 4601 | PlotData.IndexObj=iobj-1; |
|---|
| 4602 | set(hdisplay(iview),'UserData',PlotData); |
|---|
| 4603 | end |
|---|
| 4604 | end |
|---|
| 4605 | end |
|---|
| 4606 | end |
|---|
| 4607 | UvData.ProjObject(IndexObj)=[]; |
|---|
| 4608 | end |
|---|
| 4609 | if numel(list_str)>=IndexObj |
|---|
| 4610 | list_str(IndexObj)=[]; |
|---|
| 4611 | end |
|---|
| 4612 | set(huvmat,'UserData',UvData); |
|---|
| 4613 | set(hlist_object,'String',list_str) |
|---|
| 4614 | set(hlist_object,'Value',length(list_str)) |
|---|
| 4615 | hlist_object_1=findobj(huvmat,'Tag','ListObject_1');%handles of the first object list in the uvmat interface |
|---|
| 4616 | old_index=get(hlist_object_1,'Value'); |
|---|
| 4617 | set(hlist_object_1,'String',list_str) |
|---|
| 4618 | if IndexObj<=old_index |
|---|
| 4619 | set(hlist_object_1,'Value',old_index-1) |
|---|
| 4620 | end |
|---|
| 4621 | |
|---|
| 4622 | %------------------------------------------------------------------------ |
|---|
| 4623 | %------------------------------------------------------------------------ |
|---|
| 4624 | % II - TOOLS FROM THE UPPER MENU BAR |
|---|
| 4625 | %------------------------------------------------------------------------ |
|---|
| 4626 | %------------------------------------------------------------------------ |
|---|
| 4627 | |
|---|
| 4628 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 4629 | % Export Menu Callbacks |
|---|
| 4630 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 4631 | %------------------------------------------------------------------------ |
|---|
| 4632 | % --- Executes on button press in Menu/Export/field in workspace. |
|---|
| 4633 | function MenuExportField_Callback(hObject, eventdata, handles) |
|---|
| 4634 | %------------------------------------------------------------------------ |
|---|
| 4635 | global Data_uvmat |
|---|
| 4636 | Data_uvmat=get(handles.uvmat,'UserData'); |
|---|
| 4637 | evalin('base','global Data_uvmat')%make CurData global in the workspace |
|---|
| 4638 | disp('Data_uvmat.Field=') |
|---|
| 4639 | evalin('base','Data_uvmat.Field') %display CurData in the workspace |
|---|
| 4640 | commandwindow; %brings the Matlab command window to the front |
|---|
| 4641 | |
|---|
| 4642 | %------------------------------------------------------------------------ |
|---|
| 4643 | % --- Executes on button press in Menu/Export/extract figure. |
|---|
| 4644 | function MenuExportFigure_Callback(hObject, eventdata, handles) |
|---|
| 4645 | %------------------------------------------------------------------------ |
|---|
| 4646 | hfig=figure; |
|---|
| 4647 | hc=copyobj(handles.PlotAxes,hfig); |
|---|
| 4648 | set(hc,'Position',[0.1 0.1 0.8 0.8]) |
|---|
| 4649 | h=findobj(handles.PlotAxes,'tag','ima'); %look for image in the plot |
|---|
| 4650 | if ~isempty(h) |
|---|
| 4651 | map=colormap(handles.PlotAxes); |
|---|
| 4652 | colormap(map);%transmit the current colormap to the new fig |
|---|
| 4653 | colorbar |
|---|
| 4654 | end |
|---|
| 4655 | |
|---|
| 4656 | % -------------------------------------------------------------------- |
|---|
| 4657 | function MenuExportAxis_Callback(hObject, eventdata, handles) |
|---|
| 4658 | % -------------------------------------------------------------------- |
|---|
| 4659 | ListFig=findobj(allchild(0),'Type','figure'); |
|---|
| 4660 | nb_option=0; |
|---|
| 4661 | menu={}; |
|---|
| 4662 | for ilist=1:numel(ListFig) |
|---|
| 4663 | FigName=get(ListFig(ilist),'name'); |
|---|
| 4664 | if isempty(FigName) |
|---|
| 4665 | FigName=['figure ' num2str(ListFig(ilist))]; |
|---|
| 4666 | end |
|---|
| 4667 | if ~strcmp(FigName,'uvmat') |
|---|
| 4668 | ListAxes=findobj(ListFig(ilist),'Type','axes'); |
|---|
| 4669 | ListTags=get(ListAxes,'Tag'); |
|---|
| 4670 | if ~isempty(ListTags) && ~isempty(find(~strcmp('Colorbar',ListTags), 1)) |
|---|
| 4671 | ListAxes=ListAxes(~strcmp('Colorbar',ListTags)); |
|---|
| 4672 | if numel(ListAxes)==1 |
|---|
| 4673 | nb_option=nb_option+1; |
|---|
| 4674 | menu{nb_option}=FigName ; |
|---|
| 4675 | AxesHandle(nb_option)=ListAxes; |
|---|
| 4676 | else |
|---|
| 4677 | nb_axis=0; |
|---|
| 4678 | for iaxes=1:numel(ListAxes) |
|---|
| 4679 | nb_axis=nb_axis+1; |
|---|
| 4680 | nb_option=nb_option+1; |
|---|
| 4681 | menu{nb_option}=[FigName '_' num2str(nb_axis)]; |
|---|
| 4682 | AxesHandle(nb_option)=ListAxes(nb_axis); |
|---|
| 4683 | end |
|---|
| 4684 | end |
|---|
| 4685 | end |
|---|
| 4686 | end |
|---|
| 4687 | end |
|---|
| 4688 | if isempty(menu) |
|---|
| 4689 | answer=msgbox_uvmat('INPUT_Y-N','no existing plotting axes available, create new figure?'); |
|---|
| 4690 | if strcmp(answer,'Yes') |
|---|
| 4691 | hfig=figure; |
|---|
| 4692 | copyobj(handles.PlotAxes,hfig); |
|---|
| 4693 | else |
|---|
| 4694 | return |
|---|
| 4695 | end |
|---|
| 4696 | map=colormap(handles.PlotAxes); |
|---|
| 4697 | colormap(map);%transmit the current colormap to the zoom fig |
|---|
| 4698 | colorbar |
|---|
| 4699 | else |
|---|
| 4700 | answer=msgbox_uvmat('INPUT_MENU','select a figure/axis on which the current uvmat plot will be exported',menu); |
|---|
| 4701 | if isempty(answer) |
|---|
| 4702 | return |
|---|
| 4703 | else |
|---|
| 4704 | axes(AxesHandle(answer)) |
|---|
| 4705 | hold on |
|---|
| 4706 | hchild=get(handles.PlotAxes,'children'); |
|---|
| 4707 | copyobj(hchild,gca); |
|---|
| 4708 | end |
|---|
| 4709 | end |
|---|
| 4710 | |
|---|
| 4711 | |
|---|
| 4712 | %------------------------------------------------------------------------ |
|---|
| 4713 | % -------------------------------------------------------------------- |
|---|
| 4714 | function MenuExportMovie_Callback(hObject, eventdata, handles) |
|---|
| 4715 | % -------------------------------------------------------------------- |
|---|
| 4716 | set(handles.MenuExportMovie,'BusyAction','queue')% activate the button |
|---|
| 4717 | |
|---|
| 4718 | [RootPath,SubDir,RootFile,FileIndex,FileExt]=read_file_boxes(handles); |
|---|
| 4719 | FileBase=fullfile(RootPath,RootFile); |
|---|
| 4720 | |
|---|
| 4721 | %% create a fig and axis for movies |
|---|
| 4722 | figure_movie=findobj(allchild(0),'name','figure_movie'); |
|---|
| 4723 | |
|---|
| 4724 | if ~isempty(figure_movie) |
|---|
| 4725 | delete(figure_movie)%delete existing figure_movie |
|---|
| 4726 | end |
|---|
| 4727 | figure_movie=figure; |
|---|
| 4728 | nbpix=[512 384];% resolution XVGA |
|---|
| 4729 | set(figure_movie,'name','figure_movie','Position',[1 1 nbpix]) |
|---|
| 4730 | newaxes=copyobj(handles.PlotAxes,figure_movie);%new plotting axes in the new figure |
|---|
| 4731 | set(newaxes,'Tag','movieaxes') |
|---|
| 4732 | |
|---|
| 4733 | %% display time if defined in uvmat |
|---|
| 4734 | time_str=get(handles.TimeValue,'String'); |
|---|
| 4735 | if ~isempty(time_str) |
|---|
| 4736 | htitle=get(newaxes,'Title'); |
|---|
| 4737 | % xlim=get(newaxes,'XLim'); |
|---|
| 4738 | % ylim=get(newaxes,'YLim'); |
|---|
| 4739 | % set(htitle,'Position',[xlim(2)+0.07*(xlim(2)-xlim(1)) ylim(2)-0.05*(ylim(2)-ylim(1)) 0]) |
|---|
| 4740 | |
|---|
| 4741 | set(htitle,'String',['t=' time_str]) |
|---|
| 4742 | end |
|---|
| 4743 | map=colormap(handles.PlotAxes); |
|---|
| 4744 | colormap(map);%transmit the current colormap to the zoom fig |
|---|
| 4745 | colorbar |
|---|
| 4746 | |
|---|
| 4747 | %% create the GUI set_movie |
|---|
| 4748 | %set(0,'Units','points') |
|---|
| 4749 | %ScreenSize=get(0,'ScreenSize');% get the size of the screen, to put the fig on the upper right |
|---|
| 4750 | Position=get(figure_movie,'Position'); |
|---|
| 4751 | Position(2)=Position(2)+1.2*Position(4); |
|---|
| 4752 | Position(3)=1.5*Position(3); |
|---|
| 4753 | Position(4)=Position(4)/2; |
|---|
| 4754 | hfig=findobj(allchild(0),'Tag','set_movie'); |
|---|
| 4755 | if ~isempty(hfig),delete(hfig), end; %delete existing version of the GUI |
|---|
| 4756 | hfig=figure('name','set_movie','tag','set_movie','MenuBar','none','NumberTitle','off','Units','pixels',... |
|---|
| 4757 | 'Position',Position); |
|---|
| 4758 | BackgroundColor=get(hfig,'Color'); |
|---|
| 4759 | hh=0.14; % box height (relative) |
|---|
| 4760 | % first raw of the GUI |
|---|
| 4761 | uicontrol('Style','text','Units','normalized', 'Position', [0.05 0.95-hh/2 0.9 hh/2],'BackgroundColor',BackgroundColor,... |
|---|
| 4762 | 'String','movie name:','FontUnits','points','FontSize',12,'FontWeight','bold','ForegroundColor','blue','HorizontalAlignment','center');%title |
|---|
| 4763 | uicontrol('Style','edit','Units','normalized', 'Position', [0.05 0.95-1.5*hh 0.9 hh],'tag','MovieName','BackgroundColor',[1 1 1],... |
|---|
| 4764 | 'String',fullfile(RootPath,[SubDir '.movie'], [RootFile '.avi']),'FontUnits','points','FontSize',12,'FontWeight','bold','TooltipString','''MovieName'': name (with path) of the movie to create');%edit box |
|---|
| 4765 | uicontrol('Style','text','Units','normalized', 'Position', [0.05 0.95-2.5*hh 0.45 hh/2],'BackgroundColor',BackgroundColor,... |
|---|
| 4766 | 'String','frames per second:','FontUnits','points','FontSize',12,'FontWeight','bold','ForegroundColor','blue','HorizontalAlignment','center');%title |
|---|
| 4767 | uicontrol('Style','text','Units','normalized', 'Position', [0.55 0.95-2.5*hh 0.45 hh/2],'BackgroundColor',BackgroundColor,... |
|---|
| 4768 | 'String','total nbre of frames:','FontUnits','points','FontSize',12,'FontWeight','bold','ForegroundColor','blue','HorizontalAlignment','center');%title |
|---|
| 4769 | uicontrol('Style','edit','Units','normalized', 'Position', [0.05 0.95-3.5*hh 0.3 hh],'tag','num_FramePerSecond','BackgroundColor',[1 1 1],... |
|---|
| 4770 | 'String','10','FontUnits','points','FontSize',12,'FontWeight','bold','TooltipString','''num_FramePerSecond'': nbre of frames per second');%edit box |
|---|
| 4771 | uicontrol('Style','edit','Units','normalized', 'Position', [0.65 0.95-3.5*hh 0.3 hh],'tag','num_FrameNumber','BackgroundColor',[1 1 1],... |
|---|
| 4772 | 'String','10','FontUnits','points','FontSize',12,'FontWeight','bold','TooltipString','''num_FrameNumber'': total nbre of frames');%edit box |
|---|
| 4773 | uicontrol('Style','pushbutton','Units','normalized', 'Position', [0.05 0.15 0.25 hh],'BackgroundColor',[1 0 0],'String','START','Callback',@(hObject,eventdata)set_movie_START_Callback(hObject,eventdata),... |
|---|
| 4774 | 'FontWeight','bold','FontUnits','points','FontSize',12,'TooltipString','''APPLY'': apply the output to the current field series in uvmat'); |
|---|
| 4775 | uicontrol('Style','pushbutton','Units','normalized', 'Position', [0.7 0.15 0.25 hh],'Callback',@(hObject,eventdata)set_movie_Cancel_Callback(hObject,eventdata),... |
|---|
| 4776 | 'String','Cancel','FontWeight','bold','FontUnits','points','FontSize',12,'TooltipString','''Cancel'': quit GUI without action'); |
|---|
| 4777 | uicontrol('Style','text','Units','normalized', 'Position', [0.05 0.05 0.9 hh/2],'BackgroundColor',BackgroundColor,... |
|---|
| 4778 | 'String','will extract the result of ++> on uvmat: adjust figure_movie with its Matlab edit menu, then press ''START ''','FontUnits','points','FontSize',12,'FontWeight','bold','ForegroundColor','blue','HorizontalAlignment','center');%title |
|---|
| 4779 | drawnow |
|---|
| 4780 | |
|---|
| 4781 | %------------------------------------------------------------------------ |
|---|
| 4782 | % function called by pressing APPLY in the GUI set_slices |
|---|
| 4783 | function set_movie_START_Callback(hObject,eventdata) |
|---|
| 4784 | %------------------------------------------------------------------------ |
|---|
| 4785 | %% read info from the GUI set_movie |
|---|
| 4786 | hset_movie=get(hObject,'parent'); |
|---|
| 4787 | hMovieName=findobj(hset_movie,'Tag','MovieName'); |
|---|
| 4788 | MovieName=get(hMovieName,'String'); |
|---|
| 4789 | hFramePerSecond=findobj(hset_movie,'Tag','num_FramePerSecond'); |
|---|
| 4790 | fps=str2double(get(hFramePerSecond,'String')); |
|---|
| 4791 | hFrameNumber=findobj(hset_movie,'Tag','num_FrameNumber'); |
|---|
| 4792 | FrameNumber=str2double(get(hFrameNumber,'String'));% total nbre of frames |
|---|
| 4793 | |
|---|
| 4794 | %% create the movie file |
|---|
| 4795 | MovieDir=fileparts(MovieName); |
|---|
| 4796 | if ~exist(MovieDir,'dir') |
|---|
| 4797 | [success,message]=mkdir(MovieDir); |
|---|
| 4798 | if ~isequal(success,1) |
|---|
| 4799 | msgbox_uvmat('ERROR',message) |
|---|
| 4800 | return |
|---|
| 4801 | end |
|---|
| 4802 | [success,message] = fileattrib(MovieDir,'+w','g','s');% allow writing access for the group of users, recursively in the folder |
|---|
| 4803 | if success==0 |
|---|
| 4804 | msgbox_uvmat('WARNING',{['unable to set group write access to ' MovieDir ':']; message});%error message for directory creation |
|---|
| 4805 | end |
|---|
| 4806 | end |
|---|
| 4807 | if exist(MovieName,'file') |
|---|
| 4808 | backup=MovieName; |
|---|
| 4809 | testexist=2; |
|---|
| 4810 | while testexist==2 |
|---|
| 4811 | backup=[backup '~']; |
|---|
| 4812 | testexist=exist(backup,'file'); |
|---|
| 4813 | end |
|---|
| 4814 | [success,message]=copyfile(MovieName,backup);%make backup of the existing file |
|---|
| 4815 | if isequal(success,1) |
|---|
| 4816 | delete(MovieName)%delete existing file |
|---|
| 4817 | else |
|---|
| 4818 | msgbox_uvmat('ERROR',message) |
|---|
| 4819 | return |
|---|
| 4820 | end |
|---|
| 4821 | end |
|---|
| 4822 | %create avi open |
|---|
| 4823 | aviobj=avifile(MovieName,'Compression','None','fps',fps); |
|---|
| 4824 | |
|---|
| 4825 | %% get info from uvmat and adjust it |
|---|
| 4826 | huvmat=findobj(allchild(0),'Tag','uvmat'); |
|---|
| 4827 | hhuvmat=guidata(huvmat); |
|---|
| 4828 | increment=str2num(get(hhuvmat.num_IndexIncrement,'String')); %get the field increment from uvmat |
|---|
| 4829 | set(hhuvmat.STOP,'Visible','on') |
|---|
| 4830 | set(hhuvmat.speed,'Visible','on') |
|---|
| 4831 | set(hhuvmat.speed_txt,'Visible','on') |
|---|
| 4832 | set(hhuvmat.Movie,'BusyAction','queue') |
|---|
| 4833 | set(hhuvmat.speed,'Value',1) |
|---|
| 4834 | figure_movie=findobj(allchild(0),'name','figure_movie'); |
|---|
| 4835 | hhuvmat.PlotAxes=findobj(figure_movie,'Tag','movieaxes');% the axis in the new figure becomes the current main plotting axes |
|---|
| 4836 | for i=1:FrameNumber |
|---|
| 4837 | if get(hhuvmat.speed,'Value')~=0 && isequal(get(hhuvmat.MenuExportMovie,'BusyAction'),'queue') % enable STOP command |
|---|
| 4838 | runpm(hObject,eventdata,hhuvmat,increment)% run plus |
|---|
| 4839 | drawnow |
|---|
| 4840 | time_str=get(hhuvmat.TimeValue,'String'); |
|---|
| 4841 | htitle=get(hhuvmat.PlotAxes,'Title'); |
|---|
| 4842 | Title=get(htitle,'String'); |
|---|
| 4843 | set(htitle,'String',regexprep(Title,'t=\d+.\d*',['t=' time_str])) |
|---|
| 4844 | mov=getframe(figure_movie); |
|---|
| 4845 | aviobj=addframe(aviobj,mov); |
|---|
| 4846 | end |
|---|
| 4847 | end |
|---|
| 4848 | aviobj=close(aviobj); |
|---|
| 4849 | msgbox_uvmat('CONFIRMATION',{['movie ' MovieName ' created '];['with ' num2str(FrameNumber) ' frames']}) |
|---|
| 4850 | |
|---|
| 4851 | |
|---|
| 4852 | %------------------------------------------------------------------------ |
|---|
| 4853 | % function called by pressing APPLY in the GUI set_slices |
|---|
| 4854 | function set_movie_Cancel_Callback(hObject,eventdata) |
|---|
| 4855 | %------------------------------------------------------------------------ |
|---|
| 4856 | delete(hObject) |
|---|
| 4857 | % |
|---|
| 4858 | % |
|---|
| 4859 | % |
|---|
| 4860 | % %read the current input file name |
|---|
| 4861 | % prompt = {'movie file name';'frames per second';'frame resolution (*[512x384] pixels)';'axis position relative to the frame';'total frame number (starting from the current uvmat display)'}; |
|---|
| 4862 | % dlg_title = 'select properties of the output avi movie'; |
|---|
| 4863 | % num_lines= 1; |
|---|
| 4864 | % def = {[FileBase '_out.avi'];'10';'1';'[0.05 0.07 0.9 0.9]';'10'}; |
|---|
| 4865 | |
|---|
| 4866 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 4867 | % Projection Objects Menu Callbacks |
|---|
| 4868 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 4869 | |
|---|
| 4870 | % ----------------------------------------------------------------------- |
|---|
| 4871 | function Menupoints_Callback(hObject, eventdata, handles) |
|---|
| 4872 | %------------------------------------------------------------------------ |
|---|
| 4873 | data.Type='points'; |
|---|
| 4874 | data.ProjMode='projection';%default |
|---|
| 4875 | data.ProjModeMenu={};% do not restrict ProjMode menus |
|---|
| 4876 | create_object(data,handles) |
|---|
| 4877 | |
|---|
| 4878 | % ----------------------------------------------------------------------- |
|---|
| 4879 | % --- Callback of the Menu command line |
|---|
| 4880 | %------------------------------------------------------------------------ |
|---|
| 4881 | function Menuline_Callback(hObject, eventdata, handles) |
|---|
| 4882 | %------------------------------------------------------------------------ |
|---|
| 4883 | data.Type='line'; |
|---|
| 4884 | data.ProjMode='projection';%default |
|---|
| 4885 | data.ProjModeMenu={};% do not restrict ProjMode menus |
|---|
| 4886 | create_object(data,handles) |
|---|
| 4887 | |
|---|
| 4888 | % ----------------------------------------------------------------------- |
|---|
| 4889 | % --- Callback of the Menu command line_x |
|---|
| 4890 | %------------------------------------------------------------------------ |
|---|
| 4891 | function Menuline_x_Callback(hObject, eventdata, handles) |
|---|
| 4892 | |
|---|
| 4893 | data.Type='line_x'; |
|---|
| 4894 | data.ProjMode='projection';%default |
|---|
| 4895 | data.ProjModeMenu={};% do not restrict ProjMode menus |
|---|
| 4896 | create_object(data,handles) |
|---|
| 4897 | |
|---|
| 4898 | % ----------------------------------------------------------------------- |
|---|
| 4899 | % --- Callback of the Menu command line_y |
|---|
| 4900 | % ----------------------------------------------------------------------- |
|---|
| 4901 | function Menuline_y_Callback(hObject, eventdata, handles) |
|---|
| 4902 | |
|---|
| 4903 | data.Type='line_y'; |
|---|
| 4904 | data.ProjMode='projection';%default |
|---|
| 4905 | data.ProjModeMenu={};% do not restrict ProjMode menus |
|---|
| 4906 | create_object(data,handles) |
|---|
| 4907 | |
|---|
| 4908 | %------------------------------------------------------------------------ |
|---|
| 4909 | function Menupolyline_Callback(hObject, eventdata, handles) |
|---|
| 4910 | %------------------------------------------------------------------------ |
|---|
| 4911 | data.Type='polyline'; |
|---|
| 4912 | data.ProjMode='projection';%default |
|---|
| 4913 | data.ProjModeMenu={};% do not restrict ProjMode menus |
|---|
| 4914 | create_object(data,handles) |
|---|
| 4915 | |
|---|
| 4916 | %------------------------------------------------------------------------ |
|---|
| 4917 | function Menupolygon_Callback(hObject, eventdata, handles) |
|---|
| 4918 | %------------------------------------------------------------------------ |
|---|
| 4919 | data.Type='polygon'; |
|---|
| 4920 | data.ProjMode='inside';%default |
|---|
| 4921 | data.ProjModeMenu={};% do not restrict ProjMode menus |
|---|
| 4922 | create_object(data,handles) |
|---|
| 4923 | |
|---|
| 4924 | %------------------------------------------------------------------------ |
|---|
| 4925 | function Menurectangle_Callback(hObject, eventdata, handles) |
|---|
| 4926 | %------------------------------------------------------------------------ |
|---|
| 4927 | data.Type='rectangle'; |
|---|
| 4928 | data.ProjMode='inside';%default |
|---|
| 4929 | data.ProjModeMenu={};% do not restrict ProjMode menus |
|---|
| 4930 | create_object(data,handles) |
|---|
| 4931 | |
|---|
| 4932 | %------------------------------------------------------------------------ |
|---|
| 4933 | function Menuellipse_Callback(hObject, eventdata, handles) |
|---|
| 4934 | %------------------------------------------------------------------------ |
|---|
| 4935 | data.Type='ellipse'; |
|---|
| 4936 | data.ProjMode='inside';%default |
|---|
| 4937 | data.ProjModeMenu={};% do not restrict ProjMode menus |
|---|
| 4938 | create_object(data,handles) |
|---|
| 4939 | |
|---|
| 4940 | %------------------------------------------------------------------------ |
|---|
| 4941 | function MenuMaskObject_Callback(hObject, eventdata, handles) |
|---|
| 4942 | %------------------------------------------------------------------------ |
|---|
| 4943 | data.Type='polygon'; |
|---|
| 4944 | data.TypeMenu={'polygon'}; |
|---|
| 4945 | data.ProjMode='mask_inside';%default |
|---|
| 4946 | data.ProjModeMenu={'mask_inside';'mask_outside'}; |
|---|
| 4947 | create_object(data,handles) |
|---|
| 4948 | |
|---|
| 4949 | %------------------------------------------------------------------------ |
|---|
| 4950 | function Menuplane_Callback(hObject, eventdata, handles) |
|---|
| 4951 | %------------------------------------------------------------------------ |
|---|
| 4952 | data.Type='plane'; |
|---|
| 4953 | data.ProjMode='projection';%default |
|---|
| 4954 | data.ProjModeMenu={};% do not restrict ProjMode menus |
|---|
| 4955 | create_object(data,handles) |
|---|
| 4956 | |
|---|
| 4957 | %------------------------------------------------------------------------ |
|---|
| 4958 | function Menuvolume_Callback(hObject, eventdata, handles) |
|---|
| 4959 | %------------------------------------------------------------------------ |
|---|
| 4960 | data.Type='volume'; |
|---|
| 4961 | data.ProjMode='interp_lin';%default |
|---|
| 4962 | data.ProjModeMenu={}; |
|---|
| 4963 | % set(handles.create,'Visible','on') |
|---|
| 4964 | % set(handles.create,'Value',1) |
|---|
| 4965 | % VOLUME_Callback(hObject,eventdata,handles)data.ProjModeMenu={}; |
|---|
| 4966 | create_object(data,handles) |
|---|
| 4967 | |
|---|
| 4968 | %------------------------------------------------------------------------ |
|---|
| 4969 | % --- generic function used for the creation of a projection object |
|---|
| 4970 | function create_object(data,handles) |
|---|
| 4971 | %------------------------------------------------------------------------ |
|---|
| 4972 | %% desactivate concurrent tools |
|---|
| 4973 | set(handles.MenuRuler,'checked','off')%desactivate ruler |
|---|
| 4974 | hgeometry_calib=findobj(allchild(0),'tag','geometry_calib');% search the GUI geometric calibration |
|---|
| 4975 | if ishandle(hgeometry_calib) |
|---|
| 4976 | hhgeometry_calib=guidata(hgeometry_calib); |
|---|
| 4977 | set(hhgeometry_calib.CheckEnableMouse,'Value',0)% desactivate mouse action in geometry_calib |
|---|
| 4978 | set(hhgeometry_calib.CheckEnableMouse,'BackgroundColor',[0.7 0.7 0.7]) |
|---|
| 4979 | end |
|---|
| 4980 | set(handles.CheckEditObject,'Value',0) %desactivate the object edit mode |
|---|
| 4981 | CheckEditObject_Callback([],[],handles) |
|---|
| 4982 | set(handles.CheckViewObject,'Value',0) % desactivate view_object (new object created) |
|---|
| 4983 | set(handles.CheckZoomFig,'Value',0) %desactivate zoom sub fig |
|---|
| 4984 | set(handles.CheckZoom,'Value',0) %desactivate the zoom action |
|---|
| 4985 | set(handles.MenuObject,'checked','on')% indicate object creation for mouse pointer display |
|---|
| 4986 | if ishandle(handles.UVMAT_title) |
|---|
| 4987 | delete(handles.UVMAT_title) %delete the initial display of uvmat if no field has been entered yet |
|---|
| 4988 | end |
|---|
| 4989 | |
|---|
| 4990 | %% initiate the new projection object |
|---|
| 4991 | UvData=get(handles.uvmat,'UserData'); |
|---|
| 4992 | data.Name=data.Type;% default name=type |
|---|
| 4993 | data.Coord=[0 0]; %default |
|---|
| 4994 | check_plot=0; |
|---|
| 4995 | if isfield(UvData,'Field') |
|---|
| 4996 | Field=UvData.Field; |
|---|
| 4997 | if isfield(Field,'NbDim')&& isequal(Field.NbDim,3) |
|---|
| 4998 | data.Coord=[0 0 0]; %default |
|---|
| 4999 | end |
|---|
| 5000 | if isfield(Field,'CoordUnit') |
|---|
| 5001 | data.CoordUnit=Field.CoordUnit; |
|---|
| 5002 | end |
|---|
| 5003 | if isfield(UvData.Field,'CoordMesh')&&~isempty(UvData.Field.CoordMesh) |
|---|
| 5004 | data.RangeX=[UvData.Field.XMin UvData.Field.XMax]; |
|---|
| 5005 | switch data.Type |
|---|
| 5006 | case {'line','polyline','points'} |
|---|
| 5007 | data.RangeY=UvData.Field.CoordMesh; |
|---|
| 5008 | case 'line_x' |
|---|
| 5009 | check_plot=1; %plot the line directly when set_object is opened |
|---|
| 5010 | data.Type='line'; |
|---|
| 5011 | data.RangeX=UvData.Field.XMin ; |
|---|
| 5012 | data.RangeY=UvData.Field.CoordMesh; |
|---|
| 5013 | data.Coord=[UvData.Field.XMin (UvData.Field.YMin +UvData.Field.YMax)/2;... |
|---|
| 5014 | UvData.Field.XMax (UvData.Field.YMin +UvData.Field.YMax)/2];% put line at the middle of the y axis |
|---|
| 5015 | case 'line_y' |
|---|
| 5016 | check_plot=1; %plot the line directly when set_object is opened |
|---|
| 5017 | data.Type='line'; |
|---|
| 5018 | data.RangeX=UvData.Field.YMin ; |
|---|
| 5019 | data.RangeY=UvData.Field.CoordMesh; |
|---|
| 5020 | data.Coord=[(UvData.Field.XMin+UvData.Field.XMax)/2 UvData.Field.YMin;... |
|---|
| 5021 | (UvData.Field.XMin +UvData.Field.XMax)/2 UvData.Field.YMax];% put line at the middle of the y axis |
|---|
| 5022 | case {'rectangle','ellipse'} |
|---|
| 5023 | data.RangeY=[UvData.Field.YMin UvData.Field.YMax]; |
|---|
| 5024 | data.RangeX=UvData.Field.CoordMesh; |
|---|
| 5025 | data.RangeY=UvData.Field.CoordMesh; |
|---|
| 5026 | otherwise |
|---|
| 5027 | data.RangeY=[UvData.Field.YMin UvData.Field.YMax]; |
|---|
| 5028 | end |
|---|
| 5029 | data.DX=UvData.Field.CoordMesh; |
|---|
| 5030 | data.DY=UvData.Field.CoordMesh; |
|---|
| 5031 | end |
|---|
| 5032 | end |
|---|
| 5033 | |
|---|
| 5034 | hset_object=set_object(data,handles);% call the GUI set_object |
|---|
| 5035 | hchild=get(hset_object,'children'); |
|---|
| 5036 | set(hchild,'enable','on') |
|---|
| 5037 | set(handles.DeleteObject,'Visible','on')% make the object delete button visible |
|---|
| 5038 | if check_plot |
|---|
| 5039 | hhset_object=guidata(hset_object); |
|---|
| 5040 | set_object('REFRESH_Callback',1,[],hhset_object);% call the GUI set_object |
|---|
| 5041 | end |
|---|
| 5042 | set(handles.CheckViewField,'Visible','on') |
|---|
| 5043 | set(handles.DeleteObject,'Visible','on') |
|---|
| 5044 | set(handles.ListObject_1,'Visible','on') |
|---|
| 5045 | set(handles.ListObject_1_title,'Visible','on') |
|---|
| 5046 | |
|---|
| 5047 | %------------------------------------------------------------------------ |
|---|
| 5048 | function MenuBrowseObject_Callback(hObject, eventdata, handles) |
|---|
| 5049 | %------------------------------------------------------------------------ |
|---|
| 5050 | %get the object file |
|---|
| 5051 | fileinput=uigetfile_uvmat('pick an xml object file:',get(handles.RootPath,'String'),'.xml'); |
|---|
| 5052 | if ~isempty(fileinput) |
|---|
| 5053 | %read the file |
|---|
| 5054 | [data,heading]=xml2struct(fileinput); |
|---|
| 5055 | if ~strcmp(heading,'ProjObject') |
|---|
| 5056 | msgbox_uvmat('WARNING','The xml file does not have the heading ProjObject for projection objects') |
|---|
| 5057 | end |
|---|
| 5058 | ListObject=get(handles.ListObject,'String'); |
|---|
| 5059 | ListObject=[ListObject;{data.Name}]; |
|---|
| 5060 | IndexObj=length(ListObject); |
|---|
| 5061 | UvData=get(handles.uvmat,'UserData'); |
|---|
| 5062 | UvData.ProjObject{IndexObj}=[]; %create a new empty object |
|---|
| 5063 | UvData.ProjObject{IndexObj}.DisplayHandle.uvmat=[]; %no plot handle before plot_field operation |
|---|
| 5064 | UvData.ProjObject{IndexObj}.DisplayHandle.view_field=[]; %no plot handle before plot_field operation |
|---|
| 5065 | set(handles.uvmat,'UserData',UvData) |
|---|
| 5066 | set(handles.CheckViewObject,'Value',1) |
|---|
| 5067 | set(handles.CheckViewField,'Value',1) |
|---|
| 5068 | hset_object=set_object(data);% call the set_object interface |
|---|
| 5069 | hhset_object=guidata(hset_object); |
|---|
| 5070 | set_object('REFRESH_Callback',hObject,eventdata,hhset_object);% plot projection |
|---|
| 5071 | set(handles.CheckEditObject,'Value',0); %suppress the object edit mode |
|---|
| 5072 | CheckEditObject_Callback([],[],handles) |
|---|
| 5073 | set(handles.DeleteObject,'Visible','on') |
|---|
| 5074 | end |
|---|
| 5075 | |
|---|
| 5076 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 5077 | % MenuTools Callbacks |
|---|
| 5078 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 5079 | %------------------------------------------------------------------------ |
|---|
| 5080 | function MenuCalib_Callback(hObject, eventdata, handles) |
|---|
| 5081 | %------------------------------------------------------------------------ |
|---|
| 5082 | %% suppress the second field if exists |
|---|
| 5083 | if get(handles.SubField,'Value') |
|---|
| 5084 | set(handles.SubField,'Value',0) |
|---|
| 5085 | SubField_Callback(hObject, eventdata, handles) |
|---|
| 5086 | end |
|---|
| 5087 | UvData=get(handles.uvmat,'UserData');%read UvData properties stored on the uvmat interface |
|---|
| 5088 | |
|---|
| 5089 | %% suppress competing tools |
|---|
| 5090 | set(handles.MenuRuler,'checked','off')%desactivate ruler |
|---|
| 5091 | set(handles.CheckZoom,'Value',0) |
|---|
| 5092 | set(handles.CheckZoom,'BackgroundColor',[0.7 0.7 0.7]) |
|---|
| 5093 | set(handles.ListObject,'Value',1) |
|---|
| 5094 | |
|---|
| 5095 | %% initiate display of the GUI geometry_calib |
|---|
| 5096 | data=[]; %default |
|---|
| 5097 | if isfield(UvData,'CoordType') |
|---|
| 5098 | data.CoordType=UvData.CoordType; |
|---|
| 5099 | end |
|---|
| 5100 | [RootPath,SubDir,RootFile,FileIndex,FileExt]=read_file_boxes(handles); |
|---|
| 5101 | FileName=[fullfile(RootPath,SubDir,RootFile) FileIndex FileExt]; |
|---|
| 5102 | set(handles.view_xml,'BackgroundColor',[1 1 0])%indicate the reading of the current xml file by geometry_calib |
|---|
| 5103 | geometry_calib(FileName);% call the geometry_calib interface |
|---|
| 5104 | set(handles.view_xml,'BackgroundColor',[1 1 1])%indicate the end of reading of the current xml file by geometry_calib |
|---|
| 5105 | set(handles.MenuCalib,'checked','on')% indicate that MenuCalib is activated, test used by mouse action |
|---|
| 5106 | |
|---|
| 5107 | |
|---|
| 5108 | % -------------------------------------------------------------------- |
|---|
| 5109 | % --- set the slice plane ro the set of slice planes when volume scan is used |
|---|
| 5110 | function MenuSetSlice_Callback(hObject, eventdata, handles) |
|---|
| 5111 | % -------------------------------------------------------------------- |
|---|
| 5112 | %% suppress the second input field if exists |
|---|
| 5113 | if get(handles.SubField,'Value') |
|---|
| 5114 | set(handles.SubField,'Value',0) |
|---|
| 5115 | SubField_Callback(hObject, eventdata, handles) |
|---|
| 5116 | end |
|---|
| 5117 | |
|---|
| 5118 | UvData=get(handles.uvmat,'UserData');%read UvData properties stored on the uvmat interface |
|---|
| 5119 | check=0; |
|---|
| 5120 | if isfield(UvData,'XmlData')&&isfield(UvData.XmlData{1},'GeometryCalib')&& isfield(UvData.XmlData{1}.GeometryCalib,'SliceCoord') |
|---|
| 5121 | GeometryCalib=UvData.XmlData{1}.GeometryCalib; |
|---|
| 5122 | else |
|---|
| 5123 | msgbox_uvmat('ERROR','3D geometric calibration needed before defining slices') |
|---|
| 5124 | return |
|---|
| 5125 | end |
|---|
| 5126 | SliceCoord=GeometryCalib.SliceCoord; |
|---|
| 5127 | InterfaceCoord=min(SliceCoord(:,3)); |
|---|
| 5128 | if isfield(GeometryCalib,'InterfaceCoord') |
|---|
| 5129 | InterfaceCoord=GeometryCalib.InterfaceCoord(1,3); |
|---|
| 5130 | end |
|---|
| 5131 | NbSlice=size(SliceCoord,1); |
|---|
| 5132 | CheckVolumeScan=0; |
|---|
| 5133 | if isfield(GeometryCalib,'CheckVolumeScan') |
|---|
| 5134 | CheckVolumeScan=GeometryCalib.CheckVolumeScan; |
|---|
| 5135 | end |
|---|
| 5136 | RefractionIndex=1.33; |
|---|
| 5137 | if isfield(GeometryCalib,'RefractionIndex') |
|---|
| 5138 | RefractionIndex=GeometryCalib.RefractionIndex; |
|---|
| 5139 | end |
|---|
| 5140 | SliceAngle=[0 0 0]; |
|---|
| 5141 | if isfield(GeometryCalib,'SliceAngle') |
|---|
| 5142 | SliceAngle=GeometryCalib.SliceAngle; |
|---|
| 5143 | end |
|---|
| 5144 | |
|---|
| 5145 | %% create the GUI set_slice |
|---|
| 5146 | set(0,'Units','points') |
|---|
| 5147 | ScreenSize=get(0,'ScreenSize');% get the size of the screen, to put the fig on the upper right |
|---|
| 5148 | Width=350;% fig width in points (1/72 inch) |
|---|
| 5149 | Height=min(0.8*ScreenSize(4),300); |
|---|
| 5150 | Left=ScreenSize(3)- Width-40; %right edge close to the right, with margin=40 |
|---|
| 5151 | Bottom=ScreenSize(4)-Height-40; %put fig at top right |
|---|
| 5152 | hfig=findobj(allchild(0),'Tag','set_slice'); |
|---|
| 5153 | if ~isempty(hfig),delete(hfig), end; %delete existing version of the GUI |
|---|
| 5154 | hfig=figure('name','set_slices','tag','set_slice','MenuBar','none','NumberTitle','off','Units','pixels','Position',[Left,Bottom,Width,Height],'UserData',GeometryCalib); |
|---|
| 5155 | BackgroundColor=get(hfig,'Color'); |
|---|
| 5156 | hh=0.14; % box height (relative) |
|---|
| 5157 | ii=0.01; % gap between uicontrols |
|---|
| 5158 | |
|---|
| 5159 | ww=(1-5*ii)/4; % box width (relative) |
|---|
| 5160 | % first raw of the GUI |
|---|
| 5161 | uicontrol('Style','text','Units','normalized', 'Position', [2*ii+ww 0.95-ii-0.25*hh ww hh/2],'BackgroundColor',BackgroundColor,... |
|---|
| 5162 | 'String','first','FontUnits','points','FontSize',12,'FontWeight','bold','ForegroundColor','blue','HorizontalAlignment','center');%title |
|---|
| 5163 | uicontrol('Style','text','Units','normalized', 'Position', [3*ii+2*ww 0.95-ii-0.25*hh ww hh/2],'BackgroundColor',BackgroundColor,... |
|---|
| 5164 | 'String','last','FontUnits','points','FontSize',12,'FontWeight','bold','ForegroundColor','blue','HorizontalAlignment','center');%title |
|---|
| 5165 | uicontrol('Style','text','Units','normalized', 'Position', [4*ii+3*ww 0.95-ii-0.25*hh ww hh/2],'BackgroundColor',BackgroundColor,... |
|---|
| 5166 | 'String','surface','FontUnits','points','FontSize',12,'FontWeight','bold','ForegroundColor','blue','HorizontalAlignment','center');%title |
|---|
| 5167 | % raw 2 of the GUI |
|---|
| 5168 | uicontrol('Style','text','Units','normalized', 'Position', [ii 0.95-2*ii-0.75*hh ww hh/2],'BackgroundColor',BackgroundColor,... |
|---|
| 5169 | 'String','Z','FontUnits','points','FontSize',12,'FontWeight','bold','ForegroundColor','blue','HorizontalAlignment','right');%title |
|---|
| 5170 | uicontrol('Style','edit','Units','normalized', 'Position', [2*ii+ww 0.95-2*ii-hh ww hh],'tag','num_Z_1','BackgroundColor',[1 1 1],... |
|---|
| 5171 | 'String',num2str(SliceCoord(1,3)),'FontUnits','points','FontSize',12,'FontWeight','bold','TooltipString','''num_Z_1'': z position of first slice');%edit box |
|---|
| 5172 | uicontrol('Style','edit','Units','normalized', 'Position', [3*ii+2*ww 0.95-2*ii-hh ww hh],'tag','num_Z_2','BackgroundColor',[1 1 1],... |
|---|
| 5173 | 'String',num2str(SliceCoord(end,3)),'FontUnits','points','FontSize',12,'FontWeight','bold','TooltipString','''num_Z_2'': z position of last slice');%edit box |
|---|
| 5174 | uicontrol('Style','edit','Units','normalized', 'Position', [4*ii+3*ww 0.95-2*ii-hh ww hh],'tag','num_H','BackgroundColor',[1 1 1],... |
|---|
| 5175 | 'String',num2str(InterfaceCoord),'FontUnits','points','FontSize',12,'FontWeight','bold','TooltipString','''num_H'': z position of the water surface (=Z_1 in air)');%edit box |
|---|
| 5176 | % raw 3 of the GUI |
|---|
| 5177 | uicontrol('Style','text','Units','normalized', 'Position', [2*ii+ww 0.95-3*ii-1.75*hh 2*ww hh/2],'BackgroundColor',BackgroundColor,'Tag','Refraction_title',... |
|---|
| 5178 | 'String','refraction index','FontUnits','points','FontSize',12,'FontWeight','bold','ForegroundColor','blue','HorizontalAlignment','right');%title |
|---|
| 5179 | uicontrol('Style','edit','Units','normalized', 'Position', [4*ii+3*ww 0.95-3*ii-2*hh ww hh],'tag','num_RefractionIndex','BackgroundColor',[1 1 1],... |
|---|
| 5180 | 'String',num2str(RefractionIndex),'FontUnits','points','FontSize',12,'FontWeight','bold','TooltipString','''num_RefractionIndex'': refraction index of water'); |
|---|
| 5181 | % raw 4 of the GUI |
|---|
| 5182 | uicontrol('Style','text','Units','normalized', 'Position', [ii 0.95-4*ii-3.25*hh ww hh],'BackgroundColor',BackgroundColor,'Tag','NbSlice_title',... |
|---|
| 5183 | 'String','NbSlice','FontUnits','points','FontSize',12,'FontWeight','bold','ForegroundColor','blue','HorizontalAlignment','right');%title |
|---|
| 5184 | uicontrol('Style','edit','Units','normalized', 'Position', [2*ii+ww 0.95-4*ii-3*hh ww hh],'tag','num_NbSlice','BackgroundColor',[1 1 1],... |
|---|
| 5185 | 'String',num2str(NbSlice),'FontUnits','points','FontSize',12,'FontWeight','bold','TooltipString','''num_NbSlice'':number of slices');%edit box |
|---|
| 5186 | uicontrol('Style','checkbox','Units','normalized', 'Position', [3*ii+2*ww 0.95-4*ii-3*hh 2*ww hh],'tag','CheckVolumeScan','BackgroundColor',BackgroundColor,... |
|---|
| 5187 | 'String','volume scan','Value',CheckVolumeScan,'FontUnits','points','FontSize',12,'FontWeight','bold','TooltipString','''CheckVolumeScan'':=1 for volume scan (z varies with j index)'); |
|---|
| 5188 | % raw 5 of the GUI |
|---|
| 5189 | uicontrol('Style','text','Units','normalized', 'Position', [2*ii+2*ww 0.95-5*ii-4.2*hh ww hh/2],'BackgroundColor',BackgroundColor,'Tag','Angle_title_1',... |
|---|
| 5190 | 'String','x axis','FontUnits','points','FontSize',12,'FontWeight','bold','ForegroundColor','blue','HorizontalAlignment','center');%title |
|---|
| 5191 | uicontrol('Style','text','Units','normalized', 'Position', [3*ii+3*ww 0.95-5*ii-4.2*hh ww hh/2],'BackgroundColor',BackgroundColor,'Tag','Angle_title_2',... |
|---|
| 5192 | 'String','y axis','FontUnits','points','FontSize',12,'FontWeight','bold','ForegroundColor','blue','HorizontalAlignment','center');%title |
|---|
| 5193 | % raw 6 of the GUI |
|---|
| 5194 | uicontrol('Style','text','Units','normalized', 'Position', [ii 0.95-5*ii-4.75*hh 2*ww hh/2],'BackgroundColor',BackgroundColor,'Tag','NbSlice_title',... |
|---|
| 5195 | 'String','tilt angle','FontUnits','points','FontSize',12,'FontWeight','bold','ForegroundColor','blue','HorizontalAlignment','right');%title |
|---|
| 5196 | uicontrol('Style','edit','Units','normalized', 'Position', [3*ii+2*ww 0.95-5*ii-5*hh ww hh],'tag','num_SliceAngle_1','BackgroundColor',[1 1 1],... |
|---|
| 5197 | 'String',num2str(SliceAngle(1)),'FontUnits','points','FontSize',12,'FontWeight','bold','TooltipString','''num_SliceAngle_1'':slice angle of inclination around the x axis');%edit box |
|---|
| 5198 | uicontrol('Style','edit','Units','normalized', 'Position', [4*ii+3*ww 0.95-5*ii-5*hh ww hh],'tag','num_SliceAngle_2','BackgroundColor',[1 1 1],... |
|---|
| 5199 | 'String',num2str(SliceAngle(2)),'FontUnits','points','FontSize',12,'FontWeight','bold','TooltipString','''num_SliceAngle_1'':slice angle of inclination around the y axis');%edit box |
|---|
| 5200 | % raw 7 of the GUI: pushbuttons |
|---|
| 5201 | wwp=(1-4*ii)/3; %width of the push buttons |
|---|
| 5202 | uicontrol('Style','pushbutton','Units','normalized', 'Position', [ii ii wwp hh],'BackgroundColor',[1 0 0],'String','APPLY','Callback',@(hObject,eventdata)set_slice_APPLY_Callback(hObject,eventdata),... |
|---|
| 5203 | 'FontWeight','bold','FontUnits','points','FontSize',12,'TooltipString','''APPLY'': apply the output to the current field series in uvmat'); |
|---|
| 5204 | uicontrol('Style','pushbutton','Units','normalized', 'Position', [2*ii+wwp ii wwp hh],'BackgroundColor',[1 0 0],'String','REPLICATE','Callback',@(hObject,eventdata)set_slice_REPLICATE_Callback(hObject,eventdata),... |
|---|
| 5205 | 'FontWeight','bold','FontUnits','points','FontSize',12,'TooltipString','''REPLICATE'': replicate the output for a series of experiments'); |
|---|
| 5206 | uicontrol('Style','pushbutton','Units','normalized', 'Position', [3*ii+2*wwp ii wwp hh],'Callback',@(hObject,eventdata)set_slice_Cancel_Callback(hObject,eventdata),... |
|---|
| 5207 | 'String','Cancel','FontWeight','bold','FontUnits','points','FontSize',12,'TooltipString','''Cancel'': quit GUI without action'); |
|---|
| 5208 | drawnow |
|---|
| 5209 | |
|---|
| 5210 | %------------------------------------------------------------------------ |
|---|
| 5211 | % function called by pressing APPLY in the GUI set_slices |
|---|
| 5212 | function set_slice_APPLY_Callback(hObject,eventdata) |
|---|
| 5213 | %------------------------------------------------------------------------ |
|---|
| 5214 | |
|---|
| 5215 | %% get the uvmat GUI data and read the current xml file |
|---|
| 5216 | huvmat=findobj(allchild(0),'Tag','uvmat'); |
|---|
| 5217 | hhuvmat=guidata(huvmat); |
|---|
| 5218 | [RootPath,SubDir,RootFile,FileIndex,FileExt]=read_file_boxes(hhuvmat); |
|---|
| 5219 | FileName=[fullfile(RootPath,SubDir,RootFile) FileIndex FileExt];%name of the xml file for calibration |
|---|
| 5220 | [RootPath,SubDir,RootFile,tild,tild,tild,tild,FileExt]=fileparts_uvmat(FileName); |
|---|
| 5221 | XmlFile=find_imadoc(RootPath,SubDir,RootFile,FileExt); |
|---|
| 5222 | [s,errormsg]=imadoc2struct(XmlFile,'GeometryCalib'); |
|---|
| 5223 | if~isempty(errormsg) |
|---|
| 5224 | msgbox_uvmat('ERROR',errormsg) |
|---|
| 5225 | return |
|---|
| 5226 | end |
|---|
| 5227 | GeometryCalib=s.GeometryCalib; |
|---|
| 5228 | |
|---|
| 5229 | %% read the content of the GUI set_slice |
|---|
| 5230 | SliceData=read_GUI(get(hObject,'parent')); |
|---|
| 5231 | GeometryCalib.NbSlice=SliceData.NbSlice; |
|---|
| 5232 | GeometryCalib.CheckVolumeScan=SliceData.CheckVolumeScan; |
|---|
| 5233 | Z_plane=linspace(SliceData.Z(1),SliceData.Z(2),SliceData.NbSlice); |
|---|
| 5234 | GeometryCalib.SliceCoord=Z_plane'*[0 0 1]; |
|---|
| 5235 | GeometryCalib.SliceAngle=zeros(GeometryCalib.NbSlice,3); |
|---|
| 5236 | GeometryCalib.SliceAngle(:,1)=SliceData.SliceAngle(1)*ones(GeometryCalib.NbSlice,1);%rotation around x axis (to generalise) |
|---|
| 5237 | GeometryCalib.SliceAngle(:,2)=SliceData.SliceAngle(2)*ones(GeometryCalib.NbSlice,1);%rotation around y axis (to generalise) |
|---|
| 5238 | GeometryCalib.SliceAngle(:,3)=0; |
|---|
| 5239 | GeometryCalib.InterfaceCoord=[0 0 SliceData.H]; |
|---|
| 5240 | GeometryCalib.RefractionIndex=SliceData.RefractionIndex; |
|---|
| 5241 | |
|---|
| 5242 | %% store the result in the xml file used for calibration |
|---|
| 5243 | errormsg=update_imadoc(GeometryCalib,XmlFile,'GeometryCalib');% introduce the calibration data in the xml file |
|---|
| 5244 | if strcmp(errormsg,'') |
|---|
| 5245 | msgbox_uvmat('CONFIRMATION',['slice positions saved in ' XmlFile]); |
|---|
| 5246 | else |
|---|
| 5247 | msgbox_uvmat('ERROR',errormsg); |
|---|
| 5248 | end |
|---|
| 5249 | |
|---|
| 5250 | %% display image with new calibration in the currently opened uvmat interface |
|---|
| 5251 | set(hhuvmat.CheckFixLimits,'Value',0)% put FixedLimits option to 'off' to plot the whole image |
|---|
| 5252 | uvmat('InputFileREFRESH_Callback',huvmat,[],hhuvmat); %file input with xml reading in uvmat, show the image in phys coordinates |
|---|
| 5253 | |
|---|
| 5254 | %------------------------------------------------------------------------ |
|---|
| 5255 | % function called by pressing REPLICATE in the GUI set_slices |
|---|
| 5256 | function set_slice_REPLICATE_Callback(hObject,eventdata) |
|---|
| 5257 | %------------------------------------------------------------------------ |
|---|
| 5258 | |
|---|
| 5259 | %% read the GUI set_slice |
|---|
| 5260 | SliceData=read_GUI(get(hObject,'parent')); |
|---|
| 5261 | |
|---|
| 5262 | %% get info on the GUI uvmat |
|---|
| 5263 | huvmat=findobj(allchild(0),'Tag','uvmat'); |
|---|
| 5264 | hhuvmat=guidata(huvmat); |
|---|
| 5265 | [RootPath,SubDir,RootFile,FileIndex,FileExt]=read_file_boxes(hhuvmat); |
|---|
| 5266 | |
|---|
| 5267 | %% open the GUI browse_data |
|---|
| 5268 | answer=msgbox_uvmat('INPUT_TXT','Campaign to calibrate with slice position?',fileparts(RootPath)); |
|---|
| 5269 | if strcmp(answer,'Cancel') |
|---|
| 5270 | return |
|---|
| 5271 | end |
|---|
| 5272 | OutPut=browse_data(answer); |
|---|
| 5273 | nbcalib=0; |
|---|
| 5274 | for ilist=1:numel(OutPut.Experiment) |
|---|
| 5275 | SubDirBase=regexprep(OutPut.DataSeries{1},'\..+$',''); |
|---|
| 5276 | XmlFile=fullfile(OutPut.Campaign,OutPut.Experiment{ilist},[SubDirBase '.xml']); |
|---|
| 5277 | |
|---|
| 5278 | % read the current xml file |
|---|
| 5279 | [s,errormsg]=imadoc2struct(XmlFile,'GeometryCalib'); |
|---|
| 5280 | if ~isempty(errormsg) |
|---|
| 5281 | msgbox_uvmat('ERROR',['error in reading ' XmlFile ': ' errormsg]) |
|---|
| 5282 | return |
|---|
| 5283 | end |
|---|
| 5284 | GeometryCalib=s.GeometryCalib; |
|---|
| 5285 | GeometryCalib.NbSlice=SliceData.NbSlice; |
|---|
| 5286 | GeometryCalib.VolumeScan=SliceData.CheckVolumeScan; |
|---|
| 5287 | Z_plane=linspace(SliceData.Z(1),SliceData.Z(2),SliceData.NbSlice); |
|---|
| 5288 | GeometryCalib.SliceCoord=Z_plane'*[0 0 1]; |
|---|
| 5289 | GeometryCalib.SliceAngle=zeros(GeometryCalib.NbSlice,3); |
|---|
| 5290 | GeometryCalib.SliceAngle(:,1)=SliceData.SliceAngle(1)*ones(GeometryCalib.NbSlice,1);%rotation around x axis (to generalise) |
|---|
| 5291 | GeometryCalib.SliceAngle(:,2)=SliceData.SliceAngle(2)*ones(GeometryCalib.NbSlice,1);%rotation around y axis (to generalise) |
|---|
| 5292 | GeometryCalib.SliceAngle(:,3)=0; |
|---|
| 5293 | GeometryCalib.InterfaceCoord=[0 0 SliceData.H]; |
|---|
| 5294 | GeometryCalib.RefractionIndex=SliceData.RefractionIndex; |
|---|
| 5295 | |
|---|
| 5296 | % update the current xml file |
|---|
| 5297 | errormsg=update_imadoc(GeometryCalib,XmlFile,'GeometryCalib');% introduce the calibration data in the xml file |
|---|
| 5298 | if ~strcmp(errormsg,'') |
|---|
| 5299 | msgbox_uvmat('ERROR',errormsg); |
|---|
| 5300 | else |
|---|
| 5301 | display([XmlFile ' updated with slice positions']) |
|---|
| 5302 | nbcalib=nbcalib+1; |
|---|
| 5303 | end |
|---|
| 5304 | end |
|---|
| 5305 | msgbox_uvmat('CONFIMATION',[SubDirBase ' calibrated with slice positions for ' num2str(nbcalib) ' experiments']); |
|---|
| 5306 | |
|---|
| 5307 | %------------------------------------------------------------------------ |
|---|
| 5308 | % function called by pressing Cancel in the GUI set_slices |
|---|
| 5309 | function set_slice_Cancel_Callback(hObject,eventdata) |
|---|
| 5310 | %------------------------------------------------------------------------ |
|---|
| 5311 | hfig=get(hObject,'parent'); |
|---|
| 5312 | delete(hfig) |
|---|
| 5313 | |
|---|
| 5314 | %----------------------------------------------------------------------- |
|---|
| 5315 | function MenuLIFCalib_Callback(hObject, eventdata, handles) |
|---|
| 5316 | %------------------------------------------------------------------------ |
|---|
| 5317 | %% read UvData properties stored on the uvmat interface |
|---|
| 5318 | UvData=get(handles.uvmat,'UserData'); |
|---|
| 5319 | if isfield(UvData,'XmlData')&& isfield(UvData.XmlData{1},'GeometryCalib') |
|---|
| 5320 | XmlData=UvData.XmlData{1}; |
|---|
| 5321 | else |
|---|
| 5322 | msgbox_uvmat('ERROR','geometric calibration needed: use Tools/geometric calibration in the menu bar'); |
|---|
| 5323 | return |
|---|
| 5324 | end |
|---|
| 5325 | |
|---|
| 5326 | %% read lines currently drawn |
|---|
| 5327 | ListObj=UvData.ProjObject; |
|---|
| 5328 | select=zeros(1,numel(ListObj)); |
|---|
| 5329 | for iobj=1:numel(ListObj); |
|---|
| 5330 | if isfield(ListObj{iobj},'Type') && strcmp(ListObj{iobj}.Type,'line') |
|---|
| 5331 | select(iobj)=1; |
|---|
| 5332 | end |
|---|
| 5333 | end |
|---|
| 5334 | val=find(select); |
|---|
| 5335 | if numel(val)<2 |
|---|
| 5336 | msgbox_uvmat('ERROR','light rays must be defined by at least two lines created by Projection object/line in the menu bar'); |
|---|
| 5337 | return |
|---|
| 5338 | else |
|---|
| 5339 | set(handles.ListObject,'Value',val);% show the selected lines on the list |
|---|
| 5340 | ObjectData=UvData.ProjObject(val); |
|---|
| 5341 | for iobj=1:length(ObjectData) |
|---|
| 5342 | xA(iobj)=ObjectData{iobj}.Coord(1,1); |
|---|
| 5343 | yA(iobj)=ObjectData{iobj}.Coord(1,2); |
|---|
| 5344 | xB(iobj)=ObjectData{iobj}.Coord(2,1); |
|---|
| 5345 | yB(iobj)=ObjectData{iobj}.Coord(2,2); |
|---|
| 5346 | end |
|---|
| 5347 | end |
|---|
| 5348 | |
|---|
| 5349 | %% find the origin as intersection of the two first lines (see http://www.ahristov.com/tutorial/geometry-games/intersection-lines.html ) |
|---|
| 5350 | x1=xA(1);x2=xB(1); |
|---|
| 5351 | x3=xA(2);x4=xB(2); |
|---|
| 5352 | y1=yA(1);y2=yB(1); |
|---|
| 5353 | y3=yA(2);y4=yB(2); |
|---|
| 5354 | D = (x1-x2)*(y3-y4) -(y1-y2)*(x3-x4); |
|---|
| 5355 | if D==0 |
|---|
| 5356 | msgbox_uvmat('ERROR','the two lines are parallel'); |
|---|
| 5357 | return |
|---|
| 5358 | end |
|---|
| 5359 | x0=((x3-x4)*(x1*y2-y1*x2)-(x1-x2)*(x3*y4-y3*x4))/D; |
|---|
| 5360 | y0=((y3-y4)*(x1*y2-y1*x2)-(y1-y2)*(x3*y4-y3*x4))/D; |
|---|
| 5361 | XmlData.Illumination.Origin=[x0 y0]; |
|---|
| 5362 | XmlData.PolarCentre=[x0 y0]; |
|---|
| 5363 | |
|---|
| 5364 | %% display the current image in polar axes with origin at the illumination source |
|---|
| 5365 | currentdir=pwd; |
|---|
| 5366 | uvmatpath=fileparts(which('uvmat')); |
|---|
| 5367 | cd(fullfile(uvmatpath,'transform_field')); |
|---|
| 5368 | phys_polar=str2func('phys_polar'); |
|---|
| 5369 | cd(currentdir) |
|---|
| 5370 | DataOut=phys_polar(UvData.Field,XmlData); |
|---|
| 5371 | view_field(DataOut); |
|---|
| 5372 | |
|---|
| 5373 | %% use the third line for reference luminosity |
|---|
| 5374 | if numel(val)==3 |
|---|
| 5375 | x_ref=linspace(ObjectData{3}.Coord(1,1),ObjectData{3}.Coord(2,1),10); |
|---|
| 5376 | y_ref=linspace(ObjectData{3}.Coord(1,2),ObjectData{3}.Coord(2,2),10); |
|---|
| 5377 | x_ref=x_ref-x0; |
|---|
| 5378 | y_ref=y_ref-y0; |
|---|
| 5379 | [theta_ref,r_ref] = cart2pol(x_ref,y_ref);%theta_ref and r_ref are the polar coordinates of the points on the line |
|---|
| 5380 | theta_ref=theta_ref*180/pi; |
|---|
| 5381 | figure |
|---|
| 5382 | plot(theta_ref,r_ref) |
|---|
| 5383 | azimuth_ima=linspace(DataOut.Coord_y(1),DataOut.Coord_y(2),size(DataOut.A,1));%profile of x index on the transformed image |
|---|
| 5384 | dist_source = interp1(theta_ref,r_ref,azimuth_ima); |
|---|
| 5385 | dist_source_pixel=round(size(DataOut.A,2)*(dist_source-DataOut.Coord_x(1))/(DataOut.Coord_x(2)-DataOut.Coord_x(1))); |
|---|
| 5386 | line_nan= isnan(dist_source_pixel); |
|---|
| 5387 | dist_source_pixel(line_nan)=1; |
|---|
| 5388 | width=20; %number of pixels used for reference |
|---|
| 5389 | DataOut.A=double(DataOut.A); |
|---|
| 5390 | Anorm=zeros(size(DataOut.A)); |
|---|
| 5391 | Aval=mean(mean(DataOut.A)); |
|---|
| 5392 | for iline=1:size(DataOut.A,1) |
|---|
| 5393 | lum(iline)=mean(DataOut.A(iline,dist_source_pixel(iline):dist_source_pixel(iline)+width)); |
|---|
| 5394 | Anorm(iline,:)=uint16(Aval*DataOut.A(iline,:)/lum(iline)); |
|---|
| 5395 | end |
|---|
| 5396 | lum(line_nan)=NaN; |
|---|
| 5397 | figure |
|---|
| 5398 | plot(1:size(DataOut.A,1),lum) |
|---|
| 5399 | end |
|---|
| 5400 | ImaName=regexprep([get(handles.RootFile,'String') get(handles.FileIndex,'String')],'//',''); |
|---|
| 5401 | NewImageName=fullfile(get(handles.RootPath,'String'),'polar',[ImaName get(handles.FileExt,'String')]); |
|---|
| 5402 | imwrite(Anorm,NewImageName,'BitDepth',16) |
|---|
| 5403 | |
|---|
| 5404 | %% record the origin in the xml file |
|---|
| 5405 | XmlFileName=find_imadoc(get(handles.RootPath,'String'),get(handles.SubDir,'String'),get(handles.RootFile,'String'),get(handles.FileExt,'String')); |
|---|
| 5406 | answer=msgbox_uvmat('INPUT_Y-N','save the illumination origin in the current xml file?'); |
|---|
| 5407 | if strcmp(answer,'Yes') |
|---|
| 5408 | t=xmltree(XmlFileName); %read the file |
|---|
| 5409 | title=get(t,1,'name'); |
|---|
| 5410 | if ~strcmp(title,'ImaDoc') |
|---|
| 5411 | msgbox_uvmat('ERROR','wrong xml file'); |
|---|
| 5412 | return |
|---|
| 5413 | end |
|---|
| 5414 | % backup the output file if it already exist, and read it |
|---|
| 5415 | backupfile=XmlFileName; |
|---|
| 5416 | testexist=2; |
|---|
| 5417 | while testexist==2 |
|---|
| 5418 | backupfile=[backupfile '~']; |
|---|
| 5419 | testexist=exist(backupfile,'file'); |
|---|
| 5420 | end |
|---|
| 5421 | [success,message]=copyfile(XmlFileName,backupfile);%make backup |
|---|
| 5422 | if success~=1 |
|---|
| 5423 | errormsg=['errror in xml file backup: ' message]; |
|---|
| 5424 | return |
|---|
| 5425 | end |
|---|
| 5426 | uid_illumination=find(t,'ImaDoc/Illumination'); |
|---|
| 5427 | if isempty(uid_illumination) %if GeometryCalib does not already exists, create it |
|---|
| 5428 | [t,uid_illumination]=add(t,1,'element','Illumination'); |
|---|
| 5429 | end |
|---|
| 5430 | uid_origin=find(t,'ImaDoc/Illumination/Origin'); |
|---|
| 5431 | if ~isempty(uid_origin) %if GeometryCalib does not already exists, create it |
|---|
| 5432 | t=delete(t,uid_origin); |
|---|
| 5433 | end |
|---|
| 5434 | % save the illumination origin |
|---|
| 5435 | t=struct2xml(XmlData.Illumination,t,uid_illumination); |
|---|
| 5436 | save(t,XmlFileName); |
|---|
| 5437 | end |
|---|
| 5438 | |
|---|
| 5439 | |
|---|
| 5440 | |
|---|
| 5441 | %------------------------------------------------------------------------ |
|---|
| 5442 | function MenuMask_Callback(hObject, eventdata, handles) |
|---|
| 5443 | %------------------------------------------------------------------------ |
|---|
| 5444 | UvData=get(handles.uvmat,'UserData');%read UvData properties stored on the uvmat interface |
|---|
| 5445 | ListObj=UvData.ProjObject; |
|---|
| 5446 | select=zeros(1,numel(ListObj)); |
|---|
| 5447 | for iobj=1:numel(ListObj); |
|---|
| 5448 | if strcmp(ListObj{iobj}.ProjMode,'mask_inside')||strcmp(ListObj{iobj}.ProjMode,'mask_outside') |
|---|
| 5449 | select(iobj)=1; |
|---|
| 5450 | end |
|---|
| 5451 | end |
|---|
| 5452 | val=find(select); |
|---|
| 5453 | if isempty(val) |
|---|
| 5454 | msgbox_uvmat('ERROR','polygons must be first created by Projection object/mask polygon in the menu bar'); |
|---|
| 5455 | return |
|---|
| 5456 | else |
|---|
| 5457 | set(handles.ListObject,'Value',val); |
|---|
| 5458 | flag=1; |
|---|
| 5459 | if ~isfield(UvData.Field,'A') |
|---|
| 5460 | msgbox_uvmat('ERROR','an image needs to be opened to set the mask size'); |
|---|
| 5461 | return |
|---|
| 5462 | end |
|---|
| 5463 | npx=size(UvData.Field.A,2); |
|---|
| 5464 | npy=size(UvData.Field.A,1); |
|---|
| 5465 | xi=0.5:npx-0.5; |
|---|
| 5466 | yi=0.5:npy-0.5; |
|---|
| 5467 | [Xi,Yi]=meshgrid(xi,yi); |
|---|
| 5468 | for iobj=1:length(UvData.ProjObject) |
|---|
| 5469 | ObjectData=UvData.ProjObject{iobj}; |
|---|
| 5470 | if isfield(ObjectData,'ProjMode') &&(isequal(ObjectData.ProjMode,'mask_inside')||isequal(ObjectData.ProjMode,'mask_outside')); |
|---|
| 5471 | flagobj=1; |
|---|
| 5472 | testphys=0; %coordinates in pixels by default |
|---|
| 5473 | if isfield(ObjectData,'CoordUnit') && ~isequal(ObjectData.CoordUnit,'pixel') |
|---|
| 5474 | if isfield(UvData,'XmlData')&& isfield(UvData.XmlData{1},'GeometryCalib') |
|---|
| 5475 | Calib=UvData.XmlData{1}.GeometryCalib; |
|---|
| 5476 | testphys=1; |
|---|
| 5477 | end |
|---|
| 5478 | end |
|---|
| 5479 | if isfield(ObjectData,'Coord')&& isfield(ObjectData,'Type') |
|---|
| 5480 | if isequal(ObjectData.Type,'polygon') |
|---|
| 5481 | X=ObjectData.Coord(:,1); |
|---|
| 5482 | Y=ObjectData.Coord(:,2); |
|---|
| 5483 | if testphys |
|---|
| 5484 | pos=[X Y zeros(size(X))]; |
|---|
| 5485 | if isfield(Calib,'SliceCoord') && length(Calib.SliceCoord)>=3 |
|---|
| 5486 | if isfield(Calib,'SliceAngle')&&~isequal(Calib.SliceAngle,[0 0 0]) |
|---|
| 5487 | om=norm(Calib.SliceAngle);%norm of rotation angle in radians |
|---|
| 5488 | OmAxis=Calib.SliceAngle/om; %unit vector marking the rotation axis |
|---|
| 5489 | cos_om=cos(pi*om/180); |
|---|
| 5490 | sin_om=sin(pi*om/180); |
|---|
| 5491 | pos=cos_om*pos+sin_om*cross(OmAxis,pos)+(1-cos_om)*(OmAxis*pos')*OmAxis; |
|---|
| 5492 | end |
|---|
| 5493 | pos(:,1)=pos(:,1)+Calib.SliceCoord(1); |
|---|
| 5494 | pos(:,2)=pos(:,2)+Calib.SliceCoord(2); |
|---|
| 5495 | pos(:,3)=pos(:,3)+Calib.SliceCoord(3); |
|---|
| 5496 | end |
|---|
| 5497 | [X,Y]=px_XYZ(Calib,pos(:,1),pos(:,2),pos(:,3)); |
|---|
| 5498 | end |
|---|
| 5499 | flagobj=~inpolygon(Xi,Yi,X',Y');%=0 inside the polygon, 1 outside |
|---|
| 5500 | elseif isequal(ObjectData.Type,'ellipse') |
|---|
| 5501 | if testphys |
|---|
| 5502 | %[X,Y]=px_XYZ(Calib,X,Y,0);% TODO:create a polygon boundary and transform to phys |
|---|
| 5503 | end |
|---|
| 5504 | RangeX=max(ObjectData.RangeX); |
|---|
| 5505 | RangeY=max(ObjectData.RangeY); |
|---|
| 5506 | X2Max=RangeX*RangeX; |
|---|
| 5507 | Y2Max=RangeY*RangeY; |
|---|
| 5508 | distX=(Xi-ObjectData.Coord(1,1)); |
|---|
| 5509 | distY=(Yi-ObjectData.Coord(1,2)); |
|---|
| 5510 | flagobj=(distX.*distX/X2Max+distY.*distY/Y2Max)>1; |
|---|
| 5511 | elseif isequal(ObjectData.Type,'rectangle') |
|---|
| 5512 | if testphys |
|---|
| 5513 | %[X,Y]=px_XYZ(Calib,X,Y,0);% TODO:create a polygon boundary and transform to phys |
|---|
| 5514 | end |
|---|
| 5515 | distX=abs(Xi-ObjectData.Coord(1,1)); |
|---|
| 5516 | distY=abs(Yi-ObjectData.Coord(1,2)); |
|---|
| 5517 | flagobj=distX>max(ObjectData.RangeX) | distY>max(ObjectData.RangeY); |
|---|
| 5518 | end |
|---|
| 5519 | if isequal(ObjectData.ProjMode,'mask_outside') |
|---|
| 5520 | flagobj=~flagobj; |
|---|
| 5521 | end |
|---|
| 5522 | flag=flag & flagobj; |
|---|
| 5523 | end |
|---|
| 5524 | end |
|---|
| 5525 | end |
|---|
| 5526 | %mask name |
|---|
| 5527 | RootPath=get(handles.RootPath,'String'); |
|---|
| 5528 | SubDir=get(handles.SubDir,'String'); |
|---|
| 5529 | RootFile=get(handles.RootFile,'String'); |
|---|
| 5530 | if ~isempty(RootFile)&&(isequal(RootFile(1),'/')|| isequal(RootFile(1),'\')) |
|---|
| 5531 | RootFile(1)=[]; |
|---|
| 5532 | end |
|---|
| 5533 | list=get(handles.masklevel,'String'); |
|---|
| 5534 | masknumber=num2str(length(list)); |
|---|
| 5535 | maskindex=get(handles.masklevel,'Value'); |
|---|
| 5536 | mask_name=fullfile_uvmat(RootPath,[SubDir '.mask'],'mask','.png','_1',maskindex); |
|---|
| 5537 | imflag=uint8(255*(0.392+0.608*flag));% =100 for flag=0 (vectors not computed when 20<imflag<200) |
|---|
| 5538 | imflag=flipdim(imflag,1); |
|---|
| 5539 | |
|---|
| 5540 | %display the mask |
|---|
| 5541 | hfigmask=figure; |
|---|
| 5542 | set(hfigmask,'Name','mask image') |
|---|
| 5543 | vec=linspace(0,1,256);%define a linear greyscale colormap |
|---|
| 5544 | map=[vec' vec' vec']; |
|---|
| 5545 | colormap(map) |
|---|
| 5546 | image(imflag); |
|---|
| 5547 | answer=msgbox_uvmat('INPUT_TXT','mask file name:', mask_name); |
|---|
| 5548 | if ~strcmp(answer,'Cancel') |
|---|
| 5549 | mask_dir=fileparts(answer); |
|---|
| 5550 | if ~exist(mask_dir,'dir') |
|---|
| 5551 | [success,msg]=mkdir(mask_dir); |
|---|
| 5552 | if success==0 |
|---|
| 5553 | msgbox_uvmat('ERROR',['cannot create ' mask_dir ': ' msg]);%error message for directory creation |
|---|
| 5554 | return |
|---|
| 5555 | end |
|---|
| 5556 | [success,msg] = fileattrib(mask_dir,'+w','g','s');% allow writing access for the group of users, recursively in the folder |
|---|
| 5557 | if success==0 |
|---|
| 5558 | msgbox_uvmat('WARNING',{['unable to set group write access to ' mask_dir ':']; msg});%error message for directory creation |
|---|
| 5559 | end |
|---|
| 5560 | end |
|---|
| 5561 | imwrite(imflag,answer,'BitDepth',8); |
|---|
| 5562 | end |
|---|
| 5563 | set(handles.ListObject,'Value',1) |
|---|
| 5564 | end |
|---|
| 5565 | |
|---|
| 5566 | %------------------------------------------------------------------------ |
|---|
| 5567 | %-- open the GUI set_grid.fig to create grid |
|---|
| 5568 | function MenuGrid_Callback(hObject, eventdata, handles) |
|---|
| 5569 | %------------------------------------------------------------------------ |
|---|
| 5570 | %suppress the other options if grid is chosen |
|---|
| 5571 | set(handles.edit_vect,'Value',0) |
|---|
| 5572 | edit_vect_Callback(hObject, eventdata, handles) |
|---|
| 5573 | set(handles.ListObject,'Value',1) |
|---|
| 5574 | |
|---|
| 5575 | %prepare display of the set_grid GUI |
|---|
| 5576 | [RootPath,SubDir,RootFile,FileIndex,FileExt]=read_file_boxes(handles); |
|---|
| 5577 | FileName=[fullfile(RootPath,SubDir,RootFile) FileIndex FileExt]; |
|---|
| 5578 | UvData=get(handles.uvmat,'UserData'); |
|---|
| 5579 | % CoordList=get(handles.TransformName,'String'); |
|---|
| 5580 | % val=get(handles.TransformName,'Value'); |
|---|
| 5581 | set_grid(FileName,UvData.Field);% call the set_object interface |
|---|
| 5582 | |
|---|
| 5583 | |
|---|
| 5584 | %------------------------------------------------------------------------ |
|---|
| 5585 | function MenuRuler_Callback(hObject, eventdata, handles) |
|---|
| 5586 | %------------------------------------------------------------------------ |
|---|
| 5587 | if strcmp(get(handles.MenuRuler,'checked'),'on') |
|---|
| 5588 | set(handles.MenuRuler,'checked','off')%desactivate if activated |
|---|
| 5589 | else |
|---|
| 5590 | set(handles.MenuRuler,'checked','on')%activate if selected |
|---|
| 5591 | set(handles.CheckZoom,'Value',0) |
|---|
| 5592 | CheckZoom_Callback(handles.uvmat, [], handles) |
|---|
| 5593 | UvData=get(handles.uvmat,'UserData'); |
|---|
| 5594 | UvData.MouseAction='ruler'; |
|---|
| 5595 | set(handles.uvmat,'UserData',UvData); |
|---|
| 5596 | end |
|---|
| 5597 | |
|---|
| 5598 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 5599 | % MenuRun Callbacks |
|---|
| 5600 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 5601 | |
|---|
| 5602 | %------------------------------------------------------------------------ |
|---|
| 5603 | % open the GUI 'series' |
|---|
| 5604 | function MenuSeries_Callback(hObject, eventdata, handles) |
|---|
| 5605 | %------------------------------------------------------------------------ |
|---|
| 5606 | Param=read_GUI(handles.uvmat); |
|---|
| 5607 | Param.HiddenData=get(handles.uvmat,'UserData'); |
|---|
| 5608 | series(Param); %run the series interface |
|---|
| 5609 | |
|---|
| 5610 | % -------------------------------------------------------------------- |
|---|
| 5611 | function MenuPIV_Callback(hObject, eventdata, handles) |
|---|
| 5612 | Param=read_GUI(handles.uvmat); |
|---|
| 5613 | Param.HiddenData=get(handles.uvmat,'UserData'); |
|---|
| 5614 | hseries=series(Param); |
|---|
| 5615 | hhseries=guidata(hseries); |
|---|
| 5616 | ActionMenu=get(hhseries.ActionName,'String'); |
|---|
| 5617 | index_action=find(strcmp('civ_series',ActionMenu)); |
|---|
| 5618 | set(hhseries.ActionName,'Value',index_action); |
|---|
| 5619 | series('ActionName_Callback',hObject,eventdata,hhseries); %file input with xml reading in uvmat, show the image in phys coordinates |
|---|
| 5620 | |
|---|
| 5621 | |
|---|
| 5622 | %------------------------------------------------------------------------ |
|---|
| 5623 | % -- open the GUI civ.fig for PIV |
|---|
| 5624 | function MenuCIVx_Callback(hObject, eventdata, handles) |
|---|
| 5625 | %------------------------------------------------------------------------ |
|---|
| 5626 | [RootPath,SubDir,RootFile,FileIndex,FileExt]=read_file_boxes(handles); |
|---|
| 5627 | FileName=[fullfile(RootPath,SubDir,RootFile) FileIndex FileExt]; |
|---|
| 5628 | civ(FileName);% interface de civ(not in the uvmat file) |
|---|
| 5629 | |
|---|
| 5630 | % function Param=read_param(handles) |
|---|
| 5631 | % |
|---|
| 5632 | % [RootPath,SubDir,RootFile,FileIndex,FileExt]=read_file_boxes(handles); |
|---|
| 5633 | % Param.FileName=[fullfile(RootPath,SubDir,RootFile) FileIndex FileExt];%first input file name |
|---|
| 5634 | % if isequal(get(handles.SubField,'Value'),1) |
|---|
| 5635 | % [RootPath_1,SubDir_1,RootFile_1,FileIndex_1,FileExt_1]=read_file_boxes_1(handles); |
|---|
| 5636 | % FileName_1=[fullfile(RootPath_1,SubDir_1,RootFile_1) FileIndex_1 FileExt_1]; |
|---|
| 5637 | % if ~isequal(FileName_1,Param.FileName) |
|---|
| 5638 | % Param.FileName_1=FileName_1;%second input file name if relevant |
|---|
| 5639 | % end |
|---|
| 5640 | % end |
|---|
| 5641 | % Param.NomType=get(handles.NomType,'String'); |
|---|
| 5642 | % Param.NomType_1=get(handles.NomType_1,'String'); |
|---|
| 5643 | % Param.CheckFixPair=get(handles.CheckFixPair,'Value'); |
|---|
| 5644 | % UvData=get(handles.uvmat,'UserData'); |
|---|
| 5645 | % if isfield(UvData,'XmlData')&& isfield(UvData.XmlData{1},'Time') |
|---|
| 5646 | % Param.Time=UvData.XmlData{1}.Time; |
|---|
| 5647 | % end |
|---|
| 5648 | % if isequal(get(handles.scan_i,'Value'),1) |
|---|
| 5649 | % Param.incr_i=str2num(get(handles.num_IndexIncrement,'String')); |
|---|
| 5650 | % elseif isequal(get(handles.scan_j,'Value'),1) |
|---|
| 5651 | % Param.incr_j=str2num(get(handles.num_IndexIncrement,'String')); |
|---|
| 5652 | % end |
|---|
| 5653 | % |
|---|
| 5654 | % %% transfer fields and coordinate names |
|---|
| 5655 | % Param.list_fields=get(handles.FieldName,'String');% list menu fields |
|---|
| 5656 | % FieldName=Param.list_fields{get(handles.FieldName,'Value')}; |
|---|
| 5657 | % ind_image=find(strcmp('image',Param.list_fields)); |
|---|
| 5658 | % if ~isempty(ind_image) && numel(Param.list_fields)>1 |
|---|
| 5659 | % Param.list_fields(ind_image)=[]; %suppress 'image' option |
|---|
| 5660 | % end |
|---|
| 5661 | % Param.index_fields=find(strcmp(FieldName,Param.list_fields));% selected string index |
|---|
| 5662 | % Param.list_fields_1=get(handles.FieldName_1,'String');% list menu fields |
|---|
| 5663 | % if ischar(Param.list_fields_1),Param.list_fields_1={Param.list_fields_1};end |
|---|
| 5664 | % FieldName_1=Param.list_fields_1{get(handles.FieldName_1,'Value')}; |
|---|
| 5665 | % ind_image=find(strcmp('image',Param.list_fields_1)); |
|---|
| 5666 | % if ~isempty(ind_image) && numel(Param.list_fields_1)>1 |
|---|
| 5667 | % Param.list_fields_1(ind_image)=[]; %suppress 'image' option |
|---|
| 5668 | % end |
|---|
| 5669 | % Param.index_fields_1=find(strcmp(FieldName_1,Param.list_fields_1));% selected string index |
|---|
| 5670 | % TransformList=get(handles.TransformName,'String'); |
|---|
| 5671 | % Param.TransformName=TransformList{get(handles.TransformName,'Value')}; |
|---|
| 5672 | % Param.Coord_x_str=get(handles.Coord_x,'String'); |
|---|
| 5673 | % %Param.Coord_x_val=get(handles.Coord_x,'Value'); |
|---|
| 5674 | % Param.Coord_y_str=get(handles.Coord_y,'String'); |
|---|
| 5675 | |
|---|
| 5676 | % -------------------------------------------------------------------- |
|---|
| 5677 | function MenuHelp_Callback(hObject, eventdata, handles) |
|---|
| 5678 | % -------------------------------------------------------------------- |
|---|
| 5679 | web('http://servforge.legi.grenoble-inp.fr/projects/soft-uvmat/wiki/UvmatHelp') |
|---|
| 5680 | |
|---|
| 5681 | % path_to_uvmat=which ('uvmat');% check the path of uvmat |
|---|
| 5682 | % pathelp=fileparts(path_to_uvmat); |
|---|
| 5683 | % helpfile=fullfile(pathelp,'uvmat_doc','uvmat_doc.html'); |
|---|
| 5684 | % if isempty(dir(helpfile)), msgbox_uvmat('ERROR','Please put the help file uvmat_doc.html in the sub-directory /uvmat_doc of the UVMAT package') |
|---|
| 5685 | % else |
|---|
| 5686 | % addpath (fullfile(pathelp,'uvmat_doc')) |
|---|
| 5687 | % web(helpfile); |
|---|
| 5688 | % end |
|---|
| 5689 | |
|---|
| 5690 | |
|---|
| 5691 | |
|---|
| 5692 | %TODO: use to modify fill_GUI |
|---|
| 5693 | %'write_plot_param': update the plotting parameters on the uvmat or view_field interface after a plotting operation |
|---|
| 5694 | function write_plot_param(handles,PlotParam) |
|---|
| 5695 | %% axes |
|---|
| 5696 | if isempty(PlotParam.Axes) |
|---|
| 5697 | set(handles.Axes,'Visible','off') |
|---|
| 5698 | set(handles.PlotAxes,'Visible','off') |
|---|
| 5699 | set(handles.text_display,'Visible','off') |
|---|
| 5700 | set(handles.TableDisplay,'Visible','on') |
|---|
| 5701 | else |
|---|
| 5702 | set(handles.Axes,'Visible','on') |
|---|
| 5703 | set(handles.PlotAxes,'Visible','on') |
|---|
| 5704 | set(handles.text_display,'Visible','on') |
|---|
| 5705 | if isfield(handles,'TableDisplay') |
|---|
| 5706 | set(handles.TableDisplay,'Visible','off') |
|---|
| 5707 | end |
|---|
| 5708 | Coordinates=PlotParam.Axes; |
|---|
| 5709 | if isfield(Coordinates,'CheckFixAspectRatio') |
|---|
| 5710 | if Coordinates.CheckFixAspectRatio |
|---|
| 5711 | set(handles.CheckFixAspectRatio,'Value',1) |
|---|
| 5712 | else |
|---|
| 5713 | set(handles.CheckFixAspectRatio,'Value',0) |
|---|
| 5714 | |
|---|
| 5715 | end |
|---|
| 5716 | end |
|---|
| 5717 | if isfield(Coordinates,'AspectRatio') |
|---|
| 5718 | set(handles.num_AspectRatio,'String',num2str(Coordinates.AspectRatio)) |
|---|
| 5719 | end |
|---|
| 5720 | if isfield(Coordinates,'MinX') |
|---|
| 5721 | set(handles.num_MinX,'String',num2str(Coordinates.MinX,4)); |
|---|
| 5722 | set(handles.num_MaxX,'String',num2str(Coordinates.MaxX,4)); |
|---|
| 5723 | set(handles.num_MinY,'String',num2str(Coordinates.MinY,4)); |
|---|
| 5724 | set(handles.num_MaxY,'String',num2str(Coordinates.MaxY,4)); |
|---|
| 5725 | else |
|---|
| 5726 | set(handles.num_MinX,'String',''); |
|---|
| 5727 | set(handles.num_MaxX,'String',''); |
|---|
| 5728 | set(handles.num_MinY,'String',''); |
|---|
| 5729 | set(handles.num_MaxY,'String',''); |
|---|
| 5730 | end |
|---|
| 5731 | end |
|---|
| 5732 | |
|---|
| 5733 | %% scalar or image parameters |
|---|
| 5734 | if isfield(PlotParam,'Scalar') |
|---|
| 5735 | set(handles.Scalar,'Visible','on') |
|---|
| 5736 | if isfield(PlotParam.Scalar,'MaxA') |
|---|
| 5737 | set(handles.num_MaxA,'String',num2str(PlotParam.Scalar.MaxA,3)); |
|---|
| 5738 | end |
|---|
| 5739 | if isfield(PlotParam.Scalar,'MinA') |
|---|
| 5740 | set(handles.num_MinA,'String',num2str(PlotParam.Scalar.MinA,3)); |
|---|
| 5741 | end |
|---|
| 5742 | if isfield(PlotParam.Scalar,'IncrA') |
|---|
| 5743 | set(handles.num_IncrA,'String',num2str(PlotParam.Scalar.IncrA,3)) |
|---|
| 5744 | end |
|---|
| 5745 | set(handles.CheckBW,'Value',PlotParam.Scalar.CheckBW) |
|---|
| 5746 | if isfield(PlotParam.Scalar,'Opacity')&&isfield(handles,'num_Opacity') |
|---|
| 5747 | set(handles.num_Opacity,'String',num2str(PlotParam.Scalar.Opacity)) |
|---|
| 5748 | end |
|---|
| 5749 | else |
|---|
| 5750 | set(handles.Scalar,'Visible','off') |
|---|
| 5751 | end |
|---|
| 5752 | |
|---|
| 5753 | %% parameter for vector field |
|---|
| 5754 | if isfield(PlotParam,'Vectors') |
|---|
| 5755 | set(handles.Vectors,'Visible','on') |
|---|
| 5756 | if isfield(PlotParam.Vectors,'VecScale') |
|---|
| 5757 | set(handles.num_VecScale,'String',num2str(PlotParam.Vectors.VecScale,3)) |
|---|
| 5758 | end |
|---|
| 5759 | if isfield(PlotParam.Vectors,'MinC')&& isfield(PlotParam.Vectors,'MaxC') |
|---|
| 5760 | MinC=PlotParam.Vectors.MinC; |
|---|
| 5761 | MaxC=PlotParam.Vectors.MaxC; |
|---|
| 5762 | set(handles.num_MinVec,'String', num2str(MinC,3)); |
|---|
| 5763 | set(handles.num_MaxVec,'String',num2str(MaxC,3)); |
|---|
| 5764 | list=get(handles.ColorCode,'String'); |
|---|
| 5765 | ichoice=get(handles.ColorCode,'Value'); |
|---|
| 5766 | color_option=list{ichoice}; |
|---|
| 5767 | test3color=strcmp(color_option,'rgb')||strcmp(color_option,'bgr'); |
|---|
| 5768 | if test3color% need to update color thresholds |
|---|
| 5769 | set(handles.num_ColCode1,'Visible','on') |
|---|
| 5770 | set(handles.num_ColCode2,'Visible','on') |
|---|
| 5771 | set(handles.Slider1,'Visible','on') |
|---|
| 5772 | set(handles.Slider2,'Visible','on') |
|---|
| 5773 | set(handles.num_ColCode1,'String',num2str(PlotParam.Vectors.ColCode1,3)) |
|---|
| 5774 | set(handles.num_ColCode2,'String',num2str(PlotParam.Vectors.ColCode2,3)) |
|---|
| 5775 | set(handles.Slider1,'Value',(PlotParam.Vectors.ColCode1-MinC)/(MaxC-MinC)) |
|---|
| 5776 | set(handles.Slider2,'Value',(PlotParam.Vectors.ColCode2-MinC)/(MaxC-MinC)) |
|---|
| 5777 | else |
|---|
| 5778 | set(handles.num_ColCode1,'Visible','off') |
|---|
| 5779 | set(handles.num_ColCode2,'Visible','off') |
|---|
| 5780 | set(handles.Slider1,'Visible','off') |
|---|
| 5781 | set(handles.Slider2,'Visible','off') |
|---|
| 5782 | end |
|---|
| 5783 | end |
|---|
| 5784 | else |
|---|
| 5785 | set(handles.Vectors,'Visible','off') |
|---|
| 5786 | if isfield(handles,'edit_vect') |
|---|
| 5787 | set(handles.edit_vect,'Visible','off') |
|---|
| 5788 | set(handles.record,'Visible','off') |
|---|
| 5789 | end |
|---|
| 5790 | end |
|---|
| 5791 | |
|---|
| 5792 | % -------------------------------------------------------------------- |
|---|
| 5793 | % --- Executes on button press in CheckTable. |
|---|
| 5794 | % -------------------------------------------------------------------- |
|---|
| 5795 | function CheckTable_Callback(hObject, eventdata, handles) |
|---|
| 5796 | if get(handles.CheckTable,'Value') |
|---|
| 5797 | set(handles.TableDisplay,'Visible','on') |
|---|
| 5798 | else |
|---|
| 5799 | set(handles.TableDisplay,'Visible','off') |
|---|
| 5800 | end |
|---|