From b26ed2a3a9b0fd29bb09ed14090d7d5dc8f656b0 Mon Sep 17 00:00:00 2001 From: wmayer Date: Thu, 14 Aug 2014 19:11:51 +0200 Subject: [PATCH] + Support Quasi methods in discretize() --- src/Mod/Part/App/GeometryCurvePy.xml | 2 ++ src/Mod/Part/App/GeometryCurvePyImp.cpp | 46 +++++++++++++++++++++++++ src/Mod/Part/App/TopoShapeEdgePy.xml | 2 ++ src/Mod/Part/App/TopoShapeEdgePyImp.cpp | 46 +++++++++++++++++++++++++ src/Mod/Part/App/TopoShapeWirePy.xml | 2 ++ src/Mod/Part/App/TopoShapeWirePyImp.cpp | 46 +++++++++++++++++++++++++ 6 files changed, 144 insertions(+) diff --git a/src/Mod/Part/App/GeometryCurvePy.xml b/src/Mod/Part/App/GeometryCurvePy.xml index 14470aed97..a70c115fba 100644 --- a/src/Mod/Part/App/GeometryCurvePy.xml +++ b/src/Mod/Part/App/GeometryCurvePy.xml @@ -26,8 +26,10 @@ Discretizes the curve and returns a list of points. The function accepts keywords as argument: discretize(Number=n) => gives a list of 'n' equidistant points +discretize(QuasiNumber=n) => gives a list of 'n' quasi equidistant points (is faster than the method above) discretize(Distance=d) => gives a list of equidistant points with distance 'd' discretize(Deflection=d) => gives a list of points with a maximum deflection 'd' to the curve +discretize(QuasiDeflection=d) => gives a list of points with a maximum deflection 'd' to the curve (faster) discretize(Angular=a,Curvature=c,[Minimum=m]) => gives a list of points with an angular deflection of 'a' and a curvature deflection of 'c'. Optionally a minimum number of points can be set which by default is set to 2. diff --git a/src/Mod/Part/App/GeometryCurvePyImp.cpp b/src/Mod/Part/App/GeometryCurvePyImp.cpp index 3b96aebd6e..a8d1912af0 100644 --- a/src/Mod/Part/App/GeometryCurvePyImp.cpp +++ b/src/Mod/Part/App/GeometryCurvePyImp.cpp @@ -31,6 +31,8 @@ # include # include # include +# include +# include # include # include # include @@ -233,6 +235,50 @@ PyObject* GeometryCurvePy::discretize(PyObject *args, PyObject *kwds) return 0; } } + + // use QuasiNumber kwds + static char* kwds_QuasiNumPoints[] = {"QuasiNumber","First","Last",NULL}; + PyErr_Clear(); + int quasiNumPoints; + if (PyArg_ParseTupleAndKeywords(args, kwds, "i|dd", kwds_QuasiNumPoints, &quasiNumPoints, &first, &last)) { + GCPnts_QuasiUniformAbscissa discretizer(adapt, quasiNumPoints, first, last); + if (discretizer.NbPoints () > 0) { + Py::List points; + int nbPoints = discretizer.NbPoints (); + for (int i=1; i<=nbPoints; i++) { + gp_Pnt p = adapt.Value (discretizer.Parameter (i)); + points.append(Py::Vector(Base::Vector3d(p.X(),p.Y(),p.Z()))); + } + + return Py::new_reference_to(points); + } + else { + PyErr_SetString(PyExc_Exception, "Discretization of curve failed"); + return 0; + } + } + + // use QuasiDeflection kwds + static char* kwds_QuasiDeflection[] = {"QuasiDeflection","First","Last",NULL}; + PyErr_Clear(); + double quasiDeflection; + if (PyArg_ParseTupleAndKeywords(args, kwds, "d|dd", kwds_QuasiDeflection, &quasiDeflection, &first, &last)) { + GCPnts_QuasiUniformDeflection discretizer(adapt, quasiDeflection, first, last); + if (discretizer.NbPoints () > 0) { + Py::List points; + int nbPoints = discretizer.NbPoints (); + for (int i=1; i<=nbPoints; i++) { + gp_Pnt p = discretizer.Value (i); + points.append(Py::Vector(Base::Vector3d(p.X(),p.Y(),p.Z()))); + } + + return Py::new_reference_to(points); + } + else { + PyErr_SetString(PyExc_Exception, "Discretization of curve failed"); + return 0; + } + } } catch (const Base::Exception& e) { PyErr_SetString(PyExc_Exception, e.what()); diff --git a/src/Mod/Part/App/TopoShapeEdgePy.xml b/src/Mod/Part/App/TopoShapeEdgePy.xml index adf51dbb16..a2e527e014 100644 --- a/src/Mod/Part/App/TopoShapeEdgePy.xml +++ b/src/Mod/Part/App/TopoShapeEdgePy.xml @@ -74,8 +74,10 @@ Discretizes the edge and returns a list of points. The function accepts keywords as argument: discretize(Number=n) => gives a list of 'n' equidistant points +discretize(QuasiNumber=n) => gives a list of 'n' quasi equidistant points (is faster than the method above) discretize(Distance=d) => gives a list of equidistant points with distance 'd' discretize(Deflection=d) => gives a list of points with a maximum deflection 'd' to the edge +discretize(QuasiDeflection=d) => gives a list of points with a maximum deflection 'd' to the edge (faster) discretize(Angular=a,Curvature=c,[Minimum=m]) => gives a list of points with an angular deflection of 'a' and a curvature deflection of 'c'. Optionally a minimum number of points can be set which by default is set to 2. diff --git a/src/Mod/Part/App/TopoShapeEdgePyImp.cpp b/src/Mod/Part/App/TopoShapeEdgePyImp.cpp index 75afedeaa9..9b305bbbab 100644 --- a/src/Mod/Part/App/TopoShapeEdgePyImp.cpp +++ b/src/Mod/Part/App/TopoShapeEdgePyImp.cpp @@ -60,6 +60,8 @@ #include #include #include +#include +#include #include #include @@ -501,6 +503,50 @@ PyObject* TopoShapeEdgePy::discretize(PyObject *args, PyObject *kwds) return 0; } } + + // use QuasiNumber kwds + static char* kwds_QuasiNumPoints[] = {"QuasiNumber","First","Last",NULL}; + PyErr_Clear(); + int quasiNumPoints; + if (PyArg_ParseTupleAndKeywords(args, kwds, "i|dd", kwds_QuasiNumPoints, &quasiNumPoints, &first, &last)) { + GCPnts_QuasiUniformAbscissa discretizer(adapt, quasiNumPoints, first, last); + if (discretizer.NbPoints () > 0) { + Py::List points; + int nbPoints = discretizer.NbPoints (); + for (int i=1; i<=nbPoints; i++) { + gp_Pnt p = adapt.Value (discretizer.Parameter (i)); + points.append(Py::Vector(Base::Vector3d(p.X(),p.Y(),p.Z()))); + } + + return Py::new_reference_to(points); + } + else { + PyErr_SetString(PyExc_Exception, "Discretization of edge failed"); + return 0; + } + } + + // use QuasiDeflection kwds + static char* kwds_QuasiDeflection[] = {"QuasiDeflection","First","Last",NULL}; + PyErr_Clear(); + double quasiDeflection; + if (PyArg_ParseTupleAndKeywords(args, kwds, "d|dd", kwds_QuasiDeflection, &quasiDeflection, &first, &last)) { + GCPnts_QuasiUniformDeflection discretizer(adapt, quasiDeflection, first, last); + if (discretizer.NbPoints () > 0) { + Py::List points; + int nbPoints = discretizer.NbPoints (); + for (int i=1; i<=nbPoints; i++) { + gp_Pnt p = discretizer.Value (i); + points.append(Py::Vector(Base::Vector3d(p.X(),p.Y(),p.Z()))); + } + + return Py::new_reference_to(points); + } + else { + PyErr_SetString(PyExc_Exception, "Discretization of edge failed"); + return 0; + } + } } catch (const Base::Exception& e) { PyErr_SetString(PyExc_Exception, e.what()); diff --git a/src/Mod/Part/App/TopoShapeWirePy.xml b/src/Mod/Part/App/TopoShapeWirePy.xml index 3912462e93..adbfcfa009 100644 --- a/src/Mod/Part/App/TopoShapeWirePy.xml +++ b/src/Mod/Part/App/TopoShapeWirePy.xml @@ -56,8 +56,10 @@ Make a loft defined by a list of profiles along a wire. Transition can be Discretizes the wire and returns a list of points. The function accepts keywords as argument: discretize(Number=n) => gives a list of 'n' equidistant points +discretize(QuasiNumber=n) => gives a list of 'n' quasi equidistant points (is faster than the method above) discretize(Distance=d) => gives a list of equidistant points with distance 'd' discretize(Deflection=d) => gives a list of points with a maximum deflection 'd' to the wire +discretize(QuasiDeflection=d) => gives a list of points with a maximum deflection 'd' to the wire (faster) discretize(Angular=a,Curvature=c,[Minimum=m]) => gives a list of points with an angular deflection of 'a' and a curvature deflection of 'c'. Optionally a minimum number of points can be set which by default is set to 2. diff --git a/src/Mod/Part/App/TopoShapeWirePyImp.cpp b/src/Mod/Part/App/TopoShapeWirePyImp.cpp index 7a906e3f05..6dbee4d790 100644 --- a/src/Mod/Part/App/TopoShapeWirePyImp.cpp +++ b/src/Mod/Part/App/TopoShapeWirePyImp.cpp @@ -40,6 +40,8 @@ #include #include #include +#include +#include #include #include @@ -442,6 +444,50 @@ PyObject* TopoShapeWirePy::discretize(PyObject *args, PyObject *kwds) return 0; } } + + // use QuasiNumber kwds + static char* kwds_QuasiNumPoints[] = {"QuasiNumber","First","Last",NULL}; + PyErr_Clear(); + int quasiNumPoints; + if (PyArg_ParseTupleAndKeywords(args, kwds, "i|dd", kwds_QuasiNumPoints, &quasiNumPoints, &first, &last)) { + GCPnts_QuasiUniformAbscissa discretizer(adapt, quasiNumPoints, first, last); + if (discretizer.NbPoints () > 0) { + Py::List points; + int nbPoints = discretizer.NbPoints (); + for (int i=1; i<=nbPoints; i++) { + gp_Pnt p = adapt.Value (discretizer.Parameter (i)); + points.append(Py::Vector(Base::Vector3d(p.X(),p.Y(),p.Z()))); + } + + return Py::new_reference_to(points); + } + else { + PyErr_SetString(PyExc_Exception, "Discretization of wire failed"); + return 0; + } + } + + // use QuasiDeflection kwds + static char* kwds_QuasiDeflection[] = {"QuasiDeflection","First","Last",NULL}; + PyErr_Clear(); + double quasiDeflection; + if (PyArg_ParseTupleAndKeywords(args, kwds, "d|dd", kwds_QuasiDeflection, &quasiDeflection, &first, &last)) { + GCPnts_QuasiUniformDeflection discretizer(adapt, quasiDeflection, first, last); + if (discretizer.NbPoints () > 0) { + Py::List points; + int nbPoints = discretizer.NbPoints (); + for (int i=1; i<=nbPoints; i++) { + gp_Pnt p = discretizer.Value (i); + points.append(Py::Vector(Base::Vector3d(p.X(),p.Y(),p.Z()))); + } + + return Py::new_reference_to(points); + } + else { + PyErr_SetString(PyExc_Exception, "Discretization of wire failed"); + return 0; + } + } } catch (const Base::Exception& e) { PyErr_SetString(PyExc_Exception, e.what());