/**
  * Paint the contour.
  *
  * @param g
  */
 public synchronized void draw(DrawingPanel panel, Graphics g) {
   if (!visible || (griddata == null)) {
     return;
   }
   if (!autoscaleZ) {
     g.setColor(colorMap.getFloorColor());
     int w = panel.getWidth() - panel.getLeftGutter() - panel.getRightGutter();
     int h = panel.getHeight() - panel.getTopGutter() - panel.getBottomGutter();
     g.fillRect(panel.getLeftGutter(), panel.getTopGutter(), Math.max(w, 0), Math.max(h, 0));
   }
   accumulator.clearAccumulator();
   contour_stepz = (zmax - zmin) / (contour_lines + 1);
   double z = zmin;
   for (int c = 0; c < contourColors.length; c++) {
     if (!autoscaleZ && (c == contourColors.length - 1)) {
       contourColors[c] = colorMap.getCeilColor();
     } else {
       contourColors[c] = colorMap.doubleToColor(z);
     }
     z += contour_stepz;
   }
   // double dx=griddata.getDx();
   // double dy=griddata.getDy();
   // double x = griddata.getLeft();
   double x = griddata.getLeft(), dx = (griddata.getRight() - griddata.getLeft()) / (nx - 1);
   double y = griddata.getTop(), dy = -(griddata.getTop() - griddata.getBottom()) / (ny - 1);
   for (int i = 0, mx = internalData.length - 1; i < mx; i++) {
     y = griddata.getTop();
     for (int j = 0, my = internalData[0].length - 1; j < my; j++) {
       contour_vertex[0][0] = x;
       contour_vertex[0][1] = y;
       contour_vertex[0][2] = internalData[i][j];
       contour_vertex[1][0] = x;
       contour_vertex[1][1] = y + dy;
       contour_vertex[1][2] = internalData[i][j + 1];
       contour_vertex[2][0] = x + dx;
       contour_vertex[2][1] = y + dy;
       contour_vertex[2][2] = internalData[i + 1][j + 1];
       contour_vertex[3][0] = x + dx;
       contour_vertex[3][1] = y;
       contour_vertex[3][2] = internalData[i + 1][j];
       createContour(panel, g);
       y += dy;
     }
     x += dx;
   }
   if (showContourLines) {
     g.setColor(lineColor);
     accumulator.drawAll(g);
     int lpix = panel.xToPix(griddata.getLeft());
     int tpix = panel.yToPix(griddata.getTop());
     int rpix = panel.xToPix(griddata.getRight());
     int bpix = panel.yToPix(griddata.getBottom());
     g.drawRect(
         Math.min(lpix, rpix), Math.min(tpix, bpix), Math.abs(lpix - rpix), Math.abs(tpix - bpix));
   }
 }
 /** Updates the internal data by interpolating large grids onto a smaller array. */
 void updateInterpolated(GridData griddata) {
   if (autoscaleZ) {
     double[] minmax = griddata.getZRange(ampIndex);
     zmax = minmax[1];
     zmin = minmax[0];
     if (zMap != null) {
       zMap.setMinMax(zmin, zmax);
     }
     colorMap.setScale(zmin, zmax);
   }
   double x = griddata.getLeft(), dx = (griddata.getRight() - griddata.getLeft()) / (nx - 1);
   double y = griddata.getTop(), dy = -(griddata.getTop() - griddata.getBottom()) / (ny - 1);
   for (int i = 0; i < nx; i++) {
     y = griddata.getTop();
     for (int j = 0; j < ny; j++) {
       internalData[i][j] = griddata.interpolate(x, y, ampIndex);
       if (zMap != null) {
         internalData[i][j] = zMap.evaluate(internalData[i][j]);
       }
       y += dy;
     }
     x += dx;
   }
 }
 /* The following methods are requried for the measurable interface */
 public double getXMin() {
   return griddata.getLeft();
 }