use of javax.vecmath.Point2d in project bb4-common by bb4.
the class MathUtilTest method testFindAngle.
@Test
public void testFindAngle() {
Point2d point = new Point2d(1.0, 1.0);
for (double x = 0; x < 2.0 * Math.PI; x += 0.3) {
Point2d toPoint = new Point2d(point.x + Math.cos(x), point.y + Math.sin(x));
System.out.println("angle to " + toPoint + " is " + MathUtil.getDirectionTo(point, toPoint));
}
assertEquals("Unexpected angle.", Math.PI / 4.0, MathUtil.getDirectionTo(point, new Point2d(2.0, 2.0)), 0);
assertEquals("Unexpected angle.", 3.0 * Math.PI / 4.0, MathUtil.getDirectionTo(point, new Point2d(0.0, 2.0)), 0);
assertEquals("Unexpected angle.", 5.0 * Math.PI / 4.0 - 2.0 * Math.PI, MathUtil.getDirectionTo(point, new Point2d(0.0, 0.0)), 0);
assertEquals("Unexpected angle.", -Math.PI / 4.0, MathUtil.getDirectionTo(point, new Point2d(2.0, 0.0)), 0);
}
use of javax.vecmath.Point2d in project chordatlas by twak.
the class SolverState method debugSolverResult.
public void debugSolverResult() {
new Plot(mesh).add(miniPainter()).add(new ICanPaint() {
@Override
public void paint(Graphics2D g, PanMouseAdaptor ma) {
Set<HalfEdge> seen = new HashSet<>();
Color tWhite = new Color(255, 255, 255, 150);
if (!seen.isEmpty())
for (HalfFace f : mesh) {
for (HalfEdge e : f) {
int i = ((SuperEdge) e).profI;
// if (i == -1)
// continue;
Point2d loc = e.line().fromPPram(0.5);
String s = "" + i;
int offset = e.start.x < e.end.x ? -10 : 10;
seen.add(e);
Rectangle2D b = g.getFontMetrics().getStringBounds(s, g);
b = new Rectangle2D.Double(0, 0, b.getWidth() + 4, b.getHeight());
g.setColor(tWhite);
g.fillRect(ma.toX(loc.x) - (int) (b.getWidth() / 2), offset + ma.toY(loc.y) - (int) (b.getHeight() / 2), (int) (b.getWidth()), (int) (b.getHeight()));
g.setColor(Color.gray);
g.drawString(s, ma.toX(loc.x) - (int) (b.getWidth() / 2) + 2, offset + ma.toY(loc.y) + (int) (b.getHeight() / 2) - 3);
}
}
}
});
}
use of javax.vecmath.Point2d in project chordatlas by twak.
the class VizSkelGen method toHalf.
private SuperFace toHalf(Loop<Point3d> loop) {
Cache<Point3d, Point2d> look = new Cach<>(x -> Pointz.to2(x));
HalfEdge last = null, first = null;
SuperFace out = new SuperFace();
for (Loopable<Point3d> edge : loop.loopableIterator()) {
SuperEdge e = new SuperEdge(look.get(edge.get()), look.get(edge.getNext().get()), null);
if (first == null)
first = e;
if (last != null)
last.next = e;
e.face = out;
// !
e.prof = null;
e.mini = Collections.EMPTY_LIST;
if (mode == Mode.Profiles)
for (Line l : footprint) {
if (l.absAngle(e.line()) < 0.1 && l.distance(e.start, true) < 1.5 && l.distance(e.end, true) < 1.5) {
SuperLine sl = (SuperLine) l;
MegaFacade mf = sl.getMega();
e.prof = findProf(e.start, e.end, sl, mf);
}
}
last = e;
}
last.next = first;
out.e = first;
SkelFootprint.meanModeHeightColor(Loopz.toXZLoop(loop), out, blockGen);
if (mode == Mode.CE) {
for (HalfEdge ee : out) {
SuperEdge e = (SuperEdge) ee;
Matrix4d m = new Matrix4d();
m.setIdentity();
e.prof = new Prof(m, new Vector3d());
e.prof.add(new Point2d(0, 0));
e.prof.add(new Point2d(0, out.height));
e.prof.add(new Point2d(-1, out.height + 1));
}
}
return out;
}
use of javax.vecmath.Point2d 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();
}
use of javax.vecmath.Point2d in project chordatlas by twak.
the class Slice method buildUI.
private void buildUI() {
ma = new PanMouseAdaptor(this);
ma.center(new Point2d((max[flatAxis[0]] - min[flatAxis[0]]) / 2 + min[flatAxis[0]], (max[flatAxis[1]] - min[flatAxis[1]]) / 2 + min[flatAxis[1]]));
ma.setZoom(16);
JFrame jf = new JFrame("slice");
WindowManager.register(jf);
jf.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
// System.exit(0);
}
});
jf.setLayout(new BorderLayout());
this.setPreferredSize(new Dimension(600, 600));
jf.add(this, BorderLayout.CENTER);
final JSlider heightSlider = new JSlider(SwingConstants.VERTICAL, (int) (min[majorAxis] * sliderScale), (int) (max[majorAxis] * sliderScale), (int) ((max[majorAxis] - min[majorAxis]) * 0.5 + min[majorAxis]) * sliderScale);
final JSlider lineSlider = new JSlider(SwingConstants.VERTICAL, -1, 50, -1);
heightSlider.setPaintLabels(false);
final ChangeListener cl;
heightSlider.addChangeListener(cl = new ChangeListener() {
@Override
public void stateChanged(ChangeEvent arg0) {
sliceHeight = heightSlider.getValue() / (double) sliderScale;
LineSoup rawSoup = sliceMesh(rawMesh, sliceHeight);
slice = sliceMesh(filteredMesh, sliceHeight);
foundLines = new FindLines(slice, gisBias, lineSlider.getValue(), rawSoup.clique(P.CL_HIGH, P.CL_LOW), P);
Concarnie cc = new Concarnie(foundLines.result, foundLines.cliques, P);
// Concarnie cc = new Concarnie(slice, rawSoup.clique() );
carnieSoup = cc.graph;
carnie = cc.out;
Slice.this.repaint();
}
});
cl.stateChanged(null);
lineSlider.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
cl.stateChanged(null);
}
});
final JSlider parameterScaleSlider = new JSlider(SwingConstants.VERTICAL, 0, 2000, (int) (P.getScale() * 100));
parameterScaleSlider.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
P.setScale(parameterScaleSlider.getValue() / 100.);
}
});
JButton go = new JButton("support");
go.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
setupObj(new ObjRead(toSlice));
// supportPoints.clear();
// Slice.this.repaint();
// SwingUtilities.invokeLater(new Runnable() {
// @Override
// public void run() {
// PerpSupport ps = new PerpSupport(slice, gis);
// Slice.this.supportMax = ps.supportMax;
// Slice.this.supportPoints = ps.supportPoints;
// Slice.this.repaint();
// }
// });
}
});
JButton fs = new JButton("full support");
fs.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
Set<Point2d> points = new HashSet();
for (double v = min[majorAxis]; v < max[majorAxis]; v += 0.01) {
System.out.println("processing slice " + v + " / " + max[majorAxis]);
slice = sliceMesh(filteredMesh, sliceHeight);
for (SupportPoint sp : new PerpSupport(slice, gis).supportPoints) points.add(new Point2d(sp.support, max[majorAxis] - v));
}
System.out.println("found " + points.size() + " pts");
new Plot(points);
}
});
JButton ge = new JButton("lines");
ge.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
foundLines = new FindLines(slice, gisBias, lineSlider.getValue(), slice.clique(P.CL_HIGH, P.CL_LOW), P);
Slice.this.repaint();
}
});
JButton cc = new JButton("carnie");
cc.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
LineSoup rawSoup = sliceMesh(rawMesh, sliceHeight);
foundLines = new FindLines(slice, gisBias, lineSlider.getValue(), rawSoup.clique(P.CL_HIGH, P.CL_LOW), P);
Concarnie cc = new Concarnie(foundLines.result, foundLines.cliques, P);
carnieSoup = cc.graph;
carnie = cc.out;
Slice.this.repaint();
}
});
JButton ob = new JButton("dump");
ob.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
ObjDump out = new ObjDump();
double delta = 2.5;
for (double d = min[majorAxis]; d <= max[majorAxis]; d += delta) {
System.out.println(d + " / " + max[majorAxis]);
boolean error;
int count = 0;
do {
error = false;
try {
LineSoup rawSoup = sliceMesh(rawMesh, d);
slice = sliceMesh(filteredMesh, d);
foundLines = new FindLines(slice, null, lineSlider.getValue(), rawSoup.clique(P.CL_HIGH, P.CL_LOW), P);
// foundLines = new FindLines(slice, gisBias, lineSlider.getValue(), rawSoup.clique(P.CL_HIGH, P.CL_LOW), P);
Concarnie c = new Concarnie(foundLines.result, foundLines.cliques, P);
//
extrude(out, c.out, d, d + delta);
// capAtHeight (out, c.out, false, d );
capAtHeight(out, c.out, true, d + delta);
} catch (Throwable th) {
error = true;
}
} while (error && count++ < 10);
}
out.dump(new File(Tweed.SCRATCH + "test2.obj"));
}
});
JButton an = new JButton("anim");
an.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
BufferedImage bi = new BufferedImage(Slice.this.getWidth(), Slice.this.getHeight(), BufferedImage.TYPE_3BYTE_BGR);
for (File f : new File(Tweed.SCRATCH + "vid").listFiles()) f.delete();
int c = 0;
for (int i = heightSlider.getMinimum(); i < heightSlider.getMaximum(); i += 100) {
heightSlider.setValue(i);
Slice.this.paintComponent(bi.getGraphics());
try {
ImageIO.write(bi, "png", new File(String.format(Tweed.SCRATCH + "vid/%05d.png", c++)));
} catch (IOException e) {
e.printStackTrace();
}
}
}
});
JButton sl = new JButton("global");
sl.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
new SliceSolver(new File(Tweed.SCRATCH + "test2.obj"), Slice.this, P);
}
});
JButton pr = new JButton("profiles");
pr.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
double delta = 0.5;
BufferedImage out = new BufferedImage(Slice.this.getWidth(), Slice.this.getHeight(), BufferedImage.TYPE_4BYTE_ABGR);
Graphics2D g2 = (Graphics2D) out.getGraphics();
g2.setColor(Color.white);
g2.fillRect(0, 0, getWidth(), getHeight());
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.setColor(new Color(0, 0, 0, 50));
for (double d = min[majorAxis]; d <= max[majorAxis]; d += delta) {
System.out.println(d + " / " + max[majorAxis]);
boolean error;
int count = 0;
do {
error = false;
try {
LineSoup rawSoup = sliceMesh(rawMesh, d);
slice = sliceMesh(filteredMesh, d);
FindLines fl = new FindLines(slice, gisBias, lineSlider.getValue(), rawSoup.clique(P.CL_HIGH, P.CL_LOW), P);
PaintThing.paint(fl.result, g2, ma);
// Concarnie c = new Concarnie(foundLines.result, foundLines.cliques, P);
} catch (Throwable th) {
error = true;
}
} while (error && count++ < 10);
}
g2.dispose();
try {
ImageIO.write(out, "png", new File(Tweed.SCRATCH + "lines"));
} catch (IOException e) {
e.printStackTrace();
}
}
});
final JCheckBox sg = new JCheckBox("gis", true);
sg.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
showGis = sg.isSelected();
Slice.this.repaint();
}
});
final JCheckBox sf = new JCheckBox("fit", true);
sf.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
showFit = sf.isSelected();
Slice.this.repaint();
}
});
final JCheckBox sc = new JCheckBox("poly-out", true);
sc.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
showCarnie = sc.isSelected();
Slice.this.repaint();
}
});
final JCheckBox ss = new JCheckBox("slice", true);
ss.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
showSlice = ss.isSelected();
Slice.this.repaint();
}
});
JPanel buttons = new JPanel(new ListDownLayout());
buttons.add(go);
buttons.add(fs);
buttons.add(ge);
buttons.add(cc);
buttons.add(an);
buttons.add(ob);
buttons.add(sl);
buttons.add(pr);
buttons.add(sg);
buttons.add(sf);
buttons.add(sc);
buttons.add(ss);
buttons.add(lineSlider);
JPanel controls = new JPanel(new BorderLayout());
controls.add(heightSlider, BorderLayout.CENTER);
controls.add(parameterScaleSlider, BorderLayout.WEST);
controls.add(buttons, BorderLayout.EAST);
jf.add(controls, BorderLayout.EAST);
jf.pack();
jf.setVisible(true);
}
Aggregations