1 | %'set_grid':produce grid for PIV with one or two images (stereo case) |
---|
2 | %------------------------------------------------------------------------ |
---|
3 | % function varargout = set_grid(varargin) |
---|
4 | % associated with the GUI set_grid.fig |
---|
5 | % |
---|
6 | %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA |
---|
7 | % Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org. |
---|
8 | %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA |
---|
9 | % This file is part of the toolbox UVMAT. |
---|
10 | % |
---|
11 | % UVMAT is free software; you can redistribute it and/or modify |
---|
12 | % it under the terms of the GNU General Public License as published by |
---|
13 | % the Free Software Foundation; either version 2 of the License, or |
---|
14 | % (at your option) any later version. |
---|
15 | % |
---|
16 | % UVMAT is distributed in the hope that it will be useful, |
---|
17 | % but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
18 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
19 | % GNU General Public License (file UVMAT/COPYING.txt) for more details. |
---|
20 | %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA |
---|
21 | |
---|
22 | function varargout = set_grid(varargin) |
---|
23 | |
---|
24 | % Last Modified by GUIDE v2.5 23-Apr-2010 15:44:47 |
---|
25 | |
---|
26 | % Begin initialization code - DO NOT PLOT |
---|
27 | gui_Singleton = 1; |
---|
28 | gui_State = struct('gui_Name', mfilename, ... |
---|
29 | 'gui_Singleton', gui_Singleton, ... |
---|
30 | 'gui_OpeningFcn', @set_grid_OpeningFcn, ... |
---|
31 | 'gui_OutputFcn', @set_grid_OutputFcn, ... |
---|
32 | 'gui_LayoutFcn', [] , ... |
---|
33 | 'gui_Callback', []); |
---|
34 | if nargin & isstr(varargin{1}) |
---|
35 | gui_State.gui_Callback = str2func(varargin{1}); |
---|
36 | end |
---|
37 | |
---|
38 | if nargout |
---|
39 | [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); |
---|
40 | else |
---|
41 | gui_mainfcn(gui_State, varargin{:}); |
---|
42 | end |
---|
43 | % End initialization code - DO NOT PLOT |
---|
44 | |
---|
45 | %------------------------------------------------------------------- |
---|
46 | % --- Executes just before set_grid is made visible. |
---|
47 | %INPUT: |
---|
48 | % handles: handles of the set_grid interface elements |
---|
49 | %'IndexObj': index of the object (on the UvData list) that set_grid will modify |
---|
50 | % if =[] or absent: index still undefined (create mode in uvmat) |
---|
51 | % if=0; no associated object (used for series), the button 'PLOT' is then unvisible |
---|
52 | %'data': read from an existing object selected in the interface |
---|
53 | % .TITLE : class of object ('POINTS','LINE',....) |
---|
54 | % .DX,DY,DZ; meshes for regular grids |
---|
55 | % .Coord: object position coordinates |
---|
56 | % .ParentButton: handle of the uicontrol object calling the interface |
---|
57 | % PlotHandles: set of handles of the elements contolling the plotting of the projected field: |
---|
58 | % if =[] or absent, no plot (mask mode in uvmat) |
---|
59 | % parameters on the uvmat interface (obtained by 'get_plot_handle.m') |
---|
60 | function set_grid_OpeningFcn(hObject, eventdata, handles,inputfile,CoordType) |
---|
61 | |
---|
62 | % Choose default command line output for set_grid |
---|
63 | handles.output = hObject; |
---|
64 | |
---|
65 | % Update handles structure |
---|
66 | guidata(hObject, handles); |
---|
67 | |
---|
68 | %default |
---|
69 | % set(hObject,'Unit','Normalized')% set the unit normalized to the screen size |
---|
70 | % set(hObject,'Position',[0.7 0.1 0.25 0.5])%set the position of the set_grid interface |
---|
71 | set(hObject,'DeleteFcn',@closefcn) |
---|
72 | % set(handles.TITLE,'Value',1) |
---|
73 | %set(handles.ObjectStyle,'Value',1) |
---|
74 | %set(handles.ProjMode,'Value',1) |
---|
75 | set(handles.MenuCoord,'ListboxTop',1) |
---|
76 | set(handles.MenuCoord,'Value',1); |
---|
77 | set(handles.MenuCoord,'String',{'phys';'px'}); |
---|
78 | if exist('inputfile','var')& ~isempty(inputfile) |
---|
79 | set(handles.image_1,'String',inputfile) |
---|
80 | set(handles.image_2,'String',inputfile) |
---|
81 | end |
---|
82 | if exist('CoordType','var') |
---|
83 | if strcmp(CoordType,'px') |
---|
84 | set(handles.MenuCoord,'Value',2) |
---|
85 | end |
---|
86 | end |
---|
87 | |
---|
88 | % --- Outputs from this function are returned to the command line. |
---|
89 | function varargout = set_grid_OutputFcn(hObject, eventdata, handles) |
---|
90 | % Get default command line output from handles structure |
---|
91 | varargout{1} = handles.output; |
---|
92 | varargout{2}=handles; |
---|
93 | |
---|
94 | |
---|
95 | %----------------------------------------------------- |
---|
96 | % --- Executes on button press in import. |
---|
97 | function import_Callback(hObject, eventdata, handles) |
---|
98 | %get the object file |
---|
99 | oldfile=''; |
---|
100 | huvmat=findobj('Tag','uvmat'); |
---|
101 | if isempty(huvmat) |
---|
102 | huvmat=findobj(allchild(0),'Name','series'); |
---|
103 | end |
---|
104 | hchild=get(huvmat,'Children'); |
---|
105 | hrootpath=findobj(hchild,'Tag','RootPath'); |
---|
106 | oldfile=get(hrootpath,'String'); |
---|
107 | if iscell(oldfile) |
---|
108 | oldfile=oldfile{1}; |
---|
109 | end |
---|
110 | %[FileName,PathName] = uigetfile('*.civ','Select a .civ file',oldfile) |
---|
111 | [FileName, PathName, filterindex] = uigetfile( ... |
---|
112 | {'*.xml;*.mat', ' (*.xml,*.mat)'; |
---|
113 | '*.xml', '.xml files '; ... |
---|
114 | '*.mat', '.mat matlab files '}, ... |
---|
115 | 'Pick a file',oldfile); |
---|
116 | fileinput=[PathName FileName];%complete file name |
---|
117 | testblank=findstr(fileinput,' ');%look for blanks |
---|
118 | if ~isempty(testblank) |
---|
119 | errordlg('forbidden input file name: contain blanks') |
---|
120 | return |
---|
121 | end |
---|
122 | sizf=size(fileinput); |
---|
123 | if (~ischar(fileinput)|~isequal(sizf(1),1)),return;end |
---|
124 | |
---|
125 | %read the file |
---|
126 | t=xmltree(fileinput); |
---|
127 | s=convert(t); |
---|
128 | testmode=0; |
---|
129 | if isfield(s,'ProjMode') |
---|
130 | menu=get(handles.ProjMode,'String'); |
---|
131 | for iline=1:length(menu) |
---|
132 | if isequal(menu{iline},s.ProjMode) |
---|
133 | set(handles.ProjMode,'Value',iline) |
---|
134 | testmode=1; |
---|
135 | break |
---|
136 | end |
---|
137 | end |
---|
138 | end |
---|
139 | |
---|
140 | ProjMode_Callback(hObject, eventdata, handles);%visualize the appropriate edit boxes |
---|
141 | if isfield(s,'CoordType') |
---|
142 | if isequal(s.CoordType,'phys') |
---|
143 | set(handles.MenuCoord,'Value',1) |
---|
144 | elseif isequal(s.CoordType,'px') |
---|
145 | set(handles.MenuCoord,'Value',2) |
---|
146 | else |
---|
147 | warndlg('unknown CoordType (px or phys) in set_grid.m') |
---|
148 | end |
---|
149 | end |
---|
150 | if isfield(s,'XMax') |
---|
151 | set(handles.XMax,'String',s.XMax) |
---|
152 | end |
---|
153 | if isfield(s,'XMin') |
---|
154 | set(handles.XMin,'String',s.XMin) |
---|
155 | end |
---|
156 | if isfield(s,'YMax') |
---|
157 | set(handles.YMax,'String',s.YMax) |
---|
158 | end |
---|
159 | if isfield(s,'YMin') |
---|
160 | set(handles.YMin,'String',s.YMin) |
---|
161 | end |
---|
162 | if isfield(s,'DX') |
---|
163 | set(handles.DX,'String',s.DX) |
---|
164 | end |
---|
165 | if isfield(s,'DY') |
---|
166 | set(handles.DY,'String',s.DY) |
---|
167 | end |
---|
168 | if ~isfield(s,'Coord') |
---|
169 | XObject='0';%default |
---|
170 | YObject='0'; |
---|
171 | elseif ischar(s.Coord) |
---|
172 | line=str2num(s.Coord); |
---|
173 | XObject=num2str(line(1)); |
---|
174 | YObject=num2str(line(2)); |
---|
175 | else |
---|
176 | for i=1:length(s.Coord) |
---|
177 | line=str2num(s.Coord{i}); |
---|
178 | XObject{i}=num2str(line(1)); |
---|
179 | YObject{i}=num2str(line(2)); |
---|
180 | end |
---|
181 | end |
---|
182 | set(handles.XObject,'String',XObject) |
---|
183 | set(handles.YObject,'String',YObject) |
---|
184 | %METTRA A JOUR ASPECT DE L'INTERFACE (COMME set_grid_Opening |
---|
185 | |
---|
186 | %---------------------------------------------------- |
---|
187 | % executed when closing: set the parent interface button to value 0 |
---|
188 | function closefcn(gcbo,eventdata) |
---|
189 | huvmat=findobj(allchild(0),'Name','uvmat');%find the current uvmat interface handle |
---|
190 | parent_button=findobj(huvmat,'Tag','grid'); |
---|
191 | if ~isempty(parent_button) |
---|
192 | set(parent_button,'Value',0)%put unactivated buttons to green |
---|
193 | tag=get(parent_button,'Tag'); |
---|
194 | if isequal(tag,'edit') |
---|
195 | set(parent_button,'BackgroundColor',[0.7 0.7 0.7]); |
---|
196 | else |
---|
197 | set(parent_button,'BackgroundColor',[0 1 0]); |
---|
198 | end |
---|
199 | end |
---|
200 | |
---|
201 | %----------------------------------------------------------------------- |
---|
202 | % --- Executes on button press in plot: PLOT the defined object and its projected field |
---|
203 | function plot_Callback(hObject, eventdata, handles) |
---|
204 | grid_pix_A=get_grid(handles); |
---|
205 | huvmat=uvmat(get(handles.image_1,'String')); |
---|
206 | hhuvmat=guidata(huvmat); |
---|
207 | set(hhuvmat.transform_fct,'Value',1) |
---|
208 | uvmat('run0_Callback',hObject,eventdata,hhuvmat); %file input with xml reading in uvmat |
---|
209 | axes(hhuvmat.axes3); |
---|
210 | hold on |
---|
211 | plot(grid_pix_A(:,1),grid_pix_A(:,2),'.') |
---|
212 | |
---|
213 | % --- Executes on button press in plot_2. |
---|
214 | function plot_2_Callback(hObject, eventdata, handles) |
---|
215 | [grid_pix_A,grid_pix_B]=get_grid(handles); |
---|
216 | huvmat=uvmat(get(handles.image_2,'String')); |
---|
217 | hhuvmat=guidata(huvmat); |
---|
218 | set(hhuvmat.transform_fct,'Value',1) |
---|
219 | uvmat('run0_Callback',hObject,eventdata,hhuvmat); %file input with xml reading in uvmat |
---|
220 | axes(hhuvmat.axes3); |
---|
221 | hold on |
---|
222 | plot(grid_pix_B(:,1),grid_pix_B(:,2),'.') |
---|
223 | |
---|
224 | |
---|
225 | |
---|
226 | % --- Executes on button press in MenuCoord. |
---|
227 | function MenuCoord_Callback(hObject, eventdata, handles) |
---|
228 | |
---|
229 | |
---|
230 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
231 | % --- Executes on button press in delete. |
---|
232 | function delete_Callback(hObject, eventdata, handles) |
---|
233 | |
---|
234 | %SetData=get(gcbf,'UserData');%get the interface data |
---|
235 | %IndexObj=SetData.IndexObj; |
---|
236 | huvmat=findobj('Name','uvmat');%find the current uvmat interface handle |
---|
237 | UvData=get(huvmat,'UserData');%Data associated to the current uvmat interface |
---|
238 | if isfield(UvData,'CurrentObjectIndex') |
---|
239 | IndexObj=UvData.CurrentObjectIndex; |
---|
240 | else |
---|
241 | IndexObj=[]; |
---|
242 | end |
---|
243 | delete_object(IndexObj); |
---|
244 | |
---|
245 | |
---|
246 | % ------------------------------------------------------ |
---|
247 | function save_Callback(hObject, eventdata, handles) |
---|
248 | % ------------------------------------------------------ |
---|
249 | [grid_pix_A,grid_pix_B]=get_grid(handles); |
---|
250 | |
---|
251 | %ECRIRE FICHIERS |
---|
252 | nbpointsA=size(grid_pix_A); |
---|
253 | XA=grid_pix_A(:,1); |
---|
254 | YA=grid_pix_A(:,2); |
---|
255 | unitcolumn=32*ones(size(XA)); |
---|
256 | Xchar=num2str(XA); |
---|
257 | blanc=char(unitcolumn); |
---|
258 | Ychar=num2str(YA); |
---|
259 | tete=['1 ' num2str(nbpointsA(1))]; |
---|
260 | txt=[Xchar blanc Ychar]; |
---|
261 | textgrid={tete;txt}; |
---|
262 | textout=char(textgrid); |
---|
263 | imageA=get(handles.image_1,'String'); |
---|
264 | [Pathsub]=name2display(imageA); |
---|
265 | Answer = msgbox_uvmat('INPUT_TXT','grid file name (*.grid)',fullfile(Pathsub,'gridA.grid')); |
---|
266 | % Answer = inputdlg('grid file name (*.grid)',' ',1,{fullfile(Pathsub,'gridA.grid')},'on'); |
---|
267 | dlmwrite(Answer,textout,''); |
---|
268 | msgbox_uvmat('CONFIRMATION',[Answer ' written as ASCII text file']); |
---|
269 | if ~isempty(grid_pix_B) |
---|
270 | nbpointsB=size(grid_pix_B); |
---|
271 | XB=grid_pix_B(:,1); |
---|
272 | YB=grid_pix_B(:,2); |
---|
273 | unitcolumn=32*ones(size(XB)); |
---|
274 | Xchar=num2str(XB); |
---|
275 | blanc=char(unitcolumn); |
---|
276 | Ychar=num2str(YB); |
---|
277 | tete=['1 ' num2str(nbpointsB(1))]; |
---|
278 | txt=[Xchar blanc Ychar]; |
---|
279 | textgrid={tete;txt}; |
---|
280 | textout=char(textgrid); |
---|
281 | Answer = msgbox_uvmat('INPUT_TXT','grid file name (*.grid)',fullfile(Pathsub,'gridB.grid')); |
---|
282 | dlmwrite(Answer,textout,''); |
---|
283 | msgbox_uvmat('CONFIRMATION',[Answer ' written as ASCII text file']); |
---|
284 | end |
---|
285 | |
---|
286 | %------------------------- |
---|
287 | function [grid_pix_A,grid_pix_B]=get_grid(handles); |
---|
288 | %Object=read_set_object(handles);%read the set_grid interface; |
---|
289 | grid_pix_B=[];%default |
---|
290 | DX=str2num(get(handles.DX,'String')); |
---|
291 | DY=str2num(get(handles.DY,'String')); |
---|
292 | XMin=str2num(get(handles.XMin,'String')); |
---|
293 | XMax=str2num(get(handles.XMax,'String')); |
---|
294 | YMin=str2num(get(handles.YMin,'String')); |
---|
295 | YMax=str2num(get(handles.YMax,'String')); |
---|
296 | array_realx=[XMin:DX:XMax]; |
---|
297 | array_realy=[YMin:DY:YMax]; |
---|
298 | nx_patch=length(array_realx); |
---|
299 | ny_patch=length(array_realy); |
---|
300 | [grid_realx,grid_realy]=meshgrid(array_realx,array_realy); |
---|
301 | grid_real(:,1)=reshape(grid_realx,nx_patch*ny_patch,1); |
---|
302 | grid_real(:,2)=reshape(grid_realy,nx_patch*ny_patch,1); |
---|
303 | grid_real(:,3)=zeros(nx_patch*ny_patch,1); |
---|
304 | |
---|
305 | imageA=get(handles.image_1,'String'); |
---|
306 | imageB=get(handles.image_2,'String'); |
---|
307 | testB=1; |
---|
308 | if isempty(imageA) || isequal(imageA,'') |
---|
309 | if isempty(imageB) || isequal(imageB,'') |
---|
310 | msgbox_uvmat('ERROR','at least one image file name must be introduced') |
---|
311 | else |
---|
312 | imageA=imageB; |
---|
313 | testB=0; |
---|
314 | end |
---|
315 | end |
---|
316 | if isempty(imageB) || isequal(imageB,'') || isequal(imageA,imageB) |
---|
317 | testB=0; |
---|
318 | end |
---|
319 | |
---|
320 | testexist=exist(imageA,'file'); |
---|
321 | if isequal(testexist,0) |
---|
322 | msgbox_uvmat('ERROR',['input image file' imageA 'does not exist']) |
---|
323 | return |
---|
324 | end |
---|
325 | [Pathsub,RootFile,field_count,str2,str_a,str_b,ext,nom_type,subdir]=name2display(imageA); |
---|
326 | form=imformats(ext(2:end)); |
---|
327 | if isempty(form)% if the extension corresponds to an image format recognized by Matlab |
---|
328 | msgbox_uvmat('ERROR',['error: ' imageA ' is not an image name recognized by Matlab ']) |
---|
329 | return |
---|
330 | end |
---|
331 | fileAxml=[fullfile(Pathsub,RootFile) '.xml']; |
---|
332 | [XmlDataA,error]=imadoc2struct(fileAxml); |
---|
333 | if isfield(XmlDataA,'GeometryCalib') |
---|
334 | tsaiA=XmlDataA.GeometryCalib; |
---|
335 | else |
---|
336 | msgbox_uvmat('WARNING','no geometric calibration available for image A') |
---|
337 | tsaiA=[]; |
---|
338 | end |
---|
339 | MenuCoord=get(handles.MenuCoord,'String'); |
---|
340 | val=get(handles.MenuCoord,'Value'); |
---|
341 | if isempty(tsaiA)||strcmp(MenuCoord{val},'px') |
---|
342 | grid_imaA(:,1)=grid_real(:,1); |
---|
343 | grid_imaA(:,2)=grid_real(:,2); |
---|
344 | else |
---|
345 | [grid_imaA(:,1),grid_imaA(:,2)]=px_XYZ(tsaiA,grid_real(:,1),grid_real(:,2),0); |
---|
346 | end |
---|
347 | A=imread(imageA); |
---|
348 | siz=size(A); |
---|
349 | npxA=siz(2); |
---|
350 | npyA=siz(1); |
---|
351 | |
---|
352 | flagA=grid_imaA(:,1)>0 & grid_imaA(:,1)<npxA & grid_imaA(:,2)>0 & grid_imaA(:,2)<npyA; |
---|
353 | |
---|
354 | if testB |
---|
355 | testexist=exist(imageB,'file'); |
---|
356 | if isequal(testexist,0) |
---|
357 | msgbox_uvmat('ERROR',['input image file' imageB 'does not exist']) |
---|
358 | return |
---|
359 | end |
---|
360 | [Pathsub,RootFile,field_count,str2,str_a,str_b,ext,nom_type,subdir]=name2display(imageB); |
---|
361 | form=imformats(ext([2:end])); |
---|
362 | if isempty(form)% if the extension corresponds to an image format recognized by Matlab |
---|
363 | msgbox_uvmat('ERROR',['error: ' imageB ' is not an image name recognized by Matlab ']) |
---|
364 | return |
---|
365 | end |
---|
366 | fileBxml=[fullfile(Pathsub,RootFile) '.xml']; |
---|
367 | [XmlDataB,error]=imadoc2struct(fileBxml); |
---|
368 | if isfield(XmlDataB,'GeometryCalib') |
---|
369 | tsaiB=XmlDataB.GeometryCalib; |
---|
370 | else |
---|
371 | msgbox_uvmat('WARNING','no geometric calibration available for image B') |
---|
372 | tsaiB=[]; |
---|
373 | end |
---|
374 | %[error,Heading,nom_type_read,ext_ima_read,time,TimeUnit,mode,NbSlice,... |
---|
375 | % npxB,npyB,tsaiB]=read_imadoc(fileBxml,0); |
---|
376 | [grid_imaB(:,1),grid_imaB(:,2)]=px_XYZ(tsaiB,grid_real(:,1),grid_real(:,2),0); |
---|
377 | % if isempty(npxB)|isempty(npyB) |
---|
378 | B=imread(imageB); |
---|
379 | siz=size(B); |
---|
380 | npxB=siz(2); |
---|
381 | npyB=siz(1); |
---|
382 | % end |
---|
383 | flagB=grid_imaB(:,1)>0 & grid_imaB(:,1)<npxB & grid_imaB(:,2)>0 & grid_imaB(:,2)<npyB; |
---|
384 | end |
---|
385 | if testB |
---|
386 | ind_good=find(flagA==1&flagB==1); |
---|
387 | XimaB=grid_imaB(ind_good,1); |
---|
388 | YimaB=grid_imaB(ind_good,2); |
---|
389 | else |
---|
390 | ind_good=find(flagA==1); |
---|
391 | end |
---|
392 | XimaA=grid_imaA(ind_good,1); |
---|
393 | YimaA=grid_imaA(ind_good,2); |
---|
394 | |
---|
395 | grid_real_x=grid_real(ind_good,1); |
---|
396 | grid_real_y=grid_real(ind_good,2); |
---|
397 | nx_patch_new=length(grid_real_x); |
---|
398 | grid_real2(:,1)=grid_real_x; |
---|
399 | grid_real2(:,2)=grid_real_y; |
---|
400 | grid_real2(:,3)=zeros(nx_patch_new,1); |
---|
401 | if isempty(tsaiA)||strcmp(MenuCoord{val},'px') |
---|
402 | grid_pix_A(:,1)=grid_real2(:,1); |
---|
403 | grid_pix_A(:,2)= grid_real2(:,2); |
---|
404 | else |
---|
405 | [grid_pix_A(:,1),grid_pix_A(:,2)]=px_XYZ(tsaiA,grid_real2(:,1),grid_real2(:,2)); |
---|
406 | end |
---|
407 | if testB |
---|
408 | [grid_pix_B(:,1),grid_pix_B(:,2)]=px_XYZ(tsaiB,grid_real2(:,1),grid_real2(:,2)); |
---|
409 | end |
---|
410 | |
---|
411 | |
---|
412 | |
---|
413 | %------------------------------------------------------------------------ |
---|
414 | % --- Executes on button press in HELP. |
---|
415 | function HELP_Callback(hObject, eventdata, handles) |
---|
416 | %------------------------------------------------------------------------ |
---|
417 | path_to_uvmat=which ('uvmat');% check the path of uvmat |
---|
418 | pathelp=fileparts(path_to_uvmat); |
---|
419 | helpfile=fullfile(pathelp,'uvmat_doc','uvmat_doc.html'); |
---|
420 | if isempty(dir(helpfile)), errordlg('Please put the help file uvmat_doc.html in the directory UVMAT/UVMAT_DOC') |
---|
421 | else |
---|
422 | web([helpfile '#set_grid']) |
---|
423 | end |
---|
424 | |
---|
425 | |
---|
426 | |
---|