def _compute_cached_image(self, selection_masks=None): """ Updates the cached image. """ self._cached_image = None if not self._mapped_image_cache_valid: # Clear the old image. We don't need the extra memory lying around # as we compute the new mapped image. self._cached_mapped_image = None self._cached_mapped_image =\ self.value_mapper.map_screen(self.value.data) self._cached_mapped_image *= 255 self._cached_mapped_image = \ self._cached_mapped_image.astype('uint8') if selection_masks is not None: if len(selection_masks) > 0: mask = selection_masks[0].copy() for m in selection_masks[1:]: mask |= m else: mask = zeros(self._cached_mapped_image.shape[:2], dtype=bool) # Apply the selection fade, from speedups.py apply_selection_fade(self._cached_mapped_image, mask, self.fade_alpha, self.fade_background) self._mapped_image_cache_valid = True ImagePlot._compute_cached_image(self, self._cached_mapped_image)
def _render(self, gc): """ Ensures that the cached image is valid. Called before _render() is called. Implements the Base2DPlot interface. """ if not self._mapped_image_cache_valid: if 'selection_masks' in self.value.metadata: self._compute_cached_image(self.value.metadata['selection_masks']) else: self._compute_cached_image() ImagePlot._render(self, gc)
def _compute_cached_image(self, selection_masks=None): """ Updates the cached image. """ if self.cache_full_map: if not self._mapped_image_cache_valid: self._cached_mapped_image = self._cmap_values(self.value.data, selection_masks) self._mapped_image_cache_valid = True mapped_value = self._cached_mapped_image ImagePlot._compute_cached_image(self, mapped_value) else: self._mapped_image_cache_valid = True ImagePlot._compute_cached_image(self, self.value.data, mapper=lambda data: self._cmap_values(data))
def main(): swm = OceanModel() plot = ImagePlot(swm) swm.set_plot(plot) import enaml with enaml.imports(): from ocean_view import OceanView view = OceanView(model=swm, plot=plot) view.show()
def main(): swm = ShallowWaterModel() plot = ImagePlot(swm) swm.set_plot(plot) import enaml with enaml.imports(): from swm_view import SimpleView view = SimpleView(model=swm, plot=plot) view.show()
def main(): swm = StormModel() plot = ImagePlot(swm) swm.set_plot(plot) import enaml with enaml.imports(): from storm_view import StormView view = StormView(model=swm, plot=plot) view.show()
def main(): swm = WindDrivenModel() plot = ImagePlot(swm) swm.set_plot(plot) import enaml with enaml.imports(): from wind_view import WindView view = WindView(model=swm, plot=plot) view.show()
def _compute_cached_image(self, selection_masks=None): """ Updates the cached image. """ if not self._mapped_image_cache_valid: cached_mapped_image = \ self.value_mapper.map_screen(self.value.data) * 255 if selection_masks is not None: # construct a composite mask mask = zeros(cached_mapped_image.shape[:2], dtype=bool) for m in selection_masks: mask = mask | m invmask = invert(mask) # do a cheap alpha blend with our specified color cached_mapped_image[invmask,0:3] = \ self.fade_alpha*(cached_mapped_image[invmask,0:3] - self.fade_background) + self.fade_background self._cached_mapped_image = cached_mapped_image self._mapped_image_cache_valid = True mapped_value = self._cached_mapped_image ImagePlot._compute_cached_image(self, mapped_value.astype("UInt8"))