Skip to content

Commit

Permalink
FEM: add getNodesBySolid()
Browse files Browse the repository at this point in the history
Conflicts:
	src/Mod/Fem/App/FemMesh.cpp
  • Loading branch information
berndhahnebach authored and yorikvanhavre committed Nov 7, 2015
1 parent 52ad0bc commit 0c55f92
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/Mod/Fem/App/FemMesh.cpp
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/Mod/Fem/App/FemMesh.h
Expand Up @@ -39,6 +39,7 @@ class TopoDS_Shape;
class TopoDS_Face;
class TopoDS_Edge;
class TopoDS_Vertex;
class TopoDS_Solid;

namespace Fem
{
Expand Down Expand Up @@ -87,6 +88,8 @@ class AppFemExport FemMesh : public Data::ComplexGeoData
//@{
/// 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
Expand Down
5 changes: 5 additions & 0 deletions src/Mod/Fem/App/FemMeshPy.xml
Expand Up @@ -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>
Expand Down
29 changes: 29 additions & 0 deletions src/Mod/Fem/App/FemMeshPyImp.cpp
Expand Up @@ -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>
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 0c55f92

Please sign in to comment.