0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 function varargout = geometry_calib(varargin)
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048 gui_Singleton = 1;
0049 gui_State = struct('gui_Name', mfilename, ...
0050 'gui_Singleton', gui_Singleton, ...
0051 'gui_OpeningFcn', @geometry_calib_OpeningFcn, ...
0052 'gui_OutputFcn', @geometry_calib_OutputFcn, ...
0053 'gui_LayoutFcn', [] , ...
0054 'gui_Callback', []);
0055 if nargin & isstr(varargin{1})
0056 gui_State.gui_Callback = str2func(varargin{1});
0057 end
0058
0059 if nargout
0060 [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
0061 else
0062 gui_mainfcn(gui_State, varargin{:});
0063 end
0064
0065
0066
0067
0068
0069
0070
0071
0072 function geometry_calib_OpeningFcn(hObject, eventdata, handles, handles_uvmat,pos,inputfile)
0073 set(handles.Phi,'TooltipString','Phi: rotation angle of the physical point coordiantes (in degrees)')
0074
0075 handles.output = hObject;
0076
0077
0078 guidata(hObject, handles);
0079 movegui(hObject,'east');
0080 if exist('handles_uvmat','var')
0081 set(hObject,'DeleteFcn',{@closefcn,handles_uvmat})
0082 end
0083
0084 if exist('pos','var')& length(pos)>2
0085 pos_gui=get(hObject,'Position');
0086 pos_gui(1)=pos(1);
0087 pos_gui(2)=pos(2);
0088 set(hObject,'Position',pos_gui);
0089 end
0090 inputxml='';
0091 if exist('inputfile','var')& ~isempty(inputfile)
0092 [Path,Name,ext]=fileparts(inputfile);
0093 form=imformats(ext([2:end]));
0094 if ~isempty(form)
0095 set(hObject,'UserData',inputfile)
0096 [Pathsub,RootFile,field_count,str2,str_a,str_b,ext,nom_type,subdir]=name2display(inputfile);
0097 inputxml=[fullfile(Pathsub,RootFile) '.xml'];
0098 end
0099 end
0100 set(handles.ListCoord,'String',{''})
0101 if exist(inputxml,'file')
0102 loadfile(handles,inputxml)
0103 end
0104
0105 set(handles.ListCoord,'KeyPressFcn',{@key_press_fcn,handles})
0106
0107
0108
0109
0110
0111 function varargout = geometry_calib_OutputFcn(hObject, eventdata, handles)
0112
0113
0114
0115
0116
0117
0118 varargout{1} = handles.output;
0119 varargout{2}=handles;
0120
0121
0122 function Phi_Callback(hObject, eventdata, handles)
0123
0124
0125
0126
0127 function OPEN_Callback(hObject, eventdata, handles)
0128
0129 huvmat=findobj(allchild(0),'Name','uvmat');
0130 UvData=get(huvmat,'UserData');
0131 hchild=get(huvmat,'Children');
0132 hrootpath=findobj(hchild,'Tag','RootPath');
0133 oldfile=get(hrootpath,'String');
0134 if isempty(oldfile)
0135 oldfile='';
0136 end
0137
0138 [FileName, PathName, filterindex] = uigetfile( ...
0139 {'*.xml;*.mat', ' (*.xml,*.mat)';
0140 '*.xml', '.xml files '; ...
0141 '*.mat', '.mat matlab files '}, ...
0142 'Pick a file',oldfile);
0143 fileinput=[PathName FileName];
0144 testblank=findstr(fileinput,' ');
0145 if ~isempty(testblank)
0146 warndlg_uvmat('forbidden input file name or path: no blank character allowed','ERROR')
0147 return
0148 end
0149 sizf=size(fileinput);
0150 if (~ischar(fileinput)|~isequal(sizf(1),1)),return;end
0151 loadfile(handles,fileinput)
0152
0153
0154
0155 function loadfile(handles,fileinput)
0156
0157
0158 t=xmltree(fileinput);
0159 s=convert(t);
0160
0161 PointCoord=[];
0162 Coord_cell=get(handles.ListCoord,'String');
0163 data=read_geometry_calib(Coord_cell);
0164
0165 Coord=[];
0166 if isfield(data,'Coord')
0167 Coord=data.Coord;
0168 end
0169 TabChar_0=get(handles.ListCoord,'String');
0170 nbcoord_0=size(TabChar_0,1);
0171 if isequal(get(handles.edit_append,'Value'),2)
0172 val=get(handles.ListCoord,'Value')-1;
0173 else
0174 val=length(TabChar_0);
0175 end
0176 nbcoord=0;
0177
0178
0179 if isfield(s,'Heading')
0180 CalibData=s.Heading;
0181 end
0182 CalibData.XmlInput=fileinput;
0183 hcalib=get(handles.OPEN,'parent');
0184 set(hcalib,'UserData',CalibData);
0185 if isfield(s,'GeometryCalib')
0186 Calib=s.GeometryCalib;
0187 if isfield(Calib,'CalibrationType')
0188 CalibrationType=Calib.CalibrationType;
0189 switch CalibrationType
0190 case 'linear'
0191 set(handles.calib_type,'Value',2)
0192 case 'tsai'
0193 set(handles.calib_type,'Value',3)
0194 end
0195 end
0196 if isfield(Calib,'SourceCalib')
0197 if isfield(Calib.SourceCalib,'PointCoord')
0198 PointCoord=Calib.SourceCalib.PointCoord;
0199 end
0200
0201
0202
0203
0204 end
0205 nbcoord=length(PointCoord);
0206 if ~isfield(Calib,'ErrorRms')&~isfield(Calib,'ErrorMax')
0207 for i=1:length(PointCoord)
0208 line=str2num(PointCoord{i});
0209 Coord(i+val,4:5)=line(4:5);
0210 Coord(i+val,1:3)=line(1:3)/10;
0211 end
0212 else
0213 for i=1:length(PointCoord)
0214 line=str2num(PointCoord{i});
0215 Coord(i,4:5)=line(4:5);
0216 Coord(i,1:3)=line(1:3);
0217 end
0218 end
0219 end
0220
0221 if isfield(s,'Coord')
0222 PointCoord=s.Coord;
0223 nbcoord=length(PointCoord);
0224
0225 if isfield(s,'CoordType')& isequal(s.CoordType,'px')
0226 for i=1:nbcoord
0227 line=str2num(PointCoord{i});
0228 Coord(i+val,4:5)=line(1:2);
0229 end
0230
0231 else
0232 for i=1:nbcoord
0233 line=str2num(PointCoord{i});
0234 Coord(i+val,1:3)=line(1:3);
0235 nbcolumn=size(Coord,2);
0236 if nbcolumn<5
0237 Coord(i+val,nbcolumn+1:5)=zeros(1,5-nbcolumn);
0238 end
0239 end
0240 end
0241 end
0242 CoordCell={};
0243 for iline=1:size(Coord,1)
0244 for j=1:5
0245 CoordCell{iline,j}=num2str(Coord(iline,j),4);
0246 end
0247 end
0248 Tabchar=cell2tab(CoordCell,' | ');
0249 set(handles.ListCoord,'Value',1)
0250 set(handles.ListCoord,'String',Tabchar)
0251
0252
0253
0254
0255 function closefcn(gcbo,eventdata,handles_uvmat)
0256 huvmat=findobj(allchild(0),'Name','uvmat');
0257 if exist('handles_uvmat','var')
0258 set(handles_uvmat.cal,'Value',0)
0259 uvmat('cal_Callback',huvmat,[],handles_uvmat);
0260
0261
0262 end
0263
0264
0265
0266 function PLOT_Callback(hObject, eventdata, handles)
0267
0268 huvmat=findobj(allchild(0),'Name','uvmat');
0269 UvData=get(huvmat,'UserData');
0270 hhuvmat=guidata(huvmat);
0271 hplot=findobj(huvmat,'Tag','axes3');
0272 h_menu_coord=findobj(huvmat,'Tag','menu_coord');
0273 menu=get(h_menu_coord,'String');
0274 choice=get(h_menu_coord,'Value');
0275 if iscell(menu)
0276 option=menu{choice};
0277 else
0278 option='px';
0279 end
0280 Coord_cell=get(handles.ListCoord,'String');
0281 ObjectData=read_geometry_calib(Coord_cell);
0282
0283 if isequal(option,'phys')
0284 ObjectData.Coord=ObjectData.Coord(:,[1:3]);
0285 elseif isequal(option,'px')||isequal(option,'')
0286 ObjectData.Coord=ObjectData.Coord(:,[4:5]);
0287 else
0288 warndlg_uvmat('the choice in menu_coord of uvmat must be px or phys ','ERROR')
0289 end
0290 axes(hhuvmat.axes3)
0291 hh=findobj('Tag','calib_points');
0292 if isempty(hh)
0293 hh=line(ObjectData.Coord(:,1),ObjectData.Coord(:,2),'Color','m','Tag','calib_points','LineStyle','.','Marker','+');
0294 else
0295 set(hh,'XData',ObjectData.Coord(:,1))
0296 set(hh,'YData',ObjectData.Coord(:,2))
0297 end
0298
0299
0300 function MenuCoord_Callback(hObject, eventdata, handles)
0301
0302
0303
0304 function delete_Callback(hObject, eventdata, handles)
0305 SetData=get(gcbf,'UserData');
0306 IndexObj=SetData.IndexObj;
0307 delete_object(IndexObj);
0308
0309
0310
0311
0312 function APPLY_Callback(hObject, eventdata, handles)
0313
0314 calib_cell=get(handles.calib_type,'String');
0315 val=get(handles.calib_type,'Value');
0316 calib_type=calib_cell{val};
0317 Coord_cell=get(handles.ListCoord,'String');
0318 Object=read_geometry_calib(Coord_cell);
0319
0320 if isequal(calib_type,'rescale')
0321 GeometryCalib=calib_rescale(Object.Coord);
0322 elseif isequal(calib_type,'linear')
0323 GeometryCalib=calib_linear(Object.Coord);
0324 elseif isequal(calib_type,'tsai')
0325 GeometryCalib=calib_tsai(Object.Coord);
0326 end
0327 unitlist=get(handles.CoordUnit,'String');
0328 unit=unitlist{get(handles.CoordUnit,'value')};
0329 GeometryCalib.CoordUnit=unit;
0330
0331 huvmat=findobj(allchild(0),'Name','uvmat');
0332 hhuvmat=guidata(huvmat);
0333 RootPath='';
0334 RootFile='';
0335 if ~isempty(hhuvmat.RootPath)& ~isempty(hhuvmat.RootFile)
0336 testhandle=1;
0337 RootPath=get(hhuvmat.RootPath,'String');
0338 RootFile=get(hhuvmat.RootFile,'String');
0339 filebase=fullfile(RootPath,RootFile);
0340 outputfile=[filebase '.xml'];
0341 else
0342 question={'save the calibration data and point coordinates in'};
0343 def={fullfile(RootPath,['ObjectCalib.xml'])};
0344 options.Resize='on';
0345 answer=inputdlg(question,'save average in a new file',1,def,options);
0346 outputfile=answer{1};
0347 end
0348 testappend=0;
0349 if exist(outputfile,'file');
0350 t=xmltree(outputfile);
0351 uid=find(t,'ImaDoc');
0352 if ~isequal(uid,1)
0353 backupfile=outputfile;
0354 testexist=2;
0355 while testexist==2
0356 backupfile=[backupfile '~'];
0357 testexist=exist(backupfile,'file');
0358 end
0359 [success,message]=copyfile(outputfile,backupfile);
0360 if isequal(success,1)
0361 delete(outputfile)
0362 else
0363 return
0364 end
0365 else
0366 uid_calib=find(t,'ImaDoc/GeometryCalib');
0367 if ~isempty(uid)
0368 backupfile=outputfile;
0369 testexist=2;
0370 while testexist==2
0371 backupfile=[backupfile '~'];
0372 testexist=exist(backupfile,'file');
0373 end
0374 [success,message]=copyfile(outputfile,backupfile);
0375 if isequal(success,1)
0376 delete(outputfile)
0377 else
0378 return
0379 end
0380 uid_child=children(t,uid_calib);
0381 t=delete(t,uid_child);
0382 testappend=1;
0383 end
0384 end
0385 end
0386 if ~testappend
0387 t=xmltree;
0388 t=set(t,1,'name','ImaDoc');
0389 [t,uid_calib]=add(t,1,'element','GeometryCalib');
0390
0391 end
0392
0393
0394
0395
0396
0397 GeometryCalib.SourceCalib.PointCoord=Object.Coord;
0398 t=struct2xml(GeometryCalib,t,uid_calib);
0399 save(t,outputfile);
0400 warndlg_uvmat({[outputfile ' updated with calibration data'];...
0401 ['Error rms (along x,y)=' num2str(GeometryCalib.ErrorRms) ' pixels'];...
0402 ['Error max (along x,y)=' num2str(GeometryCalib.ErrorMax) ' pixels']},'CONFIRMATION')
0403
0404
0405 hhh=findobj(hhuvmat.axes3,'Tag','calib_marker');
0406 if ~isempty(hhh)
0407 delete(hhh);
0408 end
0409 hhh=findobj(hhuvmat.axes3,'Tag','calib_points');
0410 if ~isempty(hhh)
0411 delete(hhh);
0412 end
0413 set(hhuvmat.FixedLimits,'Value',0)
0414 set(hhuvmat.FixedLimits,'BackgroundColor',[0.7 0.7 0.7])
0415 uvmat('RootPath_Callback',hObject,eventdata,hhuvmat);
0416
0417
0418
0419 function REPLICATE_Callback(hObject, eventdata, handles)
0420
0421 calib_cell=get(handles.calib_type,'String');
0422 val=get(handles.calib_type,'Value');
0423 calib_type=calib_cell{val};
0424 Coord_cell=get(handles.ListCoord,'String');
0425 Object=read_geometry_calib(Coord_cell);
0426
0427 if isequal(calib_type,'rescale')
0428 GeometryCalib=calib_rescale(Object.Coord);
0429 elseif isequal(calib_type,'linear')
0430 GeometryCalib=calib_linear(Object.Coord);
0431 elseif isequal(calib_type,'tsai')
0432 GeometryCalib=calib_tsai(Object.Coord);
0433 end
0434
0435
0436
0437
0438
0439
0440 GeometryCalib.SourceCalib.PointCoord=Object.Coord;
0441
0442
0443 h_dataview=findobj(allchild(0),'name','dataview');
0444 Device=[];
0445 if isempty(h_dataview)
0446 h_dataview=dataview;
0447 hhdataview=guidata(h_dataview);
0448 drawnow
0449 hGUI=get(handles.REPLICATE,'parent');
0450 Heading=get(hGUI,'UserData');
0451 if isfield(Heading,'XmlInput')
0452 XmlInput=fileparts(Heading.XmlInput);
0453 [XmlInput,filename,ext]=fileparts(XmlInput);
0454 end
0455 if isfield(Heading,'Record') && isequal([filename ext],Heading.Record)
0456 [XmlInput,filename,ext]=fileparts(XmlInput);
0457 end
0458 if isfield(Heading,'Device') && isequal([filename ext],Heading.Device)
0459 [XmlInput,filename,ext]=fileparts(XmlInput);
0460 Device=Heading.Device;
0461 end
0462 if isfield(Heading,'Experiment') && isequal([filename ext],Heading.Experiment)
0463 [PP,filename,ext]=fileparts(XmlInput);
0464 end
0465 testinput=0;
0466 if isfield(Heading,'SubCampaign') && isequal([filename ext],Heading.SubCampaign)
0467 set(hhdataview.RootDirectory,'String',XmlInput)
0468 set(hhdataview.SubCampaignTest,'Value',1)
0469 testinput=1;
0470 elseif isfield(Heading,'Campaign') && isequal([filename ext],Heading.Campaign)
0471 set(hhdataview.RootDirectory,'String',XmlInput)
0472 set(hhdataview.SubCampaignTest,'Value',0)
0473 testinput=1;
0474 end
0475 if testinput
0476 dataview('RootDirectory_Callback',hObject,eventdata,hhdataview)
0477 ListDevices=get(hhdataview.ListDevices,'String');
0478 for ilist=1:length(ListDevices)
0479 if isequal(ListDevices{ilist},Device)
0480 set(hhdataview.ListDevices,'Value',ilist)
0481 dataview('ListDevices_Callback',hObject,eventdata,hhdataview)
0482 break
0483 end
0484 end
0485 end
0486 return
0487 end
0488
0489 hhdataview=guidata(h_dataview);
0490 CurrentPath=get(hhdataview.RootDirectory,'String');
0491 ListExperiments=get(hhdataview.ListExperiments,'String');
0492 Value=get(hhdataview.ListExperiments,'Value');
0493 if ~isequal(Value,1)
0494 ListExperiments=ListExperiments(Value);
0495 end
0496 ListDevices=get(hhdataview.ListDevices,'String');
0497 Value=get(hhdataview.ListDevices,'Value');
0498 if isequal(Value,1)
0499 warndlg_uvmat('manually select in the GUI dataview the device being calibrated','ERROR')
0500 return
0501 else
0502 ListDevices=ListDevices(Value);
0503 end
0504 ListRecords=get(hhdataview.ListRecords,'String');
0505 Value=get(hhdataview.ListRecords,'Value');
0506 if ~isequal(Value,1)
0507 ListRecords=ListRecords(Value);
0508 end
0509 [ListDevices,ListRecords,ListXml,List]=ListDir(CurrentPath,ListExperiments,ListDevices,ListRecords);
0510 ListXml=get(hhdataview.ListXml,'String');
0511 Value=get(hhdataview.ListXml,'Value');
0512 if isequal(Value,1)
0513 warndlg_uvmat('you need to select in the GUI dataview the xml files to edit','ERROR')
0514 return
0515 else
0516 ListXml=ListXml(Value);
0517 end
0518
0519
0520 answer=msgbox_uvmat('INPUT_Y-N',[num2str(length(Value)) ' xml files for device ' ListDevices{1} ' will be refreshed with ' calib_type ' calibration data']);
0521 if ~isequal(answer{1},'OK')
0522 return
0523 end
0524
0525
0526
0527 for iexp=1:length(List.Experiment)
0528 ExpName=List.Experiment{iexp}.name;
0529 if isfield(List.Experiment{iexp},'Device')
0530 for idevice=1:length(List.Experiment{iexp}.Device)
0531 DeviceName=List.Experiment{iexp}.Device{idevice}.name;
0532 if isfield(List.Experiment{iexp}.Device{idevice},'xmlfile')
0533 for ixml=1:length(List.Experiment{iexp}.Device{idevice}.xmlfile)
0534 FileName=List.Experiment{iexp}.Device{idevice}.xmlfile{ixml};
0535 for ilistxml=1:length(ListXml)
0536 if isequal(FileName,ListXml{ilistxml})
0537 set(hhdataview.ListXml,'Value',Value(ilistxml))
0538 drawnow
0539 xmlfullname=fullfile(CurrentPath,ExpName,DeviceName,FileName);
0540 update_imadoc(GeometryCalib,xmlfullname)
0541 break
0542 end
0543 end
0544 end
0545 elseif isfield(List.Experiment{iexp}.Device{idevice},'Record')
0546 for irecord=1:length(List.Experiment{iexp}.Device{idevice}.Record)
0547 RecordName=List.Experiment{iexp}.Device{idevice}.Record{irecord}.name;
0548 if isfield(List.Experiment{iexp}.Device{idevice}.Record{irecord},'xmlfile')
0549 for ixml=1:length(List.Experiment{iexp}.Device{idevice}.Record{irecord}.xmlfile)
0550 FileName=List.Experiment{iexp}.Device{idevice}.Record{irecord}.xmlfile{ixml};
0551 for ilistxml=1:length(ListXml)
0552 if isequal(FileName,ListXml{ilistxml})
0553 set(hhdataview.ListXml,'Value',Value(ilistxml))
0554 drawnow
0555 xmlfullname=fullfile(CurrentPath,ExpName,DeviceName,RecordName,FileName);
0556 update_imadoc(GeometryCalib,xmlfullname)
0557 break
0558 end
0559 end
0560 end
0561 end
0562 end
0563 end
0564 end
0565 end
0566 end
0567 set(hhdataview.ListXml,'Value',Value)
0568
0569
0570
0571 function update_imadoc(GeometryCalib,outputfile)
0572 testappend=0;
0573 if exist(outputfile,'file');
0574 t=xmltree(outputfile);
0575 uid=find(t,'ImaDoc');
0576 if isequal(uid,1)
0577 uid_calib=find(t,'ImaDoc/GeometryCalib');
0578 if ~isempty(uid)
0579 backupfile=outputfile;
0580 testexist=2;
0581 while testexist==2
0582 backupfile=[backupfile '~'];
0583 testexist=exist(backupfile,'file');
0584 end
0585 [success,message]=copyfile(outputfile,backupfile);
0586 if isequal(success,1)
0587 delete(outputfile)
0588 else
0589 return
0590 end
0591 uid_child=children(t,uid_calib);
0592 t=delete(t,uid_child);
0593 testappend=1;
0594 end
0595 end
0596 end
0597 if ~testappend
0598 t=xmltree;
0599 t=set(t,1,'name','ImaDoc');
0600 [t,uid_calib]=add(t,1,'element','GeometryCalib');
0601
0602 end
0603
0604 t=struct2xml(GeometryCalib,t,uid_calib);
0605 save(t,outputfile);
0606
0607
0608
0609
0610 function GeometryCalib=calib_rescale(Coord)
0611
0612
0613 X=Coord(:,1);
0614 Y=Coord(:,2);
0615 x_ima=Coord(:,4);
0616 y_ima=Coord(:,5);
0617 [px,sx]=polyfit(X,x_ima,1);
0618 [py,sy]=polyfit(Y,y_ima,1);
0619 T_x=px(2);
0620 T_y=py(2);
0621 GeometryCalib.CalibrationType='rescale';
0622 GeometryCalib.focal=1;
0623 GeometryCalib.CoordUnit=[];
0624 GeometryCalib.Tx_Ty_Tz=[T_x T_y 1];
0625 GeometryCalib.R=[px(1),0,0;0,py(1),0;0,0,1];
0626
0627
0628 Calib.dpx=1;
0629 Calib.dpy=1;
0630 Calib.sx=1;
0631 Calib.Cx=0;
0632 Calib.Cy=0;
0633 Calib.Tz=1;
0634 Calib.kappa1=0;
0635 Calib.f=GeometryCalib.focal;
0636 Calib.Tx=T_x;
0637 Calib.Ty=T_y;
0638 Calib.R=GeometryCalib.R;
0639 [Xpoints,Ypoints]=px_XYZ(Calib,X,Y,0);
0640 GeometryCalib.ErrorRms(1)=sqrt(mean((Xpoints-x_ima).*(Xpoints-x_ima)));
0641 GeometryCalib.ErrorMax(1)=max(abs(Xpoints-x_ima));
0642 GeometryCalib.ErrorRms(2)=sqrt(mean((Ypoints-y_ima).*(Ypoints-y_ima)));
0643 GeometryCalib.ErrorMax(2)=max(abs(Ypoints-y_ima));
0644
0645
0646
0647
0648 function GeometryCalib=calib_linear(Coord)
0649
0650 X=Coord(:,1);
0651 Y=Coord(:,2);
0652 x_ima=Coord(:,4);
0653 y_ima=Coord(:,5);
0654 XY_mat=[ones(size(X)) X Y];
0655 a_X1=XY_mat\x_ima;
0656 x1=XY_mat*a_X1;
0657 err_X1=max(abs(x1-x_ima));
0658 a_Y1=XY_mat\y_ima;
0659 y1=XY_mat*a_Y1;
0660 err_Y1=max(abs(y1-y_ima));
0661 T_x=a_X1(1);
0662 T_y=a_Y1(1);
0663 GeometryCalib.CalibrationType='linear';
0664 GeometryCalib.focal=1;
0665 GeometryCalib.CoordUnit=[];
0666 GeometryCalib.Tx_Ty_Tz=[T_x T_y 1];
0667 GeometryCalib.R=[a_X1(2),a_X1(3),0;a_Y1(2),a_Y1(3),0;0,0,1];
0668
0669
0670 GeometryCalib.ErrorRms(1)=sqrt(mean((x1-x_ima).*(x1-x_ima)));
0671 GeometryCalib.ErrorMax(1)=max(abs(x1-x_ima));
0672 GeometryCalib.ErrorRms(2)=sqrt(mean((y1-y_ima).*(y1-y_ima)));
0673 GeometryCalib.ErrorMax(2)=max(abs(y1-y_ima));
0674
0675
0676
0677
0678
0679 function GeometryCalib=calib_tsai(Coord)
0680
0681
0682
0683 path_uvmat=which('uvmat');
0684 path_UVMAT=fileparts(path_uvmat);
0685 if isunix
0686
0687 xmlfile=fullfile(path_UVMAT,'PARAM_LINUX.xml');
0688 if exist(xmlfile,'file')
0689 t=xmltree(xmlfile);
0690 sparam=convert(t);
0691 end
0692 else
0693
0694 xmlfile=fullfile(path_UVMAT,'PARAM_WIN.xml');
0695 if exist(xmlfile,'file')
0696 t=xmltree(xmlfile);
0697 sparam=convert(t);
0698 end
0699 end
0700 if ~isfield(sparam,'GeometryCalib_exe')
0701 warndlg_uvmat(['calibration program <GeometryCalib_exe> undefined in parameter file ' xmlfile],'ERROR')
0702 return
0703 end
0704 Tsai_exe=sparam.GeometryCalib_exe;
0705 if ~exist(Tsai_exe,'file')
0706 warndlg_uvmat(['calibration program ' Tsai_exe ' does not exist'],'ERROR')
0707 return
0708 end
0709
0710 textcoord=num2str(Coord,4);
0711 dlmwrite('t.txt',textcoord,'');
0712
0713 eval(['!' Tsai_exe ' -f t.txt > tsaicalib.log']);
0714 if ~exist('calib.dat','file')
0715 warndlg_uvmat('no output from calibration program Tsai_exe: possibly too few points','ERROR')
0716 end
0717 calibdat=dlmread('calib.dat');
0718 GeometryCalib.CalibrationType='tsai';
0719 GeometryCalib.focal=calibdat(10);
0720 GeometryCalib.dpx_dpy=[calibdat(5) calibdat(6)];
0721 GeometryCalib.Cx_Cy=[calibdat(7) calibdat(8)];
0722 GeometryCalib.sx=calibdat(9);
0723 GeometryCalib.kappa1=calibdat(11);
0724 GeometryCalib.CoordUnit=[];
0725 GeometryCalib.Tx_Ty_Tz=[calibdat(12) calibdat(13) calibdat(14)];
0726 Rx_Ry_Rz=calibdat([15:17]);
0727 sa = sin(Rx_Ry_Rz(1)) ;
0728 ca=cos(Rx_Ry_Rz(1));
0729 sb=sin(Rx_Ry_Rz(2));
0730 cb =cos(Rx_Ry_Rz(2));
0731 sg =sin(Rx_Ry_Rz(3));
0732 cg =cos(Rx_Ry_Rz(3));
0733 r1 = cb * cg;
0734 r2 = cg * sa * sb - ca * sg;
0735 r3 = sa * sg + ca * cg * sb;
0736 r4 = cb * sg;
0737 r5 = sa * sb * sg + ca * cg;
0738 r6 = ca * sb * sg - cg * sa;
0739 r7 = -sb;
0740 r8 = cb * sa;
0741 r9 = ca * cb;
0742
0743 GeometryCalib.R=[r1,r2,r3;r4,r5,r6;r7,r8,r9];
0744
0745
0746 Calib.dpx=GeometryCalib.dpx_dpy(1);
0747 Calib.dpy=GeometryCalib.dpx_dpy(2);
0748 Calib.sx=GeometryCalib.sx;
0749 Calib.Cx=GeometryCalib.Cx_Cy(1);
0750 Calib.Cy=GeometryCalib.Cx_Cy(2);
0751 Calib.kappa1=GeometryCalib.kappa1;
0752 Calib.f=GeometryCalib.focal;
0753 Calib.Tx=GeometryCalib.Tx_Ty_Tz(1);
0754 Calib.Ty=GeometryCalib.Tx_Ty_Tz(2);
0755 Calib.Tz=GeometryCalib.Tx_Ty_Tz(3);
0756 Calib.R=GeometryCalib.R;
0757 X=Coord(:,1);
0758 Y=Coord(:,2);
0759 Z=Coord(:,3);
0760 x_ima=Coord(:,4);
0761 y_ima=Coord(:,5);
0762 [Xpoints,Ypoints]=px_XYZ(Calib,X,Y,Z);
0763
0764 GeometryCalib.ErrorRms(1)=sqrt(mean((Xpoints-x_ima).*(Xpoints-x_ima)));
0765 GeometryCalib.ErrorMax(1)=max(abs(Xpoints-x_ima));
0766 GeometryCalib.ErrorRms(2)=sqrt(mean((Ypoints-y_ima).*(Ypoints-y_ima)));
0767 GeometryCalib.ErrorMax(2)=max(abs(Ypoints-y_ima));
0768
0769
0770
0771
0772
0773
0774
0775
0776
0777
0778
0779
0780
0781
0782
0783
0784
0785
0786
0787
0788
0789
0790 function translation_Callback(hObject, eventdata, handles)
0791
0792
0793 function T_x_Callback(hObject, eventdata, handles)
0794
0795
0796
0797
0798
0799
0800
0801
0802
0803
0804
0805 function T_y_Callback(hObject, eventdata, handles)
0806
0807
0808
0809
0810
0811
0812
0813
0814 function T_z_Callback(hObject, eventdata, handles)
0815
0816
0817
0818
0819
0820
0821
0822
0823
0824 function rotation_Callback(hObject, eventdata, handles)
0825 angle_rot=(pi/180)*str2num(get(handles.Phi,'String'));
0826 Coord_cell=get(handles.ListCoord,'String');
0827 data=read_geometry_calib(Coord_cell);
0828 data.Coord(:,1)=cos(angle_rot)*data.Coord(:,1)+sin(angle_rot)*data.Coord(:,2);
0829 data.Coord(:,1)=-sin(angle_rot)*data.Coord(:,1)+cos(angle_rot)*data.Coord(:,2);
0830 set(handles.XObject,'String',num2str(data.Coord(:,1),4));
0831 set(handles.YObject,'String',num2str(data.Coord(:,2),4));
0832
0833
0834 function XImage_Callback(hObject, eventdata, handles)
0835 update_list(hObject, eventdata,handles)
0836
0837 function YImage_Callback(hObject, eventdata, handles)
0838 update_list(hObject, eventdata,handles)
0839
0840 function XObject_Callback(hObject, eventdata, handles)
0841 update_list(hObject, eventdata,handles)
0842
0843 function YObject_Callback(hObject, eventdata, handles)
0844 update_list(hObject, eventdata,handles)
0845
0846 function ZObject_Callback(hObject, eventdata, handles)
0847 update_list(hObject, eventdata,handles)
0848
0849 function update_list(hObject, eventdata, handles)
0850 str4=get(handles.XImage,'String');
0851 str5=get(handles.YImage,'String');
0852 str1=get(handles.XObject,'String');
0853 tt=double(str1);
0854 str2=get(handles.YObject,'String');
0855 str3=get(handles.ZObject,'String');
0856 if ~isempty(str1) & ~isequal(double(str1),32) & (isempty(str3)|isequal(double(str3),32))
0857 str3='0';
0858 end
0859 strline=[str1 ' | ' str2 ' | ' str3 ' | ' str4 ' | ' str5];
0860 Coord=get(handles.ListCoord,'String');
0861 val=get(handles.ListCoord,'Value');
0862 Coord{val}=strline;
0863 set(handles.ListCoord,'String',Coord)
0864
0865
0866
0867
0868 function ListCoord_Callback(hObject, eventdata, handles)
0869
0870
0871
0872
0873
0874
0875
0876 Coord_cell=get(handles.ListCoord,'String');
0877 val=get(handles.ListCoord,'Value');
0878 if length(Coord_cell)>0
0879 coord_str=Coord_cell{val};
0880 k=findstr('|',coord_str);
0881 if isempty(k)
0882 return
0883 end
0884 set(handles.XObject,'String',coord_str(1:k(1)-5))
0885 set(handles.YObject,'String',coord_str(k(1)+5:k(2)-5))
0886 set(handles.ZObject,'String',coord_str(k(2)+5:k(3)-5))
0887 set(handles.XImage,'String',coord_str(k(3)+5:k(4)-5))
0888 set(handles.YImage,'String',coord_str(k(4)+5:end))
0889 huvmat=findobj(allchild(0),'Name','uvmat');
0890 hplot=findobj(huvmat,'Tag','axes3');
0891 h_menu_coord=findobj(huvmat,'Tag','menu_coord');
0892 menu=get(h_menu_coord,'String');
0893 choice=get(h_menu_coord,'Value');
0894 if iscell(menu)
0895 option=menu{choice};
0896 else
0897 option='px';
0898 end
0899 if isequal(option,'phys')
0900 XCoord=str2num(coord_str(1:k(1)-5));
0901 YCoord=str2num(coord_str(k(1)+5:k(2)-5));
0902 elseif isequal(option,'px')|| isequal(option,'')
0903 XCoord=str2num(coord_str(k(3)+5:k(4)-5));
0904 YCoord=str2num(coord_str(k(4)+5:end));
0905 else
0906 warndlg_uvmat('the choice in menu_coord of uvmat must be px or phys ','ERROR')
0907 end
0908 huvmat=findobj(allchild(0),'Name','uvmat');
0909 hplot=findobj(huvmat,'Tag','axes3');
0910 hhh=findobj(hplot,'Tag','calib_marker');
0911 if isempty(hhh)
0912 axes(hplot)
0913 line(XCoord,YCoord,'Color','m','Tag','calib_marker','LineStyle','.','Marker','o','MarkerSize',20);
0914 else
0915 set(hhh,'XData',XCoord)
0916 set(hhh,'YData',YCoord)
0917 end
0918 end
0919
0920
0921 function translation_plus_Callback(hObject, eventdata, handles)
0922
0923 T=[0 0 0];
0924 T_x=get(handles.T_x,'String');
0925 T_y=get(handles.T_y,'String');
0926 T_z=get(handles.T_z,'String');
0927 if ~isempty(T_x)
0928 T(1)=str2num(T_x);
0929 end
0930 if ~isempty(T_y)
0931 T(2)=str2num(T_y);
0932 end
0933 if ~isempty(T_z)
0934 T(3)=str2num(T_z);
0935 end
0936 translation(handles,T)
0937
0938
0939
0940
0941 function translation_minus_Callback(hObject, eventdata, handles)
0942
0943 T=[0 0 0];
0944 T_x=get(handles.T_x,'String');
0945 T_y=get(handles.T_y,'String');
0946 T_z=get(handles.T_z,'String');
0947 if ~isempty(T_x)
0948 T(1)=-str2num(T_x);
0949 end
0950 if ~isempty(T_y)
0951 T(2)=-str2num(T_y);
0952 end
0953 if ~isempty(T_z)
0954 T(3)=-str2num(T_z);
0955 end
0956 translation(handles,T)
0957
0958
0959
0960 function translation(handles,T)
0961 Coord_cell=get(handles.ListCoord,'String');
0962 data=read_geometry_calib(Coord_cell);
0963
0964 data.Coord(:,1)=T(1)+data.Coord(:,1);
0965 data.Coord(:,2)=T(2)+data.Coord(:,2);
0966 data.Coord(:,3)=T(3)+data.Coord(:,3);
0967 data.Coord(:,[4 5])=data.Coord(:,[4 5]);
0968 for i=1:size(data.Coord,1)
0969 for j=1:5
0970 Coord{i,j}=num2str(data.Coord(i,j),4);
0971 end
0972 end
0973 Tabchar=cell2tab(Coord,' | ');
0974 set(handles.ListCoord,'Value',1)
0975 set(handles.ListCoord,'String',Tabchar)
0976
0977
0978
0979 function rotation_plus_Callback(hObject, eventdata, handles)
0980 Phi=0;
0981 Phi=get(handles.Phi,'String');
0982 if ~isempty(Phi)
0983 Phi=str2num(Phi);
0984 end
0985 rotation(handles,Phi)
0986
0987
0988
0989 function rotation_minus_Callback(hObject, eventdata, handles)
0990 Phi=0;
0991 Phi=get(handles.Phi,'String');
0992 if ~isempty(Phi)
0993 Phi=-str2num(Phi);
0994 end
0995 rotation(handles,Phi)
0996
0997
0998
0999 function rotation(handles,Phi)
1000 O_x=str2num(get(handles.O_x,'String'));
1001 O_y=str2num(get(handles.O_y,'String'));
1002 if isempty(O_x)
1003 O_x=0;
1004 end
1005 if isempty(O_y)
1006 O_y=0;
1007 end
1008 Coord_cell=get(handles.ListCoord,'String');
1009 data=read_geometry_calib(Coord_cell);
1010
1011 r1=cos(pi*Phi/180);
1012 r2=-sin(pi*Phi/180);
1013 r3=sin(pi*Phi/180);
1014 r4=cos(pi*Phi/180);
1015 x=data.Coord(:,1);
1016 y=data.Coord(:,2);
1017 data.Coord(:,1)=r1*x+r2*y;
1018 data.Coord(:,2)=r3*x+r4*y;
1019
1020 for i=1:size(data.Coord,1)
1021 for j=1:5
1022 Coord{i,j}=num2str(data.Coord(i,j),4);
1023 end
1024 end
1025 Tabchar=cell2tab(Coord,' | ');
1026 set(handles.ListCoord,'Value',1)
1027 set(handles.ListCoord,'String',Tabchar)
1028
1029
1030 function O_x_Callback(hObject, eventdata, handles)
1031
1032
1033 function O_y_Callback(hObject, eventdata, handles)
1034
1035
1036 function O_z_Callback(hObject, eventdata, handles)
1037
1038
1039
1040 function edit_append_Callback(hObject, eventdata, handles)
1041
1042
1043
1044
1045 choice=get(handles.edit_append,'Value');
1046 if choice==1
1047 Coord=get(handles.ListCoord,'String');
1048 val=length(Coord);
1049 if val>=1 & isequal(Coord{val},'')
1050 val=val-1;
1051 end
1052 Coord{val+1}='';
1053 set(handles.ListCoord,'String',Coord)
1054 set(handles.ListCoord,'Value',val+1)
1055 end
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082 function NEW_Callback(hObject, eventdata, handles)
1083
1084 huvmat=findobj(allchild(0),'Name','uvmat');
1085 hchild=get(huvmat,'children');
1086 hcoord=findobj(hchild,'Tag','menu_coord');
1087 coordtype=get(hcoord,'Value');
1088 haxes=findobj(hchild,'Tag','axes3');
1089 AxeData=get(haxes,'UserData');
1090 if ~isequal(hcoord,2)
1091 set(hcoord,'Value',2)
1092 huvmat=uvmat(AxeData);
1093 'relancer uvmat'
1094 end
1095 if ~isfield(AxeData,'ZoomAxes')
1096 warndlg_uvmat('first draw a window around a grid marker','ERRROR')
1097 return
1098 end
1099 XLim=get(AxeData.ZoomAxes,'XLim');
1100 YLim=get(AxeData.ZoomAxes,'YLim');
1101 np=size(AxeData.A);
1102 ind_sub_x=round(XLim)
1103 ind_sub_y=np(1)-round(YLim)
1104 Mfiltre=AxeData.A([ind_sub_y(2):ind_sub_y(1)] ,ind_sub_x,:);
1105 Mfiltre_norm=double(Mfiltre);
1106 Mfiltre_norm=Mfiltre_norm/sum(sum(Mfiltre_norm));
1107 Mfiltre_norm=100*(Mfiltre_norm-mean(mean(Mfiltre_norm)));
1108 Atype=class(AxeData.A)
1109 Data.NbDim=2;
1110 Data.A=filter2(Mfiltre_norm,double(AxeData.A));
1111 Data.A=feval(Atype,Data.A);
1112 Data.AName='image';
1113 Data.AX=AxeData.AX;
1114 Data.AY=AxeData.AY;
1115 Data.CoordType='px';
1116 plot_field(Data)
1117
1118
1119
1120 function HELP_Callback(hObject, eventdata, handles)
1121
1122
1123
1124 path_to_uvmat=which ('uvmat');
1125 pathelp=fileparts(path_to_uvmat);
1126 helpfile=fullfile(pathelp,'UVMAT_DOC','uvmat_doc.html');
1127 if isempty(dir(helpfile)), warndlg_uvmat('The help file uvmat_doc.html needs to be put in the directory UVMAT/UVMAT_DOC','ERROR')
1128 else
1129 web([helpfile '#geometry_calib'])
1130 end
1131
1132
1133
1134 function key_press_fcn(hObject,eventdata,handles)
1135 hh=get(hObject,'parent');
1136 xx=double(get(hh,'CurrentCharacter'))
1137
1138 if isequal(xx,8)
1139 Coord_cell=get(handles.ListCoord,'String');
1140 data=read_geometry_calib(Coord_cell);
1141 Coord=[];
1142 if isfield(data,'Coord')
1143 Coord=data.Coord;
1144 end
1145 val=get(handles.ListCoord,'Value');
1146 Coord(val,:)=[];
1147 CoordCell={};
1148 for iline=1:size(Coord,1)
1149 for j=1:5
1150 CoordCell{iline,j}=num2str(Coord(iline,j),4);
1151 end
1152 end
1153 Tabchar=cell2tab(CoordCell,' | ');
1154 val=min(size(Coord,1),val);
1155 set(handles.ListCoord,'Value',max(val,1))
1156 set(handles.ListCoord,'String',Tabchar)
1157 ListCoord_Callback(hObject, eventdata, handles)
1158 end
1159
1160
1161
1162 function append_point_Callback(hObject, eventdata, handles)
1163
1164 Coord=get(handles.ListCoord,'String');
1165 val=length(Coord);
1166 if val>=1 & isequal(Coord{val},'')
1167 val=val-1;
1168 end
1169 Coord{val+1}='';
1170 set(handles.ListCoord,'String',Coord)
1171 set(handles.ListCoord,'Value',val+1)
1172
1173
1174