BRepExtrema_DistShapeShape()

Hello everyone,

     I'm new here and want to get some help,when I use the function BRepExtrema_DistShapeShape() to compute the mindistance of two Shape.One of them is a reduced robot model(TopoDS_Shape),another is an Artifact(TopoDS_Compound),at first ,the function was running fast,it spend approximate 100ms one time,but as time gose by,its speed will be more and more lower, I want to know why its speed get lower and how to promote its speed,maybe keep the initial speed will be ok.

    I'm sorry about my poor English,and I'm so appriciate if some can give me some advice.

    Thanks!

Kirill Gavrilov's picture

at first ,the function was running fast
but as time gose by,its speed will be more and more lower,

What do you mean "as time goes"? Function becomes slower at second / n-th call or after some changes in the shape (which then)?

su tianxiao's picture

Thank you for replying, when I get one distance of two this two shape ,I will tranlate the robot shape to a new location  and use the function once again.I repeat the process about 1k times. First 20 times is fast  and then become slower and slower.

Kirill Gavrilov's picture

If you are translating shape incrementally many times, then you may struggle with accumulated history in TopLoc_Location - depending on how new location is set.
Sharing the code showing how you locate the shape may reveal what might cause problems.

su tianxiao's picture

void occqtWidget::MoveShape(TopoDS_Shape& aLSObjects, gp_Vec& aVec) {
    gp_Trsf theTransformation = gp_Trsf();
    gp_Vec theVectorOfTranslation = aVec;
    theTransformation.SetTranslation(theVectorOfTranslation);
    BRepBuilderAPI_Transform myBRepTransformation = BRepBuilderAPI_Transform(aLSObjects, theTransformation, false);  
    aLSObjects = myBRepTransformation.Shape();
}
void occqtWidget::RotateShape(TopoDS_Shape& aLSObjects, gp_Ax1& axe, double& degree) {
    gp_Trsf theTransformation = gp_Trsf();
    theTransformation.SetRotation(axe, degree);
    BRepBuilderAPI_Transform myBRepTransformation = BRepBuilderAPI_Transform(aLSObjects, theTransformation, false);
    aLSObjects = myBRepTransformation.Shape();
}

Thanks a lot for your replying , I use this two function to tranlate my shape,whether this two function cause my problem?

Kirill Gavrilov's picture

Indeed, using BRepBuilderAPI_Transform in such way leads to continuous accumulation of transformations history:

void BRepBuilderAPI_Transform::Perform(const TopoDS_Shape& theS, const Standard_Boolean theCopy)
{
...
  myShape = theS.Moved (myLocation);
}

//! Multiplies the Shape location by thePosition.
void TopoDS_Shape::Move (const TopLoc_Location& thePosition)
{ myLocation = thePosition * myLocation; }

TopoDS_Shape::Moved() is designed in such a way that result TopLoc_Location preserves the history of all multiplications. This is intended behavior required to identify different TopoDS_Shape within hierarchy with shared instances, but it might be unexpected in case of trivial transformation.

Things to consider in your code:

  • Avoid incremental transformations when possible.
    This is not only causes additional issues with TopLoc_Location, but actually leads to additional error accumulated by floating point math.
    Store TopoDS_Shape with original location and apply final gp_Trsf to it instead of computing delta transformation at each step,
     
  • Use TopoDS_Shape::Located() with TopLoc_Location constructed from gp_Trsf instead of using tool BRepBuilderAPI_Transform, while applying trivial transformations (rotation/translation). gp_Trsf doesn't store the history of transformations, unlike TopLoc_Location:
    gp_Trsf theTransformation;
    gp_Trsf aNewTrsf = theTransformation * aLSObjects.Location();
    TopoDS_Shape aShape = aShape.Located (TopLoc_Location (aNewTrsf));

But this just answers only why your code might become slower and slower within many iterations doing similar actions.

su tianxiao's picture

I'm so appreciate about your help!We saved a lot of time because of your help.And my leader is so glad that say if you travel to China AnHui WuHu,  we will receive you warmly!: )

Mikhail Sazonov's picture

I suppose you simulate motion of shapes one relative the other. In this case (especially when one object becomes surrounded by the bounding box of another one) the increasing computation time is a usual deal. Indeed, this tool is not appropriate to use in such environment.

You can look at advanced component developed for this kind of computation -  Collision Detection.

su tianxiao's picture

Thank you. So how much is this advanced component developed.