de.gsi.chart.renderer.spi.marchingsquares.Grid Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of chartfx-chart Show documentation
Show all versions of chartfx-chart Show documentation
This charting library ${project.artifactId}- is an extension
in the spirit of Oracle's XYChart and performance/time-proven JDataViewer charting functionalities.
Emphasis was put on plotting performance for both large number of data points and real-time displays,
as well as scientific accuracies leading to error bar/surface plots, and other scientific plotting
features (parameter measurements, fitting, multiple axes, zoom, ...).
package de.gsi.chart.renderer.spi.marchingsquares;
/**
*
* Given a two-dimensional scalar field (rectangular array of individual
* numerical values) the Marching Squares algorithm applies a threshold
* (a.k.a contour level or isovalue) to make a binary image containing:
*
*
* - 1 where the data value is above the isovalue,
* - 0 where the data value is below the isovalue.
*
*
* Every 2x2 block of pixels in the binary image forms a contouring cell, so
* the whole image is represented by a grid of such cells (shown in green in
* the picture below). Note that this contouring grid is one cell smaller in
* each direction than the original 2D data field.
*
*/
class Grid {
private final Cell[][] cells;
public final int rowCount;
public final int colCount;
private final double threshold;
private String str;
Grid(final Cell[][] cells, final double threshold) {
super();
this.cells = cells;
rowCount = cells.length;
colCount = cells[0].length;
this.threshold = threshold;
}
public Cell getCellAt(final int r, final int c) {
return cells[r][c];
}
public int getCellNdxAt(final int r, final int c) {
final Cell cell = cells[r][c];
if (cell == null) {
return 0;
}
return cells[r][c].getCellNdx();
}
@Override
public String toString() {
if (str == null) {
str = "Grid{rowCount=" + rowCount + ", colCount=" + colCount + ", threshold=" + threshold + '}';
}
return str;
}
}