Foam::label Foam::surfaceToCell::getNearest ( const triSurfaceSearch& querySurf, const label pointi, const point& pt, const vector& span, Map<label>& cache ) { Map<label>::const_iterator iter = cache.find(pointi); if (iter != cache.end()) { // Found cached answer return iter(); } else { pointIndexHit inter = querySurf.nearest(pt, span); // Triangle label (can be -1) label triI = inter.index(); // Store triangle on point cache.insert(pointi, triI); return triI; } }
// Update intersections for selected edges. void Foam::edgeIntersections::intersectEdges ( const triSurface& surf1, const pointField& points1, // surf1 meshPoints (not localPoints!) const triSurfaceSearch& querySurf2, const scalarField& surf1PointTol, // surf1 tolerance per point const labelList& edgeLabels ) { const triSurface& surf2 = querySurf2.surface(); const vectorField& normals2 = surf2.faceNormals(); const labelList& meshPoints = surf1.meshPoints(); if (debug) { Pout<< "Calculating intersection of " << edgeLabels.size() << " edges" << " out of " << surf1.nEdges() << " with " << surf2.size() << " triangles ..." << endl; } pointField start(edgeLabels.size()); pointField end(edgeLabels.size()); vectorField edgeDirs(edgeLabels.size()); // Go through all edges, calculate intersections forAll(edgeLabels, i) { label edgeI = edgeLabels[i]; if (debug)// && (i % 1000 == 0)) { Pout<< "Intersecting edge " << edgeI << " with surface" << endl; } const edge& e = surf1.edges()[edgeI]; const point& pStart = points1[meshPoints[e.start()]]; const point& pEnd = points1[meshPoints[e.end()]]; const vector eVec(pEnd - pStart); const vector n(eVec/(mag(eVec) + VSMALL)); // Start tracking somewhat before pStart and up to somewhat after p1. // Note that tolerances here are smaller than those used to classify // hit below. // This will cause this hit to be marked as degenerate and resolved // later on. start[i] = pStart - 0.5*surf1PointTol[e[0]]*n; end[i] = pEnd + 0.5*surf1PointTol[e[1]]*n; edgeDirs[i] = n; }
bool Foam::surfaceToCell::differingPointNormals ( const triSurfaceSearch& querySurf, const vector& span, // Current search span const label celli, const label cellTriI, // Nearest (to cell centre) surface triangle Map<label>& pointToNearest // Cache for nearest triangle to point ) const { const triSurface& surf = querySurf.surface(); const vectorField& normals = surf.faceNormals(); const faceList& faces = mesh().faces(); const pointField& points = mesh().points(); const labelList& cFaces = mesh().cells()[celli]; forAll(cFaces, cFacei) { const face& f = faces[cFaces[cFacei]]; forAll(f, fp) { label pointi = f[fp]; label pointTriI = getNearest ( querySurf, pointi, points[pointi], span, pointToNearest ); if (pointTriI != -1 && pointTriI != cellTriI) { scalar cosAngle = normals[pointTriI] & normals[cellTriI]; if (cosAngle < 0.9) { return true; } } } }
// Update intersections for selected edges. void Foam::edgeIntersections::intersectEdges ( const triSurface& surf1, const pointField& points1, // surf1 meshPoints (not localPoints!) const triSurfaceSearch& querySurf2, const scalarField& surf1PointTol, // surf1 tolerance per point const labelList& edgeLabels ) { const triSurface& surf2 = querySurf2.surface(); const vectorField& normals2 = surf2.faceNormals(); const labelList& meshPoints = surf1.meshPoints(); if (debug) { Pout<< "Calculating intersection of " << edgeLabels.size() << " edges" << " out of " << surf1.nEdges() << " with " << surf2.size() << " triangles ..." << endl; } // Construct octree. const indexedOctree<treeDataTriSurface>& tree = querySurf2.tree(); label nHits = 0; // Go through all edges, calculate intersections forAll(edgeLabels, i) { label edgeI = edgeLabels[i]; if (debug && (i % 1000 == 0)) { Pout<< "Intersecting edge " << edgeI << " with surface" << endl; } const edge& e = surf1.edges()[edgeI]; const point& pStart = points1[meshPoints[e.start()]]; const point& pEnd = points1[meshPoints[e.end()]]; const vector eVec(pEnd - pStart); const scalar eMag = mag(eVec); const vector n(eVec/(eMag + VSMALL)); // Smallish length for intersection calculation errors. const point tolVec = 1e-6*eVec; // Start tracking somewhat before pStart and upto somewhat after p1. // Note that tolerances here are smaller than those used to classify // hit below. // This will cause this hit to be marked as degenerate and resolved // later on. point p0 = pStart - 0.5*surf1PointTol[e[0]]*n; const point p1 = pEnd + 0.5*surf1PointTol[e[1]]*n; const scalar maxS = mag(p1 - pStart); // Get all intersections of the edge with the surface DynamicList<pointIndexHit> currentIntersections(100); DynamicList<label> currentIntersectionTypes(100); while (true) { pointIndexHit pHit = tree.findLine(p0, p1); if (pHit.hit()) { nHits++; currentIntersections.append(pHit); // Classify point on surface1 edge. label edgeEnd = -1; if (mag(pHit.hitPoint() - pStart) < surf1PointTol[e[0]]) { edgeEnd = 0; } else if (mag(pHit.hitPoint() - pEnd) < surf1PointTol[e[1]]) { edgeEnd = 1; } else if (mag(n & normals2[pHit.index()]) < alignedCos_) { Pout<< "Flat angle edge:" << edgeI << " face:" << pHit.index() << " cos:" << mag(n & normals2[pHit.index()]) << endl; edgeEnd = 2; } currentIntersectionTypes.append(edgeEnd); if (edgeEnd == 1) { // Close to end break; } else { // Continue tracking. Shift by a small amount. p0 = pHit.hitPoint() + tolVec; if (((p0-pStart) & n) >= maxS) { break; } } } else { // No hit. break; } } // Done current edge. Transfer all data into *this operator[](edgeI).transfer(currentIntersections); classification_[edgeI].transfer(currentIntersectionTypes); }