def _read_vtk_file(fname): """Given a .vtk file (or .vtk.gz), read it and return the output. """ if fname.endswith('.vtk.gz'): tmpfname = tempfile.mktemp(suffix='.vtk') with open(tmpfname, 'wb') as tmpf: data = gzip.open(fname).read() tmpf.write(data) r = tvtk.DataSetReader(file_name=tmpfname) else: tmpfname = None r = tvtk.DataSetReader(file_name=fname) r.update() if tmpfname is not None: os.remove(tmpfname) return r.output
def test_write_data_vtk(self): "Old-style VTK file writing with specified extension" datasets = self.datasets for d in datasets: fh, fname = tempfile.mkstemp('.vtk') os.close(fh) os.remove(fname) self.assertEqual(os.path.exists(fname), False) write_data(d, fname) self.assertEqual(os.path.exists(fname), True) r = tvtk.DataSetReader(file_name=fname) r.update() self.assertEqual(isinstance(r.output, d.__class__), True) os.remove(fname)
def __set_pure_state__(self, state): z = state.data if z is not None: d = gunzip_string(z) r = tvtk.DataSetReader(read_from_input_string=1, input_string=d) warn = r.global_warning_display r.global_warning_display = 0 r.update() r.global_warning_display = warn self.data = r.output # Now set the remaining state without touching the children. set_state(self, state, ignore=['children', 'data']) # Setup the children. handle_children_state(self.children, state.children) # Setup the children's state. set_state(self, state, first=['children'], ignore=['*'])