Point Clouds

A point cloud object is a collection of 3D Cartesian coordinate points, uniformly arranged in a rectangular grid. Object methods provide assignment of value and color for points within the domain volume.

A point cloud object, cloudObj, is instantiated from the Point3DCloud class as:

import s3dlib.pntcloud as ptc

cloudObj = ptc.Point3DCloud(rez)

where the rez argument is a multiplier of 10 for the number of subdivisions between points along each of the coordinate axes. The default domain for coordinates is -1 to 1, which can be directly set using the ‘domain’ keyword argument. Addition of the object to the 3D Matplotlib axes, ax, uses the cloud method:

cloudObj.add_to3d(ax)

which produces a figure as:

../../_images/cloud_sm.png

The above cloud object was constructed with a rez of 1.5 and a domain assignment of [-10,20] . The string representation, shown at the figure top, contains the rez, value mapping and number of point coordinates in the object. In this example, the point values are not assigned value or color, resulting a uniform default color for all points.

.

Value and Color Assignment

Values …………………

Point values are assigned using one of three ways:

  1. a defined function of coordinate positions.

  2. the values from a set of data samples with values.

  3. the density of a set of data samples.

Each of these ways are discussed in the following sections. The way cloud values have been assigned can be determined from the object string property:

cloudObj.val_source

which is either function, sampleVals[..], or sampleDens[..,..] where the ‘..’ indicates contruction properties of the cloud from samples. If values are not assigned, the value mapping string is UnMapped.

Color …………………

Cloud uniform color is assigned using the color argument in the constructor or using the object method:

cloudObj.set_color(color)

Cloud point colors also can be functionally assigned using:

cloudObj.map_color_from_op(op, rgb)

where op is a function of x,y,z coordinates which return RGB color values. The rgb argument defaults to True, but if assigned False, the function returns HSV color values.

In general, cloud values are initially assigned using one of the three ways referenced above. Once a cloud has values assigned, colors may be assigned from a colormap, cmap, using these values with the method:

cloudObj.map_cmap_from_cloudvals(cmap)

If the cmap argument is not assigned, the default colormap is used, which can be defined in the contructor.

.

Functional Values

Cloud points are assigned scalar values using a function of x,y,z, f, as:

cloudObj.map_vals_from_op(f,cmap=None)

If the cmap argument is assigned, points are color mapped from the values. If the cmap argument is unassigned, all points will have a uniform color.

An equivalent method can be used as:

cloudObj.map_cmap_from_op(f,cmap=None)

However, in this case, if the cmap argument is unassigned, points are color mapped using the default colormap, which can be set in cloud constructor.

For example, consider an offset spherical function of xyz coordinates as:

def example(xyz) :
    x,y,z = ( xyz.T - [-7,5,15] ).T  # .. offset from origin
    return np.sqrt(x**2 + y**2 + z**2)

Then for a cloud object defined within the [-10,20] domain, the visulization of this function, using the Matplotlib jet_r colormap is:

../../_images/cloud_fig_1.png

The colorbar in this figure is constructed from a Matplotlib ScalarMappable object, which is a property of the cloud object:

cloudObj.cBar_ScalarMappable

See the Figure_1 script below which exemplifies the colorbar construction.

.

Cloud Visualization

The cloud object point coordinates and colors are directly accessable so that the Matplotlib scatter plotting method may be used to display the cloud as:

xyz =    cloudObj.points
colors = cloudObj.point_colors
ax.scatter( *xyz, c=colors )

However this can limit the view of the cloud internal structure. To address this limitation, the cloud method add_to3d has two additional arguments to adjust the color transparency throughout the cloud, focus and span, and an argument to view a subdomain of the cloud, subview, as:

cloudObj.add_to3d(ax,*focus,span,subview)

This method does not change the cloud object, only the view on the 3D axes. The focus sets the normalized value color alpha to 1 (opaque) at the focus value, with a decrease in alpha from the focus. The decrease is controlled by the span which ranges from 0.1 to 1.0. The plot below exemplifies the dependency of alpha on these parameters.

../../_images/focus_diagram.png

The default value for span is 0.1 for multiple focus values. For a single focus value, span is set to generate an alpha to be zero at a value boundary. The subview is a domain array to view only a rectangular subsection of the cloud, and defaults to None.

For the above cloud object, the following show two examples of emphasizing regions within the cloud domain:

../../_images/cloud_fig_2.png

The subview argument of this method is a 3 x 2 array specifying a subdomain of the cloud points to be viewed. An example of this argument usage is shown in the following sample values section.

.

Cloud Surfaces

Constant values within a cloud may be visualized by surfaces. A surface is generated from a cloud at constant values using the cloud method:

surface = cloudObj.valsurf(*fval)

where fval are scalar values within the cloud. Using the previous cloud example, the surfaces for values of 10 and 30 is:

../../_images/cloud_fig_3.png

The surface colors are based on the coloration of the cloud values.

In a similar manner, a set of constant valued surfaces within a cloud domain can be constructed as:

surface = cloudObj.valsurfSet(nsurf)

where the nsurf argument is the number of surfaces which have evenly spaced constant values within the domain. Again, using the example cloud, the set of 6 surfaces within the domain is:

../../_images/cloud_fig_4.png

To facilitate constructing a legend for a cloud surface set, the following object method is available:

c,v,n = cloudObj.get_color_for_val(nsurf)

where the return values, c,v,n, are arrays of colors, values, and normalized values. The argument nsurf is either evenly spaced values (as used with valsurfSet ), or an array of values (as used with valsurf ). Note: the normalized values are convenient for setting the focus argument of the add_to3d method. See the Figure_4 script below which exemplifies the legend construction. If the cloud is not colorized using a colormap, the colors array will contain the single cloud color for all values.

.

Sample Values

Cloud points are assigned values from a set of N samples using the object method:

cloudObj.map_vals_from_sampvals(samples, vadj, dreset, cmap)

where the samples parameter is an N X 4 array, each sample having x,y,z coordinates and an associated scalar value, [x,y,z,V]. The minimum sample size is limited by the sample coordinate distribution in the domain.

The boolean argument dreset sets the sample-size/domain. For dreset as True, the cloud object domain is modified to enclose all samples if necessary. For False, the cloud domain is unaffected and any samples out of the cloud domain are excluded. The default for dreset is False.

The string argument vadj sets how the cloud point values throughout the domain are interpolated to the range of the sample values. For varg = ‘c’, the interpolated cloud values are clipped to the minimun/maximun sample values. For varg = ‘s’, interpolated cloud values are linearly scaled to the sample values. For varg = None, the interpolated cloud values are unaffected, which can result in cloud values outside of the sample value range. A smaller sample size will increase the cloud value range within the domain, compared to the sample value range.

As with functional mapping, if the cmap argument is assigned, points are color mapped from the values.

From a random sample of 50, the resulting point cloud is shown below, colormapped base on the sample values. Cloud values were clipped to the sample value range using vadj = ‘c’ . As a result, the scatter colorbar and cloud colorbar are identical.

../../_images/cloud_fig_5.png

Note that the string representation of the object indicates the cloud type (sampleVals) and the number of samples used for contruction.

A comparison among point clouds using the three different vadj values ( None, ‘s’, ‘c’ ) is shown below. Note in this figure, the maximum and minimum values for the samples and the point clouds are given in addition to the colorbar.

../../_images/cloud_fig_A.png

A comparison among the clouds shows several effects of the value interpolation method.

  • For None, the cloud value distribution is continuous. However, regions further from sample coordinates will produce interpolated values beyond the maximum and minimum sample values. This results in the extend range of the colorbar values.

  • For s and None, the color patterns are identical since the interpolated value distributions are identical, only the values have been scaled for s to the sample values.

  • For c, the distributions have been truncated at the lower and upper sample values. The result is an extended color regions for the minimum and maximum values.

  • For s and c, the range in the cloud values is identical to the sample value range.

The influence of the sample domain size is shown in the following figure. In this case, two clouds are generated from the a sample dataset. The difference between the two clouds is one used a smaller subset of the initial domain. As a result, only a subset of the samples are used from the smaller domain by setting the dreset argument to False.

../../_images/cloud_fig_B.png

The upper left axes show the samples in the domain and subdomain. The cloud object for all samples in the domain is shown in the top right. The lower left is a sub-domain cloud, which contains the fewer samples only in the sub-domain. The lower right is a inner view of the full domain. The inner view is set using the subview argument of the add_to3d cloud method. For this case, the sub-domain was assigned to the subview argument, only for the inner view of the full domain cloud.

Even though lower plots show the same region, the cloud view is influenced by the samples external to the view as shown in the right plot.

In a similar manner to the set of surfaces generated from a functional cloud using the valsurfSet method, the sample cloud surface set is shown below:

../../_images/cloud_fig_C.png

.

Sample Density

The density distribution of a set of N samples within a domain can be used to set the point cloud values using:

cloudObj.map_vals_from_sampdens(samples,pdg,dreset,cmap)

where the samples parameter is an N X 3 array, each sample having x,y,z coordinates [x,y,z,V]. A N X 4 array can be passed but only the coordinate information will be used.

The pdg argument controls the normal distribution about a sample point, which is normalized with respect to the domain and sample size. This argument is in the range of 0.5 to 5.0, with a default value of 1.0. As with the sample value method, the dreset sets the sample-size/domain.

As with other value mapping, if the cmap argument is assigned, points are color mapped from the values.

../../_images/cloud_fig_6.png

Note that the string representation of the object indicates the cloud type (sampleDens), the number of samples, and the pdg value used for contruction.

In a similar manner to the surfaces generated from a functional cloud using the valsurf method, the sample density cloud surfaces are shown below for two relative densities of 0.2 and 0.5:

../../_images/cloud_fig_D.png

.

Map Surface From Cloud

Surfaces may be colormapped from a cloud using various surface methods.

For directly coloring a surface from a colored cloud, the following surface method is used:

surface.map_color_from_cloud(cloudObj)

Using this method, surface faces are colored from the colors within the cloud. This method applies to any colored cloud and is useful when the cloud points are not assigned values, as is the case when using map_color_from_op cloud method. If the cloud object has values, the colors associated with the values will be used.

An alternative approach is to first assign cloud values to surface vertices as:

surface.map_vertvals_from_cloud(cloudObj)

Using the vertex values, the vertices colors are mapped from the cloud colormapping. This approach results in the surface colors matching the values from the point cloud. This is advantageous for sample valued clouds because the surface colors match the sample colors for the same values. This is demonstrated in the Comparison of Surface Color Methods from clouds example and the Domain Values from Sample Data animation.

Once surface vertices have values, further colormapping can be applied using:

surface.map_cmap_from_vertvals(cmap)

In this case, the colors from the colormap are normalized with respect to the minimum and maximum vertex values, not the cloud value range.

For example, consider mapping the color of the cloud object in Figure 1 to a dodecahedron within the cloud domain.

../../_images/cloud_fig_7.png

The left and center surface vertices are mapped from the same cloud shown on the right. As a result, both surface have the same value ranges, but these values are a subset of the cloud value range.

The colors for the left surface directly corrospond to the cloud colors for the same value. This is reflected in the colorbar for this surface, which is a subset of the cloud colorbar.

The center surface was further colormapped from the vertex values using the same colormap as the used for the cloud. This further mapping resulted in normalizing the colormap to the surface minimum and maximum values, not normalized to the cloud values. This results in the surface colorbar colors matching the cloud colorbar colors, but the values do not match.

The differences among the surface colormapping techniques is more apparent using colormaps generated using small sample sizes. This is illustrated using a flat planar surface in the domain of only 15 samples, as shown in the Comparison of Surface Color Methods from clouds example,.

Instead of using a point cloud to colormap a surface, surfaces may be directly colormapped for valued samples. First, surface vertices are assigned values directly form the sample values using:

surface.map_vertvals_from_samples(samples,domain)

This method algorithm maps the vertex values from the value of the nearest coordinate samples. This approach can produce large surface color patches for sparsely distributed samples whereas point cloud mapping results in a smoother distribution of values on the surface. This is illlustrated in the figure below for an identical sample set.

../../_images/cloud_fig_8.png

However, mapping the surface directly from samples can be useful for cases then samples are near surface locations. For such conditions, point clouds distributions can vary widely, not representing near surface values, thus not a favorerable approach. The direct sampling method was used for density surface coloring in examples Swiss Roll Surface and MPG Dataset Surface.

.

Example Python Scripts

Functional Value

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

# ___ Figure 1 _____________________________________________________

# 1. Define function to examine .....................................
def example(xyz) :
    x,y,z = ( xyz.T - [-7,5,15] ).T
    return np.sqrt(x**2 + y**2 + z**2)

# 2. Setup and map cloud ............................................
cloudObj = ptc.Point3DCloud(2.5,domain=[-10,20])
cloudObj.map_vals_from_op(example,'jet_r')

# 3. Construct figures, add cloud, and plot ........................
fig = plt.figure(figsize=(5,3.5))
fig.text(.98,.02,'Figure 1',va='bottom',ha='right', color='r')
fig.text(.5,.95,str(cloudObj),va='top',ha='center')
ax = plt.axes(projection='3d', aspect='equal', proj_type='ortho')
ax.set(xlim=[-10,20],ylim=[-10,20],zlim=[-10,20],xlabel='X',ylabel='Y',zlabel='Z')

cloudObj.add_to3d(ax)
scmp = cloudObj.cBar_ScalarMappable
cbar = plt.colorbar(scmp, ax=ax,  shrink=0.8, pad=.15 )
cbar.set_label('cloud values', rotation=270, labelpad = 20)

plt.show()
import numpy as np
import matplotlib.pyplot as plt
import s3dlib.pntcloud as ptc

# ___ Figure 2 _____________________________________________________

# 1. Define function to examine .....................................
def example(xyz) :
    x,y,z = ( xyz.T - [-7,5,15] ).T
    return np.sqrt(x**2 + y**2 + z**2)

# 2. Setup and map cloud ............................................
cloudObj = ptc.Point3DCloud(2.5,domain=[-10,20])
cloudObj.map_vals_from_op(example,'jet_r')

# 3. Construct figures, add cloud, and plot .........................
fig = plt.figure(figsize=(8,3))
fig.text(.98,.02,'Figure 2',va='bottom',ha='right', color='r')
# ....................
fig.text(.14,.98,'focus : 0.0\nspan : 1.0',ha='left',va='top')
ax = fig.add_subplot(121, projection='3d', aspect='equal',proj_type='ortho')
ax.set(xlim=[-10,20],ylim=[-10,20],zlim=[-10,20],xlabel='X',ylabel='Y',zlabel='Z')
cloudObj.add_to3d(ax,0,span=1)
# ....................
fig.text(.53,.98,'focus : 0.24, 0.75\nspan : 0.1',ha='left',va='top')
ax = fig.add_subplot(122, projection='3d', aspect='equal',proj_type='ortho')
ax.set(xlim=[-10,20],ylim=[-10,20],zlim=[-10,20],xlabel='X',ylabel='Y',zlabel='Z')
cloudObj.add_to3d(ax,0.24,0.75,span=0.1)
scmp = cloudObj.cBar_ScalarMappable
cbar = plt.colorbar(scmp, ax=ax,  shrink=0.8, pad=.15 )
cbar.set_label('cloud values', rotation=270, labelpad = 20)
# ....................
fig.tight_layout(pad=2.5)
plt.show()

Cloud Surface

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

# ___ Figure 3 _____________________________________________________

# 1. Define function to examine .....................................
def example(xyz) :
    x,y,z = ( xyz.T - [-7,5,15] ).T
    return np.sqrt(x**2 + y**2 + z**2)

# 2. Setup and map cloud ............................................
cloudObj = ptc.Point3DCloud(2.5,domain=[-10,20])
cloudObj.map_vals_from_op(example,'jet_r')
surface = cloudObj.valsurf(10,30)

# 3. Construct figures, add cloud, and plot ........................
fig = plt.figure(figsize=(5,3.5))
fig.text(.98,.02,'Figure 3',va='bottom',ha='right', color='r')
fig.text(.5,.95,'cloud surface values: 10, 30',va='top',ha='center')
ax = plt.axes(projection='3d', aspect='equal', proj_type='ortho')
ax.set(xlim=[-10,20],ylim=[-10,20],zlim=[-10,20],xlabel='X',ylabel='Y',zlabel='Z')

ax.add_collection3d(surface.shade().hilite(.5))
scmp = cloudObj.cBar_ScalarMappable
cbar = plt.colorbar(scmp, ax=ax,  shrink=0.8, pad=.15 )
cbar.set_label('cloud values', rotation=270, labelpad = 20)

plt.show()
import numpy as np
from matplotlib import patches
import matplotlib.pyplot as plt
import s3dlib.pntcloud as ptc

# ___ Figure 4 _____________________________________________________

# 1. Define function to examine .....................................
def example(xyz) :
    x,y,z = ( xyz.T - [-7,5,15] ).T
    return np.sqrt(x**2 + y**2 + z**2)

# 2. Setup and map cloud ............................................
nsurf = 6

cloudObj = ptc.Point3DCloud(2.5,domain=[-10,20])
cloudObj.map_vals_from_op(example,'jet_r')
surface = cloudObj.valsurfSet(nsurf)

# 3. Construct figures, add cloud, and plot ........................
fig = plt.figure(figsize=(4.5,3.5))
fig.text(.98,.02,'Figure 4',va='bottom',ha='right', color='r')
title = str(cloudObj) +'\n' + str(surface)
fig.text(0.975,0.99,title, ha='right', va='top', fontsize='smaller')
ax = plt.axes(projection='3d', aspect='equal', proj_type='ortho')
ax.set(xlim=[-10,20],ylim=[-10,20],zlim=[-10,20],xlabel='X',ylabel='Y',zlabel='Z')

ax.add_collection3d(surface.shade().hilite(.5))

c,v,n = cloudObj.get_color_for_val(nsurf)
hnd = [ patches.Patch(label='{:.2f}'.format(v[i]), facecolor=c[i]) \
    for i in range(nsurf) ]    
fig.legend(handles=hnd, loc='outside upper left')

plt.show()

Sample values

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

# ___ Figure 5 _____________________________________________________

# 1. generate data samples with values ............................
N,seed,val_mult,domain = 50, 8, 25.0, [ [-1,1], [-1,1], [-1,1] ]
points = 2*Halton(4, seed=seed).random(N) - 1
dt_coor = points[:,0:3]
vals = val_mult*(points[:,3] +1)
points = np.column_stack((dt_coor,vals))
vmin,vmax,vmid = np.min(vals),np.max(vals), ( np.min(vals) + np.max(vals) )/2

# 2. Setup and map point cloud ....................................
drez,vadj,cmap = 3, 'c', 'jet'

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

# 3. Construct figures, add surfaces, and plot ....................
fig = plt.figure(figsize=(8,4))
fig.text(.98,.02,'Figure 5',va='bottom',ha='right', color='r')
# ....................
title = str(cloudObj) +'\nrange: {:.2f} - {:.2f}'.format(*cloudObj.bounds['vlim'])
fig.text(0.25,0.9,title, ha='center', fontsize='small')
ax = fig.add_subplot(121, projection='3d', aspect='equal', proj_type='ortho')
ax.set(xlim=domain[0], ylim=domain[1], zlim=domain[2], xlabel='x',ylabel='y')
cloudObj.add_to3d(ax)
cbar = plt.colorbar(cloudObj.cBar_ScalarMappable, ax=ax,  shrink=0.7, pad=0.1 )
cbar.set_label('cloud values', rotation=270, labelpad = 15)
# ....................
title = 'sample size : {}\nrange: {:.2f} - {:.2f}'.format(N,vmin,vmax)
fig.text(.75,0.9,title,ha='center', fontsize='small')
ax = fig.add_subplot(122, projection='3d', aspect='equal', proj_type='ortho')
ax.set(xlim=domain[0], ylim=domain[1], zlim=domain[2], xlabel='x',ylabel='y')
ax.scatter(*dt_coor.T, s=50, c=vals, cmap=cmap ,edgecolor='k')
s3d.add_boxCorner(ax,domain)
norm = colors.Normalize(vmin,vmax)
cbar =fig.colorbar(cm.ScalarMappable(norm=norm, cmap=cmap), ax=ax,shrink=0.7, pad=.1)
cbar.set_label('sample values', rotation=270, labelpad = 15)
# ....................
fig.tight_layout(pad=1)
plt.show()
import numpy as np
import matplotlib.pyplot as plt
import s3dlib.pntcloud as ptc
from scipy.stats.qmc import Halton

# ___ Figure 6 _____________________________________________________

# 1. generate data samples with values ............................
N,seed,val_mult,domain = 50, 8, 25.0, [ [-1,1], [-1,1], [-1,1] ]
points = 2*Halton(4, seed=seed).random(N) - 1
dt_coor = points[:,0:3]
vals = val_mult*(points[:,3] +1)
points = np.column_stack((dt_coor,vals))
vmin,vmax,vmid = np.min(vals),np.max(vals), ( np.min(vals) + np.max(vals) )/2

# 2. Setup and map point cloud ....................................
drez,cmap = 3, 'YlGnBu_r'

cloudObj = ptc.Point3DCloud(drez,domain=domain)
cloudObj.map_vals_from_sampdens(dt_coor,cmap=cmap)

# 3. Construct figures, add surfaces, and plot ....................
fig = plt.figure(figsize=(5,4))
fig.text(.98,.02,'Figure 6',va='bottom',ha='right', color='r')
fig.text(.5,0.99,str(cloudObj),ha='center',va='top')
ax = plt.axes(projection='3d', aspect='equal')
ax.set(xlim=domain[0], ylim=domain[1], zlim=domain[2],  
    xlabel='x',ylabel='y',zlabel='z')
cloudObj.add_to3d(ax,1,span=1.5)
scmp = cloudObj.cBar_ScalarMappable
cbar = plt.colorbar(scmp, ax=ax,  shrink=0.8, pad=.1 )
cbar.set_label('sample density', rotation=270, labelpad = 15)

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

Cloud Mapped Surface

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

# ___ Figure 7 ______________________________________________________

# 1. Define function to examine .....................................
def example(xyz) :
    x,y,z = ( xyz.T - [-7,5,15] ).T
    return np.sqrt(x**2 + y**2 + z**2)

# 2. Setup and map point cloud ......................................
rez,cmap,dmn = 5, 'jet_r',[-10,20]

cloudObj = ptc.Point3DCloud(2.0,domain=dmn)
cloudObj.map_vals_from_op(example,cmap)

# 3. Construct figures, add surfaces, and plot ......................
fig = plt.figure(figsize=(9,3.4))
fig.text(.98,.02,'Figure 7',va='bottom',ha='right', color='r')
fig.text(.5,.99,'Surface Colormapped from a Cloud',va='top',ha='center', fontsize='x-large')

for i in range(2) :
    ax = fig.add_subplot(131+i, projection='3d', aspect='equal', proj_type='ortho')
    ax.set(xlim=dmn, ylim=dmn, zlim=dmn, xlabel='x',ylabel='y')
    surface = s3d.SphericalSurface.platonic(rez,'dodeca').domain(15)
    surface.transform(translate=[5,5,5])
    surface.map_vertvals_from_cloud(cloudObj)
    if i==1:  surface.map_cmap_from_vertvals(cmap)
    csrc = 'values' if i==1 else 'cloud'
    ax.set_title('color from {}\n( {:.2f} - {:.2f} )'.format(csrc,*surface.bounds['vlim']), fontsize='medium')
    ax.add_collection3d(surface.shade())
    cbar = plt.colorbar(surface.cBar_ScalarMappable, ax=ax,  shrink=0.5, pad=0.1 )
    cbar.set_label('surface values', rotation=270, labelpad = 15, fontsize='medium')
    s3d.add_boxCorner(ax,dmn)

ax = fig.add_subplot(133, projection='3d', aspect='equal', proj_type='ortho')
ax.set(xlim=dmn, ylim=dmn, zlim=dmn, xlabel='x',ylabel='y')
ax.set_title('cloud values\n( {:.2f} - {:.2f} )'.format(*cloudObj.bounds['vlim']), fontsize='medium')
cloudObj.add_to3d(ax)
cbar = plt.colorbar(cloudObj.cBar_ScalarMappable, ax=ax,  shrink=0.5, pad=.15 )
cbar.set_label('cloud values', rotation=270, labelpad = 15, fontsize='medium')
# ....................
fig.tight_layout(pad=0)
plt.show()
import numpy as np
import matplotlib.pyplot as plt
import s3dlib.surface as s3d
import s3dlib.pntcloud as ptc
from scipy.stats.qmc import Halton

# ___ Figure 8 _____________________________________________________

# 1. generate data samples with values ............................
N,seed,val_mult,domain = 50, 8, 25.0, [ [-1,1], [-1,1], [-1,1] ]
points = 2*Halton(4, seed=seed).random(N) - 1
dt_coor = points[:,0:3]
vals = val_mult*(points[:,3] +1)
points = np.column_stack((dt_coor,vals))
vmin,vmax,vmid = np.min(vals),np.max(vals), ( np.min(vals) + np.max(vals) )/2

# 2. Setup and map point cloud ....................................
rez,drez,vadj,cmap = 6, 3, 'c', 'jet'

cloudObj = ptc.Point3DCloud(drez,domain=domain)
cloudObj.map_vals_from_sampvals(points,vadj=vadj,cmap=cmap)
surface_c = s3d.SphericalSurface.platonic(rez,'dodeca')
surface_c.map_vertvals_from_cloud(cloudObj)

surface = s3d.SphericalSurface.platonic(rez,'dodeca')
surface.map_vertvals_from_samples(points,domain=domain)
surface.map_cmap_from_vertvals(cmap)

pobj = s3d.samples_to_object(points,domain,cmap,size=.8)

# 3. Construct figures, add surfaces, and plot ....................
fig = plt.figure(figsize=(8,4))
fig.text(.98,.02,'Figure 8',va='bottom',ha='right', color='r')
title = 'sample size: {}\nsample range: {:.2f} - {:.2f}'.format(N,vmin,vmax)
fig.text(0.5,.01, title, va='bottom', ha='center')
# ....................
title = 'sample value cloud mapped\nsurface.map_vertvals_from_cloud'
title += '\nsurface range: {:.2f} - {:.2f}'.format(*surface_c.bounds['vlim'])
fig.text(0.25,0.99,title, va='top',ha='center')#, fontsize='small')
ax = fig.add_subplot(121, projection='3d', aspect='equal', proj_type='ortho')
ax.set(xlim=domain[0], ylim=domain[1], zlim=domain[2], xlabel='x',ylabel='y')
ax.add_collection3d((surface_c+pobj).shade())
s3d.add_boxCorner(ax,domain)
scmp = surface_c.cBar_ScalarMappable
cbar = plt.colorbar(scmp, ax=ax,  shrink=0.6, pad=.1 )
cbar.set_label('surface values', rotation=270, labelpad = 15)
# ....................
title = 'nearest sample mapped\nsurface.map_vertvals_from_samples'
title += '\nsurface range: {:.2f} - {:.2f}'.format(vmin,vmax)
fig.text(.75,0.99,title, va='top',ha='center')#, fontsize='small')
ax = fig.add_subplot(122, projection='3d', aspect='equal', proj_type='ortho')
ax.set(xlim=domain[0], ylim=domain[1], zlim=domain[2], xlabel='x',ylabel='y')
ax.add_collection3d((surface+pobj).shade())
s3d.add_boxCorner(ax,domain)
scmp = surface.cBar_ScalarMappable
cbar = plt.colorbar(scmp, ax=ax,  shrink=0.6, pad=.1 )
cbar.set_label('surface values', rotation=270, labelpad = 15)
# ....................
fig.tight_layout(pad=1)
plt.show()