VoxelTransferFunctionStyle.js 4.3 KB

12345
  1. /*
  2. All material copyright ESRI, All Rights Reserved, unless otherwise specified.
  3. See https://js.arcgis.com/4.25/esri/copyright.txt for details.
  4. */
  5. import{_ as o}from"../../chunks/tslib.es6.js";import t from"../../Color.js";import{ClonableMixin as r}from"../../core/Clonable.js";import e from"../../core/Collection.js";import{referenceSetter as s}from"../../core/collectionUtils.js";import{JSONSupport as i}from"../../core/JSONSupport.js";import{clamp as p,lerp as n}from"../../core/mathUtils.js";import{property as l}from"../../core/accessorSupport/decorators/property.js";import"../../core/arrayUtils.js";import"../../core/accessorSupport/ensureType.js";import{subclass as c}from"../../core/accessorSupport/decorators/subclass.js";import a from"./VoxelColorStop.js";import h from"./VoxelOpacityStop.js";import f from"./VoxelRangeFilter.js";var u;!function(o){o[o.Color=1]="Color",o[o.Alpha=2]="Alpha",o[o.Both=3]="Both"}(u||(u={}));let y=class extends(r(i)){constructor(o){super(o),this.interpolation=null,this.stretchRange=null,this.rangeFilter=null,this._colorMapSize=256,this.colorStops=new(e.ofType(a)),this.opacityStops=new(e.ofType(h))}set colorStops(o){this._set("colorStops",s(o,this._get("colorStops"),e.ofType(a)))}set opacityStops(o){this._set("opacityStops",s(o,this._get("opacityStops"),e.ofType(h)))}getPreviousNext(o,t,r){let e=o;for(;--e>0&&t[e].type!==r&&t[e].type!==u.Both;);let s=o;const i=t.length;for(;++s<i&&t[s].type!==r&&t[s].type!==u.Both;);return[e,s]}get rasterizedTransferFunction(){const o=[];if(this.colorStops.length<2)return o;const r=[],e=[],s=1e-5;for(const t of this.colorStops){if(!t.color)return o;e.push({color:{r:t.color.r,g:t.color.g,b:t.color.b,a:Math.round(255*(1-t.color.a))},position:t.position,type:u.Color})}if(0===this.opacityStops.length)for(const t of e)r.push({color:t.color,position:t.position});else{for(const t of this.opacityStops){const o=p(t.position,0,1),r=Math.round(255*p(1-t.opacity,0,1));let i=!1;for(const t of e)if(t.type===u.Color&&Math.abs(t.position-o)<s){t.color.a=r,t.type=u.Both,i=!0;break}i||e.push({color:{r:0,g:0,b:0,a:r},position:t.position,type:u.Alpha})}e.sort(((o,t)=>o.position<t.position?-1:1));const o=e.length;for(let t=0;t<o;++t){const r=e[t];if(r.type!==u.Both)if(r.type===u.Color){const[s,i]=this.getPreviousNext(t,e,u.Alpha);if(-1!==s&&i!==o){const o=(r.position-e[s].position)/(e[i].position-e[s].position);r.color.a=Math.round(n(e[s].color.a,e[i].color.a,o))}else r.color.a=-1!==s?e[s].color.a:e[i].color.a}else{const[s,i]=this.getPreviousNext(t,e,u.Color);if(-1!==s&&i!==o){const o=(r.position-e[s].position)/(e[i].position-e[s].position),t=e[s].color,p=e[i].color;["r","g","b"].forEach((e=>{r.color[e]=Math.round(n(t[e],p[e],o))}))}else["r","g","b"].forEach(-1!==s?o=>{r.color[o]=e[s][o]}:o=>{r.color[o]=e[i][o]})}}for(const t of e)r.push({color:t.color,position:t.position})}r[0].position=0,r[r.length-1].position=1;let i=0,l=1;for(let c=0;c<this._colorMapSize;++c){const e=c/this._colorMapSize;for(;e>r[l].position;)i=l++;const s=(e-r[i].position)/(r[l].position-r[i].position),a=r[i].color,h=r[l].color,f=new t;["r","g","b"].forEach((o=>{f[o]=Math.round(n(a[o],h[o],s))})),f.a=p(1-n(a.a,h.a,s)/255,0,1),o.push(f)}return o}getColorForContinuousDataValue(o,t){const r=this.rasterizedTransferFunction;if(this.colorStops.length<2||!Array.isArray(this.stretchRange)||this.stretchRange.length<2||r.length<256)return null;let e=this.stretchRange[0],s=this.stretchRange[1];if(e>s){const o=e;e=s,s=o}o=p(o,e,s);const i=r[Math.round((o-e)/(s-e)*(this._colorMapSize-1))].clone();return t||(i.a=1),i}};o([l({type:["linear","nearest"],json:{write:!0}})],y.prototype,"interpolation",void 0),o([l({type:[Number],json:{write:{enabled:!0,isRequired:!0}}})],y.prototype,"stretchRange",void 0),o([l({type:e.ofType(a),json:{write:{enabled:!0,overridePolicy(){return{enabled:!!this.colorStops&&this.colorStops.length>0}}}}})],y.prototype,"colorStops",null),o([l({type:e.ofType(h),json:{read:{source:"alphaStops"},write:{enabled:!0,target:"alphaStops",overridePolicy(){return{enabled:!!this.opacityStops&&this.opacityStops.length>0}}}}})],y.prototype,"opacityStops",null),o([l({type:f,json:{write:!0}})],y.prototype,"rangeFilter",void 0),o([l({type:[t],clonable:!1,json:{read:!1}})],y.prototype,"rasterizedTransferFunction",null),y=o([c("esri.layers.voxel.VoxelTransferFunctionStyle")],y);const g=y;export{g as default};