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