use of org.twak.utils.Cache in project chordatlas by twak.
the class SkelFootprint method mergeOnProfiles.
private void mergeOnProfiles(HalfMesh2 mesh, List<Line> footprint) {
System.out.println("merging over profiles...");
TreeSet<HalfFace> togo = new TreeSet<>((HalfFace o1, HalfFace o2) -> Double.compare(o1.area(), o2.area()));
togo.addAll(mesh.faces);
int count = 0;
while (!togo.isEmpty()) {
HalfFace f = togo.pollFirst();
Cache<HalfEdge, MutableDouble> crossedBy = new Cach<>(e -> new MutableDouble(0));
for (HalfEdge e : f) {
SuperEdge se = (SuperEdge) e;
if (se.profLine != null) {
MegaFacade mf = ((SuperLine) se.profLine).mega;
if (mf != null)
for (Prof p : mf.getTween(se.start, se.end, 0)) {
Line proj = new Line(Pointz.to2(p.to3d(p.get(0))), Pointz.to2(p.to3d(p.get(p.size() - 1))));
for (HalfEdge e2 : f) {
SuperEdge se2 = (SuperEdge) e2;
if (se2.profLine == null && (se2.over == null || ((SuperEdge) se2.over).profLine == null) && e2.over != null && e2.line().intersects(proj) != null && Mathz.inRange(e2.line().absAngle(proj), 0.25 * Math.PI, 0.75 * Math.PI)) {
crossedBy.get(e2).d += TweedSettings.settings.profileHSampleDist;
}
}
}
}
}
count += crossedBy.cache.size();
Optional<Map.Entry<HalfEdge, MutableDouble>> longestO = crossedBy.cache.entrySet().stream().filter(//
e1 -> ((SuperEdge) e1.getKey()).profLine == null && e1.getValue().d > 0).max((e1, e2) -> Double.compare(e1.getValue().d, e2.getValue().d));
if (longestO.isPresent()) {
Map.Entry<HalfEdge, MutableDouble> longest = longestO.get();
if (longest.getValue().d > 0.6 * longest.getKey().length()) {
HalfFace tgf = longest.getKey().over.face;
togo.remove(tgf);
longest.getKey().face.merge(mesh, tgf);
((SuperFace) longest.getKey().face).mergeFrom((SuperFace) tgf);
togo.add(f);
}
}
}
System.out.println("found crossings " + count);
killDoubleEdges(mesh);
}
use of org.twak.utils.Cache in project chordatlas by twak.
the class SliceSolver method slicesByDataFit.
private void slicesByDataFit(Slice slice, double delta, List<State> states) {
{
Cache<State, Double> cache = new Cache<State, Double>() {
@Override
public Double create(State i) {
double out = 0;
for (State s : states) {
double d = dataFit(s.filtered, i.con.out);
if (d != Double.MAX_VALUE)
out += d;
else
out += 1e3;
}
if (out == 0)
out = Double.MAX_VALUE;
return out;
}
};
Collections.sort(states, new Comparator<State>() {
public int compare(State o1, State o2) {
return -Double.compare(cache.get(o1), cache.get(o2));
}
});
states.stream().forEach(s -> CutHoles.cutHoles(s.con.out, P.CON_TOL / 5));
ObjDump out = new ObjDump();
double height = slice.min[slice.majorAxis];
for (int i = 0; i < states.size(); i++) {
State s = states.get(i);
System.out.println(" >>>> " + cache.get(s));
Slice.extrude(out, s.con.out, height, height + delta);
Slice.capAtHeight(out, s.con.out, false, height);
Slice.capAtHeight(out, s.con.out, true, height + delta);
height += delta * 3;
}
out.dump(outfile);
}
}
use of org.twak.utils.Cache in project chordatlas by twak.
the class SkelFootprint method profileRuns.
private static void profileRuns(SuperLine sl, MultiMap<SuperLine, List<Prof>> profSets) {
MegaFacade mf = sl.getMega();
Cache<Integer, Double> distance2Next = new Cache<Integer, Double>() {
@Override
public Double create(Integer i) {
Prof pc = mf.profiles.get(i), pn = mf.profiles.get(i + 1);
if (pc == null || pn == null)
return 1e6;
return pc.distance(pn, true, false, false);
}
};
// i -> mf.profiles.get( i ).distance( mf.profiles.get(i+1), true ));
int start = mf.hExtentMin;
for (int i = mf.hExtentMin; i < mf.hExtentMax; i++) {
if (distance2Next.get(i) > 4 || i == mf.hExtentMax - 1) {
// if ( (Math.random() > 0.95 || i == mf.hExtentMax - 1) ){//0.5 / ProfileGen.HORIZ_SAMPLE_DIST) {
if (i - start > 0.5 / TweedSettings.settings.profileHSampleDist) {
List<Prof> lp = IntStream.range(start, i + 1).mapToObj(p -> mf.profiles.get(p)).filter(p -> p != null).collect(Collectors.toList());
if (lp != null && !lp.isEmpty())
profSets.put(sl, lp);
}
start = i + 1;
// i++;
// }
}
}
// System.out.println( (mf.hExtentMax - mf.hExtentMin)+ " mm " + min+ " / " + max +" found " + profSets.size() );
}
Aggregations