add vertex at intersection

karim

CAD community veteran
I have a situation where I want opencascade to add a vertex at the intersection of too lines when possible.
Code:
  auto a = gp_Pnt(0, 0, 0);
  auto b = gp_Pnt(100, 0, 0);
  auto c = gp_Pnt(50, -100, 0);
  auto d = gp_Pnt(50, 100, 0);
  auto edge1 = BRepBuilderAPI_MakeEdge(a, b);
  auto edge2 = BRepBuilderAPI_MakeEdge(c, d);

  TopoDS_Compound aRes;
  BRep_Builder aBuilder;
  aBuilder.MakeCompound (aRes);
  aBuilder.Add (aRes, edge1);
  aBuilder.Add (aRes, edge2);

now when I want to enumerate, the compound, I want to have 5 points instead of 4, How to achieve it. (In my application which is fem, there is another joint at the intersection, the program should identify it and treat it properly).
I wonder if it is possible with open cascade.
 

Quaoar

Administrator
Staff member
@karim I'd say, the easiest solution would be running the so-called General Fuse algorithm of OpenCascade. Before fuse:

1629486858530.png

After fuse:

1629486828254.png
I made this test in Analysis Situs, but it's fully implemented at the level of OpenCascade. Here is the snippet:

C++:
//! Performs Boolean General Fuse for the passed objects.
//! \param[in]  objects objects to fuse in non-manifold manner.
//! \param[in]  fuzz    fuzzy value to control the tolerance.
//! \param[out] API     Boolean algorithm to access history.
//! \param[in]  glue    whether gluing is requested.
TopoDS_Shape asiAlgo_Utils::BooleanGeneralFuse(const TopTools_ListOfShape& objects,
                                               const double                fuzz,
                                               BOPAlgo_Builder&            API,
                                               const bool                  glue)
{
  const bool bRunParallel = false;

  BOPAlgo_PaveFiller DSFiller;
  DSFiller.SetArguments(objects);
  DSFiller.SetRunParallel(bRunParallel);
  DSFiller.SetFuzzyValue(fuzz);
  DSFiller.Perform();
  bool hasErr = DSFiller.HasErrors();
  //
  if ( hasErr )
  {
    return TopoDS_Shape();
  }

  if ( glue )
    API.SetGlue(BOPAlgo_GlueFull);

  API.SetArguments(objects);
  API.SetRunParallel(bRunParallel);
  API.PerformWithFiller(DSFiller);
  hasErr = API.HasErrors();
  //
  if ( hasErr )
  {
    return TopoDS_Shape();
  }

  return API.Shape();
}
 
Top