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

Class ContourPlot

src/org/opensourcephysics/display2d/ContourPlot.java:24–720  ·  view source on GitHub ↗

ContourPlot draws a contour plot of a scalar field. Contour uses code from the Surface Plotter package by Yanto Suryono. @author Wolfgang Christian @version 1.0

Source from the content-addressed store, hash-verified

22 * @version 1.0
23 */
24public class ContourPlot implements Plot2D {
25 private GridData griddata;
26 private Color lineColor = new Color(0, 64, 0); // dark green
27 private boolean visible = true;
28 private int contour_lines = 12; // number of contour lines
29 private boolean showContourLines = true;
30 private boolean showColoredLevels = true; // fill with colors
31 private double contour_stepz; // contour spacing
32 private int[] xpoints = new int[8];
33 private int[] ypoints = new int[8];
34 private int[] contour_x = new int[8];
35 private int[] contour_y = new int[8];
36 private double[] delta = new double[4];
37 private double[] intersection = new double[4];
38 private double[][] contour_vertex = new double[4][3];
39 private ContourAccumulator accumulator = new ContourAccumulator();
40 private double zmin = 0, zmax = 1.0; // the range for contour levels
41 private boolean autoscaleZ = true;
42 private boolean symmetricZ=false;
43 protected ZExpansion zMap = null;
44 protected ColorMapper colorMap = new ColorMapper(contour_lines, zmin, zmax, ColorMapper.SPECTRUM);
45 private Color[] contourColors = new Color[contour_lines+2];
46 private double[][] internalData = new double[1][1];
47 private int ampIndex = 0; // amplitude index
48 private int nx = 0, ny = 0;
49 private int maxGridSize = 48;
50 protected boolean interpolateLargeGrids = true; // interpolates a large grid onto a smaller grid to speed the computation of contour lines
51
52 /**
53 * Constructs a ContourPlot without any data.
54 *
55 */
56 public ContourPlot() {}
57
58 /**
59 * Constructs a ContourPlot that renders the given GridData.
60 *
61 * @param _griddata data storage
62 */
63 public ContourPlot(GridData _griddata) {
64 griddata = _griddata;
65 if(griddata==null) {
66 return;
67 }
68 nx = (interpolateLargeGrids&&(griddata.getNx()>maxGridSize)) ? 32 : griddata.getNx();
69 ny = (interpolateLargeGrids&&(griddata.getNy()>maxGridSize)) ? 32 : griddata.getNy();
70 internalData = new double[nx][ny];
71 update();
72 }
73
74 /**
75 * Gets the x coordinate for the given index.
76 *
77 * @param i int
78 * @return double the x coordinate
79 */
80 @Override
81public double indexToX(int i) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected