use of javax.vecmath.Point2d in project chordatlas by twak.
the class MiniGen method inBounds.
private boolean inBounds(Matrix4d mini, List<double[]> bounds) {
// mini matrix is in mini-mesh format: a translation from a 255^3 cube in the first quadrant
// trans.offset is a transform from that space, into jme rendered space (cartesian in meters, around the origin)
Matrix4d m = new Matrix4d();
m.mul(Jme3z.fromMatrix(trans.offset), mini);
for (Point2d p : Arrays.stream(cubeCorners).map(c -> {
Point3d tmp = new Point3d();
m.transform(c, tmp);
return new Point2d(tmp.x, tmp.z);
}).collect(Collectors.toList())) {
for (double[] bound : bounds) {
if (bound[0] < p.x && bound[1] > p.x && bound[2] < p.y && bound[3] > p.y)
return true;
}
}
return false;
}
use of javax.vecmath.Point2d in project chordatlas by twak.
the class MiniGen method clip.
public void clip(Loop<Point3d> in, File objLocation) {
ObjDump obj = new ObjDump();
double[] bounds = Loopz.minMaxXZ(in);
List<LinearForm3D> halfPlanes = new ArrayList();
File writeFolder = objLocation.getParentFile();
for (Pair<Point3d, Point3d> p : in.pairs()) {
Vector3d norm = new Vector3d(p.second());
norm.sub(p.first());
norm = new Vector3d(-norm.z, 0, norm.x);
norm.normalize();
halfPlanes.add(new LinearForm3D(norm, p.first()));
}
Map<File, File> copied = new HashMap<>();
int nameCount = 0;
double minY = Double.MAX_VALUE, maxY = -Double.MAX_VALUE;
for (Map.Entry<Integer, Matrix4d> e : trans.index.entrySet()) {
if (!inBounds(e.getValue(), Collections.singletonList(bounds)))
continue;
else {
Matrix4d m = new Matrix4d();
m.mul(Jme3z.fromMatrix(trans.offset), e.getValue());
File readFolder = new File(Tweed.toWorkspace(root), e.getKey() + "");
ObjDump or = new ObjDump(new File(readFolder, "model.obj"));
or.computeMissingNormals();
for (ObjDump.Material mat : or.material2Face.keySet()) {
f: for (Face f : or.material2Face.get(mat)) {
for (int j = 0; j < f.vtIndexes.size(); j++) {
Point3d pt = new Point3d(or.orderVert.get(f.vtIndexes.get(j)));
m.transform(pt);
if (pt.x > bounds[0] && pt.x < bounds[1] && pt.z > bounds[2] && pt.z < bounds[3])
if (inside(pt, halfPlanes)) {
if (IMPORT_TEXTURES && !((obj.currentMaterial != null && obj.currentMaterial.equals(mat)) || (obj.currentMaterial == null && mat == null))) {
File source = new File(readFolder, mat.filename);
ObjDump.Material newMat;
if (copied.containsKey(source)) {
newMat = new ObjDump.Material(mat);
newMat.filename = copied.get(source).getName();
} else {
newMat = makeUnique(mat, writeFolder);
File destFile = new File(writeFolder, newMat.filename);
copied.put(source, destFile);
try {
Files.copy(source.toPath(), new FileOutputStream(destFile));
} catch (IOException e1) {
e1.printStackTrace();
}
}
newMat.diffuse = new double[] { 0, 0, 0 };
newMat.ambient = new double[] { 1, 1, 1 };
newMat.specular = new double[] { 0, 0, 0 };
newMat.name = "mat_" + (nameCount++);
obj.setCurrentMaterial(newMat);
}
List<Point3d> fVerts = new ArrayList<>(3), fNorms = new ArrayList<>(3);
List<Point2d> fUVs = new ArrayList<>(2);
for (int i = 0; i < f.vtIndexes.size(); i++) {
Point3d vts = new Point3d(or.orderVert.get(f.vtIndexes.get(i)));
Point3d ns = new Point3d(or.orderNorm.get(f.normIndexes.get(i)));
ns.add(vts);
m.transform(vts);
m.transform(ns);
ns.sub(vts);
minY = Math.min(vts.y, minY);
maxY = Math.max(vts.y, maxY);
fVerts.add(vts);
fNorms.add(ns);
fUVs.add(new Point2d(or.orderUV.get(f.uvIndexes.get(i))));
}
obj.addFace(fVerts, fNorms, fUVs);
continue f;
}
}
}
}
}
}
for (Tuple3d t : obj.orderVert) t.y -= (maxY - minY) * 0.03 + minY;
obj.dump(objLocation);
}
use of javax.vecmath.Point2d in project chordatlas by twak.
the class FeatureCache method readFeatures.
public static ImageFeatures readFeatures(File fFolder, MegaFeatures megaFeatures) {
Line mega = new Line(megaFeatures.megafacade);
ImageFeatures out = new ImageFeatures();
out.mega = megaFeatures;
Line imageL = null;
out.miniFacades = new ArrayList();
{
if (Tweed.DATA == null)
out.ortho = new File(fFolder, RENDERED_IMAGE_PNG);
else
out.ortho = Paths.get(Tweed.DATA).relativize(new File(fFolder, RENDERED_IMAGE_PNG).toPath()).toFile();
File rectFile = new File(fFolder, "rectified.png");
if (rectFile.exists()) {
if (Tweed.DATA == null)
out.rectified = rectFile;
else
out.rectified = Paths.get(Tweed.DATA).relativize(rectFile.toPath()).toFile();
} else
out.rectified = out.ortho;
}
int imageWidth = out.getRectified().getWidth(), imageHeight = out.getRectified().getHeight();
double rectifiedToOrtho = out.getRectified().getWidth() / (double) out.getOrtho().getWidth();
{
List<String> lines = null;
try {
lines = Files.readAllLines(new File(fFolder, "meta.txt").toPath());
} catch (IOException e) {
System.err.println("failed to read metafile");
}
if (lines == null) {
System.out.println("warning, failed to read input files in " + fFolder);
imageL = new Line(0, 0, out.getRectified().getWidth() / FacadeTool.pixelsPerMeter, 0);
} else {
String plane = lines.get(1);
String[] pVals = plane.split(" ");
Point2d a = new Point2d(Float.parseFloat(pVals[0]), Float.parseFloat(pVals[1]));
Point2d b = new Point2d(Float.parseFloat(pVals[2]), Float.parseFloat(pVals[3]));
imageL = new Line(a, b);
}
}
out.start = mega.findPPram(imageL.start) * mega.length();
out.end = mega.findPPram(imageL.end) * mega.length();
try {
File yFile = new File(fFolder, PARAMETERS_YML);
if (yFile.exists()) {
YamlReader fromVision = new YamlReader(new FileReader(yFile));
Map m = (Map) fromVision.read();
List yamlFac = (List) m.get("facades");
double maxW = 0;
if (yamlFac != null) {
for (Object o : yamlFac) try {
MiniFacade mf = new MiniFacade(out, (Map) o, imageWidth / (rectifiedToOrtho * FacadeTool.pixelsPerMeter), imageHeight / FacadeTool.pixelsPerMeter, rectifiedToOrtho * FacadeTool.pixelsPerMeter, out.start);
if (!mf.invalid())
out.miniFacades.add(mf);
maxW = Math.max(maxW, (mf.left + mf.width - out.start));
} catch (Throwable th) {
System.out.println("while reading " + yFile);
th.printStackTrace();
}
}
} else
System.out.println("no parameters in " + fFolder);
} catch (Throwable e) {
e.printStackTrace();
}
return out;
}
use of javax.vecmath.Point2d in project chordatlas by twak.
the class MiniFacade method paint.
@Override
public void paint(Graphics2D g, PanMouseAdaptor ma) {
if (PAINT_IMAGE && imageFeatures != null) {
Composite oldC = g.getComposite();
g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.4f));
paintImage(g, ma, left, -height, left + width, 0);
g.setComposite(oldC);
}
g.setStroke(new BasicStroke(2f));
if (width < 5)
return;
for (Feature f : Feature.values()) if (f != Feature.GRID)
for (FRect w : rects.get(f)) {
if (w.outer == null) {
g.setColor(f.color);
// if (w.width < 10)
g.drawRect(ma.toX(w.x), ma.toY(-w.y - w.height), ma.toZoom(w.width), ma.toZoom(w.height));
g.setColor(Color.black);
if (w.id >= 0)
g.drawString(w.id + "", ma.toX(w.x) + 3, ma.toY(-w.y - w.height) + 13);
// try {
// g.drawString(
// w.attachedHeight.get( Feature.CORNICE ).d +", " +
// w.attachedHeight.get( Feature.BALCONY ).d +", "+
// w.attachedHeight.get( Feature.SILL ).d + ", ",
// ma.toX( w.x ) + 3, ma.toY( -w.y - w.height ) + 13 );
// } catch (NullPointerException e) {}
}
for (Dir dir : Dir.values()) {
FRect n = w.getAdj(dir);
if (n != null) {
g.setColor(Rainbow.getColour(dir.ordinal()));
Point2d s = getRectPoint(w, dir), e = getRectPoint(n, dir.opposite);
s.y = -s.y;
e.y = -e.y;
Line l = new Line(s, e);
PaintThing.paint(l, g, ma);
PaintThing.drawArrow(g, ma, l, 3);
// if ( dir == Dir.L || dir == Dir.U ) {
// Point2d label = l.fromPPram( 0.5 );
// g.drawString( w.distanceToAdjacent( dir ) + "", ma.toX( label.x ), ma.toY( label.y ) );
// }
}
}
}
if (false && grid != null) {
g.setColor(new Color(100, 100, 255, 200));
// for ( DRectangle w : grid.dows )
// g.fillRect( ma.toX( w.x ), ma.toY( -w.y - w.height ), ma.toZoom( w.width ), ma.toZoom( w.height ) );
g.setColor(new Color(100, 255, 10, 200));
if (false)
for (int x = 0; x < grid.cols; x++) for (int y = 0; y < grid.rows; y++) {
g.fillRect(ma.toX(x * grid.hspacing + grid.x), ma.toY(-y * grid.vspacing - grid.wHeight - grid.y), ma.toZoom(grid.wWidth), ma.toZoom(grid.wHeight));
}
}
g.setColor(Color.black);
g.drawLine(ma.toX(left), ma.toY(0), ma.toX(left + width), ma.toY(0));
g.setColor(Color.green);
g.setColor(new Color(0, 170, 255));
g.setStroke(new BasicStroke(softLeft ? 1 : 3));
g.drawLine(ma.toX(left), ma.toY(0), ma.toX(left), ma.toY(-height));
g.setStroke(new BasicStroke(softRight ? 1 : 3));
g.drawLine(ma.toX(left + width), ma.toY(0), ma.toX(left + width), ma.toY(-height));
g.setColor(Color.black);
g.setStroke(new BasicStroke(1));
g.drawLine(ma.toX(left), ma.toY(-height), ma.toX(left + width), ma.toY(-height));
g.drawLine(ma.toX(left), ma.toY(-groundFloorHeight), ma.toX(left + width), ma.toY(-groundFloorHeight));
}
use of javax.vecmath.Point2d in project chordatlas by twak.
the class MiniFacade method mouseDown.
@Override
public void mouseDown(MouseEvent e, PanMouseAdaptor ma) {
Point2d pt = flip(ma.from(e));
double bestDist = ma.fromZoom(10);
dragging = null;
mouseLastDown = e.getButton();
for (FRect f : getRects()) {
double dist = f.getDistance(pt);
if (dist < bestDist) {
bestDist = dist;
dragging = f;
}
}
if (dragging != null && e.getButton() == 3)
dragging.mouseDown(e, ma);
}
Aggregations