1 | %'geometry_calib': performs geometric calibration from a set of reference points |
---|
2 | % |
---|
3 | % function varargout = geometry_calib(varargin) |
---|
4 | % |
---|
5 | %A%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA |
---|
6 | % Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org. |
---|
7 | %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA |
---|
8 | % This file is part of the toolbox UVMAT. |
---|
9 | % |
---|
10 | % UVMAT is free software; you can redistribute it and/or modify |
---|
11 | % it under the terms of the GNU General Public License as published by |
---|
12 | % the Free Software Foundation; either version 2 of the License, or |
---|
13 | % (at your option) any later version. |
---|
14 | % |
---|
15 | % UVMAT is distributed in the hope that it will be useful, |
---|
16 | % but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
17 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
18 | % GNU General Public License (file UVMAT/COPYING.txt) for more details. |
---|
19 | %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA |
---|
20 | |
---|
21 | function varargout = geometry_calib(varargin) |
---|
22 | % GEOMETRY_CALIB M-file for geometry_calib.fig |
---|
23 | % GEOMETRY_CALIB, by itself, creates a MenuCoord GEOMETRY_CALIB or raises the existing |
---|
24 | % singleton*. |
---|
25 | % |
---|
26 | % H = GEOMETRY_CALIB returns the handle to a MenuCoord GEOMETRY_CALIB or the handle to |
---|
27 | % the existing singleton*. |
---|
28 | % |
---|
29 | % GEOMETRY_CALIB('CALLBACK',hObject,eventData,handles,...) calls the local |
---|
30 | % function named CALLBACK in GEOMETRY_CALIB.M with the given input arguments. |
---|
31 | % |
---|
32 | % GEOMETRY_CALIB('Property','Value',...) creates a MenuCoord GEOMETRY_CALIB or raises the |
---|
33 | % existing singleton*. Starting from the left, property value pairs are |
---|
34 | % applied to the GUI before geometry_calib_OpeningFunction gets called. An |
---|
35 | % unrecognized property name or invalid value makes property application |
---|
36 | % stop. All inputs are passed to geometry_calib_OpeningFcn via varargin. |
---|
37 | % |
---|
38 | % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one |
---|
39 | % instance to run (singleton)". |
---|
40 | % |
---|
41 | % See also: GUIDE, GUIDATA, GUIHANDLES |
---|
42 | |
---|
43 | % Edit the above text to modify the response to help geometry_calib |
---|
44 | |
---|
45 | % Last Modified by GUIDE v2.5 05-Jan-2010 23:22:04 |
---|
46 | |
---|
47 | % Begin initialization code - DO NOT edit |
---|
48 | gui_Singleton = 1; |
---|
49 | gui_State = struct('gui_Name', mfilename, ... |
---|
50 | 'gui_Singleton', gui_Singleton, ... |
---|
51 | 'gui_OpeningFcn', @geometry_calib_OpeningFcn, ... |
---|
52 | 'gui_OutputFcn', @geometry_calib_OutputFcn, ... |
---|
53 | 'gui_LayoutFcn', [] , ... |
---|
54 | 'gui_Callback', []); |
---|
55 | if nargin & isstr(varargin{1}) |
---|
56 | gui_State.gui_Callback = str2func(varargin{1}); |
---|
57 | end |
---|
58 | |
---|
59 | if nargout |
---|
60 | [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); |
---|
61 | else |
---|
62 | gui_mainfcn(gui_State, varargin{:}); |
---|
63 | end |
---|
64 | % End initialization code - DO NOT edit |
---|
65 | |
---|
66 | |
---|
67 | % --- Executes just before geometry_calib is made visible. |
---|
68 | %INPUT: |
---|
69 | %handles: handles of the geometry_calib interface elements |
---|
70 | % PlotHandles: set of handles of the elements contolling the plotting |
---|
71 | % parameters on the uvmat interface (obtained by 'get_plot_handle.m') |
---|
72 | function geometry_calib_OpeningFcn(hObject, eventdata, handles, handles_uvmat,pos,inputfile) |
---|
73 | |
---|
74 | % Choose default command line output for geometry_calib |
---|
75 | handles.output = hObject; |
---|
76 | |
---|
77 | % Update handles structure |
---|
78 | guidata(hObject, handles); |
---|
79 | movegui(hObject,'east');% position the GUI ton the right of the screen |
---|
80 | if exist('handles_uvmat','var') %& isfield(data,'ParentButton') |
---|
81 | set(hObject,'DeleteFcn',{@closefcn,handles_uvmat})% |
---|
82 | end |
---|
83 | %set the position of the interface |
---|
84 | if exist('pos','var')& length(pos)>2 |
---|
85 | pos_gui=get(hObject,'Position'); |
---|
86 | pos_gui(1)=pos(1); |
---|
87 | pos_gui(2)=pos(2); |
---|
88 | set(hObject,'Position',pos_gui); |
---|
89 | end |
---|
90 | inputxml=''; |
---|
91 | if exist('inputfile','var')& ~isempty(inputfile) |
---|
92 | [Path,Name,ext]=fileparts(inputfile); |
---|
93 | form=imformats(ext([2:end])); |
---|
94 | if ~isempty(form)% if the input file is an image |
---|
95 | struct.XmlInputfile=inputfile; |
---|
96 | set(hObject,'UserData',struct) |
---|
97 | [Pathsub,RootFile,field_count,str2,str_a,str_b,ext,nom_type,subdir]=name2display(inputfile); |
---|
98 | inputxml=[fullfile(Pathsub,RootFile) '.xml']; |
---|
99 | end |
---|
100 | end |
---|
101 | set(handles.ListCoord,'String',{''}) |
---|
102 | if exist(inputxml,'file') |
---|
103 | loadfile(handles,inputxml)% load the point coordiantes existing in the xml file |
---|
104 | end |
---|
105 | |
---|
106 | set(handles.ListCoord,'KeyPressFcn',{@key_press_fcn,handles})%set keyboard action function |
---|
107 | %set(hObject,'KeyPressFcn',{'keyboard_callback',handles})%set keyboard action function on uvmat interface when geometry_calib is on top |
---|
108 | %htable=uitable(10,5) |
---|
109 | %set(htable,'ColumnNames',{'x','y','z','X(pixels)','Y(pixels)'}) |
---|
110 | |
---|
111 | % --- Outputs from this function are returned to the command line. |
---|
112 | function varargout = geometry_calib_OutputFcn(hObject, eventdata, handles) |
---|
113 | % varargout cell array for returning output args (see VARARGOUT); |
---|
114 | % hObject handle to figure |
---|
115 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
116 | % handles structure with handles and user data (see GUIDATA) |
---|
117 | |
---|
118 | % Get default command line output from handles structure |
---|
119 | varargout{1} = handles.output; |
---|
120 | varargout{2}=handles; |
---|
121 | |
---|
122 | %------------ |
---|
123 | function Phi_Callback(hObject, eventdata, handles) |
---|
124 | |
---|
125 | |
---|
126 | |
---|
127 | |
---|
128 | %-------------------------------------------------- |
---|
129 | %read input xml file and update the edit boxes |
---|
130 | function loadfile(handles,fileinput) |
---|
131 | |
---|
132 | %read the input xml file |
---|
133 | t=xmltree(fileinput); |
---|
134 | s=convert(t);%convert to matlab structure |
---|
135 | %read data currently displayed on the interface |
---|
136 | PointCoord=[]; |
---|
137 | Coord_cell=get(handles.ListCoord,'String'); |
---|
138 | data=read_geometry_calib(Coord_cell); |
---|
139 | %data=read_geometry_calib(handles); |
---|
140 | Coord=[]; %default |
---|
141 | if isfield(data,'Coord') |
---|
142 | Coord=data.Coord; |
---|
143 | end |
---|
144 | TabChar_0=get(handles.ListCoord,'String'); |
---|
145 | nbcoord_0=size(TabChar_0,1); |
---|
146 | if isequal(get(handles.edit_append,'Value'),2) %edit mode A REVOIR |
---|
147 | val=get(handles.ListCoord,'Value')-1; |
---|
148 | else |
---|
149 | val=length(TabChar_0); |
---|
150 | end |
---|
151 | nbcoord=0; |
---|
152 | |
---|
153 | %case of calibration (ImaDoc) input file |
---|
154 | hcalib=get(handles.calib_type,'parent'); |
---|
155 | CalibData=get(hcalib,'UserData'); |
---|
156 | CalibData.XmlInput=fileinput; |
---|
157 | if isfield(s,'Heading') |
---|
158 | CalibData.Heading=s.Heading; |
---|
159 | end |
---|
160 | |
---|
161 | set(hcalib,'UserData',CalibData);%store the heading in the interface 'UserData' |
---|
162 | if isfield(s,'GeometryCalib') |
---|
163 | Calib=s.GeometryCalib; |
---|
164 | if isfield(Calib,'CalibrationType') |
---|
165 | CalibrationType=Calib.CalibrationType; |
---|
166 | switch CalibrationType |
---|
167 | case 'linear' |
---|
168 | set(handles.calib_type,'Value',2) |
---|
169 | case 'tsai' |
---|
170 | set(handles.calib_type,'Value',3) |
---|
171 | end |
---|
172 | end |
---|
173 | if isfield(Calib,'SourceCalib') |
---|
174 | if isfield(Calib.SourceCalib,'PointCoord') |
---|
175 | PointCoord=Calib.SourceCalib.PointCoord; |
---|
176 | end |
---|
177 | end |
---|
178 | nbcoord=length(PointCoord); |
---|
179 | if ~isfield(Calib,'ErrorRms')&~isfield(Calib,'ErrorMax') %old convention of Gauthier (cord in mm) |
---|
180 | for i=1:length(PointCoord) |
---|
181 | line=str2num(PointCoord{i}); |
---|
182 | Coord(i+val,4:5)=line(4:5);%px x |
---|
183 | Coord(i+val,1:3)=line(1:3)/10;%phys x |
---|
184 | end |
---|
185 | else |
---|
186 | for i=1:length(PointCoord) |
---|
187 | line=str2num(PointCoord{i}); |
---|
188 | Coord(i,4:5)=line(4:5);%px x |
---|
189 | Coord(i,1:3)=line(1:3);%phys x |
---|
190 | end |
---|
191 | end |
---|
192 | end |
---|
193 | %case of xml files of points |
---|
194 | if isfield(s,'Coord') |
---|
195 | PointCoord=s.Coord; |
---|
196 | nbcoord=length(PointCoord); |
---|
197 | %case of image coordinates |
---|
198 | if isfield(s,'CoordType')& isequal(s.CoordType,'px') |
---|
199 | for i=1:nbcoord |
---|
200 | line=str2num(PointCoord{i}); |
---|
201 | Coord(i+val,4:5)=line(1:2); |
---|
202 | end |
---|
203 | %case of physical coordinates |
---|
204 | else |
---|
205 | for i=1:nbcoord |
---|
206 | line=str2num(PointCoord{i}); |
---|
207 | Coord(i+val,1:3)=line(1:3); |
---|
208 | nbcolumn=size(Coord,2); |
---|
209 | if nbcolumn<5 |
---|
210 | Coord(i+val,nbcolumn+1:5)=zeros(1,5-nbcolumn); |
---|
211 | end |
---|
212 | end |
---|
213 | end |
---|
214 | end |
---|
215 | CoordCell={}; |
---|
216 | for iline=1:size(Coord,1) |
---|
217 | for j=1:5 |
---|
218 | CoordCell{iline,j}=num2str(Coord(iline,j),4); |
---|
219 | end |
---|
220 | end |
---|
221 | Tabchar=cell2tab(CoordCell,' | ');%transform cells into table ready for display |
---|
222 | set(handles.ListCoord,'Value',1) |
---|
223 | set(handles.ListCoord,'String',Tabchar) |
---|
224 | |
---|
225 | |
---|
226 | %---------------------------------------------------- |
---|
227 | % executed when closing: set the parent interface button to value 0 |
---|
228 | function closefcn(gcbo,eventdata,handles_uvmat) |
---|
229 | huvmat=findobj(allchild(0),'Name','uvmat'); |
---|
230 | if exist('handles_uvmat','var') |
---|
231 | set(handles_uvmat.cal,'Value',0) |
---|
232 | uvmat('cal_Callback',huvmat,[],handles_uvmat); |
---|
233 | % set(parent_button,'Value',0)%put unactivated buttons to green |
---|
234 | % set(parent_button,'BackgroundColor',[0 1 0]); |
---|
235 | end |
---|
236 | |
---|
237 | |
---|
238 | % % --- Executes on button press in MenuCoord. |
---|
239 | % function MenuCoord_Callback(hObject, eventdata, handles) |
---|
240 | |
---|
241 | % |
---|
242 | % % --- Executes on button press in delete. |
---|
243 | % function delete_Callback(hObject, eventdata, handles) |
---|
244 | % SetData=get(gcbf,'UserData');%get the interface data |
---|
245 | % IndexObj=SetData.IndexObj; |
---|
246 | % delete_object(IndexObj); |
---|
247 | |
---|
248 | |
---|
249 | %------------------------------------------------------------------ |
---|
250 | % --- Executes on button press in calibrate_lin. |
---|
251 | function APPLY_Callback(hObject, eventdata, handles) |
---|
252 | %------------------------------------------------------------------ |
---|
253 | calib_cell=get(handles.calib_type,'String'); |
---|
254 | val=get(handles.calib_type,'Value'); |
---|
255 | calib_type=calib_cell{val}; |
---|
256 | Coord_cell=get(handles.ListCoord,'String'); |
---|
257 | Object=read_geometry_calib(Coord_cell); |
---|
258 | |
---|
259 | if isequal(calib_type,'rescale') |
---|
260 | GeometryCalib=calib_rescale(Object.Coord); |
---|
261 | elseif isequal(calib_type,'linear') |
---|
262 | GeometryCalib=calib_linear(Object.Coord); |
---|
263 | elseif isequal(calib_type,'tsai') |
---|
264 | GeometryCalib=calib_tsai(Object.Coord); |
---|
265 | end |
---|
266 | unitlist=get(handles.CoordUnit,'String'); |
---|
267 | unit=unitlist{get(handles.CoordUnit,'value')}; |
---|
268 | GeometryCalib.CoordUnit=unit; |
---|
269 | |
---|
270 | huvmat=findobj(allchild(0),'Name','uvmat'); |
---|
271 | hhuvmat=guidata(huvmat);%handles of elements in the GUI uvmat |
---|
272 | RootPath=''; |
---|
273 | RootFile=''; |
---|
274 | if ~isempty(hhuvmat.RootPath)& ~isempty(hhuvmat.RootFile) |
---|
275 | testhandle=1; |
---|
276 | RootPath=get(hhuvmat.RootPath,'String'); |
---|
277 | RootFile=get(hhuvmat.RootFile,'String'); |
---|
278 | filebase=fullfile(RootPath,RootFile); |
---|
279 | outputfile=[filebase '.xml']; |
---|
280 | else |
---|
281 | question={'save the calibration data and point coordinates in'}; |
---|
282 | def={fullfile(RootPath,['ObjectCalib.xml'])}; |
---|
283 | options.Resize='on'; |
---|
284 | answer=inputdlg(question,'save average in a new file',1,def,options); |
---|
285 | outputfile=answer{1}; |
---|
286 | end |
---|
287 | testappend=0; |
---|
288 | if exist(outputfile,'file');%=1 if the output file already exists, 0 else |
---|
289 | t=xmltree(outputfile); %read the file |
---|
290 | backupfile=outputfile; |
---|
291 | testexist=2; |
---|
292 | while testexist==2 |
---|
293 | backupfile=[backupfile '~'];% make a backup name by adding ~ to the xml file name |
---|
294 | testexist=exist(backupfile,'file'); |
---|
295 | end |
---|
296 | [success,message]=copyfile(outputfile,backupfile);%make backup |
---|
297 | t=xmltree(outputfile); %read the file |
---|
298 | uid=find(t,'ImaDoc'); |
---|
299 | if ~isequal(uid,1)%if the xml file is not ImaDoc, delete it (after backup) |
---|
300 | if isequal(success,1) |
---|
301 | delete(outputfile) |
---|
302 | else |
---|
303 | msgbox_uvmat('ERROR',['error in the backup of the existing xml file: ' message]) |
---|
304 | return |
---|
305 | end |
---|
306 | else |
---|
307 | uid_calib=find(t,'ImaDoc/GeometryCalib'); |
---|
308 | testappend=1; |
---|
309 | if isempty(uid_calib) |
---|
310 | [t,uid_calib]=add(t,1,'element','GeometryCalib'); |
---|
311 | else %if GeometryCalib already exists, delete its content |
---|
312 | uid_child=children(t,uid_calib); |
---|
313 | t=delete(t,uid_child); |
---|
314 | % testappend=1; |
---|
315 | end |
---|
316 | end |
---|
317 | end |
---|
318 | if ~testappend %create a new xml file for calibration data |
---|
319 | t=xmltree; |
---|
320 | t=set(t,1,'name','ImaDoc'); |
---|
321 | [t,uid_calib]=add(t,1,'element','GeometryCalib'); |
---|
322 | end |
---|
323 | % hgrid=get(handles.REPLICATE,'parent');%read the calibration image source on the interface userdata |
---|
324 | % imagename=get(hgrid,'UserData'); |
---|
325 | % if exist(imagename,'file') |
---|
326 | % GeometryCalib.SourceCalib.ImageCalib=imagename; |
---|
327 | % end |
---|
328 | GeometryCalib.SourceCalib.PointCoord=Object.Coord; |
---|
329 | t=struct2xml(GeometryCalib,t,uid_calib); |
---|
330 | save(t,outputfile); |
---|
331 | msgbox_uvmat('CONFIRMATION',{[outputfile ' updated with calibration data'];... |
---|
332 | ['Error rms (along x,y)=' num2str(GeometryCalib.ErrorRms) ' pixels'];... |
---|
333 | ['Error max (along x,y)=' num2str(GeometryCalib.ErrorMax) ' pixels']}) |
---|
334 | |
---|
335 | %display image with new calibration in the currently opened uvmat interface |
---|
336 | hhh=findobj(hhuvmat.axes3,'Tag','calib_marker');% delete calib points and markers |
---|
337 | if ~isempty(hhh) |
---|
338 | delete(hhh); |
---|
339 | end |
---|
340 | hhh=findobj(hhuvmat.axes3,'Tag','calib_points'); |
---|
341 | if ~isempty(hhh) |
---|
342 | delete(hhh); |
---|
343 | end |
---|
344 | set(hhuvmat.FixedLimits,'Value',0)% put FixedLimits option to 'off' |
---|
345 | set(hhuvmat.FixedLimits,'BackgroundColor',[0.7 0.7 0.7]) |
---|
346 | uvmat('RootPath_Callback',hObject,eventdata,hhuvmat); %file input with xml reading in uvmat |
---|
347 | |
---|
348 | %------------------------------------------------------------------ |
---|
349 | % --- Executes on button press in calibrate_lin. |
---|
350 | function REPLICATE_Callback(hObject, eventdata, handles) |
---|
351 | %------------------------------------------------------------------ |
---|
352 | calib_cell=get(handles.calib_type,'String'); |
---|
353 | val=get(handles.calib_type,'Value'); |
---|
354 | calib_type=calib_cell{val}; |
---|
355 | Coord_cell=get(handles.ListCoord,'String'); |
---|
356 | Object=read_geometry_calib(Coord_cell); |
---|
357 | |
---|
358 | if isequal(calib_type,'rescale') |
---|
359 | GeometryCalib=calib_rescale(Object.Coord); |
---|
360 | elseif isequal(calib_type,'linear') |
---|
361 | GeometryCalib=calib_linear(Object.Coord); |
---|
362 | elseif isequal(calib_type,'tsai') |
---|
363 | GeometryCalib=calib_tsai(Object.Coord); |
---|
364 | end |
---|
365 | % %record image source |
---|
366 | % hgrid=get(handles.REPLICATE,'parent');%read the calibration image source on the interface userdata |
---|
367 | % imagename=get(hgrid,'UserData'); |
---|
368 | % if exist(imagename,'file') |
---|
369 | % GeometryCalib.SourceCalib.ImageCalib=imagename; |
---|
370 | % end |
---|
371 | GeometryCalib.SourceCalib.PointCoord=Object.Coord; |
---|
372 | |
---|
373 | |
---|
374 | %root PROJETS |
---|
375 | |
---|
376 | %open and read the dataview GUI |
---|
377 | h_dataview=findobj(allchild(0),'name','dataview'); |
---|
378 | if ~isempty(h_dataview) |
---|
379 | delete(h_dataview) |
---|
380 | end |
---|
381 | CalibData=get(handles.figure1,'UserData');%read the calibration image source on the interface userdata |
---|
382 | % filename='PROJETS';%default |
---|
383 | % if isfield(CalibData,'XmlInput') |
---|
384 | % [pp,filename]=fileparts(CalibData.XmlInput); |
---|
385 | % end |
---|
386 | % while ~isequal(filename,'PROJETS') && numel(filename)>1 |
---|
387 | % filename_1=filename; |
---|
388 | % pp_1=pp; |
---|
389 | % [pp,filename]=fileparts(pp) |
---|
390 | % end |
---|
391 | % projinput=fullfile(pp_1,filename_1) |
---|
392 | % dd=dataview(projinput) |
---|
393 | |
---|
394 | % |
---|
395 | % Device=[];%default |
---|
396 | % |
---|
397 | % h_dataview=dataview; |
---|
398 | % hhdataview=guidata(h_dataview); |
---|
399 | % drawnow |
---|
400 | |
---|
401 | if isfield(CalibData,'XmlInput') |
---|
402 | XmlInput=fileparts(CalibData.XmlInput); |
---|
403 | [XmlInput,filename,ext]=fileparts(XmlInput); |
---|
404 | end |
---|
405 | SubCampaignTest='n'; %default |
---|
406 | testinput=0; |
---|
407 | if isfield(CalibData,'Heading') |
---|
408 | Heading=CalibData.Heading; |
---|
409 | if isfield(Heading,'Record') && isequal([filename ext],Heading.Record) |
---|
410 | [XmlInput,filename,ext]=fileparts(XmlInput); |
---|
411 | end |
---|
412 | if isfield(Heading,'Device') && isequal([filename ext],Heading.Device) |
---|
413 | [XmlInput,filename,ext]=fileparts(XmlInput); |
---|
414 | Device=Heading.Device; |
---|
415 | end |
---|
416 | if isfield(Heading,'Experiment') && isequal([filename ext],Heading.Experiment) |
---|
417 | [PP,filename,ext]=fileparts(XmlInput); |
---|
418 | end |
---|
419 | testinput=0; |
---|
420 | if isfield(Heading,'SubCampaign') && isequal([filename ext],Heading.SubCampaign) |
---|
421 | % set(hhdataview.RootDirectory,'String',XmlInput) |
---|
422 | % set(hhdataview.SubCampaignTest,'Value',1) |
---|
423 | SubCampaignTest='y'; |
---|
424 | testinput=1; |
---|
425 | elseif isfield(Heading,'Campaign') && isequal([filename ext],Heading.Campaign) |
---|
426 | % set(hhdataview.RootDirectory,'String',XmlInput) |
---|
427 | % set(hhdataview.SubCampaignTest,'Value',0) |
---|
428 | testinput=1; |
---|
429 | end |
---|
430 | end |
---|
431 | if ~testinput |
---|
432 | filename='PROJETS';%default |
---|
433 | if isfield(CalibData,'XmlInput') |
---|
434 | [pp,filename]=fileparts(CalibData.XmlInput); |
---|
435 | end |
---|
436 | while ~isequal(filename,'PROJETS') && numel(filename)>1 |
---|
437 | filename_1=filename; |
---|
438 | pp_1=pp; |
---|
439 | [pp,filename]=fileparts(pp); |
---|
440 | end |
---|
441 | XmlInput=fullfile(pp_1,filename_1); |
---|
442 | testinput=1; |
---|
443 | end |
---|
444 | if testinput |
---|
445 | outcome=dataview(XmlInput,SubCampaignTest,GeometryCalib)%,SubCampaignTest) |
---|
446 | end |
---|
447 | % %A COMPLETER |
---|
448 | % dataview('RootDirectory_Callback',hObject,eventdata,hhdataview) |
---|
449 | % ListDevices=get(hhdataview.ListDevices,'String'); |
---|
450 | % for ilist=1:length(ListDevices) |
---|
451 | % if isequal(ListDevices{ilist},Device) |
---|
452 | % set(hhdataview.ListDevices,'Value',ilist) |
---|
453 | % dataview('ListDevices_Callback',hObject,eventdata,hhdataview) |
---|
454 | % break |
---|
455 | % end |
---|
456 | % end |
---|
457 | |
---|
458 | % % hhdataview=guidata(h_dataview); |
---|
459 | % CurrentPath=get(hhdataview.RootDirectory,'String'); |
---|
460 | % ListExperiments=get(hhdataview.ListExperiments,'String'); |
---|
461 | % Value=get(hhdataview.ListExperiments,'Value'); |
---|
462 | % if ~isequal(Value,1) |
---|
463 | % ListExperiments=ListExperiments(Value); |
---|
464 | % end |
---|
465 | % ListDevices=get(hhdataview.ListDevices,'String'); |
---|
466 | % Value=get(hhdataview.ListDevices,'Value'); |
---|
467 | % if isequal(Value,1) |
---|
468 | % msgbox_uvmat('ERROR','manually select in the GUI dataview the device being calibrated') |
---|
469 | % return |
---|
470 | % else |
---|
471 | % ListDevices=ListDevices(Value); |
---|
472 | % end |
---|
473 | % ListRecords=get(hhdataview.ListRecords,'String'); |
---|
474 | % Value=get(hhdataview.ListRecords,'Value'); |
---|
475 | % if ~isequal(Value,1) |
---|
476 | % ListRecords=ListRecords(Value); |
---|
477 | % end |
---|
478 | % [ListDevices,ListRecords,ListXml,List]=ListDir(CurrentPath,ListExperiments,ListDevices,ListRecords); |
---|
479 | % ListXml=get(hhdataview.ListXml,'String'); |
---|
480 | % Value=get(hhdataview.ListXml,'Value'); |
---|
481 | % if isequal(Value,1) |
---|
482 | % msgbox_uvmat('ERROR','you need to select in the GUI dataview the xml files to edit') |
---|
483 | % return |
---|
484 | % else |
---|
485 | % ListXml=ListXml(Value); |
---|
486 | % end |
---|
487 | % |
---|
488 | % %update all the selected xml files |
---|
489 | % answer=msgbox_uvmat('INPUT_Y-N',[num2str(length(Value)) ' xml files for device ' ListDevices{1} ' will be refreshed with ' calib_type ' calibration data']) |
---|
490 | % if ~isequal(answer,'Yes') |
---|
491 | % return |
---|
492 | % end |
---|
493 | % 'TESTcalib' |
---|
494 | % List=DataFiles.List |
---|
495 | % for iexp=1:length(List.Experiment) |
---|
496 | % ExpName=List.Experiment{iexp}.name; |
---|
497 | % if isfield(List.Experiment{iexp},'Device') |
---|
498 | % for idevice=1:length(List.Experiment{iexp}.Device) |
---|
499 | % DeviceName=List.Experiment{iexp}.Device{idevice}.name; |
---|
500 | % if isfield(List.Experiment{iexp}.Device{idevice},'xmlfile') |
---|
501 | % for ixml=1:length(List.Experiment{iexp}.Device{idevice}.xmlfile) |
---|
502 | % FileName=List.Experiment{iexp}.Device{idevice}.xmlfile{ixml}; |
---|
503 | % for ilistxml=1:length(ListXml) |
---|
504 | % if isequal(FileName,ListXml{ilistxml}) |
---|
505 | % set(hhdataview.ListXml,'Value',Value(ilistxml)) |
---|
506 | % drawnow |
---|
507 | % xmlfullname=fullfile(CurrentPath,ExpName,DeviceName,FileName); |
---|
508 | % update_imadoc(GeometryCalib,xmlfullname) |
---|
509 | % break |
---|
510 | % end |
---|
511 | % end |
---|
512 | % end |
---|
513 | % elseif isfield(List.Experiment{iexp}.Device{idevice},'Record') |
---|
514 | % for irecord=1:length(List.Experiment{iexp}.Device{idevice}.Record) |
---|
515 | % RecordName=List.Experiment{iexp}.Device{idevice}.Record{irecord}.name; |
---|
516 | % if isfield(List.Experiment{iexp}.Device{idevice}.Record{irecord},'xmlfile') |
---|
517 | % for ixml=1:length(List.Experiment{iexp}.Device{idevice}.Record{irecord}.xmlfile) |
---|
518 | % FileName=List.Experiment{iexp}.Device{idevice}.Record{irecord}.xmlfile{ixml}; |
---|
519 | % for ilistxml=1:length(ListXml) |
---|
520 | % if isequal(FileName,ListXml{ilistxml}) |
---|
521 | % set(hhdataview.ListXml,'Value',Value(ilistxml)) |
---|
522 | % drawnow |
---|
523 | % xmlfullname=fullfile(CurrentPath,ExpName,DeviceName,RecordName,FileName); |
---|
524 | % update_imadoc(GeometryCalib,xmlfullname) |
---|
525 | % break |
---|
526 | % end |
---|
527 | % end |
---|
528 | % end |
---|
529 | % end |
---|
530 | % end |
---|
531 | % end |
---|
532 | % end |
---|
533 | % end |
---|
534 | % end |
---|
535 | % set(hhdataview.ListXml,'Value',Value) |
---|
536 | |
---|
537 | |
---|
538 | %----------------------------------------------------------------- |
---|
539 | % determine the parameters for a calibration by an affine function (rescaling and offset, no rotation) |
---|
540 | function GeometryCalib=calib_rescale(Coord) |
---|
541 | %------------------------------------------------------------------ |
---|
542 | |
---|
543 | X=Coord(:,1); |
---|
544 | Y=Coord(:,2); |
---|
545 | x_ima=Coord(:,4); |
---|
546 | y_ima=Coord(:,5); |
---|
547 | [px,sx]=polyfit(X,x_ima,1); |
---|
548 | [py,sy]=polyfit(Y,y_ima,1); |
---|
549 | T_x=px(2); |
---|
550 | T_y=py(2); |
---|
551 | GeometryCalib.CalibrationType='rescale'; |
---|
552 | GeometryCalib.focal=1; |
---|
553 | GeometryCalib.CoordUnit=[];% default value, to be updated by the calling function |
---|
554 | GeometryCalib.Tx_Ty_Tz=[T_x T_y 1]; |
---|
555 | GeometryCalib.R=[px(1),0,0;0,py(1),0;0,0,1]; |
---|
556 | |
---|
557 | %check error |
---|
558 | Calib.dpx=1; |
---|
559 | Calib.dpy=1; |
---|
560 | Calib.sx=1; |
---|
561 | Calib.Cx=0; |
---|
562 | Calib.Cy=0; |
---|
563 | Calib.Tz=1; |
---|
564 | Calib.kappa1=0; |
---|
565 | Calib.f=GeometryCalib.focal; |
---|
566 | Calib.Tx=T_x; |
---|
567 | Calib.Ty=T_y; |
---|
568 | Calib.R=GeometryCalib.R; |
---|
569 | [Xpoints,Ypoints]=px_XYZ(Calib,X,Y,0); |
---|
570 | GeometryCalib.ErrorRms(1)=sqrt(mean((Xpoints-x_ima).*(Xpoints-x_ima))); |
---|
571 | GeometryCalib.ErrorMax(1)=max(abs(Xpoints-x_ima)); |
---|
572 | GeometryCalib.ErrorRms(2)=sqrt(mean((Ypoints-y_ima).*(Ypoints-y_ima))); |
---|
573 | GeometryCalib.ErrorMax(2)=max(abs(Ypoints-y_ima)); |
---|
574 | |
---|
575 | |
---|
576 | %------------------------------------------------------------------ |
---|
577 | % determine the parameters for a calibration by a linear transform matrix (rescale and rotation) |
---|
578 | function GeometryCalib=calib_linear(Coord) |
---|
579 | %------------------------------------------------------------------ |
---|
580 | X=Coord(:,1); |
---|
581 | Y=Coord(:,2); |
---|
582 | x_ima=Coord(:,4); |
---|
583 | y_ima=Coord(:,5); |
---|
584 | XY_mat=[ones(size(X)) X Y]; |
---|
585 | a_X1=XY_mat\x_ima; %transformation matrix for X |
---|
586 | x1=XY_mat*a_X1;%reconstruction |
---|
587 | err_X1=max(abs(x1-x_ima));%error |
---|
588 | a_Y1=XY_mat\y_ima;%transformation matrix for X |
---|
589 | y1=XY_mat*a_Y1; |
---|
590 | err_Y1=max(abs(y1-y_ima));%error |
---|
591 | T_x=a_X1(1); |
---|
592 | T_y=a_Y1(1); |
---|
593 | GeometryCalib.CalibrationType='linear'; |
---|
594 | GeometryCalib.focal=1; |
---|
595 | GeometryCalib.CoordUnit=[];% default value, to be updated by the calling function |
---|
596 | GeometryCalib.Tx_Ty_Tz=[T_x T_y 1]; |
---|
597 | GeometryCalib.R=[a_X1(2),a_X1(3),0;a_Y1(2),a_Y1(3),0;0,0,1]; |
---|
598 | |
---|
599 | %check error |
---|
600 | GeometryCalib.ErrorRms(1)=sqrt(mean((x1-x_ima).*(x1-x_ima))); |
---|
601 | GeometryCalib.ErrorMax(1)=max(abs(x1-x_ima)); |
---|
602 | GeometryCalib.ErrorRms(2)=sqrt(mean((y1-y_ima).*(y1-y_ima))); |
---|
603 | GeometryCalib.ErrorMax(2)=max(abs(y1-y_ima)); |
---|
604 | |
---|
605 | |
---|
606 | |
---|
607 | |
---|
608 | %------------------------------------------------------------------ |
---|
609 | function GeometryCalib=calib_tsai(Coord) |
---|
610 | %------------------------------------------------------------------ |
---|
611 | %TSAI |
---|
612 | % 'calibration_lin' provides a linear transform on coordinates, |
---|
613 | path_uvmat=which('uvmat');% check the path detected for source file uvmat |
---|
614 | path_UVMAT=fileparts(path_uvmat); %path to UVMAT |
---|
615 | if isunix |
---|
616 | %fid = fopen(fullfile(path_UVMAT,'PARAM_LINUX.txt'),'r');%open the file with civ binary names |
---|
617 | xmlfile=fullfile(path_UVMAT,'PARAM_LINUX.xml'); |
---|
618 | if exist(xmlfile,'file') |
---|
619 | t=xmltree(xmlfile); |
---|
620 | sparam=convert(t); |
---|
621 | end |
---|
622 | else |
---|
623 | %fid = fopen(fullfile(path_UVMAT,'PARAM_WIN.txt'),'r');%open the file with civ binary names |
---|
624 | xmlfile=fullfile(path_UVMAT,'PARAM_WIN.xml'); |
---|
625 | if exist(xmlfile,'file') |
---|
626 | t=xmltree(xmlfile); |
---|
627 | sparam=convert(t); |
---|
628 | end |
---|
629 | end |
---|
630 | if ~isfield(sparam,'GeometryCalib_exe') |
---|
631 | warndlg_uvmat(['calibration program <GeometryCalib_exe> undefined in parameter file ' xmlfile],'ERROR') |
---|
632 | return |
---|
633 | end |
---|
634 | Tsai_exe=sparam.GeometryCalib_exe; |
---|
635 | if ~exist(Tsai_exe,'file') |
---|
636 | warndlg_uvmat(['calibration program ' Tsai_exe ' does not exist'],'ERROR') |
---|
637 | return |
---|
638 | end |
---|
639 | |
---|
640 | textcoord=num2str(Coord,4); |
---|
641 | dlmwrite('t.txt',textcoord,''); |
---|
642 | % ['!' Tsai_exe ' -f1 0 -f2 t.txt'] |
---|
643 | eval(['!' Tsai_exe ' -f t.txt > tsaicalib.log']); |
---|
644 | if ~exist('calib.dat','file') |
---|
645 | warndlg_uvmat('no output from calibration program Tsai_exe: possibly too few points','ERROR') |
---|
646 | end |
---|
647 | calibdat=dlmread('calib.dat'); |
---|
648 | GeometryCalib.CalibrationType='tsai'; |
---|
649 | GeometryCalib.focal=calibdat(10); |
---|
650 | GeometryCalib.dpx_dpy=[calibdat(5) calibdat(6)]; |
---|
651 | GeometryCalib.Cx_Cy=[calibdat(7) calibdat(8)]; |
---|
652 | GeometryCalib.sx=calibdat(9); |
---|
653 | GeometryCalib.kappa1=calibdat(11); |
---|
654 | GeometryCalib.CoordUnit=[];% default value, to be updated by the calling function |
---|
655 | GeometryCalib.Tx_Ty_Tz=[calibdat(12) calibdat(13) calibdat(14)]; |
---|
656 | Rx_Ry_Rz=calibdat([15:17]); |
---|
657 | sa = sin(Rx_Ry_Rz(1)) ; |
---|
658 | ca=cos(Rx_Ry_Rz(1)); |
---|
659 | sb=sin(Rx_Ry_Rz(2)); |
---|
660 | cb =cos(Rx_Ry_Rz(2)); |
---|
661 | sg =sin(Rx_Ry_Rz(3)); |
---|
662 | cg =cos(Rx_Ry_Rz(3)); |
---|
663 | r1 = cb * cg; |
---|
664 | r2 = cg * sa * sb - ca * sg; |
---|
665 | r3 = sa * sg + ca * cg * sb; |
---|
666 | r4 = cb * sg; |
---|
667 | r5 = sa * sb * sg + ca * cg; |
---|
668 | r6 = ca * sb * sg - cg * sa; |
---|
669 | r7 = -sb; |
---|
670 | r8 = cb * sa; |
---|
671 | r9 = ca * cb; |
---|
672 | %EN DEDUIRE MATRICE R ?? |
---|
673 | GeometryCalib.R=[r1,r2,r3;r4,r5,r6;r7,r8,r9]; |
---|
674 | %erreur a caracteriser? |
---|
675 | %check error |
---|
676 | Calib.dpx=GeometryCalib.dpx_dpy(1); |
---|
677 | Calib.dpy=GeometryCalib.dpx_dpy(2); |
---|
678 | Calib.sx=GeometryCalib.sx; |
---|
679 | Calib.Cx=GeometryCalib.Cx_Cy(1); |
---|
680 | Calib.Cy=GeometryCalib.Cx_Cy(2); |
---|
681 | Calib.kappa1=GeometryCalib.kappa1; |
---|
682 | Calib.f=GeometryCalib.focal; |
---|
683 | Calib.Tx=GeometryCalib.Tx_Ty_Tz(1); |
---|
684 | Calib.Ty=GeometryCalib.Tx_Ty_Tz(2); |
---|
685 | Calib.Tz=GeometryCalib.Tx_Ty_Tz(3); |
---|
686 | Calib.R=GeometryCalib.R; |
---|
687 | X=Coord(:,1); |
---|
688 | Y=Coord(:,2); |
---|
689 | Z=Coord(:,3); |
---|
690 | x_ima=Coord(:,4); |
---|
691 | y_ima=Coord(:,5); |
---|
692 | [Xpoints,Ypoints]=px_XYZ(Calib,X,Y,Z); |
---|
693 | |
---|
694 | GeometryCalib.ErrorRms(1)=sqrt(mean((Xpoints-x_ima).*(Xpoints-x_ima))); |
---|
695 | GeometryCalib.ErrorMax(1)=max(abs(Xpoints-x_ima)); |
---|
696 | GeometryCalib.ErrorRms(2)=sqrt(mean((Ypoints-y_ima).*(Ypoints-y_ima))); |
---|
697 | GeometryCalib.ErrorMax(2)=max(abs(Ypoints-y_ima)); |
---|
698 | % Nfx |
---|
699 | % dx |
---|
700 | % dy |
---|
701 | % 5 dpx |
---|
702 | % 6 dpy |
---|
703 | % cx |
---|
704 | % cy |
---|
705 | % sx |
---|
706 | % f |
---|
707 | % kappa1 |
---|
708 | % tx |
---|
709 | % ty |
---|
710 | % tz |
---|
711 | % rx |
---|
712 | % ry |
---|
713 | % rz |
---|
714 | % p1 |
---|
715 | % p2 |
---|
716 | |
---|
717 | %calibcoeff=str2num(calibdat) |
---|
718 | |
---|
719 | |
---|
720 | |
---|
721 | % --- Executes on button press in rotation. |
---|
722 | function rotation_Callback(hObject, eventdata, handles) |
---|
723 | angle_rot=(pi/180)*str2num(get(handles.Phi,'String')); |
---|
724 | Coord_cell=get(handles.ListCoord,'String'); |
---|
725 | data=read_geometry_calib(Coord_cell); |
---|
726 | data.Coord(:,1)=cos(angle_rot)*data.Coord(:,1)+sin(angle_rot)*data.Coord(:,2); |
---|
727 | data.Coord(:,1)=-sin(angle_rot)*data.Coord(:,1)+cos(angle_rot)*data.Coord(:,2); |
---|
728 | set(handles.XObject,'String',num2str(data.Coord(:,1),4)); |
---|
729 | set(handles.YObject,'String',num2str(data.Coord(:,2),4)); |
---|
730 | |
---|
731 | |
---|
732 | function XImage_Callback(hObject, eventdata, handles) |
---|
733 | update_list(hObject, eventdata,handles) |
---|
734 | |
---|
735 | function YImage_Callback(hObject, eventdata, handles) |
---|
736 | update_list(hObject, eventdata,handles) |
---|
737 | |
---|
738 | function XObject_Callback(hObject, eventdata, handles) |
---|
739 | update_list(hObject, eventdata,handles) |
---|
740 | |
---|
741 | function YObject_Callback(hObject, eventdata, handles) |
---|
742 | update_list(hObject, eventdata,handles) |
---|
743 | |
---|
744 | function ZObject_Callback(hObject, eventdata, handles) |
---|
745 | update_list(hObject, eventdata,handles) |
---|
746 | |
---|
747 | function update_list(hObject, eventdata, handles) |
---|
748 | str4=get(handles.XImage,'String'); |
---|
749 | str5=get(handles.YImage,'String'); |
---|
750 | str1=get(handles.XObject,'String'); |
---|
751 | tt=double(str1); |
---|
752 | str2=get(handles.YObject,'String'); |
---|
753 | str3=get(handles.ZObject,'String'); |
---|
754 | if ~isempty(str1) & ~isequal(double(str1),32) & (isempty(str3)|isequal(double(str3),32)) |
---|
755 | str3='0';%put z to 0 by default |
---|
756 | end |
---|
757 | strline=[str1 ' | ' str2 ' | ' str3 ' | ' str4 ' | ' str5]; |
---|
758 | Coord=get(handles.ListCoord,'String'); |
---|
759 | val=get(handles.ListCoord,'Value'); |
---|
760 | Coord{val}=strline; |
---|
761 | set(handles.ListCoord,'String',Coord) |
---|
762 | |
---|
763 | %-------------------------------------------------------------------- |
---|
764 | % --- Executes on selection change in ListCoord. |
---|
765 | %-------------------------------------------------------------------- |
---|
766 | function ListCoord_Callback(hObject, eventdata, handles) |
---|
767 | % hObject handle to ListCoord (see GCBO) |
---|
768 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
769 | % handles structure with handles and user data (see GUIDATA) |
---|
770 | |
---|
771 | % Hints: contents = get(hObject,'String') returns ListCoord contents as cell array |
---|
772 | % contents{get(hObject,'Value')} returns selected item from ListCoord |
---|
773 | %set(handles.edit_append,'Value',2); %set to edit mode |
---|
774 | Coord_cell=get(handles.ListCoord,'String'); |
---|
775 | val=get(handles.ListCoord,'Value'); |
---|
776 | if length(Coord_cell)>0 |
---|
777 | coord_str=Coord_cell{val}; |
---|
778 | k=findstr('|',coord_str); |
---|
779 | if isempty(k) |
---|
780 | return |
---|
781 | end |
---|
782 | set(handles.XObject,'String',coord_str(1:k(1)-5)) |
---|
783 | set(handles.YObject,'String',coord_str(k(1)+5:k(2)-5)) |
---|
784 | set(handles.ZObject,'String',coord_str(k(2)+5:k(3)-5)) |
---|
785 | set(handles.XImage,'String',coord_str(k(3)+5:k(4)-5)) |
---|
786 | set(handles.YImage,'String',coord_str(k(4)+5:end)) |
---|
787 | huvmat=findobj(allchild(0),'Name','uvmat');%find the current uvmat interface handle |
---|
788 | hplot=findobj(huvmat,'Tag','axes3');%main plotting axis of uvmat |
---|
789 | h_menu_coord=findobj(huvmat,'Tag','menu_coord'); |
---|
790 | menu=get(h_menu_coord,'String'); |
---|
791 | choice=get(h_menu_coord,'Value'); |
---|
792 | if iscell(menu) |
---|
793 | option=menu{choice}; |
---|
794 | else |
---|
795 | option='px'; %default |
---|
796 | end |
---|
797 | if isequal(option,'phys') |
---|
798 | XCoord=str2num(coord_str(1:k(1)-5)); |
---|
799 | YCoord=str2num(coord_str(k(1)+5:k(2)-5)); |
---|
800 | elseif isequal(option,'px')|| isequal(option,'') |
---|
801 | XCoord=str2num(coord_str(k(3)+5:k(4)-5)); |
---|
802 | YCoord=str2num(coord_str(k(4)+5:end)); |
---|
803 | else |
---|
804 | warndlg_uvmat('the choice in menu_coord of uvmat must be px or phys ','ERROR') |
---|
805 | end |
---|
806 | huvmat=findobj(allchild(0),'Name','uvmat');%find the current uvmat interface handle |
---|
807 | hplot=findobj(huvmat,'Tag','axes3');%main plotting axis of uvmat |
---|
808 | hhh=findobj(hplot,'Tag','calib_marker'); |
---|
809 | if isempty(hhh) |
---|
810 | axes(hplot) |
---|
811 | line(XCoord,YCoord,'Color','m','Tag','calib_marker','LineStyle','.','Marker','o','MarkerSize',20); |
---|
812 | else |
---|
813 | set(hhh,'XData',XCoord) |
---|
814 | set(hhh,'YData',YCoord) |
---|
815 | end |
---|
816 | end |
---|
817 | |
---|
818 | |
---|
819 | %---------------------------------------------------- |
---|
820 | % --- Executes on button press in rotation_plus. |
---|
821 | function rotation_plus_Callback(hObject, eventdata, handles) |
---|
822 | Phi=0; |
---|
823 | Phi=get(handles.Phi,'String'); |
---|
824 | if ~isempty(Phi) |
---|
825 | Phi=str2num(Phi); |
---|
826 | end |
---|
827 | rotation(handles,Phi) |
---|
828 | |
---|
829 | %------------------------------------------------- |
---|
830 | % --- Executes on button press in rotation_minus. |
---|
831 | function rotation_minus_Callback(hObject, eventdata, handles) |
---|
832 | Phi=0; |
---|
833 | Phi=get(handles.Phi,'String'); |
---|
834 | if ~isempty(Phi) |
---|
835 | Phi=-str2num(Phi); |
---|
836 | end |
---|
837 | rotation(handles,Phi) |
---|
838 | |
---|
839 | |
---|
840 | |
---|
841 | function O_x_Callback(hObject, eventdata, handles) |
---|
842 | |
---|
843 | |
---|
844 | function O_y_Callback(hObject, eventdata, handles) |
---|
845 | |
---|
846 | |
---|
847 | function O_z_Callback(hObject, eventdata, handles) |
---|
848 | |
---|
849 | |
---|
850 | % --- Executes on selection change in edit_append. |
---|
851 | function edit_append_Callback(hObject, eventdata, handles) |
---|
852 | % val=get(handles.PLOT_append,'Value'); |
---|
853 | % if isequal(val,2); %append mode |
---|
854 | % %appeler mouse |
---|
855 | % end |
---|
856 | choice=get(handles.edit_append,'Value'); |
---|
857 | if choice==1 |
---|
858 | Coord=get(handles.ListCoord,'String'); |
---|
859 | val=length(Coord); |
---|
860 | if val>=1 & isequal(Coord{val},'') |
---|
861 | val=val-1; %do not take into account blank |
---|
862 | end |
---|
863 | Coord{val+1}=''; |
---|
864 | set(handles.ListCoord,'String',Coord) |
---|
865 | set(handles.ListCoord,'Value',val+1) |
---|
866 | end |
---|
867 | |
---|
868 | |
---|
869 | %A REVOIR |
---|
870 | % if choice==2 |
---|
871 | % %display image with px coordinates |
---|
872 | % hrootpath=findobj(huvmat,'Tag','RootPath'); |
---|
873 | % hrootfile=findobj(huvmat,'Tag','RootFile'); |
---|
874 | % RootPath=''; |
---|
875 | % RootFile=''; |
---|
876 | % % if ~isempty(hrootpath)& ~isempty(hrootfile) |
---|
877 | % testhandle=1; |
---|
878 | % RootPath=get(hrootpath,'String'); |
---|
879 | % RootFile=get(hrootfile,'String'); |
---|
880 | % % filebase=fullfile(RootPath,RootFile); |
---|
881 | % % outputfile=[filebase '.xml']; |
---|
882 | % Indices=get(findobj(huvmat,'Tag','FileIndex'),'String'); |
---|
883 | % Ext=get(findobj(huvmat,'Tag','FileExt'),'String'); |
---|
884 | % imagename=[fullfile(RootPath,RootFile) Indices Ext]; |
---|
885 | % % input.menu_coord=1; |
---|
886 | % h_menu_coord=findobj(huvmat,'Tag','menu_coord'); |
---|
887 | % set(h_menu_coord,'Value',3) |
---|
888 | % huvmat=uvmat(imagename);%open uvmat, set phys coord (Value 1) |
---|
889 | % |
---|
890 | % % end |
---|
891 | % end |
---|
892 | |
---|
893 | function NEW_Callback(hObject, eventdata, handles) |
---|
894 | %A METTRE SOUS UN BOUTON |
---|
895 | huvmat=findobj(allchild(0),'Name','uvmat'); |
---|
896 | hchild=get(huvmat,'children'); |
---|
897 | hcoord=findobj(hchild,'Tag','menu_coord'); |
---|
898 | coordtype=get(hcoord,'Value'); |
---|
899 | haxes=findobj(hchild,'Tag','axes3'); |
---|
900 | AxeData=get(haxes,'UserData'); |
---|
901 | if ~isequal(hcoord,2) |
---|
902 | set(hcoord,'Value',2) |
---|
903 | huvmat=uvmat(AxeData); |
---|
904 | 'relancer uvmat'; |
---|
905 | end |
---|
906 | if ~isfield(AxeData,'ZoomAxes') |
---|
907 | warndlg_uvmat('first draw a window around a grid marker','ERRROR') |
---|
908 | return |
---|
909 | end |
---|
910 | XLim=get(AxeData.ZoomAxes,'XLim'); |
---|
911 | YLim=get(AxeData.ZoomAxes,'YLim'); |
---|
912 | np=size(AxeData.A); |
---|
913 | ind_sub_x=round(XLim); |
---|
914 | ind_sub_y=np(1)-round(YLim); |
---|
915 | Mfiltre=AxeData.A([ind_sub_y(2):ind_sub_y(1)] ,ind_sub_x,:); |
---|
916 | Mfiltre_norm=double(Mfiltre); |
---|
917 | Mfiltre_norm=Mfiltre_norm/sum(sum(Mfiltre_norm)); |
---|
918 | Mfiltre_norm=100*(Mfiltre_norm-mean(mean(Mfiltre_norm))); |
---|
919 | Atype=class(AxeData.A); |
---|
920 | Data.NbDim=2; |
---|
921 | Data.A=filter2(Mfiltre_norm,double(AxeData.A)); |
---|
922 | Data.A=feval(Atype,Data.A); |
---|
923 | Data.AName='image'; |
---|
924 | Data.AX=AxeData.AX; |
---|
925 | Data.AY=AxeData.AY; |
---|
926 | Data.CoordType='px'; |
---|
927 | plot_field(Data) |
---|
928 | |
---|
929 | |
---|
930 | |
---|
931 | %'key_press_fcn:' function activated when a key is pressed on the keyboard |
---|
932 | %----------------------------------- |
---|
933 | function key_press_fcn(hObject,eventdata,handles) |
---|
934 | hh=get(hObject,'parent'); |
---|
935 | xx=double(get(hh,'CurrentCharacter')); %get the keyboard character |
---|
936 | |
---|
937 | if ismember(xx,[8 127])%backspace or delete |
---|
938 | Coord_cell=get(handles.ListCoord,'String'); |
---|
939 | data=read_geometry_calib(Coord_cell); |
---|
940 | Coord=[]; %default |
---|
941 | if isfield(data,'Coord') |
---|
942 | Coord=data.Coord; |
---|
943 | end |
---|
944 | val=get(handles.ListCoord,'Value'); |
---|
945 | Coord(val,:)=[];%suppress the selected item in the list |
---|
946 | CoordCell={}; |
---|
947 | for iline=1:size(Coord,1) |
---|
948 | for j=1:5 |
---|
949 | CoordCell{iline,j}=num2str(Coord(iline,j),4); |
---|
950 | end |
---|
951 | end |
---|
952 | Tabchar=cell2tab(CoordCell,' | ');%transform cells into table ready for display |
---|
953 | val=min(size(Coord,1),val); |
---|
954 | set(handles.ListCoord,'Value',max(val,1)) |
---|
955 | set(handles.ListCoord,'String',Tabchar) |
---|
956 | ListCoord_Callback(hObject, eventdata, handles) |
---|
957 | PLOT_Callback(hObject,eventdata,handles) |
---|
958 | end |
---|
959 | |
---|
960 | |
---|
961 | % --- Executes on button press in append_point. |
---|
962 | function append_point_Callback(hObject, eventdata, handles) |
---|
963 | |
---|
964 | Coord=get(handles.ListCoord,'String'); |
---|
965 | val=length(Coord); |
---|
966 | if val>=1 & isequal(Coord{val},'') |
---|
967 | val=val-1; %do not take into account blank |
---|
968 | end |
---|
969 | Coord{val+1}=''; |
---|
970 | set(handles.ListCoord,'String',Coord) |
---|
971 | set(handles.ListCoord,'Value',val+1) |
---|
972 | |
---|
973 | |
---|
974 | % -------------------------------------------------------------------- |
---|
975 | function MenuOpen_Callback(hObject, eventdata, handles) |
---|
976 | %get the object file |
---|
977 | huvmat=findobj(allchild(0),'Name','uvmat'); |
---|
978 | UvData=get(huvmat,'UserData'); |
---|
979 | hchild=get(huvmat,'Children'); |
---|
980 | hrootpath=findobj(hchild,'Tag','RootPath'); |
---|
981 | oldfile=get(hrootpath,'String'); |
---|
982 | if isempty(oldfile) |
---|
983 | oldfile=''; |
---|
984 | end |
---|
985 | %[FileName,PathName] = uigetfile('*.civ','Select a .civ file',oldfile) |
---|
986 | [FileName, PathName, filterindex] = uigetfile( ... |
---|
987 | {'*.xml;*.mat', ' (*.xml,*.mat)'; |
---|
988 | '*.xml', '.xml files '; ... |
---|
989 | '*.mat', '.mat matlab files '}, ... |
---|
990 | 'Pick a file',oldfile); |
---|
991 | fileinput=[PathName FileName];%complete file name |
---|
992 | testblank=findstr(fileinput,' ');%look for blanks |
---|
993 | if ~isempty(testblank) |
---|
994 | msgbox_uvmat('ERROR','forbidden input file name or path: no blank character allowed') |
---|
995 | return |
---|
996 | end |
---|
997 | sizf=size(fileinput); |
---|
998 | if (~ischar(fileinput)|~isequal(sizf(1),1)),return;end |
---|
999 | loadfile(handles,fileinput) |
---|
1000 | |
---|
1001 | |
---|
1002 | % -------------------------------------------------------------------- |
---|
1003 | function Untitled_3_Callback(hObject, eventdata, handles) |
---|
1004 | % hObject handle to Untitled_3 (see GCBO) |
---|
1005 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
1006 | % handles structure with handles and user data (see GUIDATA) |
---|
1007 | |
---|
1008 | |
---|
1009 | % -------------------------------------------------------------------- |
---|
1010 | function MenuPlot_Callback(hObject, eventdata, handles) |
---|
1011 | |
---|
1012 | huvmat=findobj(allchild(0),'Name','uvmat');%find the current uvmat interface handle |
---|
1013 | UvData=get(huvmat,'UserData');%Data associated to the current uvmat interface |
---|
1014 | hhuvmat=guidata(huvmat); %handles of GUI elements in uvmat |
---|
1015 | hplot=findobj(huvmat,'Tag','axes3');%main plotting axis of uvmat |
---|
1016 | h_menu_coord=findobj(huvmat,'Tag','menu_coord'); |
---|
1017 | menu=get(h_menu_coord,'String'); |
---|
1018 | choice=get(h_menu_coord,'Value'); |
---|
1019 | if iscell(menu) |
---|
1020 | option=menu{choice}; |
---|
1021 | else |
---|
1022 | option='px'; %default |
---|
1023 | end |
---|
1024 | Coord_cell=get(handles.ListCoord,'String'); |
---|
1025 | ObjectData=read_geometry_calib(Coord_cell); |
---|
1026 | %ObjectData=read_geometry_calib(handles);%read the interface input parameters defining the object |
---|
1027 | if isequal(option,'phys') |
---|
1028 | ObjectData.Coord=ObjectData.Coord(:,[1:3]); |
---|
1029 | elseif isequal(option,'px')||isequal(option,'') |
---|
1030 | ObjectData.Coord=ObjectData.Coord(:,[4:5]); |
---|
1031 | else |
---|
1032 | msgbox_uvmat('ERROR','the choice in menu_coord of uvmat must be px or phys ') |
---|
1033 | end |
---|
1034 | axes(hhuvmat.axes3) |
---|
1035 | hh=findobj('Tag','calib_points'); |
---|
1036 | if isempty(hh) |
---|
1037 | hh=line(ObjectData.Coord(:,1),ObjectData.Coord(:,2),'Color','m','Tag','calib_points','LineStyle','.','Marker','+'); |
---|
1038 | else |
---|
1039 | set(hh,'XData',ObjectData.Coord(:,1)) |
---|
1040 | set(hh,'YData',ObjectData.Coord(:,2)) |
---|
1041 | end |
---|
1042 | |
---|
1043 | % -------------------------------------------------------------------- |
---|
1044 | function MenuHelp_Callback(hObject, eventdata, handles) |
---|
1045 | path_to_uvmat=which ('uvmat');% check the path of uvmat |
---|
1046 | pathelp=fileparts(path_to_uvmat); |
---|
1047 | helpfile=fullfile(pathelp,'UVMAT_DOC','uvmat_doc.html'); |
---|
1048 | if isempty(dir(helpfile)), warndlg_uvmat('The help file uvmat_doc.html needs to be put in the directory UVMAT/UVMAT_DOC','ERROR') |
---|
1049 | else |
---|
1050 | web([helpfile '#geometry_calib']) |
---|
1051 | end |
---|
1052 | |
---|
1053 | |
---|
1054 | |
---|
1055 | % -------------------------------------------------------------------- |
---|
1056 | function MenuCreateGrid_Callback(hObject, eventdata, handles) |
---|
1057 | hcalib=get(handles.calib_type,'parent');%handles of the GUI geometry_calib |
---|
1058 | CalibData=get(hcalib,'UserData'); |
---|
1059 | Tinput=[];%default |
---|
1060 | if isfield(CalibData,'grid') |
---|
1061 | Tinput=CalibData.grid; |
---|
1062 | end |
---|
1063 | T=create_grid(Tinput);%display translate_points GUI and get shift parameters |
---|
1064 | CalibData.grid=T; |
---|
1065 | set(hcalib,'UserData',CalibData) |
---|
1066 | |
---|
1067 | %grid in phys space |
---|
1068 | Coord_cell=get(handles.ListCoord,'String'); |
---|
1069 | data=read_geometry_calib(Coord_cell); |
---|
1070 | data.Coord(:,1)=T(1)+data.Coord(:,1); |
---|
1071 | data.Coord(:,2)=T(2)+data.Coord(:,2); |
---|
1072 | data.Coord(:,3)=T(3)+data.Coord(:,3); |
---|
1073 | data.Coord(:,[4 5])=data.Coord(:,[4 5]); |
---|
1074 | for i=1:size(data.Coord,1) |
---|
1075 | for j=1:5 |
---|
1076 | Coord{i,j}=num2str(data.Coord(i,j),4);%phys x,y,z |
---|
1077 | end |
---|
1078 | end |
---|
1079 | Tabchar=cell2tab(Coord,' | '); |
---|
1080 | set(handles.ListCoord,'Value',1) |
---|
1081 | set(handles.ListCoord,'String',Tabchar) |
---|
1082 | |
---|
1083 | |
---|
1084 | |
---|
1085 | % -------------------------------------------------------------------- |
---|
1086 | function MenuTranslatePoints_Callback(hObject, eventdata, handles) |
---|
1087 | hcalib=get(handles.calib_type,'parent');%handles of the GUI geometry_calib |
---|
1088 | CalibData=get(hcalib,'UserData') |
---|
1089 | Tinput=[];%default |
---|
1090 | if isfield(CalibData,'translate') |
---|
1091 | Tinput=CalibData.translate; |
---|
1092 | end |
---|
1093 | T=translate_points(Tinput);%display translate_points GUI and get shift parameters |
---|
1094 | CalibData.translate=T; |
---|
1095 | set(hcalib,'UserData',CalibData) |
---|
1096 | %translation |
---|
1097 | Coord_cell=get(handles.ListCoord,'String'); |
---|
1098 | data=read_geometry_calib(Coord_cell); |
---|
1099 | data.Coord(:,1)=T(1)+data.Coord(:,1); |
---|
1100 | data.Coord(:,2)=T(2)+data.Coord(:,2); |
---|
1101 | data.Coord(:,3)=T(3)+data.Coord(:,3); |
---|
1102 | data.Coord(:,[4 5])=data.Coord(:,[4 5]); |
---|
1103 | for i=1:size(data.Coord,1) |
---|
1104 | for j=1:5 |
---|
1105 | Coord{i,j}=num2str(data.Coord(i,j),4);%phys x,y,z |
---|
1106 | end |
---|
1107 | end |
---|
1108 | Tabchar=cell2tab(Coord,' | '); |
---|
1109 | set(handles.ListCoord,'Value',1) |
---|
1110 | set(handles.ListCoord,'String',Tabchar) |
---|
1111 | |
---|
1112 | |
---|
1113 | % -------------------------------------------------------------------- |
---|
1114 | function MenuRotatePoints_Callback(hObject, eventdata, handles) |
---|
1115 | hcalib=get(handles.calib_type,'parent');%handles of the GUI geometry_calib |
---|
1116 | CalibData=get(hcalib,'UserData') |
---|
1117 | Tinput=[];%default |
---|
1118 | if isfield(CalibData,'rotate') |
---|
1119 | Tinput=CalibData.rotate; |
---|
1120 | end |
---|
1121 | T=rotate_points(Tinput);%display translate_points GUI and get shift parameters |
---|
1122 | CalibData.rotate=T; |
---|
1123 | set(hcalib,'UserData',CalibData) |
---|
1124 | %----------------------------------------------------- |
---|
1125 | %rotation |
---|
1126 | Phi=T(1); |
---|
1127 | O_x=0;%default |
---|
1128 | O_y=0;%default |
---|
1129 | if numel(T)>=2 |
---|
1130 | O_x=T(2);%default |
---|
1131 | end |
---|
1132 | if numel(T)>=3 |
---|
1133 | O_y=T(3);%default |
---|
1134 | end |
---|
1135 | Coord_cell=get(handles.ListCoord,'String'); |
---|
1136 | data=read_geometry_calib(Coord_cell); |
---|
1137 | r1=cos(pi*Phi/180); |
---|
1138 | r2=-sin(pi*Phi/180); |
---|
1139 | r3=sin(pi*Phi/180); |
---|
1140 | r4=cos(pi*Phi/180); |
---|
1141 | x=data.Coord(:,1)-O_x; |
---|
1142 | y=data.Coord(:,2)-O_y; |
---|
1143 | data.Coord(:,1)=r1*x+r2*y; |
---|
1144 | data.Coord(:,2)=r3*x+r4*y; |
---|
1145 | % data.Coord(:,[4 5])=data.Coord(:,[4 5]); |
---|
1146 | for i=1:size(data.Coord,1) |
---|
1147 | for j=1:5 |
---|
1148 | Coord{i,j}=num2str(data.Coord(i,j),4);%phys x,y,z |
---|
1149 | end |
---|
1150 | end |
---|
1151 | Tabchar=cell2tab(Coord,' | '); |
---|
1152 | set(handles.ListCoord,'Value',1) |
---|
1153 | set(handles.ListCoord,'String',Tabchar) |
---|
1154 | |
---|
1155 | |
---|