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

Fix volume tasks from file without specified Bbox #5362

Merged
merged 3 commits into from
Apr 7, 2021
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
1 change: 1 addition & 0 deletions CHANGELOG.unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ For upgrade instructions, please check the [migration guide](MIGRATIONS.released
### Fixed
- Fixed a bug where some values in the project list were displayed incorrectly after pausing/unpausing the project. [#5339](https://github.com/scalableminds/webknossos/pull/5339)
- Fixed that editing a task type would always re-add the default values to the recommended configuration (if enabled). [#5341](https://github.com/scalableminds/webknossos/pull/5341)
- Fixed a bug where tasks created from existing volume annotations that did not have a specified bounding box were broken. [#5362](https://github.com/scalableminds/webknossos/pull/5361)

### Removed
-
Expand Down
5 changes: 3 additions & 2 deletions app/controllers/TaskController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ class TaskController @Inject()(taskCreationService: TaskCreationService,
extractedFiles = nmlService.extractFromFiles(inputFiles.map(f => (f.ref.path.toFile, f.filename)),
useZipName = false,
isTaskUpload = true)
extractedTracingBoxes: List[TracingBoxContainer] = extractedFiles.toBoxes
extractedTracingBoxesRaw: List[TracingBoxContainer] = extractedFiles.toBoxes
extractedTracingBoxes: List[TracingBoxContainer] <- taskCreationService
.addVolumeFallbackBoundingBoxes(extractedTracingBoxesRaw, request.identity._organization)
fullParams: List[Box[TaskParameters]] = taskCreationService.buildFullParamsFromFiles(params,
extractedTracingBoxes)
(skeletonBases, volumeBases) <- taskCreationService.fillInMissingTracings(extractedTracingBoxes.map(_.skeleton),
Expand All @@ -93,7 +95,6 @@ class TaskController @Inject()(taskCreationService: TaskCreationService,
result <- taskCreationService.createTasks(fullParamsWithTracings, request.identity)
} yield Ok(Json.toJson(result))
}

def update(taskId: String): Action[TaskParameters] = sil.SecuredAction.async(validateJson[TaskParameters]) {
implicit request =>
val params = request.body
Expand Down
26 changes: 24 additions & 2 deletions app/models/task/TaskCreationService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package models.task

import java.io.File

import com.scalableminds.util.accesscontext.DBAccessContext
import com.scalableminds.util.accesscontext.{DBAccessContext, GlobalAccessContext}
import com.scalableminds.util.geometry.{BoundingBox, Point3D, Vector3D}
import com.scalableminds.util.tools.{Fox, FoxImplicits}
import com.scalableminds.webknossos.datastore.SkeletonTracing.{SkeletonTracing, SkeletonTracingOpt, SkeletonTracings}
Expand All @@ -21,7 +21,7 @@ import models.annotation.{
TracingStoreRpcClient,
TracingStoreService
}
import models.binary.{DataSet, DataSetDAO}
import models.binary.{DataSet, DataSetDAO, DataSetService}
import models.project.{Project, ProjectDAO}
import models.team.{Team, TeamDAO}
import models.user.{User, UserExperiencesDAO, UserService, UserTeamRolesDAO}
Expand All @@ -47,6 +47,7 @@ class TaskCreationService @Inject()(taskTypeService: TaskTypeService,
userExperiencesDAO: UserExperiencesDAO,
scriptDAO: ScriptDAO,
dataSetDAO: DataSetDAO,
dataSetService: DataSetService,
tracingStoreService: TracingStoreService,
)(implicit ec: ExecutionContext)
extends FoxImplicits
Expand Down Expand Up @@ -212,6 +213,27 @@ class TaskCreationService @Inject()(taskTypeService: TaskTypeService,
boxContainer.description)
}

// Used in createFromFiles. For all volume tracings that have an empty bounding box, reset it to the dataset bounding box
def addVolumeFallbackBoundingBoxes(tracingBoxes: List[TracingBoxContainer],
organizationId: ObjectId): Fox[List[TracingBoxContainer]] =
Fox.serialCombined(tracingBoxes) { tracingBox: TracingBoxContainer =>
tracingBox.volume match {
case Full(v) =>
for { volumeAdapted <- addVolumeFallbackBoundingBox(v._1, organizationId) } yield
tracingBox.copy(volume = Full(volumeAdapted, v._2))
case _ => Fox.successful(tracingBox)
}
}

// Used in createFromFiles. Called once per requested task if volume tracing is passed
private def addVolumeFallbackBoundingBox(volume: VolumeTracing, organizationId: ObjectId): Fox[VolumeTracing] =
if (volume.boundingBox.isEmpty) {
for {
dataSet <- dataSetDAO.findOneByNameAndOrganization(volume.dataSetName, organizationId)(GlobalAccessContext)
dataSource <- dataSetService.dataSourceFor(dataSet).flatMap(_.toUsable)
} yield volume.copy(boundingBox = dataSource.boundingBox)
} else Fox.successful(volume)

// Used in createFromFiles. Called once per requested task
private def buildFullParamsFromFilesForSingleTask(
nmlFormParams: NmlTaskParameters,
Expand Down