Skip to content

Commit

Permalink
+ support of tangents in BSplineCurve.interpolate
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed May 24, 2016
1 parent 7582f17 commit 8cfabdb
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 45 deletions.
2 changes: 1 addition & 1 deletion src/Mod/Part/App/BSplineCurvePy.xml
Expand Up @@ -302,7 +302,7 @@ from the knots table of this B-Spline curve.</UserDocu>
</UserDocu>
</Documentation>
</Methode>
<Methode Name="interpolate">
<Methode Name="interpolate" Keyword="true">
<Documentation>
<UserDocu>
interpolate(list_of_points, parameters = None, bool periodic = False, float tolerance = 1e-6,
Expand Down
95 changes: 51 additions & 44 deletions src/Mod/Part/App/BSplineCurvePyImp.cpp
Expand Up @@ -30,9 +30,11 @@
# include <gp_Pnt.hxx>
# include <TColStd_Array1OfReal.hxx>
# include <TColgp_Array1OfPnt.hxx>
# include <TColgp_Array1OfVec.hxx>
# include <TColgp_HArray1OfPnt.hxx>
# include <TColStd_Array1OfInteger.hxx>
# include <TColStd_HArray1OfReal.hxx>
# include <TColStd_HArray1OfBoolean.hxx>
# include <TColgp_HArray1OfPnt.hxx>
# include <Precision.hxx>
#endif
Expand Down Expand Up @@ -773,68 +775,52 @@ PyObject* BSplineCurvePy::approximate(PyObject *args)
}
}

PyObject* BSplineCurvePy::interpolate(PyObject *args)
PyObject* BSplineCurvePy::interpolate(PyObject *args, PyObject *kwds)
{
PyObject* obj;
PyObject* par;
PyObject* par = 0;
double tol3d = Precision::Approximation();
PyObject* periodic = Py_False;
PyObject* t1=0; PyObject* t2=0;
PyObject* t1 = 0; PyObject* t2 = 0;
PyObject* ts = 0; PyObject* fl = 0;
PyObject* scale = Py_True;

Handle_TColgp_HArray1OfPnt interpolationPoints;
Handle_TColStd_HArray1OfReal parameters;
std::auto_ptr<GeomAPI_Interpolate> aBSplineInterpolation;
static char* kwds_interp[] = {"Points", "PeriodicFlag", "Tolerance", "InitialTangent", "FinalTangent",
"Tangents", "TangentFlags", "Parameters", "Scale", NULL};

do {
if (PyArg_ParseTuple(args, "O|O!dO!O!",&obj, &PyBool_Type, &periodic, &tol3d,
&Base::VectorPy::Type, &t1, &Base::VectorPy::Type, &t2)) {
Py::Sequence list(obj);
interpolationPoints = new TColgp_HArray1OfPnt(1, list.size());
Standard_Integer index = 1;
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
Py::Vector v(*it);
Base::Vector3d pnt = v.toVector();
interpolationPoints->SetValue(index++, gp_Pnt(pnt.x,pnt.y,pnt.z));
}
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|O!dO!O!OOOO!",kwds_interp,
&obj, &PyBool_Type, &periodic, &tol3d,
&Base::VectorPy::Type, &t1,
&Base::VectorPy::Type, &t2,
&ts, &fl, &par, &PyBool_Type, &scale))
return 0;

if (interpolationPoints->Length() < 2) {
Standard_Failure::Raise("not enough points given");
}
break;
try {
Py::Sequence list(obj);
Handle_TColgp_HArray1OfPnt interpolationPoints = new TColgp_HArray1OfPnt(1, list.size());
Standard_Integer index = 1;
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
Py::Vector v(*it);
Base::Vector3d pnt = v.toVector();
interpolationPoints->SetValue(index++, gp_Pnt(pnt.x,pnt.y,pnt.z));
}

PyErr_Clear();
if (PyArg_ParseTuple(args, "OO|O!dO!O!",&obj, &par, &PyBool_Type, &periodic, &tol3d,
&Base::VectorPy::Type, &t1, &Base::VectorPy::Type, &t2)) {
Py::Sequence list(obj);
interpolationPoints = new TColgp_HArray1OfPnt(1, list.size());
Standard_Integer index = 1;
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
Py::Vector v(*it);
Base::Vector3d pnt = v.toVector();
interpolationPoints->SetValue(index++, gp_Pnt(pnt.x,pnt.y,pnt.z));
}

if (interpolationPoints->Length() < 2) {
Standard_Failure::Raise("not enough points given");
}
if (interpolationPoints->Length() < 2) {
Standard_Failure::Raise("not enough points given");
}

Handle_TColStd_HArray1OfReal parameters;
if (par) {
Py::Sequence plist(par);
parameters = new TColStd_HArray1OfReal(1, plist.size());
Standard_Integer pindex = 1;
for (Py::Sequence::iterator it = plist.begin(); it != plist.end(); ++it) {
Py::Float f(*it);
parameters->SetValue(pindex++, static_cast<double>(f));
}
break;
}

PyErr_SetString(PyExc_ValueError, "wrong arguments");
return 0;
}
while (false);

try {
std::auto_ptr<GeomAPI_Interpolate> aBSplineInterpolation;
if (parameters.IsNull()) {
aBSplineInterpolation.reset(new GeomAPI_Interpolate(interpolationPoints,
PyObject_IsTrue(periodic) ? Standard_True : Standard_False, tol3d));
Expand All @@ -848,7 +834,28 @@ PyObject* BSplineCurvePy::interpolate(PyObject *args)
Base::Vector3d v1 = Py::Vector(t1,false).toVector();
Base::Vector3d v2 = Py::Vector(t2,false).toVector();
gp_Vec initTangent(v1.x,v1.y,v1.z), finalTangent(v2.x,v2.y,v2.z);
aBSplineInterpolation->Load(initTangent, finalTangent);
aBSplineInterpolation->Load(initTangent, finalTangent, PyObject_IsTrue(scale)
? Standard_True : Standard_False);
}
else if (ts && fl) {
Py::Sequence tlist(ts);
TColgp_Array1OfVec tangents(1, tlist.size());
Standard_Integer index = 1;
for (Py::Sequence::iterator it = tlist.begin(); it != tlist.end(); ++it) {
Py::Vector v(*it);
Base::Vector3d vec = v.toVector();
tangents.SetValue(index++, gp_Vec(vec.x,vec.y,vec.z));
}

Py::Sequence flist(fl);
Handle_TColStd_HArray1OfBoolean tangentFlags = new TColStd_HArray1OfBoolean(1, flist.size());
Standard_Integer findex = 1;
for (Py::Sequence::iterator it = flist.begin(); it != flist.end(); ++it) {
Py::Boolean flag(*it);
tangentFlags->SetValue(findex++, static_cast<bool>(flag) ? Standard_True : Standard_False);
aBSplineInterpolation->Load(tangents, tangentFlags, PyObject_IsTrue(scale)
? Standard_True : Standard_False);
}
}

aBSplineInterpolation->Perform();
Expand Down

0 comments on commit 8cfabdb

Please sign in to comment.