Skip to content

Commit

Permalink
Mesh: [skip-ci] add method to get curvature info directly from mesh o…
Browse files Browse the repository at this point in the history
…bject
  • Loading branch information
wwmayer committed Jan 30, 2020
1 parent 6d109cd commit b0902db
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/Mod/Mesh/App/MeshPy.xml
Expand Up @@ -491,7 +491,15 @@ mesh.getSegmentsByCurvature([c,p])
</UserDocu>
</Documentation>
</Methode>
<Attribute Name="Points" ReadOnly="true">
<Methode Name="getCurvaturePerVertex" Const="true">
<Documentation>
<UserDocu>
getCurvaturePerVertex() -> list
The items in the list contains minimum and maximum curvature with their directions
</UserDocu>
</Documentation>
</Methode>
<Attribute Name="Points" ReadOnly="true">
<Documentation>
<UserDocu>A collection of the mesh points
With this attribute it is possible to get access to the points of the mesh
Expand Down
32 changes: 32 additions & 0 deletions src/Mod/Mesh/App/MeshPyImp.cpp
Expand Up @@ -1924,6 +1924,38 @@ PyObject* MeshPy::getSegmentsByCurvature(PyObject *args)
return Py::new_reference_to(list);
}

PyObject* MeshPy::getCurvaturePerVertex(PyObject* args)
{
if (!PyArg_ParseTuple(args, ""))
return NULL;

const MeshCore::MeshKernel& kernel = getMeshObjectPtr()->getKernel();
MeshCore::MeshSegmentAlgorithm finder(kernel);
MeshCore::MeshCurvature meshCurv(kernel);
meshCurv.ComputePerVertex();

const std::vector<MeshCore::CurvatureInfo>& curv = meshCurv.GetCurvature();
Py::List list;
for (const auto& it : curv) {
Py::Tuple tuple(4);
tuple.setItem(0, Py::Float(it.fMaxCurvature));
tuple.setItem(1, Py::Float(it.fMinCurvature));
Py::Tuple maxDir(3);
maxDir.setItem(0, Py::Float(it.cMaxCurvDir.x));
maxDir.setItem(1, Py::Float(it.cMaxCurvDir.y));
maxDir.setItem(2, Py::Float(it.cMaxCurvDir.z));
tuple.setItem(2, maxDir);
Py::Tuple minDir(3);
minDir.setItem(0, Py::Float(it.cMinCurvDir.x));
minDir.setItem(1, Py::Float(it.cMinCurvDir.y));
minDir.setItem(2, Py::Float(it.cMinCurvDir.z));
tuple.setItem(3, minDir);
list.append(tuple);
}

return Py::new_reference_to(list);
}

Py::Long MeshPy::getCountPoints(void) const
{
return Py::Long((long)getMeshObjectPtr()->countPoints());
Expand Down

0 comments on commit b0902db

Please sign in to comment.