@vitessce/gl 2.0.0-beta.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.
- package/LICENSE +21 -0
- package/dist/BitmaskLayer.js +132 -0
- package/dist/HeatmapBitmapLayer.js +123 -0
- package/dist/HeatmapCompositeTextLayer.js +129 -0
- package/dist/PaddedExpressionHeatmapBitmapLayer.js +129 -0
- package/dist/PixelatedBitmapLayer.js +26 -0
- package/dist/ScaledExpressionExtension/ScaledExpressionExtension.js +105 -0
- package/dist/ScaledExpressionExtension/index.js +2 -0
- package/dist/ScaledExpressionExtension/shader-module.js +32 -0
- package/dist/SelectionExtension/SelectionExtension.js +31 -0
- package/dist/SelectionExtension/index.js +2 -0
- package/dist/SelectionExtension/shader-module.js +20 -0
- package/dist/SelectionLayer.js +167 -0
- package/dist/bitmask-layer-shaders.js +90 -0
- package/dist/constants.js +11 -0
- package/dist/deck.js +4 -0
- package/dist/glsl/index.js +340 -0
- package/dist/heatmap-bitmap-layer-shaders.js +109 -0
- package/dist/heatmap-constants.js +27 -0
- package/dist/index.js +17 -0
- package/dist/layer-controller.js +109 -0
- package/dist/luma.js +2 -0
- package/dist/padded-expression-heatmap-bitmap-layer-shaders.js +143 -0
- package/dist/selection-utils.js +92 -0
- package/dist/spatial.js +281 -0
- package/dist/spatial.test.js +8 -0
- package/dist/viv.js +9 -0
- package/package.json +62 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { colormaps } from '../glsl/index';
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
* Reference: https://github.com/visgl/deck.gl/blob/8.4-release/modules/layers/src/scatterplot-layer/scatterplot-layer-vertex.glsl.js
|
|
5
|
+
* Reference: https://observablehq.com/@rreusser/selecting-the-right-opacity-for-2d-point-clouds
|
|
6
|
+
* Reference: https://github.com/flekschas/regl-scatterplot/blob/5e3b03e/src/point.vs
|
|
7
|
+
*/
|
|
8
|
+
const vs = `
|
|
9
|
+
${colormaps}
|
|
10
|
+
|
|
11
|
+
// Custom attributes for Vitessce:
|
|
12
|
+
attribute float expressionValue;
|
|
13
|
+
|
|
14
|
+
// Custom uniforms for Vitessce:
|
|
15
|
+
uniform vec2 uColorScaleRange;
|
|
16
|
+
uniform bool uIsExpressionMode;
|
|
17
|
+
|
|
18
|
+
`;
|
|
19
|
+
const inject = {
|
|
20
|
+
'vs:DECKGL_FILTER_COLOR': `
|
|
21
|
+
if(uIsExpressionMode) {
|
|
22
|
+
float normalizedExpressionValue = expressionValue / 255.0;
|
|
23
|
+
float scaledExpressionValue = (normalizedExpressionValue - uColorScaleRange[0]) / max(0.005, (uColorScaleRange[1] - uColorScaleRange[0]));
|
|
24
|
+
color.rgb = COLORMAP_FUNC(clamp(scaledExpressionValue, 0.0, 1.0)).rgb;
|
|
25
|
+
}
|
|
26
|
+
`,
|
|
27
|
+
};
|
|
28
|
+
export default {
|
|
29
|
+
name: 'scaled-expression',
|
|
30
|
+
vs,
|
|
31
|
+
inject,
|
|
32
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/* eslint-disable no-underscore-dangle */
|
|
2
|
+
/* eslint-disable import/no-extraneous-dependencies */
|
|
3
|
+
import GL from '@luma.gl/constants';
|
|
4
|
+
import { LayerExtension } from '@deck.gl/core';
|
|
5
|
+
import module from './shader-module';
|
|
6
|
+
export default class SelectionExtension extends LayerExtension {
|
|
7
|
+
// eslint-disable-next-line class-methods-use-this
|
|
8
|
+
getShaders() {
|
|
9
|
+
return {
|
|
10
|
+
modules: [module],
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
initializeState(context, extension) {
|
|
14
|
+
const attributeManager = this.getAttributeManager();
|
|
15
|
+
if (attributeManager) {
|
|
16
|
+
attributeManager.add({
|
|
17
|
+
isSelected: {
|
|
18
|
+
type: GL.FLOAT,
|
|
19
|
+
size: 1,
|
|
20
|
+
transition: true,
|
|
21
|
+
accessor: 'getCellIsSelected',
|
|
22
|
+
defaultValue: 1,
|
|
23
|
+
// PolygonLayer needs not-intsanced attribute but
|
|
24
|
+
// ScatterplotLayer needs instanced.
|
|
25
|
+
divisor: Number(extension.opts.instanced),
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
SelectionExtension.extensionName = 'SelectionExtension';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const vs = `
|
|
2
|
+
attribute float isSelected;
|
|
3
|
+
`;
|
|
4
|
+
const inject = {
|
|
5
|
+
'vs:DECKGL_FILTER_GL_POSITION': `
|
|
6
|
+
position.z += (1. - isSelected) * .00005; // Add a small z offset for unselected points in the positive direction i.e into the screen.
|
|
7
|
+
`,
|
|
8
|
+
'fs:#main-start': ` // Gets rid of bad border effects (active after deck.gl 8.5): https://github.com/visgl/deck.gl/pull/6081
|
|
9
|
+
float distToCenterNew = length(unitPosition) * outerRadiusPixels;
|
|
10
|
+
float inCircleNew = step(distToCenterNew, outerRadiusPixels);
|
|
11
|
+
if (inCircleNew == 0.0) {
|
|
12
|
+
discard;
|
|
13
|
+
}
|
|
14
|
+
`,
|
|
15
|
+
};
|
|
16
|
+
export default {
|
|
17
|
+
name: 'selection',
|
|
18
|
+
vs,
|
|
19
|
+
inject,
|
|
20
|
+
};
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/* eslint-disable import/no-extraneous-dependencies */
|
|
2
|
+
/* eslint-disable no-underscore-dangle */
|
|
3
|
+
// File adopted from nebula.gl's SelectionLayer
|
|
4
|
+
// https://github.com/uber/nebula.gl/blob/8e9c2ec8d7cf4ca7050909ed826eb847d5e2cd9c/modules/layers/src/layers/selection-layer.js
|
|
5
|
+
import { CompositeLayer } from 'deck.gl';
|
|
6
|
+
import { polygon as turfPolygon, point as turfPoint } from '@turf/helpers';
|
|
7
|
+
import booleanWithin from '@turf/boolean-within';
|
|
8
|
+
import booleanContains from '@turf/boolean-contains';
|
|
9
|
+
import booleanOverlap from '@turf/boolean-overlap';
|
|
10
|
+
import booleanPointInPolygon from '@turf/boolean-point-in-polygon';
|
|
11
|
+
import { ScatterplotLayer } from '@deck.gl/layers';
|
|
12
|
+
import { SELECTION_TYPE } from 'nebula.gl';
|
|
13
|
+
import { EditableGeoJsonLayer } from '@nebula.gl/layers';
|
|
14
|
+
import { DrawRectangleMode, DrawPolygonByDraggingMode, ViewMode } from '@nebula.gl/edit-modes';
|
|
15
|
+
const EDIT_TYPE_ADD = 'addFeature';
|
|
16
|
+
const EDIT_TYPE_CLEAR = 'clearFeatures';
|
|
17
|
+
// Customize the click handlers for the rectangle and polygon tools,
|
|
18
|
+
// so that clicking triggers the `onEdit` callback.
|
|
19
|
+
class ClickableDrawRectangleMode extends DrawRectangleMode {
|
|
20
|
+
// eslint-disable-next-line class-methods-use-this
|
|
21
|
+
handleClick(event, props) {
|
|
22
|
+
props.onEdit({ editType: EDIT_TYPE_CLEAR });
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
class ClickableDrawPolygonByDraggingMode extends DrawPolygonByDraggingMode {
|
|
26
|
+
// eslint-disable-next-line class-methods-use-this
|
|
27
|
+
handleClick(event, props) {
|
|
28
|
+
props.onEdit({ editType: EDIT_TYPE_CLEAR });
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const MODE_MAP = {
|
|
32
|
+
[SELECTION_TYPE.RECTANGLE]: ClickableDrawRectangleMode,
|
|
33
|
+
[SELECTION_TYPE.POLYGON]: ClickableDrawPolygonByDraggingMode,
|
|
34
|
+
};
|
|
35
|
+
const defaultProps = {
|
|
36
|
+
selectionType: SELECTION_TYPE.RECTANGLE,
|
|
37
|
+
layerIds: [],
|
|
38
|
+
onSelect: () => { },
|
|
39
|
+
};
|
|
40
|
+
const EMPTY_DATA = {
|
|
41
|
+
type: 'FeatureCollection',
|
|
42
|
+
features: [],
|
|
43
|
+
};
|
|
44
|
+
const LAYER_ID_GEOJSON = 'selection-geojson';
|
|
45
|
+
const PASS_THROUGH_PROPS = [
|
|
46
|
+
'lineWidthScale',
|
|
47
|
+
'lineWidthMinPixels',
|
|
48
|
+
'lineWidthMaxPixels',
|
|
49
|
+
'lineWidthUnits',
|
|
50
|
+
'lineJointRounded',
|
|
51
|
+
'lineMiterLimit',
|
|
52
|
+
'pointRadiusScale',
|
|
53
|
+
'pointRadiusMinPixels',
|
|
54
|
+
'pointRadiusMaxPixels',
|
|
55
|
+
'lineDashJustified',
|
|
56
|
+
'getLineColor',
|
|
57
|
+
'getFillColor',
|
|
58
|
+
'getPointRadius',
|
|
59
|
+
'getLineWidth',
|
|
60
|
+
'getLineDashArray',
|
|
61
|
+
'getTentativeLineDashArray',
|
|
62
|
+
'getTentativeLineColor',
|
|
63
|
+
'getTentativeFillColor',
|
|
64
|
+
'getTentativeLineWidth',
|
|
65
|
+
'editHandlePointRadiusScale',
|
|
66
|
+
'editHandlePointRadiusMinPixels',
|
|
67
|
+
'editHandlePointRadiusMaxPixels',
|
|
68
|
+
'getEditHandlePointColor',
|
|
69
|
+
'getEditHandlePointRadius',
|
|
70
|
+
'modeHandlers',
|
|
71
|
+
];
|
|
72
|
+
export default class SelectionLayer extends CompositeLayer {
|
|
73
|
+
_selectPolygonObjects(coordinates) {
|
|
74
|
+
const { onSelect, getCellCoords, cellsQuadTree, flipY, } = this.props;
|
|
75
|
+
const flippedCoordinates = (flipY
|
|
76
|
+
? coordinates.map(poly => poly.map(p => ([p[0], -p[1]])))
|
|
77
|
+
: coordinates);
|
|
78
|
+
// Convert the selection to a turf polygon object.
|
|
79
|
+
const selectedPolygon = turfPolygon(flippedCoordinates);
|
|
80
|
+
// Create an array to store the results.
|
|
81
|
+
const pickingInfos = [];
|
|
82
|
+
// quadtree.visit() takes a callback that returns a boolean:
|
|
83
|
+
// If true returned, then the children of the node are _not_ visited.
|
|
84
|
+
// If false returned, then the children of the node are visited.
|
|
85
|
+
// Reference: https://github.com/d3/d3-quadtree#quadtree_visit
|
|
86
|
+
cellsQuadTree.visit((node, x0, y0, x1, y1) => {
|
|
87
|
+
const nodePoints = [[[x0, y0], [x1, y0], [x1, y1], [x0, y1], [x0, y0]]];
|
|
88
|
+
const nodePolygon = turfPolygon(nodePoints);
|
|
89
|
+
const nodePolygonContainsSelectedPolygon = booleanContains(nodePolygon, selectedPolygon);
|
|
90
|
+
const nodePolygonWithinSelectedPolygon = booleanWithin(nodePolygon, selectedPolygon);
|
|
91
|
+
const nodePolygonOverlapsSelectedPolgyon = booleanOverlap(nodePolygon, selectedPolygon);
|
|
92
|
+
if (!nodePolygonContainsSelectedPolygon
|
|
93
|
+
&& !nodePolygonWithinSelectedPolygon
|
|
94
|
+
&& !nodePolygonOverlapsSelectedPolgyon) {
|
|
95
|
+
// We are not interested in anything below this node,
|
|
96
|
+
// so return true because we are done with this node.
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
// This node made it past the above return statement, so it must either
|
|
100
|
+
// contain, be within, or overlap with the selected polygon.
|
|
101
|
+
// Check if this is a leaf node.
|
|
102
|
+
if (node.data
|
|
103
|
+
&& booleanPointInPolygon(turfPoint([].slice.call(getCellCoords(node.data))), selectedPolygon)) {
|
|
104
|
+
// This node has data, so it is a leaf node representing one data point,
|
|
105
|
+
// and we have verified that the point is in the selected polygon.
|
|
106
|
+
pickingInfos.push(node.data);
|
|
107
|
+
}
|
|
108
|
+
// Return false because we are not done.
|
|
109
|
+
// We want to visit the children of this node.
|
|
110
|
+
return false;
|
|
111
|
+
});
|
|
112
|
+
onSelect({ pickingInfos });
|
|
113
|
+
}
|
|
114
|
+
renderLayers() {
|
|
115
|
+
const { onSelect } = this.props;
|
|
116
|
+
const mode = MODE_MAP[this.props.selectionType] || ViewMode;
|
|
117
|
+
const inheritedProps = {};
|
|
118
|
+
PASS_THROUGH_PROPS.forEach((p) => {
|
|
119
|
+
if (this.props[p] !== undefined)
|
|
120
|
+
inheritedProps[p] = this.props[p];
|
|
121
|
+
});
|
|
122
|
+
const layers = [
|
|
123
|
+
new EditableGeoJsonLayer(this.getSubLayerProps({
|
|
124
|
+
id: LAYER_ID_GEOJSON,
|
|
125
|
+
pickable: true,
|
|
126
|
+
mode,
|
|
127
|
+
modeConfig: {
|
|
128
|
+
dragToDraw: true,
|
|
129
|
+
},
|
|
130
|
+
selectedFeatureIndexes: [],
|
|
131
|
+
data: EMPTY_DATA,
|
|
132
|
+
onEdit: ({ updatedData, editType }) => {
|
|
133
|
+
if (editType === EDIT_TYPE_ADD) {
|
|
134
|
+
const { coordinates } = updatedData.features[0].geometry;
|
|
135
|
+
this._selectPolygonObjects(coordinates);
|
|
136
|
+
}
|
|
137
|
+
else if (editType === EDIT_TYPE_CLEAR) {
|
|
138
|
+
// We want to select an empty array to clear any previous selection.
|
|
139
|
+
onSelect({ pickingInfos: [] });
|
|
140
|
+
}
|
|
141
|
+
},
|
|
142
|
+
_subLayerProps: {
|
|
143
|
+
guides: {
|
|
144
|
+
pointType: 'circle',
|
|
145
|
+
_subLayerProps: {
|
|
146
|
+
'points-circle': {
|
|
147
|
+
// Styling for editHandles goes here.
|
|
148
|
+
// Reference: https://github.com/uber/nebula.gl/issues/618#issuecomment-898466319
|
|
149
|
+
type: ScatterplotLayer,
|
|
150
|
+
radiusScale: 1,
|
|
151
|
+
stroked: true,
|
|
152
|
+
getLineWidth: 1,
|
|
153
|
+
radiusMinPixels: 1,
|
|
154
|
+
radiusMaxPixels: 3,
|
|
155
|
+
getPointRadius: 2,
|
|
156
|
+
},
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
},
|
|
160
|
+
...inheritedProps,
|
|
161
|
+
})),
|
|
162
|
+
];
|
|
163
|
+
return layers;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
SelectionLayer.layerName = 'SelectionLayer';
|
|
167
|
+
SelectionLayer.defaultProps = defaultProps;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { colormaps } from './glsl/index';
|
|
2
|
+
export const vs = `
|
|
3
|
+
#define SHADER_NAME bitmask-layer-vertex-shader
|
|
4
|
+
|
|
5
|
+
attribute vec2 texCoords;
|
|
6
|
+
attribute vec3 positions;
|
|
7
|
+
attribute vec3 positions64Low;
|
|
8
|
+
attribute vec3 instancePickingColors;
|
|
9
|
+
|
|
10
|
+
varying vec2 vTexCoord;
|
|
11
|
+
|
|
12
|
+
void main(void) {
|
|
13
|
+
geometry.worldPosition = positions;
|
|
14
|
+
geometry.uv = texCoords;
|
|
15
|
+
geometry.pickingColor = instancePickingColors;
|
|
16
|
+
gl_Position = project_position_to_clipspace(positions, positions64Low, vec3(0.0), geometry.position);
|
|
17
|
+
DECKGL_FILTER_GL_POSITION(gl_Position, geometry);
|
|
18
|
+
vTexCoord = texCoords;
|
|
19
|
+
vec4 color = vec4(0.0);
|
|
20
|
+
DECKGL_FILTER_COLOR(color, geometry);
|
|
21
|
+
}
|
|
22
|
+
`;
|
|
23
|
+
export const fs = `
|
|
24
|
+
#define SHADER_NAME bitmask-layer-fragment-shader
|
|
25
|
+
precision highp float;
|
|
26
|
+
|
|
27
|
+
${colormaps}
|
|
28
|
+
|
|
29
|
+
// Data (mask) texture
|
|
30
|
+
uniform sampler2D channel0;
|
|
31
|
+
uniform sampler2D channel1;
|
|
32
|
+
uniform sampler2D channel2;
|
|
33
|
+
uniform sampler2D channel3;
|
|
34
|
+
uniform sampler2D channel4;
|
|
35
|
+
uniform sampler2D channel5;
|
|
36
|
+
|
|
37
|
+
// Color texture
|
|
38
|
+
uniform sampler2D colorTex;
|
|
39
|
+
uniform float colorTexHeight;
|
|
40
|
+
uniform float colorTexWidth;
|
|
41
|
+
uniform float hovered;
|
|
42
|
+
// range
|
|
43
|
+
uniform bool channelsVisible[6];
|
|
44
|
+
|
|
45
|
+
// Expression mapping
|
|
46
|
+
uniform vec2 uColorScaleRange;
|
|
47
|
+
uniform bool uIsExpressionMode;
|
|
48
|
+
uniform sampler2D expressionTex;
|
|
49
|
+
|
|
50
|
+
// opacity
|
|
51
|
+
uniform float opacity;
|
|
52
|
+
|
|
53
|
+
varying vec2 vTexCoord;
|
|
54
|
+
|
|
55
|
+
vec4 sampleAndGetColor(sampler2D dataTex, vec2 coord, bool isOn){
|
|
56
|
+
float sampledData = texture(dataTex, coord).r;
|
|
57
|
+
vec4 hoveredColor = float(sampledData == hovered && sampledData > 0. && hovered > 0.) * vec4(0., 0., 1., 1.);
|
|
58
|
+
// Colors are laid out corresponding to ids in row-major order in the texture. So if width of the texture is 10, and you want ID 25,
|
|
59
|
+
// you need coordinate (1, 4) (i.e 2 rows down, and 5 columns over indexed from 0 for a total of 25 units covered in row major order).
|
|
60
|
+
vec2 colorTexCoord = vec2(mod(sampledData, colorTexWidth) / colorTexWidth, floor(sampledData / colorTexWidth) / (colorTexHeight - 1.));
|
|
61
|
+
float expressionValue = texture(expressionTex, colorTexCoord).r / 255.;
|
|
62
|
+
float scaledExpressionValue = (expressionValue - uColorScaleRange[0]) / max(0.005, (uColorScaleRange[1] - uColorScaleRange[0]));
|
|
63
|
+
vec4 sampledColor = float(uIsExpressionMode) * COLORMAP_FUNC(clamp(scaledExpressionValue, 0.0, 1.0)) + (1. - float(uIsExpressionMode)) * vec4(texture(colorTex, colorTexCoord).rgb, 1.);
|
|
64
|
+
// Only return a color if the data is non-zero.
|
|
65
|
+
return max(0., min(sampledData, 1.)) * float(isOn) * (sampledColor + hoveredColor);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
void main() {
|
|
69
|
+
|
|
70
|
+
gl_FragColor = sampleAndGetColor(channel0, vTexCoord, channelsVisible[0]);
|
|
71
|
+
|
|
72
|
+
// If the sampled color and the currently stored color (gl_FragColor) are identical, don't blend and use the sampled color,
|
|
73
|
+
// otherwise just use the currently stored color. Repeat this for all channels.
|
|
74
|
+
vec4 sampledColor = sampleAndGetColor(channel1, vTexCoord, channelsVisible[1]);
|
|
75
|
+
gl_FragColor = (sampledColor == gl_FragColor || sampledColor == vec4(0.)) ? gl_FragColor : sampledColor;
|
|
76
|
+
sampledColor = sampleAndGetColor(channel2, vTexCoord, channelsVisible[2]);
|
|
77
|
+
gl_FragColor = (sampledColor == gl_FragColor || sampledColor == vec4(0.)) ? gl_FragColor : sampledColor;
|
|
78
|
+
sampledColor = sampleAndGetColor(channel3, vTexCoord, channelsVisible[3]);
|
|
79
|
+
gl_FragColor = (sampledColor == gl_FragColor || sampledColor == vec4(0.)) ? gl_FragColor : sampledColor;
|
|
80
|
+
sampledColor = sampleAndGetColor(channel4, vTexCoord, channelsVisible[4]);
|
|
81
|
+
gl_FragColor = (sampledColor == gl_FragColor || sampledColor == vec4(0.)) ? gl_FragColor : sampledColor;
|
|
82
|
+
sampledColor = sampleAndGetColor(channel5, vTexCoord, channelsVisible[5]);
|
|
83
|
+
gl_FragColor = (sampledColor == gl_FragColor || sampledColor == vec4(0.)) ? gl_FragColor : sampledColor;
|
|
84
|
+
// Apply the opacity if there is pixel data, and if the pixel data is empty i.e no segmentation, use 0 opacity.
|
|
85
|
+
gl_FragColor = vec4(gl_FragColor.rgb, (gl_FragColor.rgb == vec3(0., 0., 0.)) ? 0.0 : opacity);
|
|
86
|
+
|
|
87
|
+
geometry.uv = vTexCoord;
|
|
88
|
+
DECKGL_FILTER_COLOR(gl_FragColor, geometry);
|
|
89
|
+
}
|
|
90
|
+
`;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// List of the GLSL colormaps available,
|
|
2
|
+
// to validate against before string replacing.
|
|
3
|
+
export const GLSL_COLORMAPS = [
|
|
4
|
+
'plasma',
|
|
5
|
+
'viridis',
|
|
6
|
+
'jet',
|
|
7
|
+
];
|
|
8
|
+
export const GLSL_COLORMAP_DEFAULT = 'plasma';
|
|
9
|
+
export const COLORMAP_SHADER_PLACEHOLDER = 'COLORMAP_FUNC';
|
|
10
|
+
export const DEFAULT_GL_OPTIONS = { webgl2: true };
|
|
11
|
+
export { SELECTION_TYPE } from 'nebula.gl';
|
package/dist/deck.js
ADDED