occ - identify with given trafo (allows identifying multiple faces at once)

This commit is contained in:
mhochsteger@cerbsim.com 2021-12-14 12:16:03 +01:00
parent d7be2c8561
commit 44471fe649
5 changed files with 70 additions and 21 deletions

View File

@ -11,6 +11,22 @@ namespace netgen
return occ2ng( Handle(BRep_TVertex)::DownCast(shape)->Pnt() ); return occ2ng( Handle(BRep_TVertex)::DownCast(shape)->Pnt() );
} }
Transformation<3> occ2ng (const gp_Trsf & occ_trafo)
{
Transformation<3> trafo;
auto v = occ_trafo.TranslationPart();
auto m = occ_trafo.VectorialPart();
auto & tv = trafo.GetVector();
auto & tm = trafo.GetMatrix();
for(auto i : Range(3))
{
tv[i] = v.Coord(i+1);
for(auto k : Range(3))
tm(i,k) = m(i+1,k+1);
}
return trafo;
}
Box<3> GetBoundingBox( const TopoDS_Shape & shape ) Box<3> GetBoundingBox( const TopoDS_Shape & shape )
{ {
Bnd_Box bb; Bnd_Box bb;

View File

@ -9,6 +9,7 @@
#include <TopTools_IndexedMapOfShape.hxx> #include <TopTools_IndexedMapOfShape.hxx>
#include <TopoDS.hxx> #include <TopoDS.hxx>
#include <TopoDS_Vertex.hxx> #include <TopoDS_Vertex.hxx>
#include <gp_Trsf.hxx>
#include "meshing.hpp" #include "meshing.hpp"
@ -47,6 +48,8 @@ namespace netgen
return occ2ng (BRep_Tool::Pnt (v)); return occ2ng (BRep_Tool::Pnt (v));
} }
DLL_HEADER Transformation<3> occ2ng (const gp_Trsf & t);
inline gp_Pnt ng2occ (const Point<3> & p) inline gp_Pnt ng2occ (const Point<3> & p)
{ {
return gp_Pnt(p(0), p(1), p(2)); return gp_Pnt(p(0), p(1), p(2));

View File

@ -1940,12 +1940,19 @@ namespace netgen
return occ2ng( props.CentreOfMass() ); return occ2ng( props.CentreOfMass() );
} }
void OCCGeometry :: IdentifyEdges(const TopoDS_Shape & me, const TopoDS_Shape & you, string name, Identifications::ID_TYPE type) void OCCGeometry :: IdentifyEdges(const TopoDS_Shape & me, const TopoDS_Shape & you, string name, Identifications::ID_TYPE type, std::optional<gp_Trsf> opt_trafo)
{
Transformation<3> trafo;
if(opt_trafo)
trafo = occ2ng(*opt_trafo);
else
{ {
auto cme = GetCenter(me); auto cme = GetCenter(me);
auto cyou = GetCenter(you); auto cyou = GetCenter(you);
Transformation<3> trafo{cyou-cme}; trafo = Transformation<3>{cyou-cme};
identifications[me.TShape()].push_back( {me.TShape(), you.TShape(), Transformation<3>(cyou - cme), name, type} ); }
identifications[me.TShape()].push_back( {me.TShape(), you.TShape(), trafo, name, type} );
auto vme = GetVertices(me); auto vme = GetVertices(me);
auto vyou = GetVertices(you); auto vyou = GetVertices(you);
@ -1976,6 +1983,11 @@ namespace netgen
std::map<T_Shape, T_Shape> vmap; std::map<T_Shape, T_Shape> vmap;
auto verts_me = GetVertices(me); auto verts_me = GetVertices(me);
auto verts_you = GetVertices(you);
if(verts_me.size() != verts_you.size())
return false;
for (auto i : Range(verts_me.size())) for (auto i : Range(verts_me.size()))
{ {
auto s = verts_me[i].TShape(); auto s = verts_me[i].TShape();
@ -1987,7 +1999,7 @@ namespace netgen
} }
bool all_verts_mapped = true; bool all_verts_mapped = true;
for (auto vert : GetVertices(you)) for (auto vert : verts_you)
{ {
auto s = vert.TShape(); auto s = vert.TShape();
auto p = occ2ng(s); auto p = occ2ng(s);
@ -2006,14 +2018,31 @@ namespace netgen
return all_verts_mapped; return all_verts_mapped;
} }
void OCCGeometry :: IdentifyFaces(const TopoDS_Shape & solid, const TopoDS_Shape & me, const TopoDS_Shape & you, string name, Identifications::ID_TYPE type) void OCCGeometry :: IdentifyFaces(const TopoDS_Shape & solid, const TopoDS_Shape & me, const TopoDS_Shape & you, string name, Identifications::ID_TYPE type, std::optional<gp_Trsf> opt_trafo)
{
Transformation<3> trafo;
if(opt_trafo)
{
trafo = occ2ng(*opt_trafo);
}
else
{ {
auto cme = GetCenter(me); auto cme = GetCenter(me);
auto cyou = GetCenter(you); auto cyou = GetCenter(you);
Transformation<3> trafo(cyou-cme); trafo = Transformation<3>(cyou-cme);
}
identifications[me.TShape()].push_back auto faces_me = GetFaces(me);
(OCCIdentification { me.TShape(), you.TShape(), trafo, name, type }); auto faces_you = GetFaces(you);
for(auto face_me : faces_me)
for(auto face_you : faces_you)
{
if(!IsMappedShape(trafo, face_me, face_you))
continue;
identifications[face_me.TShape()].push_back
(OCCIdentification { face_me.TShape(), face_you.TShape(), trafo, name, type });
auto edges_me = GetEdges(me); auto edges_me = GetEdges(me);
auto edges_you = GetEdges(you); auto edges_you = GetEdges(you);
@ -2021,7 +2050,8 @@ namespace netgen
for (auto e_me : edges_me) for (auto e_me : edges_me)
for (auto e_you : edges_you) for (auto e_you : edges_you)
if(IsMappedShape(trafo, e_me, e_you)) if(IsMappedShape(trafo, e_me, e_you))
IdentifyEdges(e_me, e_you, name, type); IdentifyEdges(e_me, e_you, name, type, opt_trafo);
}
} }
void OCCParameters :: Print(ostream & ost) const void OCCParameters :: Print(ostream & ost) const

View File

@ -341,8 +341,8 @@ namespace netgen
bool ErrorInSurfaceMeshing (); bool ErrorInSurfaceMeshing ();
// void WriteOCC_STL(char * filename); // void WriteOCC_STL(char * filename);
static void IdentifyEdges(const TopoDS_Shape & me, const TopoDS_Shape & you, string name, Identifications::ID_TYPE type); static void IdentifyEdges(const TopoDS_Shape & me, const TopoDS_Shape & you, string name, Identifications::ID_TYPE type, std::optional<gp_Trsf> opt_trafo = nullopt);
static void IdentifyFaces(const TopoDS_Shape & solid,const TopoDS_Shape & me, const TopoDS_Shape & you, string name, Identifications::ID_TYPE type); static void IdentifyFaces(const TopoDS_Shape & solid,const TopoDS_Shape & me, const TopoDS_Shape & you, string name, Identifications::ID_TYPE type, std::optional<gp_Trsf> opt_trafo = nullopt);
private: private:
//bool FastProject (int surfi, Point<3> & ap, double& u, double& v) const; //bool FastProject (int surfi, Point<3> & ap, double& u, double& v) const;

View File

@ -1091,7 +1091,7 @@ DLL_HEADER void ExportNgOCCShapes(py::module &m)
}, py::arg("other"), py::arg("name"), py::arg("type")=Identifications::PERIODIC, "Identify shapes for periodic meshing") }, py::arg("other"), py::arg("name"), py::arg("type")=Identifications::PERIODIC, "Identify shapes for periodic meshing")
.def("Identify", OCCGeometry::IdentifyFaces, "Identify faces", .def("Identify", OCCGeometry::IdentifyFaces, "Identify faces",
py::arg("from"), py::arg("to"), py::arg("name"), py::arg("type")=Identifications::PERIODIC) py::arg("from"), py::arg("to"), py::arg("name"), py::arg("type")=Identifications::PERIODIC, py::arg("trafo")=nullopt)
.def("Distance", [](const TopoDS_Shape& self, .def("Distance", [](const TopoDS_Shape& self,
const TopoDS_Shape& other) const TopoDS_Shape& other)