marcomusy / vedo

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

interpolating data on the surface #451

Closed Amin-Fakia closed 3 years ago

Amin-Fakia commented 3 years ago

I am trying to plot data of an eeg device on a headmodel. I have managed to import the data and project the sensor locations on the model itsself by find the shortest distance to the model. The result is seen in the following picture

L6HVmwm

this is already a good result but the values still need to be interpolated to some thing like

Screenshot from 2021-09-06 15-11-05

In 2D this can be easly done by using contour lines to interpolate the data, for example: Dpm1f6H

But i dont know how i can do this in 3D. I am a bit new to these stuff, any help is appriciated

marcomusy commented 3 years ago

Hi, the question is a bit too vague.. :)

what are you trying to interpolate? What's the data format? Have a look at these examples:

examples/advanced/interpolateMeshArray.py
examples/advanced/interpolateScalar1.py
examples/advanced/interpolateScalar2.py

PS: you can drag and drop images in github window

Amin-Fakia commented 3 years ago

Hello, Thank you for your answer. So i have 22 Data points ( 3D Positions of the sensors) and i have a recorded set of data for these 22 Data points ( 8 Seconds). I would like to interpolate the data from one sensor to the rest(basically to find the values that are between this sensor and the other ones) and apply it on the model. As for the data format its in EDF but i know how to extract the data and save it in an array or dictionary. If its still not clear what i want to do i will try to write a document to explain it exactly

Amin-Fakia commented 3 years ago

Maybe to make it easier, is it possible to draw contour lines on the model surface itsself ? for example: 0_ThHiymBhC6sbCWyC

marcomusy commented 3 years ago

you can have a look at examples/pyplot/isolines.py But the problem is that your model is 3D - so are you looking for distances in 3D space o r distances along the surface of the mesh? I'm not sure what makes more sense in this case..

Amin-Fakia commented 3 years ago

tbh with you i think the task itsself doenst make that much sense but my instructor told me that i need to interpolate the data in 3D space, i am gonna have another talk with him to understand why this is important. I think it looks good as it is already like the in first picture

marcomusy commented 3 years ago

If you signal (whatever it is) is supposed to travel in the brain tissue, it may make sense to have it 3d instead of 2d (?) in this case the relevant example would be examples/advanced/interpolateScalar1.py

Amin-Fakia commented 3 years ago

am sorry to annoy you but is there a way to find the shortest path from one vertix to the others and save the path of the vertices in an array ? image

marcomusy commented 3 years ago

uhm sorry I forgot to store that information.... I will push a new version soon

marcomusy commented 3 years ago

Please try: pip install -U git+https://github.com/marcomusy/vedo.git

then

from vedo import *
import numpy as np

sphere = Sphere(r=1.02, res=200).clean(0.007).wireframe().alpha(0.1)

geo = sphere.geodesic(10, 3000) # 2 point index
geo.print()
idx = geo.pointdata["VertexIDs"]

show(Earth(), sphere, geo, bg2='lb', viewup="z")

Screenshot from 2021-09-08 19-53-33

Amin-Fakia commented 3 years ago

sorry for keeping you waiting i was busy doing other stuff in the days. The algorithm seem to work fine for this example but it doesnt work on any other mesh. should the start and end point be in [x,y,z] coordiantes ? cuz this doesnt work.

Amin-Fakia commented 3 years ago

i should also mention that it doesnt show any errors when running the script

marcomusy commented 3 years ago

you are not giving me enough information.. the argument of geodesic are 2 indices not xyz coords. maybe the mesh is not triangular? (try .triangulate())

Amin-Fakia commented 3 years ago

image The code runs but nothing happens, as you can see i have an Obj model i imported it and tried with and without triangulate() method. Both doesnt work i have tried the same for another mesh object and it still doesnt work

marcomusy commented 3 years ago

Thanks for reporting, try: pip install -U git+https://github.com/marcomusy/vedo.git

then

from vedo import *

msh = Mesh('https://www.dropbox.com/s/7u10tkgmao2ldwz/11091_FemaleHead_v4.obj?dl=0')
msh.triangulate().clean()
msh.c("yellow")

geo = msh.geodesic(16200, 12500) # 2 point index
# geo = msh.geodesic([-6.12917771,  0.91979967, 11.64302759], [-0.07440148,  9.09446493,  9.1692904 ])
geo.color("red").lw(3)

# geo.print()
# printc(geo.pointdata["VertexIDs"])

show(msh, 
     msh.labels('id', ratio=100, scale=.1),
     geo,
     bg2='lb', viewup="z", axes=1)

Screenshot from 2021-09-10 17-29-47

Amin-Fakia commented 3 years ago

thank you so much. I think i have finally got the results i wanted. This is project is so awsome i thank you very much for helping me :D i will discuss the results with my instructor and will make a github project for this ^^ image