-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement viewing sharded neuroglancer precomputed datasets (#6920)
- Loading branch information
Showing
14 changed files
with
318 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package backend | ||
|
||
import com.scalableminds.webknossos.datastore.datareaders.precomputed.CompressedMortonCode | ||
import org.scalatestplus.play.PlaySpec | ||
|
||
class CompressedMortonCodeTestSuite extends PlaySpec { | ||
|
||
"Compressed Morton Code" when { | ||
"Grid size = 10,10,10" should { | ||
val grid_size = Array(10, 10, 10) | ||
"encode 0,0,0" in { | ||
assert(CompressedMortonCode.encode(Array(0, 0, 0), grid_size) == 0) | ||
} | ||
"encode 1,2,3" in { | ||
assert(CompressedMortonCode.encode(Array(1, 2, 3), grid_size) == 53) | ||
} | ||
"encode 9,9,9" in { | ||
assert(CompressedMortonCode.encode(Array(9, 9, 9), grid_size) == 3591) | ||
} | ||
"encode 10,10,10" in { | ||
assert(CompressedMortonCode.encode(Array(10, 10, 10), grid_size) == 3640) | ||
} | ||
} | ||
"Grid size = 2048,2048,1024" should { | ||
val grid_size = Array(2048, 2048, 1024) | ||
"encode 0,0,0" in { | ||
assert(CompressedMortonCode.encode(Array(0, 0, 0), grid_size) == 0) | ||
} | ||
"encode 1,2,3" in { | ||
assert(CompressedMortonCode.encode(Array(1, 2, 3), grid_size) == 53) | ||
} | ||
"encode 1024, 512, 684" in { | ||
assert(CompressedMortonCode.encode(Array(1024, 512, 684), grid_size) == 1887570176) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...com/scalableminds/webknossos/datastore/datareaders/precomputed/CompressedMortonCode.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.scalableminds.webknossos.datastore.datareaders.precomputed | ||
|
||
import scala.math.log10 | ||
|
||
object CompressedMortonCode { | ||
|
||
def log2(x: Double): Double = log10(x) / log10(2.0) | ||
|
||
def encode(position: Array[Int], gridSize: Array[Int]): Long = { | ||
/* | ||
Computes the compressed morton code as per | ||
https://github.com/google/neuroglancer/blob/master/src/neuroglancer/datasource/precomputed/volume.md#compressed-morton-code | ||
https://github.com/google/neuroglancer/blob/162b698f703c86e0b3e92b8d8e0cacb0d3b098df/src/neuroglancer/util/zorder.ts#L72 | ||
*/ | ||
val bits = gridSize.map(log2(_).ceil.toInt) | ||
val maxBits = bits.max | ||
var outputBit = 0L | ||
val one = 1L | ||
|
||
var output = 0L | ||
for (bit <- 0 to maxBits) { | ||
if (bit < bits(0)) { | ||
output |= (((position(0) >> bit) & one) << outputBit) | ||
outputBit += 1 | ||
} | ||
if (bit < bits(1)) { | ||
output |= (((position(1) >> bit) & one) << outputBit) | ||
outputBit += 1 | ||
} | ||
if (bit < bits(2)) { | ||
output |= (((position(2) >> bit) & one) << outputBit) | ||
outputBit += 1 | ||
} | ||
} | ||
|
||
output | ||
} | ||
|
||
} |
Oops, something went wrong.