Esempio n. 1
0
  /**
   * Rotate
   *
   * @param d angle in radians
   *     <p>TODO Don't be lazy and do it directly on the values instead of creating another
   *     transform
   */
  public void rotate(final double d) {
    final double dcos = Math.cos(d);
    final double dsin = Math.sin(d);
    final AffineTransform2D dR = new AffineTransform2D();

    dR.set(dcos, -dsin, 0.0, dsin, dcos, 0.0);

    preConcatenate(dR);
  }
Esempio n. 2
0
  @Override
  public final AffineTransform2D preConcatenate(final AffineGet affine) {
    assert affine.numSourceDimensions() >= 2
        : "Only >=2d affine transformations can be pre-concatenated to a 2d affine transformation.";

    final double am00 = affine.get(0, 0);
    final double am01 = affine.get(0, 1);
    final double am02 = affine.get(0, 2);

    final double am10 = affine.get(1, 0);
    final double am11 = affine.get(1, 1);
    final double am12 = affine.get(1, 2);

    final double a00 = am00 * a.m00 + am01 * a.m10;
    final double a01 = am00 * a.m01 + am01 * a.m11;
    final double a02 = am00 * a.m02 + am01 * a.m12 + am02;

    final double a10 = am10 * a.m00 + am11 * a.m10;
    final double a11 = am10 * a.m01 + am11 * a.m11;
    final double a12 = am10 * a.m02 + am11 * a.m12 + am12;

    a.m00 = a00;
    a.m01 = a01;
    a.m02 = a02;

    a.m10 = a10;
    a.m11 = a11;
    a.m12 = a12;

    invert();
    updateDs();
    inverse.updateDs();

    return this;
  }
 @Override
 public void transformChanged(final AffineTransform2D transform) {
   synchronized (sourceToScreen) {
     sourceToScreen.set(transform);
   }
   renderTransformListener.transformChanged(transform);
   requestRepaint();
 }
  public JuliaRealViewer2DExample(
      final ComplexDoubleType c,
      final int maxIterations,
      final int maxAmplitude,
      final Converter<LongType, ARGBType> converter) {
    this.c = c;
    juliaset = new JuliaRealRandomAccessible(c, maxIterations, maxAmplitude);

    /* center shift */
    final AffineTransform2D centerShift = new AffineTransform2D();
    centerShift.set(1, 0, -width / 2.0, 0, 1, -height / 2.0);

    /* center un-shift */
    final AffineTransform2D centerUnShift = new AffineTransform2D();
    centerUnShift.set(1, 0, width / 2.0, 0, 1, height / 2.0);

    /* initialize rotation */
    final AffineTransform2D rotation = new AffineTransform2D();
    rotation.scale(200);

    rotation.preConcatenate(centerUnShift);

    final LogoPainter logo = new LogoPainter();
    viewer =
        new InteractiveRealViewer2D<LongType>(width, height, juliaset, rotation, converter) {
          @Override
          public void drawScreenImage() {
            super.drawScreenImage();
            logo.paint(screenImage);
          }
        };
    viewer.getDisplay().addHandler(new JuliaListener());
  }
Esempio n. 5
0
  /**
   * Translate
   *
   * @param t 2d translation vector
   */
  public void translate(final double... t) {
    assert t.length == 2 : "2d affine transformations can be translated by 2d vector only.";
    a.m02 += t[0];
    a.m12 += t[1];

    invert();
    updateDs();
    inverse.updateDs();
  }
Esempio n. 6
0
  protected AffineTransform2D(final AffineMatrix2D a) {
    this.a = a;

    d0 = new RealPoint(2);
    d1 = new RealPoint(2);
    ds = new RealPoint[] {d0, d1};
    updateDs();

    inverse = new AffineTransform2D(this);
    invert();
    inverse.updateDs();
  }
Esempio n. 7
0
  /**
   * Scale
   *
   * @param d scale factor
   */
  public void scale(final double d) {
    a.m00 *= d;
    a.m01 *= d;
    a.m02 *= d;
    a.m10 *= d;
    a.m11 *= d;
    a.m12 *= d;

    invert();
    updateDs();
    inverse.updateDs();
  }
Esempio n. 8
0
  @Override
  public void set(final double[][] values) {
    assert values.length >= 2 && values[0].length >= 3 && values[1].length == 3
        : "Input dimensions do not match.  A 2d affine matrix is a 2x3 matrix.";

    a.m00 = values[0][0];
    a.m01 = values[0][1];
    a.m02 = values[0][2];

    a.m10 = values[1][0];
    a.m11 = values[1][1];
    a.m12 = values[1][2];

    updateDs();
    invert();
    inverse.updateDs();
  }
Esempio n. 9
0
  @Override
  public void set(final double... values) {
    assert values.length >= 6
        : "Input dimensions do not match.  A 2d affine matrix is a 2x3 matrix.";

    a.m00 = values[0];
    a.m01 = values[1];
    a.m02 = values[2];

    a.m10 = values[3];
    a.m11 = values[4];
    a.m12 = values[5];

    updateDs();
    invert();
    inverse.updateDs();
  }
Esempio n. 10
0
  public final void set(final AffineTransform2D m) {
    a.m00 = m.a.m00;
    a.m10 = m.a.m10;
    a.m01 = m.a.m01;
    a.m11 = m.a.m11;
    a.m02 = m.a.m02;
    a.m12 = m.a.m12;

    inverse.a.m00 = m.inverse.a.m00;
    inverse.a.m10 = m.inverse.a.m10;
    inverse.a.m01 = m.inverse.a.m01;
    inverse.a.m11 = m.inverse.a.m11;
    inverse.a.m02 = m.inverse.a.m02;
    inverse.a.m12 = m.inverse.a.m12;

    updateDs();
    inverse.updateDs();
  }
Esempio n. 11
0
  public final AffineTransform2D preConcatenate(final AffineTransform2D affine) {
    final double a00 = affine.a.m00 * a.m00 + affine.a.m01 * a.m10;
    final double a01 = affine.a.m00 * a.m01 + affine.a.m01 * a.m11;
    final double a02 = affine.a.m00 * a.m02 + affine.a.m01 * a.m12 + affine.a.m02;

    final double a10 = affine.a.m10 * a.m00 + affine.a.m11 * a.m10;
    final double a11 = affine.a.m10 * a.m01 + affine.a.m11 * a.m11;
    final double a12 = affine.a.m10 * a.m02 + affine.a.m11 * a.m12 + affine.a.m12;

    a.m00 = a00;
    a.m01 = a01;
    a.m02 = a02;

    a.m10 = a10;
    a.m11 = a11;
    a.m12 = a12;

    invert();
    updateDs();
    inverse.updateDs();

    return this;
  }
Esempio n. 12
0
  public final AffineTransform2D concatenate(final AffineTransform2D model) {
    final double a00 = a.m00 * model.a.m00 + a.m01 * model.a.m10;
    final double a01 = a.m00 * model.a.m01 + a.m01 * model.a.m11;
    final double a02 = a.m00 * model.a.m02 + a.m01 * model.a.m12 + a.m02;

    final double a10 = a.m10 * model.a.m00 + a.m11 * model.a.m10;
    final double a11 = a.m10 * model.a.m01 + a.m11 * model.a.m11;
    final double a12 = a.m10 * model.a.m02 + a.m11 * model.a.m12 + a.m12;

    a.m00 = a00;
    a.m01 = a01;
    a.m02 = a02;

    a.m10 = a10;
    a.m11 = a11;
    a.m12 = a12;

    invert();
    updateDs();
    inverse.updateDs();

    return this;
  }
Esempio n. 13
0
  @Override
  public void set(final double value, final int row, final int column) {
    assert row >= 0 && row < 2 && column >= 0 && column < 3
        : "Index out of bounds, a 2d affine matrix is a 2x3 matrix.";

    switch (row) {
      case 0:
        switch (column) {
          case 0:
            a.m00 = value;
            break;
          case 1:
            a.m01 = value;
            break;
          default:
            a.m02 = value;
        }
        break;
      default:
        switch (column) {
          case 0:
            a.m10 = value;
            break;
          case 1:
            a.m11 = value;
            break;
          default:
            a.m12 = value;
            break;
        }
    }

    updateDs();
    invert();
    inverse.updateDs();
  }
 public double getScale() {
   final AffineTransform2D a = viewer.getDisplay().getViewerTransform();
   final double ax = a.get(0, 0);
   final double ay = a.get(0, 1);
   return Math.sqrt(ax * ax + ay * ay);
 }