Transfer in makeElementRefine

This commit is contained in:
Zheng, Lei
2024-02-01 13:07:15 -05:00
committed by bgbsww
parent 80deeb3ed7
commit c4b36466e8
5 changed files with 197 additions and 1 deletions

View File

@@ -1,6 +1,10 @@
#include <TopoDS.hxx>
#include <BRep_Tool.hxx>
#include <TopoDS_Edge.hxx>
#include "PreCompiled.h"
#include "TopoShapeMapper.h"
#include "Geometry.h"
namespace Part
{
@@ -96,4 +100,62 @@ void ShapeMapper::insert(MappingStatus status,
}
};
void GenericShapeMapper::init(const TopoShape &src, const TopoDS_Shape &dst)
{
for (TopExp_Explorer exp(dst, TopAbs_FACE); exp.More(); exp.Next()) {
const TopoDS_Shape &dstFace = exp.Current();
if (src.findShape(dstFace))
continue;
std::unordered_map<TopoDS_Shape, int> map;
bool found = false;
// Try to find a face in the src that shares at least two edges (or one
// closed edge) with dstFace.
// TODO: consider degenerative cases of two or more edges on the same line.
for (TopExp_Explorer it(dstFace, TopAbs_EDGE); it.More(); it.Next()) {
int idx = src.findShape(it.Current());
if (!idx)
continue;
TopoDS_Edge e = TopoDS::Edge(it.Current());
if(BRep_Tool::IsClosed(e))
{
// closed edge, one face is enough
TopoDS_Shape face = src.findAncestorShape(
src.getSubShape(TopAbs_EDGE,idx), TopAbs_FACE);
if (!face.IsNull()) {
this->insert(MappingStatus::Generated, face, dstFace);
found = true;
break;
}
continue;
}
for (auto &face : src.findAncestorsShapes(src.getSubShape(TopAbs_EDGE,idx), TopAbs_FACE)) {
int &cnt = map[face];
if (++cnt == 2) {
this->insert(MappingStatus::Generated, face, dstFace);
found = true;
break;
}
if (found)
break;
}
}
if (found) continue;
// if no face matches, try search by geometry surface
std::unique_ptr<Geometry> g(Geometry::fromShape(dstFace));
if (!g) continue;
for (auto &v : map) {
std::unique_ptr<Geometry> g2(Geometry::fromShape(v.first));
if (g2 && g2->isSame(*g,1e-7,1e-12)) {
this->insert(MappingStatus::Generated, v.first, dstFace);
break;
}
}
}
}
} // namespace Part