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);
}
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();
}
Aggregations