Example #1
0
 /*
  * (non-Javadoc)
  *
  * @see org.math.plot.render.AbstractDrawer#drawLine(double[], double[])
  */
 public void drawLine(double[]... pC) {
   int[][] sC = new int[pC.length][];
   for (int i = 0; i < sC.length; i++) {
     sC[i] = projection.screenProjection(pC[i]);
   }
   drawLine(sC);
 }
Example #2
0
  /*
   * (non-Javadoc)
   *
   * @see org.math.plot.render.AbstractDrawer#fillPloygon(double[][])
   */
  public void fillPolygon(float alpha, double[]... pC) {
    int[][] c = new int[pC.length][2];
    for (int i = 0; i < pC.length; i++) {
      c[i] = projection.screenProjection(pC[i]);
    }

    int minx = c[0][0], miny = c[0][1], maxx = c[0][0] + 1, maxy = c[0][1] + 1;
    int[] x = new int[c.length];
    for (int i = 0; i < c.length; i++) {
      x[i] = c[i][0];
      minx = FastMath.min(minx, x[i]);
      maxx = FastMath.max(maxx, x[i]);
    }
    int[] y = new int[c.length];
    for (int i = 0; i < c.length; i++) {
      y[i] = c[i][1];
      miny = FastMath.min(miny, y[i]);
      maxy = FastMath.max(maxy, y[i]);
    }
    if (comp2D.hitClip(minx, miny, maxx - minx, maxy - miny)) {
      Composite cs = comp2D.getComposite();
      comp2D.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha));
      comp2D.fillPolygon(x, y, c.length);
      comp2D.setComposite(cs);
    }
  }
Example #3
0
  /*
   * (non-Javadoc)
   *
   * @see org.math.plot.render.AbstractDrawer#drawStringRatio(java.lang.String,
   *      double[], double, double, double)
   */
  public void drawTextBase(String label, double... rC) {
    int[] sC = projection.screenProjectionBase(rC);

    // Corner offset adjustment : Text Offset is used Here
    FontRenderContext frc = comp2D.getFontRenderContext();
    Font font1 = comp2D.getFont();
    int x = sC[0];
    int y = sC[1];
    double w = font1.getStringBounds(label, frc).getWidth();
    double h = font1.getSize2D();
    x -= (int) (w * text_Eastoffset);
    y += (int) (h * text_Northoffset);

    int wc = (int) (w * FastMath.cos(text_angle) + h * FastMath.sin(text_angle));
    int hc = (int) (h * FastMath.cos(text_angle) + w * FastMath.sin(text_angle));
    if (!comp2D.hitClip(x, y, wc, hc)) {
      return;
    }

    if (text_angle != 0) {
      comp2D.rotate(text_angle, x + w / 2, y - h / 2);
    }

    String[] lines = label.split("\n");
    for (int i = 0; i < lines.length; i++) {
      comp2D.drawString(lines[i], x, y);
      y += h;
    }
    // comp2D.drawString(label, x, y);

    if (text_angle != 0) {
      comp2D.rotate(-text_angle, x + w / 2, y - h / 2);
    }
  }
Example #4
0
 public void drawPatternDot(double... pC) {
   int[] sC = projection.screenProjection(pC);
   int yoffset = (int) FastMath.ceil(dot_pattern.length / 2.0);
   int xoffset = (int) FastMath.ceil(dot_pattern[0].length / 2.0);
   for (int i = 0; i < dot_pattern.length; i++) {
     for (int j = 0; j < dot_pattern[i].length; j++) {
       if (dot_pattern[i][j]) // comp2D.setColor(new Color(getColor())
       {
         // System.err.println("comp2D.fillRect");
         comp2D.fillRect(sC[0] - xoffset + j, sC[1] - yoffset + i, 1, 1);
       }
     }
   }
 }
Example #5
0
  public void drawShadowedText(String label, float alpha, double... pC) {
    int[] sC = projection.screenProjection(pC);

    // Corner offset adjustment : Text Offset is used Here
    FontRenderContext frc = comp2D.getFontRenderContext();
    Font font1 = comp2D.getFont();
    int x = sC[0];
    int y = sC[1];
    double w = font1.getStringBounds(label, frc).getWidth();
    double h = font1.getSize2D();
    x -= (int) (w * text_Eastoffset);
    y += (int) (h * text_Northoffset);

    int wc = (int) (w * FastMath.cos(text_angle) + h * FastMath.sin(text_angle));
    int hc = (int) (h * FastMath.cos(text_angle) + w * FastMath.sin(text_angle));
    if (!comp2D.hitClip(x, y, wc, hc)) {
      return;
    }

    if (text_angle != 0) {
      comp2D.rotate(text_angle, x + w / 2, y - h / 2);
    }

    Composite cs = comp2D.getComposite();
    Color c = comp2D.getColor();

    String[] lines = label.split("\n");
    for (int i = 0; i < lines.length; i++) {

      comp2D.setColor(Color.white);
      comp2D.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha));
      comp2D.fillRect(x, y - (int) h, (int) w, (int) h);
      comp2D.setComposite(cs);
      comp2D.setColor(c);

      comp2D.drawString(lines[i], x, y);
      y += h;
    }

    if (text_angle != 0) {
      comp2D.rotate(-text_angle, x + w / 2, y - h / 2);
    }
  }
Example #6
0
  /*
   * (non-Javadoc)
   *
   * @see org.math.plot.render.AbstractDrawer#drawPloygon(double[][])
   */
  public void drawPolygon(double[]... pC) {
    int[][] c = new int[pC.length][2];
    for (int i = 0; i < pC.length; i++) {
      c[i] = projection.screenProjection(pC[i]);
    }

    int minx = c[0][0], miny = c[0][1], maxx = c[0][0] + 1, maxy = c[0][1] + 1;
    int[] x = new int[c.length];
    for (int i = 0; i < c.length; i++) {
      x[i] = c[i][0];
      minx = FastMath.min(minx, x[i]);
      maxx = FastMath.max(maxx, x[i]);
    }
    int[] y = new int[c.length];
    for (int i = 0; i < c.length; i++) {
      y[i] = c[i][1];
      miny = FastMath.min(miny, y[i]);
      maxy = FastMath.max(maxy, y[i]);
    }

    if (comp2D.hitClip(minx, miny, maxx - minx, maxy - miny)) {
      comp2D.drawPolygon(x, y, c.length);
    }
  }
Example #7
0
 /*
  * (non-Javadoc)
  *
  * @see org.math.plot.render.AbstractDrawer#projectRatio(double[])
  */
 public int[] projectBase(double... rC) {
   return projection.screenProjectionBase(rC);
 }
Example #8
0
 /*
  * (non-Javadoc)
  *
  * @see org.math.plot.render.AbstractDrawer#project(double[])
  */
 public int[] project(double... pC) {
   return projection.screenProjection(pC);
 }
Example #9
0
  public AffineTransform getAffineTransform(
      int width, int height, double[] _xyzSW, double[] _xyzSE, double[] _xyzNW) {
    int[] cornerNW = projection.screenProjection(_xyzNW);
    int[] cornerSE = projection.screenProjection(_xyzSE);
    int[] cornerSW = projection.screenProjection(_xyzSW);

    double[] vectWE = {
      (double) cornerSE[0] - (double) cornerSW[0], (double) cornerSE[1] - (double) cornerSW[1]
    };
    double normvectWE = sqrt(sqr(vectWE[0]) + sqr(vectWE[1]));
    double[] vectSN = {
      (double) cornerNW[0] - (double) cornerSW[0], (double) cornerNW[1] - (double) cornerSW[1]
    };
    double normvectSN = sqrt(sqr(vectSN[0]) + sqr(vectSN[1]));
    double angleSW =
        acos((vectWE[0] * vectSN[0] + vectWE[1] * vectSN[1]) / (normvectWE * normvectSN));

    if (angleSW == 0.0) {
      return null;
    }

    AffineTransform t = new AffineTransform();

    t.translate(cornerNW[0], cornerNW[1]);
    t.scale(sign(vectWE[0]), -sign(vectSN[1]));
    t.rotate(-atan(vectSN[0] / vectSN[1]));
    t.shear(0, 1 / tan(PI - angleSW));
    t.scale(normvectWE * cos(angleSW - PI / 2) / (double) width, normvectSN / (double) height);

    double[] _cornerSE_tr = new double[2];
    double[] _cornerSE = {width, height};
    t.transform(_cornerSE, 0, _cornerSE_tr, 0, 1);

    if (isDiff(_cornerSE_tr, cornerSE)) {
      double[] vectSE_NW_1 = {
        (double) cornerNW[0] - (double) cornerSE[0], (double) cornerNW[1] - (double) cornerSE[1]
      };
      double[] vectSE_NW_2 = {
        (double) cornerNW[0] - (double) _cornerSE_tr[0],
        (double) cornerNW[1] - (double) _cornerSE_tr[1]
      };

      double normvect_1 = sqrt(sqr(vectSE_NW_1[0]) + sqr(vectSE_NW_1[1]));
      double normvect_2 = sqrt(sqr(vectSE_NW_1[0]) + sqr(vectSE_NW_1[1]));

      double cos_angle =
          (((vectSE_NW_1[0] * vectSE_NW_2[0] + vectSE_NW_1[1] * vectSE_NW_2[1])
              / (normvect_1 * normvect_2)));
      double vect = (vectSE_NW_1[0] * vectSE_NW_2[1] - vectSE_NW_1[1] * vectSE_NW_2[0]);

      AffineTransform t2 = new AffineTransform();
      if (vect < 0) {
        t2.rotate(acos(cos_angle), cornerNW[0], cornerNW[1]);
      } else {
        t2.rotate(-acos(cos_angle), cornerNW[0], cornerNW[1]);
      }
      t.preConcatenate(t2);
    }

    // TODO patch for many cases...

    /*double[] _cornerSW_tr = new double[2];
    double[] _cornerSW = { 0, img.getHeight(canvas) };
    t.transform(_cornerSW, 0, _cornerSW_tr, 0, 1);

    if (isDiff(_cornerSW_tr, cornerSW)) {
    double[] vectSW_NW_1 = { (double) cornerNW[0] - (double) cornerSW[0], (double) cornerNW[1] - (double) cornerSW[1] };
    double[] vectSW_NW_2 = { (double) cornerNW[0] - (double) _cornerSW_tr[0], (double) cornerNW[1] - (double) _cornerSW_tr[1] };

    double normvect_1 = sqrt(sqr(vectSW_NW_1[0]) + sqr(vectSW_NW_1[1]));
    double normvect_2 = sqrt(sqr(vectSW_NW_1[0]) + sqr(vectSW_NW_1[1]));

    double cos_angle = (((vectSW_NW_1[0] * vectSW_NW_2[0] + vectSW_NW_1[1] * vectSW_NW_2[1]) / (normvect_1 * normvect_2)));
    double vect = (vectSW_NW_1[0] * vectSW_NW_2[1] - vectSW_NW_1[1] * vectSW_NW_2[0]);

    System.out.println(cos_angle + " " + vect + " -> " + toDegrees(acos(cos_angle)));

    //System.out.println(" "+vectSE_NW_1[0]+","+vectSE_NW_1[1]+"  "+vectSE_NW_2[0]+","+vectSE_NW_2[1]);
    AffineTransform t2 = new AffineTransform();
    if (vect > 0)
    t2.rotate(acos(cos_angle), cornerNW[0], cornerNW[1]);
    else
    t2.rotate(-acos(cos_angle), cornerNW[0], cornerNW[1]);
    t.preConcatenate(t2);

    }*/
    return t;
  }
Example #10
0
 public void drawCrossDot(double... pC) {
   int[] sC = projection.screenProjection(pC);
   comp2D.drawLine(sC[0] - dot_radius, sC[1] - dot_radius, sC[0] + dot_radius, sC[1] + dot_radius);
   comp2D.drawLine(sC[0] + dot_radius, sC[1] - dot_radius, sC[0] - dot_radius, sC[1] + dot_radius);
 }
Example #11
0
 public void drawRoundDot(double... pC) {
   int[] sC = projection.screenProjection(pC);
   comp2D.fillOval(sC[0] - dot_radius, sC[1] - dot_radius, 2 * dot_radius, 2 * dot_radius);
 }
Example #12
0
 /*
  * (non-Javadoc)
  *
  * @see org.math.plot.render.AbstractDrawer#resetProjection()
  */
 public void resetBaseProjection() {
   projection.initBaseCoordsProjection(true);
 }
Example #13
0
 /*
  * (non-Javadoc)
  *
  * @see org.math.plot.render.AbstractDrawer#dilate(int[], double[])
  */
 public void dilate(int[] screenOrigin, double[] screenRatio) {
   projection.dilate(screenOrigin, screenRatio);
 }
Example #14
0
 /*
  * (non-Javadoc)
  *
  * @see org.math.plot.render.AbstractDrawer#translate(int[])
  */
 public void translate(int... t) {
   projection.translate(t);
 }