Skip to content

Commit

Permalink
Add coordinate transformation to datalayer not datasource
Browse files Browse the repository at this point in the history
  • Loading branch information
frcroth committed Jul 25, 2023
1 parent 186fd47 commit e1b0a5c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
33 changes: 26 additions & 7 deletions app/models/binary/explore/ExploreRemoteLayerService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ class ExploreRemoteLayerService @Inject()(credentialService: CredentialService,
with LazyLogging {

def exploreRemoteDatasource(
urisWithCredentials: List[ExploreRemoteDatasetParameters],
parameters: List[ExploreRemoteDatasetParameters],
requestIdentity: WkEnv#I,
reportMutable: ListBuffer[String])(implicit ec: ExecutionContext): Fox[GenericDataSource[DataLayer]] =
for {
exploredLayersNested <- Fox.serialCombined(urisWithCredentials)(
exploredLayersNested <- Fox.serialCombined(parameters)(
parameters =>
exploreRemoteLayersForUri(parameters.remoteUri,
parameters.credentialIdentifier,
Expand All @@ -61,13 +61,14 @@ class ExploreRemoteLayerService @Inject()(credentialService: CredentialService,
rescaledLayers = rescaledLayersAndVoxelSize._1
voxelSize = rescaledLayersAndVoxelSize._2
renamedLayers = makeLayerNamesUnique(rescaledLayers)
preferredVoxelSize = urisWithCredentials.flatMap(_.preferredVoxelSize).headOption
coordinateTransformations = coordinateTransformationForVoxelSize(voxelSize, preferredVoxelSize)
preferredVoxelSize = parameters.flatMap(_.preferredVoxelSize).headOption
layersWithCoordinateTransformations = addCoordinateTransformationsToLayers(renamedLayers,
preferredVoxelSize,
voxelSize)
dataSource = GenericDataSource[DataLayer](
DataSourceId("", ""), // Frontend will prompt user for a good name
renamedLayers,
voxelSize,
coordinateTransformations = coordinateTransformations
layersWithCoordinateTransformations,
voxelSize
)
} yield dataSource

Expand All @@ -94,6 +95,24 @@ class ExploreRemoteLayerService @Inject()(credentialService: CredentialService,
}
}

private def addCoordinateTransformationsToLayers(layers: List[DataLayer],
preferredVoxelSize: Option[Array[Double]],
voxelSize: Vec3Double): List[DataLayer] =
layers.map(l => {
val coordinateTransformations = coordinateTransformationForVoxelSize(voxelSize, preferredVoxelSize)
l match {
case l: ZarrDataLayer => l.copy(coordinateTransformations = coordinateTransformations)
case l: ZarrSegmentationLayer => l.copy(coordinateTransformations = coordinateTransformations)
case l: N5DataLayer => l.copy(coordinateTransformations = coordinateTransformations)
case l: N5SegmentationLayer => l.copy(coordinateTransformations = coordinateTransformations)
case l: PrecomputedDataLayer => l.copy(coordinateTransformations = coordinateTransformations)
case l: PrecomputedSegmentationLayer => l.copy(coordinateTransformations = coordinateTransformations)
case l: Zarr3DataLayer => l.copy(coordinateTransformations = coordinateTransformations)
case l: Zarr3SegmentationLayer => l.copy(coordinateTransformations = coordinateTransformations)
case _ => throw new Exception("Encountered unsupported layer format during explore remote")
}
})

private def magFromVoxelSize(minVoxelSize: Vec3Double, voxelSize: Vec3Double)(
implicit ec: ExecutionContext): Fox[Vec3Int] = {
def isPowerOfTwo(x: Int): Boolean =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ package object datasource {
case class GenericDataSource[+T <: DataLayerLike](id: DataSourceId,
dataLayers: List[T],
scale: Vec3Double,
defaultViewConfiguration: Option[DataSetViewConfiguration] = None,
coordinateTransformations: Option[List[CoordinateTransformation]] =
None)
defaultViewConfiguration: Option[DataSetViewConfiguration] = None)
extends GenericInboxDataSource[T] {

val toUsable: Option[GenericDataSource[T]] = Some(this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ package object inbox {
def statusOpt: Option[String]

def defaultViewConfiguration: Option[DataSetViewConfiguration]

def coordinateTransformations: Option[List[CoordinateTransformation]]
}

object GenericInboxDataSource {
Expand Down Expand Up @@ -49,8 +47,6 @@ package object inbox {
val statusOpt: Option[String] = Some(status)

val defaultViewConfiguration: Option[DataSetViewConfiguration] = None

val coordinateTransformations: Option[List[CoordinateTransformation]] = None
}

object UnusableDataSource {
Expand Down

0 comments on commit e1b0a5c

Please sign in to comment.