From 52b48147ab140a729a5dd1e908e030df0c49a5fa Mon Sep 17 00:00:00 2001 From: wmayer Date: Fri, 23 Oct 2015 17:56:24 +0200 Subject: [PATCH] + extend Python interface of approxSurface --- .../App/AppReverseEngineeringPy.cpp | 40 +++++++++++++++---- .../ReverseEngineering/App/ApproxSurface.cpp | 10 ++--- .../ReverseEngineering/App/ApproxSurface.h | 6 +-- 3 files changed, 40 insertions(+), 16 deletions(-) diff --git a/src/Mod/ReverseEngineering/App/AppReverseEngineeringPy.cpp b/src/Mod/ReverseEngineering/App/AppReverseEngineeringPy.cpp index b50ee0f195..e6ed7b429e 100644 --- a/src/Mod/ReverseEngineering/App/AppReverseEngineeringPy.cpp +++ b/src/Mod/ReverseEngineering/App/AppReverseEngineeringPy.cpp @@ -43,12 +43,32 @@ using namespace Reen; /* module functions */ -static PyObject * approxSurface(PyObject *self, PyObject *args) +static PyObject * approxSurface(PyObject *self, PyObject *args, PyObject *kwds) { PyObject *o; - int orderU=4,orderV=4; - int pointsU=6,pointsV=6; - if (!PyArg_ParseTuple(args, "O|iiii",&o,&orderU,&orderV,&pointsU,&pointsV)) + // spline parameters + int orderU = 4; + int orderV = 4; + int pointsU = 6; + int pointsV = 6; + // smoothing + PyObject* smooth = Py_True; + double weight = 0.1; + double first = 1.0; //0.5 + double second = 0.0; //0.2 + double third = 0.0; //0.3 + // other parameters + int iteration = 5; + PyObject* correction = Py_True; + double factor = 1.0; + + static char* kwds_approx[] = {"Points", "OrderU", "OrderV", "PolesU", "PolesV", + "Smooth", "Weight", "First", "Second", "Third", + "Iterations", "Correction", "PatchFactor", NULL}; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|iiiiO!ddddiO!d",kwds_approx, + &o,&orderU,&orderV,&pointsU,&pointsV, + &PyBool_Type,&smooth,&weight,&first,&second,&third, + &iteration,&PyBool_Type,&correction,&factor)) return NULL; PY_TRY { @@ -68,8 +88,8 @@ static PyObject * approxSurface(PyObject *self, PyObject *args) Handle_Geom_BSplineSurface hSurf; //pc.EnableSmoothing(true, 0.1f, 0.5f, 0.2f, 0.3f); - pc.EnableSmoothing(true, 0.1f, 1.0f, 0.0f, 0.0f); - hSurf = pc.CreateSurface(clPoints, 5, true, 1.0); + pc.EnableSmoothing(PyObject_IsTrue(smooth) ? true : false, weight, first, second, third); + hSurf = pc.CreateSurface(clPoints, iteration, PyObject_IsTrue(correction) ? true : false, factor); if (!hSurf.IsNull()) { return new Part::BSplineSurfacePy(new Part::GeomBSplineSurface(hSurf)); } @@ -102,9 +122,13 @@ triangulate(PyObject *self, PyObject *args) /* registration table */ struct PyMethodDef ReverseEngineering_methods[] = { - {"approxSurface" , approxSurface, 1}, + {"approxSurface", (PyCFunction)approxSurface, METH_VARARGS|METH_KEYWORDS, + "approxSurface(Points=,OrderU=4,OrderV=4,PolesU=6,PolesV=6,Smooth=True)\n" + "Weight=0.1,First=1.0,Second=0.0,Third=0.0,\n" + "Iterations=5,Correction=True,PatchFactor=1.0" + }, #if defined(HAVE_PCL_SURFACE) - {"triangulate" , triangulate, 1}, + {"triangulate" , triangulate, METH_VARARGS}, #endif {NULL, NULL} /* end of table marker */ }; diff --git a/src/Mod/ReverseEngineering/App/ApproxSurface.cpp b/src/Mod/ReverseEngineering/App/ApproxSurface.cpp index cdab08cb65..5c9f4d060a 100644 --- a/src/Mod/ReverseEngineering/App/ApproxSurface.cpp +++ b/src/Mod/ReverseEngineering/App/ApproxSurface.cpp @@ -677,7 +677,7 @@ Base::Vector3d ParameterCorrection::GetGravityPoint() const } Handle(Geom_BSplineSurface) ParameterCorrection::CreateSurface(const TColgp_Array1OfPnt& points, - unsigned short usIter, + int iIter, bool bParaCor, double fSizeFactor) { @@ -697,7 +697,7 @@ Handle(Geom_BSplineSurface) ParameterCorrection::CreateSurface(const TColgp_Arra return NULL; if (bParaCor) - DoParameterCorrection(usIter); + DoParameterCorrection(iIter); return new Geom_BSplineSurface(_vCtrlPntsOfSurf, _vUKnots, _vVKnots, _vUMults, _vVMults, _usUOrder-1, _usVOrder-1); @@ -803,13 +803,13 @@ void BSplineParameterCorrection::SetVKnots(const std::vector& afKnots) _clVSpline.SetKnots(_vVKnots, _vVMults, _usVOrder); } -void BSplineParameterCorrection::DoParameterCorrection(unsigned short usIter) +void BSplineParameterCorrection::DoParameterCorrection(int iIter) { int i=0; double fMaxDiff=0.0, fMaxScalar=1.0; double fWeight = _fSmoothInfluence; - Base::SequencerLauncher seq("Calc surface...", usIter*_pvcPoints->Length()); + Base::SequencerLauncher seq("Calc surface...", iIter*_pvcPoints->Length()); do { fMaxScalar = 1.0; @@ -869,7 +869,7 @@ void BSplineParameterCorrection::DoParameterCorrection(unsigned short usIter) i++; } - while(i FLOAT_EPS && fMaxScalar < 0.99); + while(i FLOAT_EPS && fMaxScalar < 0.99); } bool BSplineParameterCorrection::SolveWithoutSmoothing() diff --git a/src/Mod/ReverseEngineering/App/ApproxSurface.h b/src/Mod/ReverseEngineering/App/ApproxSurface.h index 9ce7e92bd2..0ca340d4b8 100644 --- a/src/Mod/ReverseEngineering/App/ApproxSurface.h +++ b/src/Mod/ReverseEngineering/App/ApproxSurface.h @@ -265,7 +265,7 @@ protected: /** * Fuehrt eine Parameterkorrektur durch. */ - virtual void DoParameterCorrection(unsigned short usIter)=0; + virtual void DoParameterCorrection(int iIter)=0; /** * Loest Gleichungssystem @@ -282,7 +282,7 @@ public: * Berechnet eine B-Spline-Flaeche.aus den geg. Punkten */ virtual Handle_Geom_BSplineSurface CreateSurface(const TColgp_Array1OfPnt& points, - unsigned short usIter, + int iIter, bool bParaCor, double fSizeFactor=0.0f); /** @@ -356,7 +356,7 @@ protected: /** * Fuehrt eine Parameterkorrektur durch. */ - virtual void DoParameterCorrection(unsigned short usIter); + virtual void DoParameterCorrection(int iIter); /** * Loest ein ueberbestimmtes LGS mit Hilfe der Householder-Transformation