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}.")