Skip to content

Commit

Permalink
feat(datasource/graphene) view only (#383)
Browse files Browse the repository at this point in the history
* graphene view only logic

* made graphene extend more of precomputed (MultiscaleVolumeInfo)

* having GrapheneMultiscaleVolumeChunkSource extend PrecomputedMultiscaleVolumeChunkSource

* removed unverified mesh logic

* removed temporary graphene specific http functions that helped avoid cors errors

* ChunkedGraphChunk now only loads data for a single segment id and is immutable. previous version had a reference to the visible segments, loaded data for all of them andn reacted to changnes to the visible segments

* refactored chunked graph to use SliceViewPanelRenderLayer

* kept the existing unsafeKeys/unsafeEntries as optional performance sensitive options for bash table iteration. [Symbol.iterator] defaults to safe version so that Array.from and the spread operator (...) work correctly

* renamed VisibleSegmentType and added brief descriptions

* using forEachVisibleSegment in chunked_graph and also fixed bug due to previous use of unsafeKeys in that loop

* moved computeChunkBounds logic out of VolumeChunkSource so ChunkedGraphChunkSource could use it

* moved chunked graph code into graphene datasource and combined some classes

* avoiding unnecessary graphene manfiest calls if segment is a base segment

* changed computeChunkBounds helper function interface

* changed highBitRepresentative into a bitvector

* clean up - addressing pr comments

* removed another unnecessary export

* more cleanup

* removed usage of parseSpecialUrlOld
  • Loading branch information
chrisj authored May 17, 2022
1 parent faa9be7 commit 5f62034
Show file tree
Hide file tree
Showing 30 changed files with 1,628 additions and 135 deletions.
7 changes: 7 additions & 0 deletions config/bundle-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@ const DEFAULT_DATA_SOURCES = exports.DEFAULT_DATA_SOURCES = [
{
source: 'neuroglancer/datasource/nggraph',
},
{
source: 'neuroglancer/datasource/graphene',
asyncComputation: [
'neuroglancer/async_computation/decode_jpeg',
'neuroglancer/async_computation/decode_gzip',
],
},
];

const DEFAULT_SUPPORTED_LAYERS = exports.DEFAULT_SUPPORTED_LAYERS = [
Expand Down
423 changes: 423 additions & 0 deletions src/neuroglancer/datasource/graphene/backend.ts

Large diffs are not rendered by default.

129 changes: 129 additions & 0 deletions src/neuroglancer/datasource/graphene/base.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
/**
* @license
* Copyright 2019 The Neuroglancer Authors
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import {mat4} from 'neuroglancer/util/geom';
import {ShardingParameters} from 'neuroglancer/datasource/precomputed/base';
import {ChunkLayoutOptions, makeSliceViewChunkSpecification, SliceViewChunkSource, SliceViewChunkSpecification, SliceViewChunkSpecificationBaseOptions, SliceViewChunkSpecificationOptions} from 'neuroglancer/sliceview/base';
import {DataType} from 'neuroglancer/sliceview/base';

export const PYCG_APP_VERSION = 1;

export enum VolumeChunkEncoding {
RAW,
JPEG,
COMPRESSED_SEGMENTATION
}

export class VolumeChunkSourceParameters {
url: string;
encoding: VolumeChunkEncoding;
sharding: ShardingParameters|undefined;

static RPC_ID = 'graphene/VolumeChunkSource';
}


export class ChunkedGraphSourceParameters {
url: string;

static RPC_ID = 'graphene/ChunkedGraphSource';
}

export class MeshSourceParameters {
manifestUrl: string;
fragmentUrl: string;
lod: number;
sharding: Array<ShardingParameters>|undefined;
nBitsForLayerId: number;

static RPC_ID = 'graphene/MeshSource';
}

export class MultiscaleMeshMetadata {
transform: mat4;
lodScaleMultiplier: number;
vertexQuantizationBits: number;
sharding: Array<ShardingParameters>|undefined;
}

import { Uint64 } from 'neuroglancer/util/uint64';

export const responseIdentity = async (x: any) => x;

export function isBaseSegmentId(segmentId: Uint64, nBitsForLayerId: number) {
const layerId = Uint64.rshift(new Uint64(), segmentId, 64 - nBitsForLayerId);
return Uint64.equal(layerId, Uint64.ONE);
}

export function getGrapheneFragmentKey(fragmentId: string) {
const sharded = fragmentId.charAt(0) === '~';

if (sharded) {
const parts = fragmentId.substring(1).split(/:(.+)/);
return {key:parts[0], fragmentId: parts[1]};
} else {
return {key:fragmentId, fragmentId: fragmentId};
}
}

export const CHUNKED_GRAPH_LAYER_RPC_ID = 'ChunkedGraphLayer';
export const CHUNKED_GRAPH_RENDER_LAYER_UPDATE_SOURCES_RPC_ID = 'ChunkedGraphLayer:updateSources'
export const RENDER_RATIO_LIMIT = 5.0;

export interface ChunkedGraphChunkSpecificationBaseOptions extends
SliceViewChunkSpecificationBaseOptions {
/**
* Specifies offset for use by backend.ts:GenericVolumeChunkSource.computeChunkBounds in
* calculating chunk voxel coordinates. The calculated chunk coordinates will be equal to the
* voxel position (in chunkLayout coordinates) plus this value.
*
* Defaults to kZeroVec if not specified.
*/
baseVoxelOffset?: Float32Array;
dataType: DataType;
}

export interface ChunkedGraphChunkSpecificationOptions extends
ChunkedGraphChunkSpecificationBaseOptions, SliceViewChunkSpecificationOptions<Uint32Array> {}

/**
* Specifies parameters for ChunkedGraphChunkSpecification.getDefaults.
*/
export interface ChunkedGraphChunkSpecificationGetDefaultsOptions extends
ChunkedGraphChunkSpecificationBaseOptions, ChunkLayoutOptions {}

/**
* Specifies a chunk layout and voxel size.
*/
export interface ChunkedGraphChunkSpecification extends SliceViewChunkSpecification<Uint32Array> {
baseVoxelOffset: Float32Array;
dataType: DataType;
}

export function makeChunkedGraphChunkSpecification(options: ChunkedGraphChunkSpecificationOptions): ChunkedGraphChunkSpecification {
const {rank, dataType} = options;
const {baseVoxelOffset = new Float32Array(rank)} = options;

return {
...makeSliceViewChunkSpecification(options),
baseVoxelOffset,
dataType,
}
}

export interface ChunkedGraphChunkSource extends SliceViewChunkSource {
spec: ChunkedGraphChunkSpecification;
}
Loading

0 comments on commit 5f62034

Please sign in to comment.