use of javax.vecmath.Point2d in project chordatlas by twak.
the class Extruder method readPath.
private void readPath(String name) {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
try {
// Using factory get an instance of document builder
DocumentBuilder db = dbf.newDocumentBuilder();
// parse using builder to get DOM representation of the XML file
Document dom = db.parse(name);
NodeList paths = dom.getElementsByTagName("path");
PathParser pathParser = new PathParser();
PathHandler pathHandler = new MyPathHandler();
pathParser.setPathHandler(pathHandler);
for (int i = 0; i < paths.getLength(); i++) {
pathParser.parse(paths.item(i).getAttributes().getNamedItem("d").getTextContent());
}
for (Point2d pt : path) {
System.out.println(pt);
}
} catch (Throwable pce) {
pce.printStackTrace();
}
}
use of javax.vecmath.Point2d in project chordatlas by twak.
the class FindLines method rotateToAngle.
public static Line rotateToAngle(Line nLine, Point2d cen, double angle) {
double len = nLine.length() / 2;
Vector2d dir = new Vector2d(-Math.cos(angle) * len, -Math.sin(angle) * len);
Point2d start = new Point2d(cen), end = new Point2d(cen);
start.add(dir);
end.sub(dir);
return new Line(start, end);
}
use of javax.vecmath.Point2d in project chordatlas by twak.
the class FindLines method forClique.
private void forClique(Set<Line> remaining, List<Line> out, int debugLine, int clique) {
Iterator<Line> filter = remaining.iterator();
while (filter.hasNext()) {
Line l = filter.next();
// double l = filter.next().length();
if (l.lengthSquared() == 0 || l.hasNaN())
filter.remove();
}
if (remaining.isEmpty())
return;
int count = 0;
while (!remaining.isEmpty()) {
double angle = nextAngle(remaining, count);
// offset bin
Bin.Builder<Line> oBBin = new Bin.Builder<>();
LinearForm lfPerp = new LinearForm(Math.cos(angle), Math.sin(angle));
for (Line l : remaining) {
if (Anglez.dist(l.aTan2(), angle) < Math.PI / 2) {
// and line angle near angle+-180
oBBin.add(lfPerp.findPParam(l.start), l.length(), l);
oBBin.add(lfPerp.findPParam(l.end), l.length(), l);
}
}
// we're super sensitive to the number of orientation bins :(
Bin<Line> oBin = oBBin.done(P.FL_BINS * 2, false);
int oBinI = oBin.maxI();
int[] oBinM = oBin.maxMode(1, 10);
LinearForm lfDir = new LinearForm(lfPerp.y, -lfPerp.x);
lfDir.findC(lfPerp.fromPParam(oBin.val(oBinI)));
RangeMerge<Line> rm = new RangeMerge(P.FL_GAP_TOL, P.FL_GAP_TOL / 2);
for (Line w : oBin.getThings(oBinI, oBinM)) {
if (lfDir.distance(w.start) < getTolNearLine(w.start) && lfDir.distance(w.end) < getTolNearLine(w.end) && // and line angle near angle+-180
Anglez.dist(w.aTan2(), angle) < Math.PI / 2.5) {
rm.add(lfDir.findPParam(w.start), lfDir.findPParam(w.end), w);
}
}
List<Result<Line>> merged = rm.getResults();
if (merged.isEmpty()) {
for (Line w : oBin.getThings(oBinI, oBinM)) remaining.remove(w);
} else {
double maxP = merged.stream().map(x -> x.max - x.min).max(Double::compare).get();
for (Result<Line> r : merged) {
if (r.max - r.min < 0.2 * maxP)
continue;
Line line = null;
if (P.FL_REGRESS)
line = regress(r.things, lfDir);
if (line == null)
line = new Line(lfDir, r.min, r.max);
Iterator<Line> rit = remaining.iterator();
boolean removed = false;
Bin<Line> counts = null;
if (P.MIN_LINES > 1)
counts = new Bin<>(0, 1, 50, false);
while (rit.hasNext()) {
Line rine = rit.next();
if (line.distance(rine.start, true) < getTolNearLine2(rine.start) && line.distance(rine.end, true) < getTolNearLine2(rine.end) && Anglez.dist(line.aTan2(), rine.aTan2()) < getTolRemoveAngle(rine)) {
if (counts != null)
counts.addRange(line.findPPram(rine.start), line.findPPram(rine.end), 1, rine);
removed = true;
rit.remove();
}
}
if (counts != null) {
// for (Pair<Double, Double > d : new ConsecutiveItPairs<>( counts.getRegionAbove( P.MIN_LINES ) )) {
//
// Point2d start = line.fromPPram( counts.getFirst( P.MIN_LINES ) ),
// end = line.fromPPram( counts.getLast( P.MIN_LINES ) );
//
// if ( start != null && end != null ) {
// out.add( new Line(start, end) );
// }
// }
Point2d start = line.fromPPram(counts.getFirst(P.MIN_LINES)), end = line.fromPPram(counts.getLast(P.MIN_LINES));
if (start != null && end != null) {
line.start = start;
line.end = end;
} else
line = null;
}
if (!removed)
for (Line l : r.things) {
if (remaining.contains(l)) {
remaining.remove(l);
}
}
if (line != null) {
if (bias != null) {
Point2d cen = line.fromPPram(0.5);
Double toGIS = bias.getAngle(line, cen);
if (toGIS != null)
line = rotateToAngle(line, cen, toGIS);
}
if (debugFilter(count, debugLine) && line.start.distanceSquared(line.end) > 0.001) {
out.add(line);
cliques.put(line, clique);
}
}
}
}
count++;
}
}
use of javax.vecmath.Point2d in project chordatlas by twak.
the class GreebleGrid method moulding.
protected void moulding(Matrix4d to3d, DRectangle rect, MeshBuilder mb) {
double hh = rect.height / 2;
Point3d start = new Point3d(rect.x, 0, rect.y + hh), end = new Point3d(rect.getMaxX(), 0, rect.y + hh);
to3d.transform(start);
to3d.transform(end);
Line3d line = new Line3d(start, end);
Vector3d dir = line.dir();
dir.normalize();
Vector3d nDir = new Vector3d(dir);
nDir.scale(-1);
LinearForm3D left = new LinearForm3D(nDir, start), right = new LinearForm3D(dir, end);
LinearForm3D wall = new LinearForm3D(to3d.m01, to3d.m11, to3d.m21);
wall.findD(start);
Tube.tube(mb, Collections.singleton(left), Collections.singleton(right), line, wall, wall, new CrossGen() {
@Override
public List<Point2d> gen(Vector2d down, Vector2d up) {
Vector2d d = new Vector2d(down);
d.normalize();
Vector2d dP = new Vector2d(d.y, -d.x);
List<Point2d> out = new ArrayList();
for (double[] coords : new double[][] { { 1.00, 0.00 }, { 1.00, 0.05 }, { 0.66, 0.05 }, { 0.66, 0.10 }, { 0.33, 0.10 }, { 0.33, 0.17 }, { 0.00, 0.17 }, { 0.00, 0.00 } }) {
Point2d tmp = new Point2d(d);
tmp.scale(coords[0] * rect.height - hh);
Point2d tmp2 = new Point2d(dP);
tmp2.scale(coords[1]);
tmp.add(tmp2);
out.add(tmp);
}
return out;
}
});
}
use of javax.vecmath.Point2d in project chordatlas by twak.
the class GreebleGrid method createWindow.
protected void createWindow(DRectangle winPanel, Matrix4d to3d, MeshBuilder wall, MeshBuilder window, MeshBuilder glass, double depth, float sillDepth, float sillHeight, float corniceHeight, double panelWidth, double panelHeight) {
Point2d[] pts = winPanel.points();
Point3d[] ptt = new Point3d[4];
for (int i = 0; i < 4; i++) {
ptt[i] = Pointz.to3(pts[i]);
to3d.transform(ptt[i]);
}
Vector3d along = new Vector3d(ptt[3]);
along.sub(ptt[0]);
along.normalize();
Vector3d up = new Vector3d(ptt[1]);
up.sub(ptt[0]);
up.normalize();
Vector3d out = new Vector3d();
out.cross(along, up);
out.scale(-1 / out.length());
Vector3d loc = new Vector3d();
loc.cross(along, up);
loc.scale(-depth / loc.length());
loc.add(ptt[0]);
WindowGen.createWindow(window, glass, new Window(Jme3z.to(loc), Jme3z.to(along), Jme3z.to(up), winPanel.width, winPanel.height, 0.3, panelWidth, panelHeight));
Vector3f u = Jme3z.to(up), o = Jme3z.to(out);
wall.addInsideRect(Jme3z.to(ptt[0]), o, Jme3z.to(along), u, (float) depth, (float) winPanel.width, (float) winPanel.height, null);
if (sillDepth > 0 && sillHeight > 0)
window.addCube(Jme3z.to(ptt[0]).add(u.mult(-sillHeight + 0.01f)).add(o.mult(-sillDepth)), Jme3z.to(out), Jme3z.to(along), Jme3z.to(up), (float) depth + sillDepth, (float) winPanel.width, (float) sillHeight);
if (corniceHeight > 0)
moulding(to3d, new DRectangle(winPanel.x, winPanel.getMaxY(), winPanel.width, corniceHeight), wall);
}
Aggregations