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);