BRepExtrema_DistShapeShape doesn't return all shapes

Hi everyone, I implemented a very simple example where two boxes were added on the scene and I tried to find the distance between them. Considering the one box has a small displacement relative to another one and it's supposed to get the distance = 0.2. And the result is 0.2 but when I tried to look through all elements that could be obtained by calling "SupportTypeShape1/2" I didn't find there any faces only vertices. Do somebody know it's a normal behavior for the algorithm or we should obtain in this case a pair of two faces among all rest results.

TEST(DistanceOperations, Two_Boxes_Test_OCCT_FUNCTION) {
  auto box1 = BRepPrimAPI_MakeBox(
    gp_Pnt(0.0, 0.0, 0.0),
    gp_Pnt(10.0, 2.0, 10.0));
  auto box2 = BRepPrimAPI_MakeBox(
    gp_Pnt(0.0, 2.1, 0.0),
    gp_Pnt(10.0, 4.0, 10.0));
  BRepExtrema_DistShapeShape dist(box1, box2);
  ASSERT_TRUE(dist.Perform());
  bool found = false;
  for (Standard_Integer index = 1; index < dist.NbSolution(); index++) {
    if (dist.SupportTypeShape1(index) == BRepExtrema_SupportType::BRepExtrema_IsInFace &&
      dist.SupportTypeShape2(index) == BRepExtrema_SupportType::BRepExtrema_IsInFace) {
      found = true;
    }
    std::cerr << (int)dist.SupportTypeShape1(index) << std::endl;
    std::cerr << (int)dist.SupportTypeShape2(index) << std::endl;
  }
  ASSERT_TRUE(found);
}
Serov Igor's picture

I checked the source code "BRepExtrema_DistanceSS::Perform" for faces and realized that for parallel faces it isn't possible to obtain u,v coordinates for a couple of vertices located on these faces and which represent the closest points. If it's like I've described then it's not possible to obtain two parallel faces as a candidate containing minimal distance.
In this case, is there another solution for obtaining the minimal distance between shapes considering only faces?

Mikhail Sazonov's picture

The algorithm DistShapeShape always tries to return subshapes of the lowest dimension. If the distance between a pair of faces is not less than the distance between some vertices belonging to these faces then faces are not returned.

You always can get faces containing the vertex solutions (using child-parents mapping), iterate them and make what you want.

Serov Igor's picture

I understood your point, thanks for the solution.

Guido van Hilst not specified's picture

Don't know if this fixes it but you miss the last solution in the for loop:

should it not be: index <= dist.NbSolution(); OCC is 1 based

Serov Igor's picture

It doesn't matter considering the Michail's answer above.