Search in sources :

Example 6 with VectorD

use of org.jwildfire.base.mathlib.VecMathLib.VectorD in project JWildfire by thargor6.

the class DLA3DWFFuncIterator method iterate.

public List<DLA3DWFFuncPoint> iterate() {
    List<DLA3DWFFuncPoint> res = new ArrayList<>();
    DLA3DWFFuncPoint initialPoint = new DLA3DWFFuncPoint();
    res.add(initialPoint);
    innerRadius = 3.0;
    outerRadius = 3.0 * innerRadius;
    while (res.size() < max_iter) {
        double phi = randGen.random() * (M_PI + M_PI);
        sinAndCos(phi, sinPhi, cosPhi);
        double theta = randGen.random() * (M_PI + M_PI);
        sinAndCos(theta, sinTheta, cosTheta);
        double ci = innerRadius * sinTheta.value * cosPhi.value;
        double cj = innerRadius * sinTheta.value * sinPhi.value;
        double ck = innerRadius * cosTheta.value;
        if (thread_count > 1) {
            List<WalkerThread> threads = new ArrayList<>();
            for (int i = 0; i < 2 * thread_count; i++) {
                WalkerThread thread = new WalkerThread(ci, cj, ck, res);
                threads.add(thread);
                new Thread(thread).start();
            }
            boolean isDone = false;
            while (!isDone) {
                isDone = true;
                for (WalkerThread thread : threads) {
                    if (!thread.isDone()) {
                        isDone = false;
                        try {
                            Thread.sleep(1);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                        break;
                    }
                }
            }
            for (WalkerThread thread : threads) {
                DLA3DWFFuncPoint nextPoint = thread.getRes();
                if (nextPoint != null) {
                    res.add(nextPoint);
                    if (res.size() > 1000 && res.size() % 100 == 0) {
                        System.out.println("PNTS " + res.size());
                    }
                }
            }
        } else {
            DLA3DWFFuncPoint nextPoint = nextWalk(ci, cj, ck, res);
            if (nextPoint != null) {
                res.add(nextPoint);
                if (res.size() > 1000 && res.size() % 100 == 0) {
                    System.out.println("PNTS " + res.size());
                }
            }
        }
    }
    for (DLA3DWFFuncPoint p : res) {
        p.relDepth = (double) p.pathLength / (double) calcMaxPathLength(res, p);
        if (p.parent != null) {
            VectorD d = new VectorD(p.x - p.parent.x, p.y - p.parent.y, p.z - p.parent.z);
            d.normalize();
            p.elevation = MathLib.atan2(d.y, d.x) + MathLib.M_PI_2;
            p.azimuth = -MathLib.atan2(d.z, MathLib.sqrt(d.x * d.x + d.y * d.y));
            double sina = MathLib.sin(p.elevation);
            double cosa = MathLib.cos(p.elevation);
            double sinb = MathLib.sin(p.azimuth);
            double cosb = MathLib.cos(p.azimuth);
            Matrix3D a = new Matrix3D();
            a.m[0][0] = cosb;
            a.m[0][1] = 0;
            a.m[0][2] = sinb;
            a.m[1][0] = sina * sinb;
            a.m[1][1] = cosa;
            a.m[1][2] = -sina * cosb;
            a.m[2][0] = -cosa * sinb;
            a.m[2][1] = sina;
            a.m[2][2] = cosa * cosb;
            p.rotation = a;
        }
    }
    return res;
}
Also used : Matrix3D(org.jwildfire.base.mathlib.VecMathLib.Matrix3D) ArrayList(java.util.ArrayList) VectorD(org.jwildfire.base.mathlib.VecMathLib.VectorD)

Example 7 with VectorD

use of org.jwildfire.base.mathlib.VecMathLib.VectorD in project JWildfire by thargor6.

the class AbstractOBJMeshWFFunc method transform.

@Override
public void transform(FlameTransformationContext pContext, XForm pXForm, XYZPoint pAffineTP, XYZPoint pVarTP, double pAmount) {
    if (mesh == null || mesh.getFaceCount() == 0) {
        return;
    }
    Face f = mesh.getFace(pContext.random(mesh.getFaceCount()));
    Vertex rawP1 = mesh.getVertex(f.v1);
    Vertex rawP2 = mesh.getVertex(f.v2);
    Vertex rawP3 = mesh.getVertex(f.v3);
    if ((colorMapHolder.isActive() || displacementMapHolder.isActive()) && rawP1 instanceof VertexWithUV) {
        VertexWithUV p1 = transform((VertexWithUV) rawP1);
        VertexWithUV p2 = transform((VertexWithUV) rawP2);
        VertexWithUV p3 = transform((VertexWithUV) rawP3);
        // uniform sampling:  http://math.stackexchange.com/questions/18686/uniform-random-point-in-triangle
        double sqrt_r1 = MathLib.sqrt(pContext.random());
        double r2 = pContext.random();
        double a = 1.0 - sqrt_r1;
        double b = sqrt_r1 * (1.0 - r2);
        double c = r2 * sqrt_r1;
        double dx = a * p1.x + b * p2.x + c * p3.x;
        double dy = a * p1.y + b * p2.y + c * p3.y;
        double dz = a * p1.z + b * p2.z + c * p3.z;
        pVarTP.x += pAmount * dx;
        pVarTP.y += pAmount * dy;
        pVarTP.z += pAmount * dz;
        double u = a * p1.u + b * p2.u + c * p3.u;
        double v = a * p1.v + b * p2.v + c * p3.v;
        if (colorMapHolder.isActive()) {
            double iu = GfxMathLib.clamp(u * (colorMapHolder.getColorMapWidth() - 1.0), 0.0, colorMapHolder.getColorMapWidth() - 1.0);
            double iv = GfxMathLib.clamp(colorMapHolder.getColorMapHeight() - 1.0 - v * (colorMapHolder.getColorMapHeight() - 1.0), 0, colorMapHolder.getColorMapHeight() - 1.0);
            int ix = (int) MathLib.trunc(iu);
            int iy = (int) MathLib.trunc(iv);
            colorMapHolder.applyImageColor(pVarTP, ix, iy, iu, iv);
            pVarTP.color = uvColorMapper.getUVColorIdx(Tools.FTOI(pVarTP.redColor), Tools.FTOI(pVarTP.greenColor), Tools.FTOI(pVarTP.blueColor));
        }
        if (displacementMapHolder.isActive()) {
            VectorD av = new VectorD(p2.x - p1.x, p2.y - p1.y, p2.y - p1.y);
            VectorD bv = new VectorD(p3.x - p1.x, p3.y - p1.y, p3.y - p1.y);
            VectorD n = VectorD.cross(av, bv);
            n.normalize();
            double iu = GfxMathLib.clamp(u * (displacementMapHolder.getDisplacementMapWidth() - 1.0), 0.0, displacementMapHolder.getDisplacementMapWidth() - 1.0);
            double iv = GfxMathLib.clamp(displacementMapHolder.getDisplacementMapHeight() - 1.0 - v * (displacementMapHolder.getDisplacementMapHeight() - 1.0), 0, displacementMapHolder.getDisplacementMapHeight() - 1.0);
            int ix = (int) MathLib.trunc(iu);
            int iy = (int) MathLib.trunc(iv);
            double d = displacementMapHolder.calculateImageDisplacement(ix, iy, iu, iv) * _displ_amount;
            pVarTP.x += pAmount * n.x * d;
            pVarTP.y += pAmount * n.y * d;
            pVarTP.z += pAmount * n.z * d;
        }
    } else {
        Vertex p1 = transform(rawP1);
        Vertex p2 = transform(rawP2);
        Vertex p3 = transform(rawP3);
        // uniform sampling:  http://math.stackexchange.com/questions/18686/uniform-random-point-in-triangle
        double sqrt_r1 = MathLib.sqrt(pContext.random());
        double r2 = pContext.random();
        double a = 1.0 - sqrt_r1;
        double b = sqrt_r1 * (1.0 - r2);
        double c = r2 * sqrt_r1;
        double dx = a * p1.x + b * p2.x + c * p3.x;
        double dy = a * p1.y + b * p2.y + c * p3.y;
        double dz = a * p1.z + b * p2.z + c * p3.z;
        pVarTP.x += pAmount * dx;
        pVarTP.y += pAmount * dy;
        pVarTP.z += pAmount * dz;
    }
    if (receive_only_shadows == 1) {
        pVarTP.receiveOnlyShadows = true;
    }
}
Also used : VectorD(org.jwildfire.base.mathlib.VecMathLib.VectorD) XYZPoint(org.jwildfire.create.tina.base.XYZPoint)

Example 8 with VectorD

use of org.jwildfire.base.mathlib.VecMathLib.VectorD in project JWildfire by thargor6.

the class SimpleMesh method distributeFaces.

public void distributeFaces() {
    System.out.println("VERTICES: " + vertices.size());
    List<Double> areaLst = new ArrayList<>();
    double areaMin = Double.MAX_VALUE, areaMax = 0.0;
    for (Face face : faces) {
        Vertex p1 = getVertex(face.v1);
        Vertex p2 = getVertex(face.v2);
        Vertex p3 = getVertex(face.v3);
        VectorD a = new VectorD(p2.x - p1.x, p2.y - p1.y, p2.z - p1.z);
        VectorD b = new VectorD(p3.x - p1.x, p3.y - p1.y, p3.z - p1.z);
        double area = VectorD.cross(a, b).length();
        areaLst.add(area);
        if (area < areaMin) {
            areaMin = area;
        }
        if (area > areaMax) {
            areaMax = area;
        }
    }
    if (MathLib.fabs(areaMin - areaMax) > MathLib.EPSILON) {
        int maxFaces = faces.size() < 5000 ? 5000 : 500;
        List<Face> newFaces = new ArrayList<>();
        for (int i = 0; i < faces.size(); i++) {
            Face face = faces.get(i);
            int count = Math.min(Tools.FTOI(areaLst.get(i) / areaMin), maxFaces);
            for (int j = 0; j < count; j++) {
                newFaces.add(face);
            }
        }
        faces = newFaces;
    }
}
Also used : ArrayList(java.util.ArrayList) VectorD(org.jwildfire.base.mathlib.VecMathLib.VectorD)

Example 9 with VectorD

use of org.jwildfire.base.mathlib.VecMathLib.VectorD in project JWildfire by thargor6.

the class ParPlot2DWFFunc method transform.

@Override
public void transform(FlameTransformationContext pContext, XForm pXForm, XYZPoint pAffineTP, XYZPoint pVarTP, double pAmount) {
    if (evaluator == null) {
        return;
    }
    double randU, randV;
    if (solid == 0) {
        randU = pAffineTP.x;
        randV = pAffineTP.y;
    } else {
        randU = pContext.random();
        randV = pContext.random();
    }
    double u = _umin + randU * _du;
    double v = _vmin + randV * _dv;
    double x = evaluator.evaluateX(u, v);
    double y = evaluator.evaluateY(u, v);
    double z = evaluator.evaluateZ(u, v);
    if (displacementMapHolder.isActive()) {
        double epsu = _du / 100.0;
        double u1 = u + epsu;
        double x1 = evaluator.evaluateX(u1, v);
        double y1 = evaluator.evaluateY(u1, v);
        double z1 = evaluator.evaluateZ(u1, v);
        double epsv = _dv / 100.0;
        double v1 = v + epsv;
        double x2 = evaluator.evaluateX(u, v1);
        double y2 = evaluator.evaluateY(u, v1);
        double z2 = evaluator.evaluateZ(u, v1);
        VectorD av = new VectorD(x1 - x, y1 - y, z1 - z);
        VectorD bv = new VectorD(x2 - x, y2 - y, z2 - z);
        VectorD n = VectorD.cross(av, bv);
        n.normalize();
        double iu = GfxMathLib.clamp(randU * (displacementMapHolder.getDisplacementMapWidth() - 1.0), 0.0, displacementMapHolder.getDisplacementMapWidth() - 1.0);
        double iv = GfxMathLib.clamp(displacementMapHolder.getDisplacementMapHeight() - 1.0 - randV * (displacementMapHolder.getDisplacementMapHeight() - 1.0), 0, displacementMapHolder.getDisplacementMapHeight() - 1.0);
        int ix = (int) trunc(iu);
        int iy = (int) trunc(iv);
        double d = displacementMapHolder.calculateImageDisplacement(ix, iy, iu, iv) * _displ_amount;
        pVarTP.x += pAmount * n.x * d;
        pVarTP.y += pAmount * n.y * d;
        pVarTP.z += pAmount * n.z * d;
    }
    if (direct_color > 0) {
        switch(color_mode) {
            case CM_V:
                pVarTP.color = (v - _vmin) / _dv;
                break;
            case CM_U:
                pVarTP.color = (u - _umin) / _du;
                break;
            case CM_COLORMAP:
                if (colorMapHolder.isActive()) {
                    double iu = GfxMathLib.clamp(randU * (colorMapHolder.getColorMapWidth() - 1.0), 0.0, colorMapHolder.getColorMapWidth() - 1.0);
                    double iv = GfxMathLib.clamp(colorMapHolder.getColorMapHeight() - 1.0 - randV * (colorMapHolder.getColorMapHeight() - 1.0), 0, colorMapHolder.getColorMapHeight() - 1.0);
                    int ix = (int) MathLib.trunc(iu);
                    int iy = (int) MathLib.trunc(iv);
                    colorMapHolder.applyImageColor(pVarTP, ix, iy, iu, iv);
                    pVarTP.color = getUVColorIdx(Tools.FTOI(pVarTP.redColor), Tools.FTOI(pVarTP.greenColor), Tools.FTOI(pVarTP.blueColor));
                }
                break;
            default:
            case CM_UV:
                pVarTP.color = (v - _vmin) / _dv * (u - _umin) / _du;
                break;
        }
        if (pVarTP.color < 0.0)
            pVarTP.color = 0.0;
        else if (pVarTP.color > 1.0)
            pVarTP.color = 1.0;
    }
    pVarTP.x += pAmount * x;
    pVarTP.y += pAmount * y;
    pVarTP.z += pAmount * z;
}
Also used : VectorD(org.jwildfire.base.mathlib.VecMathLib.VectorD) XYZPoint(org.jwildfire.create.tina.base.XYZPoint)

Example 10 with VectorD

use of org.jwildfire.base.mathlib.VecMathLib.VectorD in project JWildfire by thargor6.

the class YPlot2DWFFunc method transform.

@Override
public void transform(FlameTransformationContext pContext, XForm pXForm, XYZPoint pAffineTP, XYZPoint pVarTP, double pAmount) {
    if (evaluator == null) {
        return;
    }
    double randU = pContext.random();
    double randV = pContext.random();
    double x = _xmin + randU * _dx;
    double z = _zmin + randV * _dz;
    double y = evaluator.evaluate(x);
    if (displacementMapHolder.isActive()) {
        double eps = _dx / 100.0;
        double x1 = x + eps;
        double y1 = evaluator.evaluate(x1);
        VectorD av = new VectorD(eps, y1 - y, 0);
        VectorD bv = new VectorD(0.0, 0.0, 1.0);
        VectorD n = VectorD.cross(av, bv);
        n.normalize();
        double iu = GfxMathLib.clamp(randU * (displacementMapHolder.getDisplacementMapWidth() - 1.0), 0.0, displacementMapHolder.getDisplacementMapWidth() - 1.0);
        double iv = GfxMathLib.clamp(displacementMapHolder.getDisplacementMapHeight() - 1.0 - randV * (displacementMapHolder.getDisplacementMapHeight() - 1.0), 0, displacementMapHolder.getDisplacementMapHeight() - 1.0);
        int ix = (int) MathLib.trunc(iu);
        int iy = (int) MathLib.trunc(iv);
        double d = displacementMapHolder.calculateImageDisplacement(ix, iy, iu, iv) * _displ_amount;
        pVarTP.x += pAmount * n.x * d;
        pVarTP.y += pAmount * n.y * d;
        pVarTP.z += pAmount * n.z * d;
    }
    if (direct_color > 0) {
        switch(color_mode) {
            case CM_COLORMAP:
                if (colorMapHolder.isActive()) {
                    double iu = GfxMathLib.clamp(randU * (colorMapHolder.getColorMapWidth() - 1.0), 0.0, colorMapHolder.getColorMapWidth() - 1.0);
                    double iv = GfxMathLib.clamp(colorMapHolder.getColorMapHeight() - 1.0 - randV * (colorMapHolder.getColorMapHeight() - 1.0), 0, colorMapHolder.getColorMapHeight() - 1.0);
                    int ix = (int) MathLib.trunc(iu);
                    int iy = (int) MathLib.trunc(iv);
                    colorMapHolder.applyImageColor(pVarTP, ix, iy, iu, iv);
                    pVarTP.color = getUVColorIdx(Tools.FTOI(pVarTP.redColor), Tools.FTOI(pVarTP.greenColor), Tools.FTOI(pVarTP.blueColor));
                }
                break;
            case CM_Y:
                pVarTP.color = (y - _ymin) / _dy;
                break;
            default:
            case CM_X:
                pVarTP.color = (x - _xmin) / _dx;
                break;
        }
        if (pVarTP.color < 0.0)
            pVarTP.color = 0.0;
        else if (pVarTP.color > 1.0)
            pVarTP.color = 1.0;
    }
    pVarTP.x += pAmount * x;
    pVarTP.y += pAmount * y;
    pVarTP.z += pAmount * z;
}
Also used : VectorD(org.jwildfire.base.mathlib.VecMathLib.VectorD) XYZPoint(org.jwildfire.create.tina.base.XYZPoint)

Aggregations

VectorD (org.jwildfire.base.mathlib.VecMathLib.VectorD)10 XYZPoint (org.jwildfire.create.tina.base.XYZPoint)4 ArrayList (java.util.ArrayList)2 Matrix3D (org.jwildfire.base.mathlib.VecMathLib.Matrix3D)1 RGBColorD (org.jwildfire.base.mathlib.VecMathLib.RGBColorD)1 UVPairD (org.jwildfire.base.mathlib.VecMathLib.UVPairD)1 RasterPoint (org.jwildfire.create.tina.base.raster.RasterPoint)1 DistantLight (org.jwildfire.create.tina.base.solidrender.DistantLight)1 MaterialSettings (org.jwildfire.create.tina.base.solidrender.MaterialSettings)1 Vertex (org.jwildfire.create.tina.variation.mesh.Vertex)1 VertexWithUV (org.jwildfire.create.tina.variation.mesh.VertexWithUV)1 SimpleImage (org.jwildfire.image.SimpleImage)1