Point Valued Density Surface Set 1

../../_images/pntdensurf_val_c.png

For the case when each point has a value, the value may be used to colormap the density surface. In this example :

  1. Cloud values are assigned density from sample coordinates. The density cloud is then used to create the surface.

  2. Cloud values are ‘reassigned’ values from the sample values.

  3. The surface vertices are assigned values from the cloud values.

  4. The surface is then colormapped from the vertex values.

import numpy as np
import matplotlib.pyplot as plt
import s3dlib.surface as s3d
import s3dlib.pntcloud as ptc

# 1. Get data to examine ...........................................
npnts,seed,val_mult,domain = 50, 6, 25.0, [ [-7,6], [5,30], [0,50] ]
np.random.seed(seed)
xc = np.random.uniform(*domain[0], npnts)
yc = np.random.uniform(*domain[1], npnts)
zc = np.random.uniform(*domain[2], npnts)
input_coor = np.column_stack((xc,yc,zc))
vals = val_mult*np.random.uniform(size=npnts)
data = np.column_stack((input_coor,vals))

# 2. Setup and map surface .........................................
pdg, drez, relden,cmap = 1.2, 3, 0.3, 'jet'

cloudObj = ptc.Point3DCloud(drez,domain=domain,cmap=cmap)
cloudObj.map_vals_from_sampdens(input_coor,pdg)
surface = cloudObj.valsurf(relden)

#... reset point cloud values from sample values ...
cloudObj.map_vals_from_sampvals(data,vadj='c')

#... set surface vertex values from cloud, then color map from values
surface.map_vertvals_from_cloud(cloudObj)
surface.map_cmap_from_vertvals(cmap)
surface.triangulate(1)

#... colormap cloud based on sample values
cloudObj.map_cmap_from_cloudvals()

# 3. Construct figures, add surfaces, and plot ....................
fig = plt.figure(figsize=(10,4))
# ....................
title = 'cloud valued density surface\n( pdg = {:.2f}, relden = {:.2f} )'.format(pdg,relden)
fig.text(.27,0.92,title,ha='center', va='center')
ax = fig.add_subplot(121, projection='3d', aspect='equal')
ax.set(xlim=domain[0], ylim=domain[1], zlim=domain[2],  
    xlabel='x',ylabel='y',zlabel='z')
ax.view_init(20)
ax.add_collection3d(surface.shade(flat=False).hilite(.5,flat=False))
s3d.add_boxCorner(ax,domain)
# ....................
title = 'point cloud ({})'.format(npnts)
fig.text(.7,0.92,title,ha='center', va='center')
ax = fig.add_subplot(122, projection='3d', aspect='equal')
ax.set(xlim=domain[0], ylim=domain[1], zlim=domain[2],  
    xlabel='x',ylabel='y',zlabel='z')
ax.view_init(20)
cloudObj.add_to3d(ax,0,0.6,1,span=.2)
s3d.add_boxCorner(ax,domain)
scmp = cloudObj.cBar_ScalarMappable
cbar = plt.colorbar(scmp, ax=ax,  shrink=0.8, pad=.1 )
cbar.set_label('cloud values', rotation=270, labelpad = 15)
# ....................
fig.tight_layout(pad=3)
plt.show()