Пример #1
0
 def add_isocontour(self, val=None):
     if val is None: val = (self._max_val + self._min_val) * 0.5
     isocontour = tvtk.ContourFilter(executive=tvtk.CompositeDataPipeline())
     isocontour.input = self._hdata_set
     isocontour.generate_values(1, (val, val))
     lut_manager = LUTManager(data_name=self.field, scene=self.scene)
     isocontour_normals = tvtk.PolyDataNormals(
         executive=tvtk.CompositeDataPipeline())
     isocontour_normals.input_connection = isocontour.output_port
     iso_mapper = tvtk.HierarchicalPolyDataMapper(
         input_connection=isocontour_normals.output_port,
         lookup_table=lut_manager.lut)
     iso_mapper.scalar_range = (self._min_val, self._max_val)
     iso_actor = tvtk.Actor(mapper=iso_mapper)
     self.scene.add_actors(iso_actor)
     self.operators.append(
         MappingIsoContour(operator=isocontour,
                           vmin=self._min_val,
                           vmax=self._max_val,
                           vdefault=val,
                           mapper=iso_mapper,
                           post_call=self.scene.render,
                           lut_manager=lut_manager,
                           scene=self.scene))
     return self.operators[-1]
Пример #2
0
    def __init__(self, **traits):
        self.property = self.actor.property

        HasTraits.__init__(self, **traits)
        self._create_points(self.coords, self.indices)
        self._color_changed(self.color)
        self._visibility_changed(self.visibility)
        normals = tvtk.PolyDataNormals(input=self.polydata)
        m = tvtk.PolyDataMapper(
            input=normals.output)  # the usual vtk pipleine countinuation
        self.actor.mapper = m
        self.property = self.actor.property
        self.property.representation = self.representation
        show_actor(self.actor)  # passing the actors function for rendering
        self.viewer = get_viewer()  # getting the ivtk viewer
        self.property.on_trait_change(self.viewer.scene.render)
        self.actor.on_trait_change(self.viewer.scene.render)
Пример #3
0
    z = numpy.reshape(numpy.transpose(5.0 * numpy.sin(r) / r), (-1, ))

# Now set the scalar data for the StructuredPoints object.  The
# scalars of the structured points object will be a view into our
# Numeric array.  Thus, if we change `z` in-place, the changes will
# automatically affect the VTK arrays.
sp.point_data.scalars = z

# Convert this to a PolyData object.
geom_filter = tvtk.ImageDataGeometryFilter(input=sp)

# Now warp this using the scalar value to generate a carpet plot.
warp = tvtk.WarpScalar(input=geom_filter.output)

# Smooth the resulting data so it looks good.
normals = tvtk.PolyDataNormals(input=warp.output)

# The rest of the VTK pipeline.
m = tvtk.PolyDataMapper(input=normals.output, scalar_range=(min(z), max(z)))
a = tvtk.Actor(mapper=m)

ren = tvtk.Renderer(background=(0.5, 0.5, 0.5))
ren.add_actor(a)

# Get a nice view.
cam = ren.active_camera
cam.azimuth(-60)
cam.roll(90)

# Create a RenderWindow, add the renderer and set its size.
rw = tvtk.RenderWindow(size=(600, 600))
Пример #4
0
def make_surf_actor(x,
                    y,
                    z,
                    warp=1,
                    scale=[1.0, 1.0, 1.0],
                    make_actor=True,
                    *args,
                    **kwargs):
    """Creates a surface given regularly spaced values of x, y and the
    corresponding z as arrays.  Also works if z is a function.
    Currently works only for regular data - can be enhanced later.

    Parameters
    ----------
    
        x -- Array of x points (regularly spaced)

        y -- Array if y points (regularly spaced)

        z -- A 2D array for the x and y points with x varying fastest
        and y next.  Also will work if z is a callable which supports
        x and y arrays as the arguments.

        warp -- If true, warp the data to show a 3D surface
        (default = 1).        

        scale -- Scale the x, y and z axis as per passed values.
        Defaults to [1.0, 1.0, 1.0].

        make_actor -- also create actors suitably (default True)

        args -- additional positional arguments for func()
        (default is empty)

        kwargs -- a dict of additional keyword arguments for func()
        (default is empty)
    """

    if callable(z):
        zval = numpy.ravel(sampler(x, y, z, *args, **kwargs))
        x, y = squeeze(x), squeeze(y)
    else:
        x, y = squeeze(x), squeeze(y)
        _check_sanity(x, y, z)
        zval = numpy.ravel(z)
        assert len(zval) > 0, "z is empty - nothing to plot!"

    xs = x * scale[0]
    ys = y * scale[1]
    data = _create_structured_points_direct(xs, ys, zval)
    if not make_actor:
        return data
    if warp:
        geom_f = tvtk.ImageDataGeometryFilter(input=data)

        warper = tvtk.WarpScalar(input=geom_f.output, scale_factor=scale[2])
        normals = tvtk.PolyDataNormals(input=warper.output, feature_angle=45)

        mapper = tvtk.PolyDataMapper(input=normals.output,
                                     scalar_range=(min(zval), max(zval)))
    else:
        mapper = tvtk.PolyDataMapper(input=data,
                                     scalar_range=(min(zval), max(zval)))
    actor = _make_actor(mapper=mapper)
    return data, actor
data = tvtk.PolyData(points=points, polys=cells, lines=lines)
data.point_data.scalars = numpy.linspace(-5,5,6)

lm = LUTManager()
#lm.configure_traits()
map = tvtk.PolyDataMapper(input=data)
map.lookup_table = lm.lut
act = tvtk.Actor(mapper=map)

x,y = numpy.ogrid[-5:5:0.1, -5:5:0.1]
r = x**2 + y**2
z = numpy.cos(r*2) * numpy.exp(-r/3)

img = tvtk.ImageData(origin=(2,2,2), spacing=(0.1,0.1,0.1),
                    dimensions = (z.shape[0], z.shape[1],1 ))
img.point_data.scalars=z.ravel()

img_poly = tvtk.GeometryFilter(input=img)
warp = tvtk.WarpScalar(input_connection=img_poly.output_port)
norm = tvtk.PolyDataNormals(input_connection = warp.output_port)
img_map = tvtk.PolyDataMapper(input_connection=norm.output_port)
img_act = tvtk.Actor(mapper=img_map)

ren = tvtk.Renderer()
#ren.add_actor(act)
ren.add_actor(img_act)

renwin = tvtk.RenderWindow()
renwin.add_renderer(ren)
iren = tvtk.RenderWindowInteractor(render_window=renwin)
iren.start()
Пример #6
0
 def test_help_trait(self):
     """Test if the help attribute is correct."""
     n = tvtk.PolyDataNormals()
     t = n.traits()
     test = t['splitting'].help != t['non_manifold_traversal'].help
     self.assertEqual(test, True)