Search in sources :

Example 1 with ImagePlaneGen

use of org.twak.tweed.gen.ImagePlaneGen 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

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 FileOutputStream (java.io.FileOutputStream)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 JComboBox (javax.swing.JComboBox)1 JLabel (javax.swing.JLabel)1