Skip to content

Commit

Permalink
A FunctionImageData class which is to ImageData as FunctionDataSource…
Browse files Browse the repository at this point in the history
… is to ArrayDataSource.
  • Loading branch information
cwebster committed Oct 2, 2010
1 parent 58b475b commit 8f56b57
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions enthought/chaco/function_image_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from enthought.chaco.api import DataRange2D, ImageData

# Adapted (ie. copied and modified) from function_data_source.

# Given the time frequently required for image manipulation,
# it would be awesome if there was a mechanism for returning
# partial results as they become available.

class FunctionImageData(ImageData):
""" A class that provides data for a 2-D image based upon the range
supplied.
Computation should be fairly swift for acceptable interactive performance.
"""

# The function to call with the low and high values of the range
# in the x and y dimensions. It should return a 2-D array of values.
func = Callable

# the 2D data_range required for the data shown
data_range = Instance(DataRange2D)

def __init__(self, **kw):
super(FunctionImageData, self).__init__(**kw)
# Explicitly construct the initial data set for ImageData
self.recalculate()

@on_trait_change('data_range.updated')
def recalculate(self):
if self.func is not None and self.data_range is not None:
newarray = self.func(self.data_range.x_range.low, self.data_range.x_range.high,
self.data_range.y_range.low, self.data_range.y_range.high)
ImageData.set_data(self, newarray)
else:
self._data = array([], dtype=float)

def set_data(self, *args, **kw):
raise RuntimeError("Cannot set numerical data on a FunctionDataSource")

def set_mask(self, mask):
# This would be REALLY FREAKING SLICK, but it's currently unimplemented
raise NotImplementedError

def remove_mask(self):
raise NotImplementedError

0 comments on commit 8f56b57

Please sign in to comment.