-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GPU Aggregation: miscellaneous clean up (#9142)
- Loading branch information
1 parent
8a7c3c7
commit c20af82
Showing
14 changed files
with
377 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
modules/aggregation-layers/src/common/utils/bounds-utils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** Utility to estimate binIdRange as expected by AggregatorProps */ | ||
export function getBinIdRange({ | ||
dataBounds, | ||
getBinId, | ||
padding = 0 | ||
}: { | ||
/** Bounds of the input data */ | ||
dataBounds: [min: number[], max: number[]]; | ||
/** Given a data point, returns the bin id that it belongs to */ | ||
getBinId: (p: number[]) => number[]; | ||
/** Add a border around the result to avoid clipping */ | ||
padding?: number; | ||
}): [number, number][] { | ||
const corners = [ | ||
dataBounds[0], | ||
dataBounds[1], | ||
[dataBounds[0][0], dataBounds[1][1]], | ||
[dataBounds[1][0], dataBounds[0][1]] | ||
].map(p => getBinId(p)); | ||
|
||
const minX = Math.min(...corners.map(p => p[0])) - padding; | ||
const minY = Math.min(...corners.map(p => p[1])) - padding; | ||
const maxX = Math.max(...corners.map(p => p[0])) + padding + 1; | ||
const maxY = Math.max(...corners.map(p => p[1])) + padding + 1; | ||
|
||
return [ | ||
[minX, maxX], | ||
[minY, maxY] | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import {Deck, OrthographicView} from '@deck.gl/core'; | ||
import {HistogramLayer} from './histogram-layer'; | ||
|
||
const deckgl = new Deck({ | ||
views: new OrthographicView(), | ||
initialViewState: { | ||
target: [0, 0, 0], | ||
zoom: 1 | ||
}, | ||
controller: true | ||
}); | ||
|
||
const slider = document.getElementById('bin-size-slider') as HTMLInputElement; | ||
slider.oninput = updateLayer; | ||
updateLayer(); | ||
|
||
function updateLayer() { | ||
const layer = new HistogramLayer({ | ||
data: generateData(10000, 0, 100), | ||
getPosition: d => d, | ||
gpuAggregation: true, | ||
binSize: Number(slider.value), | ||
heightScale: 1 | ||
}); | ||
deckgl.setProps({layers: [layer]}); | ||
} | ||
|
||
function generateData(count: number, mean: number, stdev: number) { | ||
const result: number[] = []; | ||
for (let i = 0; i < count; i++) { | ||
// Gaussian random | ||
const u = 1 - Math.random(); | ||
const v = Math.random(); | ||
const z = Math.sqrt(-2.0 * Math.log(u)) * Math.cos(2.0 * Math.PI * v); | ||
result.push(z * stdev + mean); | ||
} | ||
return result; | ||
} |
Oops, something went wrong.