0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022 function varargout = set_grid(varargin)
0023
0024
0025
0026
0027 gui_Singleton = 1;
0028 gui_State = struct('gui_Name', mfilename, ...
0029 'gui_Singleton', gui_Singleton, ...
0030 'gui_OpeningFcn', @set_grid_OpeningFcn, ...
0031 'gui_OutputFcn', @set_grid_OutputFcn, ...
0032 'gui_LayoutFcn', [] , ...
0033 'gui_Callback', []);
0034 if nargin & isstr(varargin{1})
0035 gui_State.gui_Callback = str2func(varargin{1});
0036 end
0037
0038 if nargout
0039 [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
0040 else
0041 gui_mainfcn(gui_State, varargin{:});
0042 end
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060 function set_grid_OpeningFcn(hObject, eventdata, handles,inputfile)
0061
0062
0063 handles.output = hObject;
0064
0065
0066 guidata(hObject, handles);
0067
0068
0069
0070
0071 set(hObject,'DeleteFcn',@closefcn)
0072 set(handles.TITLE,'Value',1)
0073 set(handles.ObjectStyle,'Value',1)
0074 set(handles.ProjMode,'Value',1)
0075 set(handles.MenuCoord,'ListboxTop',1)
0076 set(handles.MenuCoord,'Value',1);
0077 set(handles.MenuCoord,'String',{'phys';'px'});
0078 if exist('inputfile','var')& ~isempty(inputfile)
0079 set(handles.image_1,'String',inputfile)
0080 set(handles.image_2,'String',inputfile)
0081 end
0082
0083
0084
0085 function varargout = set_grid_OutputFcn(hObject, eventdata, handles)
0086
0087
0088
0089
0090
0091
0092 varargout{1} = handles.output;
0093 varargout{2}=handles;
0094
0095
0096 function ObjectStyle_Callback(hObject, eventdata, handles)
0097
0098 ProjMode_Callback(hObject, eventdata, handles)
0099
0100
0101 function xObject_Callback(hObject, eventdata, handles)
0102
0103
0104 function yObject_Callback(hObject, eventdata, handles)
0105
0106
0107
0108 function zObject_Callback(hObject, eventdata, handles)
0109
0110
0111
0112
0113 function ProjMode_Callback(hObject, eventdata, handles)
0114 menu=get(handles.ProjMode,'String');
0115 value=get(handles.ProjMode,'Value');
0116 ProjMode=menu{value};
0117 menu=get(handles.ObjectStyle,'String');
0118 value=get(handles.ObjectStyle,'Value');
0119 ObjectStyle=menu{value};
0120 test3D=isequal(get(handles.ZObject,'Visible'),'on');
0121 if isequal(ObjectStyle,'plane')||isequal(ObjectStyle,'volume')
0122 set(handles.Phi,'Visible','on')
0123 if test3D
0124 set(handles.Theta,'Visible','on')
0125 set(handles.Psi,'Visible','on')
0126 end
0127 set(handles.XMin,'Visible','on')
0128 set(handles.XMax,'Visible','on')
0129 set(handles.YMin,'Visible','on')
0130 set(handles.YMax,'Visible','on')
0131 if test3D
0132 set(handles.Theta,'Visible','on')
0133 set(handles.Psi,'Visible','on')
0134 set(handles.ZMin,'Visible','on')
0135 set(handles.ZMax,'Visible','on')
0136 end
0137 else
0138 set(handles.Phi,'Visible','off')
0139 set(handles.Theta,'Visible','off')
0140 set(handles.Psi,'Visible','off')
0141 set(handles.XMin,'Visible','off')
0142 set(handles.XMax,'Visible','off')
0143 set(handles.YMin,'Visible','off')
0144 if isequal(ProjMode,'interp')
0145 set(handles.YMax,'Visible','off')
0146 else
0147 set(handles.YMax,'Visible','on')
0148 end
0149 if isequal(ObjectStyle,'rectangle')|isequal(ObjectStyle,'ellipse')
0150 set(handles.XMax,'Visible','on')
0151 else
0152 set(handles.XMax,'Visible','off')
0153 end
0154 set(handles.ZMin,'Visible','off')
0155 set(handles.ZMax,'Visible','off')
0156 end
0157 if isequal(ProjMode,'projection')|isequal(ProjMode,'inside')|isequal(ProjMode,'outside')|isequal(ObjectStyle,'points')
0158 set(handles.DX,'Visible','off')
0159 set(handles.DY,'Visible','off')
0160 set(handles.DZ,'Visible','off')
0161 else
0162 set(handles.DX,'Visible','on')
0163 set(handles.DY,'Visible','on')
0164 if test3D
0165 set(handles.DZ,'Visible','on')
0166 end
0167 end
0168
0169
0170
0171 function TITLE_Callback(hObject, eventdata, handles)
0172 hsetobject=get(handles.TITLE,'parent');
0173 SetData=get(hsetobject,'UserData');
0174
0175 menu=get(handles.TITLE,'String');
0176 value=get(handles.TITLE,'Value');
0177 titl=menu{value};
0178 if isequal(titl,'POINTS')
0179 menu_style={'points'};
0180 menu_proj={'projection';'interp';'filter';'none'};
0181 elseif isequal(titl,'LINE')
0182 menu_style={'line';'polyline';'rectangle';'polygon';'ellipse'};
0183 menu_proj={'projection';'interp';'filter';'none'};
0184 elseif isequal(titl,'PATCH')
0185 menu_style={'rectangle';'polygon';'ellipse'};
0186 menu_proj={'inside';'outside';'none'};
0187 elseif isequal(titl,'PLANE')
0188 menu_style={'plane'};
0189 menu_proj={'projection';'interp'};
0190 elseif isequal(titl,'VOLUME')
0191 menu_style={'volume'};
0192 menu_proj={'none'};
0193
0194 end
0195 set(handles.ObjectStyle,'String',menu_style)
0196 set(handles.ObjectStyle,'Value',1)
0197 set(handles.ProjMode,'String',menu_proj)
0198 set(handles.ProjMode,'Value',1)
0199 if isfield(SetData,'ParentButton')
0200 update_parentbutton(SetData.ParentButton,titl)
0201 end
0202 ObjectStyle_Callback(hObject, eventdata, handles)
0203
0204
0205 function update_parentbutton(ParentButton,titl)
0206
0207 if isstruct(ParentButton)
0208 parentfields=fields(ParentButton);
0209 for ibutton=1:length(parentfields)
0210 buttonhandle=eval(['ParentButton.' parentfields{ibutton}]);
0211 if ishandle(buttonhandle)
0212 set(buttonhandle,'Value',0)
0213 set(buttonhandle,'BackgroundColor',[0 1 0])
0214 end
0215 end
0216 if isfield(ParentButton,titl)
0217 buttonhandle=eval(['ParentButton.' titl]);
0218 if ishandle(buttonhandle)
0219 set(buttonhandle,'Value',1)
0220 set(buttonhandle,'BackgroundColor',[1 1 0])
0221 end
0222 end
0223 end
0224
0225 function Phi_Callback(hObject, eventdata, handles)
0226 update_slider(hObject, eventdata,handles)
0227
0228 function Theta_Callback(hObject, eventdata, handles)
0229 update_slider(hObject, eventdata,handles)
0230
0231 function update_slider(hObject, eventdata,handles)
0232
0233 Phi=(pi/180)*str2num(get(handles.Phi,'String'));
0234 Theta=(pi/180)*str2num(get(handles.Theta,'String'));
0235
0236
0237 NormVec_X=-sin(Phi)*sin(Theta);
0238 NormVec_Y=cos(Phi)*sin(Theta);
0239 NormVec_Z=cos(Theta);
0240 huvmat=findobj('Tag','uvmat');
0241 UvData=get(huvmat,'UserData');
0242 Z=NormVec_X *(UvData.X)+NormVec_Y *(UvData.Y)+NormVec_Z *(UvData.Z);
0243 set(handles.z_slider,'Min',min(Z))
0244 set(handles.z_slider,'Max',max(Z))
0245 ZMax_Callback(hObject, eventdata, handles)
0246
0247 function DX_Callback(hObject, eventdata, handles)
0248
0249
0250 function DY_Callback(hObject, eventdata, handles)
0251
0252
0253 function DZ_Callback(hObject, eventdata, handles)
0254
0255
0256
0257
0258
0259 function import_Callback(hObject, eventdata, handles)
0260
0261 oldfile='';
0262 huvmat=findobj('Tag','uvmat');
0263 if isempty(huvmat)
0264 huvmat=findobj(allchild(0),'Name','series');
0265 end
0266 hchild=get(huvmat,'Children');
0267 hrootpath=findobj(hchild,'Tag','RootPath');
0268 oldfile=get(hrootpath,'String');
0269 if iscell(oldfile)
0270 oldfile=oldfile{1};
0271 end
0272
0273 [FileName, PathName, filterindex] = uigetfile( ...
0274 {'*.xml;*.mat', ' (*.xml,*.mat)';
0275 '*.xml', '.xml files '; ...
0276 '*.mat', '.mat matlab files '}, ...
0277 'Pick a file',oldfile);
0278 fileinput=[PathName FileName];
0279 testblank=findstr(fileinput,' ');
0280 if ~isempty(testblank)
0281 errordlg('forbidden input file name: contain blanks')
0282 return
0283 end
0284 sizf=size(fileinput);
0285 if (~ischar(fileinput)|~isequal(sizf(1),1)),return;end
0286
0287
0288 t=xmltree(fileinput);
0289 s=convert(t);
0290
0291 title=set_title(s.Style,s.ProjMode);
0292
0293
0294
0295
0296
0297
0298
0299
0300
0301
0302
0303
0304
0305
0306
0307
0308
0309
0310
0311
0312
0313
0314
0315 testmode=0;
0316 if isfield(s,'ProjMode')
0317 menu=get(handles.ProjMode,'String');
0318 for iline=1:length(menu)
0319 if isequal(menu{iline},s.ProjMode)
0320 set(handles.ProjMode,'Value',iline)
0321 testmode=1;
0322 break
0323 end
0324 end
0325 end
0326
0327 ProjMode_Callback(hObject, eventdata, handles);
0328 if isfield(s,'CoordType')
0329 if isequal(s.CoordType,'phys')
0330 set(handles.MenuCoord,'Value',1)
0331 elseif isequal(s.CoordType,'px')
0332 set(handles.MenuCoord,'Value',2)
0333 else
0334 warndlg('unknown CoordType (px or phys) in set_grid.m')
0335 end
0336 end
0337 if isfield(s,'XMax')
0338 set(handles.XMax,'String',s.XMax)
0339 end
0340 if isfield(s,'XMin')
0341 set(handles.XMin,'String',s.XMin)
0342 end
0343 if isfield(s,'YMax')
0344 set(handles.YMax,'String',s.YMax)
0345 end
0346 if isfield(s,'YMin')
0347 set(handles.YMin,'String',s.YMin)
0348 end
0349 if isfield(s,'DX')
0350 set(handles.DX,'String',s.DX)
0351 end
0352 if isfield(s,'DY')
0353 set(handles.DY,'String',s.DY)
0354 end
0355 if ~isfield(s,'Coord')
0356 XObject='0';
0357 YObject='0';
0358 elseif ischar(s.Coord)
0359 line=str2num(s.Coord);
0360 XObject=num2str(line(1));
0361 YObject=num2str(line(2));
0362 else
0363 for i=1:length(s.Coord)
0364 line=str2num(s.Coord{i});
0365 XObject{i}=num2str(line(1));
0366 YObject{i}=num2str(line(2));
0367 end
0368 end
0369 set(handles.XObject,'String',XObject)
0370 set(handles.YObject,'String',YObject)
0371
0372
0373
0374
0375 function closefcn(gcbo,eventdata)
0376 huvmat=findobj(allchild(0),'Name','uvmat');
0377 parent_button=findobj(huvmat,'Tag','grid');
0378 if ~isempty(parent_button)
0379 set(parent_button,'Value',0)
0380 tag=get(parent_button,'Tag');
0381 if isequal(tag,'edit')
0382 set(parent_button,'BackgroundColor',[0.7 0.7 0.7]);
0383 else
0384 set(parent_button,'BackgroundColor',[0 1 0]);
0385 end
0386 end
0387
0388
0389
0390 function edit_Callback(hObject, eventdata, handles)
0391 hsetobject=get(hObject,'parent');
0392 SetData=get(hsetobject,'UserData');
0393
0394 huvmat=findobj('Tag','uvmat');
0395 UvData=get(huvmat,'UserData');
0396 if isfield(UvData,'CuurentObjectIndex')
0397 IndexObj=UvData.CurrentObjectIndex;
0398 else
0399 IndexObj=[];
0400 end
0401 ObjectData=read_set_grid(handles);
0402 [UvData,IndexObj]=update_obj(UvData,IndexObj,ObjectData,SetData.PlotHandles);
0403 uvmat('write_plot_param',PlotHandles,UvData.Object{IndexObj}.PlotParam);
0404 SetData.IndexObj=IndexObj;
0405 set(gcbf,'UserData',SetData)
0406 set(huvmat,'UserData',UvData)
0407
0408
0409
0410 function MenuCoord_Callback(hObject, eventdata, handles)
0411
0412
0413
0414
0415 function delete_Callback(hObject, eventdata, handles)
0416
0417
0418
0419 huvmat=findobj('Name','uvmat');
0420 UvData=get(huvmat,'UserData');
0421 if isfield(UvData,'CurrentObjectIndex')
0422 IndexObj=UvData.CurrentObjectIndex;
0423 else
0424 IndexObj=[];
0425 end
0426 delete_object(IndexObj);
0427
0428
0429 function YMin_Callback(hObject, eventdata, handles)
0430
0431
0432
0433
0434
0435
0436
0437
0438 function ZMin_Callback(hObject, eventdata, handles)
0439
0440
0441 function ZMax_Callback(hObject, eventdata, handles)
0442 DZ=str2num(get(handles.ZMax,'String'));
0443 ZMin=get(handles.z_slider,'Min');
0444 ZMax=get(handles.z_slider,'Max');
0445 rel_step(1)=DZ/(ZMax-ZMin);
0446 rel_step(2)=0.2;
0447 set(handles.z_slider,'SliderStep',rel_step)
0448
0449 function YMax_Callback(hObject, eventdata, handles)
0450
0451
0452 function XMin_Callback(hObject, eventdata, handles)
0453
0454
0455 function XMax_Callback(hObject, eventdata, handles)
0456
0457
0458
0459 function save_Callback(hObject, eventdata, handles)
0460
0461 Object=read_set_object(handles);
0462 DX=Object.DX;
0463 DY=Object.DY;
0464 RangeX=Object.RangeX;
0465 RangeY=Object.RangeY;
0466 array_realx=[RangeX(2):DX:RangeX(1)];
0467 array_realy=[RangeY(2):DY:RangeY(1)];
0468 nx_patch=length(array_realx);
0469 ny_patch=length(array_realy);
0470 [grid_realx,grid_realy]=meshgrid(array_realx,array_realy);
0471 grid_real(:,1)=reshape(grid_realx,nx_patch*ny_patch,1);
0472 grid_real(:,2)=reshape(grid_realy,nx_patch*ny_patch,1);
0473 grid_real(:,3)=zeros(nx_patch*ny_patch,1);
0474
0475 imageA=get(handles.image_1,'String');
0476 imageB=get(handles.image_2,'String');
0477 testB=1;
0478 if isempty(imageA) | isequal(imageA,'')
0479 if isempty(imageB) | isequal(imageB,'')
0480 warndlg_uvmat('at least one image file name must be introduced','ERROR')
0481 else
0482 imageA=imageB;
0483 testB=0;
0484 end
0485 end
0486 if isempty(imageB) || isequal(imageB,'') || isequal(imageA,imageB)
0487 testB=0;
0488 end
0489
0490 testexist=exist(imageA,'file');
0491 if isequal(testexist,0)
0492 warndlg_uvmat(['input image file' imageA 'does not exist'],'ERROR')
0493 return
0494 end
0495 [Pathsub,RootFile,field_count,str2,str_a,str_b,ext,nom_type,subdir]=name2display(imageA);
0496 form=imformats(ext([2:end]));
0497 if isempty(form)
0498 warndlg_uvmat(['error in read_image.m: ' imageA ' is not an image name recognized by Matlab '],'ERROR')
0499 return
0500 end
0501 fileAxml=[fullfile(Pathsub,RootFile) '.xml'];
0502 [XmlDataA,error]=imadoc2struct(fileAxml);
0503 if isfield(XmlDataA,'GeometryCalib')
0504 tsaiA=XmlDataA.GeometryCalib;
0505 else
0506 msgbox_uvmat('WARNING','no geometric calibration available for image A')
0507 tsaiA=[];
0508 end
0509
0510
0511 [grid_imaA(:,1),grid_imaA(:,2)]=px_XYZ(tsaiA,grid_real(:,1),grid_real(:,2),0);
0512
0513 A=imread(imageA);
0514 siz=size(A);
0515 npxA=siz(2);
0516 npyA=siz(1);
0517
0518 flagA=grid_imaA(:,1)>0 & grid_imaA(:,1)<npxA & grid_imaA(:,2)>0 & grid_imaA(:,2)<npyA;
0519
0520 if testB
0521 testexist=exist(imageB,'file');
0522 if isequal(testexist,0)
0523 warndlg_uvmat(['input image file' imageB 'does not exist'],'ERROR')
0524 return
0525 end
0526 [Pathsub,RootFile,field_count,str2,str_a,str_b,ext,nom_type,subdir]=name2display(imageB);
0527 form=imformats(ext([2:end]));
0528 if isempty(form)
0529 warndlg_uvmat(['error in read_image.m: ' imageB ' is not an image name recognized by Matlab '],'ERROR')
0530 return
0531 end
0532 fileBxml=[fullfile(Pathsub,RootFile) '.xml'];
0533 [XmlDataB,error]=imadoc2struct(fileBxml);
0534 if isfield(XmlDataB,'GeometryCalib')
0535 tsaiB=XmlDataB.GeometryCalib;
0536 else
0537 warndlg_uvmat('no geometric calibration available for image B','WARNING')
0538 tsaiB=[];
0539 end
0540
0541
0542 [grid_imaB(:,1),grid_imaB(:,2)]=px_XYZ(tsaiB,grid_real(:,1),grid_real(:,2),0);
0543
0544 B=imread(imageB);
0545 siz=size(B);
0546 npxB=siz(2);
0547 npyB=siz(1);
0548
0549 flagB=grid_imaB(:,1)>0 & grid_imaB(:,1)<npxB & grid_imaB(:,2)>0 & grid_imaB(:,2)<npyB;
0550 end
0551 if testB
0552 ind_good=find(flagA==1&flagB==1);
0553 XimaB=grid_imaB(ind_good,1);
0554 YimaB=grid_imaB(ind_good,2);
0555 else
0556 ind_good=find(flagA==1);
0557 end
0558 XimaA=grid_imaA(ind_good,1);
0559 YimaA=grid_imaA(ind_good,2);
0560
0561 grid_real_x=grid_real(ind_good,1);
0562 grid_real_y=grid_real(ind_good,2);
0563 nx_patch_new=length(grid_real_x);
0564 grid_real2(:,1)=grid_real_x;
0565 grid_real2(:,2)=grid_real_y;
0566 grid_real2(:,3)=zeros(nx_patch_new,1);
0567 [grid_pix_A(:,1),grid_pix_A(:,2)]=px_XYZ(tsaiA,grid_real2(:,1),grid_real2(:,2));
0568 if testB
0569 [grid_pix_B(:,1),grid_pix_B(:,2)]=px_XYZ(tsaiB,grid_real2(:,1),grid_real2(:,2));
0570 end
0571
0572
0573 nbpointsA=size(grid_pix_A);
0574 XA=grid_pix_A(:,1);
0575 YA=grid_pix_A(:,2);
0576 unitcolumn=32*ones(size(XA));
0577 Xchar=num2str(XA);
0578 blanc=char(unitcolumn);
0579 Ychar=num2str(YA);
0580 tete=['1 ' num2str(nbpointsA(1))];
0581 txt=[Xchar blanc Ychar];
0582 textgrid={tete;txt};
0583 textout=char(textgrid);
0584 Answer = msgbox_uvmat('INPUT_TXT','grid file name (*.grid)',fullfile(Pathsub,'gridA.grid'));
0585
0586 dlmwrite(Answer,textout,'');
0587 msgbox_uvmat('CONFIRMATION',[Answer ' written as ASCII text file']);
0588 if testB
0589 nbpointsB=size(grid_pix_B);
0590 XB=grid_pix_B(:,1);
0591 YB=grid_pix_B(:,2);
0592 unitcolumn=32*ones(size(XB));
0593 Xchar=num2str(XB);
0594 blanc=char(unitcolumn);
0595 Ychar=num2str(YB);
0596 tete=['1 ' num2str(nbpointsB(1))];
0597 txt=[Xchar blanc Ychar];
0598 textgrid={tete;txt};
0599 textout=char(textgrid);
0600 Answer = msgbox_uvmat('INPUT_TXT','grid file name (*.grid)',fullfile(Pathsub,'gridB.grid'));
0601 dlmwrite(Answer,textout,'');
0602 msgbox_uvmat('CONFIRMATION',[Answer ' written as ASCII text file']);
0603 end
0604
0605
0606
0607 function TITLE=set_title(Style,ProjMode)
0608
0609 if isequal(Style,'points')
0610 TITLE='POINTS';
0611 elseif isequal(Style,'line')|isequal(Style,'polyline')
0612 TITLE='LINE';
0613 elseif isequal(Style,'plane')
0614 TITLE='PLANE';
0615 elseif isequal(Style,'volume')
0616 TITLE='VOLUME';
0617 elseif isequal(Style,'polygon')|isequal(Style,'rectangle')|isequal(Style,'ellipse')
0618 if isequal(ProjMode,'inside')|isequal(ProjMode,'outside')
0619 TITLE='PATCH';
0620 else
0621 TITLE='LINE';
0622 end
0623 end
0624
0625
0626
0627 function z_slider_Callback(hObject, eventdata, handles)
0628
0629 Z_value=get(handles.z_slider,'Value');
0630
0631
0632 Phi=(pi/180)*str2num(get(handles.Phi,'String'));
0633 Theta=(pi/180)*str2num(get(handles.Theta,'String'));
0634
0635
0636 NormVec_X=-sin(Phi)*sin(Theta);
0637 NormVec_Y=cos(Phi)*sin(Theta);
0638 NormVec_Z=cos(Theta);
0639
0640
0641 set(handles.XObject,'String',num2str(NormVec_X*Z_value))
0642 set(handles.YObject,'String',num2str(NormVec_Y*Z_value))
0643 set(handles.ZObject,'String',num2str(NormVec_Z*Z_value))
0644 edit_Callback(hObject, eventdata, handles)
0645
0646
0647
0648 function XObject_Callback(hObject, eventdata, handles)
0649
0650
0651 function YObject_Callback(hObject, eventdata, handles)
0652
0653
0654
0655
0656 function ZObject_Callback(hObject, eventdata, handles)
0657
0658
0659 function image_2_Callback(hObject, eventdata, handles)
0660
0661
0662
0663
0664
0665
0666
0667
0668
0669 function image_1_Callback(hObject, eventdata, handles)
0670
0671
0672
0673
0674
0675
0676
0677
0678
0679 function HELP_Callback(hObject, eventdata, handles)
0680 path_to_uvmat=which ('uvmat');
0681 pathelp=fileparts(path_to_uvmat);
0682 helpfile=fullfile(pathelp,'UVMAT_DOC','uvmat_doc.html');
0683 if isempty(dir(helpfile)), errordlg('Please put the help file uvmat_doc.html in the directory UVMAT/UVMAT_DOC')
0684 else
0685 web([helpfile '#set_grid'])
0686 end
0687