diff --git a/src/Mod/Mesh/App/MeshPy.xml b/src/Mod/Mesh/App/MeshPy.xml index c71944df60..ed549875dd 100644 --- a/src/Mod/Mesh/App/MeshPy.xml +++ b/src/Mod/Mesh/App/MeshPy.xml @@ -403,7 +403,7 @@ The argument int is the mode: 0=inner, 1=outer Fillup holes - + Smooth the mesh smooth([iteration=1,maxError=FLT_MAX]) @@ -520,7 +520,7 @@ for p in mesh.Facets: private: friend class PropertyMeshKernel; - class PropertyMeshKernel* parentProperty; + class PropertyMeshKernel* parentProperty = nullptr; diff --git a/src/Mod/Mesh/App/MeshPyImp.cpp b/src/Mod/Mesh/App/MeshPyImp.cpp index ac5d6b9910..1a8f4a5bd5 100644 --- a/src/Mod/Mesh/App/MeshPyImp.cpp +++ b/src/Mod/Mesh/App/MeshPyImp.cpp @@ -43,6 +43,7 @@ #include "Core/Grid.h" #include "Core/MeshKernel.h" #include "Core/Segmentation.h" +#include "Core/Smoothing.h" #include "Core/Curvature.h" #include @@ -1627,16 +1628,41 @@ PyObject* MeshPy::trim(PyObject *args) Py_Return; } -PyObject* MeshPy::smooth(PyObject *args) +PyObject* MeshPy::smooth(PyObject *args, PyObject *kwds) { + char* method = "Laplace"; int iter=1; - float d_max=FLOAT_MAX; - if (!PyArg_ParseTuple(args, "|if", &iter,&d_max)) - return NULL; + double lambda = 0; + double micro = 0; + static char* keywords_smooth[] = {"Method","Iteration","Lambda","Micro",NULL}; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|sidd",keywords_smooth, + &method, &iter, &lambda, µ)) + return 0; PY_TRY { MeshPropertyLock lock(this->parentProperty); - getMeshObjectPtr()->smooth(iter, d_max); + MeshCore::MeshKernel& kernel = getMeshObjectPtr()->getKernel(); + if (strcmp(method, "Laplace") == 0) { + MeshCore::LaplaceSmoothing smooth(kernel); + if (lambda > 0) + smooth.SetLambda(lambda); + smooth.Smooth(iter); + } + else if (strcmp(method, "Taubin") == 0) { + MeshCore::TaubinSmoothing smooth(kernel); + if (lambda > 0) + smooth.SetLambda(lambda); + if (micro > 0) + smooth.SetMicro(micro); + smooth.Smooth(iter); + } + else if (strcmp(method, "PlaneFit") == 0) { + MeshCore::PlaneFitSmoothing smooth(kernel); + smooth.Smooth(iter); + } + else { + throw Py::ValueError("No such smoothing algorithm"); + } } PY_CATCH; Py_Return;