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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transform mode of Labels layer pivots wrong when non-empty Shapes/Points present #6897

Open
psobolewskiPhD opened this issue May 7, 2024 · 7 comments 路 May be fixed by #6927
Open

Transform mode of Labels layer pivots wrong when non-empty Shapes/Points present #6897

psobolewskiPhD opened this issue May 7, 2024 · 7 comments 路 May be fixed by #6927
Labels
bug Something isn't working
Milestone

Comments

@psobolewskiPhD
Copy link
Member

馃悰 Bug Report

If there is a non-empty Shapes or Points layer present and you use Transform mode on a Labels layer (activate using 7), rotation pivots wrong: the bounding box desyncs the layer data.

Kapture.2024-05-06.at.21.08.31.mp4

馃挕 Steps to Reproduce

  1. Open napari
  2. Make a Shapes or Points that is not empty
  3. Make a labels layer and paint something
  4. Activate Transform mode (7) and try to rotate the labels layer

馃挕 Expected Behavior

The transform box should match the layer data and remain functional.

馃寧 Environment

napari: 0.5.0a2.dev649+g2d2cac676
Platform: macOS-13.3.1-arm64-arm-64bit
System: MacOS 13.3.1
Python: 3.12.2 | packaged by conda-forge | (main, Feb 16 2024, 20:54:21) [Clang 16.0.6 ]
Qt: 6.6.1
PyQt6:
NumPy: 1.26.4
SciPy: 1.12.0
Dask: 2024.3.1
VisPy: 0.14.3.dev3
magicgui: 0.8.2
superqt: 0.6.2
in-n-out: 0.2.0
app-model: 0.2.5
npe2: 0.7.4

OpenGL:

  • GL version: 2.1 Metal - 83.1
  • MAX_TEXTURE_SIZE: 16384
  • GL_MAX_3D_TEXTURE_SIZE: 2048

Screens:

  • screen 1: resolution 1680x1050, scale 2.0

Optional:

  • numba: 0.59.0
  • triangle not installed

Settings path:

  • /Users/piotrsobolewski/Library/Application Support/napari/napari-dev_a1eb8b76ba95fa16ad06e26097b46b8455dfbf0b/settings.yaml

馃挕 Additional Context

No response

@psobolewskiPhD psobolewskiPhD added the bug Something isn't working label May 7, 2024
@psobolewskiPhD psobolewskiPhD added this to the 0.5.0 milestone May 7, 2024
@Czaki
Copy link
Collaborator

Czaki commented May 7, 2024

When you remove Shapes layer, you cannot longer even rotate this layer.

@dalthviz
Copy link
Member

Gave this a check from the GUI and seems like what is failing is that the bounding box/transform box is being shown with some translation? I was able to keep transforming the layer but the place where mouse events trigger actual transformations doesn't correspond with the place the box handles are being displayed, instead they still correspond with the actual layer limits 馃

transform_box_displaced

Checking things around seems like when a shapes layer is created first that constrains the size of the labels layer? Maybe there are some missing things to do/setup so this size constraint is taken into account for the labels layer bounding box/transform box overlay?

Creating first a shapes layer Creating first a labels layer
imagen imagen

Also, if the labels layer is created first the bounding box/transform box is displayed correctly when doing transforms 馃

transform_box_ok

@Czaki
Copy link
Collaborator

Czaki commented May 21, 2024

Ok. This is not a problem with the order of layer creation. It is a bug connected to translation. If you first create a shape or point layer, then labels layer will be created with negative translation.

Minimum script is:

import napari
import numpy as np

from napari.utils.transforms import Affine

viewer = napari.Viewer()
labels = viewer.add_labels(np.ones((10, 10), dtype=np.uint8), translate=(10, 10), affine=Affine(rotate=45))
labels.mode = "transform"

napari.run()

@brisvag it looks like we hit the same problem again...
@psobolewskiPhD could you update the description of issue to correctly point the problem?

@Czaki
Copy link
Collaborator

Czaki commented May 21, 2024

The problem is here:

new_translate = (

In general, for simple layer it should evaluate to [0.5, 0.5], but does not. We need to describe it with equations and find a way to test it.

@dalthviz
Copy link
Member

Maybe naive but seems like changing

translate_child = (
self.layer.translate[dims_displayed]
+ self.layer.affine.translate[dims_displayed]
)[::-1] - offset[::-1]
to be something like

translate_child = (
    simplified_transform.translate[dims_displayed]
)[::-1] - offset[::-1]

Makes things work (at least when checking things from the GUI with the minimum reproducer script/code snippet):

transform_box_ok_repro

Is there a reason to not use the simplified transform for the translate value in the same way that it's used to get the rotate and scale values?

@Czaki
Copy link
Collaborator

Czaki commented May 21, 2024

Is there a reason to not use the simplified transform for the translate value in the same way that it's used to get the rotate and scale values?

I do not check it (Yes, I'm the author of this code too). Maybde it is enough, but I think that we should also find a way to test it and prepare excessive test coverage to validate all cases.

@brisvag
Copy link
Contributor

brisvag commented May 22, 2024

This makes sense to me; agree that we need proper coverage here, but we don't even have proper agreements on the coordinate systems (#3783)...

@Czaki Czaki linked a pull request May 23, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants