Changeset 82 for trunk/src/uvmat.m


Ignore:
Timestamp:
Apr 15, 2010, 5:12:42 AM (14 years ago)
Author:
sommeria
Message:

mouse_up: improve zoom : keep the selected point at the same place on the graph
plot_field: memorize the max coordiantes on the graph (AxeData?) for zoom out
set_object: input possibilities extende to restrict menu (for mask objects)
uvmat: improvement of mask creation
civ: select mask option for civ2 when select(ed for civ1

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/uvmat.m

    r81 r82  
    30853085
    30863086%read the rootfile input display
    3087 FileExt=get(handles.FileExt,'String');
     3087[FileName,RootPath,FileBase,FileIndices,FileExt]=read_file_boxes(handles);
    30883088[P,F,str1,str2,str_a,str_b,E,NomType]=name2display(['xxx' get(handles.FileIndex,'String') FileExt]);
    30893089NomTypeNew=NomType;%default
     
    31033103        elseif isequal(NomType,'_i1-i2')
    31043104            NomTypeNew='_i';
     3105            % TODO: look for other types
    31053106        end 
    31063107    end
     
    31923193RootPath_1=get(handles.RootPath_1,'String');
    31933194RootFile_1=get(handles.RootFile_1,'String');
    3194 if isempty(RootPath_1)|isequal(RootPath_1,'')
     3195if isempty(RootPath_1)||isequal(RootPath_1,'')
    31953196    set(handles.RootPath_1,'String','"')
    31963197end
    3197 if isempty(RootFile_1) | isequal(RootFile_1,'')
     3198if isempty(RootFile_1) || isequal(RootFile_1,'')
    31983199    set(handles.RootFile_1,'String','"')
    31993200end
    3200 if ~isempty(RootFile_1)&(isequal(RootFile_1(1),'/')|isequal(RootFile_1(1),'\'))
     3201if ~isempty(RootFile_1)&&(isequal(RootFile_1(1),'/')||isequal(RootFile_1(1),'\'))
    32013202    RootFile_1(1)=[];
    32023203end
     
    32493250        filebase_1=fullfile(RootPath_1,RootFile_1);
    32503251        SubDir_1=get(handles.SubDir,'String');
    3251         if isempty(SubDir_1)|isequal(SubDir_1,'')
     3252        if isempty(SubDir_1)||isequal(SubDir_1,'')
    32523253            if isfield(UvData,'SubDir_1')
    32533254                SubDir_1=UvData.SubDir_1;%retrieve previous subdir
     
    32563257            end
    32573258        end
    3258         if isequal(NomType_1,'#_ab')|isequal(NomType_1,'_i1-i2_j')|isequal(NomType_1,'_i_j1-j2')|isequal(NomType_1,'_i1-i2')
     3259        str1=get(handles.i1,'String');
     3260        str_a=get(handles.j1,'String');
     3261        if isequal(NomType_1,'#_ab')||isequal(NomType_1,'_i1-i2_j')||isequal(NomType_1,'_i_j1-j2')||isequal(NomType_1,'_i1-i2')
    32593262            NomTypeNew=NomType_1;
    32603263        elseif isequal(NomType_1,'#a')
    3261              [filename,idetect,n1,na,n2,nb,SubDir_1]=name_generator(filebase_1, str2num(str1),str2num(str_a),'.nc','#_ab',0,[],[],SubDir_1);
     3264             [filename, n1,na,n2,nb,SubDir_1]=name_generator(filebase_1, str2num(str1),stra2num(str_a),'.nc','#_ab',0,[],[],SubDir_1);
    32623265             NomTypeNew='#_ab';
    32633266        elseif isequal(NomType_1,'_i_j')
    3264              [filename,idetect,n1,na,n2,nb,SubDir_1]=name_generator(filebase_1,str2num(str1),str2num(str_a),'.nc','_i1-i2_j',0,str2num(str1),[],SubDir_1);
     3267             [filename,n1,na,n2,nb,SubDir_1]=name_generator(filebase_1,str2num(str1),stra2num(str_a),'.nc','_i1-i2_j',0,str2num(str1),[],SubDir_1);
    32653268            if idetect==1
    32663269                NomTypeNew='_i1-i2_j';
     
    32693272            end
    32703273        else %for instance avi files or any ima_num series
    3271             [filename,idetect,n1,na,n2,nb,SubDir_1]=name_generator(filebase_1,str2num(str1),str2num(str_a),'.nc','_i1-i2',0,str2num(str1),[],SubDir_1);
     3274            [filename,n1,na,n2,nb,SubDir_1]=name_generator(filebase_1,str2num(str1),stra2num(str_a),'.nc','_i1-i2',0,str2num(str1),[],SubDir_1);
    32723275            NomTypeNew='_i1-i2';
    32733276        end           
     
    35873590function save_mask_Callback(hObject, eventdata, handles)
    35883591%-----------------------------------------------------------------------
    3589 huvmat=get(handles.save_mask,'parent');
    3590 UvData=get(huvmat,'UserData');
    3591 
    3592 hpatch=findobj(huvmat,'Type','patch');
     3592UvData=get(handles.uvmat,'UserData');
     3593
    35933594flag=1;
    35943595npx=size(UvData.Field.A,2);
     
    36163617                        [X,Y]=px_XYZ(Calib,X,Y,0);% to generalise with 3D cases
    36173618                    end
    3618                     flagobj=~inpolygon(Xi,Yi,X,Y);%=0 inside the polygon, 1 outside                 
     3619                    flagobj=~inpolygon(Xi,Yi,X',Y');%=0 inside the polygon, 1 outside                 
    36193620                elseif isequal(ObjectData.Style,'ellipse')
    36203621                    if testphys
     
    43114312hset_object=set_object(ObjectData,PlotHandles,ZBounds);% call the set_object interface,
    43124313set(hset_object,'name',ObjectName)
    4313 % pos_uvmat=get(handles.uvmat,'Position');
    4314 % %position the set_object GUI with respect to uvmat
    4315 % if isfield(UvData,'SetObjectOrigin')
    4316 %     pos_set_object(1:2)=UvData.SetObjectOrigin + pos_uvmat(1:2);
    4317 %     pos_set_object(3:4)=UvData.SetObjectSize .* pos_uvmat(3:4);
    4318 %     set(hset_object,'Position',pos_set_object)
     4314
     4315% %project the current field on the object and plot it
     4316% ProjData= proj_field(UvData.Field,ObjectData,IndexObj);%project the current interface field on ObjectData
     4317% if option==1%length(UvData.Object)>= IndexObj && isfield(UvData.Object{IndexObj},'plotaxes')&& ishandle(UvData.Object{IndexObj}.plotaxes)
     4318%     plot_field(ProjData,handles.axes3,PlotHandles);
     4319%     UvData.Object{IndexObj}.plotaxes=handles.axes3;
     4320% else
     4321%     UvData.Object{IndexObj}.plotaxes=view_field(ProjData);
    43194322% end
    4320 
    4321 %project the current field on the object and plot it
    4322 ProjData= proj_field(UvData.Field,ObjectData,IndexObj);%project the current interface field on ObjectData
    4323 if option==1%length(UvData.Object)>= IndexObj && isfield(UvData.Object{IndexObj},'plotaxes')&& ishandle(UvData.Object{IndexObj}.plotaxes)
    4324     plot_field(ProjData,handles.axes3,PlotHandles);
    4325     UvData.Object{IndexObj}.plotaxes=handles.axes3;
    4326 else
    4327     UvData.Object{IndexObj}.plotaxes=view_field(ProjData);
    4328 end
    4329 set(handles.uvmat,'UserData',UvData)
    4330 hother=findobj('Tag','proj_object');%find all the proj objects
    4331 for iobj=1:length(hother)
    4332     if isequal(get(hother(iobj),'Type'),'rectangle')|isequal(get(hother(iobj),'Type'),'patch')
    4333         set(hother(iobj),'EdgeColor','b')
    4334         if isequal(get(hother(iobj),'FaceColor'),'m')
    4335             set(hother(iobj),'FaceColor','b')
    4336         end
    4337     elseif isequal(get(hother(iobj),'Type'),'image')
    4338            Acolor=get(hother(iobj),'CData');
    4339            Acolor(:,:,1)=zeros(size(Acolor,1),size(Acolor,2));
    4340            set(hother(iobj),'CData',Acolor);
    4341     else
    4342          set(hother(iobj),'Color','b')
    4343     end
    4344     set(hother(iobj),'Selected','off')
    4345 end
     4323% set(handles.uvmat,'UserData',UvData)
     4324% hother=findobj('Tag','proj_object');%find all the proj objects
     4325% for iobj=1:length(hother)
     4326%     if isequal(get(hother(iobj),'Type'),'rectangle')|isequal(get(hother(iobj),'Type'),'patch')
     4327%         set(hother(iobj),'EdgeColor','b')
     4328%         if isequal(get(hother(iobj),'FaceColor'),'m')
     4329%             set(hother(iobj),'FaceColor','b')
     4330%         end
     4331%     elseif isequal(get(hother(iobj),'Type'),'image')
     4332%            Acolor=get(hother(iobj),'CData');
     4333%            Acolor(:,:,1)=zeros(size(Acolor,1),size(Acolor,2));
     4334%            set(hother(iobj),'CData',Acolor);
     4335%     else
     4336%          set(hother(iobj),'Color','b')
     4337%     end
     4338%     set(hother(iobj),'Selected','off')
     4339% end
    43464340hother=findobj('Tag','DeformPoint');
    43474341set(hother,'Color','b');
     
    43904384global CurData
    43914385CurData=get(handles.uvmat,'UserData');
    4392 % if isfield(UvData,'ProjField')
    4393     CurData=UvData;
    4394     evalin('base','global CurData')%make CurData global in the workspace
    4395     display(['current field :'])
    4396 % end
     4386evalin('base','global CurData')%make CurData global in the workspace
     4387display(['current field :'])
    43974388evalin('base','CurData') %display CurData in the workspace
    4398 commandwindow;
     4389commandwindow; %brings the Matlab command window to the front
    43994390
    44004391%------------------------------------------------------
     
    45474538% ------------------------------------------------------------------
    45484539function MenuMask_Callback(hObject, eventdata, handles)
    4549 set(handles.TOOLS_txt,'Visible','on')
    4550 set(handles.frame_tools,'Visible','on')
    4551 % set(handles.create,'Visible','on')
    4552 % set(handles.create,'Value',1)
    4553 % set(handles.create,'BackgroundColor',[1 1 0]) %visualise in yellow
    4554 set(handles.save_mask,'Visible','on')
    4555 set(handles.masklevel,'Visible','on')
    4556 if isequal(get(handles.z_index,'Visible'),'on')
    4557     nb_slice=str2num(get(handles.nb_slice,'String'));
    4558     for ilist=1:nb_slice
    4559         list_index{ilist,1}=num2str(ilist);
    4560     end   
    4561     set(handles.masklevel,'String',list_index)
    4562     val=str2num(get(handles.z_index,'String'));
    4563     if val<=nb_slice
    4564         set(handles.masklevel,'Value',val)
    4565     end
    4566 else
    4567     set(handles.masklevel,'String',{'1'})
    4568     set(handles.masklevel,'Value',1)
    4569 end
    4570 if ishandle(handles.UVMAT_title)
    4571     delete(handles.UVMAT_title)
    4572 end
    4573 % huvmat=get(handles.create,'parent');
     4540% set(handles.TOOLS_txt,'Visible','on')
     4541% set(handles.frame_tools,'Visible','on')
     4542% % set(handles.create,'Visible','on')
     4543% % set(handles.create,'Value',1)
     4544% % set(handles.create,'BackgroundColor',[1 1 0]) %visualise in yellow
     4545% set(handles.save_mask,'Visible','on')
     4546% set(handles.masklevel,'Visible','on')
     4547% if isequal(get(handles.z_index,'Visible'),'on')
     4548%     nb_slice=str2num(get(handles.nb_slice,'String'));
     4549%     for ilist=1:nb_slice
     4550%         list_index{ilist,1}=num2str(ilist);
     4551%     end   
     4552%     set(handles.masklevel,'String',list_index)
     4553%     val=str2num(get(handles.z_index,'String'));
     4554%     if val<=nb_slice
     4555%         set(handles.masklevel,'Value',val)
     4556%     end
     4557% else
     4558%     set(handles.masklevel,'String',{'1'})
     4559%     set(handles.masklevel,'Value',1)
     4560% end
     4561% if ishandle(handles.UVMAT_title)
     4562%     delete(handles.UVMAT_title)
     4563% end
    45744564UvData=get(handles.uvmat,'UserData');%read UvData properties stored on the uvmat interface
    4575 set(handles.zoom,'Value',0)
    4576 set(handles.zoom,'BackgroundColor',[0.7 0.7 0.7])
    4577 set(handles.edit_vect,'Value',0)
    4578 edit_vect_Callback(hObject, eventdata, handles)
    4579 set(handles.edit,'Value',0)
    4580 set(handles.edit,'BackgroundColor',[0.7 0.7 0.7])
    4581 set(handles.edit_vect,'Value',0) 
    4582 edit_vect_Callback(hObject, eventdata, handles)
     4565% set(handles.zoom,'Value',0)
     4566% set(handles.zoom,'BackgroundColor',[0.7 0.7 0.7])
     4567% set(handles.edit_vect,'Value',0)
     4568% edit_vect_Callback(hObject, eventdata, handles)
     4569% set(handles.edit,'Value',0)
     4570% set(handles.edit,'BackgroundColor',[0.7 0.7 0.7])
     4571% set(handles.edit_vect,'Value',0) 
     4572% edit_vect_Callback(hObject, eventdata, handles)
    45834573% set(handles.cal,'Value',0)
    45844574% set(handles.cal,'BackgroundColor',[0 1 0])
    45854575
    45864576%initiate the GUI set_object
    4587 data.TITLE='MASK';
    4588 if isfield(UvData,'CoordType')
    4589     data.CoordType=UvData.CoordType;
    4590 end
    4591 if isfield(UvData,'Mesh')&&~isempty(UvData.Mesh)
    4592     data.YMax=UvData.Mesh;
    4593 elseif isfield(UvData.Field,'AX')&&isfield(UvData.Field,'AY')&& isfield(UvData.Field,'A')%only image
    4594     np=size(UvData.Field.A);
    4595     meshx=(UvData.Field.AX(end)-UvData.Field.AX(1))/(np(2)-1);
    4596     meshy=abs(UvData.Field.AY(end)-UvData.Field.AY(1))/(np(1)-1);
    4597     data.YMax=max(meshx,meshy);
    4598     data.DX=max(meshx,meshy);
    4599 end
    4600 data.Coord=[0 0 0]; %default
    4601 PlotHandles=get_plot_handles(handles);%get the handles of the graphic objects setting the plotting parameters
    4602 [hset_object,UvData.sethandles]=set_object(data,PlotHandles);% call the set_object interface
    4603 pos_uvmat=get(handles.huvmat,'Position');
    4604 if isfield(UvData,'SetObjectOrigin')
    4605     pos_set_object(1:2)=UvData.SetObjectOrigin + pos_uvmat(1:2);
    4606     pos_set_object(3:4)=UvData.SetObjectSize .* pos_uvmat(3:4);
    4607     set(hset_object,'Position',pos_set_object)
    4608 end
    4609 list_object=get(handles.list_object_1,'String');
    4610 if ~isempty(list_object)
    4611     set(handles.list_object_1,'Value',length(list_object))
    4612 end
    4613 UvData.MouseAction='create_object';
     4577% data.TITLE='MASK';
     4578% if isfield(UvData,'CoordType')
     4579%     data.CoordType=UvData.CoordType;
     4580% end
     4581% if isfield(UvData,'Mesh')&&~isempty(UvData.Mesh)
     4582%     data.YMax=UvData.Mesh;
     4583% elseif isfield(UvData.Field,'AX')&&isfield(UvData.Field,'AY')&& isfield(UvData.Field,'A')%only image
     4584%     np=size(UvData.Field.A);
     4585%     meshx=(UvData.Field.AX(end)-UvData.Field.AX(1))/(np(2)-1);
     4586%     meshy=abs(UvData.Field.AY(end)-UvData.Field.AY(1))/(np(1)-1);
     4587%     data.YMax=max(meshx,meshy);
     4588%     data.DX=max(meshx,meshy);
     4589% end
     4590% data.Coord=[0 0 0]; %default
     4591% PlotHandles=get_plot_handles(handles);%get the handles of the graphic objects setting the plotting parameters
     4592% [hset_object,UvData.sethandles]=set_object(data,PlotHandles);% call the set_object interface
     4593% pos_uvmat=get(handles.uvmat,'Position');
     4594% if isfield(UvData,'SetObjectOrigin')
     4595%     pos_set_object(1:2)=UvData.SetObjectOrigin + pos_uvmat(1:2);
     4596%     pos_set_object(3:4)=UvData.SetObjectSize .* pos_uvmat(3:4);
     4597%     set(hset_object,'Position',pos_set_object)
     4598% end
     4599ListObj=UvData.Object;
     4600select=zeros(1,numel(ListObj));
     4601for iobj=1:numel(ListObj);
     4602    if strcmp(ListObj{iobj}.ProjMode,'mask_inside')||strcmp(ListObj{iobj}.ProjMode,'mask_outside')
     4603        select(iobj)=1;
     4604    end
     4605end
     4606val=find(select);
     4607if isempty(val)
     4608    msgbox_uvmat('ERROR','polygons must be first created by Projection object/mask polygon in the menu bar');
     4609    return
     4610else
     4611    set(handles.list_object_1,'Max',2);%allow multiple selection
     4612    set(handles.list_object_1,'Value',val);
     4613%     answer=msgbox_uvmat('INPUT_Y-N',['make the mask image from ' num2str(numel(val)) ' polygons']);
     4614%     if ~isempty(answer)
     4615        flag=1;
     4616        npx=size(UvData.Field.A,2);
     4617        npy=size(UvData.Field.A,1);
     4618        xi=[0.5:npx-0.5];
     4619        yi=[0.5:npy-0.5];
     4620        [Xi,Yi]=meshgrid(xi,yi);
     4621        if isfield(UvData,'Object')
     4622            for iobj=1:length(UvData.Object)
     4623                ObjectData=UvData.Object{iobj};
     4624                if isfield(ObjectData,'ProjMode') &&(isequal(ObjectData.ProjMode,'mask_inside')||isequal(ObjectData.ProjMode,'mask_outside'));
     4625                    flagobj=1;
     4626                    testphys=0; %coordinates in pixels by default
     4627                    if isfield(ObjectData,'CoordType') && isequal(ObjectData.CoordType,'phys')
     4628                        if isfield(UvData,'XmlData')&& isfield(UvData.XmlData,'GeometryCalib')
     4629                            Calib=UvData.XmlData.GeometryCalib;
     4630                            testphys=1;
     4631                        end
     4632                    end
     4633                    if isfield(ObjectData,'Coord')& isfield(ObjectData,'Style')
     4634                        if isequal(ObjectData.Style,'polygon')
     4635                            X=ObjectData.Coord(:,1);
     4636                            Y=ObjectData.Coord(:,2);
     4637                            if testphys
     4638                                [X,Y]=px_XYZ(Calib,X,Y,0);% to generalise with 3D cases
     4639                            end
     4640                            flagobj=~inpolygon(Xi,Yi,X',Y');%=0 inside the polygon, 1 outside
     4641                        elseif isequal(ObjectData.Style,'ellipse')
     4642                            if testphys
     4643                                %[X,Y]=px_XYZ(Calib,X,Y,0);% TODO:create a polygon boundary and transform to phys
     4644                            end
     4645                            RangeX=max(ObjectData.RangeX);
     4646                            RangeY=max(ObjectData.RangeY);
     4647                            X2Max=RangeX*RangeX;
     4648                            Y2Max=RangeY*RangeY;
     4649                            distX=(Xi-ObjectData.Coord(1,1));
     4650                            distY=(Yi-ObjectData.Coord(1,2));
     4651                            flagobj=(distX.*distX/X2Max+distY.*distY/Y2Max)>1;
     4652                        elseif isequal(ObjectData.Style,'rectangle')
     4653                            if testphys
     4654                                %[X,Y]=px_XYZ(Calib,X,Y,0);% TODO:create a polygon boundary and transform to phys
     4655                            end
     4656                            distX=abs(Xi-ObjectData.Coord(1,1));
     4657                            distY=abs(Yi-ObjectData.Coord(1,2));
     4658                            flagobj=distX>max(ObjectData.RangeX) | distY>max(ObjectData.RangeY);
     4659                        end
     4660                        if isequal(ObjectData.ProjMode,'mask_outside')
     4661                            flagobj=~flagobj;
     4662                        end
     4663                        flag=flag & flagobj;
     4664                    end
     4665                end
     4666            end
     4667        end
     4668        % flag=~flag;
     4669        %mask name
     4670        RootPath=get(handles.RootPath,'String');
     4671        RootFile=get(handles.RootFile,'String');
     4672        if ~isempty(RootFile)&(isequal(RootFile(1),'/')| isequal(RootFile(1),'\'))
     4673            RootFile(1)=[];
     4674        end
     4675        filebase=fullfile(RootPath,RootFile);
     4676        list=get(handles.masklevel,'String');
     4677        masknumber=num2str(length(list));
     4678        maskindex=get(handles.masklevel,'Value');
     4679        mask_name=name_generator([filebase '_' masknumber 'mask'],maskindex,1,'.png','_i');
     4680        imflag=uint8(255*(0.392+0.608*flag));% =100 for flag=0 (vectors not computed when 20<imflag<200)
     4681        imflag=flipdim(imflag,1);
     4682        % imflag=uint8(255*flag);% =0 for flag=0 (vectors=0 when
     4683        % 20<imflag<200)
     4684
     4685        %display the mask
     4686        %update_mask(handles,num_i1,num_j1)
     4687        figure;
     4688        vec=linspace(0,1,256);%define a linear greyscale colormap
     4689        map=[vec' vec' vec'];
     4690        colormap(map)
     4691        image(imflag);
     4692        answer=msgbox_uvmat('INPUT_TXT','mask file name:', mask_name)
     4693        if ~strcmp(answer,'Cancel')
     4694            imwrite(imflag,answer,'BitDepth',8);
     4695        end
     4696        set(list_object_1,'Value',1)
     4697        set(list_object_1,'Max',1)
     4698%     end
     4699end       
     4700     
     4701
     4702% UvData.MouseAction='create_object';
    46144703set(handles.uvmat,'UserData',UvData);
    46154704
     
    47794868create_object(data,handles)
    47804869
     4870%------------------------------------------------------------------------
     4871function MenuMaskObject_Callback(hObject, eventdata, handles)
     4872%------------------------------------------------------------------------
     4873data.Style='polygon';
     4874data.StyleMenu={'polygon'};
     4875data.ProjMode='mask_inside';%default
     4876data.ProjMenu={'mask_inside';'mask_outside'};
     4877create_object(data,handles)
     4878
    47814879% ------------------------------------------------------------------
    47824880function Menuplane_Callback(hObject, eventdata, handles)
     
    48524950set(handles.edit,'BackgroundColor',[0.7,0.7,0.7]) 
    48534951data.enable_plot=1;
    4854 if isfield(UvData,'CoordType')
    4855     data.CoordType=UvData.CoordType;
    4856 end
     4952transform_list=get(handles.transform_fct,'String');
     4953val=get(handles.transform_fct,'Value');
     4954data.CoordType=transform_list{val};
     4955% if isfield(UvData,'CoordType')
     4956%     data.CoordType=UvData.CoordType;
     4957% end
    48574958if isfield(UvData,'Mesh')&&~isempty(UvData.Mesh)
    48584959    data.RangeX=UvData.Mesh;
     
    49345035
    49355036
    4936 
Note: See TracChangeset for help on using the changeset viewer.