Skip to content

Commit

Permalink
Validate animation job bounding box (#7883)
Browse files Browse the repository at this point in the history
* validate BB size to be larger then 0

* changelog

* appy PR feedback
  • Loading branch information
hotzenklotz authored and MichaelBuessemeyer committed Jun 17, 2024
1 parent 5bb3997 commit 1797a4e
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ For upgrade instructions, please check the [migration guide](MIGRATIONS.released
- When downloading + reuploading an annotation that is based on a segmentation layer with active mapping, that mapping is now still be selected after the reupload. [#7822](https://github.com/scalableminds/webknossos/pull/7822)
- In the Voxelytics workflow list, the name of the WEBKNOSSOS user who started the job is displayed. [#7794](https://github.com/scalableminds/webknossos/pull/7795)
- Start an alignment job (aligns the section in a dataset) via the "AI Analysis" button. [#7820](https://github.com/scalableminds/webknossos/pull/7820)
- Added additional validation for the animation job modal. Bounding boxes must be larger then zero. [#7883](https://github.com/scalableminds/webknossos/pull/7883)

### Changed
- The "WEBKNOSSOS Changelog" modal now lazily loads its content potentially speeding up the initial loading time of WEBKNOSSOS and thus improving the UX. [#7843](https://github.com/scalableminds/webknossos/pull/7843)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {
PricingPlanEnum,
isFeatureAllowedByPricingPlan,
} from "admin/organization/pricing_plan_utils";
import { BoundingBoxType, Vector3 } from "oxalis/constants";
import { Vector3 } from "oxalis/constants";
import BoundingBox from "oxalis/model/bucket_data_handling/bounding_box";
import { BoundingBoxSelection } from "./starting_job_modals";
import { LayerSelection } from "components/layer_selection";
Expand All @@ -50,17 +50,13 @@ const MAX_MESHES_PER_ANIMATION = 40; // arbitrary limit to not overload the serv

function selectMagForTextureCreation(
colorLayer: APIDataLayer,
boundingBox: BoundingBoxType,
boundingBox: BoundingBox,
): [Vector3, number] {
// Utility method to determine the best mag in relation to the dataset size to create the textures in the worker job
// We aim to create textures with a rough length/height of 2000px (aka target_video_frame_size)
const colorLayerBB = new BoundingBox(
computeBoundingBoxFromBoundingBoxObject(colorLayer.boundingBox),
);
const bb = new BoundingBox(boundingBox).intersectedWith(colorLayerBB);

const longestSide = Math.max(...bb.getSize());
const dimensionLongestSide = bb.getSize().indexOf(longestSide);
const longestSide = Math.max(...boundingBox.getSize());
const dimensionLongestSide = boundingBox.getSize().indexOf(longestSide);

let bestMag = colorLayer.resolutions[0];
let bestDifference = Infinity;
Expand Down Expand Up @@ -137,15 +133,16 @@ function CreateAnimationModal(props: Props) {

const validateAnimationOptions = (
colorLayer: APIDataLayer,
selectedBoundingBox: BoundingBoxType,
selectedBoundingBox: BoundingBox,
renderingBoundingBox: BoundingBox,
meshes: Partial<MeshInformation>[],
) => {
// Validate the select parameters and dataset to make sure it actually works and does not overload the server

const state = Store.getState();
const errorMessages: string[] = [];

const [_, estimatedTextureSize] = selectMagForTextureCreation(colorLayer, selectedBoundingBox);
const [_, estimatedTextureSize] = selectMagForTextureCreation(colorLayer, renderingBoundingBox);

const hasEnoughMags = estimatedTextureSize < 1.5 * TARGET_TEXTURE_SIZE;
if (!hasEnoughMags)
Expand All @@ -167,7 +164,25 @@ function CreateAnimationModal(props: Props) {
`You selected too many meshes for the animation. Please keep the number of meshes below ${MAX_MESHES_PER_ANIMATION} to create an animation.`,
);

const validationStatus = hasEnoughMags && isDtypeSupported && isDataset3D && !isTooManyMeshes;
const isBoundingBoxEmpty = selectedBoundingBox.getVolume() === 0;
if (isBoundingBoxEmpty)
errorMessages.push(
"Please select a bounding box that is not empty. Width, height, and depth of the bounding box must be larger than zero.",
);

const isRenderingBoundingBoxEmpty = renderingBoundingBox.getVolume() === 0;
if (isRenderingBoundingBoxEmpty && !isBoundingBoxEmpty)
errorMessages.push(
"Your selected bounding box is located outside the dataset's volume. Please select a bounding box contained within the dataset's outer bounds.",
);

const validationStatus =
hasEnoughMags &&
isDtypeSupported &&
isDataset3D &&
!isTooManyMeshes &&
!isBoundingBoxEmpty &&
!isRenderingBoundingBoxEmpty;

setValidationErrors(errorMessages);
setIsValid(validationStatus);
Expand Down Expand Up @@ -216,7 +231,14 @@ function CreateAnimationModal(props: Props) {
state.datasetConfiguration,
);

const [magForTextures, _] = selectMagForTextureCreation(colorLayer, boundingBox);
// the actual rendering bounding box in Blender is the intersection of the selected user bounding box and the color layer's outer bounds
const colorLayerBB = new BoundingBox(
computeBoundingBoxFromBoundingBoxObject(selectedColorLayer.boundingBox),
);
const selectedBoundingBox = new BoundingBox(boundingBox);
const renderingBoundingBox = selectedBoundingBox.intersectedWith(colorLayerBB);

const [magForTextures, _] = selectMagForTextureCreation(colorLayer, renderingBoundingBox);

const animationOptions: RenderAnimationOptions = {
layerName: selectedColorLayerName,
Expand All @@ -230,7 +252,15 @@ function CreateAnimationModal(props: Props) {
cameraPosition: selectedCameraPosition,
};

if (!validateAnimationOptions(selectedColorLayer, boundingBox, meshes)) return;
if (
!validateAnimationOptions(
selectedColorLayer,
selectedBoundingBox,
renderingBoundingBox,
meshes,
)
)
return;

startRenderAnimationJob(state.dataset.owningOrganization, state.dataset.name, animationOptions);

Expand Down

0 comments on commit 1797a4e

Please sign in to comment.