Skip to content

Commit

Permalink
Remove explicit returns (#8205)
Browse files Browse the repository at this point in the history
  • Loading branch information
frcroth authored Nov 20, 2024
1 parent a8fe8b7 commit 3c7700c
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 47 deletions.
12 changes: 6 additions & 6 deletions frontend/javascripts/admin/admin_rest_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
}

Expand All @@ -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,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1026,32 +1026,32 @@ class DatasetSettings extends React.PureComponent<DatasetSettingsProps, State> {
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,
Expand All @@ -1073,7 +1073,7 @@ class DatasetSettings extends React.PureComponent<DatasetSettingsProps, State> {
}

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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}.")
Expand Down

0 comments on commit 3c7700c

Please sign in to comment.