Binary Cloud SurfaceΒΆ

../../_images/binary_points_surface.png

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.

../../_images/binary_points_cloud.png
import numpy as np
import matplotlib.pyplot as plt
import s3dlib.surface as s3d
from matplotlib import cm,colormaps
import matplotlib.colors as mcolors

# 1. Generate a binary cloud distribution to examine ...............
N = 10
np.random.seed(3)
vals = np.random.randint(2, size=N**3)
cloud = np.reshape( vals, (N,N,N) )

# 2. Setup surface .................................................
dmn,fval,cmap = [-10,10], 0.5, 'jet'
surfcol = colormaps[cmap](fval)

surface = s3d.Surface3DCollection.cloudsurf(cloud,dmn,fval,color=surfcol)
surface.triangulate(3)

# 3. Construct figure, add surface, and plot .......................
fig = plt.figure(figsize=(6.0, 4.5))
figtitle = str(surface) + '\nbinary point cloud: '+str(cloud.shape) + \
     '\nrelative value = '+str(fval)
fig.text(.95,.98,figtitle,ha='right',va='top')
ax = fig.add_subplot(111, projection='3d', aspect='equal', focal_length=0.5)
ax.set(xlim=dmn,ylim=dmn,zlim=dmn,xlabel='x',ylabel='y',zlabel='z')
ax.view_init(20)

ax.add_collection3d(surface.shade(ax=ax,flat=False))

norm = mcolors.Normalize(np.min(cloud),np.max(cloud) )
scmp = cm.ScalarMappable(norm=norm,cmap=cmap)
cbar = plt.colorbar(scmp, ax=ax,  shrink=0.6, pad=.08 )
cbar.set_label('cloud relative value', rotation=270, labelpad = 15)

vE,iE = [ [-10,-10,10], [10,-10,10], [10,10,10], [10,-10,-10] ], [ [0,1,2],[1,3]]
ax.add_collection3d( s3d.ColorLine3DCollection(vE,iE,color='0.6',lw=1) )

fig.tight_layout(pad=1.5)
plt.show()

The point coordinates and values for the binary cloud plot was generated from:

dmn,fval,cmap = [-10,10], 0.5, cmu.binary_cmap( 'k','w' )
xyz, colors, scmp = s3d.get_points_from_cloud(cloud,dmn,cmap)

The points were used for a Matplotlib scatter plot:

ax.scatter(*xyz, c=colors, marker='.', s=400, edgecolor='k')