Bunny ContoursΒΆ

../../_images/bunny_contours1.png

Contours may be constructed from any surface object. These contours are from the surface object shown in the Stanford Bunny example.

import matplotlib.pyplot as plt
import s3dlib.surface as s3d

# Contours on a general surface object.

# 1.  Stanford Bunny Obj datafile ................................
bsurf = s3d.get_surfgeom_from_obj("data/bunny.obj", color='k', cmap='Wistia')

# note: the bsurf-object native coordinates are Cartesian..(xyz)
radial_distance = lambda xyz : s3d.SphericalSurface.coor_convert(xyz)[0]

# 2. Setup surface ................................................

# center the object for cylindrical and spherical contours.
sc = [ -(bsurf.bounds['xlim'][1]+bsurf.bounds['xlim'][0])/2 ,
       -(bsurf.bounds['xlim'][1]+bsurf.bounds['xlim'][0])/2 ,
       -(bsurf.bounds['zlim'][1]+bsurf.bounds['zlim'][0])/2  ] 
bsurf.transform(translate=sc)
bsurf.map_cmap_from_op( radial_distance ).shade() # effectively, shade contours.

contours = bsurf.contourLineSet(30,coor='s') # contour color taken from surface.

# 3. Construct figure, add surface, plot ..........................
fig = plt.figure(figsize=plt.figaspect(1), facecolor='k')
fig.text(0.975,0.975,'Spherical Contours', ha='right', va='top', 
      color='y' , fontsize='x-large')
ax = plt.axes(projection='3d', aspect='equal', facecolor='k')
ax.set_axis_off()

s3d.auto_scale(ax,bsurf,uscale=.9)
ax.add_collection3d(contours.fade())

fig.tight_layout(pad=0)

plt.show()