Open jonaslindemann opened 2 years ago
Uhm... does this work for you?
import vedo
import numpy as np
class RunnerTest:
def __init__(self):
self.positions = np.random.rand(100, 3)
self.plt = vedo.Plotter(axes=1, interactive=False)
self.points = vedo.Points(self.positions)
self.text = vedo.Text2D(c='r4')
self.plt += [self.points, self.text]
def run(self):
print("Run simulation...")
reset_cam = True
while True:
self.positions *= 0.99
self.points.points(self.positions)
self.text.text(f'cm={self.points.centerOfMass()}')
self.plt.show(resetcam=reset_cam)
if reset_cam:
reset_cam = False
if self.plt.escaped:
break # if ESC is hit during the loop
rt = RunnerTest()
rt.run()
You may also use Sphere
instead of Spheres
, so you don't need to recreate the object in the loop.
Thanks for your quick reply. It almost worked. After removing the text object it works:
import vedo
import numpy as np
class RunnerTest:
def __init__(self):
self.positions = np.random.rand(100, 3)
self.plt = vedo.Plotter(axes=1, interactive=False)
self.points = vedo.Points(self.positions)
#self.text = vedo.Text2D(c='r4')
self.plt += [self.points]
def run(self):
print("Run simulation...")
reset_cam = True
while True:
self.positions *= 0.99
self.points.points(self.positions)
#self.text.text(f'cm={self.points.centerOfMass()}')
self.plt.show(resetcam=reset_cam)
if reset_cam:
reset_cam = False
if self.plt.escaped:
break # if ESC is hit during the loop
rt = RunnerTest()
rt.run()
I have an example that uses a list of spheres that are updated manually, but then I have to use a python loop which slows down the animation significantly. I could make my own example work with Points. I would like the self.spheres.points(self.positions) to work ;)
Jonas
BTW: Replacing Points with Spheres also crashes the above code.
Uhm.. what happens to the Text2D? Is it crashing?
I would like the self.spheres.points(self.positions) to work ;)
You can use Sphere
instead of Spheres
, so you don't need to recreate the object in the loop. You'll then update their position with a loop calling spheres[i].pos(self.positions[i]
(this will be fast).
BTW: Replacing Points with Spheres also crashes the above code.
Probably because you're trying to set the points (mesh vertices!!) of the Spheres
object which is a single Mesh
.
Uhm.. what happens to the Text2D? Is it crashing?
Yes. Black window appears and then disappears. No drawing from what I can see.
I would like the self.spheres.points(self.positions) to work ;)
You can use
Sphere
instead ofSpheres
, so you don't need to recreate the object in the loop. You'll then update their position with a loop callingspheres[i].pos(self.positions[i]
(this will be fast).
Ok, That was in principle what I did. I will try it again.
BTW: Replacing Points with Spheres also crashes the above code.
Probably because you're trying to set the points (mesh vertices!!) of the
Spheres
object which is a singleMesh
.
Ok, I was a bit confused by the API that looked a lot like the Points API. So the spheres in Spheres are a single mesh?
Jonas
Yes. Black window appears and then disappears. No drawing from what I can see.
that's pretty weird! But the small standalone script I sent is also failing ?
Ok, I was a bit confused by the API that looked a lot like the Points API. So the spheres in Spheres are a single mesh?
Yes. And - you are right - the API similarity can be misleading... I need to clarify it in the docs.
Yes. Black window appears and then disappears. No drawing from what I can see.
that's pretty weird! But the small standalone script I sent is also failing ? Yes
Ok, I was a bit confused by the API that looked a lot like the Points API. So the spheres in Spheres are a single mesh?
Yes. And - you are right - the API similarity can be misleading... I need to clarify it in the docs.
Thanks, looks like a very impressive library. Evaluating right now for a project assignment in a Scientific Programming course.
Jonas
the small standalone script I sent is also failing ? Yes
can you do:
vedo --info
to know your system specs, I will try reproduce the problem if possible. Thanks for reporting!
Perhaps a bug, but on Windows you can't type vedo in the command line. For all the other scripts in this folder there are .exe equivalents. I had to do:
python vedo --info in the Scripts directory
_________________________________________________________________
vedo version : 2021.0.6 https://vedo.embl.es
vtk version : 9.0.1
python version : 3.7.11 (default, Jul 27 2021, 09:42:29) [MSC v.1916 64 bit (AMD64)]
python interpreter: C:\Anaconda3\envs\sciprog-project\python.exe
vedo installation : C:\Anaconda3\envs\sciprog-project\lib\site-packages\vedo
system : Windows 10 nt AMD64
I am trying to visualise a particle system using the vedo.shapes.Spheres class. This is the main loop:
Running this will display a single set of points and then crash without an exception.
particle_driver is a fortran extension module. Using vedo.mesh.Points class works.
It also works when you recreate a Spheres instance every loop iteration, but that is really slow...
Any ideas?