Closed alisheikholeslam closed 2 years ago
I suspect that the number of spheres is likely too large to visualise with Mayavi, but that may depend on the underlying hardware that you have; it would certainly be suitable for watching the motion of a smaller subset - that should be a matter of creating the visualization you need of the spheres (eg. passing the numpy arrays for position and radius to a 3D scatterplot as described in the documentation), and then updating the plot object with new arrays as the values change.
@alisheikholeslam -- Do you have a snippet of code that you are using for this? There are two possible issues. If you are creating multiple VTK actors that will be a problem but if you are plotting this in one shot using say mlab.points3d
it should work. However when you use such a large number of points, you need to be a bit careful. if you use a sphere glyph source, then VTK will generate one sphere with about 50 or so polygons (or more if you change the parameters) for each point. This may drown your visualization. A quick way around this is to instead render the points as vertices (use mode='point') and then render the points as spheres. Here is some code:
from mayavi import mlab
import numpy as np
x, y, z = np.random.random((3, 1000000))
g = mlab.points3d(x, y, z, x+y+z, mode='point')
g.actor.property.render_points_as_spheres = True
g.actor.property.point_size = 5
Adjust the point size as you see fit. This should be much faster and should look good too.
@prabhuramachandran
from mayavi import mlab import numpy as np x, y, z = np.random.random((3, 1000000)) g = mlab.points3d(x, y, z, x+y+z, mode='point') g.actor.property.render_points_as_spheres = True g.point_size = 5
I have test this code without any changes but it gets the following error:
Traceback (most recent call last): File "C:/Users/Ali/Desktop/test.py", line 30, in
g.point_size = 5 traits.trait_errors.TraitError: Cannot set the undefined 'point_size' attribute of a 'Glyph' object.
Is it a complete running code? What should I change to run this code and view the sample results? Is it related to the mentioned point size
and needs to adjust it for this example by writing another code line? Does it get an array for adjusting sizes?
I have installed mayavi 4.7.4
; g
have not any modules named point_size
or something like g.actor.property.point_size
.
Updated the answer, I am not sure how I wrote g.point_size = 5
. It should be g.actor.property.point_size = 5
.
Adjust the point size as you see fit. This should be much faster and should look good too.
Thanks for the solution. Using this method is much faster than using it without adjusting mode='point'
and …. On my machine, using codes like:
from mayavi import mlab
x, y, z, value = np.random.random((4, 10000))
mlab.points3d(x, y, z, value)
mlab.show()
will be slow and for sphere numbers about >500000
will get stuck by the following error:
2022-01-24 04:25:51.792 ( 5.376s) [ ]vtkGenericDataArray.txx:389 ERR| vtkTypeInt64Array (0000027B20494A70): Unable to allocate 288000000 elements of size 8 bytes.
Also, applicable resolution is limited for large sphere numbers. But it is showing spheres with their radii magnitudes, when it runs without problem.
Could I visualize the results by showing radii differences or radii are just with the same size using mode='point'
method?
Hello all,
I know it is not an issue, but I didn't know where to ask my question. I was seeking about python libraries that could visualize combination of spheres during my code running and I like mayavi:
I am working on movements of spheres for dense packing of them in a box in an iteration scheme. So, my particles (spheres) are moving a little during the solution steps. steps (loops) could be at least 100000 to perhaps 1000000 or more (it is not limited) and spheres could be 50000 to 500000 or 1000000 numbers with various specified radii. In each loop I will get numpy arrays of positions and radii of the all spheres which could be used for further usages. I don't know, mayavi is an appropriate tool for visualizing the movements during the running time of my code (visualizing such as an animation). I would like to see what is happening during my running code to sphere positions. Could I use numpy arrays to put all data in a moment (one-step) in each step, or it needs just to loop? If it could, how could I do this in python? Is mayavi appropriate for this work where sphere positions are updating in each loop and need to be updated in visualization view?
I would be very grateful if any one would help doing this or referring a python code to do so.
best regards, Ali