Binary Cloud SurfaceΒΆ
The above figure represents a surface of constant value = 0.5 within a binary point cloud shown below. Values within the domain are between 0 and 1 in the cloud where the points on the mesh are exactly 0 or 1.
import numpy as np
import matplotlib.pyplot as plt
import s3dlib.surface as s3d
import s3dlib.pntcloud as ptc
# 1. Generate a binary cloud distribution to examine ...............
np.random.seed(3)
ranfunc = lambda c : np.random.randint(2, size=c[0].shape)
# 2. Setup surface .................................................
drez, domain, cmap = 0.9, 10, 'pink'
cloudObj = ptc.Point3DCloud(drez,cmap=cmap,domain=domain)
cloudObj.map_vals_from_op(ranfunc)
cloudObj.map_cmap_from_cloudvals()
surface = cloudObj.valsurf(0.5)
surface.triangulate(3)
domain = cloudObj.get_domain() # get the 3 X 2 domain array
xlim,ylim,zlim = domain
# 3. Construct figure, add surface, and plot .......................
fig = plt.figure(figsize=(6.0, 4.5))
figtitle = str(surface) + '\n'+ str(cloudObj)
fig.text(.98,.98,figtitle,ha='right',va='top',fontsize='small')
fig.text(.5,.87,'cloud surface contour ( 0.5 ) ',ha='center',va='center',fontsize='large')
ax = fig.add_subplot(111, projection='3d', aspect='equal', focal_length=0.5)
ax.set(xlim=xlim,ylim=ylim,zlim=zlim,xlabel='x',ylabel='y',zlabel='z')
ax.view_init(20)
ax.add_collection3d(surface.shade(ax=ax,flat=False))
s3d.add_boxCorner(ax,domain)
scmp = cloudObj.cBar_ScalarMappable
cbar = plt.colorbar(scmp, ax=ax, shrink=0.6, pad=.08 )
cbar.set_label('cloud value', rotation=270, labelpad = 15)
#....................................................
fig.tight_layout(pad=2.0)
plt.show()
The point cloud figure is generated using the script:
import numpy as np
import matplotlib.pyplot as plt
import s3dlib.surface as s3d
import s3dlib.pntcloud as ptc
from matplotlib import patches
# 1. Generate a binary cloud distribution to examine ...............
np.random.seed(3)
ranfunc = lambda c : np.random.randint(2, size=c[0].shape)
# 2. Setup surface .................................................
drez, domain, cmap = 0.9, 10, 'pink'
cloudObj = ptc.Point3DCloud(drez,cmap=cmap,domain=domain)
cloudObj.map_vals_from_op(ranfunc).map_cmap_from_cloudvals()
domain = cloudObj.get_domain() # get the 3 X 2 domain array
xlim,ylim,zlim = domain
# 3. Construct figure, add cloud points, and plot .......................
fig = plt.figure(figsize=(3.5, 3.5))
fig.text(.5,.94,str(cloudObj),ha='center',va='center')
ax = fig.add_subplot(111, projection='3d', aspect='equal', focal_length=0.5)
ax.set(xlim=xlim,ylim=ylim,zlim=zlim,xlabel='x',ylabel='y',zlabel='z')
ax.view_init(20)
xyz,c = cloudObj.points, cloudObj.point_colors
ax.scatter(*xyz, c=c, s=100,edgecolor='k')
s3d.add_boxCorner(ax,domain)
hnd = [ patches.Patch(label='value = 0.0', facecolor='k', edgecolor='k' ) ,
patches.Patch(label='value = 1.0', facecolor='w', edgecolor='k' ) ]
ax.legend(handles=hnd, edgecolor='k',facecolor='w')
#....................................................
fig.tight_layout(pad=2)
plt.show()
