Esempio n. 1
0
 def setup_pipeline(self):
     mask = MaskPoints()
     mask.filter.set(generate_vertices=True, random_mode=True)
     self.mask = mask
     v = UserDefined(filter=tvtk.SelectVisiblePoints(),
                     name='VisiblePoints')
     self.visible_points = Optional(filter=v, enabled=False)
     mapper = tvtk.LabeledDataMapper()
     self.mapper = mapper
     self.actor = Actor2D(mapper=mapper)
     self.property = mapper.label_text_property
     self.property.on_trait_change(self.render)
     self.components = [self.mask, self.visible_points, self.actor]
def create_labels(img, render):
    liste = list(img.labels())
    xmin = 0
    xLength = 1000
    xmax = xmin + xLength
    ymin = 00
    yLength = 1000
    ymax = ymin + yLength
    # Create labels for barycenters
    m = tvtk.PolyData()
    vertex = tvtk.Points()
    provi1 = tvtk.LongArray()
    p = 0
    cell_barycentre = img.center_of_mass()
    x, y, z = img.image.resolution
    for c, toto in enumerate(liste):
        vertex.insert_point(p, cell_barycentre[c][0] / x,
                            cell_barycentre[c][1] / y,
                            cell_barycentre[c][2] / z)
        provi1.insert_value(p, toto)
        p += 1

    m.points = vertex
    m.point_data.scalars = provi1
    vtkLabels = m
    #here the idea is to mask labels behind surfaces
    visPts = tvtk.SelectVisiblePoints()
    visPts.input = vtkLabels
    visPts.renderer = render
    visPts.selection_window = 1
    visPts.selection = (xmin, xmin + xLength, ymin, ymin + yLength)
    # Create the mapper to display the point ids.  Specify the format to
    # use for the labels.  Also create the associated actor.
    ldm = tvtk.LabeledDataMapper()
    # ldm.SetLabelFormat("%g")
    ldm.input = visPts.output
    ldm.label_mode = 'label_scalars'
    vtk_labels = tvtk.Actor2D()
    vtk_labels.mapper = ldm
    return vtk_labels