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

Ensure that extra buckets and fallback buckets are loaded with lower priority #2724

Merged
merged 2 commits into from
Jun 21, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -112,29 +112,32 @@ function addNecessaryBucketsToPriorityQueueOrthogonal(

// Build up priority queue
wSliceOffsets.forEach(wSliceOffset => {
for (
let y = scaledTopLeftVector[v] - extraBucket;
y <= scaledBottomRightVector[v] + extraBucket;
y++
) {
for (
let x = scaledTopLeftVector[u] - extraBucket;
x <= scaledBottomRightVector[u] + extraBucket;
x++
) {
const extraYBucketStart = scaledTopLeftVector[v] - extraBucket;
const extraYBucketEnd = scaledBottomRightVector[v] + extraBucket;
const extraXBucketStart = scaledTopLeftVector[u] - extraBucket;
const extraXBucketEnd = scaledBottomRightVector[u] + extraBucket;

for (let y = extraYBucketStart; y <= extraYBucketEnd; y++) {
for (let x = extraXBucketStart; x <= extraXBucketEnd; x++) {
const bucketAddress = ((topLeftBucket.slice(): any): Vector4);
bucketAddress[u] = x;
bucketAddress[v] = y;
bucketAddress[w] += wSliceOffset;

const bucket = binary.cube.getOrCreateBucket(bucketAddress);
const isExtraBucket =
Copy link
Member Author

Choose a reason for hiding this comment

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

I can't think of a more elegant way to express the logic for the "extra" bucket (better naming needed, too ^^).

Copy link
Member

Choose a reason for hiding this comment

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

What do you think about simply using the Chebyshev distance instead of the manhattan distance to assign priorities for the priority queue? I feel like this would reduce complexity and avoid the need to take special care of the "extra" buckets :)

Copy link
Member Author

Choose a reason for hiding this comment

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

That would indeed solve the problem. However, we would change the loading behavior (from the user's point of view) quite a bit 🤔 Not sure whether that's ok..

Copy link
Member

Choose a reason for hiding this comment

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

I can't remember what the conclusion of our discussion about this yesterday was 🙈

Copy link
Member Author

Choose a reason for hiding this comment

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

I think we said that the priority here doesn't really matter as the ping strategy takes precedence, anyway. However, it's good to leave this edge case in the code because the code might make the ping strategy obsolete at some point (and then it's important). I wouldn't switch to chebyshev without having the approval from the lab..

y === extraYBucketStart ||
y === extraYBucketEnd ||
x === extraXBucketStart ||
x === extraXBucketEnd;

if (bucket.type !== "null") {
const priority =
Math.abs(x - centerBucketUV[0]) +
Math.abs(y - centerBucketUV[1]) +
Math.abs(100 * wSliceOffset) +
additionalPriorityWeight;
additionalPriorityWeight +
(isExtraBucket ? 100 : 0);
bucketQueue.queue({
priority,
bucket,
Expand Down
8 changes: 7 additions & 1 deletion app/assets/javascripts/oxalis/model/binary/ping_strategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export class PingStrategy extends AbstractPingStrategy {
zoomStepDiff,
activePlane,
areas,
false,
);

let queueItemsForFallbackZoomStep = [];
Expand All @@ -100,6 +101,7 @@ export class PingStrategy extends AbstractPingStrategy {
zoomStepDiff - 1,
activePlane,
areas,
true,
);
}

Expand All @@ -113,6 +115,7 @@ export class PingStrategy extends AbstractPingStrategy {
zoomStepDiff: number,
activePlane: OrthoViewType,
areas: OrthoViewMapType<AreaType>,
isFallback: boolean,
): Array<PullQueueItemType> {
const pullQueue = [];

Expand All @@ -123,6 +126,8 @@ export class PingStrategy extends AbstractPingStrategy {
const centerBucket = this.cube.positionToZoomedAddress(position, zoomStep);
const centerBucket3 = [centerBucket[0], centerBucket[1], centerBucket[2]];

const fallbackPriorityWeight = isFallback ? 50 : 0;

for (const plane of OrthoViewValuesWithoutTDView) {
const [u, v, w] = Dimensions.getIndices(plane);
this.u = u;
Expand Down Expand Up @@ -150,7 +155,8 @@ export class PingStrategy extends AbstractPingStrategy {
const priority =
Math.abs(bucket[0] - centerBucket3[0]) +
Math.abs(bucket[1] - centerBucket3[1]) +
Math.abs(bucket[2] - centerBucket3[2]);
Math.abs(bucket[2] - centerBucket3[2]) +
fallbackPriorityWeight;
pullQueue.push({ bucket: [bucket[0], bucket[1], bucket[2], zoomStep], priority });
if (plane === activePlane) {
// preload only for active plane
Expand Down