const FLIP_REGIONS=["LA_cavity","LV_cavity","PULM_VEINS"];let _f16=null;function _half2float(){if(_f16)return _f16;const i=new Float32Array(65536);for(let t=0;t<65536;t++){const e=t&32768?-1:1,a=t>>10&31,s=t&1023;i[t]=a===0?e*s*Math.pow(2,-24):a===31?s?NaN:e*(1/0):e*(1+s/1024)*Math.pow(2,a-15)}return _f16=i,i}async function loadFlipReplay(i){const t=await fetch(i);if(!t.ok)throw new Error(`\u771F\u6D41\u4F53\u56DE\u653E ${i}\uFF1AHTTP ${t.status}`);const e=await t.arrayBuffer(),a=new DataView(e).getUint32(0,!0),s=JSON.parse(new TextDecoder().decode(new Uint8Array(e,4,a))),o=4+a,h=s.counts.map((r,f)=>{const n=o+s.offsets[f];return{count:r,pos:new Uint16Array(e,n,r*3),vel:new Uint16Array(e,n+r*6,r*3)}});return{header:s,frames:h,maxCount:Math.max(...s.counts)}}class FlipReplay{constructor(t,e,a,s){this.data=t;const o=t.maxCount;this.geo=new THREE.BufferGeometry,this.attr=new THREE.BufferAttribute(new Float32Array(o*3),3),this.attr.setUsage(THREE.DynamicDrawUsage),this.geo.setAttribute("position",this.attr),this.geo.setDrawRange(0,0),this.mat=coronaryPointsMaterial(a,s),this.points=new THREE.Points(this.geo,this.mat),this.points.name="flip_replay",this.points.frustumCulled=!1,this.points.raycast=()=>{},this.points.castShadow=!1,this.points.renderOrder=2,this.points.visible=!1,e.add(this.points),this.frame=-1,this.lut=_half2float()}show(t,e){const a=Math.min(this.data.frames.length-1,Math.floor(t*this.data.frames.length));if(a!==this.frame){const s=this.data.frames[a],o=this.attr.array,h=this.lut,r=s.pos,f=s.count*3;for(let n=0;n<f;n++)o[n]=h[r[n]];this.attr.needsUpdate=!0,this.geo.setDrawRange(0,s.count),this.frame=a}this.mat.uniforms&&this.mat.uniforms.uViewH&&(this.mat.uniforms.uViewH.value=e)}dispose(){this.points.parent&&this.points.parent.remove(this.points),this.geo.dispose(),this.mat.dispose()}}Object.assign(window,{loadFlipReplay,FlipReplay,FLIP_REGIONS});
