-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A FunctionImageData class which is to ImageData as FunctionDataSource…
… 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.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |