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

Class PatternGenerator

source code

                       object --+    
                                |    
param.parameterized.Parameterized --+
                                    |
                                   PatternGenerator
Known Subclasses:

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 subclasses 'function' method on a rotated and scaled coordinate system.
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
 
__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
 
_apply_mask(self, params, mat)
Create (if necessary) and apply the mask to the given matrix mat.
source code
 
function(self, params)
Function to draw a pattern that will then be scaled and rotated.
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_dynamic_time_fn, state_pop, state_push, verbose, warning

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

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.
  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_fn is applied.
  mask_shape = param.ClassSelector(param.Parameterized, default=...
Optional PatternGenerator used to construct a mask to be applied to the pattern.
  offset = param.Number(default= 0.0, softbounds= (-1.0, 1.0), p...
Additive offset to input pattern, defaulting to 0.0
  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.
  output_fn = param.ClassSelector(OutputFn, default= IdentityOF(...
Optional function to apply to the pattern array after it has been created.
  position = param.Composite(attribs= ['x', 'y'], precedence=-1,...
Coordinates of location of pattern center.
  scale = param.Number(default= 1.0, softbounds= (0.0, 2.0), pre...
Multiplicative strength of input pattern, defaulting to 1.0
  size = param.Number(default= 1.0, bounds= (0.0, None), softbou...
Determines the overall size of the pattern.
  x = param.Number(default= 0.0, softbounds= (-1.0, 1.0), preced...
X-coordinate location of pattern center.
  xdensity = param.Number(default= 10, bounds= (0, None), preced...
Density (number of samples per 1.0 length) in the x direction.
  y = param.Number(default= 0.0, softbounds= (-1.0, 1.0), preced...
Y-coordinate location of pattern center.
  ydensity = param.Number(default= 10, bounds= (0, None), preced...
Density (number of samples per 1.0 length) in the y direction.

Inherited from param.parameterized.Parameterized: name, print_level

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

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

source code 

Call the subclasses '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, params)

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.")

mask

Optional object (expected to be an array) with which to multiply the pattern array after it has been created, before any output_fn is 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_fn is
        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.""")

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""")

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.""")

output_fn

Optional function to apply to the pattern array after it has been created. This function can be used for normalization, thresholding, etc.
Value:
param.ClassSelector(OutputFn, default= IdentityOF(), precedence= 0.08, doc= """
        Optional function to apply to the pattern array after it has been created.
        This function can be used for normalization, thresholding, etc.""")

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).""")

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""")

size

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

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.""")

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.""")

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.""")

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.""")