use of org.twak.utils.Line 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.Line in project chordatlas by twak.
the class ImagePlaneGen method rotateByAngle.
public ImagePlaneGen rotateByAngle(double deltaAngle, double distance) {
Line nLine = new Line(new Point2d(a.x, a.z), new Point2d(b.x, b.z));
Point2d cen = nLine.fromPPram(0.5);
double angle = nLine.aTan2() + deltaAngle;
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);
ImagePlaneGen out = new ImagePlaneGen(this);
out.a.set((float) start.x, a.y, (float) start.y);
out.b.set((float) end.x, b.y, (float) end.y);
out.calcUV();
return out;
}
use of org.twak.utils.Line in project chordatlas by twak.
the class ProfileGen method processMegaFaces.
private void processMegaFaces() {
addOnJmeThread.clear();
if (faces == null || faces.isEmpty()) {
JOptionPane.showMessageDialog(tweed.frame(), "Failed to cluster facades");
return;
}
Node mfNode = new Node();
// Node cProfileNode = new Node();
Random randy = new Random(2);
dbgProfileLookup.clear();
final boolean DBG = true;
computeProfiles(faces);
int i = 0;
for (MegaFacade mf : faces) {
// if (i == 4)
{
System.out.println("building profiles over megafacade " + i + "/" + faces.size());
ColorRGBA dispCol = new ColorRGBA(color.getRed() * randy.nextFloat() / 255f, color.getGreen() * randy.nextFloat() / 255f, color.getBlue() * randy.nextFloat() / 255f, 1);
if (DBG) {
List<Line3d> dbg = new ArrayList();
for (int d : mf.keySet()) {
for (Line l2 : mf.get(d)) {
Line3d oLine = new Line3d(l2.start.x, getHeight(d), l2.start.y, l2.end.x, getHeight(d), l2.end.y);
dbg.add(oLine);
}
}
mfNode.attachChild(Jme3z.lines(tweed.getAssetManager(), dbg, dispCol, 0.1f, true));
Line l2 = mf.origin.line;
Line3d oLine = new Line3d(l2.start.x, getHeight(mf.origin.height), l2.start.y, l2.end.x, getHeight(mf.origin.height), l2.end.y);
// mfNode.attachChild( Jme3z.lines( tweed.getAssetManager(), Collections.singletonList( oLine ), dispCol, 0.5f, true ) );
}
{
Line l3 = mf.origin.line;
// if ( mf.profiles.values().stream().mapToDouble( p -> p.get( 0 ).y ).min().getAsDouble() > 8 )
// continue;
totalPlanLineLength += l3.length();
Line3d oLine = new Line3d(l3.start.x, getHeight(mf.origin.height), l3.start.y, l3.end.x, getHeight(mf.origin.height), l3.end.y);
List<SuperLine> pLines = Prof.findProfileLines(mf.profiles.values(), oLine);
for (int pi = 0; pi < pLines.size(); pi++) {
SuperLine profileLine = pLines.get(pi);
// if ( distance ( gis, profileLine.start ) > 2 || distance ( gis, profileLine.end ) > 2 )
// continue;
Node profileNode = new Node();
// dispCol = new ColorRGBA( randy.nextFloat(), randy.nextFloat(), randy.nextFloat(), 1 );
MegaFacade pMF = mf.moveTo(profileLine);
if (pi >= 1) {
Line newOrigin = null;
double bestDist = Double.MAX_VALUE;
Point3d plCen = Pointz.to3(profileLine.fromPPram(0.5), getHeight(mf.hExtentMin));
for (int li = mf.hExtentMin; li <= mf.hExtentMax; li++) for (Line l : mf.get(li)) {
double dist = Pointz.to3(l.fromPPram(0.5), getHeight(li)).distance(plCen);
if (dist < bestDist) {
newOrigin = l;
bestDist = dist;
}
}
if (newOrigin != null) {
pMF.setOrigin(new LineAtHeight(pMF.hExtentMin, newOrigin));
pMF.computeProfiles(ProfileGen.this);
}
}
profileLine.setMega(pMF);
footprint.add(profileLine);
dbgProfileLookup.put(i++, pMF);
if (DBG) {
profileNode.attachChild(Jme3z.lines(tweed.getAssetManager(), Collections.singletonList(new Line3d(profileLine.start.x, 0, profileLine.start.y, profileLine.end.x, 0, profileLine.end.y)), dispCol, 0.3f, true));
render(new ArrayList<>(pMF.profiles.values()), tweed, dispCol, profileNode);
// List<Prof> cleans = new ArrayList<>();
// for ( Prof p : pMF.profiles.values() ) {
// p.render( tweed, profileNode, dispCol, 1f );
// cleans.add( new Prof( p ).parameterize() );
// .render( tweed, cProfileNode, dispCol.add( ColorRGBA.Gray ), 1f );
//
// }
// render ( cleans, tweed, cProfileNode );
profileNode.attachChild(Jme3z.lines(tweed.getAssetManager(), Collections.singletonList(oLine), dispCol, 0.3f, true));
profileNode.setUserData(ProfileGen.class.getSimpleName(), i);
addOnJmeThread.add(profileNode);
}
}
}
}
}
if (DBG)
tweed.frame.addGen(new JmeGen("horizontal lines", tweed, mfNode), false);
// tweed.frame.addGen( new JmeGen( "clean profiles", tweed, cProfileNode ), false );
calculateOnJmeThread();
}
use of org.twak.utils.Line in project chordatlas by twak.
the class CutHoles method find.
public static Point3d find(Point2d pt, Map<Point2d, Point3d> root, Map<Point2d, Line> created) {
if (root.containsKey(pt))
return root.get(pt);
else {
Line l = created.get(pt);
Point3d a = find(l.start, root, created), b = find(l.end, root, created);
return new Line3d(a, b).fromPPram(l.findPPram(pt));
}
}
use of org.twak.utils.Line in project chordatlas by twak.
the class GBias method getAngle.
/**
* local bias
*/
public Double getAngle(Line line, Point2d cen) {
final double PI8 = Math.PI / 8;
DRectangle r = new DRectangle(line);
r.grow(expand);
Collection<Longer> res = tree.queryRange(r);
double bestScore = -Double.MAX_VALUE;
Double bestAngle = null;
for (AxisAlignedBoundingBox aabb : res) {
Line gis = ((Longer) aabb).line;
double len = gis.length();
// gis.distance( line );
double dist = gis.fromPPram(0.5).distance(line.fromPPram(0.5));
if (dist < len * expand) {
double angle = line.absAngle(gis);
if (angle < PI8) {
double score = (PI8 - angle) / dist;
if (score > bestScore) {
bestAngle = gis.aTan2();
bestScore = score;
}
} else if (Mathz.inRangeTol(angle, Mathz.PI2, PI8)) {
double score = 0.2 * (PI8 - angle) / dist;
if (score > bestScore) {
gis = new Line(new Point2d(gis.start.y, -gis.start.x), new Point2d(gis.end.y, -gis.end.x));
if (gis.absAngle(line) > PI8)
gis = gis.reverse();
bestAngle = gis.aTan2();
bestScore = score;
}
}
}
}
if (bestAngle != null)
return bestAngle;
else
return null;
}
Aggregations