Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add route to add segment index to existing volume annotations #7208

Merged
merged 4 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions app/controllers/AnnotationController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,20 @@ class AnnotationController @Inject()(
} yield result
}

@ApiOperation(hidden = true, value = "")
def addSegmentIndex(id: String, tracingId: String): Action[AnyContent] = sil.SecuredAction.async { implicit request =>
for {
annotation <- provider.provideAnnotation(id, request.identity)
_ <- bool2Fox(AnnotationType.Explorational == annotation.typ) ?~> "annotation.addSegmentIndex.explorationalsOnly"
annotationLayer <- annotation.annotationLayers
.find(_.tracingId == tracingId)
.toFox ?~> "annotation.addSegmentIndex.layerNotFound"
_ <- annotationService.addSegmentIndex(annotation, annotationLayer) ?~> "annotation.addSegmentIndex.failed"
updated <- provider.provideAnnotation(id, request.identity)
json <- annotationService.publicWrites(updated, Some(request.identity)) ?~> "annotation.write.failed"
} yield JsonOk(json)
}

private def finishAnnotation(typ: String, id: String, issuingUser: User, timestamp: Instant)(
implicit ctx: DBAccessContext): Fox[(Annotation, String)] =
for {
Expand Down
15 changes: 14 additions & 1 deletion app/models/annotation/AnnotationService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -393,14 +393,27 @@ class AnnotationService @Inject()(
implicit ctx: DBAccessContext): Fox[Unit] =
for {
dataSet <- dataSetDAO.findOne(annotation._dataSet) ?~> "dataSet.notFoundForAnnotation"
_ <- bool2Fox(annotation.volumeAnnotationLayers.nonEmpty) ?~> "annotation.downsample.volumeOnly"
_ <- bool2Fox(volumeAnnotationLayer.typ == AnnotationLayerType.Volume) ?~> "annotation.downsample.volumeOnly"
rpcClient <- tracingStoreService.clientFor(dataSet)
newVolumeTracingId <- rpcClient.duplicateVolumeTracing(volumeAnnotationLayer.tracingId, downsample = true)
_ = logger.info(
s"Replacing volume tracing ${volumeAnnotationLayer.tracingId} by downsampled copy $newVolumeTracingId for annotation ${annotation._id}.")
_ <- annotationLayersDAO.replaceTracingId(annotation._id, volumeAnnotationLayer.tracingId, newVolumeTracingId)
} yield ()

def addSegmentIndex(annotation: Annotation, volumeAnnotationLayer: AnnotationLayer)(
implicit ctx: DBAccessContext): Fox[Unit] =
for {
dataSet <- dataSetDAO.findOne(annotation._dataSet) ?~> "dataSet.notFoundForAnnotation"
_ <- bool2Fox(volumeAnnotationLayer.typ == AnnotationLayerType.Volume) ?~> "annotation.downsample.volumeOnly"
rpcClient <- tracingStoreService.clientFor(dataSet)
// duplicate in tracingstore will add segment index if possible
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you point me to where that happens? Didn't immediately see it in VolumeTracingController.duplicate

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hasSegmentIndex = VolumeSegmentIndexService.canHaveSegmentIndex(tracingWithResolutionRestrictions.fallbackLayer)

in combination with

Not sure how to make this more discoverable. Hence the comment here

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess line 361 in VolumeTracingService is the surprising one, so there could be a comment there "Adding segment index on duplication if the volume tracing allows it" or something like that.

newVolumeTracingId <- rpcClient.duplicateVolumeTracing(volumeAnnotationLayer.tracingId)
_ = logger.info(
s"Replacing volume tracing ${volumeAnnotationLayer.tracingId} by copy with added segment index $newVolumeTracingId for annotation ${annotation._id}.")
_ <- annotationLayersDAO.replaceTracingId(annotation._id, volumeAnnotationLayer.tracingId, newVolumeTracingId)
} yield ()

// WARNING: needs to be repeatable, might be called multiple times for an annotation
def finish(annotation: Annotation, user: User, restrictions: AnnotationRestrictions)(
implicit ctx: DBAccessContext): Fox[String] = {
Expand Down
8 changes: 6 additions & 2 deletions conf/messages
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,17 @@ annotation.transferee.noDataSetAccess=Cannot transfer annotation to a user who h
annotation.timelogging.read.failed=Time
annotation.write.failed=Could not convert annotation to json
annotation.needsEitherSkeletonOrVolume=Annotation needs at least one of skeleton or volume
annotation.downsample.layerNotFound=Could not downsample volume annotation (annotation layer not found)
annotation.addLayer.explorationalsOnly=Could not add annotation layer because it is only allowed for explorational annotations.
annotation.addLayer.nameInUse=An annotation layer with this name already exists in this annotation. Please change it to prevent duplicates.
annotation.makeHybrid.failed=Could not convert annotation to hybrid.
annotation.makeHybrid.alreadyHybrid=Could not convert annotation to hybrid annotation because it is already a hybrid annotation.
annotation.downsample.layerNotFound=Could not downsample volume annotation (annotation layer not found)
annotation.downsample.explorationalsOnly=Could not downsample annotation because it is only allowed for explorational annotations.
annotation.downsample.volumeOnly=Downsampling is only possible for volume or hybrid annotations.
annotation.downsample.volumeOnly=Downsampling is only possible for volume annotation layers.
annotation.addSegmentIndex.layerNotFound=Could not add segment index to volume annotation (annotation layer not found)
annotation.addSegmentIndex.explorationalsOnly=Could not add segment index to annotation because it is only allowed for explorational annotations.
annotation.addSegmentIndex.volumeOnly=Adding segment index is only possible for volume annotation layers.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

annotation.addSegmentIndex.failed is used but does not occur here

annotation.addSegmentIndex.failed=Failed to add segment index.
annotationType.notFound=Could not find the specified annotation type.
annotation.cantMergeVolumes=This annotation collection contains volume tracings. Merging volume tracings is not yet supported. Please use download instead.
annotation.reopen.tooLate=The annotation cannot be reopened anymore, since it has been finished for too long.
Expand Down
1 change: 1 addition & 0 deletions conf/webknossos.latest.routes
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ DELETE /annotations/:id
POST /annotations/:id/merge/:mergedTyp/:mergedId controllers.AnnotationController.mergeWithoutType(id: String, mergedTyp: String, mergedId: String)
GET /annotations/:id/download controllers.AnnotationIOController.downloadWithoutType(id: String, skeletonVersion: Option[Long], volumeVersion: Option[Long], skipVolumeData: Option[Boolean])
POST /annotations/:id/acquireMutex controllers.AnnotationController.tryAcquiringAnnotationMutex(id: String)
PATCH /annotations/:id/addSegmentIndex controllers.AnnotationController.addSegmentIndex(id: String, tracingId: String)

GET /annotations/:typ/:id/info controllers.AnnotationController.info(typ: String, id: String, timestamp: Long)
PATCH /annotations/:typ/:id/makeHybrid controllers.AnnotationController.makeHybrid(typ: String, id: String, fallbackLayerName: Option[String])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ class VolumeTracingService @Inject()(
boundingBox = boundingBoxOptToProto(boundingBox).getOrElse(tracingWithResolutionRestrictions.boundingBox),
mappingName = mappingName.orElse(tracingWithResolutionRestrictions.mappingName),
version = 0,
// Adding segment index on duplication if the volume tracing allows it. This will be used in duplicateData
hasSegmentIndex = VolumeSegmentIndexService.canHaveSegmentIndex(tracingWithResolutionRestrictions.fallbackLayer)
)
for {
Expand Down