Search in sources :

Example 1 with Point2d

use of javax.vecmath.Point2d in project chordatlas by twak.

the class MiniGen method inBounds.

private boolean inBounds(Matrix4d mini, List<double[]> bounds) {
    // mini matrix is in mini-mesh format: a translation from a 255^3 cube in the first quadrant
    // trans.offset is a transform from that space, into jme rendered space (cartesian in meters, around the origin)
    Matrix4d m = new Matrix4d();
    m.mul(Jme3z.fromMatrix(trans.offset), mini);
    for (Point2d p : Arrays.stream(cubeCorners).map(c -> {
        Point3d tmp = new Point3d();
        m.transform(c, tmp);
        return new Point2d(tmp.x, tmp.z);
    }).collect(Collectors.toList())) {
        for (double[] bound : bounds) {
            if (bound[0] < p.x && bound[1] > p.x && bound[2] < p.y && bound[3] > p.y)
                return true;
        }
    }
    return false;
}
Also used : Matrix4d(javax.vecmath.Matrix4d) XStream(com.thoughtworks.xstream.XStream) Arrays(java.util.Arrays) Matrix4d(javax.vecmath.Matrix4d) Face(org.twak.utils.geom.ObjDump.Face) Mode(com.jme3.scene.Mesh.Mode) Tuple3d(javax.vecmath.Tuple3d) MiniTransform(org.twak.readTrace.MiniTransform) Loop(org.twak.utils.collections.Loop) Node(com.jme3.scene.Node) AlignTool(org.twak.tweed.tools.AlignTool) Map(java.util.Map) Material(com.jme3.material.Material) ChangeListener(javax.swing.event.ChangeListener) Point3d(javax.vecmath.Point3d) ChangeEvent(javax.swing.event.ChangeEvent) ListDownLayout(org.twak.utils.ui.ListDownLayout) Collectors(java.util.stream.Collectors) FileNotFoundException(java.io.FileNotFoundException) List(java.util.List) JSlider(javax.swing.JSlider) JCheckBox(javax.swing.JCheckBox) Mesh(com.jme3.scene.Mesh) JPanel(javax.swing.JPanel) Geometry(com.jme3.scene.Geometry) ActionListener(java.awt.event.ActionListener) LinearForm3D(org.twak.utils.geom.LinearForm3D) HashMap(java.util.HashMap) Callable(java.util.concurrent.Callable) Pair(org.twak.utils.Pair) Vector3d(javax.vecmath.Vector3d) Filez(org.twak.utils.Filez) Tweed(org.twak.tweed.Tweed) ArrayList(java.util.ArrayList) Spatial(com.jme3.scene.Spatial) JComponent(javax.swing.JComponent) JButton(javax.swing.JButton) Files(java.nio.file.Files) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) BlendMode(com.jme3.material.RenderState.BlendMode) ActionEvent(java.awt.event.ActionEvent) File(java.io.File) Loopz(org.twak.utils.collections.Loopz) Point2d(javax.vecmath.Point2d) Jme3z(org.twak.siteplan.jme.Jme3z) EventMoveHandle(org.twak.tweed.EventMoveHandle) HandleMe(org.twak.tweed.handles.HandleMe) ObjDump(org.twak.utils.geom.ObjDump) ModelKey(com.jme3.asset.ModelKey) ColorRGBA(com.jme3.math.ColorRGBA) Collections(java.util.Collections) Transform(com.jme3.math.Transform) Point2d(javax.vecmath.Point2d) Point3d(javax.vecmath.Point3d)

Example 2 with Point2d

use of javax.vecmath.Point2d in project chordatlas by twak.

the class MiniGen method clip.

public void clip(Loop<Point3d> in, File objLocation) {
    ObjDump obj = new ObjDump();
    double[] bounds = Loopz.minMaxXZ(in);
    List<LinearForm3D> halfPlanes = new ArrayList();
    File writeFolder = objLocation.getParentFile();
    for (Pair<Point3d, Point3d> p : in.pairs()) {
        Vector3d norm = new Vector3d(p.second());
        norm.sub(p.first());
        norm = new Vector3d(-norm.z, 0, norm.x);
        norm.normalize();
        halfPlanes.add(new LinearForm3D(norm, p.first()));
    }
    Map<File, File> copied = new HashMap<>();
    int nameCount = 0;
    double minY = Double.MAX_VALUE, maxY = -Double.MAX_VALUE;
    for (Map.Entry<Integer, Matrix4d> e : trans.index.entrySet()) {
        if (!inBounds(e.getValue(), Collections.singletonList(bounds)))
            continue;
        else {
            Matrix4d m = new Matrix4d();
            m.mul(Jme3z.fromMatrix(trans.offset), e.getValue());
            File readFolder = new File(Tweed.toWorkspace(root), e.getKey() + "");
            ObjDump or = new ObjDump(new File(readFolder, "model.obj"));
            or.computeMissingNormals();
            for (ObjDump.Material mat : or.material2Face.keySet()) {
                f: for (Face f : or.material2Face.get(mat)) {
                    for (int j = 0; j < f.vtIndexes.size(); j++) {
                        Point3d pt = new Point3d(or.orderVert.get(f.vtIndexes.get(j)));
                        m.transform(pt);
                        if (pt.x > bounds[0] && pt.x < bounds[1] && pt.z > bounds[2] && pt.z < bounds[3])
                            if (inside(pt, halfPlanes)) {
                                if (IMPORT_TEXTURES && !((obj.currentMaterial != null && obj.currentMaterial.equals(mat)) || (obj.currentMaterial == null && mat == null))) {
                                    File source = new File(readFolder, mat.filename);
                                    ObjDump.Material newMat;
                                    if (copied.containsKey(source)) {
                                        newMat = new ObjDump.Material(mat);
                                        newMat.filename = copied.get(source).getName();
                                    } else {
                                        newMat = makeUnique(mat, writeFolder);
                                        File destFile = new File(writeFolder, newMat.filename);
                                        copied.put(source, destFile);
                                        try {
                                            Files.copy(source.toPath(), new FileOutputStream(destFile));
                                        } catch (IOException e1) {
                                            e1.printStackTrace();
                                        }
                                    }
                                    newMat.diffuse = new double[] { 0, 0, 0 };
                                    newMat.ambient = new double[] { 1, 1, 1 };
                                    newMat.specular = new double[] { 0, 0, 0 };
                                    newMat.name = "mat_" + (nameCount++);
                                    obj.setCurrentMaterial(newMat);
                                }
                                List<Point3d> fVerts = new ArrayList<>(3), fNorms = new ArrayList<>(3);
                                List<Point2d> fUVs = new ArrayList<>(2);
                                for (int i = 0; i < f.vtIndexes.size(); i++) {
                                    Point3d vts = new Point3d(or.orderVert.get(f.vtIndexes.get(i)));
                                    Point3d ns = new Point3d(or.orderNorm.get(f.normIndexes.get(i)));
                                    ns.add(vts);
                                    m.transform(vts);
                                    m.transform(ns);
                                    ns.sub(vts);
                                    minY = Math.min(vts.y, minY);
                                    maxY = Math.max(vts.y, maxY);
                                    fVerts.add(vts);
                                    fNorms.add(ns);
                                    fUVs.add(new Point2d(or.orderUV.get(f.uvIndexes.get(i))));
                                }
                                obj.addFace(fVerts, fNorms, fUVs);
                                continue f;
                            }
                    }
                }
            }
        }
    }
    for (Tuple3d t : obj.orderVert) t.y -= (maxY - minY) * 0.03 + minY;
    obj.dump(objLocation);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ObjDump(org.twak.utils.geom.ObjDump) Point3d(javax.vecmath.Point3d) Face(org.twak.utils.geom.ObjDump.Face) IOException(java.io.IOException) LinearForm3D(org.twak.utils.geom.LinearForm3D) Matrix4d(javax.vecmath.Matrix4d) Vector3d(javax.vecmath.Vector3d) Point2d(javax.vecmath.Point2d) Tuple3d(javax.vecmath.Tuple3d) FileOutputStream(java.io.FileOutputStream) File(java.io.File) Map(java.util.Map) HashMap(java.util.HashMap)

Example 3 with Point2d

use of javax.vecmath.Point2d in project chordatlas by twak.

the class FeatureCache method readFeatures.

public static ImageFeatures readFeatures(File fFolder, MegaFeatures megaFeatures) {
    Line mega = new Line(megaFeatures.megafacade);
    ImageFeatures out = new ImageFeatures();
    out.mega = megaFeatures;
    Line imageL = null;
    out.miniFacades = new ArrayList();
    {
        if (Tweed.DATA == null)
            out.ortho = new File(fFolder, RENDERED_IMAGE_PNG);
        else
            out.ortho = Paths.get(Tweed.DATA).relativize(new File(fFolder, RENDERED_IMAGE_PNG).toPath()).toFile();
        File rectFile = new File(fFolder, "rectified.png");
        if (rectFile.exists()) {
            if (Tweed.DATA == null)
                out.rectified = rectFile;
            else
                out.rectified = Paths.get(Tweed.DATA).relativize(rectFile.toPath()).toFile();
        } else
            out.rectified = out.ortho;
    }
    int imageWidth = out.getRectified().getWidth(), imageHeight = out.getRectified().getHeight();
    double rectifiedToOrtho = out.getRectified().getWidth() / (double) out.getOrtho().getWidth();
    {
        List<String> lines = null;
        try {
            lines = Files.readAllLines(new File(fFolder, "meta.txt").toPath());
        } catch (IOException e) {
            System.err.println("failed to read metafile");
        }
        if (lines == null) {
            System.out.println("warning, failed to read input files in " + fFolder);
            imageL = new Line(0, 0, out.getRectified().getWidth() / FacadeTool.pixelsPerMeter, 0);
        } else {
            String plane = lines.get(1);
            String[] pVals = plane.split(" ");
            Point2d a = new Point2d(Float.parseFloat(pVals[0]), Float.parseFloat(pVals[1]));
            Point2d b = new Point2d(Float.parseFloat(pVals[2]), Float.parseFloat(pVals[3]));
            imageL = new Line(a, b);
        }
    }
    out.start = mega.findPPram(imageL.start) * mega.length();
    out.end = mega.findPPram(imageL.end) * mega.length();
    try {
        File yFile = new File(fFolder, PARAMETERS_YML);
        if (yFile.exists()) {
            YamlReader fromVision = new YamlReader(new FileReader(yFile));
            Map m = (Map) fromVision.read();
            List yamlFac = (List) m.get("facades");
            double maxW = 0;
            if (yamlFac != null) {
                for (Object o : yamlFac) try {
                    MiniFacade mf = new MiniFacade(out, (Map) o, imageWidth / (rectifiedToOrtho * FacadeTool.pixelsPerMeter), imageHeight / FacadeTool.pixelsPerMeter, rectifiedToOrtho * FacadeTool.pixelsPerMeter, out.start);
                    if (!mf.invalid())
                        out.miniFacades.add(mf);
                    maxW = Math.max(maxW, (mf.left + mf.width - out.start));
                } catch (Throwable th) {
                    System.out.println("while reading " + yFile);
                    th.printStackTrace();
                }
            }
        } else
            System.out.println("no parameters in " + fFolder);
    } catch (Throwable e) {
        e.printStackTrace();
    }
    return out;
}
Also used : MiniFacade(org.twak.viewTrace.facades.MiniFacade) ArrayList(java.util.ArrayList) IOException(java.io.IOException) YamlReader(com.esotericsoftware.yamlbeans.YamlReader) ICanPaint(org.twak.utils.PaintThing.ICanPaint) Line(org.twak.utils.Line) Point2d(javax.vecmath.Point2d) ArrayList(java.util.ArrayList) List(java.util.List) FileReader(java.io.FileReader) File(java.io.File) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) MultiMap(org.twak.utils.collections.MultiMap)

Example 4 with Point2d

use of javax.vecmath.Point2d in project chordatlas by twak.

the class MiniFacade method paint.

@Override
public void paint(Graphics2D g, PanMouseAdaptor ma) {
    if (PAINT_IMAGE && imageFeatures != null) {
        Composite oldC = g.getComposite();
        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.4f));
        paintImage(g, ma, left, -height, left + width, 0);
        g.setComposite(oldC);
    }
    g.setStroke(new BasicStroke(2f));
    if (width < 5)
        return;
    for (Feature f : Feature.values()) if (f != Feature.GRID)
        for (FRect w : rects.get(f)) {
            if (w.outer == null) {
                g.setColor(f.color);
                // if (w.width < 10)
                g.drawRect(ma.toX(w.x), ma.toY(-w.y - w.height), ma.toZoom(w.width), ma.toZoom(w.height));
                g.setColor(Color.black);
                if (w.id >= 0)
                    g.drawString(w.id + "", ma.toX(w.x) + 3, ma.toY(-w.y - w.height) + 13);
            // try {
            // g.drawString(
            // w.attachedHeight.get( Feature.CORNICE ).d +", " +
            // w.attachedHeight.get( Feature.BALCONY ).d +", "+
            // w.attachedHeight.get( Feature.SILL ).d + ", ",
            // ma.toX( w.x ) + 3, ma.toY( -w.y - w.height ) + 13  );
            // } catch (NullPointerException e) {}
            }
            for (Dir dir : Dir.values()) {
                FRect n = w.getAdj(dir);
                if (n != null) {
                    g.setColor(Rainbow.getColour(dir.ordinal()));
                    Point2d s = getRectPoint(w, dir), e = getRectPoint(n, dir.opposite);
                    s.y = -s.y;
                    e.y = -e.y;
                    Line l = new Line(s, e);
                    PaintThing.paint(l, g, ma);
                    PaintThing.drawArrow(g, ma, l, 3);
                // if ( dir == Dir.L || dir == Dir.U ) {
                // Point2d label = l.fromPPram( 0.5 );
                // g.drawString( w.distanceToAdjacent( dir ) + "", ma.toX( label.x ), ma.toY( label.y ) );
                // }
                }
            }
        }
    if (false && grid != null) {
        g.setColor(new Color(100, 100, 255, 200));
        // for ( DRectangle w : grid.dows )
        // g.fillRect( ma.toX( w.x ), ma.toY( -w.y - w.height ), ma.toZoom( w.width ), ma.toZoom( w.height ) );
        g.setColor(new Color(100, 255, 10, 200));
        if (false)
            for (int x = 0; x < grid.cols; x++) for (int y = 0; y < grid.rows; y++) {
                g.fillRect(ma.toX(x * grid.hspacing + grid.x), ma.toY(-y * grid.vspacing - grid.wHeight - grid.y), ma.toZoom(grid.wWidth), ma.toZoom(grid.wHeight));
            }
    }
    g.setColor(Color.black);
    g.drawLine(ma.toX(left), ma.toY(0), ma.toX(left + width), ma.toY(0));
    g.setColor(Color.green);
    g.setColor(new Color(0, 170, 255));
    g.setStroke(new BasicStroke(softLeft ? 1 : 3));
    g.drawLine(ma.toX(left), ma.toY(0), ma.toX(left), ma.toY(-height));
    g.setStroke(new BasicStroke(softRight ? 1 : 3));
    g.drawLine(ma.toX(left + width), ma.toY(0), ma.toX(left + width), ma.toY(-height));
    g.setColor(Color.black);
    g.setStroke(new BasicStroke(1));
    g.drawLine(ma.toX(left), ma.toY(-height), ma.toX(left + width), ma.toY(-height));
    g.drawLine(ma.toX(left), ma.toY(-groundFloorHeight), ma.toX(left + width), ma.toY(-groundFloorHeight));
}
Also used : BasicStroke(java.awt.BasicStroke) Line(org.twak.utils.Line) AlphaComposite(java.awt.AlphaComposite) Composite(java.awt.Composite) Point2d(javax.vecmath.Point2d) Color(java.awt.Color) ICanPaint(org.twak.utils.PaintThing.ICanPaint)

Example 5 with Point2d

use of javax.vecmath.Point2d in project chordatlas by twak.

the class MiniFacade method mouseDown.

@Override
public void mouseDown(MouseEvent e, PanMouseAdaptor ma) {
    Point2d pt = flip(ma.from(e));
    double bestDist = ma.fromZoom(10);
    dragging = null;
    mouseLastDown = e.getButton();
    for (FRect f : getRects()) {
        double dist = f.getDistance(pt);
        if (dist < bestDist) {
            bestDist = dist;
            dragging = f;
        }
    }
    if (dragging != null && e.getButton() == 3)
        dragging.mouseDown(e, ma);
}
Also used : Point2d(javax.vecmath.Point2d)

Aggregations

Point2d (javax.vecmath.Point2d)84 Line (org.twak.utils.Line)37 ArrayList (java.util.ArrayList)29 Point3d (javax.vecmath.Point3d)27 List (java.util.List)18 Vector2d (javax.vecmath.Vector2d)17 SuperLine (org.twak.viewTrace.SuperLine)17 File (java.io.File)15 Vector3d (javax.vecmath.Vector3d)15 Map (java.util.Map)14 HalfEdge (org.twak.utils.geom.HalfMesh2.HalfEdge)14 HashMap (java.util.HashMap)13 Loop (org.twak.utils.collections.Loop)13 Collectors (java.util.stream.Collectors)12 IOException (java.io.IOException)11 HashSet (java.util.HashSet)11 Set (java.util.Set)11 Tweed (org.twak.tweed.Tweed)11 Matrix4d (javax.vecmath.Matrix4d)10 LinearForm (org.twak.utils.geom.LinearForm)10