Search in sources :

Example 1 with FacadeFinder

use of org.twak.viewTrace.FacadeFinder in project chordatlas by twak.

the class FacadeTool method facadeSelected.

public void facadeSelected(LoopL<Point3d> list, BlockGen block) {
    // if (block == null) {
    // JOptionPane.showMessageDialog( null, "generate mesh for block first" );
    // return;
    // }
    // Polygonz.findBounds( polies, min, max );
    double[] minMax = Loopz.minMax(list);
    Loopz.expand(minMax, 30);
    Map<Point2d, Pano> panos = new HashMap<>();
    for (Gen gen : tweed.frame.gens(PanoGen.class)) for (Pano pg : ((PanoGen) gen).getPanos()) {
        Point2d pt = new Point2d(pg.location.x, pg.location.z);
        if (pt.x > minMax[0] && pt.x < minMax[1] && pt.y > minMax[4] && pt.y < minMax[5])
            panos.put(pt, pg);
    }
    List<Point3d> objPoints = null;
    if (block != null) {
        objPoints = new ObjRead(block.getCroppedFile()).points();
    }
    FacadeFinder ff = new FacadeFinder(Loopz.toXZLoop(list), panos, objPoints, block, tweed.frame.getGenOf(PlanesGen.class));
    Point2d cen = Loopz.average(Loopz.to2dLoop(list, 1, null));
    renderFacades(block == null ? null : block.gNode, cen.x + "_" + cen.y, ff);
}
Also used : BlockGen(org.twak.tweed.gen.BlockGen) ImagePlaneGen(org.twak.tweed.gen.ImagePlaneGen) PlanesGen(org.twak.tweed.gen.PlanesGen) GISGen(org.twak.tweed.gen.GISGen) PanoGen(org.twak.tweed.gen.PanoGen) Gen(org.twak.tweed.gen.Gen) Point2d(javax.vecmath.Point2d) HashMap(java.util.HashMap) Point3d(javax.vecmath.Point3d) Pano(org.twak.tweed.gen.Pano) FacadeFinder(org.twak.viewTrace.FacadeFinder) ObjRead(org.twak.utils.geom.ObjRead) PlanesGen(org.twak.tweed.gen.PlanesGen)

Example 2 with FacadeFinder

use of org.twak.viewTrace.FacadeFinder in project chordatlas by twak.

the class FacadeTool method renderFacades.

private void renderFacades(Node gNode, String blockName, FacadeFinder ff) {
    Thread thread = new Thread() {

        @Override
        public void run() {
            File blockFile = new File(Tweed.DATA + File.separator + FeatureCache.FEATURE_FOLDER + File.separator + blockName);
            if (GISGen.mode == Mode.RENDER_SELECTED_BLOCK)
                try {
                    FileUtils.deleteDirectory(blockFile);
                } catch (IOException e1) {
                    e1.printStackTrace();
                }
            for (int mfi = 0; mfi < ff.results.size(); mfi++) {
                ToProjMega tpm = ff.results.get(mfi);
                if (tpm.size() == 0 || tpm.stream().mapToInt(x -> tpm.size()).sum() == 0)
                    continue;
                File megaFolder = new File(blockFile, "" + mfi);
                megaFolder.mkdirs();
                try {
                    new XStream().toXML(tpm.megafacade, new FileOutputStream(new File(megaFolder, LINE_XML)));
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                }
                // print a list of panoramas on this side.
                // List<Double> rots = new ArrayList();
                // 
                // for (ToProject tp : tpm)
                // for ( Pano pano : tp.toProject ) {
                // ImagePlaneGen pg = new ImagePlaneGen( tweed, (float) tp.e.x, (float) tp.e.y, (float) tp.s.x, (float) tp.s.y, (float) tp.minHeight, (float) tp.maxHeight, tp.toProject );
                // pg.fudgeToDepth( pixelsPerMeter, pano, rots );
                // }
                // 
                double rot = 0;
                // if (!rots.isEmpty())
                // rot = biggestClusterMean(rots);// rots.stream().mapToDouble( x -> x ).average().getAsDouble();
                // System.out.println ( "avg rot was "+rot );
                List<BufferedImage> images = new ArrayList<>();
                for (int fc = 0; fc < tpm.size(); fc++) {
                    // if (mfi != 2 || fc != 0)
                    // continue;
                    ToProject tp = tpm.get(fc);
                    // if (!tp.toProject.iterator().next().name.contains( "hfhGoIsR24hezjXpuIqklw" ))
                    // continue;
                    System.out.println("mega " + mfi + " pano " + fc);
                    File imageFolder;
                    String imageFilename = null;
                    // if ( GISGen.mode == Mode.RENDER_SELECTED_FACADE ) {
                    imageFolder = new File(megaFolder, "" + fc);
                    imageFilename = FeatureCache.RENDERED_IMAGE;
                    // }
                    // else
                    // imageFolder = new File( blockName );
                    imageFolder.mkdirs();
                    if (tp.toProject.size() != 1)
                        throw new Error();
                    ImagePlaneGen pg = new ImagePlaneGen(tweed, (float) tp.e.x, (float) tp.e.y, (float) tp.s.x, (float) tp.s.y, (float) tp.minHeight, (float) tp.maxHeight, tp.toProject);
                    if (GISGen.mode != Mode.RENDER_ALL_BLOCKS)
                        tweed.frame.addGen(pg, true);
                    for (Pano pano_ : tp.toProject) {
                        Pano pano = new Pano(pano_);
                        pano.set(pano.oa1 - (float) rot, pano.oa2, pano.oa3);
                        if (imageFilename == null)
                            imageFilename = new File(pano.name).getName() + "_" + tpm.megafacade.start + "_" + tpm.megafacade.end;
                        BufferedImage bi = pg.render(imageFolder, pixelsPerMeter, pano, tpm.megafacade, imageFilename);
                        if (GISGen.mode == Mode.RENDER_SELECTED_BLOCK)
                            images.add(bi);
                        try {
                            FileWriter out = new FileWriter(new File(imageFolder, "meta.txt"));
                            out.write(pixelsPerMeter * 10 + " " + (tp.s.distance(tp.e) * pixelsPerMeter - pixelsPerMeter * 20) + " " + (tp.maxHeight - tp.minHeight) * pixelsPerMeter + "\n");
                            out.write(pg.toString() + "\n");
                            out.write(pano.orig.getName() + "\n");
                            Point2d cen = tpm.megafacade.project(new Point2d(pano.location.x, pano.location.z), false);
                            out.write(tp.s.x + " " + tp.s.y + " " + tp.e.x + " " + tp.e.y + " " + cen.x + " " + cen.y + " " + pano.location.x + " " + pano.location.z + "\n");
                            out.close();
                        } catch (Throwable th) {
                            th.printStackTrace();
                        }
                    }
                }
                if (GISGen.mode == Mode.RENDER_SELECTED_BLOCK)
                    Imagez.writeSummary(new File(megaFolder, "summary.png"), images);
            }
        }
    };
    if (GISGen.mode == Mode.RENDER_SELECTED_BLOCK)
        thread.start();
    else
        thread.run();
}
Also used : XStream(com.thoughtworks.xstream.XStream) ToProjMega(org.twak.viewTrace.FacadeFinder.ToProjMega) ActionListener(java.awt.event.ActionListener) CentroidCluster(org.apache.commons.math3.ml.clustering.CentroidCluster) ClickMe(org.twak.tweed.ClickMe) FacadeMode(org.twak.viewTrace.FacadeFinder.FacadeMode) Vector2f(com.jme3.math.Vector2f) HashMap(java.util.HashMap) Clusterable(org.apache.commons.math3.ml.clustering.Clusterable) Tweed(org.twak.tweed.Tweed) Pano(org.twak.tweed.gen.Pano) ArrayList(java.util.ArrayList) Mode(org.twak.tweed.gen.GISGen.Mode) Node(com.jme3.scene.Node) ObjRead(org.twak.utils.geom.ObjRead) Spatial(com.jme3.scene.Spatial) Map(java.util.Map) JComboBox(javax.swing.JComboBox) KMeansPlusPlusClusterer(org.apache.commons.math3.ml.clustering.KMeansPlusPlusClusterer) Point3d(javax.vecmath.Point3d) Imagez(org.twak.tweed.dbg.Imagez) LoopL(org.twak.utils.collections.LoopL) BlockGen(org.twak.tweed.gen.BlockGen) BufferedImage(java.awt.image.BufferedImage) ListDownLayout(org.twak.utils.ui.ListDownLayout) FileWriter(java.io.FileWriter) ToProject(org.twak.viewTrace.FacadeFinder.ToProject) Vector3f(com.jme3.math.Vector3f) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) ActionEvent(java.awt.event.ActionEvent) Collectors(java.util.stream.Collectors) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) FacadeFinder(org.twak.viewTrace.FacadeFinder) Loopz(org.twak.utils.collections.Loopz) Point2d(javax.vecmath.Point2d) List(java.util.List) JLabel(javax.swing.JLabel) ImagePlaneGen(org.twak.tweed.gen.ImagePlaneGen) PlanesGen(org.twak.tweed.gen.PlanesGen) GISGen(org.twak.tweed.gen.GISGen) PanoGen(org.twak.tweed.gen.PanoGen) JPanel(javax.swing.JPanel) FeatureCache(org.twak.tweed.gen.FeatureCache) Gen(org.twak.tweed.gen.Gen) ToProject(org.twak.viewTrace.FacadeFinder.ToProject) XStream(com.thoughtworks.xstream.XStream) ToProjMega(org.twak.viewTrace.FacadeFinder.ToProjMega) FileWriter(java.io.FileWriter) FileNotFoundException(java.io.FileNotFoundException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) BufferedImage(java.awt.image.BufferedImage) Point2d(javax.vecmath.Point2d) FileOutputStream(java.io.FileOutputStream) Pano(org.twak.tweed.gen.Pano) ImagePlaneGen(org.twak.tweed.gen.ImagePlaneGen) File(java.io.File)

Aggregations

HashMap (java.util.HashMap)2 Point2d (javax.vecmath.Point2d)2 Point3d (javax.vecmath.Point3d)2 BlockGen (org.twak.tweed.gen.BlockGen)2 GISGen (org.twak.tweed.gen.GISGen)2 Gen (org.twak.tweed.gen.Gen)2 ImagePlaneGen (org.twak.tweed.gen.ImagePlaneGen)2 Pano (org.twak.tweed.gen.Pano)2 PanoGen (org.twak.tweed.gen.PanoGen)2 PlanesGen (org.twak.tweed.gen.PlanesGen)2 Vector2f (com.jme3.math.Vector2f)1 Vector3f (com.jme3.math.Vector3f)1 Node (com.jme3.scene.Node)1 Spatial (com.jme3.scene.Spatial)1 XStream (com.thoughtworks.xstream.XStream)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 BufferedImage (java.awt.image.BufferedImage)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1