Skip to content

Commit 1c737d0

Browse files
authored
Densify tree ids when merging skeletons (#8643)
* Densify tree ids when merging skeletons * changelog
1 parent 736c9ef commit 1c737d0

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

CHANGELOG.unreleased.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ For upgrade instructions, please check the [migration guide](MIGRATIONS.released
4141
- Fixed a rare bug where segment bounding box would not be displayed correctly, with the request potentially even crashing the server. [#8590](https://github.com/scalableminds/webknossos/pull/8590)
4242
- Fixed a rare bug where download requests would terminate without sending the whole annotation. [#8624](https://github.com/scalableminds/webknossos/pull/8624)
4343
- Fixed that deletion of dataset would lead to an error. [#8639](https://github.com/scalableminds/webknossos/pull/8639)
44+
- Fixed a bug where merging annotations with large tree IDs could lead to an error. [#8643](https://github.com/scalableminds/webknossos/pull/8643)
4445

4546
### Removed
4647
- The old "Selective Segment Visibility" feature that allowed to only see the active and the hovered segment was removed. From now on the visibility of segments can be controlled with checkboxes in the segment list and with the "Hide unlisted segments" toggle in the layer settings. [#8546](https://github.com/scalableminds/webknossos/pull/8546)

webknossos-tracingstore/app/com/scalableminds/webknossos/tracingstore/tracings/skeleton/TreeUtils.scala

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,27 @@ object TreeUtils {
3333
else
3434
trees.map(_.treeId).max
3535

36+
private def densifyTreeIds(trees: Seq[Tree]): Seq[Tree] =
37+
trees.sortBy(_.treeId).zipWithIndex.map {
38+
case (tree, index) => tree.withTreeId(index + 1)
39+
}
40+
3641
def mergeTrees(sourceTrees: Seq[Tree],
3742
targetTrees: Seq[Tree],
3843
nodeMapping: FunctionalNodeMapping,
3944
groupMapping: FunctionalGroupMapping): Seq[Tree] = {
40-
val treeMaxId = maxTreeId(targetTrees)
45+
val targetTreesDensified = densifyTreeIds(targetTrees)
46+
val sourceTreesDensified = densifyTreeIds(sourceTrees)
47+
val treeMaxId = maxTreeId(targetTreesDensified)
4148

42-
val sourceNodeIds: Set[Int] = sourceTrees.flatMap(_.nodes.map(_.id)).toSet
49+
val sourceNodeIds: Set[Int] = sourceTreesDensified.flatMap(_.nodes.map(_.id)).toSet
4350

44-
val mappedSourceTrees = sourceTrees.map(
51+
val mappedSourceTrees = sourceTreesDensified.map(
4552
tree =>
4653
applyNodeMapping(tree.withTreeId(tree.treeId + treeMaxId), nodeMapping, sourceNodeIds)
4754
.copy(groupId = tree.groupId.map(groupMapping(_))))
4855

49-
targetTrees ++ mappedSourceTrees
56+
targetTreesDensified ++ mappedSourceTrees
5057
}
5158

5259
private def applyNodeMapping(tree: Tree, f: Int => Int, sourceNodeIds: Set[Int]) =

0 commit comments

Comments
 (0)