3 Common functions for *2tvtk.py 7 from collections
import defaultdict
8 from tvtk.api
import tvtk, write_data
9 from tvtk.common
import configure_input
15 make a 3d set of cells based on ring of pts extruded along X axis by dx 17 Return points and "relative cells" 21 pts2 = [ [pt[0]+dx,pt[1],pt[2]]
for pt
in pts]
26 bot_cell = range(n, 2*n)
27 cells = [top_cell, bot_cell]
32 cell = [top_cell[ind], top_cell[ind2], bot_cell[ind2], bot_cell[ind]]
50 ang = math.atan2(p[2]-c[2], p[1]-c[1]);
51 byang.append((ang, p))
53 return [p
for a,p
in byang]
57 Given a data structure which is a list of blobs, each blob is a dict: 60 points=[[x1,y1,z1], [x2,y2,z2],...], 61 values=dict(name1=val1, name2=val2), 62 thickness=1.0, # optional 65 return an unstructured grid 71 myvalnames = list(blob[
'values'].
keys())
72 datasetnames = datasetnames.union(myvalnames)
74 pts,cells =
extrude(pts, blob.get(
'thickness', 1.0))
76 blob_cells.append((len(pts),cells))
78 ugrid = tvtk.UnstructuredGrid(points=all_points)
80 ptype = tvtk.Polyhedron().cell_type
83 for npts,cells
in blob_cells:
84 cell_ids = [len(cells)]
86 cell_ids.append(len(cell))
87 cell_ids += [offset+cid
for cid
in cell]
88 ugrid.insert_next_cell(ptype, cell_ids)
91 ugrid.cell_data.scalars = list(range(len(blobs)))
92 ugrid.cell_data.scalars.name =
"indices" 96 for datasetname
in sorted(datasetnames):
97 arr = [b[
"values"].
get(datasetname, 0.0)
for b
in blobs]
98 ugrid.cell_data.add_array(arr)
99 ugrid.cell_data.get_array(narrays).name = datasetname
107 Given a data strucutre which lists point data as list of objects like: 110 values=dict(name1=val1, name2=val2, ...) 115 for n
in one[
'values'].
keys():
118 values = defaultdict(list)
123 for name
in datasetnames:
124 values[name].
append(one[
'values'].
get(name, 0.0))
128 indices.append(count)
129 points = numpy.array(points,
'f')
130 npoints = len(points)
132 ret = tvtk.PolyData(points=points)
133 verts = numpy.arange(0, npoints, 1)
134 verts.shape = (npoints,1)
136 ret.point_data.scalars = indices[:npoints]
137 ret.point_data.scalars.name =
'indices' 138 for count, datasetname
in enumerate(sorted(datasetnames)):
140 arr = [p[
"values"].
get(datasetname, 0.0)
for p
in jdat]
141 ret.point_data.add_array(numpy.array(arr,
'f'))
142 ret.point_data.get_array(count).name = datasetname
auto enumerate(Iterables &&...iterables)
Range-for loop helper tracking the number of iteration.
def orderpoints(pointset)
Configuration append(Configuration &a, Configuration &b)
Return an array which is composed of the array b appended to the array a.
auto const & get(AssnsNode< L, R, D > const &r)