use of org.twak.utils.geom.HalfMesh2.HalfEdge in project chordatlas by twak.
the class HouseTool method clickedOn.
@Override
public void clickedOn(Spatial target, Vector3f loc, Vector2f cursorPosition) {
// (Line) new XStream().fromXML( new File( "/home/twak/data/regent/March_30/congo/1/line.xml" ) ));
MegaFeatures mf = new MegaFeatures(new Line(0, 0, 10, 0));
// FeatureCache.readFeatures( new File( "/home/twak/data/regent/March_30/congo/1/0" ), mf );
ImageFeatures imf = new ImageFeatures();
imf.mega = mf;
double[] minMax = new double[] { 0, 15, 0, 25 };
HalfMesh2.Builder builder = new HalfMesh2.Builder(SuperEdge.class, SuperFace.class);
builder.newPoint(new Point2d(minMax[0] + loc.x, minMax[3] + loc.z));
builder.newPoint(new Point2d(minMax[1] + loc.x, minMax[3] + loc.z));
builder.newPoint(new Point2d(minMax[1] + loc.x, minMax[2] + loc.z));
builder.newPoint(new Point2d(minMax[0] + loc.x, minMax[2] + loc.z));
builder.newFace();
HalfMesh2 mesh = builder.done();
Prof p = new Prof();
p.add(new Point2d(0, 0));
p.add(new Point2d(0, 20));
p.add(new Point2d(-5, 25));
boolean first = true;
for (HalfFace f : mesh) {
for (HalfEdge e : f) {
SuperEdge se = (SuperEdge) e;
se.prof = p;
MiniFacade mini = newMini(imf, se.length());
if (true) {
se.addMini(mini);
se.proceduralFacade = mf;
se.toEdit = mini;
if (first)
se.addMini(mini);
}
first = false;
}
SuperFace sf = (SuperFace) f;
sf.maxProfHeights = new ArrayList();
sf.maxProfHeights.add(Double.valueOf(100));
sf.height = 100;
}
SkelGen sg = new SkelGen(mesh, tweed, null);
tweed.frame.addGen(sg, true);
}
use of org.twak.utils.geom.HalfMesh2.HalfEdge in project chordatlas by twak.
the class SkelGen method buildCamp.
private static PlanSkeleton buildCamp(SuperFace sf, Double cap) {
Plan plan = new Plan();
LoopL<Bar> loopl = new LoopL();
Loop<Bar> loop = new Loop();
loopl.add(loop);
Cache<Point2d, Point2d> cache = new Cache<Point2d, Point2d>() {
@Override
public Point2d create(Point2d i) {
return new Point2d(i.x, i.y);
}
};
LoopL<HalfEdge> edges = sf.findHoles();
LoopL<Point2d> lpd = new LoopL();
for (Loop<HalfEdge> loopHE : edges) {
Map<Point2d, SuperEdge> ses = new HashMap();
Loop<Point2d> lp = new Loop();
lpd.add(lp);
for (HalfEdge he : loopHE) {
SuperEdge se = (SuperEdge) he;
lp.append(se.start);
ses.put(se.start, se);
}
lp = Loopz.mergeAdjacentEdges2(lp, 0.001);
for (Loopable<Point2d> lpb : lp.loopableIterator()) {
Bar b = new Bar(cache.get(lpb.getNext().get()), cache.get(lpb.get()));
SuperEdge se = ses.get(lpb.get());
Profile profile = null;
if (se.prof == null || se.prof.size() < 2) {
List<Point2d> defpts = new ArrayList<>();
defpts.add(new Point2d(0, 0));
defpts.add(new Point2d(0, -sf.height * 1.2));
profile = new Profile(defpts);
} else {
profile = toProfile(se.prof);
}
tagWalls(profile, ((SuperFace) se.face).roofColor, se, lpb.get(), lpb.getNext().get());
plan.addLoop(profile.points.get(0), plan.root, profile);
b.tags.add(new SETag(se));
loop.prepend(b);
plan.profiles.put(b, profile);
}
}
plan.points = loopl;
if (cap != null) {
// skel.capAt( cap, a -> skel.capArea = a ); simple...but doesn't show in the siteplan ui
Ship s = new FlatRoofShip(cap, plan);
for (Profile prof : plan.profiles.values()) {
for (Loop<Bar> lb : prof.points) {
boolean addedMarker = false;
for (Bar b : lb) {
if (-b.start.y < cap && -b.end.y > cap || (!addedMarker && b == lb.start.getPrev().get())) {
Marker m = new Marker();
m.set(b.toLine().xAtY(-cap), -cap);
m.bar = b;
m.bar.mould.create(m, null);
Instance i = s.newInstance();
i.anchors[0].setProfileGen(m.generator);
addedMarker = true;
}
}
}
}
plan.ships.add(s);
}
PlanSkeleton skel = new PlanSkeleton(plan);
skel.skeleton();
return skel;
}
use of org.twak.utils.geom.HalfMesh2.HalfEdge in project chordatlas by twak.
the class SolverState method miniPainter.
public ICanPaint miniPainter() {
return new ICanPaint() {
@Override
public void paint(Graphics2D g, PanMouseAdaptor ma) {
// for ( MegaFeatures f : SS.minis.keySet() ) {
//
// for ( MFPoint mfp : SS.minis.get( f ) ) {
// Line l = mfp.image.mega.megafacade;
//
// spreadImages( g, ma, l, mfp, Listz.from( mfp.left, mfp.right ) );
//
// }
// }
// if (SS.minis == null)
int brake = 100;
for (HalfFace f : mesh) {
for (HalfEdge e : f) {
if (e.over != null)
continue;
if (brake-- < 0)
break;
SuperEdge se = (SuperEdge) e;
if (se.mini == null)
continue;
List<MiniFacade> mfs = new ArrayList(se.mini);
// while (mfs .size() < 2)
// mfs.add(null);
spreadImages(g, ma, se.line(), se.line().fromPPram(0.5), mfs);
}
}
int i = 0;
if (minis != null)
for (MegaFeatures f : minis.keySet()) {
// PaintThing.paint (f.megafacade, g, ma);
DumbCluster1D<MFPoint> res = GurobiSkelSolver.clusterMinis(f, minis);
Vector2d dir = f.megafacade.dir();
Vector2d out = new Vector2d(dir);
out.set(-out.y, out.x);
out.scale(ma.toZoom(2) / out.length());
for (Cluster<MFPoint> c : res) {
g.setColor(Rainbow.getColour(i++));
for (MFPoint mfp : c.things) {
Point2d pt = new Point2d(mfp);
pt.add(out);
g.setStroke(new BasicStroke(0.2f));
PaintThing.paint(pt, g, ma);
g.setStroke(new BasicStroke(0.2f));
for (HalfEdge e : GurobiSkelSolver.findNear(f.megafacade, mfp, mesh)) g.drawLine(ma.toX(pt.x), ma.toY(pt.y), ma.toX(e.end.x), ma.toY(e.end.y));
if (mfp.selectedEdge != null) {
g.setStroke(new BasicStroke(2f));
g.drawLine(ma.toX(pt.x), ma.toY(pt.y), ma.toX(mfp.selectedEdge.end.x), ma.toY(mfp.selectedEdge.end.y));
}
}
}
}
g.setStroke(new BasicStroke(1));
}
private void spreadImages(Graphics2D g, PanMouseAdaptor ma, Line sel, Point2d cen, List<MiniFacade> mfs) {
Vector2d perp = sel.dir();
perp.set(-perp.y, perp.x);
perp.normalize();
for (int i = 0; i < mfs.size(); i++) {
MiniFacade mf = mfs.get(i);
Vector2d p2 = new Vector2d(perp);
p2.scale((i + 1) * 10);
p2.add(cen);
if (mf == null) {
g.setColor(Color.black);
g.fillRect(ma.toX(p2.x - 1), ma.toY(p2.y - 3), ma.toZoom(2), ma.toZoom(6));
continue;
}
double w = mf.width * 0.1;
double h = mf.height * 0.1;
mf.paintImage(g, ma, p2.x - w, p2.y - h, p2.x + w, p2.y + h);
}
}
};
}
use of org.twak.utils.geom.HalfMesh2.HalfEdge in project chordatlas by twak.
the class SkelFootprint method killDoubleEdges.
public static void killDoubleEdges(HalfMesh2 mesh) {
for (HalfFace f : mesh) {
boolean iDidSomething;
do {
iDidSomething = false;
for (HalfEdge e : f) {
if (e.next.over == e) {
e.dissolve(mesh);
iDidSomething = true;
}
}
} while (iDidSomething);
}
}
use of org.twak.utils.geom.HalfMesh2.HalfEdge in project chordatlas by twak.
the class SkelFootprint method pushHeightsToSmallFaces.
private static void pushHeightsToSmallFaces(HalfMesh2 mesh) {
for (HalfFace f : mesh.faces) {
SuperFace sf = (SuperFace) f;
if (sf.height == -Double.MAX_VALUE) {
// || sf.area() < 1 ) {
double bestLength = -Double.MAX_VALUE;
SuperFace bestFace = null;
overProfile: for (boolean overProfiles : new boolean[] { false, true }) {
for (HalfEdge e2 : f.edges()) {
double len = e2.length();
if (len > bestLength && e2.over != null)
if (overProfiles || ((SuperEdge) e2).profLine == null && ((SuperEdge) e2.over).profLine == null) {
SuperFace sf2 = (SuperFace) e2.over.face;
if (sf2.height != -Double.MAX_VALUE) {
bestFace = sf2;
bestLength = len;
}
}
}
if (bestFace != null) {
sf.height = bestFace.height;
break overProfile;
}
}
}
}
}
Aggregations