def rootSpI(img, list_remove=[], sc=None, lut_range=False, verbose=False):
    """
    case where the data is a spatialimage
    """
    # -- cells are positionned inside a structure, the polydata, and assigned a scalar value.
    polydata, polydata2 = img2polydata_complexe(img,
                                                list_remove=list_remove,
                                                sc=sc,
                                                verbose=verbose)
    m = tvtk.PolyDataMapper(input=polydata.output)
    m2 = tvtk.PolyDataMapper(input=polydata2.output)

    # -- definition of the scalar range (default : min to max of the scalar value).
    if sc:
        ran = [sc[i] for i in sc.keys() if i not in list_remove]
        if (lut_range != None) and (lut_range != False):
            print lut_range
            m.scalar_range = lut_range[0], lut_range[1]
        else:
            m.scalar_range = np.min(ran), np.max(ran)
    else:
        m.scalar_range = np.min(img), np.max(img)

    # -- actor that manage changes of view if memory is short.
    a = tvtk.QuadricLODActor(mapper=m)
    a.property.point_size = 8
    a2 = tvtk.QuadricLODActor(mapper=m2)
    a2.property.point_size = 8
    #scalebar
    if lut_range != None:
        sc = tvtk.ScalarBarActor(orientation='vertical',
                                 lookup_table=m.lookup_table)
    return a, a2, sc, m, m2
Example #2
0
    def vtk_actors(self):
        if (self.actors is None):
            self.actors = []
            points = _getfem_to_tvtk_points(self.sl.pts())
            (triangles, cv2tr) = self.sl.splxs(2)
            triangles = numpy.array(triangles.transpose(), 'I')
            data = tvtk.PolyData(points=points, polys=triangles)
            if self.scalar_data is not None:
                data.point_data.scalars = numpy.array(self.scalar_data)
            if self.vector_data is not None:
                data.point_data.vectors = numpy.array(self.vector_data)
            if self.glyph_name is not None:
                mask = tvtk.MaskPoints()
                mask.maximum_number_of_points = self.glyph_nb_pts
                mask.random_mode = True
                mask.input = data

                if self.glyph_name == 'default':
                    if self.vector_data is not None:
                        self.glyph_name = 'arrow'
                    else:
                        self.glyph_name = 'ball'

                glyph = tvtk.Glyph3D()
                glyph.scale_mode = 'scale_by_vector'
                glyph.color_mode = 'color_by_scalar'
                #glyph.scale_mode = 'data_scaling_off'
                glyph.vector_mode = 'use_vector'  # or 'use_normal'
                glyph.input = mask.output
                if self.glyph_name == 'arrow':
                    glyph.source = tvtk.ArrowSource().output
                elif self.glyph_name == 'ball':
                    glyph.source = tvtk.SphereSource().output
                elif self.glyph_name == 'cone':
                    glyph.source = tvtk.ConeSource().output
                elif self.glyph_name == 'cylinder':
                    glyph.source = tvtk.CylinderSource().output
                elif self.glyph_name == 'cube':
                    glyph.source = tvtk.CubeSource().output
                else:
                    raise Exception("Unknown glyph name..")
                #glyph.scaling = 1
                #glyph.scale_factor = self.glyph_scale_factor
                data = glyph.output

            if self.show_faces:
                ##                if self.deform is not None:
                ##                    data.point_data.vectors = array(numarray.transpose(self.deform))
                ##                    warper = tvtk.WarpVector(input=data)
                ##                    data = warper.output
                ##                lut = tvtk.LookupTable()
                ##                lut.hue_range = 0.667,0
                ##                c=gf_colormap('tripod')
                ##                lut.number_of_table_values=c.shape[0]
                ##                for i in range(0,c.shape[0]):
                ##                    lut.set_table_value(i,c[i,0],c[i,1],c[i,2],1)

                self.mapper = tvtk.PolyDataMapper(input=data)
                self.mapper.scalar_range = self.scalar_data_range
                self.mapper.scalar_visibility = True
                # Create mesh actor for display
                self.actors += [tvtk.Actor(mapper=self.mapper)]
            if self.show_edges:
                (Pe, E1, E2) = self.sl.edges()
                if Pe.size:
                    E = numpy.array(
                        numpy.concatenate((E1.transpose(), E2.transpose()),
                                          axis=0), 'I')
                    edges = tvtk.PolyData(points=_getfem_to_tvtk_points(Pe),
                                          polys=E)
                    mapper_edges = tvtk.PolyDataMapper(input=edges)
                    actor_edges = tvtk.Actor(mapper=mapper_edges)
                    actor_edges.property.representation = 'wireframe'
                    #actor_edges.property.configure_traits()
                    actor_edges.property.color = self.edges_color
                    actor_edges.property.line_width = self.edges_width
                    actor_edges.property.ambient = 0.5
                    self.actors += [actor_edges]
            if self.sl.nbsplxs(1):
                # plot tubes
                (seg, cv2seg) = self.sl.splxs(1)
                seg = numpy.array(seg.transpose(), 'I')
                data = tvtk.Axes(origin=(0, 0, 0),
                                 scale_factor=0.5,
                                 symmetric=1)
                data = tvtk.PolyData(points=points, lines=seg)
                tube = tvtk.TubeFilter(radius=0.4,
                                       number_of_sides=10,
                                       vary_radius='vary_radius_off',
                                       input=data)
                mapper = tvtk.PolyDataMapper(input=tube.output)
                actor_tubes = tvtk.Actor(mapper=mapper)
                #actor_tubes.property.representation = 'wireframe'
                actor_tubes.property.color = self.tube_color
                #actor_tubes.property.line_width = 8
                #actor_tubes.property.ambient = 0.5

                self.actors += [actor_tubes]

            if self.use_scalar_bar:
                self.scalar_bar = tvtk.ScalarBarActor(
                    title=self.scalar_data_name,
                    orientation='horizontal',
                    width=0.8,
                    height=0.07)
                self.scalar_bar.position_coordinate.coordinate_system = 'normalized_viewport'
                self.scalar_bar.position_coordinate.value = 0.1, 0.01, 0.0
                self.actors += [self.scalar_bar]

            if (self.lookup_table is not None):
                self.set_colormap(self.lookup_table)

        return self.actors
Example #3
0
mesh = tvtk.PolyData(points=points, polys=triangles)
mesh.point_data.scalars = temperature

# Set the mapper to scale temperature range
# across the entire range of colors
mapper = tvtk.PolyDataMapper()
configure_input_data(mapper, mesh)
mapper.scalar_range = min(temperature), max(temperature)

# Create mesh actor for display
actor = tvtk.Actor(mapper=mapper)

# Create a scalar bar
scalar_bar = tvtk.ScalarBarActor(title="Temperature",
                                 orientation='horizontal',
                                 width=0.8,
                                 height=0.17,
                                 lookup_table=mapper.lookup_table)
scalar_bar.position_coordinate.coordinate_system = 'normalized_viewport'
scalar_bar.position_coordinate.value = 0.1, 0.01, 0.0

# Use the ScalarBarWidget so we can drag the scalar bar around.
sc_bar_widget = tvtk.ScalarBarWidget(interactor=interactor,
                                     scalar_bar_actor=scalar_bar)

# Now add the actors to the renderer and start the interaction.
renderer.add_actor(actor)
interactor.initialize()
# Enable the widget so the scalar bar can be seen.  Press 'i' to
# disable the widget.
sc_bar_widget.enabled = True
Example #4
0
def legendActor(actor):
    """Return a TVTK actor representing the legend of another actor."""

    scalar_bar = tvtk.ScalarBarActor()
    scalar_bar.lookup_table = actor.mapper.lookup_table
    return scalar_bar
    polygons.insert_next_cell(cell)

# Create a mesh from these lists
mesh = tvtk.PolyData()
mesh.points = verts
mesh.polys = polygons
mesh.point_data.scalars = temperature

# Set the mapper to scale temperature range
# across the entire range of colors
mapper = tvtk.PolyDataMapper()
mapper.input = mesh
mapper.scalar_range = temperature.range

# Create a scalar bar
scalar_bar = tvtk.ScalarBarActor()
scalar_bar.lookup_table = mapper.lookup_table
scalar_bar.title = "Temperature"
scalar_bar.position_coordinate.coordinate_system = 'normalized_viewport'
scalar_bar.position_coordinate.value = 0.1, 0.01, 0.0
scalar_bar.orientation = "horizontal"
scalar_bar.width = 0.8
scalar_bar.height = 0.17

actor = tvtk.Actor()
actor.mapper = mapper

window = SimpleVtkWindow()
window.add_actor(actor)
window.add_actor(scalar_bar)
window.start()