source: trunk/src/set_grid.m @ 324

Last change on this file since 324 was 315, checked in by sommeria, 12 years ago

many corrections, use of the new GUI civ with mask, grid and the new matlab civ1 and fix
pivlab now included in civ_matlab which contains all matlab subfunctions for civ.

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