gecos-lab / PZero

GNU Affero General Public License v3.0
24 stars 2 forks source link

New 2D views #37

Open gbene opened 1 year ago

gbene commented 1 year ago

Hi all!

In the new_2D branch I am experimenting with changing the 2D plotting backend from matplotlib to pyvista/vtk. I think this is a better approach than using for example PyQtGraph (#2) because:

  1. All windows will be based on the same library thus many functions will be the same for different views (e.g. the opacity can be applied without any hassle to each view #22).
  2. It should bring a more constant experience, resolving problems such as #1 and helping with #15
  3. From my testing, plotting is very fast since we can use the same entities between viewers without the need to convert and plot vtk data on a chart.

With vtk there are many functions to use to emulate the 2D views. These are the ones that I found that I have been able to adapt to our needs:

  1. vtkInteractorStyleImage combined with parallel projection (enabled in pyvista using enable_image_style and enable_parallel_projection respectively) for emulating a 2D section (map or generic section)
  2. vtkContourWidget to draw and edit a line
  3. vtkPointWidget to add points (not yet implemented)
  4. A modified version of vtkContourWidget to draw vectors.

Here are some clips!

Drawing https://user-images.githubusercontent.com/40857804/217499766-cc0d0025-96aa-4536-b353-3f44585958c7.mp4 https://user-images.githubusercontent.com/40857804/217499969-6202bb77-45d9-4ff6-93b5-e33a90ed962d.mp4
Editing https://user-images.githubusercontent.com/40857804/217489227-729308e6-3da8-4d7e-adfe-aafb6ca3ae9e.mp4 https://user-images.githubusercontent.com/40857804/217499984-f9fce3be-05ea-456a-9450-2112697a2e06.mp4
Moving https://user-images.githubusercontent.com/40857804/217500054-f3e6b1ea-fdcf-43f4-9e32-f078f9cc3dcd.mp4

This is very exiting since we could easily digitize geological map data directly in PZero without going through GIS! The experience now is very similar.

Let me know what you think and share your doubts!

Doubts

As you can see from the videos, vtkContourWidget has the possibility to interactively move and remove nodes of a line. Do we still want to use the vector method for line editing?

I think that in most cases the interactive method is faster and easier to use. For example when the position of each node of a line must be adjusted I'd rather have a continuous interaction with each point instead of drawing multiple vectors. The vector mode can be useful in the XSection, for example if a point needs to be moved parallel to a fault, but I still think that the default should be the interactive editing. The vector method could still be an option activated as a toggle (for example by pressing the v key we switch between interactive and vector mode). What do you think?

On another note, there are some nice properties of matplotlib that can be quite difficult to emulate in vtk. One that I have tried and failed to implement is the adaptive background grid and tick axis that change depending on the zoom level. With vtk I have no idea how to efficiently do such thing when zooming with the middle mouse button. Do you have any thoughts on this? Do you think that it is a necessary feature? Are there other matplotlib features that would be nice to have in the new views?

TODOs

Feel free to edit this list to add additional tasks.

andrea-bistacchi commented 5 months ago

Almost all has been done when refactoring the 2D views. Please check.