Class: Grid2D

PD. Grid2D

Defines a simple two-dimensional grid of data points.


new Grid2D( [config])

Creates a new 2D grid.

Parameters:
Name Type Argument Description
config object <optional>

An optional configuration object.

Properties of config:
Name Type Argument Description
gridType PD.GRID <optional>

The grid point distribution type, defaults to PD.GRID.REGULAR.

legend PD.Legend <optional>

The legend used to turn cell values into display colors.

Members


:number

cells

The actual array storing rows and columns of grid cells.

Type
  • number

:number

cols

The number of columns in the grid.

Type
  • number

:PD.GRID

gridType

The grid point distribution type, defaults to PD.GRID.REGULAR.

Type

:boolean

hasValidData <readonly>

Whether or not the grid has valid data to display.

Type
  • boolean

:boolean

isGrid2D <readonly>

A flag identifying this object as a 2D grid.

Type
  • boolean

:PD.Legend

legend

The legend used to turn cell values into display colors.

Type

:THREE.Plane

plane

The current plane equation of the unperturbed grid surface.

Type
  • THREE.Plane

:number

rows

The number of rows in the grid.

Type
  • number

:PD.GRID

defaultGridType <static>

The default grid point distribution type for new grids, defaults to PD.GRID.REGULAR.

Type

Methods


_copyContourBandsToPolyMesh(mesh)

Copy contour bands to the given mesh.

Parameters:
Name Type Description
mesh PD.PolyMesh

The mesh to add contour bands to.

Returns:

Return true if contour data was added to the mesh.

Type
boolean

_copyContourLinesToPolyMesh(mesh)

Copy contour lines to the given mesh.

Parameters:
Name Type Description
mesh PD.PolyMesh

The mesh to add contour lines to.

Returns:

Return true if contour data was added to the mesh.

Type
boolean

_copyHexContourLinesToPolyMesh(mesh)

Copies the smoothed hexagonal contoured triangles and outlines to the given mesh.

Parameters:
Name Type Description
mesh PD.PolyMesh

The polymesh to add the grid geometry to.

Returns:

Returns true if geometry was added to the mesh, otherwise false.

Type
boolean

_copyToPolyMeshHexBlock(mesh)

Copies the hexagonal surface triangles and cell outlines to the given mesh.

Parameters:
Name Type Description
mesh PD.PolyMesh

The polymesh to add the grid geometry to.

Returns:

Returns true if geometry was added to the mesh, otherwise false.

Type
boolean

_copyToPolyMeshHexBlockDisplaced(mesh)

Copies the hexagonal surface triangles and cell outlines to the given mesh.

Parameters:
Name Type Description
mesh PD.PolyMesh

The polymesh to add the grid geometry to.

Returns:

Returns true if geometry was added to the mesh, otherwise false.

Type
boolean

_copyToPolyMeshHexSmooth(mesh)

Copies the smoothed surface triangles and outlines to the given mesh.

Parameters:
Name Type Description
mesh PD.PolyMesh

The polymesh to add the grid geometry to.

Returns:

Returns true if geometry was added to the mesh, otherwise false.

Type
boolean

_copyToPolyMeshRegularBlock(mesh)

Copies the regular surface triangles and cell outlines to the given mesh.

Parameters:
Name Type Description
mesh PD.PolyMesh

The polymesh to add the grid geometry to.

Returns:

Returns true if geometry was added to the mesh, otherwise false.

Type
boolean

_copyToPolyMeshRegularBlockDisplaced(mesh)

Copies the regular surface triangles and cell outlines to the given mesh.

Parameters:
Name Type Description
mesh PD.PolyMesh

The polymesh to add the grid geometry to.

Returns:

Returns true if geometry was added to the mesh, otherwise false.

Type
boolean

_copyToPolyMeshRegularBlockXXX(mesh)

Copies the regular surface triangles and cell outlines to the given mesh.

Parameters:
Name Type Description
mesh PD.PolyMesh

The polymesh to add the grid geometry to.

Returns:

Returns true if geometry was added to the mesh, otherwise false.

Type
boolean

_copyToPolyMeshRegularSmooth(mesh)

Copies the regular surface triangles and cell outlines to the given mesh.

Parameters:
Name Type Description
mesh PD.PolyMesh

The polymesh to add the grid geometry to.

Returns:

Returns true if geometry was added to the mesh, otherwise false.

Type
boolean

_fitToPolygonHexPointy(polygon [, cell_size] [, offset])

Parameters:
Name Type Argument Default Description
polygon PD.Polygon

The polygon to fit the grid to.

cell_size number <optional>

The distance between grid cells in mm, defaults to a 15x15 grid.

offset number <optional>
1

The offset of points from the polygon surface in mm, default to 1mm.

Returns:

Returns true if the grid was successfully fit to the given surface, or false if the polygon is degenerate or too small for its cell size.

Type
boolean

_updateCellSurfacePositions()

Updates the surface position of each grid cell.

This method initialises the surface position of each grid cell, adds any value displacement, and resets its mesh index.


copyToPolyMesh(mesh)

Copies the surface triangles and cell outlines to the given mesh.

Parameters:
Name Type Description
mesh PD.PolyMesh

The polymesh to add the grid geometry to.

Returns:

Returns true if geometry was added to the mesh, otherwise false.

Type
boolean

copyToShell()

Distributes the grid regularly over the given polygon surface.

Returns:

Returns true if geometry was added to the shell, otherwise false.

Type
boolean

fitToPolygon(polygon, colSize, rowSize [, offset])

Distributes the grid regularly over the given polygon surface.

Parameters:
Name Type Argument Default Description
polygon PD.Polygon

The polygon to fit the grid to.

colSize number

The distance between cell columns.

rowSize number

The distance between cell rows.

offset number <optional>
1

The offset of points from the polygon surface in mm, default to 1mm.

Returns:

Returns true if the grid was successfully fit to the given surface, or false if the polygon is degenerate or too small for its cell size.

Type
boolean

fromJSON(data)

Safely copy properties from a source object.

See the PD.Base#fromJSON method for more details.

Parameters:
Name Type Description
data object

The source object containing data to copy.

Returns:

Returns this instance to support method chaining.

Type
PD.Legend

getCell(col, row)

Retrieves the cell at the given indices within the grid.

Parameters:
Name Type Description
col number

The horizontal column index of the cell.

row number

The vertical row index of the cell.

Returns:

Returns the cell at the given position, or null if either index out of range.

Type
PD.GridCell

getCellCount()

Retrieves the total number cells in the grid.

Returns:

Returns the number of cells.

Type
number

getIterator()

Retrieves an iterator which implements the Iterator protocol.

This means that the returned iterator has a next() method that returns an object with two properties:

  • value: The next grid cell in the iteration sequence.
  • done: This is true if the returned cell is the last one in the grid, otherwise false.

The iterator object has the following properties and methods:

  • cell: The current grid cell (same as next.value).
  • cellRow: The current row of grid cells.
  • progress: The current progress through the grid, as a decimal percentage.
  • done: If cell is last one (same as next.done).
  • column: The current grid column index of the cell.
  • row: The current grid row index of the cell.
  • restart(): Restarts the iterator such that any subsequent call to next() retrieves the first cell in the grid.
  • cancel(): Cancels the iteration such that any subsequent call to next() retrieves the final return value.
  • next(): Iterates to the next grid cell.
Returns:

Returns a JavaScript iterator object.

Type
object

getRow(row)

Retrieves the row of cell at the given indices within the grid.

Parameters:
Name Type Description
row number

The vertical row index of the cell.

Returns:

Returns the array of cells at the given row, or null if row index out of range.

Type
Array

map(callback)

Applies the given function to each cell in the grid.

The callback is invoked with three arguments:

  • cell: The data stored at the specific grid cell.
  • col: The column index of the cell.
  • row: The row index of the cell.
Parameters:
Name Type Description
callback function

The function to be invoked for each cell.

Throws:

Throws an error if callback is not a valid function.

Type
Error
Returns:

Returns this grid instance to support method chaining.

Type
object

orientAndFitExtents(polygon)

Orients the polygon and computes extents in local X and Y coordinates.

Parameters:
Name Type Description
polygon PD.Polygon

The polygon to fit the grid to.

Returns:

Returns true if the grid was successfully fit to the given surface, or false if the polygon is degenerate or too small for its cell size.

Type
boolean

setExtentsXY(extents, colSize, rowSize)

Sets the physical extents of the grid, in model units.

Parameters:
Name Type Description
extents THREE.Box3

The bounding box to fit.

colSize number

The distance between cell columns.

rowSize number

The distance between cell rows.

Returns:

Returns this grid instance to support method chaining.

Type
PD.Grid2D

setSize(cols, rows)

Sets the number of cells in the grid.

Parameters:
Name Type Description
cols number

The number of horizontal columns in the grid.

rows number

The number of vertical rows in the grid.

Returns:

Returns this grid instance to support method chaining.

Type
PD.Grid2D

toJSON( [data])

Converts the object instance to a simple POJO for JSON storage.

This method is used to copy, store and save the data for ths object, so the returned object must have all the properties required be able to rebuild this instance in its entirety when passed to the class constructor.

See the PD.Base#toJSON method for more details.

Parameters:
Name Type Argument Description
data object <optional>

An optional parent object to append this data to.

Returns:

Returns a JSON object.

Type
object

toString_CSV( [decimals])

Retrieves a comma-separated value (CSV) string containing grid data.

Parameters:
Name Type Argument Description
decimals number <optional>

The number of decimal places to output, defaults to 5.

Returns:

Returns a CSV formatted string containing grid data.

Type
string

toString_JSON( [indent] [, decimals])

Retrieves a JSON formatted string containing grid data.

Parameters:
Name Type Argument Description
indent string <optional>

An optional prefix string, typically one or more spaces or tabs.

decimals number <optional>

The number of decimal places to output, defaults to 5.

Returns:

Returns a JSON formatted string containing grid data.

Type
string