3 A tvtk based converter for JSON file dumped from tests 5 Convert a bunch of individual blobs JSON files into one: 7 jq -s . test-pdsp-*.json|jq '{blobs:[.[]|.blobs|.[0]]}' > test-pdsp.json 13 from tvtk.api
import tvtk, write_data
18 def main(outname=None, *infiles):
19 if outname
is None or outname ==
"-":
20 outname = os.path.splitext(infile)[0]
24 for infile
in infiles:
25 jdat = json.loads(
open(infile).
read())
26 jblobs += jdat[
"blobs"]
27 jpoints += jdat.get(
"points", [])
34 ofile = outname +
'-blobs.vtu' 36 write_data(blobdata, ofile)
40 print (
"no points to convert")
43 ofile = outname +
"-points.vtp" 45 write_data(pointdata, ofile)
50 Make a mayavi pipeline to produce an immediate display. 53 from mayavi
import mlab
55 mlab.pipeline.surface(blobdata)
59 def test(filename = "blob2tvtk_test.vtk"):
60 points = numpy.asarray([
73 ugrid = tvtk.UnstructuredGrid(points=points)
78 pt_ids += list(range(4))
80 pt_ids += list(range(4,8))
84 pt_ids += [ind, ind2, 4+ind2, 4+ind]
87 ptype = tvtk.Polyhedron().cell_type
88 ugrid.insert_next_cell(ptype, pt_ids)
90 ugrid.cell_data.scalars = [1.0]
91 ugrid.cell_data.scalars.name =
"unity" 93 ugrid.cell_data.add_array([2.0])
94 ugrid.cell_data.get_array(1).name =
"duality" 95 ugrid.cell_data.add_array([3.0])
96 ugrid.cell_data.get_array(2).name =
"trinity" 98 w = tvtk.UnstructuredGridWriter(file_name=filename)
99 configure_input(w, ugrid)
102 if '__main__' == __name__:
def test(filename="blob2tvtk_test.vtk")
int open(const char *, int)
Opens a file descriptor.
def visualize_blobs(blobdata)
std::enable_if< internal::is_string< String >::value >::type print(std::FILE *f, const text_style &ts, const String &format_str, const Args &...args)
int read(int, char *, size_t)
Read bytes from a file descriptor.
def main(outname=None, infiles)