How to move the BVH?

Forums: 

Dear developer:
In my project, there are 6 shapes. And I try to detect the collide sitituaiton in animation. One shape is fixed, and other shapes are keep moving. Each shape have a BVH_Box. After shapes moved, I don't want to recompute the shape's BVH, the cost is expensive. I want to apply the gp_Trsf of the shape to change the postion of BVH_Box. Is this can do? If yes, how?

gkv311 n's picture

BVH_Box defines an Axes-Aligned Bounding Box (AABB). Transformed AABB could be computed as new AABB based on transformed 8 corners of original AABB (see Bnd_Box::Transformed(), for example) - it is not the same as computing AABB from shape at new location (transformed AABB will be larger and less efficient.

Normally, one would not transform AABB or BVH, but rather implement traverse that would consider transformation in traversal math.

wu xin's picture

Thanks for reply. I tried this, such as:

Standard_Boolean FaceFaceDis::Accept(const Standard_Integer theIndex1,
    const Standard_Integer theIndex2)
{
    const std::vector<BVH_Vec3d>& aTri1 = myBVHSet1->Element(theIndex1);
    const std::vector<BVH_Vec3d>& aTri2 = myBVHSet2->Element(theIndex2);

    gp_Pnt pnt11(aTri1.at(0).x(), aTri1.at(0).y(), aTri1.at(0).z());
    gp_Pnt pnt12(aTri1.at(1).x(), aTri1.at(1).y(), aTri1.at(1).z());
    gp_Pnt pnt13(aTri1.at(2).x(), aTri1.at(2).y(), aTri1.at(2).z());
    pnt11 = pnt11.Transformed(_toolTrsf);
    pnt12 = pnt12.Transformed(_toolTrsf);
    pnt13 = pnt13.Transformed(_toolTrsf);
    const BVH_Vec3d newTri11(pnt11.X(), pnt11.Y(), pnt11.Z());
    const BVH_Vec3d newTri12(pnt12.X(), pnt12.Y(), pnt12.Z());
    const BVH_Vec3d newTri13(pnt13.X(), pnt13.Y(), pnt13.Z());

    gp_Pnt pnt21(aTri2.at(0).x(), aTri2.at(0).y(), aTri2.at(0).z());
    gp_Pnt pnt22(aTri2.at(1).x(), aTri2.at(1).y(), aTri2.at(1).z());
    gp_Pnt pnt23(aTri2.at(2).x(), aTri2.at(2).y(), aTri2.at(2).z());
    pnt21 = pnt21.Transformed(_robotTrsf);
    pnt22 = pnt22.Transformed(_robotTrsf);
    pnt23 = pnt23.Transformed(_robotTrsf);
    const BVH_Vec3d newTri21(pnt21.X(), pnt21.Y(), pnt21.Z());
    const BVH_Vec3d newTri22(pnt22.X(), pnt22.Y(), pnt22.Z());
    const BVH_Vec3d newTri23(pnt23.X(), pnt23.Y(), pnt23.Z());

    Standard_Real aDistance = CalculateTriangleDistance({ newTri11, newTri12,newTri13 }, { newTri21, newTri22,newTri23 });
    if (aDistance < myDistance)
    {
        myDistance = aDistance;
        return Standard_True;
    }
    return Standard_False;
}

Am I right?