use of org.twak.utils.geom.ObjRead 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.utils.geom.ObjRead 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);
}
use of org.twak.utils.geom.ObjRead in project chordatlas by twak.
the class ObjSlice method sliceTri.
public static List<Line> sliceTri(ObjRead mesh, double h, int majorAxis) {
int[] flatAxis = new int[] { (majorAxis + 1) % 3, (majorAxis + 2) % 3 };
if (flatAxis[0] > flatAxis[1]) {
int tmp = flatAxis[0];
flatAxis[0] = flatAxis[1];
flatAxis[1] = tmp;
}
Vector3d sliceNormal = new Vector3d(majorAxis == 0 ? 1 : 0, majorAxis == 1 ? 1 : 0, majorAxis == 2 ? 1 : 0), slicePt = new Vector3d(sliceNormal);
slicePt.scale(h);
LinearForm3D slicePlane = new LinearForm3D(sliceNormal, slicePt);
return slice(mesh, flatAxis, slicePlane, Double.MAX_VALUE, null, Double.MAX_VALUE).stream().map(l -> new Line(l.start.x, l.start.z, l.end.x, l.end.z)).collect(Collectors.toList());
}
use of org.twak.utils.geom.ObjRead in project chordatlas by twak.
the class GISGen method initObj.
public void initObj() {
ObjRead gObj = new ObjRead(tweed.toWorkspace(objFile));
LoopL<Point3d> fromOBJ = new LoopL<>();
Closer<Point3d> closer = new Closer<>();
for (int[] face : gObj.faces) {
Loop<Point3d> loop = fromOBJ.newLoop();
List<Point3d> points = new ArrayList<>();
for (int i = 0; i < face.length; i++) {
Point3d p = new Point3d(gObj.pts[face[i]]), n = new Point3d(gObj.pts[face[(i + 1) % face.length]]);
// !
n.y = p.y = 0;
loop.append(p);
points.add(p);
lines.add(new Line3d(p, n));
}
closer.add(points.toArray(new Point3d[points.size()]));
}
createBlocks(closer, fromOBJ);
}
use of org.twak.utils.geom.ObjRead in project chordatlas by twak.
the class ObjGen method dumpObj.
@Override
public void dumpObj(ObjDump dump) {
dump.setCurrentMaterial(Color.pink, 0.5);
dump.addAll(new ObjRead(getFile()));
}
Aggregations