Package topo :: Package base :: Module patterngenerator :: Class PatternGenerator
[hide private]
[frames] | no frames]

Class PatternGenerator

source code


A class hierarchy for callable objects that can generate 2D patterns.

Once initialized, PatternGenerators can be called to generate a value or a matrix of values from a 2D function, typically accepting at least x and y.

A PatternGenerator's Parameters can make use of Parameter's precedence attribute to specify the order in which they should appear, e.g. in a GUI. The precedence attribute has a nominal range of 0.0 to 1.0, with ordering going from 0.0 (first) to 1.0 (last), but any value is allowed.

The orientation and layout of the pattern matrices is defined by the SheetCoordinateSystem class, which see.

Note that not every parameter defined for a PatternGenerator will be used by every subclass. For instance, a Constant pattern will ignore the x, y, orientation, and size parameters, because the pattern does not vary with any of those parameters. However, those parameters are still defined for all PatternGenerators, even Constant patterns, to allow PatternGenerators to be scaled, rotated, translated, etc. uniformly.

Nested Classes [hide private]

Inherited from param.parameterized.Parameterized: __metaclass__

Instance Methods [hide private]
 
__call__(self, **params_to_override)
Call the subclass's 'function' method on a rotated and scaled coordinate system.
source code
 
_setup_xy(self, bounds, xdensity, ydensity, x, y, orientation)
Produce pattern coordinate matrices from the bounds and density (or rows and cols), and transforms them according to x, y, and orientation.
source code
 
function(self, p)
Function to draw a pattern that will then be scaled and rotated.
source code
 
_create_and_rotate_coordinate_arrays(self, x, y, orientation)
Create pattern matrices from x and y vectors, and rotate them to the specified orientation.
source code
 
_apply_mask(self, p, mat)
Create (if necessary) and apply the mask to the given matrix mat.
source code

Inherited from param.parameterized.Parameterized: __getstate__, __init__, __repr__, __setstate__, __str__, debug, defaults, force_new_dynamic_value, get_param_values, get_value_generator, inspect_value, message, print_param_values, script_repr, set_default, set_dynamic_time_fn, set_param, state_pop, state_push, verbose, warning

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __setattr__, __sizeof__, __subclasshook__

Class Methods [hide private]

Inherited from param.parameterized.Parameterized: params, print_param_defaults

Class Variables [hide private]
  __abstract = True
bool(x) -> bool
  bounds = BoundingRegionParameter(default= BoundingBox(points= ...
BoundingBox of the area in which the pattern is generated.
  xdensity = param.Number(default= 10, bounds= (0, None), preced...
Density (number of samples per 1.0 length) in the x direction.
  ydensity = param.Number(default= 10, bounds= (0, None), preced...
Density (number of samples per 1.0 length) in the y direction.
  x = param.Number(default= 0.0, softbounds= (-1.0, 1.0), preced...
X-coordinate location of pattern center.
  y = param.Number(default= 0.0, softbounds= (-1.0, 1.0), preced...
Y-coordinate location of pattern center.
  position = param.Composite(attribs= ['x', 'y'], precedence=-1,...
Coordinates of location of pattern center.
  orientation = param.Number(default= 0.0, softbounds= (0.0, 2* ...
Polar angle of pattern, i.e., the orientation in the Cartesian coordinate system, with zero at 3 o'clock and increasing counterclockwise.
  size = param.Number(default= 1.0, bounds= (0.0, None), softbou...
Determines the overall size of the pattern.
  scale = param.Number(default= 1.0, softbounds= (0.0, 2.0), pre...
Multiplicative strength of input pattern, defaulting to 1.0
  offset = param.Number(default= 0.0, softbounds= (-1.0, 1.0), p...
Additive offset to input pattern, defaulting to 0.0
  mask = param.Parameter(default= None, precedence=-1, doc= ...
Optional object (expected to be an array) with which to multiply the pattern array after it has been created, before any output_fns are applied.
  mask_shape = param.ClassSelector(param.Parameterized, default=...
Optional PatternGenerator used to construct a mask to be applied to the pattern.
  output_fns = param.HookList(default= [], class_= TransferFn, p...
Optional function(s) to apply to the pattern array after it has been created.
  __params = {'bounds': <topo.base.boundingregion.BoundingRegion...
dict() -> new empty dictionary.
  name = <param.parameterized.String object at 0xa9c186c>
String identifier for this object.

Inherited from param.parameterized.Parameterized: print_level

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__call__(self, **params_to_override)
(Call operator)

source code 

Call the subclass's 'function' method on a rotated and scaled coordinate system.

Creates and fills an array with the requested pattern. If called without any params, uses the values for the Parameters as currently set on the object. Otherwise, any params specified override those currently set on the object.

function(self, p)

source code 

Function to draw a pattern that will then be scaled and rotated.

Instead of implementing __call__ directly, PatternGenerator subclasses will typically implement this helper function used by __call__, because that way they can let __call__ handle the scaling and rotation for them. Alternatively, __call__ itself can be reimplemented entirely by a subclass (e.g. if it does not need to do any scaling or rotation), in which case this function will be ignored.


Class Variable Details [hide private]

__abstract

bool(x) -> bool

Returns True when the argument x is true, False otherwise. The builtins True and False are the only two instances of the class bool. The class bool is a subclass of the class int, and cannot be subclassed.

Value:
True

bounds

BoundingBox of the area in which the pattern is generated.
Value:
BoundingRegionParameter(default= BoundingBox(points= ((-0.5,-0.5), (0.5, 0.5))), p\
recedence=-1, doc= "BoundingBox of the area in which the pattern is generated.")

xdensity

Density (number of samples per 1.0 length) in the x direction.
Value:
param.Number(default= 10, bounds= (0, None), precedence=-1, doc= """
        Density (number of samples per 1.0 length) in the x direction.""")

ydensity

Density (number of samples per 1.0 length) in the y direction. Typically the same as the xdensity.
Value:
param.Number(default= 10, bounds= (0, None), precedence=-1, doc= """
        Density (number of samples per 1.0 length) in the y direction.
        Typically the same as the xdensity.""")

x

X-coordinate location of pattern center.
Value:
param.Number(default= 0.0, softbounds= (-1.0, 1.0), precedence= 0.20, doc= """
        X-coordinate location of pattern center.""")

y

Y-coordinate location of pattern center.
Value:
param.Number(default= 0.0, softbounds= (-1.0, 1.0), precedence= 0.21, doc= """
        Y-coordinate location of pattern center.""")

position

Coordinates of location of pattern center. Provides a convenient way to set the x and y parameters together as a tuple (x,y), but shares the same actual storage as x and y (and thus only position OR x and y need to be specified).
Value:
param.Composite(attribs= ['x', 'y'], precedence=-1, doc= """
        Coordinates of location of pattern center.
        Provides a convenient way to set the x and y parameters together
        as a tuple (x,y), but shares the same actual storage as x and y
        (and thus only position OR x and y need to be specified).""")

orientation

Polar angle of pattern, i.e., the orientation in the Cartesian coordinate system, with zero at 3 o'clock and increasing counterclockwise.
Value:
param.Number(default= 0.0, softbounds= (0.0, 2* pi), precedence= 0.40, doc= """
        Polar angle of pattern, i.e., the orientation in the Cartesian coordinate
        system, with zero at 3 o'clock and increasing counterclockwise.""")

size

Determines the overall size of the pattern.
Value:
param.Number(default= 1.0, bounds= (0.0, None), softbounds= (0.0, 6.0), precedence\
= 0.30, doc= """Determines the overall size of the pattern.""")

scale

Multiplicative strength of input pattern, defaulting to 1.0
Value:
param.Number(default= 1.0, softbounds= (0.0, 2.0), precedence= 0.10, doc= """
        Multiplicative strength of input pattern, defaulting to 1.0""")

offset

Additive offset to input pattern, defaulting to 0.0
Value:
param.Number(default= 0.0, softbounds= (-1.0, 1.0), precedence= 0.11, doc= """
        Additive offset to input pattern, defaulting to 0.0""")

mask

Optional object (expected to be an array) with which to multiply the pattern array after it has been created, before any output_fns are applied. This can be used to shape the pattern.
Value:
param.Parameter(default= None, precedence=-1, doc= """
        Optional object (expected to be an array) with which to multiply the
        pattern array after it has been created, before any output_fns are
        applied. This can be used to shape the pattern.""")

mask_shape

Optional PatternGenerator used to construct a mask to be applied to the pattern.
Value:
param.ClassSelector(param.Parameterized, default= None, precedence= 0.06, doc= """
        Optional PatternGenerator used to construct a mask to be applied to
        the pattern.""")

output_fns

Optional function(s) to apply to the pattern array after it has been created. Can be used for normalization, thresholding, etc.
Value:
param.HookList(default= [], class_= TransferFn, precedence= 0.08, doc= """
        Optional function(s) to apply to the pattern array after it has been creat\
ed.
        Can be used for normalization, thresholding, etc.""")

__params

dict() -> new empty dictionary.
dict(mapping) -> new dictionary initialized from a mapping object's
    (key, value) pairs.
dict(seq) -> new dictionary initialized as if via:
    d = {}
    for k, v in seq:
        d[k] = v
dict(**kwargs) -> new dictionary initialized with the name=value pairs
    in the keyword argument list.  For example:  dict(one=1, two=2)

Value:
{'bounds': <topo.base.boundingregion.BoundingRegionParameter object at 0xa9980d4>,
 'mask': <param.parameterized.Parameter object at 0xa99810c>,
 'mask_shape': <param.ClassSelector object at 0xa9c146c>,
 'name': <param.parameterized.String object at 0xa9c186c>,
 'offset': <param.Number object at 0xa98dd64>,
 'orientation': <param.Number object at 0xa98dadc>,
 'output_fns': <param.HookList object at 0xa98dd1c>,
 'position': <param.Composite object at 0xa9c1dac>,
...