-
Notifications
You must be signed in to change notification settings - Fork 10
Remove three.js types from public LoadSpec interface
#405
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 10 commits
241a5f8
4e982f3
cd5e2ab
424bd97
7113eba
e402f14
958f49a
32dbbd7
e7dbe5c
31b1970
c5fd64f
2e2fde5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| import { Box3, Vector2, Vector3 } from "three"; | ||
|
|
||
| import { CImageInfo, type ImageInfo } from "../ImageInfo.js"; | ||
| import { LoadSpec } from "./IVolumeLoader.js"; | ||
| import { LoadSpec, type Region, regionToBox3 } from "./IVolumeLoader.js"; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: is there a place that is more "math utils"-like to put the regionToBox3 and box3toRegion functions?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's utils/num_utils.ts, but it seems to be geared more towards formatting numbers for display |
||
|
|
||
| export const MAX_ATLAS_EDGE = 4096; | ||
|
|
||
|
|
@@ -175,14 +175,15 @@ export function pickLevelToLoadUnscaled(loadSpec: LoadSpec, spatialDimsZYX: ZYX[ | |
| * `LoadSpec`'s `subregion` property. | ||
| */ | ||
| export function pickLevelToLoad(loadSpec: LoadSpec, spatialDimsZYX: ZYX[]): number { | ||
| const scaledDims = scaleMultipleDimsToSubregion(loadSpec.subregion, spatialDimsZYX); | ||
| const region = regionToBox3(loadSpec.subregion); | ||
| const scaledDims = scaleMultipleDimsToSubregion(region, spatialDimsZYX); | ||
| return pickLevelToLoadUnscaled(loadSpec, scaledDims); | ||
| } | ||
|
|
||
| /** Given the size of a volume in pixels, convert a `Box3` in the 0-1 range to pixels */ | ||
| export function convertSubregionToPixels(region: Box3, size: Vector3): Box3 { | ||
| const min = region.min.clone().multiply(size).floor(); | ||
| const max = region.max.clone().multiply(size).ceil(); | ||
| export function convertSubregionToPixels(region: Region, size: Vector3): Box3 { | ||
| const min = new Vector3(...region.min).multiply(size).floor(); | ||
| const max = new Vector3(...region.max).multiply(size).ceil(); | ||
|
|
||
| // ensure it's always valid to specify the same number at both ends and get a single slice | ||
| if (min.x === max.x && min.x < size.x) { | ||
|
|
@@ -202,10 +203,12 @@ export function convertSubregionToPixels(region: Box3, size: Vector3): Box3 { | |
| * Return the subset of `container` specified by `region`, assuming that `region` contains fractional values (between 0 | ||
| * and 1). i.e. if `container`'s range on the X axis is 0-4 and `region`'s is 0.25-0.5, the result will have range 1-2. | ||
| */ | ||
| export function composeSubregion(region: Box3, container: Box3): Box3 { | ||
| const size = container.getSize(new Vector3()); | ||
| const min = region.min.clone().multiply(size).add(container.min); | ||
| const max = region.max.clone().multiply(size).add(container.min); | ||
| export function composeSubregion(region: Region, container: Region): Box3 { | ||
| const regionBox = regionToBox3(region); | ||
| const containerBox = regionToBox3(container); | ||
| const size = containerBox.getSize(new Vector3()); | ||
| const min = regionBox.min.clone().multiply(size).add(containerBox.min); | ||
| const max = regionBox.max.clone().multiply(size).add(containerBox.min); | ||
| return new Box3(min, max); | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,7 +14,6 @@ import type { | |
| WorkerResponsePayload, | ||
| } from "./types.js"; | ||
| import { WorkerEventType, WorkerMsgType, WorkerResponseResult } from "./types.js"; | ||
| import { rebuildLoadSpec } from "./util.js"; | ||
|
|
||
| type LoaderEntry = { loader: ThreadableVolumeLoader; copyOnLoad: boolean }; | ||
|
|
||
|
|
@@ -74,20 +73,20 @@ const messageHandlers: { [T in WorkerMsgType]: MessageHandler<T> } = { | |
| [WorkerMsgType.CREATE_VOLUME]: async (loadSpec, loaderId) => { | ||
| const { loader } = getLoader(loaderId); | ||
|
|
||
| return await loader.createImageInfo(rebuildLoadSpec(loadSpec)); | ||
| return await loader.createImageInfo(loadSpec); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this safe to do now because it now uses primitive types instead of the threejs classes?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep! All |
||
| }, | ||
|
|
||
| [WorkerMsgType.LOAD_DIMS]: async (loadSpec, loaderId) => { | ||
| const { loader } = getLoader(loaderId); | ||
| return await loader.loadDims(rebuildLoadSpec(loadSpec)); | ||
| return await loader.loadDims(loadSpec); | ||
| }, | ||
|
|
||
| [WorkerMsgType.LOAD_VOLUME_DATA]: ({ imageInfo, loadSpec, loadId }, loaderId) => { | ||
| const { loader, copyOnLoad } = getLoader(loaderId); | ||
|
|
||
| return loader.loadRawChannelData( | ||
| imageInfo, | ||
| rebuildLoadSpec(loadSpec), | ||
| loadSpec, | ||
| (imageInfo, loadSpec) => { | ||
| const message: WorkerResponse<WorkerMsgType> = { | ||
| responseResult: WorkerResponseResult.EVENT, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.