@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 3.99 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */
import{__decorate as o}from"tslib";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 n,lerp as p}from"../../core/mathUtils.js";import{property as l,subclass as c}from"../../core/accessorSupport/decorators.js";import a from"./VoxelColorStop.js";import h from"./VoxelOpacityStop.js";import f from"./VoxelRangeFilter.js";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&&3!==t[e].type;);let s=o;const i=t.length;for(;++s<i&&t[s].type!==r&&3!==t[s].type;);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:1})}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=n(t.position,0,1),r=Math.round(255*n(1-t.opacity,0,1));let i=!1;for(const t of e)if(1===t.type&&Math.abs(t.position-o)<s){t.color.a=r,t.type=3,i=!0;break}i||e.push({color:{r:0,g:0,b:0,a:r},position:t.position,type:2})}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(3!==r.type)if(1===r.type){const[s,i]=this.getPreviousNext(t,e,2);if(-1!==s&&i!==o){const o=(r.position-e[s].position)/(e[i].position-e[s].position);r.color.a=Math.round(p(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,1);if(-1!==s&&i!==o){const o=(r.position-e[s].position)/(e[i].position-e[s].position),t=e[s].color,n=e[i].color;g.forEach(e=>{r.color[e]=Math.round(p(t[e],n[e],o))})}else-1!==s?g.forEach(o=>{r.color[o]=e[s].color[o]}):g.forEach(o=>{r.color[o]=e[i].color[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;g.forEach(o=>{f[o]=Math.round(p(a[o],h[o],s))}),f.a=n(1-p(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=n(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 u=y,g=["r","g","b"];export{u as default};