use of javax.vecmath.Point2d 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 javax.vecmath.Point2d in project chordatlas by twak.
the class SkelFootprint method cleanFootprints.
private static void cleanFootprints(HalfMesh2 mesh) {
for (HalfFace hf : mesh.faces) for (HalfEdge e : hf.edges()) if (e.over != null && e.over.face != e.face)
e.over = null;
Map<HalfEdge, Double> mergePoint = new HashMap();
Predicate<HalfEdge> badEdges = new Predicate<HalfMesh2.HalfEdge>() {
@Override
public boolean test(HalfEdge t) {
if (// is edge within a single face
t.over != null)
// preserve as hole-marker
return false;
double len = t.length();
if (t.length() < 0.2) {
mergePoint.put(t, 0.5);
return true;
}
double angleNext = t.line().absAngle(t.next.line());
final double tol = 0.1;
if (t.next.over == null && len < t.next.length() && angleNext > Math.PI - tol) {
mergePoint.put(t, 0.);
return true;
}
if (t.next.over == null && angleNext < tol) {
mergePoint.put(t, 0.);
return true;
}
HalfEdge prev = t.findBefore();
double anglePrev = t.line().absAngle(prev.line());
if (prev.over == null && len <= prev.length() && anglePrev > Math.PI - tol) {
mergePoint.put(t, 1.);
return true;
}
if (prev.over == null && anglePrev < tol) {
mergePoint.put(t, 1.);
return true;
}
return false;
}
};
f: for (HalfFace f : new ArrayList<>(mesh.faces)) {
Set<HalfEdge> togo = Streamz.stream(f.edges()).filter(badEdges).collect(Collectors.toSet());
while (!togo.isEmpty()) {
HalfEdge g = togo.iterator().next(), p = g.findBefore(), n = g.next;
togo.remove(g);
togo.remove(p);
togo.remove(n);
if (g.replaceByPoint(mesh, g.line().fromPPram(mergePoint.get(g))))
continue f;
HalfEdge pp = p.findBefore();
Streamz.stream(pp, p, n, n.next).forEach(o -> togo.remove(o));
Streamz.stream(pp, p, n, n.next).filter(badEdges).forEach(e -> togo.add(e));
}
}
for (HalfFace f : mesh.faces) {
Set<Point2d> seen = new HashSet<>();
for (HalfEdge e : f) {
if (seen.contains(e.end) && e.over == null && e.next.over == null) {
HalfEdge n = e.next;
Point2d edited;
Vector2d b4 = e.line().dir(), af = n.line().dir();
b4.normalize();
af.normalize();
b4.set(b4.y, -b4.x);
af.set(af.y, -af.x);
b4.add(af);
b4.scale(1 / b4.length());
edited = new Point2d(b4);
edited.add(e.end);
n.start = edited;
e.end = new Point2d(edited);
}
seen.add(e.end);
}
}
}
use of javax.vecmath.Point2d in project chordatlas by twak.
the class SkelFootprint method boundMesh.
public static HalfMesh2 boundMesh(List<Line> footprint) {
double[] minMax = minMax(10, footprint);
HalfMesh2.Builder builder = new HalfMesh2.Builder(SuperEdge.class, SuperFace.class);
builder.newPoint(new Point2d(minMax[0], minMax[3]));
builder.newPoint(new Point2d(minMax[1], minMax[3]));
builder.newPoint(new Point2d(minMax[1], minMax[2]));
builder.newPoint(new Point2d(minMax[0], minMax[2]));
builder.newFace();
HalfMesh2 mesh = builder.done();
return mesh;
}
use of javax.vecmath.Point2d in project chordatlas by twak.
the class SkelFootprint method dbgShowProfiles.
private void dbgShowProfiles(HalfMesh2 mesh, List<Prof> globalProfs, Map<SuperEdge, double[]> profFit, String name) {
Node n = new Node();
Jme3z.removeAllChildren(n);
int colI = 0;
for (HalfFace f : mesh) {
ColorRGBA col = Jme3z.toJme(Rainbow.getColour(colI++));
colI = colI % 6;
Material mat = new Material(tweed.getAssetManager(), "Common/MatDefs/Light/Lighting.j3md");
mat.setColor("Diffuse", col);
mat.setColor("Ambient", col);
mat.setBoolean("UseMaterialColors", true);
if (true) {
Loop<Point3d> loop = new Loop<>();
for (HalfEdge e : f) loop.append(new Point3d(e.start.x, 0, e.start.y));
MeshBuilder mb = new MeshBuilder();
mb.add(loop.singleton(), null, false);
Geometry g = new Geometry("floorplan", mb.getMesh());
g.setMaterial(mat);
n.attachChild(g);
}
for (HalfEdge e : f) {
SuperEdge se = (SuperEdge) e;
Prof bestProf = null;
if (globalProfs == null)
bestProf = se.prof;
else {
// if (se.profLine != null) {
//
// SuperLine sl = ((SuperLine)se.profLine);
// MegaFacade mf = (MegaFacade) sl.properties.get( MegaFacade.class.getName() );
//
// List<Prof> pfs = mf.getTween( se.start, se.end, 0.3 );
//
// if (!pfs.isEmpty())
// bestProf = Prof.parameterize( sl, pfs );
// else {
// bestProf = clean.get( 0 );
// double bestScore = Double.MAX_VALUE;
//
// for ( Prof c : clean ) {
//
// double score = 0;
// boolean good = false;
// for ( Prof r : mf.getTween( se.start, se.end, 0.3 ) ) {
// score += c.distance( r, true, false, true );
// good = true;
// }
// if ( good && score < bestScore ) {
// bestScore = score;
// bestProf = c;
// }
//
// }
// }
//
//
// }
// if (bestProf)
// ((SuperLine))
//
double[] fitV = profFit.get(se);
if (fitV == null)
continue;
double bestScore = Double.MAX_VALUE;
for (int ii = 0; ii < fitV.length; ii++) {
double d = fitV[ii];
if (d < bestScore) {
bestScore = d;
bestProf = globalProfs.get(ii);
}
}
//
// double bestScore = Double.MAX_VALUE;
//
// for ( int ii = 0; ii < fitV.length; ii++ ) {
// double d = fitV[ ii ];
// if ( d < bestScore ) {
// bestScore = d;
// bestProf = globalProfs.get( ii );
// }
// }
// if (false)
// se.prof = bestProf;
}
if (bestProf != null) {
Geometry g = new Geometry();
Point3d cen = Pointz.to3(se.line().fromPPram(0.5));
Prof goodOrientation = Prof.buildProfile(Pointz.to3(se.line()), cen);
for (Point2d p : bestProf) goodOrientation.add(p);
g.setMesh(goodOrientation.renderStrip(1.5, cen));
g.setMaterial(mat);
n.attachChild(g);
g.updateGeometricState();
g.updateModelBound();
}
}
}
skelGen.tweed.frame.addGen(new JmeGen(name, tweed, n), false);
}
use of javax.vecmath.Point2d in project Smiles2Monomers by yoann-dufresne.
the class MonomersSerialization method deserializeObject.
private void deserializeObject(Monomer mono, ObjectInputStream ois) {
try {
int nbAtoms = ois.readInt();
if (nbAtoms != mono.getMolecule().getAtomCount()) {
System.err.println("Bad serialized value for atom count in " + mono.getCode());
}
for (IAtom a : mono.getMolecule().atoms()) {
Point2d p = new Point2d(ois.readDouble(), ois.readDouble());
a.setPoint2d(p);
}
} catch (IOException e) {
e.printStackTrace();
}
}
Aggregations