Unstructured 3-D Surface SetΒΆ

../../_images/unstruct_vol_set.png

From the unstructured distribution of values within the domain, surfaces for various constant values are shown in the above figure. Transparency surface color was used to visualize the enclosed closed surfaces.

import numpy as np
import matplotlib.pyplot as plt
from matplotlib import cm,colors,colormaps
from scipy.stats.qmc import Halton
import s3dlib.surface as s3d
import s3dlib.pntcloud as ptc

# 1. Get data to examine ...........................................
# 0. control parameters.
drez,N,seed,cmap = 5, 300, 6, colormaps['jet']
domain = [ [-1,1], [-1,1], [-1,1] ]
Fvals = [ -.3, -.2, -.1, -.01, .01, .1, .2, .3]
# generate data points with values .
dt_coor = 2*Halton(3, seed=seed).random(N) - 1
vals = np.sum(dt_coor, axis=1)*np.exp(-3*np.sum(dt_coor**2, axis=1))
points = np.column_stack((dt_coor,vals))

# 2. Setup and map surface .........................................

cloudObj = ptc.Point3DCloud(drez,domain=domain)
cloudObj.map_vals_from_sampvals(points, cmap=cmap)

surface = cloudObj.valsurf( *Fvals )
surface.evert().set_surface_alpha(.6)

# 3. Construct figures, add surfaces, and plot ....................
ticks = [-1,-.5,0,.5,1]
fig = plt.figure(figsize=(6,4.2))
ax = plt.axes(projection='3d', aspect='equal')
ax.view_init(20,-60)
ax.set(xlim=domain[0], ylim=domain[1], zlim=domain[2],  
    xlabel='x',ylabel='y',zlabel='z',xticks=ticks,yticks=ticks,zticks=ticks)

tstrg = ''
for i in range(len(Fvals)) :  tstrg = tstrg + '{:.2f}, '.format(Fvals[i])
ax.set_title('point cloud surfaces\n'+tstrg)
ax.add_collection3d(surface.shade(.2,ax=ax).hilite(.5,ax=ax))
s3d.add_boxCorner(ax,domain)

scmp = surface.cBar_ScalarMappable
cbar =fig.colorbar(scmp, ax=ax,shrink=0.8, pad=.1)
cbar.set_label('cloud values', rotation=270, labelpad = 15)

fig.tight_layout()
plt.show()