function data=c2(db_file) % Compare the path close all hidden % Read table of primary and secondary path conn=sqlite(db_file); state_data=fetch(conn,"SELECT * FROM state;"); close(conn); % Read primary data P=table2array(state_data([state_data.pri_sec==1],1:4)); Py=table2array(state_data([state_data.pri_sec==1],5:6)); yaw1=Py(1); yaw2=Py(2); p_idx=P(1); sql="SELECT * FROM images WHERE %d<= cnt_id AND cnt_id<%d ;"; sql=sprintf(sql,P(2),P(3)); conn=sqlite(db_file); res=fetch(conn,sql); close(conn); % Decode lat,lon of primary path (all S³ images) lalo_p=rowfun(@(x,y) [jsondecode(x),jsondecode(y)], res(:,["lat","lon"]),'OutputFormat', 'cell'); lalo=cell2mat(lalo_p); % Plot path of S³ center h=geoplot(lalo(:,1),lalo(:,2),'x'); hold on; hc=[]; hc2=[]; hc3=[]; ref=[]; GLaA=[]; GLoA=[]; GLaB=[]; GLoB=[]; for idx=1:size(res,1) % for each image in path % Load data of path lat=str2num(res.lat(idx)); lon=str2num(res.lon(idx)); yaw=str2num(res.yaw(idx)); perc=str2num(res.perc(idx)); time_=str2num(res.time(idx)); altitude=str2num(res.altitude(idx)); range=res.range(idx); hull=str2num(res.hull(idx)); LaA=str2num(res.LaA(idx)); LoA=str2num(res.LoA(idx)); LaB=str2num(res.LaB(idx)); LoB=str2num(res.LoB(idx)); rota=str2num(res.rota(idx)); aabb=str2num(res.aabb(idx)); cv=str2num(res.hull(idx)); % Get closed circunference of image [La,Lo]=get_circumference2(lat,lon,yaw,altitude,range); points=[La',Lo']; points=points([hull],:); figure(1); % Plot points of circunference hc2_=geoplot([La,La(1)]',[Lo,Lo(1)]','x-'); hold on; % Get partss of circunference %[LaA,LoA,LaB,LoB]=get_circumference3(lat,lon,yaw,altitude,range); %hc3_=[]; %for kk=1:length(LaA) % hc3_=[hc3_,geoplot([LaA(kk),LaB(kk)],[LoA(kk),LoB(kk)])]; %end %hold on; % Plot convex hull of circunference hc_=geoplot(points(:,1),points(:,2)); hold on; hc_.Visible="off"; hc2_.Visible="off"; %set(hc3_,'Visible','off'); hc=[hc,hc_]; hc2=[hc2,hc2_]; %hc3=[hc3;hc3_]; ref=[ref,... struct("lat",lat,... "lon",lon,... "yaw",yaw,... "altitude",altitude,... "range",range,... "time",time_,... "perc",perc,... "latc",res.latc(idx),... "lonc",res.lonc(idx),... "yawc",res.yawc(idx),... "path",res.path(idx),... "id",res.id(idx),... "LaA",LaA,... "LoA",LoA,... "LaB",LaB,... "LoB",LoB,... "cv",cv,... "aabb",aabb, ... "yaw1",yaw1,... "yaw2",yaw2,... "rota",rota)]; end hold off; % Create figure window a=uifigure("Position",[286,446,300,127]); % Create drop down menu dd=uidropdown(a,'FontSize',24,'Position',[70,120-50,150,50],... 'ValueChangedFcn',{@change_func,hc,hc2,hc3}); dd.ItemsData= 1:size(res,1); dd.Items= arrayfun(@(x) string(num2str(x)), 1:size(res,1)); % Create '+' and '-' buttons uibutton(a,'Text','+','FontSize',26,'Position',[240,120-50,50,50],... 'ButtonPushedFcn',{@plus_func,dd,hc,hc2,hc3}); uibutton(a,'Text','-','FontSize',26,'Position',[10,120-50,50,50],... 'ButtonPushedFcn',{@minus_func,dd,hc,hc2,hc3}); % Create global data data.db_file=db_file; data.ref=ref; data.p_active=-1; data.ref=ref; data.rects=[]; set(groot,"UserData",data); % Show first image of path show_current_part(dd.Value,hc,hc2,hc3); end function ref=get_part_id(id) data=get(groot,"UserData"); ref=-1; for idx=1:size(data.S,1) if data.S(idx,2)<=id && id < data.S(idx,3) ref=idx; break; end end end function minus_func(app,event,dd,hc,hc2,hc3) if dd.Value==1 return end dd.Value=dd.Value-1; show_current_part(dd.Value,hc,hc2,hc3); end function plus_func(app,event,dd,hc,hc2,hc3) if dd.Value==dd.ItemsData(end) return end dd.Value=dd.Value+1; show_current_part(dd.Value,hc,hc2,hc3); end function change_func(app,event,hc,hc2,hc3) show_current_part(app.Value,hc,hc2,hc3); end function show_current_part(idx_on,hc,hc2,hc3) data=get(groot,'UserData'); if data.p_active ~= -1 hc(data.p_active).Visible="off"; hc2(data.p_active).Visible="off"; %set(hc3(data.p_active,:),'Visible','off'); end %hc(idx_on).Visible="on"; hc2(idx_on).Visible="on"; %set(hc3(idx_on,:),'Visible','on'); LaA=data.ref(idx_on).LaA; LoA=data.ref(idx_on).LoA; LaB=data.ref(idx_on).LaB; LoB=data.ref(idx_on).LoB; yaw=data.ref(idx_on).yaw; yaw(yaw<0.0)=yaw(yaw<0.0)+2*pi; idx1=find((yaw/data.ref(idx_on).yaw1)-1 < 0.2); idx2=find((yaw/data.ref(idx_on).yaw2)-1 < 0.2); N=length(yaw); negative=setdiff(1:N,union(idx1,idx2)); figure(9) ref=data.ref(idx_on); first=imread(fullfile(ref.path,ref.id+".png")); im1=imshow(first); set(im1,"ButtonDownFcn",@p1); %rota=union(data.ref(idx_on).rota,negative); rota=data.ref(idx_on).rota; for i=1:length(rota) od=rota(i); rectangle('Position',[1 ,data.ref(idx_on).perc(od)*1024,... 1023,0.0099*1024],... 'FaceColor',[0 1 0 0.25],'EdgeColor',[ 0 1 0 0.125]); end data.p_active=idx_on; set(groot,'UserData',data); show_rects(data.ref(idx_on)); end function show_rects(ref) data=get(groot,'UserData'); for idx=1:length(data.rects) rect=data.rects(idx); if rect_in_cv_hull(rect,ref) display_rect_in_ref(9,rect,ref); end end end function ret=rect_in_cv_hull(rect,ref) p=[[ref.LaA,ref.LaB]',[ref.LoA,ref.LoB]']; pp=p(ref.cv,:); ret=inpolygon(mean(rect.LatitudeData),mean(rect.LongitudeData),pp(:,1),pp(:,2)); end function display_rect_in_ref(fig_id,rect,ref) wgs84 = wgs84Ellipsoid("m"); udata=get(rect,'UserData'); l=[]; a=[]; ii=[]; yaw=[]; for idx=1:length(ref.lat) if ismember(idx,ref.rota) continue end [ls,az]=distance(ref.lat(idx),ref.lon(idx),udata.la,udata.lo,wgs84); l=[l,ls]; if az<0 az=az+360; end a=[a,az]; ii=[ii,idx]; yaw=[yaw,rad2deg(ref.yaw(idx))]; if yaw(end)<0 yaw(end)=360+yaw(end); end end idx=find(l<=ref.range); a=a(idx); ii=ii(idx); yaw=yaw(idx); p=abs(abs(a-yaw)-180)/90; [d,i]=min(abs(p-1)); idx=ii(i); figure(9); posi=[1 ,ref.perc(idx)*1024,1023,0.0099*1024]; %rectangle('Position',[1 ,ref.perc(idx)*1024,... % 1023,0.0099*1024],... % 'FaceColor',[1 1 0 0.0],'EdgeColor',[ 1 1 0 0.75]); llla=[]; lllo=[]; lld=[]; % for jdx=max([1,idx-1]):min([idx+1,length(ref.lon)]) for jdx=idx lla=[]; llo=[]; ld=[]; for i=0:100 [la,lo,d]=getGeo_d(i/100,0.0,ref.range,... ref.lat(jdx),... ref.lon(jdx), ... ref.altitude(jdx),... ref.yaw(jdx),0.0); lla=[lla,la]; llo=[llo,lo]; ld=[ld,d]; end llla=[llla;lla]; lllo=[lllo;llo]; lld=[lld;ld]; end ep=sqrt((llla-udata.la).^2+(lllo-udata.lo).^2+1*(lld-udata.de).^2); [a,idx_x]=min(ep); if idx_x>0 idx_x=idx_x-1; end %rectangle('Position',[idx_x*1024/100 ,1,0.02*1024,1024],'EdgeColor',[1,1,1]) posi(1)=idx_x*1024/100; posi(3)=0.02*1024; rectangle('Position',posi,'FaceColor',[1 1 0 0.0],'EdgeColor',[ 1 1 0 0.75],'LineWidth',2); b=1; end function p1(src,event) %,im2) if event.Button == 1 po=event.IntersectionPoint; h = images.roi.Circle(); addlistener(h,'MovingROI',@(src,evt) updateLabel(src,evt)); %,im2)); addlistener(h,'ROIClicked',@updateUnits); %cp = hAx.CurrentPoint; cp = po(1:2); h.beginDrawingFromPoint(cp); end end function updateLabel(src,evt) %,im2) %figure(2) %data=get(2,'UserData'); %if isempty(data) % h=rectangle("Position",evt.Source(1).Position,'FaceColor',[1,0,0]); % set(2,"UserData",h); %else % data.Position=evt.Source(1).Position; %end end function updateUnits(src,evt) data=get(groot,'UserData'); rect_data=get(src,'UserData'); xy=evt.Source(1).Position; xol=xy(1)/1024; yol=xy(2)/1024; ref=data.ref(data.p_active); la=interp1(ref.perc,ref.lat,yol); lo=interp1(ref.perc,ref.lon,yol); de=interp1(ref.perc,ref.altitude,yol); ya=interp1(ref.perc,ref.yaw,yol); [laP,loP]=getGeo1024(xol,yol,ref.range,la,lo,1*de,ya,0); [scA,scO]=scircle1(laP,loP,0.000005); figure(1); hold on; if isempty(rect_data) rk=geoplot(scA,scO,'Color',[1 0 0],'LineWidth',2); rect_data.rk=rk; insert_in_userdata(rk,laP,loP,de); else rect_data.rk.LatitudeData=scA; rect_data.rk.LongitudeData=scO; rect_data.de=de; modify_in_userdata(rect_data.rk); end hold off set(src,'UserData',rect_data); end function insert_in_userdata(rk,laP,loP,de) data=get(groot,'UserData'); udata.la=laP; udata.lo=loP; udata.de=de; if isempty(data.rects) udata.id=1; set(rk,'UserData',udata); data.rects=[rk]; data.rects_id=[1]; else udata.id=data.rects_id(end)+1; set(rk,'UserData',udata); data.rects=[data.rects,rk]; data.rects_id=[data.rects_id,udata.id]; end set(groot,'UserData',data); end function modify_in_userdata(rk) data=get(groot,'UserData'); udata=get(rk,'UserData') idx=find(data.rects_id==udata.id); set(groot,'UserData',data); end