autumnplot-gl 4.0.0 → 4.1.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/README.md +2 -0
- package/dist/812.autumnplot-gl.js +2 -0
- package/dist/812.autumnplot-gl.js.map +1 -0
- package/dist/983.autumnplot-gl.js +1 -1
- package/dist/983.autumnplot-gl.js.map +1 -1
- package/dist/autumnplot-gl.js +1 -1
- package/dist/autumnplot-gl.js.map +1 -1
- package/dist/marchingsquares.wasm +0 -0
- package/lib/AutumnTypes.d.ts +6 -4
- package/lib/AutumnTypes.js +4 -1
- package/lib/Barbs.d.ts +11 -2
- package/lib/Barbs.js +9 -0
- package/lib/BillboardCollection.d.ts +2 -2
- package/lib/BillboardCollection.js +14 -14
- package/lib/ColorBar.d.ts +6 -1
- package/lib/ColorBar.js +10 -4
- package/lib/Colormap.d.ts +8 -1
- package/lib/Colormap.js +24 -1
- package/lib/Contour.d.ts +16 -1
- package/lib/Contour.js +14 -2
- package/lib/{ContourCreator.d.ts → ContourCreator.worker.d.ts} +10 -11
- package/lib/{ContourCreator.js → ContourCreator.worker.js} +15 -14
- package/lib/Fill.d.ts +29 -11
- package/lib/Fill.js +38 -18
- package/lib/Hodographs.d.ts +13 -3
- package/lib/Hodographs.js +11 -1
- package/lib/Map.d.ts +3 -4
- package/lib/Map.js +49 -51
- package/lib/Paintball.d.ts +13 -5
- package/lib/Paintball.js +96 -46
- package/lib/PlotComponent.d.ts +8 -3
- package/lib/PlotComponent.js +35 -1
- package/lib/PlotLayer.worker.js +1 -1
- package/lib/RawField.d.ts +221 -27
- package/lib/RawField.js +405 -58
- package/lib/StationPlot.d.ts +22 -6
- package/lib/StationPlot.js +88 -22
- package/lib/TextCollection.d.ts +5 -0
- package/lib/TextCollection.js +79 -9
- package/lib/WasmInterface.d.ts +7 -0
- package/lib/WasmInterface.js +11 -0
- package/lib/WorkerPool.d.ts +8 -0
- package/lib/WorkerPool.js +77 -0
- package/lib/cpp/marchingsquares.js +127 -13
- package/lib/cpp/marchingsquares.wasm +0 -0
- package/lib/cpp/marchingsquares_embind.d.ts +16 -3
- package/lib/grids/AutoZoom.d.ts +21 -0
- package/lib/grids/AutoZoom.js +63 -0
- package/lib/grids/DomainBuffer.d.ts +14 -0
- package/lib/grids/DomainBuffer.js +16 -0
- package/lib/grids/Geostationary.d.ts +35 -0
- package/lib/grids/Geostationary.js +47 -0
- package/lib/grids/Grid.d.ts +36 -0
- package/lib/grids/Grid.js +12 -0
- package/lib/grids/GridCoordinates.d.ts +10 -0
- package/lib/grids/GridCoordinates.js +64 -0
- package/lib/grids/LambertGrid.d.ts +73 -0
- package/lib/grids/LambertGrid.js +92 -0
- package/lib/grids/PlateCarreeGrid.d.ts +46 -0
- package/lib/grids/PlateCarreeGrid.js +55 -0
- package/lib/grids/PlateCarreeRotatedGrid.d.ts +53 -0
- package/lib/grids/PlateCarreeRotatedGrid.js +65 -0
- package/lib/grids/RadarSweepGrid.d.ts +46 -0
- package/lib/grids/RadarSweepGrid.js +74 -0
- package/lib/grids/StructuredGrid.d.ts +49 -0
- package/lib/grids/StructuredGrid.js +103 -0
- package/lib/grids/UnstructuredGrid.d.ts +56 -0
- package/lib/grids/UnstructuredGrid.js +102 -0
- package/lib/index.d.ts +15 -4
- package/lib/index.js +15 -7
- package/lib/utils.d.ts +11 -2
- package/lib/utils.js +63 -1
- package/package.json +3 -2
- package/lib/Grid.d.ts +0 -270
- package/lib/Grid.js +0 -600
- package/lib/ParticleTracer.d.ts +0 -19
- package/lib/ParticleTracer.js +0 -37
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { kdTree } from "kd-tree-javascript";
|
|
2
|
+
import { Cache, argMin, getArrayConstructor } from "../utils";
|
|
3
|
+
import { autoZoomGridMixin } from "./AutoZoom";
|
|
4
|
+
import { Grid } from "./Grid";
|
|
5
|
+
import { LngLat } from "../Map";
|
|
6
|
+
/**
|
|
7
|
+
* An unstructured grid defined by a list of latitudes and longitudes
|
|
8
|
+
*
|
|
9
|
+
* ## Plot Component Compatibility
|
|
10
|
+
* - :x: `Fill`
|
|
11
|
+
* - :x: `Raster`
|
|
12
|
+
* - :x: `Contour`
|
|
13
|
+
* - :x: `Paintball`
|
|
14
|
+
* - :white_check_mark: `Barbs`
|
|
15
|
+
* - :white_check_mark: `Hodographs`
|
|
16
|
+
* - :white_check_mark: `StationPlot`
|
|
17
|
+
*/
|
|
18
|
+
class UnstructuredGrid extends autoZoomGridMixin(Grid) {
|
|
19
|
+
/**
|
|
20
|
+
* Create an unstructured grid
|
|
21
|
+
* @param coords - The lat/lon coordinates of the grid points
|
|
22
|
+
*/
|
|
23
|
+
constructor(coords, zoom) {
|
|
24
|
+
const MAX_DIM = 4096;
|
|
25
|
+
super('unstructured', true, Math.min(coords.length, MAX_DIM), Math.floor(coords.length / MAX_DIM) + 1);
|
|
26
|
+
this.coords = coords;
|
|
27
|
+
this.zoom_arg = zoom === undefined ? null : zoom;
|
|
28
|
+
this.zoom_cache = new Cache((thin_fac) => {
|
|
29
|
+
const MAP_MAX_ZOOM = 24;
|
|
30
|
+
const offset = Math.log2(thin_fac);
|
|
31
|
+
const kd_nodes = this.coords.map(c => ({ ...new LngLat(c.lon, c.lat).toMercatorCoord(), min_zoom: MAP_MAX_ZOOM }));
|
|
32
|
+
const tree = new kdTree([...kd_nodes], (a, b) => Math.max(Math.abs(a.x - b.x), Math.abs(a.y - b.y)), ['x', 'y']);
|
|
33
|
+
const recursiveThin = (x, y, depth) => {
|
|
34
|
+
const size = Math.pow(0.5, depth + 1);
|
|
35
|
+
const nodes = tree.nearest({ x: x, y: y, min_zoom: 0 }, 2, size);
|
|
36
|
+
if (nodes.length > 0) {
|
|
37
|
+
const [node, dist] = nodes.sort((a, b) => a[1] - b[1])[0];
|
|
38
|
+
if (node.min_zoom == MAP_MAX_ZOOM) {
|
|
39
|
+
node.min_zoom = Math.max(depth - offset, 0);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (nodes.length > 1 && depth < MAP_MAX_ZOOM + offset) {
|
|
43
|
+
recursiveThin(x - size / 2, y - size / 2, depth + 1);
|
|
44
|
+
recursiveThin(x + size / 2, y - size / 2, depth + 1);
|
|
45
|
+
recursiveThin(x - size / 2, y + size / 2, depth + 1);
|
|
46
|
+
recursiveThin(x + size / 2, y + size / 2, depth + 1);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
// Start at -1 zoom depth, which should handle longitudes > 180 degrees.
|
|
50
|
+
recursiveThin(0.5, 0.5, -1);
|
|
51
|
+
return new Uint8Array(kd_nodes.map(n => n.min_zoom));
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
/** @internal */
|
|
55
|
+
copy() {
|
|
56
|
+
return new UnstructuredGrid(this.coords);
|
|
57
|
+
}
|
|
58
|
+
/** @internal */
|
|
59
|
+
getEarthCoords() {
|
|
60
|
+
return { lons: new Float32Array(this.coords.map(c => c.lon)), lats: new Float32Array(this.coords.map(c => c.lat)) };
|
|
61
|
+
}
|
|
62
|
+
/** @internal */
|
|
63
|
+
getGridCoords() {
|
|
64
|
+
const { lons, lats } = this.getEarthCoords();
|
|
65
|
+
return { x: lons, y: lats };
|
|
66
|
+
}
|
|
67
|
+
/** @internal */
|
|
68
|
+
transform(x, y, opts) {
|
|
69
|
+
return [x, y];
|
|
70
|
+
}
|
|
71
|
+
/** @internal */
|
|
72
|
+
getMinVisibleZoom(thin_fac) {
|
|
73
|
+
if (this.zoom_arg !== null)
|
|
74
|
+
return this.zoom_arg;
|
|
75
|
+
return this.zoom_cache.getValue(thin_fac);
|
|
76
|
+
}
|
|
77
|
+
/** @internal */
|
|
78
|
+
getThinnedGrid(thin_fac, map_max_zoom) {
|
|
79
|
+
const min_zoom = this.getMinVisibleZoom(thin_fac);
|
|
80
|
+
return new UnstructuredGrid(this.coords.filter((ll, ill) => min_zoom[ill] <= map_max_zoom), min_zoom.filter(ll => ll <= map_max_zoom));
|
|
81
|
+
}
|
|
82
|
+
/** @internal */
|
|
83
|
+
thinDataArray(original_grid, ary) {
|
|
84
|
+
let i_new = 0;
|
|
85
|
+
const arrayType = getArrayConstructor(ary);
|
|
86
|
+
const new_data = new arrayType(this.ni * this.nj);
|
|
87
|
+
for (let i = 0; i < original_grid.coords.length; i++) {
|
|
88
|
+
if (this.coords[i_new].lat == original_grid.coords[i].lat && this.coords[i_new].lon == original_grid.coords[i].lon) {
|
|
89
|
+
new_data[i_new++] = ary[i];
|
|
90
|
+
if (i_new >= this.coords.length)
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return new_data;
|
|
95
|
+
}
|
|
96
|
+
sampleNearestGridPoint(lon, lat, ary) {
|
|
97
|
+
// TAS: This is gonna be slow. Need to think about using the kdTree here.
|
|
98
|
+
const idx = argMin(this.coords.map(c => (c.lon - lon) * (c.lon - lon) + (c.lat - lat) * (c.lat - lat)));
|
|
99
|
+
return { sample: ary[idx], sample_lon: this.coords[idx].lon, sample_lat: this.coords[idx].lat };
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
export { UnstructuredGrid };
|
package/lib/index.d.ts
CHANGED
|
@@ -12,9 +12,17 @@ import { ColorMap, ColorMapOptions } from './Colormap';
|
|
|
12
12
|
import { Color } from "./Color";
|
|
13
13
|
import { makeColorBar, makePaintballKey, ColorbarOrientation, ColorbarTickDirection, ColorBarOptions, PaintballKeyOptions } from "./ColorBar";
|
|
14
14
|
import { LineStyle } from "./PolylineCollection";
|
|
15
|
-
import { RawScalarField, RawVectorField, RawProfileField, VectorRelativeTo, RawVectorFieldOptions, RawObsField, ObsRawData } from "./RawField";
|
|
16
|
-
import { Grid, GridType
|
|
17
|
-
import {
|
|
15
|
+
import { RawScalarField, ComputedScalarField, ExpressionScalarField, RawVectorField, ComputedVectorField, ExpressionVectorField, RawProfileField, VectorRelativeTo, RawVectorFieldOptions, RawObsField, ObsRawData } from "./RawField";
|
|
16
|
+
import { Grid, GridType } from "./grids/Grid";
|
|
17
|
+
import { StructuredGrid } from "./grids/StructuredGrid";
|
|
18
|
+
import { PlateCarreeGrid } from "./grids/PlateCarreeGrid";
|
|
19
|
+
import { PlateCarreeRotatedGrid } from "./grids/PlateCarreeRotatedGrid";
|
|
20
|
+
import { LambertGrid } from "./grids/LambertGrid";
|
|
21
|
+
import { RadarSweepGrid } from "./grids/RadarSweepGrid";
|
|
22
|
+
import { GeostationaryImage } from "./grids/Geostationary";
|
|
23
|
+
import { UnstructuredGrid } from "./grids/UnstructuredGrid";
|
|
24
|
+
import { AutoZoomGrid } from "./grids/AutoZoom";
|
|
25
|
+
import { FieldContourOpts } from './ContourCreator.worker';
|
|
18
26
|
/** All built-in colormaps */
|
|
19
27
|
declare const colormaps: {
|
|
20
28
|
bluered: (level_min: number, level_max: number, n_colors: number) => ColorMap;
|
|
@@ -25,15 +33,18 @@ declare const colormaps: {
|
|
|
25
33
|
pw_t2m: ColorMap;
|
|
26
34
|
pw_td2m: ColorMap;
|
|
27
35
|
nws_storm_clear_refl: ColorMap;
|
|
36
|
+
wv_cimss: ColorMap;
|
|
28
37
|
};
|
|
29
38
|
/** Options for initializing the autumnplot-gl library */
|
|
30
39
|
interface InitAutumnPlotOpts {
|
|
31
40
|
/** Base URL at which to find the WASM module (change with caution!) */
|
|
32
41
|
wasm_base_url?: string;
|
|
42
|
+
/** Number of worker threads to use for contouring */
|
|
43
|
+
contour_workers?: number;
|
|
33
44
|
}
|
|
34
45
|
/**
|
|
35
46
|
* Initialize the WebAssembly module in autumnplot-gl. It's not strictly necessary to call it first, but if you call it
|
|
36
47
|
* first, you can prevent races when you contour a bunch of fields at once.
|
|
37
48
|
*/
|
|
38
49
|
declare function initAutumnPlot(opts?: InitAutumnPlotOpts): void;
|
|
39
|
-
export { PlotComponent, Barbs, BarbsOptions, Contour, ContourOptions, ContourLabels, ContourLabelOptions, ContourFill, Raster, ContourFillOptions, RasterOptions, Paintball, PaintballOptions, Hodographs, HodographOptions, WindProfile, StormRelativeWindProfile, GroundRelativeWindProfile, StationPlot, StationPlotOptions, SPPosition, SPNumberConfig, SPStringConfig, SPBarbConfig, SPSymbolConfig, SPConfig, SPDataConfig, SPSymbol, PlotLayer, MultiPlotLayer, MapLikeType, LineStyle, ColorMap, ColorMapOptions, colormaps, makeColorBar, makePaintballKey, Color, ColorbarOrientation, ColorbarTickDirection, ColorBarOptions, PaintballKeyOptions, RawScalarField, RawVectorField, RawProfileField, RawObsField, ObsRawData, Grid, GridType, StructuredGrid, VectorRelativeTo, RawVectorFieldOptions, PlateCarreeGrid, PlateCarreeRotatedGrid, LambertGrid, UnstructuredGrid, WebGLAnyRenderingContext, TypedArray, ContourData, initAutumnPlot, InitAutumnPlotOpts, FieldContourOpts };
|
|
50
|
+
export { PlotComponent, Barbs, BarbsOptions, Contour, ContourOptions, ContourLabels, ContourLabelOptions, ContourFill, Raster, ContourFillOptions, RasterOptions, Paintball, PaintballOptions, Hodographs, HodographOptions, WindProfile, StormRelativeWindProfile, GroundRelativeWindProfile, StationPlot, StationPlotOptions, SPPosition, SPNumberConfig, SPStringConfig, SPBarbConfig, SPSymbolConfig, SPConfig, SPDataConfig, SPSymbol, PlotLayer, MultiPlotLayer, MapLikeType, LineStyle, ColorMap, ColorMapOptions, colormaps, makeColorBar, makePaintballKey, Color, ColorbarOrientation, ColorbarTickDirection, ColorBarOptions, PaintballKeyOptions, RawScalarField, ComputedScalarField, ExpressionScalarField, RawVectorField, ComputedVectorField, ExpressionVectorField, RawProfileField, RawObsField, ObsRawData, Grid, GridType, StructuredGrid, VectorRelativeTo, RawVectorFieldOptions, PlateCarreeGrid, PlateCarreeRotatedGrid, LambertGrid, UnstructuredGrid, RadarSweepGrid, GeostationaryImage, AutoZoomGrid, WebGLAnyRenderingContext, TypedArray, ContourData, initAutumnPlot, InitAutumnPlotOpts, FieldContourOpts };
|
package/lib/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PlotComponent } from "./PlotComponent";
|
|
1
|
+
import { PlotComponent, getContourWorkerPool } from "./PlotComponent";
|
|
2
2
|
import Contour, { ContourLabels } from "./Contour";
|
|
3
3
|
import { ContourFill, Raster } from "./Fill";
|
|
4
4
|
import Barbs from "./Barbs";
|
|
@@ -6,12 +6,18 @@ import Paintball from "./Paintball";
|
|
|
6
6
|
import Hodographs from './Hodographs';
|
|
7
7
|
import StationPlot from "./StationPlot";
|
|
8
8
|
import { PlotLayer, MultiPlotLayer } from './PlotLayer';
|
|
9
|
-
import { ColorMap, bluered, redblue, pw_speed500mb, pw_speed850mb, pw_cape, pw_t2m, pw_td2m, nws_storm_clear_refl } from './Colormap';
|
|
9
|
+
import { ColorMap, bluered, redblue, pw_speed500mb, pw_speed850mb, pw_cape, pw_t2m, pw_td2m, nws_storm_clear_refl, wv_cimss } from './Colormap';
|
|
10
10
|
import { Color } from "./Color";
|
|
11
11
|
import { makeColorBar, makePaintballKey } from "./ColorBar";
|
|
12
|
-
import { RawScalarField, RawVectorField, RawProfileField, RawObsField } from "./RawField";
|
|
13
|
-
import { Grid
|
|
14
|
-
import {
|
|
12
|
+
import { RawScalarField, ComputedScalarField, RawVectorField, ComputedVectorField, RawProfileField, RawObsField } from "./RawField";
|
|
13
|
+
import { Grid } from "./grids/Grid";
|
|
14
|
+
import { StructuredGrid } from "./grids/StructuredGrid";
|
|
15
|
+
import { PlateCarreeGrid } from "./grids/PlateCarreeGrid";
|
|
16
|
+
import { PlateCarreeRotatedGrid } from "./grids/PlateCarreeRotatedGrid";
|
|
17
|
+
import { LambertGrid } from "./grids/LambertGrid";
|
|
18
|
+
import { RadarSweepGrid } from "./grids/RadarSweepGrid";
|
|
19
|
+
import { GeostationaryImage } from "./grids/Geostationary";
|
|
20
|
+
import { UnstructuredGrid } from "./grids/UnstructuredGrid";
|
|
15
21
|
/** All built-in colormaps */
|
|
16
22
|
const colormaps = {
|
|
17
23
|
bluered: bluered,
|
|
@@ -22,6 +28,7 @@ const colormaps = {
|
|
|
22
28
|
pw_t2m: pw_t2m,
|
|
23
29
|
pw_td2m: pw_td2m,
|
|
24
30
|
nws_storm_clear_refl: nws_storm_clear_refl,
|
|
31
|
+
wv_cimss: wv_cimss,
|
|
25
32
|
};
|
|
26
33
|
/**
|
|
27
34
|
* Initialize the WebAssembly module in autumnplot-gl. It's not strictly necessary to call it first, but if you call it
|
|
@@ -29,6 +36,7 @@ const colormaps = {
|
|
|
29
36
|
*/
|
|
30
37
|
function initAutumnPlot(opts) {
|
|
31
38
|
opts = opts === undefined ? {} : opts;
|
|
32
|
-
|
|
39
|
+
const contour_workers = opts.contour_workers === undefined ? 1 : opts.contour_workers;
|
|
40
|
+
getContourWorkerPool(opts.wasm_base_url, contour_workers);
|
|
33
41
|
}
|
|
34
|
-
export { PlotComponent, Barbs, Contour, ContourLabels, ContourFill, Raster, Paintball, Hodographs, StationPlot, PlotLayer, MultiPlotLayer, ColorMap, colormaps, makeColorBar, makePaintballKey, Color, RawScalarField, RawVectorField, RawProfileField, RawObsField, Grid, StructuredGrid, PlateCarreeGrid, PlateCarreeRotatedGrid, LambertGrid, UnstructuredGrid, initAutumnPlot };
|
|
42
|
+
export { PlotComponent, Barbs, Contour, ContourLabels, ContourFill, Raster, Paintball, Hodographs, StationPlot, PlotLayer, MultiPlotLayer, ColorMap, colormaps, makeColorBar, makePaintballKey, Color, RawScalarField, ComputedScalarField, RawVectorField, ComputedVectorField, RawProfileField, RawObsField, Grid, StructuredGrid, PlateCarreeGrid, PlateCarreeRotatedGrid, LambertGrid, UnstructuredGrid, RadarSweepGrid, GeostationaryImage, initAutumnPlot };
|
package/lib/utils.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TypedArray } from "./AutumnTypes";
|
|
1
|
+
import { TypedArray, TypedArrayStr } from "./AutumnTypes";
|
|
2
2
|
declare function getMinZoom(jlat: number, ilon: number, thin_fac_base: number): number;
|
|
3
3
|
declare function zip(...args: any[]): Generator<any[], void, unknown>;
|
|
4
4
|
declare function getOS(): string | null;
|
|
@@ -12,4 +12,13 @@ declare class Cache<A extends unknown[], R> {
|
|
|
12
12
|
declare function normalizeOptions<Type extends Record<string, any>>(opts: Type | undefined, defaults: Required<Type>): Required<Type>;
|
|
13
13
|
declare function getArrayConstructor<ArrayType extends TypedArray>(ary: ArrayType): new (...args: any[]) => ArrayType;
|
|
14
14
|
declare function mergeShaderCode(snippet: string, main: string): string;
|
|
15
|
-
|
|
15
|
+
declare function applySamplerCodeScalar(src: string, sampler_names: string[], sampler_expression: string, dtypes: TypedArrayStr[]): string;
|
|
16
|
+
declare function applySamplerCodeVector(src: string, sampler_names: {
|
|
17
|
+
u: string[];
|
|
18
|
+
v: string[];
|
|
19
|
+
}, sampler_expressions: {
|
|
20
|
+
u: string;
|
|
21
|
+
v: string;
|
|
22
|
+
}): string;
|
|
23
|
+
declare function argMin<T>(ary: T[] | TypedArray): number;
|
|
24
|
+
export { zip, getMinZoom, getOS, Cache, normalizeOptions, getArrayConstructor, mergeShaderCode, applySamplerCodeScalar, applySamplerCodeVector, argMin };
|
package/lib/utils.js
CHANGED
|
@@ -72,4 +72,66 @@ function mergeShaderCode(snippet, main) {
|
|
|
72
72
|
}
|
|
73
73
|
return snippet + "\n" + main;
|
|
74
74
|
}
|
|
75
|
-
|
|
75
|
+
function applySamplerCodeScalar(src, sampler_names, sampler_expression, dtypes) {
|
|
76
|
+
// TAS: find a better place for this to live.
|
|
77
|
+
const SAMPLER_DTYPES = {
|
|
78
|
+
'float16': 'sampler2D', 'float32': 'sampler2D',
|
|
79
|
+
'uint8': 'lowp usampler2D', 'uint16': 'mediump usampler2D', 'uint32': 'highp usampler2D',
|
|
80
|
+
'int16': 'mediump isampler2D', 'int32': 'highp isampler2D',
|
|
81
|
+
};
|
|
82
|
+
const SHADER_DTYPES = {
|
|
83
|
+
'float16': 'highp float', 'float32': 'highp float',
|
|
84
|
+
'uint8': 'uint', 'uint16': 'uint', 'uint32': 'uint',
|
|
85
|
+
'int16': 'int', 'int32': 'int',
|
|
86
|
+
};
|
|
87
|
+
const samplers = sampler_names.map((v, i) => `uniform ${SAMPLER_DTYPES[dtypes[i]]} ${v};`).join("\n");
|
|
88
|
+
const sampler_get = sampler_names.map((v, i) => ` ${SHADER_DTYPES[dtypes[i]]} ${v}_val = texture(${v}, tex_coord).r;`).join("\n");
|
|
89
|
+
sampler_names.forEach(v => sampler_expression = sampler_expression.replaceAll(v, `${v}_val`));
|
|
90
|
+
// TAS: This assumes that the return type of the expression is the same as the type of the inputs. May need to revisit this later.
|
|
91
|
+
const sampler_code = `
|
|
92
|
+
${samplers}
|
|
93
|
+
|
|
94
|
+
${SHADER_DTYPES[dtypes[0]]} get_field_value(lowp vec2 tex_coord) {
|
|
95
|
+
${sampler_get}
|
|
96
|
+
return ${sampler_expression};
|
|
97
|
+
}`;
|
|
98
|
+
return mergeShaderCode(sampler_code, src);
|
|
99
|
+
}
|
|
100
|
+
function applySamplerCodeVector(src, sampler_names, sampler_expressions) {
|
|
101
|
+
const samplers = sampler_names.u.map(v => `uniform sampler2D ${v};`).join("\n") + "\n" +
|
|
102
|
+
sampler_names.v.map(v => `uniform sampler2D ${v};`).join("\n");
|
|
103
|
+
const sampler_u_get = sampler_names.u.map(v => ` highp float ${v}_val = texture(${v}, tex_coord).r;`).join("\n");
|
|
104
|
+
const sampler_v_get = sampler_names.v.map(v => ` highp float ${v}_val = texture(${v}, tex_coord).r;`).join("\n");
|
|
105
|
+
let sampler_expression_u = sampler_expressions.u;
|
|
106
|
+
sampler_names.u.forEach(v => sampler_expression_u = sampler_expression_u.replaceAll(v, `${v}_val`));
|
|
107
|
+
let sampler_expression_v = sampler_expressions.v;
|
|
108
|
+
sampler_names.v.forEach(v => sampler_expression_v = sampler_expression_v.replaceAll(v, `${v}_val`));
|
|
109
|
+
const sampler_code = `
|
|
110
|
+
${samplers}
|
|
111
|
+
|
|
112
|
+
highp float get_field_value_u(lowp vec2 tex_coord) {
|
|
113
|
+
${sampler_u_get}
|
|
114
|
+
return ${sampler_expression_u};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
highp float get_field_value_v(lowp vec2 tex_coord) {
|
|
118
|
+
${sampler_v_get}
|
|
119
|
+
return ${sampler_expression_v};
|
|
120
|
+
}`;
|
|
121
|
+
return mergeShaderCode(sampler_code, src);
|
|
122
|
+
}
|
|
123
|
+
function argMin(ary) {
|
|
124
|
+
if (ary.length === 0) {
|
|
125
|
+
return -1;
|
|
126
|
+
}
|
|
127
|
+
let min = ary[0];
|
|
128
|
+
let minIndex = 0;
|
|
129
|
+
for (let i = 1; i < ary.length; i++) {
|
|
130
|
+
if (ary[i] < min) {
|
|
131
|
+
minIndex = i;
|
|
132
|
+
min = ary[i];
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return minIndex;
|
|
136
|
+
}
|
|
137
|
+
export { zip, getMinZoom, getOS, Cache, normalizeOptions, getArrayConstructor, mergeShaderCode, applySamplerCodeScalar, applySamplerCodeVector, argMin };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "autumnplot-gl",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.1.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -34,8 +34,9 @@
|
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@petamoriken/float16": "^3.8.4",
|
|
37
|
-
"autumn-wgl": "^1.5.
|
|
37
|
+
"autumn-wgl": "^1.5.5",
|
|
38
38
|
"comlink": "^4.3.1",
|
|
39
|
+
"geographiclib-geodesic": "^2.2.0",
|
|
39
40
|
"kd-tree-javascript": "^1.0.3",
|
|
40
41
|
"pbf": "^3.2.1",
|
|
41
42
|
"potpack": "^2.0.0"
|
package/lib/Grid.d.ts
DELETED
|
@@ -1,270 +0,0 @@
|
|
|
1
|
-
import { WGLBuffer, WGLTexture } from "autumn-wgl";
|
|
2
|
-
import { TypedArray, WebGLAnyRenderingContext } from "./AutumnTypes";
|
|
3
|
-
interface EarthCoords {
|
|
4
|
-
lons: Float32Array;
|
|
5
|
-
lats: Float32Array;
|
|
6
|
-
}
|
|
7
|
-
interface GridCoords {
|
|
8
|
-
x: Float32Array;
|
|
9
|
-
y: Float32Array;
|
|
10
|
-
}
|
|
11
|
-
type GridType = 'latlon' | 'latlonrot' | 'lcc' | 'unstructured';
|
|
12
|
-
/** The base class for grid types */
|
|
13
|
-
declare abstract class Grid {
|
|
14
|
-
readonly type: GridType;
|
|
15
|
-
readonly ni: number;
|
|
16
|
-
readonly nj: number;
|
|
17
|
-
readonly is_conformal: boolean;
|
|
18
|
-
private readonly billboard_buffer_cache;
|
|
19
|
-
private readonly vector_rotation_cache;
|
|
20
|
-
constructor(type: GridType, is_conformal: boolean, ni: number, nj: number);
|
|
21
|
-
abstract getEarthCoords(): EarthCoords;
|
|
22
|
-
abstract getGridCoords(): GridCoords;
|
|
23
|
-
abstract transform(x: number, y: number, opts?: {
|
|
24
|
-
inverse?: boolean;
|
|
25
|
-
}): [number, number];
|
|
26
|
-
abstract sampleNearestGridPoint(lon: number, lat: number, ary: TypedArray): {
|
|
27
|
-
sample: number;
|
|
28
|
-
sample_lon: number;
|
|
29
|
-
sample_lat: number;
|
|
30
|
-
};
|
|
31
|
-
abstract getThinnedGrid(thin_fac: number, map_max_zoom: number): Grid;
|
|
32
|
-
abstract thinDataArray<ArrayType extends TypedArray>(original_grid: Grid, ary: ArrayType): ArrayType;
|
|
33
|
-
abstract getMinVisibleZoom(thin_fac: number): Uint8Array;
|
|
34
|
-
getWGLBillboardBuffers(gl: WebGLAnyRenderingContext, thin_fac: number, max_zoom: number): Promise<{
|
|
35
|
-
vertices: WGLBuffer;
|
|
36
|
-
texcoords: WGLBuffer;
|
|
37
|
-
}>;
|
|
38
|
-
abstract copy(): Grid;
|
|
39
|
-
getVectorRotationAtPoint(lon: number, lat: number): number;
|
|
40
|
-
getVectorRotationTexture(gl: WebGLAnyRenderingContext, data_are_earth_relative: boolean): {
|
|
41
|
-
rotation: WGLTexture;
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
/** A structured grid (in this case meaning a cartesian grid with i and j coordinates) */
|
|
45
|
-
declare abstract class StructuredGrid extends Grid {
|
|
46
|
-
private readonly buffer_cache;
|
|
47
|
-
protected readonly thin_x: number;
|
|
48
|
-
protected readonly thin_y: number;
|
|
49
|
-
constructor(type: GridType, is_conformal: boolean, ni: number, nj: number, thin_x?: number, thin_y?: number);
|
|
50
|
-
abstract getEarthCoords(ni?: number, nj?: number): EarthCoords;
|
|
51
|
-
/** @internal */
|
|
52
|
-
protected xyThinFromMaxZoom(thin_fac: number, map_max_zoom: number): [number, number];
|
|
53
|
-
/** @internal */
|
|
54
|
-
getMinVisibleZoom(thin_fac: number): Uint8Array;
|
|
55
|
-
/** @internal */
|
|
56
|
-
thinDataArray<ArrayType extends TypedArray>(original_grid: StructuredGrid, ary: ArrayType): ArrayType;
|
|
57
|
-
abstract copy(opts?: {
|
|
58
|
-
ni?: number;
|
|
59
|
-
nj?: number;
|
|
60
|
-
}): Grid;
|
|
61
|
-
getWGLBuffers(gl: WebGLAnyRenderingContext): Promise<{
|
|
62
|
-
vertices: WGLBuffer;
|
|
63
|
-
texcoords: WGLBuffer;
|
|
64
|
-
}>;
|
|
65
|
-
sampleNearestGridPoint(lon: number, lat: number, ary: TypedArray): {
|
|
66
|
-
sample: number;
|
|
67
|
-
sample_lon: number;
|
|
68
|
-
sample_lat: number;
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
/** A plate carree (a.k.a. lat/lon) grid with uniform grid spacing */
|
|
72
|
-
declare class PlateCarreeGrid extends StructuredGrid {
|
|
73
|
-
readonly ll_lon: number;
|
|
74
|
-
readonly ll_lat: number;
|
|
75
|
-
readonly ur_lon: number;
|
|
76
|
-
readonly ur_lat: number;
|
|
77
|
-
private readonly ll_cache;
|
|
78
|
-
private readonly gc_cache;
|
|
79
|
-
/**
|
|
80
|
-
* Create a plate carree grid
|
|
81
|
-
* @param ni - The number of grid points in the i (longitude) direction
|
|
82
|
-
* @param nj - The number of grid points in the j (latitude) direction
|
|
83
|
-
* @param ll_lon - The longitude of the lower left corner of the grid
|
|
84
|
-
* @param ll_lat - The latitude of the lower left corner of the grid
|
|
85
|
-
* @param ur_lon - The longitude of the upper right corner of the grid
|
|
86
|
-
* @param ur_lat - The latitude of the upper right corner of the grid
|
|
87
|
-
*/
|
|
88
|
-
constructor(ni: number, nj: number, ll_lon: number, ll_lat: number, ur_lon: number, ur_lat: number, thin_x?: number, thin_y?: number);
|
|
89
|
-
/** @internal */
|
|
90
|
-
copy(opts?: {
|
|
91
|
-
ni?: number;
|
|
92
|
-
nj?: number;
|
|
93
|
-
ll_lon?: number;
|
|
94
|
-
ll_lat?: number;
|
|
95
|
-
ur_lon?: number;
|
|
96
|
-
ur_lat?: number;
|
|
97
|
-
}): PlateCarreeGrid;
|
|
98
|
-
/**
|
|
99
|
-
* @internal
|
|
100
|
-
* Get a list of longitudes and latitudes on the grid (internal method)
|
|
101
|
-
*/
|
|
102
|
-
getEarthCoords(ni?: number, nj?: number): EarthCoords;
|
|
103
|
-
/** @internal */
|
|
104
|
-
getGridCoords(): GridCoords;
|
|
105
|
-
/** @internal */
|
|
106
|
-
transform(x: number, y: number, opts?: {
|
|
107
|
-
inverse?: boolean;
|
|
108
|
-
}): [number, number];
|
|
109
|
-
/** @internal */
|
|
110
|
-
getThinnedGrid(thin_fac: number, map_max_zoom: number): PlateCarreeGrid;
|
|
111
|
-
}
|
|
112
|
-
/** A rotated lat-lon (plate carree) grid with uniform grid spacing */
|
|
113
|
-
declare class PlateCarreeRotatedGrid extends StructuredGrid {
|
|
114
|
-
readonly np_lon: number;
|
|
115
|
-
readonly np_lat: number;
|
|
116
|
-
readonly lon_shift: number;
|
|
117
|
-
readonly ll_lon: number;
|
|
118
|
-
readonly ll_lat: number;
|
|
119
|
-
readonly ur_lon: number;
|
|
120
|
-
readonly ur_lat: number;
|
|
121
|
-
private readonly llrot;
|
|
122
|
-
private readonly ll_cache;
|
|
123
|
-
private readonly gc_cache;
|
|
124
|
-
/**
|
|
125
|
-
* Create a Lambert conformal conic grid
|
|
126
|
-
* @param ni - The number of grid points in the i (longitude) direction
|
|
127
|
-
* @param nj - The number of grid points in the j (latitude) direction
|
|
128
|
-
* @param np_lon - The longitude of the north pole for the rotated grid
|
|
129
|
-
* @param np_lat - The latitude of the north pole for the rotated grid
|
|
130
|
-
* @param lon_shift - The angle around the rotated north pole to shift the central meridian
|
|
131
|
-
* @param ll_lon - The longitude of the lower left corner of the grid (on the rotated earth)
|
|
132
|
-
* @param ll_lat - The latitude of the lower left corner of the grid (on the rotated earth)
|
|
133
|
-
* @param ur_lon - The longitude of the upper right corner of the grid (on the rotated earth)
|
|
134
|
-
* @param ur_lat - The latitude of the upper right corner of the grid (on the rotated earth)
|
|
135
|
-
*/
|
|
136
|
-
constructor(ni: number, nj: number, np_lon: number, np_lat: number, lon_shift: number, ll_lon: number, ll_lat: number, ur_lon: number, ur_lat: number, thin_x?: number, thin_y?: number);
|
|
137
|
-
/** @internal */
|
|
138
|
-
copy(opts?: {
|
|
139
|
-
ni?: number;
|
|
140
|
-
nj?: number;
|
|
141
|
-
ll_lon?: number;
|
|
142
|
-
ll_lat?: number;
|
|
143
|
-
ur_lon?: number;
|
|
144
|
-
ur_lat?: number;
|
|
145
|
-
}): PlateCarreeRotatedGrid;
|
|
146
|
-
/**
|
|
147
|
-
* @internal
|
|
148
|
-
* Get a list of longitudes and latitudes on the grid
|
|
149
|
-
*/
|
|
150
|
-
getEarthCoords(ni?: number, nj?: number): EarthCoords;
|
|
151
|
-
/** @internal */
|
|
152
|
-
getGridCoords(): GridCoords;
|
|
153
|
-
/** @internal */
|
|
154
|
-
transform(x: number, y: number, opts?: {
|
|
155
|
-
inverse?: boolean;
|
|
156
|
-
}): [number, number];
|
|
157
|
-
/** @internal */
|
|
158
|
-
getThinnedGrid(thin_fac: number, map_max_zoom: number): PlateCarreeRotatedGrid;
|
|
159
|
-
}
|
|
160
|
-
/** A Lambert conformal conic grid with uniform grid spacing */
|
|
161
|
-
declare class LambertGrid extends StructuredGrid {
|
|
162
|
-
readonly lon_0: number;
|
|
163
|
-
readonly lat_0: number;
|
|
164
|
-
readonly lat_std: [number, number];
|
|
165
|
-
readonly ll_x: number;
|
|
166
|
-
readonly ll_y: number;
|
|
167
|
-
readonly ur_x: number;
|
|
168
|
-
readonly ur_y: number;
|
|
169
|
-
readonly a: number;
|
|
170
|
-
readonly b: number;
|
|
171
|
-
private readonly lcc;
|
|
172
|
-
private readonly ll_cache;
|
|
173
|
-
private readonly gc_cache;
|
|
174
|
-
/**
|
|
175
|
-
* Create a Lambert conformal conic grid from the lower-left and upper-right corner x/y values.
|
|
176
|
-
* @param ni - The number of grid points in the i (longitude) direction
|
|
177
|
-
* @param nj - The number of grid points in the j (latitude) direction
|
|
178
|
-
* @param lon_0 - The standard longitude for the projection; this is also the center longitude for the projection
|
|
179
|
-
* @param lat_0 - The center latitude for the projection
|
|
180
|
-
* @param lat_std - The standard latitudes for the projection
|
|
181
|
-
* @param ll_x - The x coordinate in projection space of the lower-left corner of the grid
|
|
182
|
-
* @param ll_y - The y coordinate in projection space of the lower-left corner of the grid
|
|
183
|
-
* @param ur_x - The x coordinate in projection space of the upper-right corner of the grid
|
|
184
|
-
* @param ur_y - The y coordinate in projection space of the upper-right corner of the grid
|
|
185
|
-
* @param a - The semimajor axis of the assumed shape of Earth in meters
|
|
186
|
-
* @param b - The semiminor axis of the assumed shape of Earth in meters
|
|
187
|
-
*/
|
|
188
|
-
constructor(ni: number, nj: number, lon_0: number, lat_0: number, lat_std: [number, number], ll_x: number, ll_y: number, ur_x: number, ur_y: number, a?: number, b?: number, thin_x?: number, thin_y?: number);
|
|
189
|
-
/**
|
|
190
|
-
* Create a Lambert conformal conic grid from the lower-left grid point coordinate and a dx and dy.
|
|
191
|
-
* @param ni - The number of grid points in the i (longitude) direction
|
|
192
|
-
* @param nj - The number of grid points in the j (latitude) direction
|
|
193
|
-
* @param lon_0 - The standard longitude for the projection; this is also the center longitude for the projection
|
|
194
|
-
* @param lat_0 - The center latitude for the projection
|
|
195
|
-
* @param lat_std - The standard latitudes for the projection
|
|
196
|
-
* @param ll_lon - The longitude of the lower-left corner of the grid
|
|
197
|
-
* @param ll_lat - The latitude of the lower-left corner of the grid
|
|
198
|
-
* @param dx - The grid dx in meters
|
|
199
|
-
* @param dy - The grid dy in meters
|
|
200
|
-
* @param a - The semimajor axis of the assumed shape of Earth in meters
|
|
201
|
-
* @param b - The semiminor axis of the assumed shape of Earth in meters
|
|
202
|
-
* @returns
|
|
203
|
-
*/
|
|
204
|
-
static fromLLCornerLonLat(ni: number, nj: number, lon_0: number, lat_0: number, lat_std: [number, number], ll_lon: number, ll_lat: number, dx: number, dy: number, a?: number, b?: number): LambertGrid;
|
|
205
|
-
/** @internal */
|
|
206
|
-
copy(opts?: {
|
|
207
|
-
ni?: number;
|
|
208
|
-
nj?: number;
|
|
209
|
-
ll_x?: number;
|
|
210
|
-
ll_y?: number;
|
|
211
|
-
ur_x?: number;
|
|
212
|
-
ur_y?: number;
|
|
213
|
-
}): LambertGrid;
|
|
214
|
-
/**
|
|
215
|
-
* @internal
|
|
216
|
-
* Get a list of longitudes and latitudes on the grid
|
|
217
|
-
*/
|
|
218
|
-
getEarthCoords(ni?: number, nj?: number): EarthCoords;
|
|
219
|
-
/** @internal */
|
|
220
|
-
getGridCoords(): GridCoords;
|
|
221
|
-
/** @internal */
|
|
222
|
-
transform(x: number, y: number, opts?: {
|
|
223
|
-
inverse?: boolean;
|
|
224
|
-
}): [number, number];
|
|
225
|
-
/** @internal */
|
|
226
|
-
getThinnedGrid(thin_fac: number, map_max_zoom: number): LambertGrid;
|
|
227
|
-
}
|
|
228
|
-
/** An unstructured grid defined by a list of latitudes and longitudes */
|
|
229
|
-
declare class UnstructuredGrid extends Grid {
|
|
230
|
-
readonly coords: {
|
|
231
|
-
lon: number;
|
|
232
|
-
lat: number;
|
|
233
|
-
}[];
|
|
234
|
-
private readonly zoom_cache;
|
|
235
|
-
private readonly zoom_arg;
|
|
236
|
-
/**
|
|
237
|
-
* Create an unstructured grid
|
|
238
|
-
* @param coords - The lat/lon coordinates of the grid points
|
|
239
|
-
*/
|
|
240
|
-
constructor(coords: {
|
|
241
|
-
lon: number;
|
|
242
|
-
lat: number;
|
|
243
|
-
}[], zoom?: Uint8Array);
|
|
244
|
-
/** @internal */
|
|
245
|
-
copy(): UnstructuredGrid;
|
|
246
|
-
/** @internal */
|
|
247
|
-
getEarthCoords(): {
|
|
248
|
-
lons: Float32Array;
|
|
249
|
-
lats: Float32Array;
|
|
250
|
-
};
|
|
251
|
-
/** @internal */
|
|
252
|
-
getGridCoords(): GridCoords;
|
|
253
|
-
/** @internal */
|
|
254
|
-
transform(x: number, y: number, opts?: {
|
|
255
|
-
inverse?: boolean;
|
|
256
|
-
}): [number, number];
|
|
257
|
-
/** @internal */
|
|
258
|
-
getMinVisibleZoom(thin_fac: number): Uint8Array;
|
|
259
|
-
/** @internal */
|
|
260
|
-
getThinnedGrid(thin_fac: number, map_max_zoom: number): UnstructuredGrid;
|
|
261
|
-
/** @internal */
|
|
262
|
-
thinDataArray<ArrayType extends TypedArray>(original_grid: UnstructuredGrid, ary: ArrayType): ArrayType;
|
|
263
|
-
sampleNearestGridPoint(lon: number, lat: number, ary: TypedArray): {
|
|
264
|
-
sample: number;
|
|
265
|
-
sample_lon: number;
|
|
266
|
-
sample_lat: number;
|
|
267
|
-
};
|
|
268
|
-
}
|
|
269
|
-
export { Grid, StructuredGrid, PlateCarreeGrid, PlateCarreeRotatedGrid, LambertGrid, UnstructuredGrid };
|
|
270
|
-
export type { GridType };
|