fix: make pen drafts immediate and serializable, reject stale edits, and align tracked path ROI and optical flow with local reference evidence
这个提交包含在:
1 父节点
38adc259e0
当前提交
0b53fdcdfd
9 个文件已更改
+522
-55
没有与搜索条件相匹配的文件
+13
-13
@@ -7,12 +7,12 @@ kernel void dyTrackPyramid(device float*f[[buffer(0)]],constant PyramidInfo&i[[b
|
||||
for(int y=-1;y<=1;y++)for(int x=-1;x<=1;x++)sum+=f[i.offset[level-1]+clamp(int(p.y)*2+y,0,sh-1)*sw+clamp(int(p.x)*2+x,0,sw-1)]*(x==0?2.f:1.f)*(y==0?2.f:1.f);
|
||||
f[i.offset[level]+p.y*w+p.x]=sum/16.f;
|
||||
}
|
||||
inline bool inside(float2 p,int w,int h){return all(p>=6.f)&&p.x<w-7&&p.y<h-7;}
|
||||
inline bool inside(float2 p,int w,int h){return all(p>=12.f)&&p.x<w-13&&p.y<h-13;}
|
||||
inline float pixel(device const float*f,int w,float2 p) {
|
||||
int2 a=int2(p);float2 d=p-float2(a);int idx=a.y*w+a.x;
|
||||
return mix(mix(f[idx],f[idx+1],d.x),mix(f[idx+w],f[idx+w+1],d.x),d.y);
|
||||
}
|
||||
// One SIMD group per feature: lanes cooperatively reduce the 9x9 patch.
|
||||
// One SIMD group per feature: lanes cooperatively reduce the 21x21 patch.
|
||||
// Forward and backward checks stay in the same dispatch and reuse the resident pyramids.
|
||||
bool trackFlow(device const float*prev,device const float*next,constant PyramidInfo&i,float2 p,float2 guess,thread float2&q,thread float&error,uint lane) {
|
||||
int level=i.levels-1;for(;level>0;level--){float s=float(1<<level);if(inside(p/s,i.width[level],i.height[level])&&inside(guess/s,i.width[level],i.height[level]))break;}
|
||||
@@ -20,24 +20,24 @@ bool trackFlow(device const float*prev,device const float*next,constant PyramidI
|
||||
for(;level>=0;level--) {
|
||||
float2 pp=p/float(1<<level);int w=i.width[level],h=i.height[level];if(!inside(pp,w,h))return false;
|
||||
device const float*a=prev+i.offset[level];device const float*b=next+i.offset[level];
|
||||
float ref[3],gx[3],gy[3],mean=0,hxx=0,hxy=0,hyy=0;
|
||||
for(uint j=0;j<3;j++) {
|
||||
uint k=lane+j*32;ref[j]=gx[j]=gy[j]=0;if(k>=81)continue;
|
||||
float2 pos=pp+float2(int(k%9)-4,int(k/9)-4);ref[j]=pixel(a,w,pos);mean+=ref[j];
|
||||
float ref[14],gx[14],gy[14],mean=0,hxx=0,hxy=0,hyy=0;
|
||||
for(uint j=0;j<14;j++) {
|
||||
uint k=lane+j*32;ref[j]=gx[j]=gy[j]=0;if(k>=441)continue;
|
||||
float2 pos=pp+float2(int(k%21)-10,int(k/21)-10);ref[j]=pixel(a,w,pos);mean+=ref[j];
|
||||
gx[j]=.5f*(pixel(a,w,pos+float2(1,0))-pixel(a,w,pos-float2(1,0)));
|
||||
gy[j]=.5f*(pixel(a,w,pos+float2(0,1))-pixel(a,w,pos-float2(0,1)));
|
||||
hxx+=gx[j]*gx[j];hxy+=gx[j]*gy[j];hyy+=gy[j]*gy[j];
|
||||
}
|
||||
mean=simd_sum(mean)/81;hxx=simd_sum(hxx);hxy=simd_sum(hxy);hyy=simd_sum(hyy);
|
||||
mean=simd_sum(mean)/441;hxx=simd_sum(hxx);hxy=simd_sum(hxy);hyy=simd_sum(hyy);
|
||||
float det=hxx*hyy-hxy*hxy;if(det<1e-8f||hxx+hyy<1e-5f)return false;
|
||||
for(int iteration=0;iteration<20;iteration++) {
|
||||
if(!inside(q,w,h))return false;float target[3],tm=0;
|
||||
for(uint j=0;j<3;j++){uint k=lane+j*32;target[j]=k<81?pixel(b,w,q+float2(int(k%9)-4,int(k/9)-4)):0;tm+=target[j];}
|
||||
tm=simd_sum(tm)/81;float bx=0,by=0,sse=0;
|
||||
for(uint j=0;j<3;j++)if(lane+j*32<81){float e=ref[j]-mean-target[j]+tm;bx+=gx[j]*e;by+=gy[j]*e;sse+=e*e;}
|
||||
for(int iteration=0;iteration<30;iteration++) {
|
||||
if(!inside(q,w,h))return false;float target[14],tm=0;
|
||||
for(uint j=0;j<14;j++){uint k=lane+j*32;target[j]=k<441?pixel(b,w,q+float2(int(k%21)-10,int(k/21)-10)):0;tm+=target[j];}
|
||||
tm=simd_sum(tm)/441;float bx=0,by=0,sse=0;
|
||||
for(uint j=0;j<14;j++)if(lane+j*32<441){float e=ref[j]-mean-target[j]+tm;bx+=gx[j]*e;by+=gy[j]*e;sse+=e*e;}
|
||||
bx=simd_sum(bx);by=simd_sum(by);sse=simd_sum(sse);
|
||||
float2 delta=float2(hyy*bx-hxy*by,hxx*by-hxy*bx)/det;if(!all(isfinite(delta))||length(delta)>8)return false;
|
||||
q+=delta;error=sqrt(sse/81);if(dot(delta,delta)<.0001f)break;
|
||||
q+=delta;error=sqrt(sse/441);if(dot(delta,delta)<.0001f)break;
|
||||
}
|
||||
if(level>0)q*=2;
|
||||
}
|
||||
|
||||
在新工单中引用
屏蔽一个用户