source: trunk/src/set_grid.m @ 136

Last change on this file since 136 was 84, checked in by sommeria, 14 years ago

-update_imadoc: copy the timing information of the movie file avi in the new xml file when a geometry_calibration is performed
-set_grid: modified to produce grids in px coordiantes and to display the produced grid
-geometry_calib: display the point with max error
-civ: bug corrected for copying avi movies to png files
-uvmat: small bug fixes
-px_XYZ: introduce default values for Calib parameters

File size: 14.4 KB
Line 
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
22function 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
27gui_Singleton = 1;
28gui_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',   []);
34if nargin & isstr(varargin{1})
35    gui_State.gui_Callback = str2func(varargin{1});
36end
37
38if nargout
39    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
40else
41    gui_mainfcn(gui_State, varargin{:});
42end
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')
60function set_grid_OpeningFcn(hObject, eventdata, handles,inputfile,CoordType)
61
62% Choose default command line output for set_grid
63handles.output = hObject;
64
65% Update handles structure
66guidata(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
71set(hObject,'DeleteFcn',@closefcn)
72% set(handles.TITLE,'Value',1)
73%set(handles.ObjectStyle,'Value',1)
74%set(handles.ProjMode,'Value',1)
75set(handles.MenuCoord,'ListboxTop',1)
76set(handles.MenuCoord,'Value',1);
77set(handles.MenuCoord,'String',{'phys';'px'});
78if exist('inputfile','var')& ~isempty(inputfile)
79   set(handles.image_1,'String',inputfile)
80   set(handles.image_2,'String',inputfile)
81end
82if exist('CoordType','var')
83    if strcmp(CoordType,'px')
84        set(handles.MenuCoord,'Value',2)
85    end
86end
87
88% --- Outputs from this function are returned to the command line.
89function varargout = set_grid_OutputFcn(hObject, eventdata, handles)
90% Get default command line output from handles structure
91varargout{1} = handles.output;
92varargout{2}=handles;
93
94
95%-----------------------------------------------------
96% --- Executes on button press in import.
97function import_Callback(hObject, eventdata, handles)
98%get the object file
99oldfile='';
100huvmat=findobj('Tag','uvmat');
101if isempty(huvmat)
102    huvmat=findobj(allchild(0),'Name','series');
103end
104hchild=get(huvmat,'Children');
105hrootpath=findobj(hchild,'Tag','RootPath');
106oldfile=get(hrootpath,'String');
107if iscell(oldfile)
108    oldfile=oldfile{1};
109end
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);
116fileinput=[PathName FileName];%complete file name
117testblank=findstr(fileinput,' ');%look for blanks
118if ~isempty(testblank)
119    errordlg('forbidden input file name: contain blanks')
120    return
121end
122sizf=size(fileinput);
123if (~ischar(fileinput)|~isequal(sizf(1),1)),return;end
124
125%read the file
126 t=xmltree(fileinput);
127 s=convert(t);
128testmode=0;
129if 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
138end
139
140ProjMode_Callback(hObject, eventdata, handles);%visualize the appropriate edit boxes
141if 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
149end
150if isfield(s,'XMax')
151    set(handles.XMax,'String',s.XMax)
152end
153if isfield(s,'XMin')
154    set(handles.XMin,'String',s.XMin)
155end
156if isfield(s,'YMax')
157    set(handles.YMax,'String',s.YMax)
158end
159if isfield(s,'YMin')
160    set(handles.YMin,'String',s.YMin)
161end
162if isfield(s,'DX')
163    set(handles.DX,'String',s.DX)
164end
165if isfield(s,'DY')
166    set(handles.DY,'String',s.DY)
167end
168if ~isfield(s,'Coord')
169    XObject='0';%default
170    YObject='0';
171elseif ischar(s.Coord)
172    line=str2num(s.Coord);
173    XObject=num2str(line(1));
174    YObject=num2str(line(2));
175else
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
181end
182set(handles.XObject,'String',XObject)
183set(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
188function closefcn(gcbo,eventdata)
189huvmat=findobj(allchild(0),'Name','uvmat');%find the current uvmat interface handle
190parent_button=findobj(huvmat,'Tag','grid');
191if ~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
199end
200
201%-----------------------------------------------------------------------
202% --- Executes on button press in plot: PLOT the defined object and its projected field
203function plot_Callback(hObject, eventdata, handles)
204grid_pix_A=get_grid(handles);
205huvmat=uvmat(get(handles.image_1,'String'));
206hhuvmat=guidata(huvmat);
207set(hhuvmat.transform_fct,'Value',1)
208uvmat('run0_Callback',hObject,eventdata,hhuvmat); %file input with xml reading  in uvmat
209axes(hhuvmat.axes3);
210hold on
211plot(grid_pix_A(:,1),grid_pix_A(:,2),'.')
212
213% --- Executes on button press in plot_2.
214function plot_2_Callback(hObject, eventdata, handles)
215[grid_pix_A,grid_pix_B]=get_grid(handles);
216huvmat=uvmat(get(handles.image_2,'String'));
217hhuvmat=guidata(huvmat);
218set(hhuvmat.transform_fct,'Value',1)
219uvmat('run0_Callback',hObject,eventdata,hhuvmat); %file input with xml reading  in uvmat
220axes(hhuvmat.axes3);
221hold on
222plot(grid_pix_B(:,1),grid_pix_B(:,2),'.')
223
224
225
226% --- Executes on button press in MenuCoord.
227function MenuCoord_Callback(hObject, eventdata, handles)
228
229
230%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
231% --- Executes on button press in delete.
232function delete_Callback(hObject, eventdata, handles)
233
234%SetData=get(gcbf,'UserData');%get the interface data
235%IndexObj=SetData.IndexObj;
236huvmat=findobj('Name','uvmat');%find the current uvmat interface handle
237UvData=get(huvmat,'UserData');%Data associated to the current uvmat interface
238if isfield(UvData,'CurrentObjectIndex')
239    IndexObj=UvData.CurrentObjectIndex;
240else
241    IndexObj=[];
242end
243delete_object(IndexObj);
244
245
246% ------------------------------------------------------
247function save_Callback(hObject, eventdata, handles)
248% ------------------------------------------------------
249[grid_pix_A,grid_pix_B]=get_grid(handles);
250
251 %ECRIRE FICHIERS
252nbpointsA=size(grid_pix_A);
253XA=grid_pix_A(:,1);
254YA=grid_pix_A(:,2);
255unitcolumn=32*ones(size(XA));
256Xchar=num2str(XA);
257blanc=char(unitcolumn);
258Ychar=num2str(YA);
259tete=['1 ' num2str(nbpointsA(1))];
260txt=[Xchar blanc Ychar];
261textgrid={tete;txt};
262textout=char(textgrid);
263imageA=get(handles.image_1,'String');
264[Pathsub]=name2display(imageA);
265Answer = 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');
267dlmwrite(Answer,textout,'');
268msgbox_uvmat('CONFIRMATION',[Answer ' written as ASCII text file']);
269if ~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']);
284end
285
286%-------------------------
287function [grid_pix_A,grid_pix_B]=get_grid(handles);
288%Object=read_set_object(handles);%read the set_grid interface;
289grid_pix_B=[];%default
290DX=str2num(get(handles.DX,'String'));
291DY=str2num(get(handles.DY,'String'));
292XMin=str2num(get(handles.XMin,'String'));
293XMax=str2num(get(handles.XMax,'String'));
294YMin=str2num(get(handles.YMin,'String'));
295YMax=str2num(get(handles.YMax,'String'));
296array_realx=[XMin:DX:XMax];
297array_realy=[YMin:DY:YMax];
298nx_patch=length(array_realx);
299ny_patch=length(array_realy);
300[grid_realx,grid_realy]=meshgrid(array_realx,array_realy);
301grid_real(:,1)=reshape(grid_realx,nx_patch*ny_patch,1);
302grid_real(:,2)=reshape(grid_realy,nx_patch*ny_patch,1);
303grid_real(:,3)=zeros(nx_patch*ny_patch,1);
304 
305imageA=get(handles.image_1,'String');
306imageB=get(handles.image_2,'String');
307testB=1;
308if 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
315end
316if isempty(imageB) || isequal(imageB,'') || isequal(imageA,imageB)
317    testB=0;
318end
319
320testexist=exist(imageA,'file');
321if isequal(testexist,0)
322    msgbox_uvmat('ERROR',['input image file' imageA 'does not exist'])
323    return
324end
325[Pathsub,RootFile,field_count,str2,str_a,str_b,ext,nom_type,subdir]=name2display(imageA);
326form=imformats(ext(2:end));
327if 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
330end
331fileAxml=[fullfile(Pathsub,RootFile) '.xml'];
332[XmlDataA,error]=imadoc2struct(fileAxml);
333if isfield(XmlDataA,'GeometryCalib')
334     tsaiA=XmlDataA.GeometryCalib;
335 else
336     msgbox_uvmat('WARNING','no geometric calibration available for image A')
337     tsaiA=[];
338end
339MenuCoord=get(handles.MenuCoord,'String');
340val=get(handles.MenuCoord,'Value');
341if isempty(tsaiA)||strcmp(MenuCoord{val},'px')
342    grid_imaA(:,1)=grid_real(:,1);
343    grid_imaA(:,2)=grid_real(:,2);
344else
345    [grid_imaA(:,1),grid_imaA(:,2)]=px_XYZ(tsaiA,grid_real(:,1),grid_real(:,2),0);
346end
347    A=imread(imageA);
348   siz=size(A);
349   npxA=siz(2);
350   npyA=siz(1);
351
352flagA=grid_imaA(:,1)>0 & grid_imaA(:,1)<npxA & grid_imaA(:,2)>0 & grid_imaA(:,2)<npyA;
353
354if 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;
384end
385if testB
386    ind_good=find(flagA==1&flagB==1);
387    XimaB=grid_imaB(ind_good,1);
388    YimaB=grid_imaB(ind_good,2);
389else
390    ind_good=find(flagA==1);
391end
392XimaA=grid_imaA(ind_good,1);
393YimaA=grid_imaA(ind_good,2);
394
395grid_real_x=grid_real(ind_good,1);
396grid_real_y=grid_real(ind_good,2);
397nx_patch_new=length(grid_real_x);
398grid_real2(:,1)=grid_real_x;
399grid_real2(:,2)=grid_real_y;
400grid_real2(:,3)=zeros(nx_patch_new,1);
401if isempty(tsaiA)||strcmp(MenuCoord{val},'px')
402    grid_pix_A(:,1)=grid_real2(:,1);
403   grid_pix_A(:,2)= grid_real2(:,2);
404else
405    [grid_pix_A(:,1),grid_pix_A(:,2)]=px_XYZ(tsaiA,grid_real2(:,1),grid_real2(:,2));
406end
407if testB
408    [grid_pix_B(:,1),grid_pix_B(:,2)]=px_XYZ(tsaiB,grid_real2(:,1),grid_real2(:,2));
409end
410
411
412
413%------------------------------------------------------------------------
414% --- Executes on button press in HELP.
415function HELP_Callback(hObject, eventdata, handles)
416%------------------------------------------------------------------------
417path_to_uvmat=which ('uvmat');% check the path of uvmat
418pathelp=fileparts(path_to_uvmat);
419helpfile=fullfile(pathelp,'uvmat_doc','uvmat_doc.html');
420if isempty(dir(helpfile)), errordlg('Please put the help file uvmat_doc.html in the directory UVMAT/UVMAT_DOC')
421else
422web([helpfile '#set_grid'])   
423end
424
425
426
Note: See TracBrowser for help on using the repository browser.