Skip to content

Commit

Permalink
Store node sizes in Float32Array
Browse files Browse the repository at this point in the history
  • Loading branch information
Stukova committed Dec 21, 2023
1 parent b9492e1 commit c57b610
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -513,8 +513,7 @@ export class Graph<N extends CosmosInputNode, L extends CosmosInputLink> {
* @returns Radius of the node.
*/
public getNodeRadiusByIndex (index: number): number | undefined {
const node = this.graph.getNodeByIndex(index)
return node && this.points.getNodeRadius(node, index)
return this.points.getNodeRadiusByIndex(index)
}

/**
Expand All @@ -523,8 +522,9 @@ export class Graph<N extends CosmosInputNode, L extends CosmosInputLink> {
* @returns Radius of the node.
*/
public getNodeRadiusById (id: string): number | undefined {
const node = this.graph.getNodeById(id)
return node && this.points.getNodeRadius(node, this.graph.getInputIndexById(id))
const index = this.graph.getInputIndexById(id)
if (index === undefined) return undefined
return this.points.getNodeRadiusByIndex(index)
}

/**
Expand Down
11 changes: 6 additions & 5 deletions src/modules/Points/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import findHoveredPointFrag from '@/graph/modules/Points/find-hovered-point.frag
import findHoveredPointVert from '@/graph/modules/Points/find-hovered-point.vert'
import fillGridWithSampledNodesFrag from '@/graph/modules/Points/fill-sampled-nodes.frag'
import fillGridWithSampledNodesVert from '@/graph/modules/Points/fill-sampled-nodes.vert'
import { createSizeBuffer, getNodeSize } from '@/graph/modules/Points/size-buffer'
import { createSizeBufferAndFillSizeStore } from '@/graph/modules/Points/size-buffer'
import updatePositionFrag from '@/graph/modules/Points/update-position.frag'
import { createIndexesBuffer, createQuadBuffer, destroyFramebuffer } from '@/graph/modules/Shared/buffer'
import { createTrackedIndicesBuffer, createTrackedPositionsBuffer } from '@/graph/modules/Points/tracked-buffer'
Expand Down Expand Up @@ -45,6 +45,7 @@ export class Points<N extends CosmosInputNode, L extends CosmosInputLink> extend
private trackPointsCommand: regl.DrawCommand | undefined
private trackedIds: string[] | undefined
private trackedPositionsById: Map<string, [number, number]> = new Map()
private sizeByIndex: Float32Array | undefined

public create (): void {
const { reglInstance, store, data, config } = this
Expand Down Expand Up @@ -328,7 +329,8 @@ export class Points<N extends CosmosInputNode, L extends CosmosInputLink> extend
public updateSize (): void {
const { reglInstance, config, store: { pointsTextureSize }, data } = this
if (!pointsTextureSize) return
this.sizeFbo = createSizeBuffer(data, reglInstance, pointsTextureSize, config.nodeSize)
this.sizeByIndex = new Float32Array(data.nodes.length)
this.sizeFbo = createSizeBufferAndFillSizeStore(data, reglInstance, pointsTextureSize, config.nodeSize, this.sizeByIndex)
}

public updateSampledNodesGrid (): void {
Expand Down Expand Up @@ -383,9 +385,8 @@ export class Points<N extends CosmosInputNode, L extends CosmosInputLink> extend
this.findHoveredPointCommand?.()
}

public getNodeRadius (node: N, index?: number): number {
const { nodeSize } = this.config
return getNodeSize(node, nodeSize, index) / 2
public getNodeRadiusByIndex (index: number): number | undefined {
return this.sizeByIndex?.[index]
}

public trackNodesByIds (ids: string[]): void {
Expand Down
9 changes: 6 additions & 3 deletions src/modules/Points/size-buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ export function getNodeSize<N extends CosmosInputNode> (
return size ?? defaultNodeSize
}

export function createSizeBuffer <N extends CosmosInputNode, L extends CosmosInputLink> (
export function createSizeBufferAndFillSizeStore <N extends CosmosInputNode, L extends CosmosInputLink> (
data: GraphData<N, L>,
reglInstance: regl.Regl,
pointTextureSize: number,
sizeAccessor: NumericAccessor<N>
sizeAccessor: NumericAccessor<N>,
sizeStore: Float32Array
): regl.Framebuffer2D | undefined {
if (pointTextureSize === 0) return undefined
const numParticles = data.nodes.length
Expand All @@ -28,7 +29,9 @@ export function createSizeBuffer <N extends CosmosInputNode, L extends CosmosInp
const sortedIndex = data.getSortedIndexByInputIndex(i)
const node = data.nodes[i]
if (node && sortedIndex !== undefined) {
initialState[sortedIndex * 4] = getNodeSize(node, sizeAccessor, i)
const nodeSize = getNodeSize(node, sizeAccessor, i)
initialState[sortedIndex * 4] = nodeSize
sizeStore[i] = nodeSize
}
}

Expand Down

0 comments on commit c57b610

Please sign in to comment.