Examples of JEPWrapper


Examples of org.jwildfire.base.mathparser.JEPWrapper

    else {
      fgTop = this.top;
    }

    // Initialize the parser
    JEPWrapper parser = new JEPWrapper();
    parser.addVariable("fgR", 0.0);
    parser.addVariable("fgG", 0.0);
    parser.addVariable("fgB", 0.0);
    parser.addVariable("fgWidth", (double) fgWidth);
    parser.addVariable("fgHeight", (double) fgHeight);
    parser.addVariable("bgR", 0.0);
    parser.addVariable("bgG", 0.0);
    parser.addVariable("bgB", 0.0);
    parser.addVariable("bgWidth", (double) bgWidth);
    parser.addVariable("bgHeight", (double) bgHeight);
    parser.addVariable("fgLeft", (double) fgLeft);
    parser.addVariable("fgTop", (double) fgTop);
    parser.addVariable("fgX", 0.0);
    parser.addVariable("fgY", 0.0);
    Node redNode = parser.parse(formula1Red);
    Node greenNode = parser.parse(formula2Green);
    Node blueNode = parser.parse(formula3Blue);
    // compose the images
    for (int i = 0; i < fgHeight; i++) {
      int top = fgTop + i;
      if (top >= 0 && top < bgHeight) {
        parser.setVarValue("fgY", (double) i / 255.0);
        for (int j = 0; j < fgWidth; j++) {
          int left = fgLeft + j;
          if (left >= 0 && left < bgWidth) {
            parser.setVarValue("fgX", (double) j / 255.0);
            bgPixel.setARGBValue(bgImg.getARGBValue(left, top));
            fgPixel.setARGBValue(fgImg.getARGBValue(j, i));
            parser.setVarValue("bgR", (double) bgPixel.r / 255.0);
            parser.setVarValue("bgG", (double) bgPixel.g / 255.0);
            parser.setVarValue("bgB", (double) bgPixel.b / 255.0);
            parser.setVarValue("fgR", (double) fgPixel.r / 255.0);
            parser.setVarValue("fgG", (double) fgPixel.g / 255.0);
            parser.setVarValue("fgB", (double) fgPixel.b / 255.0);

            // TODO Genlock: z. B. Testen, ob Intensit�t 0 oder gr��er 0
            // genlockFormula, genlockOperator (gleich, gr��er), genlockRefValue

            bgPixel.r = Tools.roundColor((Double) parser.evaluate(redNode) * 255.0);
            bgPixel.g = Tools.roundColor((Double) parser.evaluate(greenNode) * 255.0);
            bgPixel.b = Tools.roundColor((Double) parser.evaluate(blueNode) * 255.0);
            bgImg.setRGB(left, top, bgPixel);
          }
        }
      }
    }
View Full Code Here

Examples of org.jwildfire.base.mathparser.JEPWrapper

  @Override
  protected void fillImage(SimpleImage res) {
    if (this.seed != 0)
      Tools.srand123(this.seed);
    JEPWrapper parser = null;
    Node node = null;
    if (transform) {
      parser = new JEPWrapper();
      parser.addVariable("x", 0.0);
      node = parser.parse(transformation);
    }

    switch (colorMode) {
      case RANDOM:
        cA.randomize();
        cB.randomize();
        break;
      case CUSTOM:
        cA.setR(lowColor.getRed());
        cA.setG(lowColor.getGreen());
        cA.setB(lowColor.getBlue());
        cB.setR(highColor.getRed());
        cB.setG(highColor.getGreen());
        cB.setB(highColor.getBlue());
        break;
    }
    initShape();
    int width = res.getImageWidth();
    int height = res.getImageHeight();
    for (int i = 0; i < height; i++) {
      double y = (double) i / (double) height;
      for (int j = 0; j < width; j++) {
        double x = (double) j / (double) width;

        double freq = initialFrequency;
        double alphaInt = 1.0;
        double grayValue = 0.0;
        for (int l = 0; l < octaves; l++) {
          double noiseValue = noise(x * freq, y * freq, 0.0);
          if (transform) {
            parser.setVarValue("x", noiseValue);
            noiseValue = (Double) parser.evaluate(node);
          }
          grayValue += alphaInt * noiseValue;
          freq *= frequencyMultiplier;
          alphaInt *= persistence;
        }
View Full Code Here

Examples of org.jwildfire.base.mathparser.JEPWrapper

    double xstep;
    int xCount = Integer.parseInt(xCountREd.getText());
    if (xCount < 2)
      xCount = 2;
    xstep = (xmax - xmin) / (double) (xCount - 1);
    JEPWrapper parser = new JEPWrapper();
    parser.addVariable("x", 0.0);
    Node[] fNode = new Node[MAX_FORMULA_COUNT];
    int fCount = 0;
    if (formula1REd.getText() != null && formula1REd.getText().length() > 0)
      fNode[fCount++] = parser.parse(formula1REd.getText());
    if (formula2REd.getText() != null && formula2REd.getText().length() > 0)
      fNode[fCount++] = parser.parse(formula2REd.getText());
    if (formula3REd.getText() != null && formula3REd.getText().length() > 0)
      fNode[fCount++] = parser.parse(formula3REd.getText());
    if (fCount == 0)
      fNode[fCount++] = parser.parse("0");
    double x[] = new double[xCount];
    double y[][] = new double[fCount][xCount];
    double xc = xmin;
    for (int i = 0; i < xCount; i++) {
      x[i] = xc;
      parser.setVarValue("x", xc);
      sb.append("  f(" + Tools.doubleToString(x[i]) + ")  \t");
      for (int j = 0; j < fCount; j++) {
        y[j][i] = (Double) parser.evaluate(fNode[j]);
        sb.append(Tools.doubleToString(y[j][i]) + " \t");
      }
      sb.append("\n");
      xc += xstep;
    }
View Full Code Here

Examples of org.jwildfire.base.mathparser.JEPWrapper

    int height = pImageHeight;
    double x[] = pMesh3D.getX();
    double y[] = pMesh3D.getY();
    double z[] = pMesh3D.getZ();

    JEPWrapper parser = new JEPWrapper();
    parser.addVariable("x", 0.0);
    Node node = parser.parse(formula);

    // Don't calculate the actual bounding box because this may cause unexpected results if the object was deformed by another tansformer before
    double objXMin = -(double) width / 2.0;
    //      double objXMax = (double) width / 2.0;
    double objYMin = -(double) height / 2.0;
    //      double objYMax = (double) height / 2.0;
    double objXSize = (double) width;
    double objYSize = (double) height;

    double dx = this.xMax - this.xMin;

    if (this.axis == Axis.X) {
      if (!this.damp) {
        for (int i = 0; i < pCount; i++) {
          double xx = ((x[i] - objXMin) * dx) / objXSize + xMin;
          parser.setVarValue("x", xx);
          double amp = (Double) parser.evaluate(node);
          z[i] -= amp;
        }
      }
      else {
        for (int i = 0; i < pCount; i++) {
          double xx = ((x[i] - objXMin) * dx) / objXSize + xMin;
          parser.setVarValue("x", xx);
          double amp = (Double) parser.evaluate(node);
          double dxx = ((x[i] - objXMin) * dx) / objXSize + xMin - originX;
          double drr = Math.abs(dxx);
          double dmp = drr * damping;
          amp *= Math.exp(dmp);
          z[i] -= amp;
        }
      }
    }
    else if (this.axis == Axis.Y) {
      if (!this.damp) {
        for (int i = 0; i < pCount; i++) {
          double yy = ((y[i] - objYMin) * dx) / objYSize + xMin;
          parser.setVarValue("x", yy);
          double amp = (Double) parser.evaluate(node);
          z[i] -= amp;
        }
      }
      else {
        for (int i = 0; i < pCount; i++) {
          double yy = ((y[i] - objYMin) * dx) / objYSize + xMin;
          parser.setVarValue("x", yy);
          double amp = (Double) parser.evaluate(node);
          double dyy = ((y[i] - objYMin) * dx) / objYSize + xMin - originY;
          double drr = Math.abs(dyy);
          double dmp = drr * damping;
          amp *= Math.exp(dmp);
          z[i] -= amp;
        }
      }
    }
    else if (this.axis == Axis.XY) {
      if (!this.damp) {
        for (int i = 0; i < pCount; i++) {
          double xx = ((x[i] - objXMin) * dx) / objXSize + xMin;
          double yy = ((y[i] - objYMin) * dx) / objYSize + xMin;
          double rr = Math.sqrt(xx * xx + yy * yy);
          parser.setVarValue("x", rr);
          double amp = (Double) parser.evaluate(node);
          z[i] -= amp;
        }
      }
      else {
        for (int i = 0; i < pCount; i++) {
          double xx = ((x[i] - objXMin) * dx) / objXSize + xMin;
          double yy = ((y[i] - objYMin) * dx) / objYSize + xMin;
          double rr = Math.sqrt(xx * xx + yy * yy);
          parser.setVarValue("x", rr);
          double amp = (Double) parser.evaluate(node);

          double dxx = ((x[i] - objXMin) * dx) / objXSize + xMin - originX;
          double dyy = ((y[i] - objYMin) * dx) / objYSize + xMin - originY;
          double drr = Math.sqrt(dxx * dxx + dyy * dyy);
          double dmp = drr * damping;
          amp *= Math.exp(dmp);
          z[i] -= amp;
        }
      }
    }
    else { /* radial */
      if (!this.damp) {
        for (int i = 0; i < pCount; i++) {
          double xx = ((x[i] - objXMin) * dx) / objXSize + xMin - originX;
          double yy = ((y[i] - objYMin) * dx) / objYSize + xMin - originY;
          double zz = z[i] - originZ;
          double rr = Math.sqrt(xx * xx + yy * yy + zz * zz);
          parser.setVarValue("x", rr);
          double amp = (Double) parser.evaluate(node);
          double vx, vy, vz;
          if (rr > 0.00001) {
            vx = xx / rr;
            vy = yy / rr;
            vz = zz / rr;
          }
          else {
            vx = vy = 0.0;
            vz = 1.0;
          }
          x[i] += vx * amp;
          y[i] += vy * amp;
          z[i] += vz * amp;
        }
      }
      else {
        for (int i = 0; i < pCount; i++) {
          double xx = ((x[i] - objXMin) * dx) / objXSize + xMin - originX;
          double yy = ((y[i] - objYMin) * dx) / objYSize + xMin - originY;
          double zz = z[i] - originZ;
          double rr = Math.sqrt(xx * xx + yy * yy + zz * zz);
          parser.setVarValue("x", rr);
          double amp = (Double) parser.evaluate(node);

          double drr = rr;
          double dmp = drr * damping;
          amp *= Math.exp(dmp);

View Full Code Here

Examples of org.jwildfire.base.mathparser.JEPWrapper

    int height = pImageHeight;
    double x[] = pMesh3D.getX();
    double y[] = pMesh3D.getY();
    double z[] = pMesh3D.getZ();

    JEPWrapper parser = new JEPWrapper();
    parser.addVariable("u", 0.0);
    parser.addVariable("v", 0.0);
    Node xNode = parser.parse(xFormula);
    Node yNode = parser.parse(yFormula);
    Node zNode = parser.parse(zFormula);

    // Don't calculate the actual bounding box because this may cause unexpected results if the object was deformed by another tansformer before
    double objUMin = -(double) width / 2.0;
    //      double objXMax = (double) width / 2.0;
    double objVMin = -(double) height / 2.0;
    //      double objYMax = (double) height / 2.0;
    double objUSize = (double) width;
    double objVSize = (double) height;

    double du = this.uMax - this.uMin;
    double dv = this.vMax - this.vMin;

    double xMin = 0.0, yMin = 0.0, zMin = 0.0;
    double xMax = 0.0, yMax = 0.0, zMax = 0.0;

    double oriZMin = 0.0, oriZMax = 0.0;
    for (int i = 0; i < pCount; i++) {
      if (z[i] < oriZMin)
        oriZMin = z[i];
      else if (z[i] > oriZMax)
        oriZMax = z[i];
    }
    double oriZSize = oriZMax - oriZMin;
    double oriZScale = oriZSize / Math.sqrt(width * width + height * height);
    for (int i = 0; i < pCount; i++) {
      double zz = oriZSize > MathLib.EPSILON ? z[i] / oriZSize * oriZScale : 0.0;
      double uu = ((x[i] - objUMin) * du) / objUSize + uMin;
      double vv = ((y[i] - objVMin) * dv) / objVSize + vMin;
      parser.setVarValue("u", uu);
      parser.setVarValue("v", vv);
      x[i] = (Double) parser.evaluate(xNode) * (1 + zz * this.zScale);
      if (x[i] < xMin)
        xMin = x[i];
      else if (x[i] > xMax)
        xMax = x[i];
      y[i] = (Double) parser.evaluate(yNode) * (1 + zz * this.zScale);
      if (y[i] < yMin)
        yMin = y[i];
      else if (y[i] > yMax)
        yMax = y[i];
      z[i] = (Double) parser.evaluate(zNode) * (1 + zz * this.zScale);
      if (z[i] < zMin)
        zMin = z[i];
      else if (z[i] > zMax)
        zMax = z[i];
    }
View Full Code Here

Examples of org.jwildfire.base.mathparser.JEPWrapper

  protected void performPixelTransformation(WFImage pImg) {
    SimpleImage img = (SimpleImage) pImg;
    int width = pImg.getImageWidth();
    int height = pImg.getImageHeight();

    JEPWrapper parser = new JEPWrapper();
    parser.addVariable("r", 0.0);
    parser.addVariable("g", 0.0);
    parser.addVariable("b", 0.0);
    parser.addVariable("x", 0.0);
    parser.addVariable("y", 0.0);
    parser.addVariable("width", (double) width);
    parser.addVariable("height", (double) height);
    Node redNode = parser.parse(formula1Red);
    Node greenNode = parser.parse(formula2Green);
    Node blueNode = parser.parse(formula3Blue);

    Pixel pixel = new Pixel();
    for (int i = 0; i < height; i++) {
      parser.setVarValue("y", i);
      for (int j = 0; j < width; j++) {
        parser.setVarValue("x", j);
        pixel.setARGBValue(srcImg.getARGBValue(j, i));
        if (useOriginalRGBValues) {
          parser.setVarValue("r", (double) pixel.r);
          parser.setVarValue("g", (double) pixel.g);
          parser.setVarValue("b", (double) pixel.b);
          pixel.r = Tools.roundColor((Double) parser.evaluate(redNode));
          pixel.g = Tools.roundColor((Double) parser.evaluate(greenNode));
          pixel.b = Tools.roundColor((Double) parser.evaluate(blueNode));
        }
        else {
          parser.setVarValue("r", (double) pixel.r / 255.0);
          parser.setVarValue("g", (double) pixel.g / 255.0);
          parser.setVarValue("b", (double) pixel.b / 255.0);
          pixel.r = Tools.roundColor((Double) parser.evaluate(redNode) * 255.0);
          pixel.g = Tools.roundColor((Double) parser.evaluate(greenNode) * 255.0);
          pixel.b = Tools.roundColor((Double) parser.evaluate(blueNode) * 255.0);
        }
        img.setRGB(j, i, pixel);
      }
    }
  }
View Full Code Here

Examples of org.jwildfire.base.mathparser.JEPWrapper

    int height = pImageHeight;
    double x[] = pMesh3D.getX();
    double y[] = pMesh3D.getY();
    double z[] = pMesh3D.getZ();

    JEPWrapper parser = new JEPWrapper();
    parser.addVariable("x", 0.0);
    parser.addVariable("y", 0.0);
    Node node = parser.parse(formula);

    // Don't calculate the actual bounding box because this may cause unexpected results if the object was deformed by another tansformer before
    double objXMin = -(double) width / 2.0;
    //      double objXMax = (double) width / 2.0;
    double objYMin = -(double) height / 2.0;
    //      double objYMax = (double) height / 2.0;
    double objXSize = (double) width;
    double objYSize = (double) height;

    double dx = this.xMax - this.xMin;
    double dy = this.yMax - this.yMin;

    if (!this.damp) {
      for (int i = 0; i < pCount; i++) {
        double xx = ((x[i] - objXMin) * dx) / objXSize + xMin;
        double yy = ((y[i] - objYMin) * dy) / objYSize + xMin;
        parser.setVarValue("x", xx);
        parser.setVarValue("y", yy);
        double amp = (Double) parser.evaluate(node);
        z[i] -= amp;
      }
    }
    else {
      for (int i = 0; i < pCount; i++) {
        double xx = ((x[i] - objXMin) * dx) / objXSize + xMin;
        double yy = ((y[i] - objYMin) * dy) / objYSize + xMin;
        parser.setVarValue("x", xx);
        parser.setVarValue("y", yy);
        double amp = (Double) parser.evaluate(node);

        double dxx = ((x[i] - objXMin) * dx) / objXSize + xMin - originX;
        double dyy = ((y[i] - objYMin) * dy) / objYSize + xMin - originY;
        double drr = Math.sqrt(dxx * dxx + dyy * dyy);
        double dmp = drr * damping;
 
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.