// Helper function to calculate tight fitting bounding boxes. Foam::treeBoundBoxList Foam::octreeDataTriSurface::calcBb ( const triSurface& surf ) { treeBoundBoxList allBb(surf.size(), treeBoundBox::invertedBox); const labelListList& pointFcs = surf.pointFaces(); const pointField& localPts = surf.localPoints(); forAll(pointFcs, pointI) { const labelList& myFaces = pointFcs[pointI]; const point& vertCoord = localPts[pointI]; forAll(myFaces, myFaceI) { // Update bb label faceI = myFaces[myFaceI]; treeBoundBox& bb = allBb[faceI]; bb.min() = min(bb.min(), vertCoord); bb.max() = max(bb.max(), vertCoord); } }
// Dump collapse region to .obj file static void writeRegionOBJ ( const triSurface& surf, const label regionI, const labelList& collapseRegion, const labelList& outsideVerts ) { fileName dir("regions"); mkDir(dir); fileName regionName(dir / "region_" + name(regionI) + ".obj"); Pout<< "Dumping region " << regionI << " to file " << regionName << endl; boolList include(surf.size(), false); forAll(collapseRegion, faceI) { if (collapseRegion[faceI] == regionI) { include[faceI] = true; } } labelList pointMap, faceMap; triSurface regionSurf(surf.subsetMesh(include, pointMap, faceMap)); Pout<< "Region " << regionI << " surface:" << nl; regionSurf.writeStats(Pout); regionSurf.write(regionName); // Dump corresponding outside vertices. fileName pointsName(dir / "regionPoints_" + name(regionI) + ".obj"); Pout<< "Dumping region " << regionI << " points to file " << pointsName << endl; OFstream str(pointsName); forAll(outsideVerts, i) { meshTools::writeOBJ(str, surf.localPoints()[outsideVerts[i]]); }
void Foam::edgeIntersections::checkEdges(const triSurface& surf) { const pointField& localPoints = surf.localPoints(); const edgeList& edges = surf.edges(); const labelListList& edgeFaces = surf.edgeFaces(); treeBoundBox bb(localPoints); scalar minSize = SMALL * bb.minDim(); forAll(edges, edgeI) { const edge& e = edges[edgeI]; scalar eMag = e.mag(localPoints); if (eMag < minSize) { WarningIn ( "Foam::edgeIntersections::checkEdges(const triSurface& surf)" ) << "Edge " << edgeI << " vertices " << e << " coords:" << localPoints[e[0]] << ' ' << localPoints[e[1]] << " is very small compared to bounding" << " box dimensions " << bb << endl << "This might lead to problems in intersection" << endl; } if (edgeFaces[edgeI].size() == 1) { WarningIn ( "Foam::edgeIntersections::checkEdges(const triSurface& surf)" ) << "Edge " << edgeI << " vertices " << e << " coords:" << localPoints[e[0]] << ' ' << localPoints[e[1]] << " has only one face connected to it:" << edgeFaces[edgeI] << endl << "This might lead to problems in intersection" << endl; } } }
// Collapses small edge to point, thus removing triangle. label collapseEdge(triSurface& surf, const scalar minLen) { label nTotalCollapsed = 0; while (true) { const pointField& localPoints = surf.localPoints(); const List<labelledTri>& localFaces = surf.localFaces(); // Mapping from old to new points labelList pointMap(surf.nPoints()); forAll(pointMap, i) { pointMap[i] = i; } // Storage for new points. pointField newPoints(localPoints); // To protect neighbours of collapsed faces. boolList okToCollapse(surf.size(), true); label nCollapsed = 0; forAll(localFaces, faceI) { if (okToCollapse[faceI]) { // Check edge lengths. const triSurface::FaceType& f = localFaces[faceI]; forAll(f, fp) { label v = f[fp]; label v1 = f[f.fcIndex(fp)]; if (mag(localPoints[v1] - localPoints[v]) < minLen) { // Collapse f[fp1] onto f[fp]. pointMap[v1] = v; newPoints[v] = 0.5*(localPoints[v1] + localPoints[v]); Pout<< "Collapsing triange " << faceI << " to edge mid " << newPoints[v] << endl; nCollapsed++; okToCollapse[faceI] = false; // Protect point neighbours from collapsing. markPointNbrs(surf, faceI, false, okToCollapse); break; } } } } Pout<< "collapseEdge : collapsing " << nCollapsed << " triangles" << endl; nTotalCollapsed += nCollapsed; if (nCollapsed == 0) { break; } // Pack the triangles surf = pack(surf, newPoints, pointMap); }