From 276927cd4f9333ada04aa18580a6e2827b64f3be Mon Sep 17 00:00:00 2001 From: xibyte Date: Sun, 3 Dec 2017 21:23:24 -0800 Subject: [PATCH] filter --- web/app/brep/operations/boolean.js | 117 ++++++++++++++++++----------- web/app/brep/topo/edge.js | 7 +- 2 files changed, 76 insertions(+), 48 deletions(-) diff --git a/web/app/brep/operations/boolean.js b/web/app/brep/operations/boolean.js index 3ba66a73..b9667a53 100644 --- a/web/app/brep/operations/boolean.js +++ b/web/app/brep/operations/boolean.js @@ -8,7 +8,7 @@ import * as math from '../../math/math'; import {eqEps, eqTol, TOLERANCE, ueq, veq} from '../geom/tolerance'; const DEBUG = { - OPERANDS_MODE: false, + OPERANDS_MODE: true, LOOP_DETECTION: true, FACE_FACE_INTERSECTION: false, NOOP: () => {} @@ -178,53 +178,86 @@ export function mergeVertices(shell1, shell2) { } +function filterFacesByInvalidEnclose(faces) { + + function encloses(f1, f2, testee, overEdge) { + const edgeV = edge => edge.tangent(edge.vertexA.point); + + const unit = edgeV(overEdge); + const pt = overEdge.vertexA.point; + const t1 = f1.surface.normal(pt).cross(unit)._normalize(); + const t2 = f2.surface.normal(pt).cross(unit)._normalize(); + const t3 = testee.surface.normal(pt).cross(unit)._normalize(); + + __DEBUG__.AddNormal(pt, unit, 0xffffff); + __DEBUG__.AddNormal(pt, t1, 0x00ff00); + __DEBUG__.AddNormal(pt, t2, 0x00ffff); + __DEBUG__.AddNormal(pt, t3, 0xff0000); + + const angle = leftTurningMeasure(t1, t2, unit); + const testAngle = leftTurningMeasure(t1, t3, unit); + return testAngle > angle; + } + + let invalidFaces = new Set(); + + for (let face of faces) { + for (let e of face.edges) { + if (e.manifold !== null) { + let all = new Set(); + all.add(face); + e.twins().forEach(t => all.add(t.loop.face)); + let invalidCandidates = new Set(all); + for (let f1 of all) { + for (let f2 of all) { + if (f1 === f2) continue; + let neverEnclose = true; + for (let f3 of all) { + if (f1 === f3 || f2 === f3) continue; + if (encloses(f1, f2, f3, e)) { + neverEnclose = false; + break; + } + } + if (neverEnclose) { + invalidCandidates.delete(f1); + invalidCandidates.delete(f2); + } + } + } + invalidCandidates.forEach(f => invalidFaces.add(f)); + } + } + } + return faces.filter(f => !invalidFaces.has(f)); +} + function filterFaces(faces) { - - return faces.filter(raycastFilter); - - - // - // function isFaceContainNewEdge(face) { - // for (let e of face.edges) { - // if (isNewNM(e)) { - // return true; - // } - // } - // return false; - // } - // - // const validFaces = new Set(faces); - // const result = new Set(); - // for (let face of faces) { - // __DEBUG__.Clear(); - // __DEBUG__.AddFace(face); - // traverseFaces(face, validFaces, (it) => { - // if (result.has(it) || isFaceContainNewEdge(it)) { - // result.add(face); - // return true; - // } - // }); - // } - // return result; -} - -function raycastFilter(face, shell, opType) { - - let testPt = getPointOnFace(face); - let testCurve = ; - - - for (let testFace of face.faces) { - let pts = testFace.surface.intersectCurve(testCurve) - + function isFaceContainNewEdge(face) { + for (let e of face.edges) { + if (isNewNM(e)) { + return true; + } + } + return false; } - - + const validFaces = new Set(faces); + const result = new Set(); + for (let face of faces) { + // __DEBUG__.Clear(); + // __DEBUG__.AddFace(face); + traverseFaces(face, validFaces, (it) => { + if (result.has(it) || isFaceContainNewEdge(it)) { + result.add(face); + return true; + } + }); + } + return filterFacesByInvalidEnclose(result); } - function traverseFaces(face, validFaces, callback) { const stack = [face]; const seen = new Set(); diff --git a/web/app/brep/topo/edge.js b/web/app/brep/topo/edge.js index 37fc336e..d0ae9ddf 100644 --- a/web/app/brep/topo/edge.js +++ b/web/app/brep/topo/edge.js @@ -70,7 +70,7 @@ class HalfEdge extends TopoObject { return res; } - attachManifold(he, shallow) { + attachManifold(he) { if (this.manifold === null) { this.manifold = []; } @@ -78,10 +78,5 @@ class HalfEdge extends TopoObject { this.manifold.push(he); } he.manifoldHolder = this; - // if (shallow === true) { - // return; - // } - // this.twin().attachManifold() - // he.attachManifold(, true); } }