Beispiel #1
0
    def insert_layer(self, index, image, colormap=None, opacity=1.0):
        """ Insert a new layer at specified position. The colormap defaults to
            a gray colormap. If the colormap's display range is None, it 
            defaults to the image range.
        """

        if colormap is None:
            colormap = Colormap(colormaps["gray"], None, False, False, False)

        if colormap.display_range is None:
            colormap.display_range = (image.data.min(), image.data.max())

        # Find out which layer class we will use
        LayerClass = Layer.get_derived_class(image)
        if LayerClass is None:
            raise medipy.base.Exception("Cannot create layer")

        # Create the layer and insert it
        if self._layers and index == 0:
            self._layers[0].remove_observer("colormap",
                                            self._on_layer_colormap)

        layer = LayerClass(self.world_to_slice, image,
                           self.display_coordinates, colormap, opacity)
        self._layers.insert(index, layer)

        # Update the physical extent
        self._compute_extent()

        # The scalar bar will always reflect layer 0
        if index == 0:
            self._on_layer_colormap(None)
            self._layers[0].add_observer("colormap", self._on_layer_colormap)

        # Adjust layer w.r.t. the current state.
        self._update_layers_positions()
        if self._cursor_physical_position is not None:
            layer.physical_position = self._cursor_physical_position
#        if isinstance(layer, ImageLayer) :
#            layer.actor.SetInterpolate(self._interpolation)

# And finally add it to the renderer
        self._renderer.AddActor(layer.actor)