use of org.twak.utils.ui.Plot in project chordatlas by twak.
the class SkelGen method selected.
private void selected(PlanSkeleton skel, Node house, SuperFace sf, SuperEdge se) {
JPanel ui = new JPanel();
ui.setLayout(new ListDownLayout());
JButton fac = new JButton("edit facade");
fac.addActionListener(e -> editFacade(skel, sf, se, false));
ui.add(fac);
// JButton tex = new JButton( "texture facade" );
// tex.addActionListener( e -> editFacade( skel, sf, se, true ) );
// ui.add( tex );
JButton proc = new JButton("procedural facade");
proc.addActionListener(e -> cgaFacade(skel, sf, se));
ui.add(proc);
JButton camp = new JButton("procedural extrusions");
camp.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
closeSitePlan();
siteplan = new Siteplan(skel.plan, false) {
SuperFace workon = sf;
public void show(Output output, Skeleton threadKey) {
super.show(output, threadKey);
Plot.closeLast();
tweed.enqueue(new Runnable() {
@Override
public void run() {
removeGeometryFor(workon);
// current selection is invalid
tweed.frame.setGenUI(null);
setSkel((PlanSkeleton) threadKey, output, workon);
}
});
}
};
siteplan.setVisible(true);
siteplan.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
}
});
ui.add(camp);
JButton mini = new JButton("street-view");
mini.addActionListener(e -> new MiniViewer(se));
if (sf != null)
ui.add(mini);
JButton prof = new JButton("profiles");
prof.addActionListener(e -> new ProfileAssignmentViewer(sf, skelFootprint == null ? null : skelFootprint.globalProfs));
ui.add(prof);
ui.add(new JLabel("height " + sf.heights.size()));
JButton plan = new JButton("plan");
plan.addActionListener(e -> new Plot(toRender, footprint));
ui.add(plan);
JButton remove = new JButton("remove");
remove.addActionListener(e -> {
visible = false;
calculateOnJmeThread();
tweed.frame.removeGen(SkelGen.this);
});
ui.add(plan);
JButton b = new JButton("view clean profiles");
b.addActionListener(e -> SkelFootprint.debugFindCleanProfiles(footprint, this, new ProgressMonitor(null, "", "", 0, 100), tweed));
ui.add(b);
JButton c = new JButton("compare profiles");
c.addActionListener(e -> skelFootprint.debugCompareProfs(skelFootprint.globalProfs));
ui.add(c);
tweed.frame.setGenUI(ui);
}
use of org.twak.utils.ui.Plot in project chordatlas by twak.
the class SkelFootprint method debugFindCleanProfiles.
public static void debugFindCleanProfiles(List<Line> footprint, SkelGen skelGen, ProgressMonitor m, Tweed tweed) {
MultiMap<SuperLine, List<Prof>> profSets = new MultiMap<>();
for (Line l : footprint) profileRuns((SuperLine) l, profSets);
List<List<Prof>> ordered = new ArrayList<>();
Map<List<Prof>, SuperLine> pairs = new LinkedHashMap<>();
for (SuperLine l : profSets.keySet()) for (List<Prof> lp : profSets.get(l)) {
pairs.put(lp, l);
ordered.add(lp);
}
JSlider bunch = new JSlider(0, ordered.size() - 1);
JButton button = new JButton("go");
Plot plot = new Plot(bunch, button);
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
PaintThing.debug.clear();
plot.toPaint.clear();
List<Prof> ps = ordered.get(bunch.getValue());
SuperLine sl = pairs.get(ps);
if (sl != null && ps != null) {
PaintThing.debug(new Color(0, 0, 0, 50), 1, ps);
Prof clean = Prof.parameterize(ps);
Prof c2 = new Prof(clean);
for (Point2d p : c2) p.x += 10;
// plot.toPaint.add( clean ) );
PaintThing.debug(new Color(0, 170, 255), 3f, c2);
Prof mid = ps.get(ps.size() / 2);
tweed.enqueue(new Runnable() {
@Override
public void run() {
Jme3z.removeAllChildren(tweed.debug);
for (Prof p : ps) {
// p = p.moveToX0();
p.render(tweed, tweed.debug, ColorRGBA.Blue, (float) TweedSettings.settings.profileHSampleDist);
}
Point3d pt = mid.to3d(mid.get(0));
pt.y = 0;
Geometry geom = new Geometry("material_", clean.renderStrip(1, null));
Material mat = new Material(tweed.getAssetManager(), "Common/MatDefs/Light/Lighting.j3md");
mat.setColor("Diffuse", ColorRGBA.Blue);
mat.setColor("Ambient", ColorRGBA.Red);
geom.setMaterial(mat);
// tweed.debug.attachChild( geom );
tweed.debug.updateGeometricState();
tweed.debug.updateModelBound();
tweed.gainFocus();
}
});
}
plot.repaint();
}
});
bunch.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
button.doClick();
}
});
}
use of org.twak.utils.ui.Plot in project chordatlas by twak.
the class SkelFootprint method debugCompareProfs.
public void debugCompareProfs(List<Prof> profs) {
JSlider slider1 = new JSlider(SwingConstants.VERTICAL, -1, profs.size() - 1, 0);
JSlider slider2 = new JSlider(SwingConstants.VERTICAL, -1, profs.size() - 1, 0);
final Plot pot = new Plot(slider1, slider2);
ChangeListener cl = new ChangeListener() {
@Override
public void stateChanged(ChangeEvent arg0) {
pot.toPaint.clear();
PaintThing.debug.clear();
pot.toPaint.add("" + profs.size());
if (slider1.getValue() == -1 || slider2.getValue() == -1) {
for (Prof p : profs) PaintThing.debug(new Color(0, 0, 0, 50), 1f, p);
pot.repaint();
return;
}
Prof p = profs.get(slider1.getValue()), d = profs.get(slider2.getValue());
pot.toPaint.add(p);
pot.toPaint.add(d);
pot.toPaint.add("pair distance: " + d.distance(p, false, true, true));
pot.repaint();
}
};
slider1.addChangeListener(cl);
slider2.addChangeListener(cl);
}
use of org.twak.utils.ui.Plot 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 org.twak.utils.ui.Plot 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