Kitware / VolView

Kitware VolView: an all-in-one radiological viewer!
https://volview.kitware.com
Apache License 2.0
175 stars 58 forks source link

Modify shortcuts and click functions #422

Closed lchauvin closed 5 months ago

lchauvin commented 11 months ago

Hello,

I would like to modify some interactions (like using the crosshair when right-clicking for example), without interfering with other interactions.

What would be the best way to do this ? I tried to use @click in 2d views vue, but then it creates some issues with the window / level, etc...

Should I create a mouse manipulator ?

Thank you.

PaulHax commented 11 months ago

Your on the right track with registering a mouse event handler in a Vue component then setting the currentTool: https://github.com/Kitware/VolView/blob/main/src/components/ToolStrip.vue#L5

Don't think you need to do anything with VTK.js manipulators.

lchauvin commented 11 months ago

I tried to add a left-click handler to enable the crosshair on vtkTwoView, but then it interfere with the window / level tool (that also require the left-click)

PaulHax commented 11 months ago

Does capturing the event before the TwoView gets it work?

https://vuejs.org/guide/essentials/event-handling.html#event-modifiers

lchauvin commented 11 months ago

I tried that and it works for the Crosshair, but it doesn't work for the paint tool. When I use setCurrentTool(Tools.Paint), it 'activates' the paint tool (I can see it in the tool strip), but the widget is not activated (I don't see the brush, and it doesn't paint).

PaulHax commented 11 months ago

Interesting. Getting guess there are details we need to work out. We want to support scripted workflows and shortcuts for switching tools. Would be good to harden/fix our tool switching code. So I'm interested in supporting your work.

Perhaps best way to proceed is for you to make a fork and a branch with your changes. List steps to reproduce the issue. Link to your branch in an issue. Then when we get a sec, we can help debug?

lchauvin commented 11 months ago

I see. However, I'm trying to make a custom version of Volview (with slightly different behaviors, as I don't use all the tools, etc...) so I don't know if it would be relevant for other users.

PaulHax commented 11 months ago

Not expected a Pull Request. A good way for solve this is to share the code you tried.

lchauvin commented 11 months ago

Here is my code:

https://github.com/lchauvin/VolView

The crosshair is working as expected, but not the painting. Another solution would be to set the paint tool as the default one, but I'm not sure how to set it.

I tried to change in src/store/tools:58 by Tools.Paint, and it's activated, but not painting.

PaulHax commented 11 months ago

Maybe set the the selected tool to Paint when VolView loads and remove the @mousedown.left.stop="paintOn" and paintOff calls in VtkTwoView. Then the crosshairOff call activates paint or the last selected tool.

lchauvin commented 11 months ago

I tried to do that, but it didn't work. Maybe I did it wrong, but I modified src/store/tools

state: (): State => ({
    currentTool: Tools.WindowLevel,
  }),

to put Tools.Paint, but when VolView loads, the paint tool is 'activated' but it's not painting. I have to change tool and comeback to paint. It seems like using setCurrentTool(Tools.Paint) is not enough to completely activate the painting tool.

PaulHax commented 11 months ago

Did you remove the @mousedown.left.stop="paintOn"?

lchauvin commented 11 months ago

Yes, I used the current main branch, and just modified the src/store/tools to modify the state from Tools.WindowLevel to Tools.Paint

PaulHax commented 11 months ago

Ah, Paint needs a labelmap createed, but creation of a labelmap silentty fails if there is no currentImageID. Would be nice to fix that. Or could call useToolStore().setCurrentTool(Tools.Paint); somewhere else as a workaround.

lchauvin commented 11 months ago

Would it be worth creating a labelmap automaticallt for each image when importing data ?

PaulHax commented 11 months ago

That would use extra memory. I'ed guess there is some logic we can fix in the .vue compoent code that creates the label map if Paint is selected upon first image load. A labelmap is created just fine if:

  1. Load image
  2. Select Paint
  3. Load second new image
  4. Label map created for new image, Paint works.

So we are close.

lchauvin commented 11 months ago

But how can we create a labelmap if the image is not loaded ? Don't we need the size of the image to create the labelmap ?

floryst commented 11 months ago

Yes, we would need to ensure the creation of the labelmap if there is none when painting. There might be an ordering issue there.

I'm currently working on some labelmap improvements, so hopefully things get easier to use. I don't agree with creating a labelmap immediately upon import, since Paul does note that it uses extra memory when you might not want to use it.

PaulHax commented 9 months ago

@lchauvin This PR may have solved some of our Paint at startup issues: https://github.com/Kitware/VolView/pull/507

PaulHax commented 5 months ago

continuing disscussion here: https://github.com/Kitware/VolView/discussions/573