/**
  * Writes the <code>shape</code>, <code>coords</code>, <code>href</code>,
  * <code>nohref</code> Attribute for the specified figure and ellipse.
  *
  * @return Returns true, if the circle is inside of the image bounds.
  */
 private boolean writeCircleAttributes(IXMLElement elem, SVGFigure f, Ellipse2D.Double ellipse) {
     AffineTransform t = TRANSFORM.getClone(f);
     if (t == null) {
         t = drawingTransform;
     } else {
         t.preConcatenate(drawingTransform);
     }
     
     if ((t.getType() &
             (AffineTransform.TYPE_UNIFORM_SCALE | AffineTransform.TYPE_TRANSLATION)) ==
             t.getType() &&
             ellipse.width == ellipse.height
             ) {
         
         Point2D.Double start = new Point2D.Double(ellipse.x, ellipse.y);
         Point2D.Double end = new Point2D.Double(ellipse.x + ellipse.width, ellipse.y + ellipse.height);
         t.transform(start, start);
         t.transform(end, end);
         ellipse.x = Math.min(start.x, end.x);
         ellipse.y = Math.min(start.y, end.y);
         ellipse.width = Math.abs(start.x - end.x);
         ellipse.height = Math.abs(start.y - end.y);
         
         elem.setAttribute("shape", "circle");
         elem.setAttribute("coords",
                 (int) (ellipse.x + ellipse.width / 2d)+","+
                 (int) (ellipse.y + ellipse.height / 2d)+","+
                 (int) (ellipse.width / 2d)
                 );
         writeHrefAttribute(elem, f);
         return bounds.intersects(ellipse.getBounds());
     } else {
         return writePolyAttributes(elem, f, (Shape) ellipse);
     }
 }
示例#2
0
 /**
  * Transforms the figure.
  *
  * @param tx the transformation.
  */
 public void transform(AffineTransform tx) {
   if (TRANSFORM.get(this) != null
       || tx.getType() != (tx.getType() & AffineTransform.TYPE_TRANSLATION)) {
     if (TRANSFORM.get(this) == null) {
       TRANSFORM.basicSet(this, (AffineTransform) tx.clone());
     } else {
       AffineTransform t = TRANSFORM.getClone(this);
       t.preConcatenate(tx);
       TRANSFORM.basicSet(this, t);
     }
   } else {
     for (int i = 0; i < coordinates.length; i++) {
       tx.transform(coordinates[i], coordinates[i]);
     }
     if (FILL_GRADIENT.get(this) != null && !FILL_GRADIENT.get(this).isRelativeToFigureBounds()) {
       Gradient g = FILL_GRADIENT.getClone(this);
       g.transform(tx);
       FILL_GRADIENT.basicSet(this, g);
     }
     if (STROKE_GRADIENT.get(this) != null
         && !STROKE_GRADIENT.get(this).isRelativeToFigureBounds()) {
       Gradient g = STROKE_GRADIENT.getClone(this);
       g.transform(tx);
       STROKE_GRADIENT.basicSet(this, g);
     }
   }
   invalidate();
 }
示例#3
0
  /**
   * Code to paint the specific shape
   *
   * @param w2v 2D affine transform
   * @param g graphics context
   */
  public void paintShape(Graphics2D g, AffineTransform w2v) {
    double x = startPoint.getX();
    double y = startPoint.getY();
    double xEnd = endPoint.getX();
    double yEnd = endPoint.getY();

    g.setStroke(new BasicStroke(this.getThickness(), BasicStroke.CAP_ROUND, BasicStroke.CAP_ROUND));

    Point2D v0 = w2v.transform(new Point2D.Double(x, y), null);
    int ix = (int) v0.getX();
    int iy = (int) v0.getY();

    Point2D v1 = w2v.transform(new Point2D.Double(xEnd, yEnd), null);

    g.drawLine(ix, iy, (int) v1.getX(), (int) v1.getY());
  }
示例#4
0
  public synchronized void paint(Graphics gin) {
    Graphics2D g = (Graphics2D) gin;

    if (im == null) return;

    int height = getHeight();
    int width = getWidth();

    if (fit) {
      t = new AffineTransform();
      double scale = Math.min(((double) width) / im.getWidth(), ((double) height) / im.getHeight());
      // we'll re-center the transform in a moment.
      t.scale(scale, scale);
    }

    // if the image (in either X or Y) is smaller than the view port, then center
    // the image with respect to that axis.
    double mwidth = im.getWidth() * t.getScaleX();
    double mheight = im.getHeight() * t.getScaleY();
    if (mwidth < width)
      t.preConcatenate(
          AffineTransform.getTranslateInstance((width - mwidth) / 2.0 - t.getTranslateX(), 0));
    if (mheight < height)
      t.preConcatenate(
          AffineTransform.getTranslateInstance(0, (height - mheight) / 2.0 - t.getTranslateY()));

    // if we're allowing panning (because only a portion of the image is visible),
    // don't allow translations that show less information that is possible.
    Point2D topleft = t.transform(new Point2D.Double(0, 0), null);
    Point2D bottomright = t.transform(new Point2D.Double(im.getWidth(), im.getHeight()), null);

    if (mwidth > width) {
      if (topleft.getX() > 0)
        t.preConcatenate(AffineTransform.getTranslateInstance(-topleft.getX(), 0));
      if (bottomright.getX() < width)
        t.preConcatenate(AffineTransform.getTranslateInstance(width - bottomright.getX(), 0));
      //		    t.translate(width-bottomright.getX(), 0);
    }
    if (mheight > height) {
      if (topleft.getY() > 0)
        t.preConcatenate(AffineTransform.getTranslateInstance(0, -topleft.getY()));
      if (bottomright.getY() < height)
        t.preConcatenate(AffineTransform.getTranslateInstance(0, height - bottomright.getY()));
    }

    g.drawImage(im, t, null);
  }
示例#5
0
 public float getFontSize() {
   //   return FONT_SIZE.get(this).floatValue();
   Point2D.Double p = new Point2D.Double(0, FONT_SIZE.get(this));
   AffineTransform tx = TRANSFORM.get(this);
   if (tx != null) {
     tx.transform(p, p);
     Point2D.Double p0 = new Point2D.Double(0, 0);
     tx.transform(p0, p0);
     p.y -= p0.y;
     /*
     try {
         tx.inverseTransform(p, p);
     } catch (NoninvertibleTransformException ex) {
         ex.printStackTrace();
     }*/
   }
   return (float) Math.abs(p.y);
 }
示例#6
0
  /**
   * WhiteboardShapeLine constructor
   *
   * @param id String that uniquely identifies this WhiteboardObject.
   * @param t number of pixels that this object (or its border)
   * @param c WhiteboardShapeLine's color (or rather it's border)
   * @param startPoint the start coordinates of this line.
   * @param endPoint the end coordinates of this line.
   * @param v2w 2D affine transform
   */
  public WhiteboardShapeLine(
      String id,
      int t,
      Color c,
      WhiteboardPoint startPoint,
      WhiteboardPoint endPoint,
      AffineTransform v2w) {
    super(id);
    this.setThickness(t);
    setColor(c);

    Point2D v0 = new Point2D.Double(startPoint.getX(), startPoint.getY());
    Point2D w0 = v2w.transform(v0, null);

    this.startPoint = new WhiteboardPoint(w0.getX(), w0.getY());

    Point2D v1 = new Point2D.Double(endPoint.getX(), endPoint.getY());
    Point2D w1 = v2w.transform(v1, null);

    this.endPoint = new WhiteboardPoint(w1.getX(), w1.getY());
  }
 /**
  * Writes the <code>shape</code>, <code>coords</code>, <code>href</code>,
  * <code>nohref</code> Attribute for the specified figure and rectangle.
  *
  * @return Returns true, if the rect is inside of the image bounds.
  */
 private boolean writeRectAttributes(IXMLElement elem, SVGFigure f, Rectangle2D.Double rect) {
     AffineTransform t = TRANSFORM.getClone(f);
     if (t == null) {
         t = drawingTransform;
     } else {
         t.preConcatenate(drawingTransform);
     }
     
     if ((t.getType() &
             (AffineTransform.TYPE_UNIFORM_SCALE | AffineTransform.TYPE_TRANSLATION)) ==
             t.getType()
             ) {
         
         Point2D.Double start = new Point2D.Double(rect.x, rect.y);
         Point2D.Double end = new Point2D.Double(rect.x + rect.width, rect.y + rect.height);
         t.transform(start, start);
         t.transform(end, end);
         Rectangle r = new Rectangle(
                 (int) Math.min(start.x, end.x),
                 (int) Math.min(start.y, end.y),
                 (int) Math.abs(start.x - end.x),
                 (int) Math.abs(start.y - end.y)
                 );
         
         elem.setAttribute("shape", "rect");
         elem.setAttribute("coords",
                 r.x + ","+
                 r.y + ","+
                 (r.x + r.width) + ","+
                 (r.y + r.height)
                 );
         writeHrefAttribute(elem, f);
         return bounds.intersects(r);
     } else {
         return writePolyAttributes(elem, f, (Shape) rect);
     }
 }
示例#8
0
 public void vec2FieldMagnitude(Field field, AffineTransform ftoi) {
   AffineTransform itof = null;
   try {
     itof = ftoi.createInverse();
   } catch (NoninvertibleTransformException niv) {
     TDebug.println(0, "NoninvertibleTransformException: " + niv);
   }
   Vector3d v = new Vector3d();
   Point2D.Double p = new Point2D.Double();
   for (int j = 0, k = 0; j < height; ++j)
     for (int i = 0; i < width; ++i, ++k) {
       p.x = i;
       p.y = j;
       itof.transform(p, p);
       v = field.get(p.x, p.y, 0.0);
       f[k] = (float) Math.sqrt(v.x * v.x + v.y * v.y);
     }
 }
示例#9
0
 public void vec2FieldZero(Field field, AffineTransform ftoi) {
   AffineTransform itof = null;
   try {
     itof = ftoi.createInverse();
   } catch (NoninvertibleTransformException niv) {
     TDebug.println(0, "NoninvertibleTransformException: " + niv);
   }
   Vector3d v = new Vector3d();
   Point2D.Double p = new Point2D.Double();
   for (int j = 0, k = 0; j < height; ++j)
     for (int i = 0; i < width; ++i, ++k) {
       p.x = i;
       p.y = j;
       itof.transform(p, p);
       v = field.get(p.x, p.y, 0.0);
       if ((v.x == 0.0) && (v.y == 0.0)) f[k] = 1.0f;
       else f[k] = 0.0f;
     }
 }
示例#10
0
 // SHAPE AND BOUNDS
 @Override
 public void transform(AffineTransform tx) {
   tx.transform(origin, origin);
 }
  /**
   * Sets the CardinalityPoints attribute of the RelationLine object
   *
   * @todo refactor this duplicate code!!!
   */
  private void setCardinalityPoints() {
    // compute vector of length 1
    _mainLength =
        Point2D.distance(
            _mainLine.getX1(), _mainLine.getY1(), _mainLine.getX2(), _mainLine.getY2());
    double vx = (_mainLine.getX2() - _mainLine.getX1()) / _mainLength;
    double vy = (_mainLine.getY2() - _mainLine.getY1()) / _mainLength;
    double cardx = 20.0 * vx;
    double cardy = 20.0 * vy;
    double arrowx = 30.0 * vx;
    double arrowy = 30.0 * vy;
    if (_leftIsWest) {
      _leftArrowPoint.setLocation(_mainLine.getX1() + cardx, _mainLine.getY1() + cardy);
      _rightArrowPoint.setLocation(_mainLine.getX2() - cardx, _mainLine.getY2() - cardy);

      // The left-side arrow head
      _temp.setLocation(_mainLine.getX1() + arrowx, _mainLine.getY1() + arrowy);

      _arrowTransform.setToRotation(Math.PI / 6, _leftArrowPoint.getX(), _leftArrowPoint.getY());
      _arrowTransform.transform(_temp, _leftArrowPoint1);
      _leftArrowLine1.setLine(
          _leftArrowPoint.getX(),
          _leftArrowPoint.getY(),
          _leftArrowPoint1.getX(),
          _leftArrowPoint1.getY());

      _arrowTransform.setToRotation(-Math.PI / 6, _leftArrowPoint.getX(), _leftArrowPoint.getY());
      _arrowTransform.transform(_temp, _leftArrowPoint2);
      _leftArrowLine2.setLine(
          _leftArrowPoint.getX(),
          _leftArrowPoint.getY(),
          _leftArrowPoint2.getX(),
          _leftArrowPoint2.getY());

      _arrowTransform.setToRotation(Math.PI / 2, _leftArrowPoint.getX(), _leftArrowPoint.getY());
      _arrowTransform.transform(_temp, _leftCardinalityPoint);

      _arrowTransform.setToRotation(-Math.PI / 2, _leftArrowPoint.getX(), _leftArrowPoint.getY());
      _arrowTransform.transform(_temp, _leftFkPoint);

      // The right-side arrow head
      _temp.setLocation(_mainLine.getX2() - arrowx, _mainLine.getY2() - arrowy);

      _arrowTransform.setToRotation(Math.PI / 6, _rightArrowPoint.getX(), _rightArrowPoint.getY());
      _arrowTransform.transform(_temp, _rightArrowPoint1);
      _rightArrowLine1.setLine(
          _rightArrowPoint.getX(),
          _rightArrowPoint.getY(),
          _rightArrowPoint1.getX(),
          _rightArrowPoint1.getY());

      _arrowTransform.setToRotation(-Math.PI / 6, _rightArrowPoint.getX(), _rightArrowPoint.getY());
      _arrowTransform.transform(_temp, _rightArrowPoint2);
      _rightArrowLine2.setLine(
          _rightArrowPoint.getX(),
          _rightArrowPoint.getY(),
          _rightArrowPoint2.getX(),
          _rightArrowPoint2.getY());

      _arrowTransform.setToRotation(-Math.PI / 2, _rightArrowPoint.getX(), _rightArrowPoint.getY());
      _arrowTransform.transform(_temp, _rightCardinalityPoint);

      _arrowTransform.setToRotation(Math.PI / 2, _rightArrowPoint.getX(), _rightArrowPoint.getY());
      _arrowTransform.transform(_temp, _rightFkPoint);
    } else {
      _leftArrowPoint.setLocation(_mainLine.getX2() - cardx, _mainLine.getY2() - cardy);
      _rightArrowPoint.setLocation(_mainLine.getX1() + cardx, _mainLine.getY1() + cardy);

      // The left-side arrow head
      _temp.setLocation(_mainLine.getX2() - arrowx, _mainLine.getY2() - arrowy);

      _arrowTransform.setToRotation(Math.PI / 6, _leftArrowPoint.getX(), _leftArrowPoint.getY());
      _arrowTransform.transform(_temp, _leftArrowPoint1);
      _leftArrowLine1.setLine(
          _leftArrowPoint.getX(),
          _leftArrowPoint.getY(),
          _leftArrowPoint1.getX(),
          _leftArrowPoint1.getY());

      _arrowTransform.setToRotation(-Math.PI / 6, _leftArrowPoint.getX(), _leftArrowPoint.getY());
      _arrowTransform.transform(_temp, _leftArrowPoint2);
      _leftArrowLine2.setLine(
          _leftArrowPoint.getX(),
          _leftArrowPoint.getY(),
          _leftArrowPoint2.getX(),
          _leftArrowPoint2.getY());

      _arrowTransform.setToRotation(Math.PI / 2, _leftArrowPoint.getX(), _leftArrowPoint.getY());
      _arrowTransform.transform(_temp, _leftCardinalityPoint);

      _arrowTransform.setToRotation(-Math.PI / 2, _leftArrowPoint.getX(), _leftArrowPoint.getY());
      _arrowTransform.transform(_temp, _leftFkPoint);

      // The right-side arrow head
      _temp.setLocation(_mainLine.getX1() + arrowx, _mainLine.getY1() + arrowy);

      _arrowTransform.setToRotation(Math.PI / 6, _rightArrowPoint.getX(), _rightArrowPoint.getY());
      _arrowTransform.transform(_temp, _rightArrowPoint1);
      _rightArrowLine1.setLine(
          _rightArrowPoint.getX(),
          _rightArrowPoint.getY(),
          _rightArrowPoint1.getX(),
          _rightArrowPoint1.getY());

      _arrowTransform.setToRotation(-Math.PI / 6, _rightArrowPoint.getX(), _rightArrowPoint.getY());
      _arrowTransform.transform(_temp, _rightArrowPoint2);
      _rightArrowLine2.setLine(
          _rightArrowPoint.getX(),
          _rightArrowPoint.getY(),
          _rightArrowPoint2.getX(),
          _rightArrowPoint2.getY());

      _arrowTransform.setToRotation(-Math.PI / 2, _rightArrowPoint.getX(), _rightArrowPoint.getY());
      _arrowTransform.transform(_temp, _rightCardinalityPoint);

      _arrowTransform.setToRotation(Math.PI / 2, _rightArrowPoint.getX(), _rightArrowPoint.getY());
      _arrowTransform.transform(_temp, _rightFkPoint);
    }
  }
示例#12
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;
  }