Hi,
Thank you very much for the suggestions.
I tried scalar and colormap arguments of points3d function but it didn't
work. Let me explain you the requirements briefly-
1) I have some points in 3-dimensional space
2) All of these points have a color value associated with it. The color
value is packed RGB value using the following formulation- rgb = (r<<16)
+ (g<<8) + b
3) My goal is to visualize these color points
In short, I have a numpy array of shape (N,4) where first 3 columns are
positions and last column is the packed color value. Below is the best
what I could get so far-
-----------------------------------------------------------
import numpy as np
from mayavi import mlab
N = 40000
scale = 0.1
ones = np.ones(N)
scalars = np.arange(N)
(x, y, z) = np.random.random((3, N))
# assume packed RGB value is unpacked into (r, g, b) individually
colors = (np.random.random((N, 4)) * 255).astype(np.uint8) # RGBA
colors[:,-1] = 255 # no transparency
mlab.figure()
pts = mlab.quiver3d(x, y, z, ones, ones, ones, scalars=scalars,
mode='sphere', scale_factor=scale)
pts.glyph.color_mode = 'color_by_scalar'
pts.module_manager.scalar_lut_manager.lut.table = colors
mlab.show()
-----------------------------------------------------------
The above code snippet takes RGBA color in a numpy array of shape (N,4).
I am able to unpack RGB into (r, g, b) individually in another code.
However, I am not able to scale down the radius of all points.
I want to know that how to scale down all the points?
Also, based on my requirements, if you have any better idea in your mind
to achieve the same, please let me know.
-
Thanks
Ravi
On 2018-07-22 23:06, Shankar Kulumani wrote:
The documentation shows a solution by using an additional scalar value
and a colormap:
The documentation is very thorough and shows a good example as well
http://docs.enthought.com/mayavi/mayavi/auto/mlab_helper_functions.html#points3d
import numpy
from mayavi.mlab import *
def test_points3d():
t = numpy.linspace(0, 4 * numpy.pi, 20)
cos = numpy.cos
sin = numpy.sin
x = sin(2 * t)
y = cos(t)
z = cos(2 * t)
s = 2 + sin(t)
return points3d(x, y, z, s, colormap="copper", scale_factor=.25)
On Sun, Jul 22, 2018 at 4:39 AM <mys...@ravijoshi.info> wrote:
Hi,
Thank you very much. I almost reached there. points3d is working
however, I am having a hard time in assigning colors to each point.
Please see the code snippet below-
-------------------------------------
import numpy as np
from mayavi import mlab
# generate random data (just for checking)
pts = 10 # number of points (just for checking)
x = np.arange(pts)
y = np.arange(pts)
z = np.arange(pts)
c = np.random.rand(pts, 3) #r, g, b values
mlab.figure()
mlab.points3d(x, y, z, color=c)
mlab.show()
-------------------------------------
The above code throws following error-
The 'color' trait of a GlyphFactory instance must be a tuple of the
form: (0.0 <= a floating point number <= 1.0, 0.0 <= a floating
point
number <= 1.0, 0.0 <= a floating point number <= 1.0) or None, but a
value of array([[...]]) <type 'numpy.ndarray'> was specified.
It seems that the color is a tuple i.e., (r, g, b)in mlab.points3d()
function and it is globally applied to all points. However, in my
case,
each point has a color value, which is different from others.
The simplest thing which came to my mind is to assign each point one
by
one as shown below-
-------------------------------------
mlab.figure()
for i in range(pts):
mlab.points3d(x[i], y[i], z[i], color=tuple(c[i].reshape(-1)))
mlab.show()
-------------------------------------
This works fine for a few points. However, I have approximately
40,000
points and the above approach isn't working!
-
Thanks
Ravi
On 2018-07-21 22:12, Shankar Kulumani wrote:
This function will do exactly what you want
http://docs.enthought.com/mayavi/mayavi/auto/mlab_helper_functions.html#points3d
Example
points3d(x, y, z...)
points3d(x, y, z, s, ...)
points3d(x, y, z, f, ...)
On Sat, Jul 21, 2018, 03:12 <mys...@ravijoshi.info> wrote:
Hello,
I am new to mayavi and I am trying to use mayavi in python to
visualize
a point cloud. I have a colored point cloud
(PointCloud<PointXYZRGB>)
stored in a numpy array of shape (40000, 4). The first three
columns
of
this array are the position in 3D space (x, y, z) and the last
column is
RGB color packed in one using the following formulation-
// pack r/g/b into rgb
uint8_t r = 255, g = 0, b = 0; // Example: Red color
uint32_t rgb = ((uint32_t)r << 16 | (uint32_t)g << 8 |
(uint32_t)b);
Hence, the point cloud contains 40,000 points in which each point
has a
color assigned to it.
I want to know if it is possible to visualize it using mayavi
python?
Any sample code will be appreciated more.
-
Thanks
Ravi
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
MayaVi-users mailing list
MayaVi-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mayavi-users
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
MayaVi-users mailing list
MayaVi-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mayavi-users