@vitessce/gl 3.1.2 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/dist/{deflate-c9746f58.js → deflate-69c280fb.js} +1 -1
  2. package/dist/{index-72755d2f.js → index-2a7f1ae0.js} +21935 -5890
  3. package/dist/index.js +14 -13
  4. package/dist/{jpeg-cb74431a.js → jpeg-95f78026.js} +1 -1
  5. package/dist/{lerc-5dffa929.js → lerc-5320d7fa.js} +1 -1
  6. package/dist/{lzw-85fa08a9.js → lzw-8d3691e0.js} +1 -1
  7. package/dist/{packbits-6b8314bf.js → packbits-2846ed6b.js} +1 -1
  8. package/dist/{raw-f12c17bf.js → raw-b0ec4406.js} +1 -1
  9. package/dist/{webimage-99c1b585.js → webimage-a17e81f9.js} +1 -1
  10. package/dist-tsc/BitmaskLayerBeta.d.ts +152 -0
  11. package/dist-tsc/BitmaskLayerBeta.d.ts.map +1 -0
  12. package/dist-tsc/BitmaskLayerBeta.js +253 -0
  13. package/dist-tsc/SelectionLayer.d.ts +1 -0
  14. package/dist-tsc/SelectionLayer.d.ts.map +1 -1
  15. package/dist-tsc/SelectionLayer.js +45 -31
  16. package/dist-tsc/bitmask-layer-beta-shaders.d.ts +3 -0
  17. package/dist-tsc/bitmask-layer-beta-shaders.d.ts.map +1 -0
  18. package/dist-tsc/bitmask-layer-beta-shaders.js +212 -0
  19. package/dist-tsc/bitmask-utils.d.ts +12 -0
  20. package/dist-tsc/bitmask-utils.d.ts.map +1 -0
  21. package/dist-tsc/bitmask-utils.js +89 -0
  22. package/dist-tsc/bitmask-utils.test.d.ts +2 -0
  23. package/dist-tsc/bitmask-utils.test.d.ts.map +1 -0
  24. package/dist-tsc/bitmask-utils.test.js +72 -0
  25. package/dist-tsc/index.d.ts +2 -1
  26. package/dist-tsc/index.js +2 -1
  27. package/dist-tsc/selection-utils.d.ts +3 -3
  28. package/dist-tsc/selection-utils.d.ts.map +1 -1
  29. package/dist-tsc/selection-utils.js +26 -28
  30. package/dist-tsc/viv.d.ts +1 -1
  31. package/dist-tsc/viv.js +1 -1
  32. package/package.json +3 -2
  33. package/src/BitmaskLayerBeta.js +360 -0
  34. package/src/SelectionLayer.js +60 -42
  35. package/src/bitmask-layer-beta-shaders.js +214 -0
  36. package/src/bitmask-utils.js +99 -0
  37. package/src/bitmask-utils.test.js +91 -0
  38. package/src/index.js +3 -1
  39. package/src/selection-utils.js +13 -17
  40. package/src/viv.js +1 -0
package/dist/index.js CHANGED
@@ -1,33 +1,34 @@
1
- import { f as distEs6 } from "./index-72755d2f.js";
2
- import { n, m, A, q, p, o, i, C, k, D, G, e, H, c, M, j, l, d, P, S, h, T, s, b, r, v } from "./index-72755d2f.js";
1
+ import { f as distEs6 } from "./index-2a7f1ae0.js";
2
+ import { o, n, A, r, q, p, i, j, C, l, D, G, e, H, c, M, k, m, d, P, S, h, T, t, b, s, v } from "./index-2a7f1ae0.js";
3
3
  import "react";
4
4
  const SELECTION_TYPE = distEs6.SELECTION_TYPE;
5
5
  export {
6
- n as AXIS_FONT_FAMILY,
7
- m as AXIS_LABEL_TEXT_SIZE,
6
+ o as AXIS_FONT_FAMILY,
7
+ n as AXIS_LABEL_TEXT_SIZE,
8
8
  A as AXIS_MARGIN,
9
- q as AXIS_MAX_SIZE,
10
- p as AXIS_MIN_SIZE,
11
- o as AXIS_PADDING,
9
+ r as AXIS_MAX_SIZE,
10
+ q as AXIS_MIN_SIZE,
11
+ p as AXIS_PADDING,
12
12
  i as BitmaskLayer,
13
+ j as BitmaskLayerBeta,
13
14
  C as COLOR_BAR_SIZE,
14
- k as DATA_TEXTURE_SIZE,
15
+ l as DATA_TEXTURE_SIZE,
15
16
  D as DEFAULT_GL_OPTIONS,
16
17
  G as GLSL_COLORMAPS,
17
18
  e as GLSL_COLORMAP_DEFAULT,
18
19
  H as HeatmapBitmapLayer,
19
20
  c as HeatmapCompositeTextLayer,
20
21
  M as MAX_ROW_AGG,
21
- j as MIN_ROW_AGG,
22
- l as PIXELATED_TEXTURE_PARAMETERS,
22
+ k as MIN_ROW_AGG,
23
+ m as PIXELATED_TEXTURE_PARAMETERS,
23
24
  d as PaddedExpressionHeatmapBitmapLayer,
24
25
  P as PixelatedBitmapLayer,
25
26
  SELECTION_TYPE,
26
27
  S as ScaledExpressionExtension,
27
28
  h as SelectionExtension,
28
29
  T as TILE_SIZE,
29
- s as deck,
30
- b as getSelectionLayers,
31
- r as luma,
30
+ t as deck,
31
+ b as getSelectionLayer,
32
+ s as luma,
32
33
  v as viv
33
34
  };
@@ -1,4 +1,4 @@
1
- import { B as BaseDecoder } from "./index-72755d2f.js";
1
+ import { B as BaseDecoder } from "./index-2a7f1ae0.js";
2
2
  import "react";
3
3
  const dctZigZag = new Int32Array([
4
4
  0,
@@ -1,5 +1,5 @@
1
1
  import { i as inflate_1 } from "./pako.esm-68f84e2a.js";
2
- import { g as getDefaultExportFromCjs, B as BaseDecoder, L as LercParameters, a as LercAddCompression } from "./index-72755d2f.js";
2
+ import { g as getDefaultExportFromCjs, B as BaseDecoder, L as LercParameters, a as LercAddCompression } from "./index-2a7f1ae0.js";
3
3
  import "react";
4
4
  var LercDecode = { exports: {} };
5
5
  (function(module) {
@@ -1,4 +1,4 @@
1
- import { B as BaseDecoder } from "./index-72755d2f.js";
1
+ import { B as BaseDecoder } from "./index-2a7f1ae0.js";
2
2
  import "react";
3
3
  const MIN_BITS = 9;
4
4
  const CLEAR_CODE = 256;
@@ -1,4 +1,4 @@
1
- import { B as BaseDecoder } from "./index-72755d2f.js";
1
+ import { B as BaseDecoder } from "./index-2a7f1ae0.js";
2
2
  import "react";
3
3
  class PackbitsDecoder extends BaseDecoder {
4
4
  decodeBlock(buffer) {
@@ -1,4 +1,4 @@
1
- import { B as BaseDecoder } from "./index-72755d2f.js";
1
+ import { B as BaseDecoder } from "./index-2a7f1ae0.js";
2
2
  import "react";
3
3
  class RawDecoder extends BaseDecoder {
4
4
  decodeBlock(buffer) {
@@ -1,4 +1,4 @@
1
- import { B as BaseDecoder } from "./index-72755d2f.js";
1
+ import { B as BaseDecoder } from "./index-2a7f1ae0.js";
2
2
  import "react";
3
3
  class WebImageDecoder extends BaseDecoder {
4
4
  constructor() {
@@ -0,0 +1,152 @@
1
+ declare const BitmaskLayer_base: new (...props: import(".pnpm/@vivjs+types@0.13.7/node_modules/@vivjs/types").Viv<{
2
+ contrastLimits: number[][];
3
+ channelsVisible: boolean[];
4
+ dtype: string;
5
+ domain?: number[] | undefined;
6
+ id?: string | undefined;
7
+ onHover?: Function | undefined;
8
+ onClick?: Function | undefined;
9
+ modelMatrix?: Object | undefined;
10
+ interpolation?: number | undefined;
11
+ }, string[]>[]) => any;
12
+ /**
13
+ * A BitmapLayer that performs aggregation in the fragment shader,
14
+ * and renders its texture from a Uint8Array rather than an ImageData.
15
+ */
16
+ declare class BitmaskLayer extends BitmaskLayer_base {
17
+ [x: string]: any;
18
+ getShaders(): {
19
+ fs: string;
20
+ vs: string;
21
+ modules: any[];
22
+ defines: {
23
+ COLORMAP_FUNC: any;
24
+ };
25
+ };
26
+ /**
27
+ * Override the parent loadChannelTextures to enable
28
+ * up to eight channels (rather than six).
29
+ * Reference: https://github.com/hms-dbmi/viv/blob/v0.13.3/packages/layers/src/xr-layer/xr-layer.js#L316
30
+ */
31
+ loadChannelTextures(channelData: any): void;
32
+ updateState({ props, oldProps, changeFlags }: {
33
+ props: any;
34
+ oldProps: any;
35
+ changeFlags: any;
36
+ }): void;
37
+ draw(opts: any): void;
38
+ /**
39
+ * This function creates textures from the data
40
+ */
41
+ dataToTexture(data: any, width: any, height: any): any;
42
+ multiSetsToTexture(multiFeatureValues: any, setColorValues: any, channelIsSetColorMode: any): any[];
43
+ }
44
+ declare namespace BitmaskLayer {
45
+ export const layerName: string;
46
+ export { defaultProps };
47
+ }
48
+ export default BitmaskLayer;
49
+ declare namespace defaultProps {
50
+ namespace channelStrokeWidths {
51
+ const type: string;
52
+ const value: null;
53
+ const compare: boolean;
54
+ }
55
+ namespace channelsFilled {
56
+ const type_1: string;
57
+ export { type_1 as type };
58
+ const value_1: null;
59
+ export { value_1 as value };
60
+ const compare_1: boolean;
61
+ export { compare_1 as compare };
62
+ }
63
+ namespace channelOpacities {
64
+ const type_2: string;
65
+ export { type_2 as type };
66
+ const value_2: null;
67
+ export { value_2 as value };
68
+ const compare_2: boolean;
69
+ export { compare_2 as compare };
70
+ }
71
+ namespace channelColors {
72
+ const type_3: string;
73
+ export { type_3 as type };
74
+ const value_3: null;
75
+ export { value_3 as value };
76
+ const compare_3: boolean;
77
+ export { compare_3 as compare };
78
+ }
79
+ namespace hoveredCell {
80
+ const type_4: string;
81
+ export { type_4 as type };
82
+ const value_4: null;
83
+ export { value_4 as value };
84
+ const compare_4: boolean;
85
+ export { compare_4 as compare };
86
+ }
87
+ namespace colormap {
88
+ const type_5: string;
89
+ export { type_5 as type };
90
+ export { GLSL_COLORMAP_DEFAULT as value };
91
+ const compare_5: boolean;
92
+ export { compare_5 as compare };
93
+ }
94
+ namespace expressionData {
95
+ const type_6: string;
96
+ export { type_6 as type };
97
+ const value_5: null;
98
+ export { value_5 as value };
99
+ const compare_6: boolean;
100
+ export { compare_6 as compare };
101
+ }
102
+ namespace multiFeatureValues {
103
+ const type_7: string;
104
+ export { type_7 as type };
105
+ const value_6: null;
106
+ export { value_6 as value };
107
+ const compare_7: boolean;
108
+ export { compare_7 as compare };
109
+ }
110
+ namespace setColorValues {
111
+ const type_8: string;
112
+ export { type_8 as type };
113
+ const value_7: null;
114
+ export { value_7 as value };
115
+ const compare_8: boolean;
116
+ export { compare_8 as compare };
117
+ }
118
+ namespace channelFeatureValueColormaps {
119
+ const type_9: string;
120
+ export { type_9 as type };
121
+ const value_8: null;
122
+ export { value_8 as value };
123
+ const compare_9: boolean;
124
+ export { compare_9 as compare };
125
+ }
126
+ namespace channelFeatureValueColormapRanges {
127
+ const type_10: string;
128
+ export { type_10 as type };
129
+ const value_9: null;
130
+ export { value_9 as value };
131
+ const compare_10: boolean;
132
+ export { compare_10 as compare };
133
+ }
134
+ namespace channelIsStaticColorMode {
135
+ const type_11: string;
136
+ export { type_11 as type };
137
+ const value_10: null;
138
+ export { value_10 as value };
139
+ const compare_11: boolean;
140
+ export { compare_11 as compare };
141
+ }
142
+ namespace channelIsSetColorMode {
143
+ const type_12: string;
144
+ export { type_12 as type };
145
+ const value_11: null;
146
+ export { value_11 as value };
147
+ const compare_12: boolean;
148
+ export { compare_12 as compare };
149
+ }
150
+ }
151
+ import { GLSL_COLORMAP_DEFAULT } from "./constants.js";
152
+ //# sourceMappingURL=BitmaskLayerBeta.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BitmaskLayerBeta.d.ts","sourceRoot":"","sources":["../src/BitmaskLayerBeta.js"],"names":[],"mappings":";;;;;;;;;;;AAgDA;;;GAGG;AACH;;IAEE;;;;;;;MAYC;IAED;;;;MAIE;IACF,4CA0BC;IAED;;;;aAyCC;IAED,sBAuHC;IAED;;OAEG;IACH,uDAqBC;IAED,oGAiEC;CACF"}
@@ -0,0 +1,253 @@
1
+ /* eslint-disable no-unused-vars */
2
+ import GL from '@luma.gl/constants'; // eslint-disable-line import/no-extraneous-dependencies
3
+ import { project32, picking } from '@deck.gl/core'; // eslint-disable-line import/no-extraneous-dependencies
4
+ import { Texture2D, isWebGL2 } from '@luma.gl/core';
5
+ import { XRLayer } from '@hms-dbmi/viv';
6
+ import { fromEntries } from '@vitessce/utils';
7
+ import { range } from 'lodash-es';
8
+ import { fs, vs } from './bitmask-layer-beta-shaders.js';
9
+ import { GLSL_COLORMAPS, GLSL_COLORMAP_DEFAULT, COLORMAP_SHADER_PLACEHOLDER, } from './constants.js';
10
+ import { multiSetsToTextureData } from './bitmask-utils.js';
11
+ const MAX_CHANNELS = 7;
12
+ const MULTI_FEATURE_TEX_SIZE = 2048;
13
+ function padWithDefault(arr, defaultValue, padWidth) {
14
+ const newArr = [...arr];
15
+ for (let i = 0; i < padWidth; i += 1) {
16
+ newArr.push(defaultValue);
17
+ }
18
+ return newArr;
19
+ }
20
+ function getColor(arr) {
21
+ return arr ? arr.map(v => v / 255) : [0, 0, 0];
22
+ }
23
+ const defaultProps = {
24
+ channelStrokeWidths: { type: 'array', value: null, compare: true },
25
+ channelsFilled: { type: 'array', value: null, compare: true },
26
+ channelOpacities: { type: 'array', value: null, compare: true },
27
+ channelColors: { type: 'array', value: null, compare: true },
28
+ hoveredCell: { type: 'number', value: null, compare: true },
29
+ colormap: { type: 'string', value: GLSL_COLORMAP_DEFAULT, compare: true },
30
+ expressionData: { type: 'object', value: null, compare: true },
31
+ multiFeatureValues: { type: 'array', value: null, compare: true },
32
+ setColorValues: { type: 'array', value: null, compare: true },
33
+ channelFeatureValueColormaps: { type: 'array', value: null, compare: true },
34
+ channelFeatureValueColormapRanges: { type: 'array', value: null, compare: true },
35
+ channelIsStaticColorMode: { type: 'array', value: null, compare: true },
36
+ channelIsSetColorMode: { type: 'array', value: null, compare: true },
37
+ };
38
+ /**
39
+ * A BitmapLayer that performs aggregation in the fragment shader,
40
+ * and renders its texture from a Uint8Array rather than an ImageData.
41
+ */
42
+ export default class BitmaskLayer extends XRLayer {
43
+ // eslint-disable-next-line class-methods-use-this
44
+ getShaders() {
45
+ const { colormap } = this.props;
46
+ return {
47
+ fs,
48
+ vs,
49
+ modules: [project32, picking],
50
+ defines: {
51
+ [COLORMAP_SHADER_PLACEHOLDER]: GLSL_COLORMAPS.includes(colormap)
52
+ ? colormap
53
+ : GLSL_COLORMAP_DEFAULT,
54
+ },
55
+ };
56
+ }
57
+ /**
58
+ * Override the parent loadChannelTextures to enable
59
+ * up to eight channels (rather than six).
60
+ * Reference: https://github.com/hms-dbmi/viv/blob/v0.13.3/packages/layers/src/xr-layer/xr-layer.js#L316
61
+ */
62
+ loadChannelTextures(channelData) {
63
+ const textures = {
64
+ channel0: null,
65
+ channel1: null,
66
+ channel2: null,
67
+ channel3: null,
68
+ channel4: null,
69
+ channel5: null,
70
+ channel6: null,
71
+ };
72
+ if (this.state.textures) {
73
+ Object.values(this.state.textures).forEach(tex => tex && tex.delete());
74
+ }
75
+ if (channelData
76
+ && Object.keys(channelData).length > 0
77
+ && channelData.data) {
78
+ channelData.data.forEach((d, i) => {
79
+ textures[`channel${i}`] = this.dataToTexture(d, channelData.width, channelData.height);
80
+ }, this);
81
+ this.setState({ textures });
82
+ }
83
+ }
84
+ updateState({ props, oldProps, changeFlags }) {
85
+ super.updateState({ props, oldProps, changeFlags });
86
+ if (props.multiFeatureValues !== oldProps.multiFeatureValues
87
+ || props.setColorValues !== oldProps.setColorValues
88
+ || props.channelIsSetColorMode !== oldProps.channelIsSetColorMode) {
89
+ const { multiFeatureValues, setColorValues, channelIsSetColorMode } = this.props;
90
+ // Use one expressionTex for all channels,
91
+ // using an offset mechanism.
92
+ const [valueTex, colorTex, valueTexOffsets, colorTexOffsets, valueTexHeight, colorTexHeight,] = this.multiSetsToTexture(multiFeatureValues, setColorValues, channelIsSetColorMode);
93
+ this.setState({
94
+ valueTex,
95
+ colorTex,
96
+ valueTexOffsets,
97
+ colorTexOffsets,
98
+ valueTexHeight,
99
+ colorTexHeight,
100
+ });
101
+ }
102
+ if (props.colormap !== oldProps.colormap) {
103
+ const { gl } = this.context;
104
+ if (this.state.model) {
105
+ this.state.model.delete();
106
+ }
107
+ // eslint-disable-next-line no-underscore-dangle
108
+ this.setState({ model: this._getModel(gl) });
109
+ this.getAttributeManager().invalidateAll();
110
+ }
111
+ }
112
+ draw(opts) {
113
+ const { uniforms } = opts;
114
+ const { channelStrokeWidths, channelsFilled, channelOpacities, channelColors, channelsVisible,
115
+ // TODO: use `channelFeatureValueColormaps` in shader,
116
+ // figure out how to call multiple GLSL colormap functions
117
+ channelFeatureValueColormaps, channelFeatureValueColormapRanges, channelIsStaticColorMode, channelIsSetColorMode, hoveredCell, colorScaleLo, colorScaleHi, isExpressionMode, zoom, minZoom, maxZoom, zoomOffset, // TODO: figure out if this needs to be used or not
118
+ } = this.props;
119
+ const { textures, model,
120
+ // Expression and set index (and colors) textures with offsets
121
+ valueTex, colorTex, valueTexOffsets, colorTexOffsets, valueTexHeight, colorTexHeight, } = this.state;
122
+ // Render the image
123
+ if (textures && model) {
124
+ const scaleFactor = 1 / (2 ** (maxZoom - zoom));
125
+ const colors = fromEntries(range(MAX_CHANNELS).map(i => ([`color${i}`, getColor(channelColors[i])])));
126
+ model
127
+ .setUniforms(Object.assign({}, uniforms, {
128
+ ...colors,
129
+ // Bitmask image channel data textures
130
+ ...textures,
131
+ multiFeatureTexSize: MULTI_FEATURE_TEX_SIZE,
132
+ // Expression textures with offsets
133
+ valueTex,
134
+ valueTexOffsets: padWithDefault(valueTexOffsets, 0, MAX_CHANNELS - valueTexOffsets.length),
135
+ valueTexHeight,
136
+ // Set indices and colors textures with offsets
137
+ colorTex,
138
+ colorTexOffsets: padWithDefault(colorTexOffsets, 0, MAX_CHANNELS - colorTexOffsets.length),
139
+ colorTexHeight,
140
+ // Visualization properties
141
+ channelsFilled: padWithDefault(channelsFilled, true,
142
+ // There are six texture entries on the shaders
143
+ MAX_CHANNELS - channelsFilled.length),
144
+ channelOpacities: padWithDefault(channelOpacities, 0.0,
145
+ // There are six texture entries on the shaders
146
+ MAX_CHANNELS - channelOpacities.length),
147
+ channelStrokeWidths: padWithDefault(channelStrokeWidths, 1.0,
148
+ // There are six texture entries on the shaders
149
+ MAX_CHANNELS - channelStrokeWidths.length),
150
+ channelColormapRangeStarts: padWithDefault(channelFeatureValueColormapRanges.map(r => r?.[0] || 0.0), 0.0,
151
+ // There are six texture entries on the shaders
152
+ MAX_CHANNELS - channelFeatureValueColormapRanges.length),
153
+ channelColormapRangeEnds: padWithDefault(channelFeatureValueColormapRanges.map(r => r?.[1] || 1.0), 1.0,
154
+ // There are six texture entries on the shaders
155
+ MAX_CHANNELS - channelFeatureValueColormapRanges.length),
156
+ channelIsStaticColorMode: padWithDefault(channelIsStaticColorMode, true,
157
+ // There are six texture entries on the shaders
158
+ MAX_CHANNELS - channelIsStaticColorMode.length),
159
+ channelIsSetColorMode: padWithDefault(channelIsSetColorMode, false,
160
+ // There are six texture entries on the shaders
161
+ MAX_CHANNELS - channelIsSetColorMode.length),
162
+ hovered: hoveredCell || 0,
163
+ channelsVisible: padWithDefault(channelsVisible, false,
164
+ // There are six texture entries on the shaders
165
+ MAX_CHANNELS - channelsVisible.length),
166
+ // uColorScaleRange: [colorScaleLo, colorScaleHi],
167
+ // uIsExpressionMode: isExpressionMode,
168
+ // uIsOutlined: false,
169
+ scaleFactor,
170
+ }))
171
+ .draw();
172
+ }
173
+ }
174
+ /**
175
+ * This function creates textures from the data
176
+ */
177
+ dataToTexture(data, width, height) {
178
+ const isWebGL2On = isWebGL2(this.context.gl);
179
+ return new Texture2D(this.context.gl, {
180
+ width,
181
+ height,
182
+ // Only use Float32 so we don't have to write two shaders
183
+ data: new Float32Array(data),
184
+ // we don't want or need mimaps
185
+ mipmaps: false,
186
+ parameters: {
187
+ // NEAREST for integer data
188
+ [GL.TEXTURE_MIN_FILTER]: GL.NEAREST,
189
+ [GL.TEXTURE_MAG_FILTER]: GL.NEAREST,
190
+ // CLAMP_TO_EDGE to remove tile artifacts
191
+ [GL.TEXTURE_WRAP_S]: GL.CLAMP_TO_EDGE,
192
+ [GL.TEXTURE_WRAP_T]: GL.CLAMP_TO_EDGE,
193
+ },
194
+ format: isWebGL2On ? GL.R32F : GL.LUMINANCE,
195
+ dataFormat: isWebGL2On ? GL.RED : GL.LUMINANCE,
196
+ type: GL.FLOAT,
197
+ });
198
+ }
199
+ multiSetsToTexture(multiFeatureValues, setColorValues, channelIsSetColorMode) {
200
+ const isWebGL2On = isWebGL2(this.context.gl);
201
+ const [totalData, valueTexHeight, indicesOffsets, totalColors, colorTexHeight, colorsOffsets,] = multiSetsToTextureData(multiFeatureValues, setColorValues, channelIsSetColorMode, MULTI_FEATURE_TEX_SIZE);
202
+ return [
203
+ // Color indices texture
204
+ new Texture2D(this.context.gl, {
205
+ width: MULTI_FEATURE_TEX_SIZE,
206
+ height: valueTexHeight,
207
+ // Only use Float32 so we don't have to write two shaders
208
+ data: new Float32Array(totalData),
209
+ // we don't want or need mimaps
210
+ mipmaps: false,
211
+ parameters: {
212
+ // NEAREST for integer data
213
+ [GL.TEXTURE_MIN_FILTER]: GL.NEAREST,
214
+ [GL.TEXTURE_MAG_FILTER]: GL.NEAREST,
215
+ // CLAMP_TO_EDGE to remove tile artifacts
216
+ [GL.TEXTURE_WRAP_S]: GL.CLAMP_TO_EDGE,
217
+ [GL.TEXTURE_WRAP_T]: GL.CLAMP_TO_EDGE,
218
+ },
219
+ format: isWebGL2On ? GL.R32F : GL.LUMINANCE,
220
+ dataFormat: isWebGL2On ? GL.RED : GL.LUMINANCE,
221
+ type: GL.FLOAT,
222
+ }),
223
+ // Colors texture
224
+ new Texture2D(this.context.gl, {
225
+ width: MULTI_FEATURE_TEX_SIZE,
226
+ height: colorTexHeight,
227
+ // Only use Float32 so we don't have to write two shaders
228
+ data: new Float32Array(totalColors),
229
+ // we don't want or need mimaps
230
+ mipmaps: false,
231
+ parameters: {
232
+ // NEAREST for integer data
233
+ [GL.TEXTURE_MIN_FILTER]: GL.NEAREST,
234
+ [GL.TEXTURE_MAG_FILTER]: GL.NEAREST,
235
+ // CLAMP_TO_EDGE to remove tile artifacts
236
+ [GL.TEXTURE_WRAP_S]: GL.CLAMP_TO_EDGE,
237
+ [GL.TEXTURE_WRAP_T]: GL.CLAMP_TO_EDGE,
238
+ },
239
+ format: isWebGL2On ? GL.R32F : GL.LUMINANCE,
240
+ dataFormat: isWebGL2On ? GL.RED : GL.LUMINANCE,
241
+ type: GL.FLOAT,
242
+ }),
243
+ // Offsets
244
+ indicesOffsets,
245
+ colorsOffsets,
246
+ // Texture heights
247
+ valueTexHeight,
248
+ colorTexHeight,
249
+ ];
250
+ }
251
+ }
252
+ BitmaskLayer.layerName = 'BitmaskLayer';
253
+ BitmaskLayer.defaultProps = defaultProps;
@@ -1,5 +1,6 @@
1
1
  declare class SelectionLayer {
2
2
  _selectPolygonObjects(coordinates: any): void;
3
+ _selectEmpty(): void;
3
4
  renderLayers(): EditableGeoJsonLayer[];
4
5
  }
5
6
  declare namespace SelectionLayer {
@@ -1 +1 @@
1
- {"version":3,"file":"SelectionLayer.d.ts","sourceRoot":"","sources":["../src/SelectionLayer.js"],"names":[],"mappings":"AAqEA;IACE,8CA0DC;IAED,uCAoDC;CACF;;;;;;;;;IAxJW,0BAAQ"}
1
+ {"version":3,"file":"SelectionLayer.d.ts","sourceRoot":"","sources":["../src/SelectionLayer.js"],"names":[],"mappings":"AAqEA;IACE,8CAqEC;IAED,qBAMC;IAED,uCAmDC;CACF;;;;;;;;;IA1KW,0BAAQ"}
@@ -61,48 +61,62 @@ const PASS_THROUGH_PROPS = [
61
61
  ];
62
62
  export default class SelectionLayer extends CompositeLayer {
63
63
  _selectPolygonObjects(coordinates) {
64
- const { onSelect, getCellCoords, cellsQuadTree, flipY, } = this.props;
64
+ const { flipY, obsLayers, } = this.props;
65
65
  const flippedCoordinates = (flipY
66
66
  ? coordinates.map(poly => poly.map(p => ([p[0], -p[1]])))
67
67
  : coordinates);
68
68
  // Convert the selection to a turf polygon object.
69
69
  const selectedPolygon = turfPolygon(flippedCoordinates);
70
- // Create an array to store the results.
71
- const pickingInfos = [];
72
70
  // quadtree.visit() takes a callback that returns a boolean:
73
71
  // If true returned, then the children of the node are _not_ visited.
74
72
  // If false returned, then the children of the node are visited.
75
73
  // Reference: https://github.com/d3/d3-quadtree#quadtree_visit
76
- cellsQuadTree.visit((node, x0, y0, x1, y1) => {
77
- const nodePoints = [[[x0, y0], [x1, y0], [x1, y1], [x0, y1], [x0, y0]]];
78
- const nodePolygon = turfPolygon(nodePoints);
79
- const nodePolygonContainsSelectedPolygon = booleanContains(nodePolygon, selectedPolygon);
80
- const nodePolygonWithinSelectedPolygon = booleanWithin(nodePolygon, selectedPolygon);
81
- const nodePolygonOverlapsSelectedPolgyon = booleanOverlap(nodePolygon, selectedPolygon);
82
- if (!nodePolygonContainsSelectedPolygon
83
- && !nodePolygonWithinSelectedPolygon
84
- && !nodePolygonOverlapsSelectedPolgyon) {
85
- // We are not interested in anything below this node,
86
- // so return true because we are done with this node.
87
- return true;
88
- }
89
- // This node made it past the above return statement, so it must either
90
- // contain, be within, or overlap with the selected polygon.
91
- // Check if this is a leaf node.
92
- if (node.data
93
- && booleanPointInPolygon(turfPoint([].slice.call(getCellCoords(node.data))), selectedPolygon)) {
94
- // This node has data, so it is a leaf node representing one data point,
95
- // and we have verified that the point is in the selected polygon.
96
- pickingInfos.push(node.data);
97
- }
98
- // Return false because we are not done.
99
- // We want to visit the children of this node.
100
- return false;
74
+ obsLayers.forEach((obsLayer) => {
75
+ const { getObsCoords, obsQuadTree, obsIndex, onSelect: layerOnSelect, } = obsLayer;
76
+ // Create an array to store the results.
77
+ // Clear the array before checking each new layer.
78
+ const pickingInfos = [];
79
+ // It is possible for a layer to not have an obsQuadTree,
80
+ // for example if the layer is a segmentation bitmask without associated
81
+ // obsLocations.
82
+ obsQuadTree?.visit((node, x0, y0, x1, y1) => {
83
+ const nodePoints = [[[x0, y0], [x1, y0], [x1, y1], [x0, y1], [x0, y0]]];
84
+ const nodePolygon = turfPolygon(nodePoints);
85
+ const nodePolygonContainsSelectedPolygon = booleanContains(nodePolygon, selectedPolygon);
86
+ const nodePolygonWithinSelectedPolygon = booleanWithin(nodePolygon, selectedPolygon);
87
+ const nodePolygonOverlapsSelectedPolgyon = booleanOverlap(nodePolygon, selectedPolygon);
88
+ if (!nodePolygonContainsSelectedPolygon
89
+ && !nodePolygonWithinSelectedPolygon
90
+ && !nodePolygonOverlapsSelectedPolgyon) {
91
+ // We are not interested in anything below this node,
92
+ // so return true because we are done with this node.
93
+ return true;
94
+ }
95
+ // This node made it past the above return statement, so it must either
96
+ // contain, be within, or overlap with the selected polygon.
97
+ // Check if this is a leaf node.
98
+ if (node.data
99
+ && booleanPointInPolygon(turfPoint([].slice.call(getObsCoords(node.data))), selectedPolygon)) {
100
+ // This node has data, so it is a leaf node representing one data point,
101
+ // and we have verified that the point is in the selected polygon.
102
+ pickingInfos.push(node.data);
103
+ }
104
+ // Return false because we are not done.
105
+ // We want to visit the children of this node.
106
+ return false;
107
+ });
108
+ const pickingIds = pickingInfos.map(obsI => obsIndex[obsI]);
109
+ layerOnSelect(pickingIds);
110
+ });
111
+ }
112
+ _selectEmpty() {
113
+ const { obsLayers } = this.props;
114
+ obsLayers.forEach((obsLayer) => {
115
+ const { onSelect: layerOnSelect } = obsLayer;
116
+ layerOnSelect([]);
101
117
  });
102
- onSelect({ pickingInfos });
103
118
  }
104
119
  renderLayers() {
105
- const { onSelect } = this.props;
106
120
  const mode = MODE_MAP[this.props.selectionType] || ViewMode;
107
121
  const inheritedProps = {};
108
122
  PASS_THROUGH_PROPS.forEach((p) => {
@@ -126,7 +140,7 @@ export default class SelectionLayer extends CompositeLayer {
126
140
  }
127
141
  else if (editType === EDIT_TYPE_CLEAR) {
128
142
  // We want to select an empty array to clear any previous selection.
129
- onSelect({ pickingInfos: [] });
143
+ this._selectEmpty();
130
144
  }
131
145
  },
132
146
  _subLayerProps: {
@@ -0,0 +1,3 @@
1
+ export const vs: "\n#define SHADER_NAME bitmask-layer-vertex-shader\n\nattribute vec2 texCoords;\nattribute vec3 positions;\nattribute vec3 positions64Low;\nattribute vec3 instancePickingColors;\n\nvarying vec2 vTexCoord;\n\nvoid main(void) {\n geometry.worldPosition = positions;\n geometry.uv = texCoords;\n geometry.pickingColor = instancePickingColors;\n gl_Position = project_position_to_clipspace(positions, positions64Low, vec3(0.0), geometry.position);\n DECKGL_FILTER_GL_POSITION(gl_Position, geometry);\n vTexCoord = texCoords;\n vec4 color = vec4(0.0);\n DECKGL_FILTER_COLOR(color, geometry);\n}\n";
2
+ export const fs: string;
3
+ //# sourceMappingURL=bitmask-layer-beta-shaders.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bitmask-layer-beta-shaders.d.ts","sourceRoot":"","sources":["../src/bitmask-layer-beta-shaders.js"],"names":[],"mappings":"AAEA,0mBAoBE;AAEF,wBA6LE"}