Skip to content

Instantly share code, notes, and snippets.

@ericspod
Created May 16, 2018 19:22
Show Gist options
  • Save ericspod/b6181b8570396e3055866a978e58cef5 to your computer and use it in GitHub Desktop.
Save ericspod/b6181b8570396e3055866a978e58cef5 to your computer and use it in GitHub Desktop.
Piecewise CR Test
from eidolon import *
# The Catmull-Rom basis types assume a fixed set of control points: 4 for 1D, 4**2 for 2D, and 4**3 for 3D.
# The piecewise Catmull-Rom allows a definition with an arbitrarily sized lattice of control points which is
# then divided up into individual elements which share control points of neighbours. The line example in the
# wiki shows an element composed of 3 lines. To allow the configuration of the element type, the basis function
# which returns coefficients for piecewise Catmull-Rom accepts extra parameters in addition to the xi coordinates
# (u,v,w): `ul', `vl', `wl' stating the dimensions of the control point lattice, `limits' stating for each dimension if
# the interpolation is to continue to the end of the lattice at either end of that dimension or even loop around,
# and `circular' for each dimension which states if the element loops around such that control points on the ends can be
# joined to make a new element. Looping is useful for defining contours, otherwise the typical case is `limits' of 0
# for each end of each dimension so that all control points define geometry instead of just derivative.
# This defines a new element type generator which is fixed for 1D elements with 5 control points
def fixedpiecewiseCatmullRomType(geom,desc,order):
linelength=5
# 1 pair of limit values per dimension, 0 means interpolate to end of lattice, 1 is stop 1 from end, -1 is loop to other side
limits=[(0,1)] # try (1,1) or (0,0) to see the difference
# 1 boolean value per dimension, stating if that dimension is continuous, eg. (True,) for contour, (True,False) for cylinder
circular=(False,)
et=piecewiseCatmullRomType(geom,desc,order) # get the old definition, the returned object is fresh
# replace its basis with our own lambda function with our supplied arguments
oldbasis=et.basis
et.basis=lambda u,v,w:oldbasis(u,v,w,ul=linelength,limits=limits,circular=circular)
return et
# add the new generator function
BasisGenFuncs.append('PCR4','Fixed PCR',fixedpiecewiseCatmullRomType)
m2=mgr.cloneMaterial('Default') # create a point material
m2.setPointSizeAbs(3.0)
m2.useLighting(False)
m2.useDepthCheck(False)
m2.setDiffuse(color(0.75,0,0))
# define a line with 5 control points, same length as linelength above
contour=[vec3(),vec3(1,0,0.5),vec3(1.5,0.2,1.25),vec3(2,1.5,1),vec3(3,2,-1)]
inds=[list(range(len(contour)))]
# create the object
ds=PyDataSet('pcr',contour,[('inds',ElemType._Line1PCR4,inds)])
obj=MeshSceneObject('pcrtest',ds)
mgr.addSceneObject(obj)
# create the representation of that object
rep=obj.createRepr(ReprType._cylinder,32,radrefine=16)
mgr.addSceneObjectRepr(rep)
mgr.showBoundBox(rep)
# create a node representation
rep=obj.createRepr(ReprType._node)
mgr.addSceneObjectRepr(rep)
mgr.showBoundBox(rep)
rep.applyMaterial(m2)
mgr.setCameraSeeAll()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment