OCCT icon indicating copy to clipboard operation
OCCT copied to clipboard

BRepAlgoAPI_Common returns empty TopoDS_Compound for two faces visually intersecting

Open GabrielJMS opened this issue 9 months ago • 2 comments

Description

BRepAlgoAPI_Common returns empty TopoDS_Compound for two faces visually intersecting

Image

Expected Behavior

It's expected to have a TopoDS_Edge that represents the intersection of the two faces.

Actual Behavior

Empty compund is returned when calling Shape()

Sample Code or DRAW Tcl Script

#include <TopoDS_Shape.hxx>
#include <BRepAlgoAPI_Common.hxx>
#include <BRep_Builder.hxx>
#include <BRepTools.hxx>
#include <stdexcept>
#include <chrono>


// Function to compute the intersection of two shapes
TopoDS_Shape IntersectShapes(const TopoDS_Shape& shape1, const TopoDS_Shape& shape2) {
    try {
        // Start measuring time
        std::cout << "Performing intersection" << std::endl;
        auto start = std::chrono::high_resolution_clock::now();
        // Perform the intersection operation
        BRepAlgoAPI_Common common(shape1, shape2);
        common.SetRunParallel(true);
        common.Build();
        // Stop measuring time
        auto end = std::chrono::high_resolution_clock::now();
        std::chrono::duration<double> duration = end - start;
        // Check if the operation was successful
        if (!common.IsDone()) {
            throw std::runtime_error("Intersection operation failed.");
        }

        std::cout << "Intersection took " << duration.count() << " seconds" << std::endl;
        // Return the resulting shape
        return common.Shape();
    }
    catch (const Standard_Failure& e) {
        throw std::runtime_error(std::string("OpenCASCADE error: ") + e.GetMessageString());
    }
    catch (const std::exception& e) {
        throw std::runtime_error(std::string("Error: ") + e.what());
    }
}


TopoDS_Shape ReadBRepFile(const std::string& filename) {
    BRep_Builder bb;
    TopoDS_Shape fromFile;
    if (!BRepTools::Read(fromFile, filename.c_str(), bb))
    {
        std::cout << "Failed to read BREP shape from file " << filename.c_str() << std::endl;
    }
    std::cout << "Successfully read BREP shape from file " << filename.c_str() << std::endl;
    return fromFile;
}


bool WriteBRepFile(const TopoDS_Shape& shape, const std::string& filePath)
{
    // Attempt to write the shape to the specified file path.
    if (!BRepTools::Write(shape, filePath.c_str()))
    {
        std::cerr << "Error: Unable to write BREP file to " << filePath << std::endl;
        return false;
    }
    return true;
}

int main(int argc, char** argv)
{

    TopoDS_Shape shape1 = ReadBRepFile("face_36_solid_1.brep");
    TopoDS_Shape shape2 = ReadBRepFile("face_13_solid_2.brep");

    TopoDS_Shape res = IntersectShapes(shape1, shape2);

    if (res.IsNull())
        return 1;

    std::string filepath = "result.brep";
    bool status = WriteBRepFile(res, filepath);
    if (status) {
        std::cout << "Result successfully saved in" << filepath;
    }

    return 0;
}

Operating System

Windows

Compiler

MSVC

Bitness

64-bit

OCCT Version

7.7

Additional Files

here the brep files for the two faces:

faces.zip

GabrielJMS avatar Apr 08 '25 13:04 GabrielJMS

Hello @dpasukhi. Any news on this issue?

Thanks

GabrielJMS avatar Jul 28 '25 14:07 GabrielJMS

Hello. The issue is not planned for closest releases.

dpasukhi avatar Jul 28 '25 16:07 dpasukhi