def view_kdtree(kdtree, bbox=[[-1., 1.], [-1., 1.], [-1., 1.]], radius=0.05): import numpy as np scene = pgl.Scene() sphere = pgl.Sphere(radius, slices=16, stacks=16) silver = pgl.Material(ambient=(49, 49, 49), diffuse=3., specular=(129, 129, 129), shininess=0.4) gold = pgl.Material(ambient=(63, 50, 18), diffuse=3., specular=(160, 141, 93), shininess=0.4) if isinstance(kdtree, KDNode): dim = kdtree.axis plane_bbox = [b for i, b in enumerate(bbox) if i != dim] plane_points = [] plane_points += [ np.insert([plane_bbox[0][0], plane_bbox[1][0]], dim, kdtree.pivot[dim]) ] plane_points += [ np.insert([plane_bbox[0][0], plane_bbox[1][1]], dim, kdtree.pivot[dim]) ] plane_points += [ np.insert([plane_bbox[0][1], plane_bbox[1][1]], dim, kdtree.pivot[dim]) ] plane_points += [ np.insert([plane_bbox[0][1], plane_bbox[1][0]], dim, kdtree.pivot[dim]) ] left_bbox = np.copy(bbox).astype(float) right_bbox = np.copy(bbox).astype(float) left_bbox[dim, 1] = kdtree.pivot[dim] right_bbox[dim, 0] = kdtree.pivot[dim] scene += pgl.Shape(pgl.Translated(kdtree.pivot, sphere), gold) scene += view_kdtree(kdtree.left_child, bbox=left_bbox, radius=radius) scene += view_kdtree(kdtree.right_child, bbox=right_bbox, radius=radius) # scene += pgl.Shape(pgl.Polyline(plane_points+[plane_points[0]],width=2),pgl.Material(ambient=(0,0,0))) scene += pgl.Shape( pgl.Polyline(plane_points + [plane_points[0]], width=2), pgl.Material(ambient=tuple(list(np.insert([0, 0], dim, 255))))) scene += pgl.Shape(pgl.FaceSet(plane_points, [range(4)]), pgl.Material(ambient=(0, 0, 0), transparency=0.6)) else: assert (type(kdtree) == list) or (isinstance(kdtree, np.ndarray)) for p in kdtree: scene += pgl.Shape(pgl.Translated(p, sphere), silver) return scene
def transform4(matrix, shape): """ Return a shape transformed by a Matrix4. """ if matrix == None: matrix = pgl.Matrix4() scale, (a, e, r), translation = matrix.getTransformation2() if type(shape) is pgl.Cylinder and matrix != pgl.Matrix4(): #print "scale for cylinder is :", scale #print "scale.xyz = ", scale.x, scale.y, scale.z if round(scale.x, 1) == 1.0 and round(scale.y, 1) == 1.0 and round( scale.z, 1) == 1.0: shape = pgl.Translated(translation, pgl.EulerRotated(a, e, r, shape)) else: raise Exception, "Invalid transformation for cylinder!" elif type(shape) is pgl.Sphere: shape = pgl.Translated( translation, pgl.EulerRotated(a, e, r, pgl.Scaled(scale, shape))) elif type(shape) is pgl.BezierPatch: scale1 = pgl.Vector3(1, 1, 1) shape = pgl.Translated( translation, pgl.EulerRotated(a, e, r, pgl.Scaled(scale, pgl.Scaled(scale1, shape)))) else: shape = pgl.Translated( translation, pgl.EulerRotated(a, e, r, pgl.Scaled(scale, shape))) return shape
def cones(obj, **kwds): X_attr = kwds.get('X_attr', 'X') Y_attr = kwds.get('Y_attr', 'Y') pos_dist = kwds.get('dist', 'Distance') pos_az = kwds.get('az', 'Azimuth') circ_attr = kwds.get('circ_attr', 'Circonference') height_attr = kwds.get('height_attr', 'Haut') botHoup_attr = kwds.get('botHoup', 'BaseHoup') radiusHoup_prefix = kwds.get('radiusHoup_prefix', 'r_houp') radiusHoup = kwds.get('radiusHoup', None) wood = kwds.get('wood', True) rgb = kwds.get('rgb', None) spec_name = kwds.get('spec_name', 'houppier_mat') if not obj.__dict__.has_key("posX") and not obj.__dict__.has_key("posY"): try: r = obj.__dict__[pos_dist] a = obj.__dict__[pos_az] obj.posX = r * cos(radians(forest2geomAZ(a))) obj.posY = r * sin(radians(forest2geomAZ(a))) except KeyError: obj.posX = obj.__dict__[X_attr] obj.posY = obj.__dict__[Y_attr] ht = 100 * (obj.__dict__[height_attr] - obj.__dict__[botHoup_attr]) rd_kz = [k for k in obj.__dict__.keys() if radiusHoup_prefix in k] radii = [obj.__dict__[k] for k in rd_kz] if radiusHoup: if radiusHoup == 'Max': cone_radius = 1.0 * max(radii) else: cone_radius = obj.__dict__[radiusHoup] else: cone_radius = 1.0 * sum(radii) / len(radii) #cone_radius = ht/2. h = pgl.Translated( pgl.Vector3(obj.posX, obj.posY, obj.__dict__[botHoup_attr] * 100), pgl.Cone(cone_radius, ht, 1, 12)) tr = pgl.Translated( pgl.Vector3(obj.posX, obj.posY, 0), pgl.Cylinder(obj.__dict__[circ_attr] / (2 * pi), obj.__dict__[botHoup_attr] * 100 + ht * 0.1)) if rgb == None: s_h = pgl.Shape(h, stand_material(spec_name=spec_name)) else: r, g, b = rgb s_h = pgl.Shape(h, stand_material(r, g, b, spec_name)) s_tr = pgl.Shape( tr, stand_material(spec_name="trunk_mat"), ) # s_h.id*10 ) if wood: return (s_h, s_tr) else: return (s_h, )
def transform_geom(geom, translation, rotation): # force cast to float (pgl does not accept values extracted from numpy arryas translation = map(float, translation) if isinstance(geom, pgl.Geometry): geom = pgl.Translated(translation, pgl.AxisRotated((0, 0, 1), rotation, geom)) elif isinstance(geom, pgl.Shape): geom = pgl.Shape( pgl.Translated(translation, pgl.AxisRotated((0, 0, 1), rotation, geom.geometry))) return geom
def arrow(x,y,z,length,az=0, el=0, radius=None, color=color(255,255,255),id=0): if radius==None: radius=length*0.05 rad_az = math.radians(az) rad_el = math.pi/2 - math.radians(el) v = pgl.Vector3( x, y, z ) c = pgl.Cylinder(radius, length*0.8, 10) con =pgl.Translated(pgl.Vector3(0,0,length*0.7), pgl.Cone(2*radius, length*0.3)) arr = pgl.Group([c,con]) dir_arr = pgl.EulerRotated(rad_az,rad_el,0,arr) tr_dir_arr = pgl.Translated(v,dir_arr) return pgl.Shape(tr_dir_arr, color, id)
def setup_func(): sc = pgl.Scene() sc += pgl.Shape(pgl.Box(1, 1, 1), red, id=1) sc += pgl.Shape(pgl.Translated(4, 4, 6, pgl.Sphere(1)), blue, id=2) sc += pgl.Shape(pgl.Translated(2, 3, -3, pgl.Cone(1, 2)), green, id=3) sc += pgl.Shape(pgl.Translated(-8, 3, -2, pgl.Box(4, 2, 0.5)), blue, id=4) sc += pgl.Shape(pgl.Translated( -4, -2, 5, pgl.EulerRotated(3.14, 2.7, 0, pgl.Cone(2, 5))), green, id=5) sc += pgl.Shape(pgl.Translated(4, -3, -3, pgl.Sphere(2)), red, id=6) return sc
def representation(self): mat = pgl.Material('mblue',(0,0,200),transparency=0.8) mat2 = pgl.Material('mred',(200,0,0),transparency=0.8) if not self.maxvalue: self.maxvalue = max(self.values) if self.maxvalue <= 0: return pgl.Scene() sc = pgl.Scene() for i, v in enumerate(self.values): size = v/(2*self.maxvalue) if size > 1e-2: sc += pgl.Shape(pgl.Translated(self.getVoxelCenterFromId(i),pgl.Box(self.getVoxelSize()*size)),mat,i) else: sc += pgl.Shape(pgl.Translated(self.getVoxelCenterFromId(i),pgl.Box(self.getVoxelSize()*0.1)),mat2,i) return sc
def stolon2d(g, v, turtle): scale= 1./5 cyl = pgl.Cylinder(0.01,0.5) cyl2 = pgl.Cylinder(0.01,0.2) cyl3 = pgl.Cylinder(0.01,0.2) cyl = pgl.AxisRotated(axis=(0,1,0), angle= radians(30.), geometry= cyl) cyl2 = pgl.AxisRotated(axis=(0,1,0), angle= -radians(120.), geometry= cyl2) cyl3 = pgl.AxisRotated(axis=(0,1,0), angle= -radians(180.), geometry= cyl3) cyl2= pgl.Translated((0.26,0,0.45),cyl2) cyl3= pgl.Translated((0.26,0,0.45),cyl3) sto= pgl.Group([cyl,cyl2,cyl3]) turtle.customGeometry(sto)
def replicate_scene(scene, domain, replicate=None): """ replicate the scene around the domain """ if replicate is None: newscene = scene newdomain = domain else: dx = abs(domain[0][0] - domain[1][0]) dy = abs(domain[0][1] - domain[1][1]) newscene = pgl.Scene() for tx in (-dx, 0, dx): for ty in (-dy, 0, dy): rep = scene.deepcopy() for sh in rep: sh.geometry = pgl.Translated(tx, ty, 0, sh.geometry) newscene += rep newdomain = ((domain[0][0] - dx, domain[0][1] - dy), (domain[1][0] + dx, domain[1][1] + dy)) if replicate == 1: replicate = None else: replicate -= 1 newscene, newdomain = replicate_scene(newscene, newdomain, replicate) return newscene, newdomain
def leaf(**kwds): global __myLeaf if __myLeaf is None: __myLeaf = mangoLeaf(alpha=20) rp = rdm_pos((1, 1, 1)) rx, ry, rz = rp.x, rp.y, rp.z az, el, rl = rdm_orientation() x = kwds.get('x', rx) y = kwds.get('y', ry) z = kwds.get('z', rz) delta = kwds.get('rotz', az) phi = kwds.get('roty', el) psi = kwds.get('rotx', rl) size = kwds.get('len', 10.0) color = kwds.get('color', __niceGreen) if not size: size = 10.0 print "length is None, using 10 instead : small leaf" v = pgl.Vector3(x, y, z) #print "leaf size : ", size #sx = pgl.Vector3(4,1,1) * size/40. #scaled_geometry = pgl.Scaled(sx, pgl.Translated(pgl.Vector3(0.5,0,0), pgl.Disc(0.5, 6)) ) sx = pgl.Vector3(1, 1, 1) * size / 10. scaled_geometry = pgl.Scaled(sx, __myLeaf.geometry) rotated_geometry = pgl.EulerRotated(delta, phi, psi, scaled_geometry) tr = pgl.Translated(v, rotated_geometry) return pgl.Shape(tr, color)
def visualise_plants(g, vids=[], positions=[]): max_scale = g.max_scale() t = pgl.PglTurtle() if not vids: vids = g.component_roots_at_scale(g.root, scale=max_scale) x = -9 y = -12 dx = 2. dy = 4. positions = [(x+(count%9)*dx,y+(count/9)*dy,0) for count in range(len(vids))] else: vids = [cid for vid in vids for cid in g.component_roots_at_scale_iter(vid, scale=max_scale)] assert len(vids) == len(positions) n= len(vids) scenes = pgl.Scene() for i, vid in enumerate(vids): #position = (x+(count%9)*dx,y+(count/9)*dy,0) position = positions[i] t = pgl.PglTurtle() #t.move(position) scene = turtle.traverse_with_turtle(g, vid, visitor=strawberry_visitor, turtle=t, gc=False) ds = scene.todict() for shid in ds: for sh in ds[shid]: sh.geometry = pgl.Translated(position, sh.geometry) scenes.add(sh) return scenes
def disc( x,y,z, color=color( 30,10,140 ) ): v = pgl.Vector3( x, y, z ) d = pgl.Disc( 0.4, 5 ) azimuth, elevation, roll= rdm_orientation() rotated_geometry= pgl.EulerRotated(azimuth, elevation, roll, d) tr = pgl.Translated( v,rotated_geometry ) return pgl.Shape( tr, color )
def toPglScene( self, geometry=None ): """ Generate a PlantGL scene of the MST with the given geometry which size must be normalized ( < 1), default is a box """ if self.dim < 4: scene = pgl.Scene() if geometry == None: geometry = pgl.Box(0.4) ( ptList, size ) = self.absolutePos() #x = y = z = 0 for pt in ptList : try: x = pt[ 0 ] except IndexError: x = 0 try: y = pt[ 1 ] except IndexError: y = 0 try: z = pt[ 2 ] except IndexError: z = 0 scene.add( pgl.Translated( (x, y, z), geometry )) else: print "Bad dimension" return scene
def plotSkyTurtle(): pgl.Viewer.start() sc = pgl.Scene() for i in range(len(elevations)): pos = pgl.Vector3(pgl.Vector3.Spherical(30,radians(azimuths[i]),radians(90-elevations[i]))) sc += pgl.Shape(pgl.Translated(pos,pgl.Sphere(0.5)),pgl.Material(),i+1) pgl.Viewer.display(sc) return sc
def transform4(matrix, shape): """ Return a shape transformed by a Matrix4. """ scale, (a, e, r), translation = matrix.getTransformation2() shape = pgl.Translated(translation, pgl.Scaled(scale, pgl.EulerRotated(a, e, r, shape))) return shape
def test_scene(): ds = pgl.Sphere() t = pgl.Tapered(1., 1., ds) t2 = pgl.Translated(0., 0., 1., ds) sc = pgl.Scene([ pgl.Shape(t, pgl.Material((255, 0, 0))), pgl.Shape(t2, pgl.Material((0, 255, 0))) ]) jsonconversion(sc)
def Unileaflet(length=1., width=1.): disc = pgl.Translated((-0.5,0,0), pgl.Disc()) disc = pgl.Scaled((length, width,1), disc) disc = pgl.AxisRotated(axis=(0,1,0), angle=radians(90.), geometry=disc) d3 = pgl.AxisRotated(axis=(1,0,0), angle=0., geometry=disc) shape = pgl.Group([d3]) return shape
def test81(leaf=leaf, scene=None): global translation, yt, zt if scene is None: scene = pgl.Scene() Viewer.display(scene) mesh = fitting.leaf_shape2(leaf, 10, 7, 7, 1) scene += pgl.Translated(translation + (0, yt / 3., 0), mesh) Viewer.update()
def _common_init( self, **keys ): """ """ if "height" in keys: self._height = keys[ "height" ] else: self._height = pgl.norm( keys[ "axis" ] ) self._radius = keys[ "radius" ] self.shaft = pgl.Scaled(pgl.Vector3(1, 1, AARROW_SHAFT_PROPORTION), ACYLINDER_PRIMITIVE ) self.head = pgl.Translated(pgl.Vector3(0, 0, AARROW_SHAFT_PROPORTION), pgl.Scaled(pgl.Vector3( AARROW_HEAD_PROPORTION,AARROW_HEAD_PROPORTION,1-AARROW_SHAFT_PROPORTION), ACONE_PRIMITIVE) )
def sphere(x, y, z, radius=0.4, color=color(80, 200, 100), slice=5, stack=5, id=0): v = pgl.Vector3(x, y, z) s = pgl.Sphere(radius, slice, stack) tr = pgl.Translated(v, s) return pgl.Shape(tr, color, id)
def plotDirect( latitude, longitude, jourJul, startH, stopH, step=30, decalSun = 1, decalGMT = 0): # Plots Sun trajectory in the sky during a given Julian day, at given latitudes and longitudes # and at hours of the day defined in hours (typically between startH = 0.0 and stopH = 23.5) # decalSun is the time zone (fuseau horaire), e.g. +1 for Paris sunPos = getDirectLight( latitude, longitude, jourJul, startH, stopH, step, decalSun, decalGMT ) sc = pgl.Scene() for i in range(len(sunPos)): #print sunPos[i][0],sunPos[i][1], sunPos[i][2] pos = pgl.Vector3(pgl.Vector3.Spherical(30,radians( sunPos[i][0] ), radians( 90 - sunPos[i][1] ) )) sc += pgl.Shape(pgl.Translated(pos,pgl.Sphere(1)),pgl.Material(),i+1) pgl.Viewer.display(sc) return sc
def add_sun(scene, sun, distance=5, radius=0.1): elevation, azimuth, luminance = sun colors = jet_colors(luminance) pgl_colors = [pgl.Material(pgl.Color3(r, g, b)) for r, g, b in colors] sph = pgl.Sphere(radius) #red = pgl.Material(pgl.Color3(150, 0, 0)) pos = cartesian(elevation, azimuth, distance) pgl_pos = [pgl.Vector3(*p) for p in pos] for i, vect in enumerate(pgl_pos): shape = pgl.Translated(vect, sph) scene.add(pgl.Shape(shape, pgl_colors[i])) return scene
def dart_display(self, radius=0.1, coef=0.8, add=False): import openalea.plantgl.all as pgl sphere = pgl.Sphere(radius,slices=16,stacks=16) coal = pgl.Material(ambient=(8,10,13),diffuse=3.,specular=(89,89,89),shininess=0.3) purple = pgl.Material(ambient=(72,28,72),diffuse=2.,specular=(89,89,89),shininess=0.3) green = pgl.Material(ambient=(0,88,9),diffuse=2.,specular=(89,89,89),shininess=0.3) blue = pgl.Material(ambient=(9,0,88),diffuse=2.,specular=(89,89,89),shininess=0.3) font = pgl.Font(size=10) s = pgl.Scene() dart_points = {} for dart in self.darts(): dart_point = self.get_position(dart) dart_face_center = self.element_center(dart,2) dart_edge_center = self.element_center(dart,1) dart_face_point = dart_face_center + coef*(dart_point-dart_face_center) dart_face_edge_center = dart_face_center + coef*(dart_edge_center-dart_face_center) dart_edge_point = dart_face_edge_center + coef*(dart_face_point-dart_face_edge_center) dart_middle_edge_point = dart_face_edge_center + 0.33*(dart_edge_point-dart_face_edge_center) dart_points[dart] = [dart_edge_point,dart_middle_edge_point] s += pgl.Shape(pgl.Translated(dart_points[dart][0],sphere),coal) # s += pgl.Shape(pgl.Translated(np.mean(dart_points[dart],axis=0), pgl.Text(str(dart),fontstyle=font)), coal, id=dart) s += pgl.Shape(pgl.Polyline(dart_points[dart],width=2),coal) for dart in self.darts(): alpha_0_points = [] alpha_0_points += [dart_points[dart][1]] alpha_0_points += [dart_points[self.alpha(0,dart)][1]] s += pgl.Shape(pgl.Polyline(alpha_0_points,width=5),purple) alpha_1_points = [] alpha_1_points += [0.66*dart_points[dart][0] + 0.33*dart_points[dart][1]] alpha_1_points += [0.66*dart_points[self.alpha(1,dart)][0] + 0.33*dart_points[self.alpha(1,dart)][1]] s += pgl.Shape(pgl.Polyline(alpha_1_points,width=5),green) alpha_2_points = [] alpha_2_points += [0.33*dart_points[dart][0] + 0.66*dart_points[dart][1]] alpha_2_points += [0.33*dart_points[self.alpha(2,dart)][0] + 0.66*dart_points[self.alpha(2,dart)][1]] s += pgl.Shape(pgl.Polyline(alpha_2_points,width=5),blue) if add : pgl.Viewer.add(s) else : pgl.Viewer.display(s)
def plotDirect(latitude, longitude, jourJul, startH, stopH, step=30, decalSun=1, decalGMT=0): sunPos = getDirectLight(latitude, longitude, jourJul, startH, stopH, step, decalSun, decalGMT) sc = pgl.Scene() for i in range(len(sunPos)): # print sunPos[i][0],sunPos[i][1], sunPos[i][2] pos = pgl.Vector3(pgl.Vector3.Spherical(30, radians(sunPos[i][0]), radians(90 - sunPos[i][1]))) sc += pgl.Shape(pgl.Translated(pos, pgl.Sphere(1)), pgl.Material(), i + 1) pgl.Viewer.display(sc) return sc
def test1(leaf=leaf, scene=None): """ Fit the leaf, create a mesh and draw it with plantGL. """ global translation if scene is None: scene = pgl.Scene() Viewer.display(scene) x, y, s, r = leaf spline_leaf, leaf_surface = fitting.fit_leaf(x, y, s, r) mesh = fitting.discretize(spline_leaf, 30, 7, 1) scene += pgl.Translated(translation, mesh) Viewer.update()
def show_sources(sun, north=0, scene=None, distance=5, radius=0.1): sc = pgl.Scene() if scene is not None: sc.add(scene) elevation, azimuth, luminance = [numpy.array(x) for x in sun] az = -(azimuth + north) colors = jet_colors(luminance) pgl_colors = [pgl.Material(pgl.Color3(r, g, b)) for r, g, b in colors] sph = pgl.Sphere(radius) pos = cartesian(elevation, az, distance) pgl_pos = [pgl.Vector3(*p) for p in pos] for i, vect in enumerate(pgl_pos): shape = pgl.Translated(vect, sph) sc.add(pgl.Shape(shape, pgl_colors[i])) pgl.Viewer.display(sc) return sc
def leaflet(length=1., width=1.): """ return ------ a strawberry leaf composed of three discs """ disc = pgl.Translated((-0.5, 0, 0), pgl.Disc()) disc = pgl.Scaled((length, width, 1), disc) disc = pgl.AxisRotated(axis=(0, 1, 0), angle=radians(90.), geometry=disc) d1 = pgl.AxisRotated(axis=(1, 0, 0), angle=-radians(60.), geometry=disc) d2 = pgl.AxisRotated(axis=(1, 0, 0), angle=-radians(-60.), geometry=disc) d3 = pgl.AxisRotated(axis=(1, 0, 0), angle=0., geometry=disc) shape = pgl.Group([d1, d2, d3]) return shape
def __init__(self, pos=ASHAPE3D_STANDARD_POS, axis=ASHAPE3D_STANDARD_AXIS, roll=ASHAPE3D_STANDARD_ROLL, scale=ASHAPE3D_STANDARD_SCALE, material=ASHAPE3D_STANDARD_MATERIAL, geometry=None, **keys): """Default constructor. Parameters: pos : Vector3 convertable pos of the object (look below), axis : Vector3 convertable main axis of the object, should be defined to describe the rotation. The Z of the primitive geometry would point to axis, roll : Real Property: rotation of the object around main axis, scale : Vector3 convertable to use while resizing the object. While scaling the Z corresponds to main axis of the object, material : pgl.Material describes the appearance of the object, geometry : pgl.Geometry describes the geometry of the object. """ if not geometry: raise Exception("AShape3D: geometry not defined.") self.geometry = geometry #TODO check for custom rotation, scale, transformation objects (shared between shapes) self.scaled = pgl.Scaled(scale, self.geometry) # roll related self._roll = roll #: to keep internal roll self.rolled = pgl.AxisRotated(pgl.Vector3.OZ, self._roll, self.scaled) # axis related (even the object which do not have intuitive axis need to have predefined axis self._axis = axis #: to keep internal axis vector rotation_axis = pgl.cross(pgl.Vector3.OZ, self._axis) rotation_angle = pgl.angle(self._axis, pgl.Vector3.OZ) self.rotated = pgl.AxisRotated(rotation_axis, rotation_angle, self.rolled) # position related self.translated = pgl.Translated(pos, self.rotated) # apperance related self.shape = pgl.Shape(self.translated, material)
def plot_spline_surface(ctrl_net, points): """ Parameters ========== - ctrl_net : the net of control points (list of list) - points : a set of evaluated points (list of list) """ scene = pgl.Scene() n = len(points) m = len(points[0]) # Compute a mesh (i.e. TriangleSet) for the set of points pointList = [pt for rank in points for pt in rank] indexList = [] for i in range(n - 1): for j in range(m - 1): ii = i * m + j i1 = (ii, ii + 1, ii + m) i2 = (ii + 1, ii + m + 1, ii + m) indexList.append(i1) indexList.append(i2) surf = pgl.Shape(pgl.TriangleSet(pointList, indexList), appearance=pgl.Material((12, 125, 12))) scene.add(surf) # plot the control net n = len(ctrl_net) m = len(ctrl_net[0]) for pts in ctrl_net: crv = pgl.Shape(geometry=pgl.Polyline(pts), appearance=pgl.Material((125, 12, 12))) scene.add(crv) for pt in pts: scene.add( pgl.Shape( pgl.Translated(pgl.Vector3(pt), pgl.Sphere(radius=0.1)))) for i in range(m): pts = [ctrl_net[j][i] for j in range(n)] crv = pgl.Shape(geometry=pgl.Polyline(pts), appearance=pgl.Material((12, 12, 125))) scene.add(crv) pgl.Viewer.display(scene)
def unileaflet(length=1., width=1.): """Generates a unileaflet shape :param length: length of the shape, defaults to 1. :type length: float, optional :param width: width of the shape, defaults to 1. :type width: float, optional :return: the shape :rtype: pgl.Group """ disc = pgl.Translated((-0.5,0,0), pgl.Disc()) disc = pgl.Scaled((length, width,1), disc) disc = pgl.AxisRotated(axis=(0,1,0), angle=radians(90.), geometry=disc) d3 = pgl.AxisRotated(axis=(1,0,0), angle=0., geometry=disc) shape = pgl.Group([d3]) return shape