Ejemplo n.º 1
0
// 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);
        }
    }
Ejemplo n.º 2
0
static triSurface pack
(
    const triSurface& surf,
    const pointField& localPoints,
    const labelList& pointMap
)
{
    List<labelledTri> newTriangles(surf.size());
    label newTriangleI = 0;

    forAll(surf, faceI)
    {
        const labelledTri& f = surf.localFaces()[faceI];

        label newA = pointMap[f[0]];
        label newB = pointMap[f[1]];
        label newC = pointMap[f[2]];

        if ((newA != newB) && (newA != newC) && (newB != newC))
        {
            newTriangles[newTriangleI++] =
                labelledTri(newA, newB, newC, f.region());
        }
    }
    newTriangles.setSize(newTriangleI);

    return triSurface(newTriangles, surf.patches(), localPoints);
}
Ejemplo n.º 3
0
void Foam::momentOfInertia::massPropertiesSolid
(
    const triSurface& surf,
    scalar density,
    scalar& mass,
    vector& cM,
    tensor& J
)
{
    triFaceList faces(surf.size());

    forAll(surf, i)
    {
        faces[i] = triFace(surf[i]);
    }
Ejemplo n.º 4
0
// 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]]);
    }
// Print on master all the per-processor surface stats.
void writeProcStats
(
    const triSurface& s,
    const List<List<treeBoundBox> >& meshBb
)
{
    // Determine surface bounding boxes, faces, points
    List<treeBoundBox> surfBb(Pstream::nProcs());
    {
        surfBb[Pstream::myProcNo()] = treeBoundBox(s.points());
        Pstream::gatherList(surfBb);
        Pstream::scatterList(surfBb);
    }

    labelList nPoints(Pstream::nProcs());
    nPoints[Pstream::myProcNo()] = s.points().size();
    Pstream::gatherList(nPoints);
    Pstream::scatterList(nPoints);

    labelList nFaces(Pstream::nProcs());
    nFaces[Pstream::myProcNo()] = s.size();
    Pstream::gatherList(nFaces);
    Pstream::scatterList(nFaces);

    forAll(surfBb, procI)
    {
        const List<treeBoundBox>& bbs = meshBb[procI];

        Info<< "processor" << procI << nl
            << "\tMesh bounds          : " << bbs[0] << nl;
        for (label i = 1; i < bbs.size(); i++)
        {
            Info<< "\t                       " << bbs[i]<< nl;
        }
        Info<< "\tSurface bounding box : " << surfBb[procI] << nl
            << "\tTriangles            : " << nFaces[procI] << nl
            << "\tVertices             : " << nPoints[procI]
            << endl;
    }
    Info<< endl;
}
Ejemplo n.º 6
0
// 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);
    }