FEM: add getNodesBySolid()
Conflicts: src/Mod/Fem/App/FemMesh.cpp
This commit is contained in:
parent
52ad0bcc9d
commit
0c55f927f5
|
@ -524,6 +524,45 @@ std::map<int, int> FemMesh::getccxVolumesByFace(const TopoDS_Face &face) const
|
|||
return result;
|
||||
}
|
||||
|
||||
std::set<int> FemMesh::getNodesBySolid(const TopoDS_Solid &solid) const
|
||||
{
|
||||
std::set<int> result;
|
||||
|
||||
Bnd_Box box;
|
||||
BRepBndLib::Add(solid, box);
|
||||
// limit where the mesh node belongs to the solid:
|
||||
double limit = box.SquareExtent()/10000.0;
|
||||
//double limit = BRep_Tool::Tolerance(solid); // does not compile --> no matching function for call to 'BRep_Tool::Tolerance(const TopoDS_Solid&)'
|
||||
box.Enlarge(limit);
|
||||
|
||||
// get the current transform of the FemMesh
|
||||
const Base::Matrix4D Mtrx(getTransform());
|
||||
|
||||
SMDS_NodeIteratorPtr aNodeIter = myMesh->GetMeshDS()->nodesIterator();
|
||||
while (aNodeIter->more()) {
|
||||
const SMDS_MeshNode* aNode = aNodeIter->next();
|
||||
Base::Vector3d vec(aNode->X(),aNode->Y(),aNode->Z());
|
||||
// Apply the matrix to hold the BoundBox in absolute space.
|
||||
vec = Mtrx * vec;
|
||||
|
||||
if (!box.IsOut(gp_Pnt(vec.x,vec.y,vec.z))) {
|
||||
// create a vertex
|
||||
BRepBuilderAPI_MakeVertex aBuilder(gp_Pnt(vec.x,vec.y,vec.z));
|
||||
TopoDS_Shape s = aBuilder.Vertex();
|
||||
// measure distance
|
||||
BRepExtrema_DistShapeShape measure(solid,s);
|
||||
measure.Perform();
|
||||
if (!measure.IsDone() || measure.NbSolution() < 1)
|
||||
continue;
|
||||
|
||||
if (measure.Value() < limit)
|
||||
result.insert(aNode->GetID());
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
std::set<int> FemMesh::getNodesByFace(const TopoDS_Face &face) const
|
||||
{
|
||||
std::set<int> result;
|
||||
|
|
|
@ -39,6 +39,7 @@ class TopoDS_Shape;
|
|||
class TopoDS_Face;
|
||||
class TopoDS_Edge;
|
||||
class TopoDS_Vertex;
|
||||
class TopoDS_Solid;
|
||||
|
||||
namespace Fem
|
||||
{
|
||||
|
@ -87,6 +88,8 @@ public:
|
|||
//@{
|
||||
/// retrieving by region growing
|
||||
std::set<long> getSurfaceNodes(long ElemId, short FaceId, float Angle=360)const;
|
||||
/// retrieving by solid
|
||||
std::set<int> getNodesBySolid(const TopoDS_Solid &solid) const;
|
||||
/// retrieving by face
|
||||
std::set<int> getNodesByFace(const TopoDS_Face &face) const;
|
||||
/// retrieving by edge
|
||||
|
|
|
@ -99,6 +99,11 @@
|
|||
<UserDocu>Get the node position vector by an Node-ID</UserDocu>
|
||||
</Documentation>
|
||||
</Methode>
|
||||
<Methode Name="getNodesBySolid" Const="true">
|
||||
<Documentation>
|
||||
<UserDocu>Return a list of node IDs which belong to a TopoSolid</UserDocu>
|
||||
</Documentation>
|
||||
</Methode>
|
||||
<Methode Name="getNodesByFace" Const="true">
|
||||
<Documentation>
|
||||
<UserDocu>Return a list of node IDs which belong to a TopoFace</UserDocu>
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
#include <Base/QuantityPy.h>
|
||||
|
||||
#include <Mod/Part/App/TopoShapePy.h>
|
||||
#include <Mod/Part/App/TopoShapeSolidPy.h>
|
||||
#include <Mod/Part/App/TopoShapeFacePy.h>
|
||||
#include <Mod/Part/App/TopoShapeEdgePy.h>
|
||||
#include <Mod/Part/App/TopoShapeVertexPy.h>
|
||||
|
@ -611,6 +612,34 @@ PyObject* FemMeshPy::getNodeById(PyObject *args)
|
|||
}
|
||||
}
|
||||
|
||||
PyObject* FemMeshPy::getNodesBySolid(PyObject *args)
|
||||
{
|
||||
PyObject *pW;
|
||||
if (!PyArg_ParseTuple(args, "O!", &(Part::TopoShapeSolidPy::Type), &pW))
|
||||
return 0;
|
||||
|
||||
try {
|
||||
const TopoDS_Shape& sh = static_cast<Part::TopoShapeSolidPy*>(pW)->getTopoShapePtr()->_Shape;
|
||||
const TopoDS_Solid& fc = TopoDS::Solid(sh);
|
||||
if (sh.IsNull()) {
|
||||
PyErr_SetString(Base::BaseExceptionFreeCADError, "Solid is empty");
|
||||
return 0;
|
||||
}
|
||||
Py::List ret;
|
||||
std::set<int> resultSet = getFemMeshPtr()->getNodesBySolid(fc);
|
||||
for (std::set<int>::const_iterator it = resultSet.begin();it!=resultSet.end();++it)
|
||||
ret.append(Py::Int(*it));
|
||||
|
||||
return Py::new_reference_to(ret);
|
||||
|
||||
}
|
||||
catch (Standard_Failure) {
|
||||
Handle_Standard_Failure e = Standard_Failure::Caught();
|
||||
PyErr_SetString(Base::BaseExceptionFreeCADError, e->GetMessageString());
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
PyObject* FemMeshPy::getNodesByFace(PyObject *args)
|
||||
{
|
||||
PyObject *pW;
|
||||
|
|
Loading…
Reference in New Issue
Block a user