use of org.twak.viewTrace.FacadeFinder.ToProject 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