Point Valued Density Surface Set 2ΒΆ

../../_images/pntdensurf_val_s.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. The surface vertices are directly assigned values from the values of the nearest sample.

  3. 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)
cloudObj.map_vals_from_sampdens(input_coor,pdg)
surface = cloudObj.valsurf(relden)

surface.map_vertvals_from_samples(data,domain)
surface.map_cmap_from_vertvals(cmap)
surface.triangulate(3)

surf_g = cloudObj.valsurf(relden)
surf_g.set_surface_alpha(.15)
samples = s3d.samples_to_object(data,domain,cmap=cmap, size=.8)

# 3. Construct figures, add surfaces, and plot ....................
fig = plt.figure(figsize=(10,4))
# ....................
title = 'near 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 = 'samples and density ({})'.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)

ax.add_collection3d(surf_g.shade())
ax.add_collection3d(samples.shade())
s3d.add_boxCorner(ax,domain)

scmp = samples.cBar_ScalarMappable
cbar = plt.colorbar(scmp, ax=ax,  shrink=0.8, pad=.1 )
cbar.set_label('sample values', rotation=270, labelpad = 15)
# ....................
fig.tight_layout(pad=3)
plt.show()