Fri, 11/29/2024 - 21:09
Forums:
I have following code for reading shape from file and then using the functionality of ShapeAnalysis_FreeBounds::ConnectEdgesToWires to get a single wire from the edges. In my application, I am not reading these edges from file but they are part of a step file which are 'CUTTING EDGE LINE' edges. I have created minimum sample for this post by reading the edges that I dumped from my application. The issue is that I am not getting one wire but getting 5 wires for 5 edges even though when I see them in viewer, they look like connected. Any help in understanding where my expectations are not correct? I have attached the input wires in the zip and attached the image showing edges in viewer.
#pragma once
#include <vector>
#include <string>
#include <BRep_Builder.hxx>
#include <BRepTools.hxx>
#include <TopoDS.hxx>
#include <TopTools_HSequenceOfShape.hxx>
#include <TopoDS_Edge.hxx>
#include <ShapeAnalysis_FreeBounds.hxx>
std::vector<std::string> fileNames;
std::vector<TopoDS_Wire> WiresFromEdges()
{
std::vector<TopoDS_Wire> wires;
fileNames.push_back("D:\\Work\\OCCT\\Data\\edge0.shape");
fileNames.push_back("D:\\Work\\OCCT\\Data\\edge1.shape");
fileNames.push_back("D:\\Work\\OCCT\\Data\\edge2.shape");
fileNames.push_back("D:\\Work\\OCCT\\Data\\edge3.shape");
fileNames.push_back("D:\\Work\\OCCT\\Data\\edge4.shape");
Handle(TopTools_HSequenceOfShape) anEdges = new TopTools_HSequenceOfShape;
for (size_t i = 0; i < fileNames.size(); i++)
{
BRep_Builder bb;
TopoDS_Shape shape;
if (!BRepTools::Read(shape, fileNames[i].c_str(), bb))
{
std::cout << "Error reading file " << fileNames[i] << std::endl;
return wires;
}
else
{
anEdges->Append(shape);
}
}
if (anEdges->Length() <= 0)
return wires;
Handle(TopTools_HSequenceOfShape) wiresSeq;
ShapeAnalysis_FreeBounds::ConnectEdgesToWires(anEdges, Precision::Confusion(),
Standard_True, wiresSeq);
for (Standard_Integer iw = 1; iw <= wiresSeq->Length(); iw++)
{
wires.emplace_back(TopoDS::Wire(wiresSeq->Value(iw)));
}
return wires;
}