@deck.gl/aggregation-layers 8.8.0-beta.2 → 8.8.0-beta.5
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/dist/dist.dev.js +271 -261
- package/dist/es5/contour-layer/contour-layer.js.map +1 -1
- package/dist/es5/cpu-grid-layer/cpu-grid-layer.js.map +1 -1
- package/dist/es5/gpu-grid-layer/gpu-grid-layer.js.map +1 -1
- package/dist/es5/grid-layer/grid-layer.js.map +1 -1
- package/dist/es5/heatmap-layer/heatmap-layer.js +17 -12
- package/dist/es5/heatmap-layer/heatmap-layer.js.map +1 -1
- package/dist/es5/hexagon-layer/hexagon-layer.js.map +1 -1
- package/dist/es5/screen-grid-layer/screen-grid-layer.js.map +1 -1
- package/dist/esm/contour-layer/contour-layer.js.map +1 -1
- package/dist/esm/cpu-grid-layer/cpu-grid-layer.js.map +1 -1
- package/dist/esm/gpu-grid-layer/gpu-grid-layer.js.map +1 -1
- package/dist/esm/grid-layer/grid-layer.js.map +1 -1
- package/dist/esm/heatmap-layer/heatmap-layer.js +16 -12
- package/dist/esm/heatmap-layer/heatmap-layer.js.map +1 -1
- package/dist/esm/hexagon-layer/hexagon-layer.js.map +1 -1
- package/dist/esm/screen-grid-layer/screen-grid-layer.js.map +1 -1
- package/dist.min.js +1 -1
- package/package.json +2 -2
- package/src/contour-layer/contour-layer.ts +2 -0
- package/src/cpu-grid-layer/cpu-grid-layer.ts +1 -0
- package/src/gpu-grid-layer/gpu-grid-layer.ts +1 -3
- package/src/grid-layer/grid-layer.ts +1 -0
- package/src/heatmap-layer/heatmap-layer.ts +24 -12
- package/src/hexagon-layer/hexagon-layer.ts +1 -0
- package/src/screen-grid-layer/screen-grid-layer.ts +1 -0
- package/typed/contour-layer/contour-layer.d.ts +1 -0
- package/typed/contour-layer/contour-layer.d.ts.map +1 -1
- package/typed/cpu-grid-layer/cpu-grid-layer.d.ts +1 -0
- package/typed/cpu-grid-layer/cpu-grid-layer.d.ts.map +1 -1
- package/typed/gpu-grid-layer/gpu-grid-layer.d.ts +1 -3
- package/typed/gpu-grid-layer/gpu-grid-layer.d.ts.map +1 -1
- package/typed/grid-layer/grid-layer.d.ts +1 -0
- package/typed/grid-layer/grid-layer.d.ts.map +1 -1
- package/typed/heatmap-layer/heatmap-layer.d.ts +1 -0
- package/typed/heatmap-layer/heatmap-layer.d.ts.map +1 -1
- package/typed/hexagon-layer/hexagon-layer.d.ts +1 -0
- package/typed/hexagon-layer/hexagon-layer.d.ts.map +1 -1
- package/typed/screen-grid-layer/screen-grid-layer.d.ts +1 -0
- package/typed/screen-grid-layer/screen-grid-layer.d.ts.map +1 -1
- package/typed/utils/bin-sorter.d.ts +1 -1
- package/typed/aggregation-layer.js +0 -151
- package/typed/contour-layer/contour-layer.js +0 -234
- package/typed/contour-layer/contour-utils.js +0 -64
- package/typed/contour-layer/marching-squares-codes.js +0 -337
- package/typed/contour-layer/marching-squares.js +0 -147
- package/typed/cpu-grid-layer/cpu-grid-layer.js +0 -129
- package/typed/cpu-grid-layer/grid-aggregator.js +0 -141
- package/typed/gpu-grid-layer/gpu-grid-cell-layer-fragment.glsl.js +0 -34
- package/typed/gpu-grid-layer/gpu-grid-cell-layer-vertex.glsl.js +0 -141
- package/typed/gpu-grid-layer/gpu-grid-cell-layer.js +0 -143
- package/typed/gpu-grid-layer/gpu-grid-layer.js +0 -289
- package/typed/grid-aggregation-layer.js +0 -172
- package/typed/grid-layer/grid-layer.js +0 -60
- package/typed/heatmap-layer/heatmap-layer-utils.js +0 -78
- package/typed/heatmap-layer/heatmap-layer.js +0 -478
- package/typed/heatmap-layer/max-fs.glsl.js +0 -7
- package/typed/heatmap-layer/max-vs.glsl.js +0 -12
- package/typed/heatmap-layer/triangle-layer-fragment.glsl.js +0 -58
- package/typed/heatmap-layer/triangle-layer-vertex.glsl.js +0 -51
- package/typed/heatmap-layer/triangle-layer.js +0 -67
- package/typed/heatmap-layer/weights-fs.glsl.js +0 -19
- package/typed/heatmap-layer/weights-vs.glsl.js +0 -23
- package/typed/hexagon-layer/hexagon-aggregator.js +0 -112
- package/typed/hexagon-layer/hexagon-layer.js +0 -171
- package/typed/index.js +0 -33
- package/typed/screen-grid-layer/screen-grid-cell-layer.js +0 -159
- package/typed/screen-grid-layer/screen-grid-layer-fragment.glsl.js +0 -37
- package/typed/screen-grid-layer/screen-grid-layer-vertex.glsl.js +0 -83
- package/typed/screen-grid-layer/screen-grid-layer.js +0 -216
- package/typed/types.js +0 -1
- package/typed/utils/aggregation-operation-utils.js +0 -94
- package/typed/utils/bin-sorter.js +0 -167
- package/typed/utils/color-utils.js +0 -53
- package/typed/utils/cpu-aggregator.js +0 -417
- package/typed/utils/gpu-grid-aggregation/aggregate-all-fs.glsl.js +0 -39
- package/typed/utils/gpu-grid-aggregation/aggregate-all-vs.glsl.js +0 -53
- package/typed/utils/gpu-grid-aggregation/aggregate-to-grid-fs.glsl.js +0 -31
- package/typed/utils/gpu-grid-aggregation/aggregate-to-grid-vs.glsl.js +0 -77
- package/typed/utils/gpu-grid-aggregation/gpu-grid-aggregator-constants.js +0 -41
- package/typed/utils/gpu-grid-aggregation/gpu-grid-aggregator-utils.js +0 -1
- package/typed/utils/gpu-grid-aggregation/gpu-grid-aggregator.js +0 -562
- package/typed/utils/gpu-grid-aggregation/transform-mean-vs.glsl.js +0 -36
- package/typed/utils/grid-aggregation-utils.js +0 -114
- package/typed/utils/prop-utils.js +0 -28
- package/typed/utils/resource-utils.js +0 -40
- package/typed/utils/scale-utils.js +0 -184
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
// All utility methods needed to implement Marching Squares algorithm
|
|
2
|
-
// Ref: https://en.wikipedia.org/wiki/Marching_squares
|
|
3
|
-
import { log } from '@deck.gl/core';
|
|
4
|
-
import { ISOLINES_CODE_OFFSET_MAP, ISOBANDS_CODE_OFFSET_MAP } from './marching-squares-codes';
|
|
5
|
-
export const CONTOUR_TYPE = {
|
|
6
|
-
ISO_LINES: 1,
|
|
7
|
-
ISO_BANDS: 2
|
|
8
|
-
};
|
|
9
|
-
const DEFAULT_THRESHOLD_DATA = {
|
|
10
|
-
zIndex: 0,
|
|
11
|
-
zOffset: 0.005
|
|
12
|
-
};
|
|
13
|
-
// Utility methods
|
|
14
|
-
function getVertexCode(weight, threshold) {
|
|
15
|
-
// threshold must be a single value or a range (array of size 2)
|
|
16
|
-
// Iso-bands
|
|
17
|
-
if (Array.isArray(threshold)) {
|
|
18
|
-
if (weight < threshold[0]) {
|
|
19
|
-
return 0;
|
|
20
|
-
}
|
|
21
|
-
return weight < threshold[1] ? 1 : 2;
|
|
22
|
-
}
|
|
23
|
-
// Iso-lines
|
|
24
|
-
return weight >= threshold ? 1 : 0;
|
|
25
|
-
}
|
|
26
|
-
// Returns marching square code for given cell
|
|
27
|
-
/* eslint-disable complexity, max-statements*/
|
|
28
|
-
export function getCode(opts) {
|
|
29
|
-
// Assumptions
|
|
30
|
-
// Origin is on bottom-left , and X increase to right, Y to top
|
|
31
|
-
// When processing one cell, we process 4 cells, by extending row to top and on column to right
|
|
32
|
-
// to create a 2X2 cell grid
|
|
33
|
-
const { cellWeights, x, y, width, height } = opts;
|
|
34
|
-
let threshold = opts.threshold;
|
|
35
|
-
if (opts.thresholdValue) {
|
|
36
|
-
log.deprecated('thresholdValue', 'threshold')();
|
|
37
|
-
threshold = opts.thresholdValue;
|
|
38
|
-
}
|
|
39
|
-
const isLeftBoundary = x < 0;
|
|
40
|
-
const isRightBoundary = x >= width - 1;
|
|
41
|
-
const isBottomBoundary = y < 0;
|
|
42
|
-
const isTopBoundary = y >= height - 1;
|
|
43
|
-
const isBoundary = isLeftBoundary || isRightBoundary || isBottomBoundary || isTopBoundary;
|
|
44
|
-
const weights = {};
|
|
45
|
-
const codes = {};
|
|
46
|
-
// TOP
|
|
47
|
-
if (isLeftBoundary || isTopBoundary) {
|
|
48
|
-
codes.top = 0;
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
weights.top = cellWeights[(y + 1) * width + x];
|
|
52
|
-
codes.top = getVertexCode(weights.top, threshold);
|
|
53
|
-
}
|
|
54
|
-
// TOP-RIGHT
|
|
55
|
-
if (isRightBoundary || isTopBoundary) {
|
|
56
|
-
codes.topRight = 0;
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
weights.topRight = cellWeights[(y + 1) * width + x + 1];
|
|
60
|
-
codes.topRight = getVertexCode(weights.topRight, threshold);
|
|
61
|
-
}
|
|
62
|
-
// RIGHT
|
|
63
|
-
if (isRightBoundary || isBottomBoundary) {
|
|
64
|
-
codes.right = 0;
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
weights.right = cellWeights[y * width + x + 1];
|
|
68
|
-
codes.right = getVertexCode(weights.right, threshold);
|
|
69
|
-
}
|
|
70
|
-
// CURRENT
|
|
71
|
-
if (isLeftBoundary || isBottomBoundary) {
|
|
72
|
-
codes.current = 0;
|
|
73
|
-
}
|
|
74
|
-
else {
|
|
75
|
-
weights.current = cellWeights[y * width + x];
|
|
76
|
-
codes.current = getVertexCode(weights.current, threshold);
|
|
77
|
-
}
|
|
78
|
-
const { top, topRight, right, current } = codes;
|
|
79
|
-
let code = -1;
|
|
80
|
-
if (Number.isFinite(threshold)) {
|
|
81
|
-
code = (top << 3) | (topRight << 2) | (right << 1) | current;
|
|
82
|
-
}
|
|
83
|
-
if (Array.isArray(threshold)) {
|
|
84
|
-
code = (top << 6) | (topRight << 4) | (right << 2) | current;
|
|
85
|
-
}
|
|
86
|
-
let meanCode = 0;
|
|
87
|
-
// meanCode is only needed for saddle cases, and they should
|
|
88
|
-
// only occur when we are not processing a cell on boundary
|
|
89
|
-
// because when on a boundary either, bottom-row, top-row, left-column or right-column will have both 0 codes
|
|
90
|
-
if (!isBoundary) {
|
|
91
|
-
meanCode = getVertexCode((weights.top + weights.topRight + weights.right + weights.current) / 4, threshold);
|
|
92
|
-
}
|
|
93
|
-
return { code, meanCode };
|
|
94
|
-
}
|
|
95
|
-
/* eslint-enable complexity, max-statements*/
|
|
96
|
-
// Returns intersection vertices for given cellindex
|
|
97
|
-
// [x, y] refers current marching cell, reference vertex is always top-right corner
|
|
98
|
-
export function getVertices(opts) {
|
|
99
|
-
const { gridOrigin, cellSize, x, y, code, meanCode, type = CONTOUR_TYPE.ISO_LINES } = opts;
|
|
100
|
-
const thresholdData = { ...DEFAULT_THRESHOLD_DATA, ...opts.thresholdData };
|
|
101
|
-
let offsets = type === CONTOUR_TYPE.ISO_BANDS
|
|
102
|
-
? ISOBANDS_CODE_OFFSET_MAP[code]
|
|
103
|
-
: ISOLINES_CODE_OFFSET_MAP[code];
|
|
104
|
-
// handle saddle cases
|
|
105
|
-
if (!Array.isArray(offsets)) {
|
|
106
|
-
offsets = offsets[meanCode];
|
|
107
|
-
}
|
|
108
|
-
// Reference vertex is at top-right move to top-right corner
|
|
109
|
-
const vZ = thresholdData.zIndex * thresholdData.zOffset;
|
|
110
|
-
const rX = (x + 1) * cellSize[0];
|
|
111
|
-
const rY = (y + 1) * cellSize[1];
|
|
112
|
-
const refVertexX = gridOrigin[0] + rX;
|
|
113
|
-
const refVertexY = gridOrigin[1] + rY;
|
|
114
|
-
// offsets format
|
|
115
|
-
// ISO_LINES: [[1A, 1B], [2A, 2B]],
|
|
116
|
-
// ISO_BANDS: [[1A, 1B, 1C, ...], [2A, 2B, 2C, ...]],
|
|
117
|
-
// vertices format
|
|
118
|
-
// ISO_LINES: [[x1A, y1A], [x1B, y1B], [x2A, x2B], ...],
|
|
119
|
-
// ISO_BANDS: => confirms to SolidPolygonLayer's simple polygon format
|
|
120
|
-
// [
|
|
121
|
-
// [[x1A, y1A], [x1B, y1B], [x1C, y1C] ... ],
|
|
122
|
-
// ...
|
|
123
|
-
// ]
|
|
124
|
-
if (type === CONTOUR_TYPE.ISO_BANDS) {
|
|
125
|
-
const polygons = [];
|
|
126
|
-
offsets.forEach(polygonOffsets => {
|
|
127
|
-
const polygon = [];
|
|
128
|
-
polygonOffsets.forEach(xyOffset => {
|
|
129
|
-
const vX = refVertexX + xyOffset[0] * cellSize[0];
|
|
130
|
-
const vY = refVertexY + xyOffset[1] * cellSize[1];
|
|
131
|
-
polygon.push([vX, vY, vZ]);
|
|
132
|
-
});
|
|
133
|
-
polygons.push(polygon);
|
|
134
|
-
});
|
|
135
|
-
return polygons;
|
|
136
|
-
}
|
|
137
|
-
// default case is ISO_LINES
|
|
138
|
-
const lines = [];
|
|
139
|
-
offsets.forEach(xyOffsets => {
|
|
140
|
-
xyOffsets.forEach(offset => {
|
|
141
|
-
const vX = refVertexX + offset[0] * cellSize[0];
|
|
142
|
-
const vY = refVertexY + offset[1] * cellSize[1];
|
|
143
|
-
lines.push([vX, vY, vZ]);
|
|
144
|
-
});
|
|
145
|
-
});
|
|
146
|
-
return lines;
|
|
147
|
-
}
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
// Copyright (c) 2015 - 2017 Uber Technologies, Inc.
|
|
2
|
-
//
|
|
3
|
-
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
-
// of this software and associated documentation files (the "Software"), to deal
|
|
5
|
-
// in the Software without restriction, including without limitation the rights
|
|
6
|
-
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
-
// copies of the Software, and to permit persons to whom the Software is
|
|
8
|
-
// furnished to do so, subject to the following conditions:
|
|
9
|
-
//
|
|
10
|
-
// The above copyright notice and this permission notice shall be included in
|
|
11
|
-
// all copies or substantial portions of the Software.
|
|
12
|
-
//
|
|
13
|
-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
-
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
-
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
-
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
-
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
-
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
-
// THE SOFTWARE.
|
|
20
|
-
import GL from '@luma.gl/constants';
|
|
21
|
-
import { GridCellLayer } from '@deck.gl/layers';
|
|
22
|
-
import { defaultColorRange } from '../utils/color-utils';
|
|
23
|
-
import { pointToDensityGridDataCPU } from './grid-aggregator';
|
|
24
|
-
import CPUAggregator from '../utils/cpu-aggregator';
|
|
25
|
-
import AggregationLayer from '../aggregation-layer';
|
|
26
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
27
|
-
function nop() { }
|
|
28
|
-
const defaultProps = {
|
|
29
|
-
// color
|
|
30
|
-
colorDomain: null,
|
|
31
|
-
colorRange: defaultColorRange,
|
|
32
|
-
getColorValue: { type: 'accessor', value: null },
|
|
33
|
-
getColorWeight: { type: 'accessor', value: 1 },
|
|
34
|
-
colorAggregation: 'SUM',
|
|
35
|
-
lowerPercentile: { type: 'number', min: 0, max: 100, value: 0 },
|
|
36
|
-
upperPercentile: { type: 'number', min: 0, max: 100, value: 100 },
|
|
37
|
-
colorScaleType: 'quantize',
|
|
38
|
-
onSetColorDomain: nop,
|
|
39
|
-
// elevation
|
|
40
|
-
elevationDomain: null,
|
|
41
|
-
elevationRange: [0, 1000],
|
|
42
|
-
getElevationValue: { type: 'accessor', value: null },
|
|
43
|
-
getElevationWeight: { type: 'accessor', value: 1 },
|
|
44
|
-
elevationAggregation: 'SUM',
|
|
45
|
-
elevationLowerPercentile: { type: 'number', min: 0, max: 100, value: 0 },
|
|
46
|
-
elevationUpperPercentile: { type: 'number', min: 0, max: 100, value: 100 },
|
|
47
|
-
elevationScale: { type: 'number', min: 0, value: 1 },
|
|
48
|
-
elevationScaleType: 'linear',
|
|
49
|
-
onSetElevationDomain: nop,
|
|
50
|
-
gridAggregator: pointToDensityGridDataCPU,
|
|
51
|
-
// grid
|
|
52
|
-
cellSize: { type: 'number', min: 0, max: 1000, value: 1000 },
|
|
53
|
-
coverage: { type: 'number', min: 0, max: 1, value: 1 },
|
|
54
|
-
getPosition: { type: 'accessor', value: x => x.position },
|
|
55
|
-
extruded: false,
|
|
56
|
-
// Optional material for 'lighting' shader module
|
|
57
|
-
material: true,
|
|
58
|
-
// data filter
|
|
59
|
-
_filterData: { type: 'function', value: null, optional: true }
|
|
60
|
-
};
|
|
61
|
-
export default class CPUGridLayer extends AggregationLayer {
|
|
62
|
-
initializeState() {
|
|
63
|
-
const cpuAggregator = new CPUAggregator({
|
|
64
|
-
getAggregator: props => props.gridAggregator,
|
|
65
|
-
getCellSize: props => props.cellSize
|
|
66
|
-
});
|
|
67
|
-
this.state = {
|
|
68
|
-
cpuAggregator,
|
|
69
|
-
aggregatorState: cpuAggregator.state
|
|
70
|
-
};
|
|
71
|
-
const attributeManager = this.getAttributeManager();
|
|
72
|
-
attributeManager.add({
|
|
73
|
-
positions: { size: 3, type: GL.DOUBLE, accessor: 'getPosition' }
|
|
74
|
-
});
|
|
75
|
-
// color and elevation attributes can't be added as attributes
|
|
76
|
-
// they are calcualted using 'getValue' accessor that takes an array of pints.
|
|
77
|
-
}
|
|
78
|
-
updateState(opts) {
|
|
79
|
-
super.updateState(opts);
|
|
80
|
-
this.setState({
|
|
81
|
-
// make a copy of the internal state of cpuAggregator for testing
|
|
82
|
-
aggregatorState: this.state.cpuAggregator.updateState(opts, {
|
|
83
|
-
viewport: this.context.viewport,
|
|
84
|
-
attributes: this.getAttributes(),
|
|
85
|
-
numInstances: this.getNumInstances()
|
|
86
|
-
})
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
getPickingInfo({ info }) {
|
|
90
|
-
return this.state.cpuAggregator.getPickingInfo({ info });
|
|
91
|
-
}
|
|
92
|
-
// create a method for testing
|
|
93
|
-
_onGetSublayerColor(cell) {
|
|
94
|
-
return this.state.cpuAggregator.getAccessor('fillColor')(cell);
|
|
95
|
-
}
|
|
96
|
-
// create a method for testing
|
|
97
|
-
_onGetSublayerElevation(cell) {
|
|
98
|
-
return this.state.cpuAggregator.getAccessor('elevation')(cell);
|
|
99
|
-
}
|
|
100
|
-
_getSublayerUpdateTriggers() {
|
|
101
|
-
return this.state.cpuAggregator.getUpdateTriggers(this.props);
|
|
102
|
-
}
|
|
103
|
-
renderLayers() {
|
|
104
|
-
const { elevationScale, extruded, cellSize, coverage, material, transitions } = this.props;
|
|
105
|
-
const { cpuAggregator } = this.state;
|
|
106
|
-
const SubLayerClass = this.getSubLayerClass('grid-cell', GridCellLayer);
|
|
107
|
-
const updateTriggers = this._getSublayerUpdateTriggers();
|
|
108
|
-
return new SubLayerClass({
|
|
109
|
-
cellSize,
|
|
110
|
-
coverage,
|
|
111
|
-
material,
|
|
112
|
-
elevationScale,
|
|
113
|
-
extruded,
|
|
114
|
-
getFillColor: this._onGetSublayerColor.bind(this),
|
|
115
|
-
getElevation: this._onGetSublayerElevation.bind(this),
|
|
116
|
-
transitions: transitions && {
|
|
117
|
-
getFillColor: transitions.getColorValue || transitions.getColorWeight,
|
|
118
|
-
getElevation: transitions.getElevationValue || transitions.getElevationWeight
|
|
119
|
-
}
|
|
120
|
-
}, this.getSubLayerProps({
|
|
121
|
-
id: 'grid-cell',
|
|
122
|
-
updateTriggers
|
|
123
|
-
}), {
|
|
124
|
-
data: cpuAggregator.state.layerData.data
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
CPUGridLayer.layerName = 'CPUGridLayer';
|
|
129
|
-
CPUGridLayer.defaultProps = defaultProps;
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
// Copyright (c) 2015 - 2017 Uber Technologies, Inc.
|
|
2
|
-
//
|
|
3
|
-
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
-
// of this software and associated documentation files (the "Software"), to deal
|
|
5
|
-
// in the Software without restriction, including without limitation the rights
|
|
6
|
-
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
-
// copies of the Software, and to permit persons to whom the Software is
|
|
8
|
-
// furnished to do so, subject to the following conditions:
|
|
9
|
-
//
|
|
10
|
-
// The above copyright notice and this permission notice shall be included in
|
|
11
|
-
// all copies or substantial portions of the Software.
|
|
12
|
-
//
|
|
13
|
-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
-
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
-
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
-
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
-
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
-
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
-
// THE SOFTWARE.
|
|
20
|
-
import { createIterable } from '@deck.gl/core';
|
|
21
|
-
import { getGridOffset } from '../utils/grid-aggregation-utils';
|
|
22
|
-
/**
|
|
23
|
-
* Calculate density grid from an array of points
|
|
24
|
-
* @param {Object} props - object containing :
|
|
25
|
-
* @param {Iterable} [props.data] - data objects to be aggregated
|
|
26
|
-
* @param {Integer} [props.cellSize] - size of the grid cell
|
|
27
|
-
*
|
|
28
|
-
* @param {Object} aggregationParams - object containing :
|
|
29
|
-
* @param {Object} gridOffset - {xOffset, yOffset} cell size in meters
|
|
30
|
-
* @param {Integer} width - width of the grid
|
|
31
|
-
* @param {Integer} height - height of the grid
|
|
32
|
-
* @param {Boolean} projectPoints - `true` if doing screen space projection, `false` otherwise
|
|
33
|
-
* @param {Array} attributes - attributes array containing position values
|
|
34
|
-
* @param {Viewport} viewport - viewport to be used for projection
|
|
35
|
-
* @param {Array} posOffset - [xOffset, yOffset] offset to be applied to positions to get cell index
|
|
36
|
-
* @param {Object} boundingBox - {xMin, yMin, xMax, yMax} bounding box of input data
|
|
37
|
-
*
|
|
38
|
-
* @returns {object} - grid data, cell dimension
|
|
39
|
-
*/
|
|
40
|
-
export function pointToDensityGridDataCPU(props, aggregationParams) {
|
|
41
|
-
const hashInfo = pointsToGridHashing(props, aggregationParams);
|
|
42
|
-
const result = getGridLayerDataFromGridHash(hashInfo);
|
|
43
|
-
return {
|
|
44
|
-
gridHash: hashInfo.gridHash,
|
|
45
|
-
gridOffset: hashInfo.gridOffset,
|
|
46
|
-
data: result
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Project points into each cell, return a hash table of cells
|
|
51
|
-
* @param {Iterable} points
|
|
52
|
-
* @param {number} cellSize - unit size in meters
|
|
53
|
-
* @param {function} getPosition - position accessor
|
|
54
|
-
* @returns {object} - grid hash and cell dimension
|
|
55
|
-
*/
|
|
56
|
-
/* eslint-disable max-statements, complexity */
|
|
57
|
-
function pointsToGridHashing(props, aggregationParams) {
|
|
58
|
-
const { data = [], cellSize } = props;
|
|
59
|
-
const { attributes, viewport, projectPoints, numInstances } = aggregationParams;
|
|
60
|
-
const positions = attributes.positions.value;
|
|
61
|
-
const { size } = attributes.positions.getAccessor();
|
|
62
|
-
const boundingBox = aggregationParams.boundingBox || getPositionBoundingBox(attributes.positions, numInstances);
|
|
63
|
-
const offsets = aggregationParams.posOffset || [180, 90];
|
|
64
|
-
const gridOffset = aggregationParams.gridOffset || getGridOffset(boundingBox, cellSize);
|
|
65
|
-
if (gridOffset.xOffset <= 0 || gridOffset.yOffset <= 0) {
|
|
66
|
-
return { gridHash: {}, gridOffset };
|
|
67
|
-
}
|
|
68
|
-
const { width, height } = viewport;
|
|
69
|
-
const numCol = Math.ceil(width / gridOffset.xOffset);
|
|
70
|
-
const numRow = Math.ceil(height / gridOffset.yOffset);
|
|
71
|
-
// calculate count per cell
|
|
72
|
-
const gridHash = {};
|
|
73
|
-
const { iterable, objectInfo } = createIterable(data);
|
|
74
|
-
const position = new Array(3);
|
|
75
|
-
for (const pt of iterable) {
|
|
76
|
-
objectInfo.index++;
|
|
77
|
-
position[0] = positions[objectInfo.index * size];
|
|
78
|
-
position[1] = positions[objectInfo.index * size + 1];
|
|
79
|
-
position[2] = size >= 3 ? positions[objectInfo.index * size + 2] : 0;
|
|
80
|
-
const [x, y] = projectPoints ? viewport.project(position) : position;
|
|
81
|
-
if (Number.isFinite(x) && Number.isFinite(y)) {
|
|
82
|
-
const yIndex = Math.floor((y + offsets[1]) / gridOffset.yOffset);
|
|
83
|
-
const xIndex = Math.floor((x + offsets[0]) / gridOffset.xOffset);
|
|
84
|
-
if (!projectPoints ||
|
|
85
|
-
// when doing screen space agggregation (projectPoints = true), filter points outside of the viewport range.
|
|
86
|
-
(xIndex >= 0 && xIndex < numCol && yIndex >= 0 && yIndex < numRow)) {
|
|
87
|
-
const key = `${yIndex}-${xIndex}`;
|
|
88
|
-
gridHash[key] = gridHash[key] || { count: 0, points: [], lonIdx: xIndex, latIdx: yIndex };
|
|
89
|
-
gridHash[key].count += 1;
|
|
90
|
-
gridHash[key].points.push({
|
|
91
|
-
source: pt,
|
|
92
|
-
index: objectInfo.index
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
return { gridHash, gridOffset, offsets: [offsets[0] * -1, offsets[1] * -1] };
|
|
98
|
-
}
|
|
99
|
-
/* eslint-enable max-statements, complexity */
|
|
100
|
-
function getGridLayerDataFromGridHash({ gridHash, gridOffset, offsets }) {
|
|
101
|
-
const data = new Array(Object.keys(gridHash).length);
|
|
102
|
-
let i = 0;
|
|
103
|
-
for (const key in gridHash) {
|
|
104
|
-
const idxs = key.split('-');
|
|
105
|
-
const latIdx = parseInt(idxs[0], 10);
|
|
106
|
-
const lonIdx = parseInt(idxs[1], 10);
|
|
107
|
-
const index = i++;
|
|
108
|
-
data[index] = {
|
|
109
|
-
index,
|
|
110
|
-
position: [
|
|
111
|
-
offsets[0] + gridOffset.xOffset * lonIdx,
|
|
112
|
-
offsets[1] + gridOffset.yOffset * latIdx
|
|
113
|
-
],
|
|
114
|
-
...gridHash[key]
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
return data;
|
|
118
|
-
}
|
|
119
|
-
// Calculate bounding box of position attribute
|
|
120
|
-
function getPositionBoundingBox(positionAttribute, numInstance) {
|
|
121
|
-
// TODO - value might not exist (e.g. attribute transition)
|
|
122
|
-
const positions = positionAttribute.value;
|
|
123
|
-
const { size } = positionAttribute.getAccessor();
|
|
124
|
-
let yMin = Infinity;
|
|
125
|
-
let yMax = -Infinity;
|
|
126
|
-
let xMin = Infinity;
|
|
127
|
-
let xMax = -Infinity;
|
|
128
|
-
let y;
|
|
129
|
-
let x;
|
|
130
|
-
for (let i = 0; i < numInstance; i++) {
|
|
131
|
-
x = positions[i * size];
|
|
132
|
-
y = positions[i * size + 1];
|
|
133
|
-
if (Number.isFinite(x) && Number.isFinite(y)) {
|
|
134
|
-
yMin = y < yMin ? y : yMin;
|
|
135
|
-
yMax = y > yMax ? y : yMax;
|
|
136
|
-
xMin = x < xMin ? x : xMin;
|
|
137
|
-
xMax = x > xMax ? x : xMax;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
return { xMin, xMax, yMin, yMax };
|
|
141
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
// Copyright (c) 2015 - 2017 Uber Technologies, Inc.
|
|
2
|
-
//
|
|
3
|
-
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
-
// of this software and associated documentation files (the "Software"), to deal
|
|
5
|
-
// in the Software without restriction, including without limitation the rights
|
|
6
|
-
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
-
// copies of the Software, and to permit persons to whom the Software is
|
|
8
|
-
// furnished to do so, subject to the following conditions:
|
|
9
|
-
//
|
|
10
|
-
// The above copyright notice and this permission notice shall be included in
|
|
11
|
-
// all copies or substantial portions of the Software.
|
|
12
|
-
//
|
|
13
|
-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
-
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
-
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
-
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
-
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
-
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
-
// THE SOFTWARE.
|
|
20
|
-
export default `\
|
|
21
|
-
#version 300 es
|
|
22
|
-
#define SHADER_NAME gpu-grid-cell-layer-fragment-shader
|
|
23
|
-
|
|
24
|
-
precision highp float;
|
|
25
|
-
|
|
26
|
-
in vec4 vColor;
|
|
27
|
-
|
|
28
|
-
out vec4 fragColor;
|
|
29
|
-
|
|
30
|
-
void main(void) {
|
|
31
|
-
fragColor = vColor;
|
|
32
|
-
fragColor = picking_filterColor(fragColor);
|
|
33
|
-
}
|
|
34
|
-
`;
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
// Copyright (c) 2015 - 2017 Uber Technologies, Inc.
|
|
2
|
-
//
|
|
3
|
-
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
-
// of this software and associated documentation files (the "Software"), to deal
|
|
5
|
-
// in the Software without restriction, including without limitation the rights
|
|
6
|
-
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
-
// copies of the Software, and to permit persons to whom the Software is
|
|
8
|
-
// furnished to do so, subject to the following conditions:
|
|
9
|
-
//
|
|
10
|
-
// The above copyright notice and this permission notice shall be included in
|
|
11
|
-
// all copies or substantial portions of the Software.
|
|
12
|
-
//
|
|
13
|
-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
-
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
-
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
-
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
-
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
-
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
-
// THE SOFTWARE.
|
|
20
|
-
// Inspired by screen-grid-layer vertex shader in deck.gl
|
|
21
|
-
export default `\
|
|
22
|
-
#version 300 es
|
|
23
|
-
#define SHADER_NAME gpu-grid-cell-layer-vertex-shader
|
|
24
|
-
#define RANGE_COUNT 6
|
|
25
|
-
|
|
26
|
-
in vec3 positions;
|
|
27
|
-
in vec3 normals;
|
|
28
|
-
|
|
29
|
-
in vec4 colors;
|
|
30
|
-
in vec4 elevations;
|
|
31
|
-
in vec3 instancePickingColors;
|
|
32
|
-
|
|
33
|
-
// Custom uniforms
|
|
34
|
-
uniform vec2 offset;
|
|
35
|
-
uniform bool extruded;
|
|
36
|
-
uniform float cellSize;
|
|
37
|
-
uniform float coverage;
|
|
38
|
-
uniform float opacity;
|
|
39
|
-
uniform float elevationScale;
|
|
40
|
-
|
|
41
|
-
uniform ivec2 gridSize;
|
|
42
|
-
uniform vec2 gridOrigin;
|
|
43
|
-
uniform vec2 gridOriginLow;
|
|
44
|
-
uniform vec2 gridOffset;
|
|
45
|
-
uniform vec2 gridOffsetLow;
|
|
46
|
-
uniform vec4 colorRange[RANGE_COUNT];
|
|
47
|
-
uniform vec2 elevationRange;
|
|
48
|
-
|
|
49
|
-
// Domain uniforms
|
|
50
|
-
uniform vec2 colorDomain;
|
|
51
|
-
uniform bool colorDomainValid;
|
|
52
|
-
uniform vec2 elevationDomain;
|
|
53
|
-
uniform bool elevationDomainValid;
|
|
54
|
-
|
|
55
|
-
layout(std140) uniform;
|
|
56
|
-
uniform ColorData
|
|
57
|
-
{
|
|
58
|
-
vec4 maxMinCount;
|
|
59
|
-
} colorData;
|
|
60
|
-
uniform ElevationData
|
|
61
|
-
{
|
|
62
|
-
vec4 maxMinCount;
|
|
63
|
-
} elevationData;
|
|
64
|
-
|
|
65
|
-
#define EPSILON 0.00001
|
|
66
|
-
|
|
67
|
-
// Result
|
|
68
|
-
out vec4 vColor;
|
|
69
|
-
|
|
70
|
-
vec4 quantizeScale(vec2 domain, vec4 range[RANGE_COUNT], float value) {
|
|
71
|
-
vec4 outColor = vec4(0., 0., 0., 0.);
|
|
72
|
-
if (value >= (domain.x - EPSILON) && value <= (domain.y + EPSILON)) {
|
|
73
|
-
float domainRange = domain.y - domain.x;
|
|
74
|
-
if (domainRange <= 0.) {
|
|
75
|
-
outColor = colorRange[0];
|
|
76
|
-
} else {
|
|
77
|
-
float rangeCount = float(RANGE_COUNT);
|
|
78
|
-
float rangeStep = domainRange / rangeCount;
|
|
79
|
-
float idx = floor((value - domain.x) / rangeStep);
|
|
80
|
-
idx = clamp(idx, 0., rangeCount - 1.);
|
|
81
|
-
int intIdx = int(idx);
|
|
82
|
-
outColor = colorRange[intIdx];
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
return outColor;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
float linearScale(vec2 domain, vec2 range, float value) {
|
|
89
|
-
if (value >= (domain.x - EPSILON) && value <= (domain.y + EPSILON)) {
|
|
90
|
-
return ((value - domain.x) / (domain.y - domain.x)) * (range.y - range.x) + range.x;
|
|
91
|
-
}
|
|
92
|
-
return -1.;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
void main(void) {
|
|
96
|
-
vec2 clrDomain = colorDomainValid ? colorDomain : vec2(colorData.maxMinCount.a, colorData.maxMinCount.r);
|
|
97
|
-
vec4 color = quantizeScale(clrDomain, colorRange, colors.r);
|
|
98
|
-
|
|
99
|
-
float elevation = 0.0;
|
|
100
|
-
|
|
101
|
-
if (extruded) {
|
|
102
|
-
vec2 elvDomain = elevationDomainValid ? elevationDomain : vec2(elevationData.maxMinCount.a, elevationData.maxMinCount.r);
|
|
103
|
-
elevation = linearScale(elvDomain, elevationRange, elevations.r);
|
|
104
|
-
elevation = elevation * (positions.z + 1.0) / 2.0 * elevationScale;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
// if aggregated color or elevation is 0 do not render
|
|
108
|
-
float shouldRender = float(color.r > 0.0 && elevations.r >= 0.0);
|
|
109
|
-
float dotRadius = cellSize / 2. * coverage * shouldRender;
|
|
110
|
-
|
|
111
|
-
int yIndex = (gl_InstanceID / gridSize[0]);
|
|
112
|
-
int xIndex = gl_InstanceID - (yIndex * gridSize[0]);
|
|
113
|
-
|
|
114
|
-
vec2 instancePositionXFP64 = mul_fp64(vec2(gridOffset[0], gridOffsetLow[0]), vec2(float(xIndex), 0.));
|
|
115
|
-
instancePositionXFP64 = sum_fp64(instancePositionXFP64, vec2(gridOrigin[0], gridOriginLow[0]));
|
|
116
|
-
vec2 instancePositionYFP64 = mul_fp64(vec2(gridOffset[1], gridOffsetLow[1]), vec2(float(yIndex), 0.));
|
|
117
|
-
instancePositionYFP64 = sum_fp64(instancePositionYFP64, vec2(gridOrigin[1], gridOriginLow[1]));
|
|
118
|
-
|
|
119
|
-
vec3 centroidPosition = vec3(instancePositionXFP64[0], instancePositionYFP64[0], elevation);
|
|
120
|
-
vec3 centroidPosition64Low = vec3(instancePositionXFP64[1], instancePositionYFP64[1], 0.0);
|
|
121
|
-
geometry.worldPosition = centroidPosition;
|
|
122
|
-
vec3 pos = vec3(project_size(positions.xy + offset) * dotRadius, 0.);
|
|
123
|
-
|
|
124
|
-
// Set color to be rendered to picking fbo (also used to check for selection highlight).
|
|
125
|
-
picking_setPickingColor(instancePickingColors);
|
|
126
|
-
|
|
127
|
-
gl_Position = project_position_to_clipspace(centroidPosition, centroidPosition64Low, pos, geometry.position);
|
|
128
|
-
|
|
129
|
-
// Light calculations
|
|
130
|
-
// Worldspace is the linear space after Mercator projection
|
|
131
|
-
|
|
132
|
-
vec3 normals_commonspace = project_normal(normals);
|
|
133
|
-
|
|
134
|
-
if (extruded) {
|
|
135
|
-
vec3 lightColor = lighting_getLightColor(color.rgb, project_uCameraPosition, geometry.position.xyz, normals_commonspace);
|
|
136
|
-
vColor = vec4(lightColor, color.a * opacity) / 255.;
|
|
137
|
-
} else {
|
|
138
|
-
vColor = vec4(color.rgb, color.a * opacity) / 255.;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
`;
|