Skip to content
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

Read Segment Index Files, Segment Stats for Annot. w/ FallbackL. #7437

Merged
merged 117 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
117 commits
Select commit Hold shift + click to select a range
7c94eb2
Add route to read segment index file
frcroth Nov 13, 2023
1e7d162
Add Hdf5Utils
frcroth Nov 13, 2023
19c8c8e
Add route to check for segment index file
frcroth Dec 6, 2023
8e32b54
Extract segment statistics logic
frcroth Dec 6, 2023
41b1a4d
wip: calculate segment volume with file
frcroth Dec 6, 2023
b57f2e9
Merge branch 'master' into segment-index-file
frcroth Dec 11, 2023
238103c
segment volume: get data from all buckets
frcroth Dec 11, 2023
91b692c
Adapt to new hd5file format
frcroth Dec 11, 2023
09a7249
WIP: Allow creating segment index when fallback exists, add todos
frcroth Dec 13, 2023
f21a769
Use segment index file as fallback in segment index buffer
frcroth Dec 18, 2023
7626a7d
Merge branch 'master' into segment-index-file
frcroth Dec 18, 2023
63b5b07
Allow segment volume to use fallback
frcroth Dec 18, 2023
b2f2adf
Move canHaveSegmentIndexOpt to WK
frcroth Dec 19, 2023
6d16d65
Correctly set hasSegmentIndex when creating annotation
frcroth Dec 19, 2023
c1ac5be
Fix some lint issues
frcroth Dec 19, 2023
808eb35
Merge branch 'master' into segment-index-file
frcroth Jan 8, 2024
133c9bd
Merge branch 'master' into segment-index-file
frcroth Jan 8, 2024
5ae019c
Add bucket provider cache key to be able to get fallback data of volu…
frcroth Jan 8, 2024
093d727
Pass mapping
frcroth Jan 8, 2024
33c18be
Use mag
frcroth Jan 10, 2024
1db3849
Implement bbox for segment index file
frcroth Jan 10, 2024
fd6d59f
Merge branch 'master' into segment-index-file
frcroth Jan 10, 2024
5668884
Lint
frcroth Jan 10, 2024
4e4d11a
Return empty list if segment index does not exist
frcroth Jan 15, 2024
4886b70
show segment volume+bbox in context menu even if there is a fallback …
fm3 Jan 15, 2024
763a885
Merge branch 'segment-index-file' of github.com:scalableminds/webknos…
fm3 Jan 15, 2024
1f7354f
show segment statistics modal also if there is a fallback layer
fm3 Jan 15, 2024
cdb9476
Implement review feedback 1
frcroth Jan 15, 2024
9bf8a7d
Implement review feedback 2
frcroth Jan 15, 2024
fabf6c0
Implement review feedback 3
frcroth Jan 15, 2024
2d06fbf
Merge branch 'master' into segment-index-file
frcroth Jan 17, 2024
d6787e7
Move await to Fox
frcroth Jan 17, 2024
a7fbc58
Merge branch 'master' into segment-index-file
frcroth Jan 22, 2024
3fc43d6
Remove unused user token
frcroth Jan 22, 2024
a4ec7de
Merge branch 'master' into segment-index-file
frcroth Jan 22, 2024
c50cfb5
WIP: change routes
knollengewaechs Jan 22, 2024
28a4a55
[ci skip]
knollengewaechs Jan 22, 2024
871c2ed
WIP: use datastore for segment stats if applicable
knollengewaechs Jan 23, 2024
4d298be
Merge branch 'master' into segment-index-file
knollengewaechs Jan 30, 2024
ae441d1
[ci skip] extract helper method to know which host to use
knollengewaechs Jan 30, 2024
b3d6de8
Merge branch 'master' into segment-index-file
frcroth Jan 31, 2024
80b60c4
cache hasSegmentIndex and store it in store
knollengewaechs Jan 31, 2024
b2d6c4e
delete unused imports
knollengewaechs Jan 31, 2024
0b8c34c
Merge branch 'master' into segment-index-file
frcroth Feb 5, 2024
87982e2
Merge branch 'master' into segment-index-file
frcroth Feb 7, 2024
f782325
Merge frontend
frcroth Feb 7, 2024
40a6e13
Improve performance of datastore segment volume
frcroth Feb 7, 2024
3804599
WIP: Unify interface again for calculate segment index
frcroth Feb 7, 2024
d19d4e6
fix errors related to merging
knollengewaechs Feb 8, 2024
413bcc5
fix context menu in dataset view mode
knollengewaechs Feb 8, 2024
b928f33
use saga to ensure the segment index state has been loaded
knollengewaechs Feb 9, 2024
2e3046f
fix that during loading no values were shown for segment volumes and …
knollengewaechs Feb 9, 2024
c314b4a
lint
knollengewaechs Feb 9, 2024
3a966f2
Merge branch 'master' into segment-index-file
knollengewaechs Feb 9, 2024
aaab819
fix that mesh volume and BB wasnt shown in viewport context menu
knollengewaechs Feb 9, 2024
d6ee56a
remove css class
knollengewaechs Feb 9, 2024
fb2c845
add accessor for segment index availability
knollengewaechs Feb 9, 2024
f1d4548
Remove old way of calculating, DENKFEHLER
frcroth Feb 12, 2024
9d32f86
Remove unused methods
frcroth Feb 12, 2024
ddae12c
Extract file extension
frcroth Feb 12, 2024
a4a5db9
Change segment id route to POST so frontend can use it for meshing
frcroth Feb 12, 2024
4ebe9b7
Merge branch 'master' into segment-index-file
frcroth Feb 12, 2024
62b5cf7
Fix minor things
frcroth Feb 12, 2024
5dde951
WIP: Batch queries to datastore segment index to improve saving perf
frcroth Feb 12, 2024
2b28b6e
Return empty list if segment is not in index file
frcroth Feb 14, 2024
d277f7c
address frontend review
knollengewaechs Feb 14, 2024
991d39b
store isBusy info by tracing id and not by tracing type only to avoid…
philippotto Feb 15, 2024
91b9338
remove unused imports
philippotto Feb 15, 2024
90fb83b
Merge branch 'master' into segment-index-file
frcroth Feb 19, 2024
95bc71b
Cache segments in buffer
frcroth Feb 19, 2024
777b0fc
Cache fallback layer
frcroth Feb 19, 2024
20059bf
Remove logging
frcroth Feb 19, 2024
e23daee
fix race condition in watchForSaveConflicts by exploiting the fact th…
philippotto Feb 20, 2024
5e670bf
update comment
philippotto Feb 20, 2024
a3617bc
Remove flush in every updateBucket
frcroth Feb 21, 2024
8cdcfae
Merge branch 'master' into segment-index-file
fm3 Feb 21, 2024
56a37cf
Fix adding segments to index without fallback
frcroth Feb 21, 2024
13a3190
Set segment index file path lookup to silent
frcroth Feb 21, 2024
54d78c3
Add temporary store for tracing id / datasource
frcroth Feb 21, 2024
3f6d786
Merge branch 'master' into segment-index-file
frcroth Feb 21, 2024
c1133c0
address review: add action to datasetaction, include mapping name in …
knollengewaechs Feb 21, 2024
d7e538e
Merge branch 'master' into segment-index-file
frcroth Feb 28, 2024
ce49334
Annotation upload: get remote datastore based on org and dsname
frcroth Feb 28, 2024
b931789
Merge branch 'master' into segment-index-file
frcroth Mar 4, 2024
63c0e37
Fix merging annotations by using first tracing as tracing to get fall…
frcroth Mar 4, 2024
141d74e
Fix segment index buffer not being queried for map
frcroth Mar 4, 2024
7bacd0d
Apply suggestions from code review
frcroth Mar 4, 2024
336fbf1
Merge branch 'master' into segment-index-file
frcroth Mar 4, 2024
f3b3ba6
Remove get or else
frcroth Mar 4, 2024
b561652
WIP: prepare for mappings
fm3 Mar 6, 2024
bd00478
include mapping name when using data store
knollengewaechs Mar 6, 2024
726a0a1
make unpacking the zip wait for the future of the passed function
fm3 Mar 6, 2024
592c13b
Merge branch 'segment-index-file' of github.com:scalableminds/webknos…
fm3 Mar 6, 2024
cf48a69
also for multi-uploads. clean up logging
fm3 Mar 6, 2024
f99e059
remove unused imports
fm3 Mar 6, 2024
42d0e8d
remove check for empty mapping name string
knollengewaechs Mar 6, 2024
0ded7c9
lint
fm3 Mar 6, 2024
59ef66b
Merge branch 'segment-index-file' of github.com:scalableminds/webknos…
fm3 Mar 6, 2024
bec652e
changelog
fm3 Mar 6, 2024
6bfdb83
merge master
knollengewaechs Mar 6, 2024
dcf381a
migrate to biome
knollengewaechs Mar 6, 2024
9e925aa
fix forgotten merge conflicts in changelog
knollengewaechs Mar 6, 2024
ae3fadf
Merge branch 'master' into segment-index-file
fm3 Mar 11, 2024
4258bea
satisfy biome by passing segmentation layer name through to saga
knollengewaechs Mar 11, 2024
b232b8c
fix after merge
fm3 Mar 11, 2024
9a9bedf
Merge branch 'segment-index-file' of github.com:scalableminds/webknos…
fm3 Mar 11, 2024
b1f9068
look up segment ids for agglomerate id
fm3 Mar 11, 2024
65f5d08
respect passed mapping when querying segment index file
fm3 Mar 11, 2024
9a1f1f1
handle agglomerate ids that are not present in agglomerate file
fm3 Mar 11, 2024
3374978
force sequential bucket processing also in initializeWithDatMultiple
fm3 Mar 11, 2024
afe3792
editable mapping support for segment index
fm3 Mar 11, 2024
14149e0
fix querying agglomerates of editable mapping that were not edited
fm3 Mar 11, 2024
e7349b4
Merge branch 'master' into segment-index-file
fm3 Mar 11, 2024
accd42d
a commit concerning the renaming of a concerned variable for the conc…
knollengewaechs Mar 12, 2024
da7c7ef
lint frontend
knollengewaechs Mar 13, 2024
3298ffb
Merge branch 'master' into segment-index-file
frcroth Mar 18, 2024
91e8111
Fix typo in error
frcroth Mar 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ For upgrade instructions, please check the [migration guide](MIGRATIONS.released
- Added a new "Split from all neighboring segments" feature for the proofreading mode. [#7611](https://github.com/scalableminds/webknossos/pull/7611)
- If storage scan is enabled, the measured used storage is now displayed in the dashboard’s dataset detail view. [#7677](https://github.com/scalableminds/webknossos/pull/7677)
- Prepared support to download full stl meshes via the HTTP api. [#7587](https://github.com/scalableminds/webknossos/pull/7587)
- You can now place segment index files with your on-disk segmentation layers, which makes segment stats available when viewing these segmentations, and also when working on volume annotations based on these segmentation layers. [#7437](https://github.com/scalableminds/webknossos/pull/7437)

### Changed
- Datasets stored in WKW format are no longer loaded with memory mapping, reducing memory demands. [#7528](https://github.com/scalableminds/webknossos/pull/7528)
Expand Down
8 changes: 2 additions & 6 deletions frontend/javascripts/admin/admin_rest_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -973,11 +973,9 @@ export function getSegmentVolumes(
additionalCoordinates: AdditionalCoordinate[] | undefined | null,
mappingName: string | null | undefined,
): Promise<number[]> {
let mappingNameNoEmptyString = mappingName;
if (mappingName != null && mappingName.length < 1) mappingNameNoEmptyString = null;
return doWithToken((token) =>
Request.sendJSONReceiveJSON(`${requestUrl}/segmentStatistics/volume?token=${token}`, {
data: { additionalCoordinates, mag, segmentIds, mappingName: mappingNameNoEmptyString },
data: { additionalCoordinates, mag, segmentIds, mappingName },
method: "POST",
}),
);
Expand All @@ -990,11 +988,9 @@ export function getSegmentBoundingBoxes(
additionalCoordinates: AdditionalCoordinate[] | undefined | null,
mappingName: string | null | undefined,
): Promise<Array<{ topLeft: Vector3; width: number; height: number; depth: number }>> {
let mappingNameNoEmptyString = mappingName;
if (mappingName != null && mappingName.length < 1) mappingNameNoEmptyString = null;
return doWithToken((token) =>
Request.sendJSONReceiveJSON(`${requestUrl}/segmentStatistics/boundingBox?token=${token}`, {
data: { additionalCoordinates, mag, segmentIds, mappingName: mappingNameNoEmptyString },
data: { additionalCoordinates, mag, segmentIds, mappingName },
method: "POST",
}),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,7 @@ export function getEffectiveIntensityRange(
// sure this info is fetched.
export function getMaybeSegmentIndexAvailability(
dataset: APIDataset,
layerName: string | undefined,
layerName: string | null | undefined,
) {
if (layerName == null) {
return false;
Expand Down
12 changes: 7 additions & 5 deletions frontend/javascripts/oxalis/model/actions/dataset_actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ export type EnsureLayerMappingsAreLoadedAction = ReturnType<
typeof ensureLayerMappingsAreLoadedAction
>;
type SetLayerHasSegmentIndexAction = ReturnType<typeof setLayerHasSegmentIndexAction>;
export type EnsureSegmentIndexIsLoadedAction = ReturnType<typeof ensureSegmentIndexIsLoadedAction>;

export type DatasetAction =
| SetDatasetAction
| SetLayerMappingsAction
| SetLayerTransformsAction
| EnsureLayerMappingsAreLoadedAction
| SetLayerHasSegmentIndexAction
| EnsureLayerMappingsAreLoadedAction;
| EnsureSegmentIndexIsLoadedAction;

export const setDatasetAction = (dataset: APIDataset) =>
({
Expand Down Expand Up @@ -47,16 +48,17 @@ export const ensureLayerMappingsAreLoadedAction = (layerName?: string) =>
({
type: "ENSURE_LAYER_MAPPINGS_ARE_LOADED",
layerName,
} as const);
}) as const;

export const setLayerHasSegmentIndexAction = (layerName: string, hasSegmentIndex: boolean) =>
({
type: "SET_LAYER_HAS_SEGMENT_INDEX",
layerName,
hasSegmentIndex,
} as const);
}) as const;

export const ensureSegmentIndexIsLoadedAction = () =>
export const ensureSegmentIndexIsLoadedAction = (layerName: string | null | undefined) =>
({
type: "ENSURE_SEGMENT_INDEX_IS_LOADED",
} as const);
layerName,
}) as const;
2 changes: 1 addition & 1 deletion frontend/javascripts/oxalis/model/actions/save_actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export const setSaveBusyAction = (
isBusy,
saveQueueType,
tracingId,
} as const);
}) as const;

export const setLastSaveTimestampAction = (saveQueueType: SaveQueueType, tracingId: string) =>
({
Expand Down
28 changes: 18 additions & 10 deletions frontend/javascripts/oxalis/model/sagas/dataset_saga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import Toast from "libs/toast";
import messages from "messages";
import {
getEnabledLayers,
getLayerByName,
getMaybeSegmentIndexAvailability,
getResolutionInfo,
getTransformsForLayer,
getVisibleSegmentationLayer,
invertAndTranspose,
isLayerVisible,
} from "../accessors/dataset_accessor";
Expand All @@ -19,7 +19,10 @@ import { getViewportExtents } from "../accessors/view_mode_accessor";
import { V3 } from "libs/mjs";
import { Identity4x4 } from "oxalis/constants";
import { hasSegmentIndex } from "oxalis/view/right-border-tabs/segments_tab/segments_view_helper";
import { setLayerHasSegmentIndexAction } from "../actions/dataset_actions";
import {
EnsureSegmentIndexIsLoadedAction,
setLayerHasSegmentIndexAction,
} from "../actions/dataset_actions";

export function* watchMaximumRenderableLayers(): Saga<void> {
function* warnMaybe(): Saga<void> {
Expand Down Expand Up @@ -154,22 +157,27 @@ export function* watchZ1Downsampling(): Saga<void> {
}

export function* ensureSegmentIndexIsLoaded(): Saga<void> {
knollengewaechs marked this conversation as resolved.
Show resolved Hide resolved
function* maybeFetchHasSegmentIndex(): Saga<void> {
const visibleSegmentationLayer = yield* select((state) => getVisibleSegmentationLayer(state));
const maybeIsSegmentIndexAvailable = yield* select((state) =>
getMaybeSegmentIndexAvailability(state.dataset, visibleSegmentationLayer?.name),
function* maybeFetchHasSegmentIndex(action: EnsureSegmentIndexIsLoadedAction): Saga<void> {
const { layerName } = action;
const dataset = yield* select((state) => state.dataset);
if (layerName == null) return;
const concernedSegmentationLayer = yield* call(getLayerByName, dataset, layerName);
knollengewaechs marked this conversation as resolved.
Show resolved Hide resolved
const maybeIsSegmentIndexAvailable = yield* call(
getMaybeSegmentIndexAvailability,
dataset,
layerName,
);
if (maybeIsSegmentIndexAvailable == null && visibleSegmentationLayer != null) {
const { dataset, tracing } = yield* select((state) => state);
if (maybeIsSegmentIndexAvailable == null && concernedSegmentationLayer != null) {
const tracing = yield* select((state) => state.tracing);
const updatedIsSegmentIndexAvailable = yield* call(
hasSegmentIndex,
visibleSegmentationLayer,
concernedSegmentationLayer,
dataset,
tracing,
);
yield* put(
setLayerHasSegmentIndexAction(
visibleSegmentationLayer.name,
concernedSegmentationLayer.name,
updatedIsSegmentIndexAvailable,
),
);
Expand Down
2 changes: 1 addition & 1 deletion frontend/javascripts/oxalis/view/context_menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1218,7 +1218,7 @@ function ContextMenuInner(propsWithInputRef: Props) {

const { dataset, tracing, flycam } = useSelector((state: OxalisState) => state);
useEffect(() => {
Store.dispatch(ensureSegmentIndexIsLoadedAction());
Store.dispatch(ensureSegmentIndexIsLoadedAction(visibleSegmentationLayer?.name));
knollengewaechs marked this conversation as resolved.
Show resolved Hide resolved
}, [visibleSegmentationLayer]);
const isSegmentIndexAvailable = useSelector((state: OxalisState) =>
getMaybeSegmentIndexAvailability(state.dataset, visibleSegmentationLayer?.name),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export function SegmentStatisticsModal({
const maybeVolumeTracing =
tracingId != null ? getVolumeTracingById(tracing, tracingId) : null;
const maybeGetMappingName = () => {
if (maybeVolumeTracing?.mappingName != null) return maybeVolumeTracing?.mappingName;
if (maybeVolumeTracing?.mappingName != null) return maybeVolumeTracing.mappingName;
const mappingInfo = getMappingInfo(
temporaryConfiguration.activeMappingByLayer,
visibleSegmentationLayer?.name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ class SegmentsView extends React.Component<Props, State> {
this.pollJobData();
}

Store.dispatch(ensureSegmentIndexIsLoadedAction());
Store.dispatch(ensureSegmentIndexIsLoadedAction(this.props.visibleSegmentationLayer?.name));
}

componentDidUpdate(prevProps: Props) {
Expand Down
59 changes: 59 additions & 0 deletions util/src/main/scala/com/scalableminds/util/io/ZipIO.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.scalableminds.util.io

import com.scalableminds.util.tools.Fox.{box2Fox, future2Fox}

import java.io._
import java.nio.file.{Files, Path, Paths}
import java.util.zip.{GZIPOutputStream => DefaultGZIPOutputStream, _}
Expand Down Expand Up @@ -164,6 +166,63 @@ object ZipIO extends LazyLogging {
def withUnziped[A](file: File)(f: (Path, InputStream) => A): Box[List[A]] =
tryo(new java.util.zip.ZipFile(file)).flatMap(withUnziped(_)((name, is) => Full(f(name, is))))

def withUnzipedAsync[A](file: File)(f: (Path, InputStream) => Fox[A])(implicit ec: ExecutionContext): Fox[List[A]] =
for {
zip <- tryo(new java.util.zip.ZipFile(file)).toFox
resultList <- withUnzipedAsync(zip)((name, is) => f(name, is))
} yield resultList

def withUnzipedAsync[A](zip: ZipFile,
includeHiddenFiles: Boolean = false,
hiddenFilesWhitelist: List[String] = List(),
truncateCommonPrefix: Boolean = false,
excludeFromPrefix: Option[List[String]] = None)(f: (Path, InputStream) => Fox[A])(
implicit ec: ExecutionContext): Fox[List[A]] = {

val zipEntries = zip.entries.asScala.filter { e: ZipEntry =>
!e.isDirectory && (includeHiddenFiles || !isFileHidden(e) || hiddenFilesWhitelist.contains(
Paths.get(e.getName).getFileName.toString))
}.toList

val commonPrefix = if (truncateCommonPrefix) {
val commonPrefixNotFixed = PathUtils.commonPrefix(zipEntries.map(e => Paths.get(e.getName)))
val strippedPrefix =
PathUtils.cutOffPathAtLastOccurrenceOf(commonPrefixNotFixed, excludeFromPrefix.getOrElse(List.empty))
PathUtils.removeSingleFileNameFromPrefix(strippedPrefix, zipEntries.map(_.getName))
} else {
Paths.get("")
}

val resultFox = zipEntries.foldLeft[Fox[List[A]]](Fox.successful(List.empty)) { (results, entry) =>
results.futureBox.map {
case Full(rs) =>
val input: InputStream = zip.getInputStream(entry)
val path = commonPrefix.relativize(Paths.get(entry.getName))
val innerResultFox: Fox[List[A]] = f(path, input).futureBox.map {
case Full(result) =>
input.close()
Full(rs :+ result)
case Empty =>
input.close()
Empty
case failure: Failure =>
input.close()
failure
}
innerResultFox
case e =>
e.toFox
}.toFox.flatten
}

for {
result <- resultFox.futureBox.map { resultBox =>
zip.close() // close even if result is not success
resultBox
}
} yield result
}

def withUnziped[A](zip: ZipFile,
includeHiddenFiles: Boolean = false,
hiddenFilesWhitelist: List[String] = List(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.scalableminds.webknossos.datastore.controllers

import com.google.inject.Inject
import com.scalableminds.util.geometry.Vec3Int
import com.scalableminds.util.tools.{Fox, FoxImplicits}
import com.scalableminds.webknossos.datastore.ListOfLong.ListOfLong
import com.scalableminds.webknossos.datastore.helpers.{
Expand Down Expand Up @@ -42,15 +43,18 @@ class DataSourceController @Inject()(
dataSourceService: DataSourceService,
remoteWebknossosClient: DSRemoteWebknossosClient,
accessTokenService: DataStoreAccessTokenService,
binaryDataServiceHolder: BinaryDataServiceHolder,
val binaryDataServiceHolder: BinaryDataServiceHolder,
connectomeFileService: ConnectomeFileService,
segmentIndexFileService: SegmentIndexFileService,
storageUsageService: DSUsedStorageService,
datasetErrorLoggingService: DatasetErrorLoggingService,
uploadService: UploadService,
composeService: ComposeService
composeService: ComposeService,
val dsRemoteWebknossosClient: DSRemoteWebknossosClient,
val dsRemoteTracingstoreClient: DSRemoteTracingstoreClient,
)(implicit bodyParsers: PlayBodyParsers, ec: ExecutionContext)
extends Controller
with MeshMappingHelper
with FoxImplicits {

override def allowRemoteOrigin: Boolean = true
Expand Down Expand Up @@ -576,11 +580,6 @@ class DataSourceController @Inject()(

/**
* Query the segment index file for a single segment
* @param token
* @param organizationName
* @param datasetName
* @param dataLayerName
* @param segmentId
* @return List of bucketPositions as positions (not indices) of 32³ buckets in mag
*/
def getSegmentIndex(token: Option[String],
Expand All @@ -592,11 +591,23 @@ class DataSourceController @Inject()(
accessTokenService.validateAccess(UserAccessRequest.readDataSources(DataSourceId(datasetName, organizationName)),
urlOrHeaderToken(token, request)) {
for {
(topLefts, fileMag) <- segmentIndexFileService.readSegmentIndex(organizationName,
datasetName,
dataLayerName,
segmentId.toLong)
bucketPositions = segmentIndexFileService.topLeftsToBucketPositions(topLefts, request.body.mag, fileMag)
segmentIds <- segmentIdsForAgglomerateIdIfNeeded(
organizationName,
datasetName,
dataLayerName,
request.body.mappingName,
request.body.editableMappingTracingId,
segmentId.toLong,
mappingNameForMeshFile = None,
urlOrHeaderToken(token, request)
)
fileMag <- segmentIndexFileService.readFileMag(organizationName, datasetName, dataLayerName)
topLeftsNested: Seq[Array[Vec3Int]] <- Fox.serialCombined(segmentIds)(sId =>
segmentIndexFileService.readSegmentIndex(organizationName, datasetName, dataLayerName, sId))
topLefts: Array[Vec3Int] = topLeftsNested.toArray.flatten
bucketPositions = segmentIndexFileService.topLeftsToDistinctBucketPositions(topLefts,
request.body.mag,
fileMag)
bucketPositionsForCubeSize = bucketPositions
.map(_.scale(DataLayer.bucketLength)) // bucket positions raw are indices of 32³ buckets
.map(_ / request.body.cubeSize)
Expand All @@ -608,10 +619,6 @@ class DataSourceController @Inject()(

/**
* Query the segment index file for multiple segments
* @param token
* @param organizationName
* @param datasetName
* @param dataLayerName
* @return List of bucketPositions as indices of 32³ buckets
*/
def querySegmentIndex(token: Option[String],
frcroth marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -622,14 +629,26 @@ class DataSourceController @Inject()(
accessTokenService.validateAccess(UserAccessRequest.readDataSources(DataSourceId(datasetName, organizationName)),
urlOrHeaderToken(token, request)) {
for {
segmentIdsAndBucketPositions <- Fox.serialCombined(request.body.segmentIds) { segmentId =>
segmentIdsAndBucketPositions <- Fox.serialCombined(request.body.segmentIds) { segmentOrAgglomerateId =>
for {
(topLefts, fileMag) <- segmentIndexFileService.readSegmentIndex(organizationName,
datasetName,
dataLayerName,
segmentId)
bucketPositions = segmentIndexFileService.topLeftsToBucketPositions(topLefts, request.body.mag, fileMag)
} yield SegmentIndexData(segmentId, bucketPositions.toSeq)
segmentIds <- segmentIdsForAgglomerateIdIfNeeded(
organizationName,
datasetName,
dataLayerName,
request.body.mappingName,
request.body.editableMappingTracingId,
segmentOrAgglomerateId,
mappingNameForMeshFile = None,
urlOrHeaderToken(token, request)
)
fileMag <- segmentIndexFileService.readFileMag(organizationName, datasetName, dataLayerName)
topLeftsNested: Seq[Array[Vec3Int]] <- Fox.serialCombined(segmentIds)(sId =>
segmentIndexFileService.readSegmentIndex(organizationName, datasetName, dataLayerName, sId))
topLefts: Array[Vec3Int] = topLeftsNested.toArray.flatten
bucketPositions = segmentIndexFileService.topLeftsToDistinctBucketPositions(topLefts,
request.body.mag,
fileMag)
} yield SegmentIndexData(segmentOrAgglomerateId, bucketPositions.toSeq)
}
} yield Ok(Json.toJson(segmentIdsAndBucketPositions))
}
Expand Down
Loading