import ConnectivityConstraint from 'Artistoo/src/hamiltonian/ConnectivityConstraint.js'
public class | source

ConnectivityConstraint

Extends:

ConstraintHardConstraint → ConnectivityConstraint
this class is experimental.

This constraint enforces that cells stay 'connected' throughout any copy attempts. Copy attempts that break the cell into two parts are therefore forbidden. To speed things up, this constraint only checks if the borderpixels of the cells stay connected.

Constructor Summary

Public Constructor
public

The constructor of the ConnectivityConstraint requires a conf object with one parameter.

Member Summary

Public Members
public set

CPM

The set CPM method attaches the CPM to the constraint.

public

Object tracking the borderpixels of each cell.

Private Members
private

Private property used by updateBorderPixels to track borders.

Method Summary

Public Methods
public

checkConnected(tgt_i: IndexCoordinate, src_type: CellId, tgt_type: CellId): *

This method checks if the connectivity still holds after pixel tgt_i is changed from tgt_type to src_type.

public

This method checks that all required parameters are present in the object supplied to the constructor, and that they are of the right format.

public

Get the connected components of a set of pixels.

public

Get the connected components of the borderpixels of the current cell.

public

fulfilled(src_i: IndexCoordinate, tgt_i: IndexCoordinate, src_type: CellId, tgt_type: CellId): boolean

Method for hard constraints to compute whether the copy attempt fulfills the rule.

public

To speed things up: first check if a pixel change disrupts the local connectivity in its direct neighborhood.

public

The postSetpixListener of the ConnectivityConstraint updates the internally tracked borderpixels after every copy.

public

Update the borderpixels when pixel i changes from t_old into t_new.

Inherited Summary

From class Constraint
public get abstract

This method is actually implemented in the subclass.

public set

CPM(C: CPM)

This function attaches the relevant CPM to this constraint, so that information about this cpm can be requested from the constraint.

public get

Get the parameters of this constraint from the conf object.

public

C: CPM

CPM on which this constraint acts.

public

Configuration object for this constraint.

public abstract

cellParameter(param: string, cid: CellId): any

Get a cellid or cellkind-specific parameter for a constraint.

public abstract

The optional confChecker method should verify that all the required conf parameters are actually present in the conf object and have the right format.

public

paramOfCell(param: string, cid: CellId): any

Get a cellId specific parameter, only used if CPMEvol is used: looks whether the requested parameter is overwritten in an @object Cell and otherwise returns @function paramOfKind

public

paramOfKind(param: string, cid: CellId): any

Returns a cellKind specfic variable: Assumes that the parameter is indexable by cellkind.

From class HardConstraint
public get

Let the CPM know that this is a soft constraint, so return 'soft'.

public abstract

fulfilled(src_i: IndexCoordinate, tgt_i: IndexCoordinate, src_type: CellId, tgt_type: CellId): boolean

Hard constraints must have a 'fulfilled' method to compute whether the copy attempt fulfills the rule.

Public Constructors

public constructor(conf: object) source

The constructor of the ConnectivityConstraint requires a conf object with one parameter.

Override:

Constraint#constructor

Params:

NameTypeAttributeDescription
conf object

parameter object for this constraint.

conf.CONNECTED PerKindBoolean

should the cellkind be connected or not?

Public Members

public set CPM source

The set CPM method attaches the CPM to the constraint.

Override:

Constraint#CPM

public borderpixelsbycell: CellObject source

Object tracking the borderpixels of each cell. This is kept up to date after every copy attempt.

Private Members

private _neighbours: Uint16Array source

Private property used by updateBorderPixels to track borders.

Public Methods

public checkConnected(tgt_i: IndexCoordinate, src_type: CellId, tgt_type: CellId): * source

This method checks if the connectivity still holds after pixel tgt_i is changed from tgt_type to src_type.

Params:

NameTypeAttributeDescription
tgt_i IndexCoordinate

the pixel to change

src_type CellId

the new cell for this pixel.

tgt_type CellId

the cell the pixel belonged to previously.

Return:

*

public confChecker() source

This method checks that all required parameters are present in the object supplied to the constructor, and that they are of the right format. It throws an error when this is not the case.

Override:

Constraint#confChecker

public connectedComponentsOf(pixelobject: object): object source

Get the connected components of a set of pixels.

Params:

NameTypeAttributeDescription
pixelobject object

an object with as keys the IndexCoordinates of the pixels to check.

Return:

object

an array with an element for every connected component, which is in turn an array of the ArrayCoordinates of the pixels belonging to that component.

public connectedComponentsOfCellBorder(cellid: CellId): object source

Get the connected components of the borderpixels of the current cell.

Params:

NameTypeAttributeDescription
cellid CellId

cell to check the connected components of.

Return:

object

an array with an element for every connected component, which is in turn an array of the ArrayCoordinates of the pixels belonging to that component.

public fulfilled(src_i: IndexCoordinate, tgt_i: IndexCoordinate, src_type: CellId, tgt_type: CellId): boolean source

Method for hard constraints to compute whether the copy attempt fulfills the rule.

Override:

HardConstraint#fulfilled

Params:

NameTypeAttributeDescription
src_i IndexCoordinate

coordinate of the source pixel that tries to copy.

tgt_i IndexCoordinate

coordinate of the target pixel the source is trying to copy into.

src_type CellId

cellid of the source pixel.

tgt_type CellId

cellid of the target pixel.

Return:

boolean

whether the copy attempt satisfies the constraint.

public localConnected(tgt_i: IndexCoordinate, tgt_type: CellId): boolean source

To speed things up: first check if a pixel change disrupts the local connectivity in its direct neighborhood. If local connectivity is not disrupted, we don't have to check global connectivity at all. This currently only works in 2D, so it returns false for 3D (ensuring that connectivity is checked globally).

Params:

NameTypeAttributeDescription
tgt_i IndexCoordinate

the pixel to change

tgt_type CellId

the cell the pixel belonged to before the copy attempt.

Return:

boolean

does the local neighborhood remain connected if this pixel changes?

public postSetpixListener(i: IndexCoordinate, t_old: CellId, t: CellId) source

The postSetpixListener of the ConnectivityConstraint updates the internally tracked borderpixels after every copy.

Params:

NameTypeAttributeDescription
i IndexCoordinate

the pixel to change

t_old CellId

the cell the pixel belonged to previously

t CellId

the cell the pixel belongs to now.

public updateBorderPixels(i: IndexCoordinate, t_old: CellId, t_new: CellId) source

Update the borderpixels when pixel i changes from t_old into t_new.

Params:

NameTypeAttributeDescription
i IndexCoordinate

the pixel to change

t_old CellId

the cell the pixel belonged to previously

t_new CellId

the cell the pixel belongs to now.