Name
Discrete2d -- Root class of all 2d discrete spaces.
Description
A Discrete2d is basically a 2d array of ids. Subclasses add particular space semantics onto this. Currently Discrete2d grids are accessed by integer pairs of X and Y coordinates.
Methods
Phase: Creating
+
create: (id <Zone>)
aZone setSizeX: (unsigned)
x Y: (unsigned)
y Convenience constructor for Discrete2d lattice
-
setSizeX: (unsigned)
x Y: (unsigned)
y Set the world size.
- (id *)
allocLattice Allocate memory for the lattice.
-
makeOffsets Given an array size, compute the offsets array that caches the multiplication by ysize. See the discrete2dSiteAt macro.
-
createEnd Create the lattice, precompute the offsets based on Y coordinate.
Phase: Setting
-
setLattice: (id *)
lattice
Phase: Using
- (unsigned)
getSizeX Get the size of the lattice in the X dimension.
- (unsigned)
getSizeY Get the size of the lattice in the Y dimension.
-
getObjectAtX: (unsigned)
x Y: (unsigned)
y Return the pointer stored at (x,y).
- (long)
getValueAtX: (unsigned)
x Y: (unsigned)
y Return the integer stored at (x,y).
-
putObject: anObject atX: (unsigned)
x Y: (unsigned)
y Put the given pointer to (x,y) overwriting whatever was there.
-
putValue: (long)
v atX: (unsigned)
x Y: (unsigned)
y Put the given integer to (x,y) overwriting whatever was there.
-
fastFillWithValue: (long)
aValue Directly fills the lattice with a value.
-
fastFillWithObject: anObj Directly fills the lattice with an object.
-
fillWithValue: (long)
aValue Fills the space using putValue.
-
fillWithObject: anObj Fills the space using putObject.
- (id *)
getLattice Returns the lattice pointer - use this for fast access.
- (int)
setDiscrete2d: (id <Discrete2d>)
a toFile: (const char *)
filename This method reads a PGM formatted file and pipes the data into a Discrete2d object.
-
copyDiscrete2d: (id <Discrete2d>)
a toDiscrete2d: (id <Discrete2d>)
b This method copies the data in one Discrete2d object to another Discrete2d object. It assumes that both objects already exist.
Examples
Example space/Discrete2d/1.
Discrete2d instances can now serialize themselves (without needing
additional classes such as Int2dFiler).
The result of value (shallow) Lisp serialization of a 4x3 Discrete2d
consisting of long values might be:
(list
(cons 'myDiscrete2d
(make-instance 'Discrete2d
#:xsize 4 #:ysize 3 #:lattice
(parse
#2((1000 1000 1000 1000)
(1000 1000 1000 1000)
(1000 1000 10 1000))))))
For object (deep) Lisp serialization of the same 4x3 lattice with
identical instances of MyClass at each point (except at (2,2) which
has an instance of MyClassOther) would look like:
(list
(cons 'myDiscrete2d
(make-instance 'Discrete2d
#:xsize 4 #:ysize 3 #:lattice
(parse
(cons '(0 . 0)
(make-instance 'MyClass #:strVal "Hello World"))
(cons '(0 . 1)
(make-instance 'MyClass #:strVal "Hello World"))
(cons '(0 . 2)
(make-instance 'MyClass #:strVal "Hello World"))
(cons '(1 . 0)
(make-instance 'MyClass #:strVal "Hello World"))
(cons '(1 . 1)
(make-instance 'MyClass #:strVal "Hello World"))
(cons '(1 . 2)
(make-instance 'MyClass #:strVal "Hello World"))
(cons '(2 . 0)
(make-instance 'MyClass #:strVal "Hello World"))
(cons '(2 . 1)
(make-instance 'MyClass #:strVal "Hello World"))
(cons '(2 . 2)
(make-instance 'MyClassOther #:strVal "Other World"))
(cons '(3 . 0)
(make-instance 'MyClass #:strVal "Hello World"))
(cons '(3 . 1)
(make-instance 'MyClass #:strVal "Hello World"))
(cons '(3 . 2)
(make-instance 'MyClass #:strVal "Hello World")))))) |