OCCT
OCCT copied to clipboard
BRepAlgoAPI_Common returns empty TopoDS_Compound for two faces visually intersecting
Description
BRepAlgoAPI_Common returns empty TopoDS_Compound for two faces visually intersecting
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:
Hello @dpasukhi. Any news on this issue?
Thanks
Hello. The issue is not planned for closest releases.