// Starting from cut edge start walking.
bool Foam::hexCellLooper::walkHex
(
    const label cellI,
    const label startFaceI,
    const label startEdgeI,

    labelList& loop,
    scalarField& loopWeights
) const
{
    label faceI = startFaceI;

    label edgeI = startEdgeI;

    label cutI = 0;

    do
    {
        if (debug & 2)
        {
            Pout<< "    walkHex : inserting cut onto edge:" << edgeI
                << " vertices:" << mesh().edges()[edgeI] << endl;
        }

        // Store cut through edge. For now cut edges halfway.
        loop[cutI] = edgeToEVert(edgeI);
        loopWeights[cutI] = 0.5;
        cutI++;

        faceI = meshTools::otherFace(mesh(), cellI, faceI, edgeI);

        const edge& e = mesh().edges()[edgeI];

        // Walk two edges further
        edgeI = meshTools::walkFace(mesh(), faceI, edgeI, e.end(), 2);

        if (edgeI == startEdgeI)
        {
            break;
        }
    }
    while (true);

    // Checks.
    if (cutI > 4)
    {
        Pout<< "hexCellLooper::walkHex" << "Problem : cell:" << cellI
            << " collected loop:";
        writeCuts(Pout, loop, loopWeights);
        Pout<< "loopWeights:" << loopWeights << endl;

        return false;
    }
    else
    {
        return true;
    }
}
Example #2
0
bool Foam::geomCellLooper::cut
(
    const plane& cutPlane,
    const label cellI,
    const boolList&,
    const boolList&,
    const scalarField&,

    labelList& loop,
    scalarField& loopWeights
) const
{
    const pointField& points = mesh().points();
    const edgeList& edges = mesh().edges();

    // Find all cuts through edges.
    // Special cases:
    // - edge cut close to endpoint. Snap to endpoint.
    // - edge endpoint close to plane (but edge not cut). Snap to endpoint.
    // - both endpoints close to plane. Edge parallel to plane. No need to
    //   cut to edge.
    // Note: any snap-to-point check must be based on all edges using a point
    // since otherwise cut through close to point but on neighbouring edge
    // might not be snapped.

    // Size overly big.
    label nEstCuts = 2*mesh().cells()[cellI].size();

    DynamicList<label> localLoop(nEstCuts);
    DynamicList<scalar> localLoopWeights(nEstCuts);

    // Points checked. Used to make sure we don't cut edge and edge endpoints
    // at the same time.
    labelHashSet checkedPoints(nEstCuts);

    const labelList& cellEdges = mesh().cellEdges()[cellI];

    forAll(cellEdges, i)
    {
        label edgeI = cellEdges[i];

        const edge& e = edges[edgeI];

        bool useStart = false;

        bool useEnd = false;

        //
        // Check distance of endpoints to cutPlane
        //

        if (!checkedPoints.found(e.start()))
        {
            checkedPoints.insert(e.start());

            scalar typStartLen = pointEqualTol_ * minEdgeLen(e.start());

            // Check distance of startPt to plane.
            if (cutPlane.distance(points[e.start()]) < typStartLen)
            {
                // Use point.
                localLoop.append(vertToEVert(e.start()));
                localLoopWeights.append(-GREAT);

                useStart = true;
            }
        }
        if (!checkedPoints.found(e.end()))
        {
            checkedPoints.insert(e.end());

            scalar typEndLen = pointEqualTol_ * minEdgeLen(e.end());

            // Check distance of endPt to plane.
            if (cutPlane.distance(points[e.end()]) < typEndLen)
            {
                // Use point.
                localLoop.append(vertToEVert(e.end()));
                localLoopWeights.append(-GREAT);

                useEnd = true;
            }
        }

        //
        // Check cut of edge
        //

        if (!useEnd && !useStart)
        {
            // Edge end points not close to plane so edge not close to
            // plane. Cut edge.
            scalar cutWeight;

            if (cutEdge(cutPlane, edgeI, cutWeight))
            {
                // Snap edge cut to vertex.
                label cutVertI = snapToVert(snapTol_, edgeI, cutWeight);

                if (cutVertI == -1)
                {
                    // Proper cut of edge
                    localLoop.append(edgeToEVert(edgeI));
                    localLoopWeights.append(cutWeight);
                }
                else
                {
                    // Cut through edge end point. Might be duplicate
                    // since connected edge might also be snapped to same
                    // endpoint so only insert if unique.
                    label cut = vertToEVert(cutVertI);

                    if (findIndex(localLoop, cut) == -1)
                    {
                        localLoop.append(vertToEVert(cutVertI));
                        localLoopWeights.append(-GREAT);
                    }
                }
            }
        }
    }