Skip to content

Dont brush outside viewport #3283

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

Merged
merged 27 commits into from
Sep 27, 2018
Merged

Conversation

MichaelBuessemeyer
Copy link
Contributor

@MichaelBuessemeyer MichaelBuessemeyer commented Sep 26, 2018

This PR disables drawing out of bounds of a viewport

URL of deployed dev instance (used for testing):

  • https://___.webknossos.xyz

Steps to test:

  • open volumetracing
  • draw with the brush around the boundaries
  • move around to check that drawing stopped when drawing out of bounds
  • there should not be noticeable difference in performance compared to the previous drawing

Issues:


MichaelBuessemeyer and others added 22 commits September 17, 2018 13:08
const zoom = yield* select(state => state.flycam.zoomStep);
const scales = yield* select(state => getBaseVoxelFactors(state.dataset.dataSource.scale));
const halfViewportWidth = Math.round((Constants.PLANE_WIDTH / 2) * zoom);
let relevantCoordinates;
Copy link
Member

Choose a reason for hiding this comment

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

const relevantCoordinates = transDim([1, 1, 0]) should work here instead of the switch block.

Copy link
Member

@philippotto philippotto left a comment

Choose a reason for hiding this comment

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

Nice fixes 👍 I left some cosmetic comments, but all in all this looks really good!

@@ -96,13 +98,17 @@ export function* editVolumeLayerAsync(): Generator<any, any, any> {
if (!addToLayerAction || addToLayerAction.type !== "ADD_TO_LAYER") {
throw new Error("Unexpected action. Satisfy flow.");
}

// if the current viewport does not match the initial viewport -> dont draw
if (initialViewport !== (yield* select(state => state.viewModeData.plane.activeViewport))) {
Copy link
Member

Choose a reason for hiding this comment

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

I'd extract the right-hand side into a activeViewport variable and move the comment into the if-block above the continue statement.

function* getBoundingsFromPosition(currentViewport: OrthoView): Saga<?BoundingBox> {
const position = Dimensions.roundCoordinate(yield* select(state => getPosition(state.flycam)));
const zoom = yield* select(state => state.flycam.zoomStep);
const scales = yield* select(state => getBaseVoxelFactors(state.dataset.dataSource.scale));
Copy link
Member

Choose a reason for hiding this comment

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

I'd rename scales to baseVoxelFactors or something similar since this is clearer in my opinion.

) {
this.map = map;
this.width = width;
this.height = height;
this.minCoord2d = minCoord2d;
this.get3DCoordinate = get3DCoordinate;
if (!this.map[0][0]) {
this.boundingBox = boundingBox;
const firstCoordinate = this.get3DCoordinate([this.minCoord2d[0], this.minCoord2d[1]]);
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't get3DCoordinate(this.minCoord2d) be enough?

@@ -35,29 +37,59 @@ export class VoxelIterator {
width: number,
height: number,
minCoord2d: Vector2,
get3DCoordinate: Vector2 => Vector3 = () => [0, 0, 0],
get3DCoordinate?: Vector2 => Vector3 = () => [0, 0, 0],
Copy link
Member

Choose a reason for hiding this comment

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

I know that this has been like that before, but I think this parameter should be not optional and should not have a default value. The default value of () => [0, 0, 0] is a bit dangerous in my opinion, since there are only very few cases where this makes sense. As far as I know, this default value is only used for the static finished method of VoxelIterator. Can you remove the default value here and make it non-optional? The former default value can then be inlined within the static method.

foundNext = true;
this.hasNext = false;
}
if (this.map[this.x][this.y]) {
Copy link
Member

Choose a reason for hiding this comment

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

I think you can change this to an else if since y === height means that we reached the end. So, in that case we don't need to run this block.

if (!this.map[0][0]) {
this.boundingBox = boundingBox;
const firstCoordinate = this.get3DCoordinate([this.minCoord2d[0], this.minCoord2d[1]]);
if (!this.map[0][0] || !this.isCoordinateInBounds(firstCoordinate)) {
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 invert the if condition and switch the body and else block. In my opinion, that's easier to read. So, it would be something like:

if (map[0][0] != null && isInBounds...) {
  this.next = firstCoordinate;
} else {
  this.getNext();
}

@MichaelBuessemeyer
Copy link
Contributor Author

@philippotto This PR is ready for another review 😃

Copy link
Member

@philippotto philippotto left a comment

Choose a reason for hiding this comment

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

Nice, works very well!

@MichaelBuessemeyer MichaelBuessemeyer merged commit e2f43ba into master Sep 27, 2018
@philippotto philippotto deleted the dont-brush-outside-viewport branch January 24, 2019 08:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Don't draw outside of viewport in volume tracing
2 participants