Skip to content

Large memory consumption in BOPAlgo_PaveFiller #800

@lucacarniato

Description

@lucacarniato

Description

I am attempting to perform a boolean cut operation between two TopoDS_Shape shapes using the following setup:

  • Left-hand side (lhs): A single solid shape.
  • Right-hand side (rhs): A compound consisting of 127 disconnected shapes.

The goal is to subtract the rhs from the lhs. The result is a new shape composed of 239 sub-shapes, representing the holes and gaps introduced by the rhs into the lhs.

The two compounds share several coplanar faces, which may influence the behavior of the boolean operation.

Expected Behavior

Memory consumption should remain within reasonable limits and not spike excessively during the operation.

Actual Behavior

During execution, there is a significant spike in memory usage during the call to pave_filler.Perform()
(see attached image).

Image
### Sample Code or DRAW Tcl Script

#include <BOPAlgo_CellsBuilder.hxx>
#include <BOPAlgo_PaveFiller.hxx>
#include <BRepBndLib.hxx>
#include <BRepTools.hxx>
#include <BRep_Builder.hxx>
#include <Bnd_Box.hxx>

#include <GeomAPI_ProjectPointOnCurve.hxx>
#include <IntTools_Context.hxx>
#include <NCollection_IncAllocator.hxx>
#include <ShapeUpgrade_UnifySameDomain.hxx>

#include <TopExp_Explorer.hxx>

namespace {

std::pair<TopoDS_Shape, TopoDS_Shape> cut(const TopoDS_Shape &lhs, const TopoDS_Shape &rhs)
{
  BOPAlgo_PaveFiller pave_filler;

  TopTools_ListOfShape arguments;
  arguments.Append(lhs);
  arguments.Append(rhs);
  pave_filler.SetArguments(arguments);

  std::cout << "start pave filler perform" << std::endl;
  pave_filler.Perform();
  std::cout << "end pave filler perform" << std::endl;

  if (pave_filler.HasErrors())
  {
    std::ostringstream oss;
    pave_filler.DumpErrors(oss);
  }

  if (pave_filler.HasWarnings())
  {
    std::cerr << std::endl;
    pave_filler.DumpWarnings(std::cerr);
    std::cerr << std::endl;
  }

  BOPAlgo_CellsBuilder cells_builder;
  cells_builder.SetToFillHistory(Standard_False);
  cells_builder.SetCheckInverted(Standard_False);
  cells_builder.AddArgument(lhs);
  cells_builder.AddArgument(rhs);
  cells_builder.PerformWithFiller(pave_filler);

  TopoDS_Shape cut_shape;
  {
    TopTools_ListOfShape take, avoid;
    cells_builder.RemoveAllFromResult();
    take.Append(lhs);
    avoid.Append(rhs);
    cells_builder.AddToResult(take, avoid, 0, Standard_False);
    cut_shape = cells_builder.Shape();
  }

  TopoDS_Shape common_shape;
  {
    TopTools_ListOfShape take, avoid;
    cells_builder.RemoveAllFromResult();
    take.Append(lhs);
    take.Append(rhs);
    cells_builder.AddToResult(take, avoid, 0, Standard_False);
    common_shape = cells_builder.Shape();
  }

  return std::make_pair(cut_shape, common_shape);
}
} // namespace

int main()
{
  TopoDS_Shape lhs;
  BRep_Builder builder;
  const char *lhs_filename = "/path/to/lhs.brep";

  if (!BRepTools::Read(lhs, lhs_filename, builder))
  {
    std::cerr << "Failed to read " << lhs_filename << std::endl;
  }

  TopoDS_Shape rhs;
  const char *rhs_filename = "/path/to/rhs.brep";
  if (!BRepTools::Read(rhs, rhs_filename, builder))
  {
    std::cerr << "Failed to read " << rhs_filename << std::endl;
  }

  const auto [cut_shape, common_shape] = cut(lhs, rhs);

  return 0;
}

Operating System

Linux

Compiler

GCC

Bitness

64-bit

OCCT Version

7.9

Additional Files

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    0. NewThe issue was created, but not updated by maintainer. Waiting for updates labels and categories2. BugSomething isn't working

    Type

    No type

    Projects

    Status

    Closed

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions