marcomusy / vedo

A python module for scientific analysis of 3D data based on VTK and Numpy
https://vedo.embl.es
MIT License
2.03k stars 264 forks source link

Inverted y-axis y x3d export #480

Closed MPenaR closed 2 years ago

MPenaR commented 2 years ago

I was testing the web export feature with one of the examples. I used the Lotka-Volterra one. When I run it as a script I get the same result as the one shown in the gallery of examples:

However, when I try to get a html page by running the following code (it is the original plus the last line and without the .close() on the show):

"""The Lotka-Volterra model where:
x is the number of preys
y is the number of predators
"""
#Credits:
#http://visual.icse.us.edu.pl/NPB/notebooks/Lotka_Volterra_with_SAGE.html
#as implemented in K3D_Animations/Lotka-Volterra.ipynb
#https://en.wikipedia.org/wiki/Lotka%E2%80%93Volterra_equations
import numpy as np
from scipy.integrate import odeint

def rhs(y0, t, a):
    x, y = y0[0], y0[1]
    return [x-x*y, a*(x*y-y)]

a_1 = 1.2
x0_1, x0_2, x0_3 = 2.0, 1.2, 1.0
y0_1, y0_2, y0_3 = 4.2, 3.7, 2.4

T = np.arange(0, 8, 0.02)
sol1 = odeint(rhs, [x0_1, y0_1], T, args=(a_1,))
sol2 = odeint(rhs, [x0_2, y0_2], T, args=(a_1,))
sol3 = odeint(rhs, [x0_3, y0_3], T, args=(a_1,))

limx = np.linspace(np.min(sol1[:,0]), np.max(sol1[:,0]), 20)
limy = np.linspace(np.min(sol1[:,1]), np.max(sol1[:,1]), 20)
vx, vy = np.meshgrid(limx, limy)
vx, vy = np.ravel(vx), np.ravel(vy)
vec = rhs([vx, vy], t=0.01, a=a_1)

origins = np.stack([np.zeros(np.shape(vx)), vx, vy]).T
vectors = np.stack([np.zeros(np.shape(vec[0])), vec[0], vec[1]]).T
vectors /= np.stack([np.linalg.norm(vectors, axis=1)]).T * 5

curve_points1 = np.vstack([np.zeros(sol1[:,0].shape), sol1[:,0], sol1[:,1]]).T
curve_points2 = np.vstack([np.zeros(sol2[:,0].shape), sol2[:,0], sol2[:,1]]).T
curve_points3 = np.vstack([np.zeros(sol3[:,0].shape), sol3[:,0], sol3[:,1]]).T

########################################################################
from vedo import *

plt = Plotter(bg="blackboard")
plt += Arrows(origins, origins+vectors, c='lr')

plt += Points(curve_points1, c='y')
plt += Line(curve_points1, c='y')
plt += Line(np.vstack([T, sol1[:,0], sol1[:,1]]).T, c='y')

plt += Points(curve_points2, c='g')
plt += Line(curve_points2, c='g')
plt += Line(np.vstack([T, sol2[:,0], sol2[:,1]]).T, c='g')

plt += Points(curve_points3, c='lb')
plt += Line(curve_points3, c='lb')
plt += Line(np.vstack([T, sol3[:,0], sol3[:,1]]).T, c='lb')

plt += Latex(r'\dot{x}=x-x y',        c='white').rotateZ(-90).pos(4,6.5,0)
plt += Latex(r'\dot{y}=\alpha(xy-y)', c='white').rotateZ(-90).pos(3,6.5,0)

plt += __doc__

plt.show(axes={'xtitle':'time',
               'ytitle':'x',
               'ztitle':'y',
               'zxGrid':True, 'yzGrid':False},
         viewup='x',
)

exportWindow('test_page.x3d')

I get a representation that has the plan from the y axis with the reversed direction:

buggy_vedo_web

Is this behaviour expected? also there are some texts missing.

here is the output from vedo --info :

_________________________________________________________________
vedo version      : 2021.0.6   https://vedo.embl.es
vtk version       : 9.0.3
python version    : 3.9.7 (default, Sep 24 2021, 09:43:00) [GCC 10.3.0]
python interpreter: /usr/bin/python3
vedo installation : /home/manuel/.local/lib/python3.9/site-packages/vedo
system            : Linux 5.14.0-2-amd64 posix x86_64
k3d version       : 2.11.0
ipyvtk version    : 0.1.4
marcomusy commented 2 years ago

Hi @MPenaR thanks for the detailed report of the issue, it's definitely not normal, and for some reason the x3d format is not working in my browser.. so I cannot check. You can at least disable the plane with 'zxGrid':False About the text equations, x3d does not support images in the 3D scene. You should be able to add them as Text3D instead of Latex:


plt += Text3D('dx/dt = x - xy', c='white', s=0.25).rotateZ(-90).pos(4,4,0)
plt += Text3D('dy/dt = \alpha(xy-y)', c='white', s=0.25).rotateZ(-90).pos(3,4,0)

Screenshot from 2021-10-11 20-30-46

MPenaR commented 2 years ago

Which browser are you using? In my case at the begining the HTML would not load the x3d because of a CORS error (being the file local) In firefox you can solve it by going to about:config and changing privacy.file_unique_origin from True to False

MPenaR commented 2 years ago

This is the new result with the text as Text3D :

bug2

Although is not right yet, it seems to me that the bug may have something to do with using "pixel" directions in one of the plots and "xy" directions in the other (like y increasing from top to bottom)

marcomusy commented 2 years ago

Actually was a problem in the upstream VTK with orientations.... I made a fix on the master: pip install -U git+https://github.com/marcomusy/vedo.git

It should now work!

Screenshot from 2021-10-11 23-08-11

MPenaR commented 2 years ago

Thank you very much, works as expected now

marcomusy commented 2 years ago

cool! I updated the web page with a nice rendering :) thanks for drawing my attention to this