occ-demo

BVH:

void occQt::makeSphere()
{
gp_Ax2 anAxis;
anAxis.SetLocation(gp_Pnt(0.0, 0.0, 0.0));

//1.创建物体
TopoDS_Shape aTopoSphere = BRepPrimAPI_MakeSphere(anAxis, 30.0).Shape();
//2.获取shape指针
Handle(AIS_Shape) anAisSphere = new AIS_Shape(aTopoSphere);
//设置颜色
anAisSphere->SetColor(Quantity_NOC_BLUE1);
//通过OccView上下文显示
myOccView->getContext()->Display(anAisSphere, Standard_True);

Handle(AIS_InteractiveContext) myAISContext = myOccView->getContext();
//构造bvh树
BRepExtrema_ShapeList faceList;
for (TopExp_Explorer exp(aTopoSphere, TopAbs_FACE); exp.More(); exp.Next()) {
    faceList.Append(TopoDS::Face(exp.Current()));
}
//BRepExtrema_ShapeList aaL;
BRepExtrema_TriangleSet triangleSet(faceList);
int triangleSize = triangleSet.Size();

// TopoDS_Shape edgeShape = edge.Current();
// Handle(AIS_Shape) h1 = new AIS_Shape(edgeShape);
// myAISContext->Display(h1, true);

triangleSet.BVH();
//const NCollection_Handle<BVH_Tree<Standard_Real, 3> > aBvh = triangleSet.BVH();
const opencascade::handle<BVH_Tree<Standard_Real, 3> > aBvh = triangleSet.BVH();
int length = aBvh->Length();//节点数量
int depth = aBvh->Depth();//深度

int innNodeNum = 0;
int leavesNodeNum = 0;

int leavesNumMax = 0;
for (int i = 0; i < length; i +=1)
{
    BVH_Vec4i aNodeData1 = aBvh->NodeInfoBuffer()[i];
    //BVH_Vec4i aNodeData =
    //std::vector<typename VectorType<T, N>::Type>
    BVH_Array4i array = aBvh->NodeInfoBuffer();//BVH_Vec4i数组,数量为length

    BVH_Vec4i aNodeData = array[i];//四个值为:节点类型、起始序号,结束序号、0
    if (aNodeData.x() == 0)
    {
        innNodeNum++;

        //aNodeData
        int beginIndex = aBvh->BegPrimitive(i);
        int endIndex = aBvh->EndPrimitive(i);
        qDebug() << " inn node, num:" << endIndex-beginIndex << endl;

        int aa = 0;

#if 0
// inner node.
const BVH_Vec3d& aP1 = aBvh->MinPoint(aNodeData.y());
const BVH_Vec3d& aP2 = aBvh->MaxPoint(aNodeData.y());

        const BVH_Vec3d& aQ1 = aBvh->MinPoint(aNodeData.z());
        const BVH_Vec3d& aQ2 = aBvh->MaxPoint(aNodeData.z());

        if (aP1.x() < aP2.x() && aP1.y() < aP2.y() && aP1.z() < aP2.z())
        {
            BRepPrimAPI_MakeBox aBoxMaker1(gp_Pnt(aP1.x(), aP1.y(), aP1.z()), gp_Pnt(aP2.x(), aP2.y(), aP2.z()));
            for (TopExp_Explorer edge(aBoxMaker1.Shape(), TopAbs_EDGE); edge.More(); edge.Next())
            {
                TopoDS_Shape edgeShape = edge.Current();
                Handle(AIS_Shape) h1 = new AIS_Shape(edgeShape);
                myAISContext->Display(h1, true);
                //qDebug() << i << "-make edge " << endl;
            }
        }

#endif
}

    else
    {
        leavesNodeNum++;

        int beginIndex = aBvh->BegPrimitive(i);
        int endIndex = aBvh->EndPrimitive(i);
        if ((endIndex - beginIndex) > leavesNumMax)
            leavesNumMax = endIndex - beginIndex;
        qDebug() << " leaves node, num:" << endIndex - beginIndex << endl;

#if 1
qDebug() << i << “-leaves” << endl;
int xVal = aNodeData.x();
// leaves node.
const BVH_Vec3d& aP1 = aBvh->MinPoint(i);//包围盒的点1
const BVH_Vec3d& aP2 = aBvh->MaxPoint(i);//包围盒的点2

        double len2 = (aP1.x() - aP2.x()) * (aP1.x() - aP2.x()) + (aP1.y() - aP2.y()) * (aP1.y() - aP2.y()) + (aP1.z() - aP2.z()) * (aP1.z() - aP2.z());
        int aa = 0;
        //if (aP1.x() < aP2.x() && aP1.y() < aP2.y() && aP1.z() < aP2.z())
        //{
        //    BRepPrimAPI_MakeBox aBoxMaker1(gp_Pnt(aP1.x(), aP1.y(), aP1.z()), gp_Pnt(aP2.x(), aP2.y(), aP2.z()));
        //    for (TopExp_Explorer edge(aBoxMaker1.Shape(), TopAbs_EDGE); edge.More(); edge.Next())
        //    {
        //        TopoDS_Shape edgeShape = edge.Current();
        //        Handle(AIS_Shape) h1 = new AIS_Shape(edgeShape);
        //        myAISContext->Display(h1, true);
        //        //qDebug() << i << "-make edge " << endl;
        //    }
        //}

#endif
}

    //myAISContext->Erase(hBox3,true);
}
qDebug() << leavesNodeNum << "-leaves node," << innNodeNum << " inn node" << endl;
qDebug() << " leaves node max num:" << leavesNumMax << endl;

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值