Search in sources :

Example 16 with LinearForm3D

use of org.twak.utils.geom.LinearForm3D in project chordatlas by twak.

the class Pano method castTo.

public int castTo(float[] pos, BufferedImage image, Point3d worldHit, Vector3d worldNormal) {
    com.jme3.math.Vector3f worldDir = new com.jme3.math.Vector3f(pos[0], pos[1], pos[2]);
    worldDir = worldDir.subtract(Jme3z.to(location));
    com.jme3.math.Vector3f dir = inverseGeomRot.mult(worldDir);
    double angle = ((Math.atan2(-dir.x, dir.z) + Math.PI) % (Math.PI * 2)) / (Math.PI * 2);
    double elevation = (Math.atan2(-dir.y, Math.sqrt(dir.x * dir.x + dir.z * dir.z)) + Math.PI / 2) / Math.PI;
    double[] rgb = new double[3];
    if (image != null) {
        double x = angle * image.getWidth(), y = elevation * image.getHeight(), xF = x - Math.floor(x), yF = y - Math.floor(y);
        get(image, Math.floor(x), Math.floor(y), (1 - xF) * (1 - yF), rgb);
        get(image, Math.ceil(x), Math.floor(y), xF * (1 - yF), rgb);
        get(image, Math.ceil(x), Math.ceil(y), xF * yF, rgb);
        get(image, Math.floor(x), Math.ceil(y), (1 - xF) * yF, rgb);
    }
    if (worldHit != null) {
        worldHit.x = Double.NaN;
        if (planeNameCache.get() != name) {
            planeNameCache.set(name);
            planeMaskCache.set(getPlanePano());
        }
        if (planeMaskCache.get() != null) {
            double x = Mathz.clamp((1 - angle) * planeMaskCache.get().getWidth(), 0, planeMaskCache.get().getWidth() - 1), y = elevation * planeMaskCache.get().getHeight();
            Color c = new Color(planeMaskCache.get().getRGB((int) x, (int) y));
            int planeNo = (c.getRed() + c.getGreen() + c.getBlue()) / 3;
            if (planeNo < planes.size() && planeNo != 0) {
                LinearForm3D plane = new LinearForm3D(planes.get(planeNo));
                {
                    double tmp = plane.B;
                    plane.B = plane.C;
                    plane.C = tmp;
                    plane.D = -plane.D;
                    plane.A = -plane.A;
                }
                Point3d pt = plane.collide(new Point3d(), Jme3z.from(dir));
                {
                    com.jme3.math.Vector3f ptm = Jme3z.to(pt);
                    worldHit.set(Jme3z.from(geomRot.mult(ptm)));
                    worldHit.add(location);
                    worldNormal.set(Jme3z.from(geomRot.mult(Jme3z.to(plane.normal()))));
                }
            }
        }
    }
    return Colour.asInt((int) rgb[0], (int) rgb[1], (int) rgb[2]);
}
Also used : Point3d(javax.vecmath.Point3d) Color(java.awt.Color) LinearForm3D(org.twak.utils.geom.LinearForm3D)

Example 17 with LinearForm3D

use of org.twak.utils.geom.LinearForm3D in project chordatlas by twak.

the class Pano method buildPlanes.

private void buildPlanes(File file) {
    if (!file.exists() || planes != null)
        return;
    planes = new ArrayList<>();
    try {
        for (String line : Files.readAllLines(file.toPath())) {
            double[] params = Arrays.stream(line.split("[,\\s]")).mapToDouble(Double::parseDouble).toArray();
            planes.add(new LinearForm3D(params[0], params[1], params[2], params[3]));
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : IOException(java.io.IOException) LinearForm3D(org.twak.utils.geom.LinearForm3D)

Aggregations

LinearForm3D (org.twak.utils.geom.LinearForm3D)17 Point3d (javax.vecmath.Point3d)14 Vector3d (javax.vecmath.Vector3d)10 Line3d (org.twak.utils.geom.Line3d)9 ArrayList (java.util.ArrayList)7 Point2d (javax.vecmath.Point2d)6 List (java.util.List)5 Map (java.util.Map)3 Vector2d (javax.vecmath.Vector2d)3 Loop (org.twak.utils.collections.Loop)3 MultiMap (org.twak.utils.collections.MultiMap)3 IOException (java.io.IOException)2 Collectors (java.util.stream.Collectors)2 Matrix4d (javax.vecmath.Matrix4d)2 Face (org.twak.camp.Output.Face)2 SharedEdge (org.twak.camp.Output.SharedEdge)2 MeshBuilder (org.twak.siteplan.jme.MeshBuilder)2 Line (org.twak.utils.Line)2 LinearForm (org.twak.utils.geom.LinearForm)2 CrossGen (org.twak.viewTrace.facades.Tube.CrossGen)2