diff --git a/frontend/javascripts/admin/admin_rest_api.ts b/frontend/javascripts/admin/admin_rest_api.ts index 634e0761dd..30e3a565ec 100644 --- a/frontend/javascripts/admin/admin_rest_api.ts +++ b/frontend/javascripts/admin/admin_rest_api.ts @@ -1546,16 +1546,16 @@ export async function findDataPositionForLayer( layerName: string, ): Promise<{ position: Vector3 | null | undefined; - resolution: Vector3 | null | undefined; + mag: Vector3 | null | undefined; }> { - const { position, resolution } = await doWithToken((token) => + const { position, mag } = await doWithToken((token) => Request.receiveJSON( `${datastoreUrl}/data/datasets/${datasetId.owningOrganization}/${datasetId.name}/layers/${layerName}/findData?token=${token}`, ), ); return { position, - resolution, + mag, }; } @@ -1564,14 +1564,14 @@ export async function findDataPositionForVolumeTracing( tracingId: string, ): Promise<{ position: Vector3 | null | undefined; - resolution: Vector3 | null | undefined; + mag: Vector3 | null | undefined; }> { - const { position, resolution } = await doWithToken((token) => + const { position, mag } = await doWithToken((token) => Request.receiveJSON(`${tracingstoreUrl}/tracings/volume/${tracingId}/findData?token=${token}`), ); return { position, - resolution, + mag, }; } diff --git a/frontend/javascripts/oxalis/view/left-border-tabs/layer_settings_tab.tsx b/frontend/javascripts/oxalis/view/left-border-tabs/layer_settings_tab.tsx index 2a3a4b3fe9..2be4d24b40 100644 --- a/frontend/javascripts/oxalis/view/left-border-tabs/layer_settings_tab.tsx +++ b/frontend/javascripts/oxalis/view/left-border-tabs/layer_settings_tab.tsx @@ -1026,32 +1026,32 @@ class DatasetSettings extends React.PureComponent { const { tracingStore } = Store.getState().tracing; const { dataset } = this.props; let foundPosition; - let foundResolution; + let foundMag; if (volume && !isDataLayer) { - const { position, resolution } = await findDataPositionForVolumeTracing( + const { position, mag } = await findDataPositionForVolumeTracing( tracingStore.url, volume.tracingId, ); - if ((!position || !resolution) && volume.fallbackLayer) { + if ((!position || !mag) && volume.fallbackLayer) { await this.handleFindData(volume.fallbackLayer, true, volume); return; } foundPosition = position; - foundResolution = resolution; + foundMag = mag; } else { - const { position, resolution } = await findDataPositionForLayer( + const { position, mag } = await findDataPositionForLayer( dataset.dataStore.url, dataset, layerName, ); foundPosition = position; - foundResolution = resolution; + foundMag = mag; } - if (foundPosition && foundResolution) { + if (foundPosition && foundMag) { const layer = getLayerByName(dataset, layerName, true); const transformMatrix = getTransformsForLayerOrNull( dataset, @@ -1073,7 +1073,7 @@ class DatasetSettings extends React.PureComponent { } this.props.onSetPosition(foundPosition); - const zoomValue = this.props.onZoomToMag(layerName, foundResolution); + const zoomValue = this.props.onZoomToMag(layerName, foundMag); Toast.success( `Jumping to position ${foundPosition .map((el) => Math.floor(el)) diff --git a/webknossos-datastore/app/com/scalableminds/webknossos/datastore/services/AdHocMeshService.scala b/webknossos-datastore/app/com/scalableminds/webknossos/datastore/services/AdHocMeshService.scala index 2529af2e31..c51b25e7bb 100644 --- a/webknossos-datastore/app/com/scalableminds/webknossos/datastore/services/AdHocMeshService.scala +++ b/webknossos-datastore/app/com/scalableminds/webknossos/datastore/services/AdHocMeshService.scala @@ -133,20 +133,20 @@ class AdHocMeshService(binaryDataService: BinaryDataService, dstArray } - def subVolumeContainsSegmentId[T](data: Array[T], - dataDimensions: Vec3Int, - boundingBox: BoundingBox, - segmentId: T): Boolean = { - for { - x <- boundingBox.topLeft.x until boundingBox.bottomRight.x - y <- boundingBox.topLeft.y until boundingBox.bottomRight.y - z <- boundingBox.topLeft.z until boundingBox.bottomRight.z - } { - val voxelOffset = x + y * dataDimensions.x + z * dataDimensions.x * dataDimensions.y - if (data(voxelOffset) == segmentId) return true + def subVolumeContainsSegmentId[T]( + data: Array[T], + dataDimensions: Vec3Int, + boundingBox: BoundingBox, + segmentId: T + ): Boolean = + boundingBox.topLeft.x until boundingBox.bottomRight.x exists { x => + boundingBox.topLeft.y until boundingBox.bottomRight.y exists { y => + boundingBox.topLeft.z until boundingBox.bottomRight.z exists { z => + val voxelOffset = x + y * dataDimensions.x + z * dataDimensions.x * dataDimensions.y + data(voxelOffset) == segmentId + } + } } - false - } def findNeighbors[T](data: Array[T], dataDimensions: Vec3Int, segmentId: T): List[Int] = { val x = dataDimensions.x - 1 diff --git a/webknossos-datastore/app/com/scalableminds/webknossos/datastore/services/DataFinder.scala b/webknossos-datastore/app/com/scalableminds/webknossos/datastore/services/DataFinder.scala index 122cb400cc..d58644b349 100644 --- a/webknossos-datastore/app/com/scalableminds/webknossos/datastore/services/DataFinder.scala +++ b/webknossos-datastore/app/com/scalableminds/webknossos/datastore/services/DataFinder.scala @@ -6,18 +6,22 @@ import com.scalableminds.webknossos.datastore.models.datasource.DataLayer trait DataFinder { private def getExactDataOffset(data: Array[Byte], bytesPerElement: Int): Vec3Int = { val bucketLength = DataLayer.bucketLength - for { - z <- 0 until bucketLength - y <- 0 until bucketLength - x <- 0 until bucketLength - scaledX = x * bytesPerElement - scaledY = y * bytesPerElement * bucketLength - scaledZ = z * bytesPerElement * bucketLength * bucketLength - } { - val voxelOffset = scaledX + scaledY + scaledZ - if (data.slice(voxelOffset, voxelOffset + bytesPerElement).exists(_ != 0)) return Vec3Int(x, y, z) - } - Vec3Int.zeros + + Iterator + .tabulate(bucketLength, bucketLength, bucketLength) { (z, y, x) => + val scaledX = x * bytesPerElement + val scaledY = y * bytesPerElement * bucketLength + val scaledZ = z * bytesPerElement * bucketLength * bucketLength + val voxelOffset = scaledX + scaledY + scaledZ + (x, y, z, voxelOffset) + } + .flatten + .flatten + .collectFirst { + case (x, y, z, voxelOffset) if data.slice(voxelOffset, voxelOffset + bytesPerElement).exists(_ != 0) => + Vec3Int(x, y, z) + } + .getOrElse(Vec3Int.zeros) } def getPositionOfNonZeroData(data: Array[Byte], diff --git a/webknossos-datastore/app/com/scalableminds/webknossos/datastore/storage/CumsumParser.scala b/webknossos-datastore/app/com/scalableminds/webknossos/datastore/storage/CumsumParser.scala index 3a6be61089..0e61b074f1 100644 --- a/webknossos-datastore/app/com/scalableminds/webknossos/datastore/storage/CumsumParser.scala +++ b/webknossos-datastore/app/com/scalableminds/webknossos/datastore/storage/CumsumParser.scala @@ -48,16 +48,16 @@ object CumsumParser extends LazyLogging { jsonReader.endObject() if (!correctOrder) { - r.close() - return parseImpl(f, maxReaderRange, boundingBoxList, start) - } + parseImpl(f, maxReaderRange, boundingBoxList, start) + } else { - val end = System.currentTimeMillis() - logger.info(s"Cumsum parsing took ${end - start} ms") + val end = System.currentTimeMillis() + logger.info(s"Cumsum parsing took ${end - start} ms") - new BoundingBoxCache(cache, - BoundingBoxFinder(positionSets._1, positionSets._2, positionSets._3, minBoundingBox), - maxReaderRange) + new BoundingBoxCache(cache, + BoundingBoxFinder(positionSets._1, positionSets._2, positionSets._3, minBoundingBox), + maxReaderRange) + } } catch { case e: JsonParseException => logger.error(s"Parse exception while parsing cumsum: ${e.getMessage}.")