MCPcopy Create free account
hub / github.com/OpenSourcePhysics/osp / GridPointData

Class GridPointData

src/org/opensourcephysics/display2d/GridPointData.java:39–574  ·  view source on GitHub ↗

GridPointData stores numeric data on a scaled rectangular grid using an array of points. Every grid point contains the x and y coordinates and one or more components. The first component is usually the magnitude of the quantity of interest. Components can represent almost anything. For example, we

Source from the content-addressed store, hash-verified

37 * @version 1.1
38 */
39public class GridPointData implements GridData {
40 protected double[][][] data;
41 protected double left, right, bottom, top;
42 protected double dx = 0, dy = 0;
43 protected boolean cellData = false;
44 protected String[] names;
45
46 /**
47 * Constructor Data2D
48 *
49 * @param ix
50 * @param iy
51 * @param ncomponents
52 */
53 public GridPointData(int ix, int iy, int ncomponents) {
54 if((iy<1)||(ix<1)) {
55 throw new IllegalArgumentException("Number of dataset rows and columns must be positive. Your row="+iy+" col="+ix); //$NON-NLS-1$ //$NON-NLS-2$
56 }
57 if((ncomponents<1)) {
58 throw new IllegalArgumentException("Number of 2d data components must be positive. Your ncomponents="+ncomponents); //$NON-NLS-1$
59 }
60 data = new double[ix][iy][ncomponents+2]; // x, y, and components
61 setScale(0, ix, 0, iy);
62 names = new String[ncomponents];
63 for(int i = 0; i<ncomponents; i++) {
64 names[i] = "Component_"+i; //$NON-NLS-1$
65 }
66 }
67
68 /**
69 * Creates a new GridPointData object with the same grid points and the given number of components.
70 *
71 * @param ncomponents number of samples dataset.
72 * @return the newly created Data2D
73 */
74 public GridPointData createGridPointData(int ncomponents) {
75 GridPointData data2d = new GridPointData(data.length, data[0].length, ncomponents+2);
76 data2d.setScale(left, right, bottom, top);
77 return data2d;
78 }
79
80 /**
81 * Sets the name of the component.
82 *
83 * @param i int the component index
84 * @param name String
85 */
86 @Override
87public void setComponentName(int i, String name) {
88 names[i] = name;
89 }
90
91 /**
92 * Gets the name of the component,
93 * @param i int the component index
94 * @return String the name
95 */
96 @Override

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected