Beispiel #1
0
TopoDS_Shape BRLFile::PerformBoolean(union tree *tp)
{
    TopoDS_Shape left, right, result;
    if(tp->tr_op==OP_UNION || tp->tr_op==OP_INTERSECT || tp->tr_op==OP_SUBTRACT
    ) {
        left=PerformBoolean(tp->tr_b.tb_left);
        right=PerformBoolean(tp->tr_b.tb_right);
    }

    if(verbose&BRL) {
        switch(tp->tr_op) {
        case OP_UNION:
        case OP_INTERSECT:
        case OP_SUBTRACT:
                cout<< "    Bool " << *tp;
                break;
        case OP_DB_LEAF:
            if(verbose&BRL)
                cout << "    Leaf " << tp->tr_l.tl_name;
            break;
        }
        cout << " remaining " << construction.size() << '\n';
    }

    switch(tp->tr_op) {
    case OP_UNION:    return BRepAlgoAPI_Fuse(left,right); 
    case OP_INTERSECT:return BRepAlgoAPI_Common(left,right);
    case OP_SUBTRACT: return BRepAlgoAPI_Cut(left,right);
    case OP_DB_LEAF:
        result=construction.back();
        construction.pop_back();
        return result;
    default:
        std::cerr << "Invalid boolean operation in " << __FUNCTION__ << '\n';
        return result;
    }
}
Beispiel #2
0
// must be critical cell
void BSPOctree::PerformIteration(PolygonPtrList& mesh1, PolygonPtrList& mesh2
                                 , Box3& bbox, OctTreeNode **node)
{
    if ((mesh1.size() + mesh2.size()) < 17)
    {
        PerformBoolean(mesh1, mesh2, bbox, node);
        return;
    }

    Box3 childBBox[8];
    bool bCriticalCells[8];
    memset(bCriticalCells, 0 , 8);

    SplitSpaceByXYZ(bbox, childBBox);
    DetermineCriticalCell(childBBox, bCriticalCells);

    PolygonPtrList XYZSplits1[8], XYZSplits2[8];
    for (auto index: mesh1)
    {
        auto &pos = mMesh1[index].Position;
        for (int i = 0; i < 8; i++)
        {
            //if (!bCriticalCells[i]) continue;
            if (TestTriangleAABBOverlap(pos[0], pos[1], pos[2], childBBox[i]))
            {
                XYZSplits1[i].push_back(index);
            }
        }
    }

    for (auto index: mesh2)
    {
        auto &pos = mMesh2[index].Position;
        for (int i = 0; i < 8; i++)
        {
            //if (!bCriticalCells[i]) continue;
            if (TestTriangleAABBOverlap(pos[0], pos[1], pos[2], childBBox[i]))
            {
                XYZSplits2[i].push_back(index);
            }
        }
    }

    // for containment test, jxd
    auto &pNode = *node;
    pNode = new OctTreeNode;
    pNode->bbox = bbox;
    pNode->type = eIntered;
    // end

    for (int i = 0; i < 8; i++)
    {
        if (!bCriticalCells[i])/* continue;*/
        {
            // for containment test, jxd
            OctLeafNode *pLeaf = new OctLeafNode;
            pLeaf->bbox = childBBox[i];
            pLeaf->type = eNormal;
            FillOctreeLeafNode(XYZSplits1[i], XYZSplits2[i], pLeaf);
            pNode->child[i] = pLeaf;
            // end
        }
        else
        {
            if (XYZSplits1[i].size()*XYZSplits2[i].size() == 0)
            {
                // for containment test, jxd
                OctLeafNode *pLeaf = new OctLeafNode;
                pLeaf->bbox = childBBox[i];
                pLeaf->type = eCritical;
                FillOctreeLeafNode(XYZSplits1[i], XYZSplits2[i], pLeaf);
                pNode->child[i] = pLeaf;
                // end
            }
            else PerformIteration(XYZSplits1[i], XYZSplits2[i], childBBox[i], &(pNode->child[i]));
        }

    }
}