mirror of
https://github.com/NGSolve/netgen.git
synced 2024-12-25 05:20:34 +05:00
Merge branch 'occ_gp_gtrsf' into 'master'
[occ] gp_GTrsf for anisotropic trafos See merge request jschoeberl/netgen!493
This commit is contained in:
commit
1de4d6e1e5
@ -12,7 +12,7 @@ namespace netgen
|
|||||||
: tface(dshape.TShape()),
|
: tface(dshape.TShape()),
|
||||||
face(TopoDS::Face(dshape))
|
face(TopoDS::Face(dshape))
|
||||||
{
|
{
|
||||||
BRepGProp::LinearProperties(face, props);
|
BRepGProp::SurfaceProperties (dshape, props);
|
||||||
bbox = ::netgen::GetBoundingBox(face);
|
bbox = ::netgen::GetBoundingBox(face);
|
||||||
|
|
||||||
surface = BRep_Tool::Surface(face);
|
surface = BRep_Tool::Surface(face);
|
||||||
|
@ -27,6 +27,22 @@ namespace netgen
|
|||||||
return trafo;
|
return trafo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Transformation<3> occ2ng (const gp_GTrsf & 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;
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
#ifndef FILE_OCC_UTILS_INCLUDED
|
#ifndef FILE_OCC_UTILS_INCLUDED
|
||||||
#define FILE_OCC_UTILS_INCLUDED
|
#define FILE_OCC_UTILS_INCLUDED
|
||||||
|
|
||||||
|
#include <variant>
|
||||||
|
|
||||||
#include <BRepGProp.hxx>
|
#include <BRepGProp.hxx>
|
||||||
#include <BRep_Tool.hxx>
|
#include <BRep_Tool.hxx>
|
||||||
#include <GProp_GProps.hxx>
|
#include <GProp_GProps.hxx>
|
||||||
@ -10,6 +12,7 @@
|
|||||||
#include <TopoDS.hxx>
|
#include <TopoDS.hxx>
|
||||||
#include <TopoDS_Vertex.hxx>
|
#include <TopoDS_Vertex.hxx>
|
||||||
#include <gp_Trsf.hxx>
|
#include <gp_Trsf.hxx>
|
||||||
|
#include <gp_GTrsf.hxx>
|
||||||
|
|
||||||
#include "meshing.hpp"
|
#include "meshing.hpp"
|
||||||
|
|
||||||
@ -49,6 +52,13 @@ namespace netgen
|
|||||||
}
|
}
|
||||||
|
|
||||||
DLL_HEADER Transformation<3> occ2ng (const gp_Trsf & t);
|
DLL_HEADER Transformation<3> occ2ng (const gp_Trsf & t);
|
||||||
|
DLL_HEADER Transformation<3> occ2ng (const gp_GTrsf & t);
|
||||||
|
inline Transformation<3> occ2ng (const variant<gp_Trsf, gp_GTrsf> & t)
|
||||||
|
{
|
||||||
|
if(auto t1 = get_if<gp_Trsf>(&t))
|
||||||
|
return occ2ng(*t1);
|
||||||
|
return occ2ng(get<gp_GTrsf>(t));
|
||||||
|
}
|
||||||
|
|
||||||
inline gp_Pnt ng2occ (const Point<3> & p)
|
inline gp_Pnt ng2occ (const Point<3> & p)
|
||||||
{
|
{
|
||||||
|
@ -1955,13 +1955,6 @@ namespace netgen
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Point<3> GetCenter(const TopoDS_Shape & shape)
|
|
||||||
{
|
|
||||||
GProp_GProps props;
|
|
||||||
BRepGProp::LinearProperties(shape, props);
|
|
||||||
return occ2ng( props.CentreOfMass() );
|
|
||||||
}
|
|
||||||
|
|
||||||
bool IsMappedShape(const Transformation<3> & trafo, const TopoDS_Shape & me, const TopoDS_Shape & you)
|
bool IsMappedShape(const Transformation<3> & trafo, const TopoDS_Shape & me, const TopoDS_Shape & you)
|
||||||
{
|
{
|
||||||
if(me.ShapeType() != you.ShapeType()) return false;
|
if(me.ShapeType() != you.ShapeType()) return false;
|
||||||
@ -1971,8 +1964,8 @@ namespace netgen
|
|||||||
BRepBndLib::Add(you, bbox);
|
BRepBndLib::Add(you, bbox);
|
||||||
BoxTree<3> tree( occ2ng(bbox.CornerMin()), occ2ng(bbox.CornerMax()) );
|
BoxTree<3> tree( occ2ng(bbox.CornerMin()), occ2ng(bbox.CornerMax()) );
|
||||||
|
|
||||||
Point<3> c_me = GetCenter(me);
|
Point<3> c_me = occ2ng(Center(me));
|
||||||
Point<3> c_you = GetCenter(you);
|
Point<3> c_you = occ2ng(Center(you));
|
||||||
if(tree.GetTolerance() < Dist(trafo(c_me), c_you))
|
if(tree.GetTolerance() < Dist(trafo(c_me), c_you))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -2010,17 +2003,17 @@ namespace netgen
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Identify(const TopoDS_Shape & me, const TopoDS_Shape & you, string name, Identifications::ID_TYPE type, std::optional<gp_Trsf> opt_trafo)
|
void Identify(const TopoDS_Shape & me, const TopoDS_Shape & you, string name, Identifications::ID_TYPE type, std::optional<std::variant<gp_Trsf, gp_GTrsf>> opt_trafo)
|
||||||
{
|
{
|
||||||
gp_Trsf trafo;
|
Transformation<3> trafo;
|
||||||
if(opt_trafo)
|
if(opt_trafo)
|
||||||
{
|
{
|
||||||
trafo = *opt_trafo;
|
trafo = occ2ng(*opt_trafo);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
auto v = GetCenter(you) - GetCenter(me);
|
auto v = occ2ng(Center(you)) - occ2ng(Center(me));
|
||||||
trafo.SetTranslation(gp_Vec(v[0], v[1], v[2]));
|
trafo = Transformation<3>(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
ListOfShapes list_me, list_you;
|
ListOfShapes list_me, list_you;
|
||||||
@ -2029,10 +2022,8 @@ namespace netgen
|
|||||||
Identify(list_me, list_you, name, type, trafo);
|
Identify(list_me, list_you, name, type, trafo);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Identify(const ListOfShapes & me, const ListOfShapes & you, string name, Identifications::ID_TYPE type, gp_Trsf occ_trafo)
|
void Identify(const ListOfShapes & me, const ListOfShapes & you, string name, Identifications::ID_TYPE type, Transformation<3> trafo)
|
||||||
{
|
{
|
||||||
Transformation<3> trafo = occ2ng(occ_trafo);
|
|
||||||
|
|
||||||
ListOfShapes id_me;
|
ListOfShapes id_me;
|
||||||
ListOfShapes id_you;
|
ListOfShapes id_you;
|
||||||
|
|
||||||
|
@ -351,8 +351,8 @@ namespace netgen
|
|||||||
//bool FastProject (int surfi, Point<3> & ap, double& u, double& v) const;
|
//bool FastProject (int surfi, Point<3> & ap, double& u, double& v) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
void Identify(const ListOfShapes & me, const ListOfShapes & you, string name, Identifications::ID_TYPE type, gp_Trsf occ_trafo);
|
void Identify(const ListOfShapes & me, const ListOfShapes & you, string name, Identifications::ID_TYPE type, Transformation<3> trafo);
|
||||||
void Identify(const TopoDS_Shape & me, const TopoDS_Shape & you, string name, Identifications::ID_TYPE type, std::optional<gp_Trsf> opt_trafo);
|
void Identify(const TopoDS_Shape & me, const TopoDS_Shape & you, string name, Identifications::ID_TYPE type, std::optional<std::variant<gp_Trsf, gp_GTrsf>> opt_trafo);
|
||||||
|
|
||||||
|
|
||||||
void PrintContents (OCCGeometry * geom);
|
void PrintContents (OCCGeometry * geom);
|
||||||
|
@ -9,11 +9,13 @@
|
|||||||
#include "occgeom.hpp"
|
#include "occgeom.hpp"
|
||||||
|
|
||||||
#include <BRepBuilderAPI_Transform.hxx>
|
#include <BRepBuilderAPI_Transform.hxx>
|
||||||
|
#include <BRepBuilderAPI_GTransform.hxx>
|
||||||
#include <gp_Ax1.hxx>
|
#include <gp_Ax1.hxx>
|
||||||
#include <gp_Ax2.hxx>
|
#include <gp_Ax2.hxx>
|
||||||
#include <gp_Ax2d.hxx>
|
#include <gp_Ax2d.hxx>
|
||||||
#include <gp_Ax3.hxx>
|
#include <gp_Ax3.hxx>
|
||||||
#include <gp_Trsf.hxx>
|
#include <gp_Trsf.hxx>
|
||||||
|
#include <gp_GTrsf.hxx>
|
||||||
|
|
||||||
using namespace netgen;
|
using namespace netgen;
|
||||||
|
|
||||||
@ -264,7 +266,27 @@ DLL_HEADER void ExportNgOCCBasic(py::module &m)
|
|||||||
}), py::arg("p")=gp_Pnt2d(0,0), py::arg("d")=gp_Dir2d(1,0))
|
}), py::arg("p")=gp_Pnt2d(0,0), py::arg("d")=gp_Dir2d(1,0))
|
||||||
;
|
;
|
||||||
|
|
||||||
|
py::class_<gp_GTrsf>(m, "gp_GTrsf")
|
||||||
|
.def(py::init([](const std::vector<double>& mat,
|
||||||
|
const std::vector<double>& vec)
|
||||||
|
{
|
||||||
|
if(mat.size() != 9)
|
||||||
|
throw Exception("Need 9 matrix values for construction of gp_GTrsf");
|
||||||
|
if(vec.size() != 3)
|
||||||
|
throw Exception("Need 3 vector values for construction of gp_GTrsf");
|
||||||
|
gp_GTrsf trafo;
|
||||||
|
trafo.SetVectorialPart({ mat[0], mat[1], mat[2],
|
||||||
|
mat[3], mat[4], mat[5],
|
||||||
|
mat[6], mat[7], mat[8] });
|
||||||
|
trafo.SetTranslationPart( { vec[0], vec[1], vec[2] });
|
||||||
|
return trafo;
|
||||||
|
}), py::arg("mat"), py::arg("vec") = std::vector<double>{ 0., 0., 0. })
|
||||||
|
.def("__call__", [] (gp_GTrsf & trafo, const TopoDS_Shape & shape) {
|
||||||
|
BRepBuilderAPI_GTransform builder(shape, trafo, true);
|
||||||
|
PropagateProperties(builder, shape, occ2ng(trafo));
|
||||||
|
return builder.Shape();
|
||||||
|
})
|
||||||
|
;
|
||||||
|
|
||||||
py::class_<gp_Trsf>(m, "gp_Trsf")
|
py::class_<gp_Trsf>(m, "gp_Trsf")
|
||||||
.def(py::init<>())
|
.def(py::init<>())
|
||||||
|
@ -1098,7 +1098,7 @@ DLL_HEADER void ExportNgOCCShapes(py::module &m)
|
|||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
.def("Identify", py::overload_cast<const TopoDS_Shape &, const TopoDS_Shape &, string, Identifications::ID_TYPE, std::optional<gp_Trsf>>(&Identify),
|
.def("Identify", py::overload_cast<const TopoDS_Shape &, const TopoDS_Shape &, string, Identifications::ID_TYPE, std::optional<std::variant<gp_Trsf, gp_GTrsf>>>(&Identify),
|
||||||
py::arg("other"), py::arg("name"),
|
py::arg("other"), py::arg("name"),
|
||||||
py::arg("type")=Identifications::PERIODIC, py::arg("trafo")=nullopt,
|
py::arg("type")=Identifications::PERIODIC, py::arg("trafo")=nullopt,
|
||||||
"Identify shapes for periodic meshing")
|
"Identify shapes for periodic meshing")
|
||||||
@ -1689,10 +1689,16 @@ DLL_HEADER void ExportNgOCCShapes(py::module &m)
|
|||||||
OCCGeometry::global_shape_properties[shape.TShape()].quad_dominated = quad_dominated;
|
OCCGeometry::global_shape_properties[shape.TShape()].quad_dominated = quad_dominated;
|
||||||
})
|
})
|
||||||
|
|
||||||
.def("Identify", py::overload_cast<const ListOfShapes&, const ListOfShapes&, string, Identifications::ID_TYPE, gp_Trsf>(&Identify),
|
.def("Identify", [](const ListOfShapes& me,
|
||||||
py::arg("other"), py::arg("name"),
|
const ListOfShapes& other,
|
||||||
py::arg("type")=Identifications::PERIODIC, py::arg("trafo"),
|
string name,
|
||||||
"Identify shapes for periodic meshing")
|
Identifications::ID_TYPE type,
|
||||||
|
std::variant<gp_Trsf, gp_GTrsf> trafo)
|
||||||
|
{
|
||||||
|
Identify(me, other, name, type, occ2ng(trafo));
|
||||||
|
}, py::arg("other"), py::arg("name"),
|
||||||
|
py::arg("type")=Identifications::PERIODIC, py::arg("trafo"),
|
||||||
|
"Identify shapes for periodic meshing")
|
||||||
|
|
||||||
;
|
;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user