Esempio n. 1
0
void SC_Triangulation::EdgeBlockCleanup(const SC_PolyStore& nodeBlocks)
{
    //  make list of OK edges
    int nEdges = edgeList.Size();

    SC_BoolArray triOK(GetNTriangles());

    SC_PointArray stBlock;
    SC_PointArray endBlock;
    Line2D nodeLine;
    Line2D resultLine;
    bool allOK;

    // repeat for outside edges until none found
    while (true)
        {
            // reset to OK
            triOK.FillToSize(true);
            allOK = true;
            for (int i = 0; i < nEdges; i++)
                {
                    TriangleEdge& currEdge = edgeList[i];
                    // skip edges that are already deleted or are not outside
                    if ((currEdge.tri1 < 0) || (currEdge.tri2 >= 0))
                        continue;

                    // set node line endpoints
                    nodeLine.stPt = nodePoints[currEdge.stNode];
                    nodeLine.endPt = nodePoints[currEdge.endNode];
                    double fullDist = nodeLine.Length();
                    double remDist = fullDist;

                    nodeBlocks.GetPolyPoints(currEdge.stNode, stBlock);
                    if (stBlock.IntersectLine(nodeLine, resultLine, false, false))
                        remDist -= resultLine.Length();

                    nodeBlocks.GetPolyPoints(currEdge.endNode, endBlock);
                    if (endBlock.IntersectLine(nodeLine, resultLine, false, false))
                        remDist -= resultLine.Length();

                    if ((remDist / fullDist) > 0.01)
                        {
                            triOK[currEdge.tri1] = false;
                            allOK = false;
                        }
                }

            if (allOK)
                return;

            DoCleanup(triOK);
        }
}
Esempio n. 2
0
void SC_Triangulation::InternalBlockCleanup(const SC_PolyStore& nodeBlocks)
{
    //  make list of OK edges
    int nEdges = edgeList.Size();

    int nTri = GetNTriangles();
    SC_BoolArray triOK(nTri, true);

    SC_PointArray stBlock;
    SC_PointArray endBlock;
    SC_PointArray otherBlock;
    Line2D nodeLine;
    Line2D resultLine;
    bool allOK = true;
    int i;

    for (i = 0; i < nEdges; i++)
        {
            TriangleEdge& currEdge = edgeList[i];
            // skip edges that are already deleted or are external
            if ((currEdge.tri1 < 0) || (currEdge.tri2 < 0))
                continue;

            // set node line endpoints
            nodeLine.stPt = nodePoints[currEdge.stNode];
            nodeLine.endPt = nodePoints[currEdge.endNode];
            double fullDist = nodeLine.Length();
            double remDist = fullDist;

            //  get blocks for end points
            nodeBlocks.GetPolyPoints(currEdge.stNode, stBlock);
            if (stBlock.IntersectLine(nodeLine, resultLine, false, false))
                remDist -= resultLine.Length();

            nodeBlocks.GetPolyPoints(currEdge.endNode, endBlock);
            if (endBlock.IntersectLine(nodeLine, resultLine, false, false))
                remDist -= resultLine.Length();

            // check for simple case
            if ((remDist / fullDist) < 0.0001)
                continue;

            // get other block for tri 1
            int otherNode = GetEdgeOtherNode(i, currEdge.tri1);
            nodeBlocks.GetPolyPoints(otherNode, otherBlock);
            double otherLength = 0.0;
            if (otherBlock.IntersectLine(nodeLine, resultLine, false, false))
                {
                    otherLength = resultLine.Length();
                    remDist -= otherLength;
                }

            // get other block for tri 2
            otherNode = GetEdgeOtherNode(i, currEdge.tri2);
            nodeBlocks.GetPolyPoints(otherNode, otherBlock);
            if (otherBlock.IntersectLine(nodeLine, resultLine, false, false))
                remDist -= resultLine.Length();

            if ((remDist / fullDist) > 0.05)
                {
                    triOK[currEdge.tri1] = false;
                    if (currEdge.tri2 >= 0)
                        triOK[currEdge.tri2] = false;
                    allOK = false;
                }
        }

    if ( !allOK)
        DoCleanup(triOK);
}