def _create_structured_points_direct(x, y, z=None): """Creates a StructuredPoints object given input data in the form of numpy arrays. Input Arguments: x -- Array of x-coordinates. These should be regularly spaced. y -- Array of y-coordinates. These should be regularly spaced. z -- Array of z values for the x, y values given. The values should be computed such that the z values are computed as x varies fastest and y next. If z is None then no scalars are associated with the structured points. Only the structured points data set is created. """ nx = len(x) ny = len(y) if z is not None: nz = numpy.size(z) assert nx*ny == nz, "len(x)*len(y) != len(z)"\ "You passed nx=%d, ny=%d, nz=%d"%(nx, ny, nz) xmin, ymin = x[0], y[0] dx, dy = (x[1] - x[0]), (y[1] - y[0]) sp = tvtk.StructuredPoints(dimensions=(nx, ny, 1), origin=(xmin, ymin, 0), spacing=(dx, dy, 1)) if z is not None: sp.point_data.scalars = numpy.ravel(z) sp.point_data.scalars.name = 'scalars' return sp
def setUp(self): datasets = [ tvtk.ImageData(), tvtk.StructuredPoints(), tvtk.RectilinearGrid(), tvtk.StructuredGrid(), tvtk.PolyData(), tvtk.UnstructuredGrid(), ] exts = ['.vti', '.vti', '.vtr', '.vts', '.vtp', '.vtu'] self.datasets = datasets self.exts = exts
def test_tvtk_dataset_name(self): "Can tvtk datasets can be converted to names correctly." datasets = [ tvtk.ImageData(), tvtk.StructuredPoints(), tvtk.RectilinearGrid(), tvtk.StructuredGrid(), tvtk.PolyData(), tvtk.UnstructuredGrid(), tvtk.Property(), # Not a dataset! 'foo', # Not a TVTK object. ] expect = [ 'image_data', 'image_data', 'rectilinear_grid', 'structured_grid', 'poly_data', 'unstructured_grid', 'none', 'none' ] result = [pipeline_info.get_tvtk_dataset_name(d) for d in datasets] self.assertEqual(result, expect)
def StructuredPointProbe(self, nx, ny, nz, bounding_box=None): """ Probe the unstructured grid dataset using a structured points dataset. """ bbox = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0] if bounding_box == None: bbox = self.ugrid.bounds else: bbox = bounding_box spacing = [0.0, 0.0, 0.0] if nx > 1: spacing[0] = (bbox[1] - bbox[0]) / (nx - 1.0) if ny > 1: spacing[1] = (bbox[3] - bbox[2]) / (ny - 1.0) if nz > 1: spacing[2] = (bbox[5] - bbox[4]) / (nz - 1.0) sgrid = tvtk.StructuredPoints(dimensions=(nx, ny, nz), origin=[bbox[0], bbox[2], bbox[4]], spacing=spacing) probe = tvtk.ProbeFilter(source=self.ugrid, input=sgrid) probe.update() return probe.output
The example is a little contrived since there are better ways of achieving the same effect but the present form nicely illustrates item 2 mentioned above. """ # Author: Prabhu Ramachandran <*****@*****.**> # Copyright (c) 2004-2007, Enthought, Inc. # License: BSD Style. from enthought.tvtk.api import tvtk import numpy import time # First create a structured points data set. sp = tvtk.StructuredPoints(origin=(-10., -10., 0.0), dimensions=(80, 80, 1), spacing=(0.25, 0.25, 0.0)) # Create some nice data at these points. x = numpy.arange(-10., 10., 0.25) y = x r = numpy.sqrt(x[:, None]**2 + y**2) # We need the transpose so the data is as per VTK's expected format # where X coords vary fastest, Y next and then Z. try: import scipy.special z = numpy.reshape(numpy.transpose(5.0 * scipy.special.j0(r)), (-1, )) except ImportError: z = numpy.reshape(numpy.transpose(5.0 * numpy.sin(r) / r), (-1, )) # Now set the scalar data for the StructuredPoints object. The
Xg, Yg, Zg = np.mgrid[nx1:nx2:im, ny1:ny2:jm, nz1:nz2:km] # Make the data. dims = np.array((nf0, nf1, nf2)) vol = np.array((0, L, 0, L, 0, L)) origin = vol[::2] spacing = (vol[1::2] - origin) / (dims - 1) xmin, xmax, ymin, ymax, zmin, zmax = vol x, y, z = np.ogrid[xmin:xmax:dims[0] * 1j, ymin:ymax:dims[1] * 1j, zmin:zmax:dims[2] * 1j] x, y, z = [t.astype('f') for t in (x, y, z)] from enthought.tvtk.api import tvtk spoints = tvtk.StructuredPoints(origin=origin, spacing=spacing, dimensions=dims) #scalars = np.log10(den +1) scalars = nstream # Make the tvtk dataset. spoints = tvtk.StructuredPoints(origin=origin, spacing=spacing, dimensions=dims) s = scalars.transpose().copy() spoints.point_data.scalars = np.ravel(s) spoints.point_data.scalars.name = 'scalars' dirOutput = "./vti/"
# License: BSD style. from numpy import arange, sqrt, sin from enthought.tvtk.api import tvtk from enthought.mayavi.scripts import mayavi2 # Generate the scalar values. x = (arange(0.1, 50.0)-25)/2.0 y = (arange(0.1, 50.0)-25)/2.0 r = sqrt(x[:,None]**2+y**2) z = 5.0*sin(r)/r # # Make the tvtk dataset. # tvtk.ImageData is identical and could also be used here. spoints = tvtk.StructuredPoints(origin=(-12.5,-12.5,0), spacing=(0.5,0.5,1), dimensions=(50,50,1)) # Transpose the array data due to VTK's implicit ordering. VTK assumes # an implicit ordering of the points: X co-ordinate increases first, Y # next and Z last. We flatten it so the number of components is 1. spoints.point_data.scalars = z.T.flatten() spoints.point_data.scalars.name = 'scalar' # Uncomment the next two lines to save the dataset to a VTK XML file. #w = tvtk.XMLImageDataWriter(input=spoints, file_name='spoints2d.vti') #w.write() # Now view the data. @mayavi2.standalone def view(): from enthought.mayavi.sources.vtk_data_source import VTKDataSource
def test_information_keys(self): """Test if vtk information objects can be created.""" s = tvtk.StructuredPoints() x = s.FIELD_ARRAY_TYPE() y = tvtk.Information() x.get(y)