Example #1
0
 /**
  * Draw the image containing the dataset pixels.
  *
  * @param panel the panel containing this data raster
  * @param g the graphics context upon which to draw
  */
 public void draw(DrawingPanel panel, Graphics g) {
   if (!visible) {
     return;
   }
   if (primaryDrawingPanel != panel) {
     return; // can only draw on one panel for now.
   }
   int xrange = panel.xToPix(xmax) - panel.xToPix(xmin);
   int yrange = panel.yToPix(ymin) - panel.yToPix(ymax);
   xrange = Math.min(xrange, panel.getWidth());
   yrange = Math.min(yrange, panel.getHeight());
   if ((xrange == 0) || (xrange == 0)) {
     return;
   }
   // render a new image if the scale or image size change
   if ((Math.abs(xrange) != image.getWidth())
       || // image size change
       (Math.abs(yrange) != image.getHeight())
       || ( // image size change
       xppu != primaryDrawingPanel.getXPixPerUnit())
       || ( // scale change
       yppu != primaryDrawingPanel.getYPixPerUnit())) {
     render();
   }
   double xmin = Math.max(primaryDrawingPanel.getXMin(), this.xmin);
   double ymax = Math.min(primaryDrawingPanel.getYMax(), this.ymax);
   if ((image != null) && (image.getWidth() > 1)) {
     g.drawImage(
         image, panel.xToPix(xmin), panel.yToPix(ymax), panel); // blast the image into the panel
   }
 }
 /**
  * Draws the spokes for the polar plot.
  *
  * @param panel
  * @param g
  */
 protected void drawRAxis(double dr, double rmax, DrawingPanel panel, Graphics g) {
   Graphics2D g2 = (Graphics2D) g;
   g.setColor(gridcolor.darker());
   int x1 = panel.xToPix(0);
   int y1 = panel.yToPix(0);
   int x2 = panel.xToPix(rmax);
   g.drawLine(x1, y1, Math.min(x2, panel.getWidth() - panel.getRightGutter()), y1);
   FontMetrics fm = g2.getFontMetrics();
   int nLabels = (int) (panel.getXMax() / dr / MAJOR_TIC);
   int stride = (nLabels > 3) ? 2 : 1;
   double rm = Math.min(rmax, panel.getXMax());
   for (double r = (nLabels > 3) ? stride * MAJOR_TIC * dr : MAJOR_TIC * dr;
       r <= rm;
       r += (stride * MAJOR_TIC * dr)) {
     String label = getLabel(r);
     int sW = fm.stringWidth(label) + 4;
     int sH = fm.getHeight();
     g2.setColor(new Color(247, 247, 247));
     int x0 = panel.xToPix(r), y0 = panel.yToPix(0);
     g2.fill(new Rectangle2D.Double(x0 - sW / 2, y0 + 3, sW, sH));
     g2.setColor(Color.black);
     g2.draw(new Rectangle2D.Double(x0 - sW / 2, y0 + 3, sW, sH));
     g2.setColor(Color.BLACK);
     g2.drawString(label, x0 - sW / 2 + 2, y0 + 1 + sH);
   }
 }
 /**
  * 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));
   }
 }
 /**
  * Draws the spokes for the polar plot.
  *
  * @param panel
  * @param g
  */
 public void drawSpokes(double rmax, DrawingPanel panel, Graphics g) {
   g.setColor(gridcolor);
   for (double theta = 0; theta < Math.PI; theta += dtheta) {
     int x1 = panel.xToPix(rmax * Math.cos(theta));
     int y1 = panel.yToPix(rmax * Math.sin(theta));
     int x2 = panel.xToPix(-rmax * Math.cos(theta));
     int y2 = panel.yToPix(-rmax * Math.sin(theta));
     g.drawLine(x1, y1, x2, y2);
   }
 }
Example #5
0
 /** Draws clusters */
 public void draw(DrawingPanel panel, Graphics g) {
   if (site == null) {
     return;
   }
   int sizeX = Math.abs(panel.xToPix(1.0) - panel.xToPix(0));
   int sizeY = Math.abs(panel.yToPix(1.0) - panel.yToPix(0));
   for (int i = 0; i < numberOfParticles; i++) {
     int xpix = panel.xToPix(x[i]) - sizeX;
     int ypix = panel.yToPix(y[i]) - sizeY;
     g.fillRect(xpix + sizeX / 2, ypix + sizeY / 2, sizeX, sizeY);
   }
 }
Example #6
0
 /**
  * Paints a new image using the existing data.
  *
  * <p>returns the image buffer
  */
 public synchronized BufferedImage render() {
   if (primaryDrawingPanel == null) {
     return null;
   }
   int xrange = primaryDrawingPanel.xToPix(xmax) - primaryDrawingPanel.xToPix(xmin);
   int yrange = primaryDrawingPanel.yToPix(ymin) - primaryDrawingPanel.yToPix(ymax);
   xrange = Math.min(xrange, primaryDrawingPanel.getWidth());
   yrange = Math.min(yrange, primaryDrawingPanel.getHeight());
   if ((Math.abs(xrange) == 0) || (Math.abs(yrange) == 0)) {
     return null; // Produces exception in IE (Paco)
   }
   image = new BufferedImage(Math.abs(xrange), Math.abs(yrange), BufferedImage.TYPE_INT_ARGB);
   backgroundColor = new Color(image.getRGB(0, 0));
   for (int i = 0, n = imageDatasets.size(); i < n; i++) {
     (imageDatasets.get(i)).render();
   }
   return image;
 }
 /**
  * Draws the rings for the polar plot.
  *
  * @param panel
  * @param g
  * @return double the ring separation used
  */
 public double drawRings(double rmax, DrawingPanel panel, Graphics g) {
   double dr = Math.max(this.dr, 1.0e-9);
   if (autospaceRings) {
     int exponent = (int) (Math.log(rmax) / LOG10);
     double decade = Math.pow(10, exponent - 1);
     dr = decade;
     while (rmax / dr > 5 * MAJOR_TIC) { // increase dr if we have more than 25 rings
       dr *= 2;
       if (dr / decade > 3.5 && dr / decade < 4.5) {
         dr = 5 * decade;
         decade *= 10;
       }
     }
   } else {
     int nrings = (int) (rmax / dr);
     while (nrings > 10 * MAJOR_TIC) {
       dr *= 2;
       nrings = (int) (rmax / dr);
     }
   }
   int xcenter = panel.xToPix(0);
   int ycenter = panel.yToPix(0);
   int xrad = (int) (panel.getXPixPerUnit() * rmax);
   int yrad = (int) (panel.getYPixPerUnit() * rmax);
   if (interiorColor != null) {
     g.setColor(interiorColor);
     g.fillOval(xcenter - xrad, ycenter - yrad, 2 * xrad, 2 * yrad);
   }
   int counter = 0;
   for (double r = 0; r <= rmax; r += dr) {
     g.setColor(gridcolor);
     xrad = panel.xToPix(r) - xcenter;
     yrad = ycenter - panel.yToPix(r);
     if (counter % MAJOR_TIC == 0) {
       g.setColor(gridcolor.darker());
     }
     g.drawOval(xcenter - xrad, ycenter - yrad, 2 * xrad, 2 * yrad);
     counter++;
   }
   return dr;
 }
 /**
  * Creates contour plot of a single area division. Called by <code>draw</code> method
  *
  * @see #draw
  */
 private final void createContour(DrawingPanel panel, Graphics g) {
   double z = zmin;
   xpoints[0] = panel.xToPix(contour_vertex[0][0]) + 1;
   xpoints[2] = panel.xToPix(contour_vertex[1][0]) + 1;
   xpoints[4] = panel.xToPix(contour_vertex[2][0]) + 1;
   xpoints[6] = panel.xToPix(contour_vertex[3][0]) + 1;
   xpoints[1] = xpoints[3] = xpoints[5] = xpoints[7] = -1;
   ypoints[0] = panel.yToPix(contour_vertex[0][1]) + 1;
   ypoints[4] = panel.yToPix(contour_vertex[2][1]) + 1;
   ypoints[2] = ypoints[3] = panel.yToPix(contour_vertex[1][1]) + 1;
   ypoints[6] = ypoints[7] = panel.yToPix(contour_vertex[3][1]) + 1;
   int xmin = xpoints[0];
   int xmax = xpoints[4];
   for (int counter = 0; counter <= contour_lines + 1; counter++) {
     // Analyzes edges
     for (int edge = 0; edge < 4; edge++) {
       int index = (edge << 1) + 1;
       int nextedge = (edge + 1) & 3;
       if (z > contour_vertex[edge][2]) {
         xpoints[index - 1] = -2;
         if (z > contour_vertex[nextedge][2]) {
           xpoints[(index + 1) & 7] = -2;
           xpoints[index] = -2;
         }
       } else if (z > contour_vertex[nextedge][2]) {
         xpoints[(index + 1) & 7] = -2;
       }
       if (xpoints[index] != -2) {
         if (xpoints[index] != -1) {
           intersection[edge] += delta[edge];
           if ((index == 1) || (index == 5)) {
             ypoints[index] = panel.yToPix(intersection[edge]) + 1;
           } else {
             xpoints[index] = panel.xToPix(intersection[edge]) + 1;
           }
         } else {
           if ((z > contour_vertex[edge][2]) || (z > contour_vertex[nextedge][2])) {
             switch (index) {
               case 1:
                 delta[edge] =
                     (contour_vertex[nextedge][1] - contour_vertex[edge][1])
                         * contour_stepz
                         / (contour_vertex[nextedge][2] - contour_vertex[edge][2]);
                 intersection[edge] =
                     (contour_vertex[nextedge][1] * (z - contour_vertex[edge][2])
                             + contour_vertex[edge][1] * (contour_vertex[nextedge][2] - z))
                         / (contour_vertex[nextedge][2] - contour_vertex[edge][2]);
                 xpoints[index] = xmin;
                 ypoints[index] = panel.yToPix(intersection[edge]) + 1;
                 break;
               case 3:
                 delta[edge] =
                     (contour_vertex[nextedge][0] - contour_vertex[edge][0])
                         * contour_stepz
                         / (contour_vertex[nextedge][2] - contour_vertex[edge][2]);
                 intersection[edge] =
                     (contour_vertex[nextedge][0] * (z - contour_vertex[edge][2])
                             + contour_vertex[edge][0] * (contour_vertex[nextedge][2] - z))
                         / (contour_vertex[nextedge][2] - contour_vertex[edge][2]);
                 xpoints[index] = panel.xToPix(intersection[edge]) + 1;
                 break;
               case 5:
                 delta[edge] =
                     (contour_vertex[edge][1] - contour_vertex[nextedge][1])
                         * contour_stepz
                         / (contour_vertex[edge][2] - contour_vertex[nextedge][2]);
                 intersection[edge] =
                     (contour_vertex[edge][1] * (z - contour_vertex[nextedge][2])
                             + contour_vertex[nextedge][1] * (contour_vertex[edge][2] - z))
                         / (contour_vertex[edge][2] - contour_vertex[nextedge][2]);
                 xpoints[index] = xmax;
                 ypoints[index] = panel.yToPix(intersection[edge]) + 1;
                 break;
               case 7:
                 delta[edge] =
                     (contour_vertex[edge][0] - contour_vertex[nextedge][0])
                         * contour_stepz
                         / (contour_vertex[edge][2] - contour_vertex[nextedge][2]);
                 intersection[edge] =
                     (contour_vertex[edge][0] * (z - contour_vertex[nextedge][2])
                             + contour_vertex[nextedge][0] * (contour_vertex[edge][2] - z))
                         / (contour_vertex[edge][2] - contour_vertex[nextedge][2]);
                 xpoints[index] = panel.xToPix(intersection[edge]) + 1;
                 break;
             }
           }
         }
       }
     }
     // Creates polygon
     int contour_n = 0;
     for (int index = 0; index < 8; index++) {
       if (xpoints[index] >= 0) {
         contour_x[contour_n] = xpoints[index];
         contour_y[contour_n] = ypoints[index];
         contour_n++;
       }
     }
     if (showColoredLevels && (colorMap.getPaletteType() != ColorMapper.WIREFRAME)) {
       g.setColor(contourColors[counter]);
       if (contour_n > 0) {
         g.fillPolygon(contour_x, contour_y, contour_n);
       }
     }
     // Creates contour lines
     if (showContourLines) {
       int x = -1;
       int y = -1;
       for (int index = 1; index < 8; index += 2) {
         if (xpoints[index] >= 0) {
           if (x != -1) {
             accumulator.addLine(x, y, xpoints[index], ypoints[index]);
           }
           x = xpoints[index];
           y = ypoints[index];
         }
       }
       if ((xpoints[1] > 0) && (x != -1)) {
         accumulator.addLine(x, y, xpoints[1], ypoints[1]);
       }
     }
     if (contour_n < 3) {
       break;
     }
     z += contour_stepz;
   }
 }