PyObject* BSplineCurvePy::interpolate(PyObject *args) { PyObject* obj; double tol3d = Precision::Approximation(); PyObject* periodic = Py_False; PyObject* t1=0; PyObject* t2=0; if (!PyArg_ParseTuple(args, "O|O!dO!O!",&obj, &PyBool_Type, &periodic, &tol3d, &Base::VectorPy::Type, &t1, &Base::VectorPy::Type, &t2)) return 0; 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)); } if (interpolationPoints->Length() < 2) { Standard_Failure::Raise("not enough points given"); } GeomAPI_Interpolate aBSplineInterpolation(interpolationPoints, PyObject_IsTrue(periodic) ? Standard_True : Standard_False, tol3d); if (t1 && t2) { 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.Perform(); if (aBSplineInterpolation.IsDone()) { Handle_Geom_BSplineCurve aBSplineCurve(aBSplineInterpolation.Curve()); this->getGeomBSplineCurvePtr()->setHandle(aBSplineCurve); Py_Return; } else { Standard_Failure::Raise("failed to interpolate points"); return 0; // goes to the catch block } } catch (Standard_Failure) { Handle_Standard_Failure e = Standard_Failure::Caught(); std::string err = e->GetMessageString(); if (err.empty()) err = e->DynamicType()->Name(); PyErr_SetString(PartExceptionOCCError, err.c_str()); return 0; } }
PyObject* BSplineSurfacePy::interpolate(PyObject *args) { PyObject* obj; double tol3d = Precision::Approximation(); PyObject* closed = Py_False; PyObject* t1=0; PyObject* t2=0; if (!PyArg_ParseTuple(args, "O!",&(PyList_Type), &obj)) return 0; try { Py::List list(obj); Standard_Integer lu = list.size(); Py::List col(list.getItem(0)); Standard_Integer lv = col.size(); TColgp_Array2OfPnt interpolationPoints(1, lu, 1, lv); Standard_Integer index1 = 0; Standard_Integer index2 = 0; for (Py::List::iterator it1 = list.begin(); it1 != list.end(); ++it1) { index1++; index2=0; Py::List row(*it1); for (Py::List::iterator it2 = row.begin(); it2 != row.end(); ++it2) { index2++; Py::Vector v(*it2); Base::Vector3d pnt = v.toVector(); gp_Pnt newPoint(pnt.x,pnt.y,pnt.z); interpolationPoints.SetValue(index1, index2, newPoint); } } if (interpolationPoints.RowLength() < 2 || interpolationPoints.ColLength() < 2) { Standard_Failure::Raise("not enough points given"); } GeomAPI_PointsToBSplineSurface surInterpolation; surInterpolation.Interpolate (interpolationPoints); Handle_Geom_BSplineSurface sur(surInterpolation.Surface()); this->getGeomBSplineSurfacePtr()->setHandle(sur); Py_Return; } catch (Standard_Failure) { Handle_Standard_Failure e = Standard_Failure::Caught(); std::string err = e->GetMessageString(); if (err.empty()) err = e->DynamicType()->Name(); PyErr_SetString(PyExc_Exception, err.c_str()); return 0; } }
PyObject* BSplineCurve2dPy::makeC1Continuous(PyObject *args) { double tol = Precision::Approximation(); if (!PyArg_ParseTuple(args, "|d", &tol)) return 0; try { Geom2dBSplineCurve* spline = this->getGeom2dBSplineCurvePtr(); spline->makeC1Continuous(tol); Py_Return; } catch (Standard_Failure) { Handle_Standard_Failure e = Standard_Failure::Caught(); std::string err = e->GetMessageString(); if (err.empty()) err = e->DynamicType()->Name(); PyErr_SetString(PartExceptionOCCError, err.c_str()); return 0; } }
PyObject* BSplineSurfacePy::approximate(PyObject *args) { PyObject* obj; Standard_Integer degMin=0; Standard_Integer degMax=0; Standard_Integer continuity=0; Standard_Real tol3d = Precision::Approximation(); Standard_Real X0=0; Standard_Real dX=0; Standard_Real Y0=0; Standard_Real dY=0; int len = PyTuple_GET_SIZE(args); if (!PyArg_ParseTuple(args, "O!iiid|dddd",&(PyList_Type), &obj, °Min, °Max, &continuity, &tol3d, &X0, &dX, &Y0, &dY)) return 0; try { Py::List list(obj); Standard_Integer lu = list.size(); Py::List col(list.getItem(0)); Standard_Integer lv = col.size(); TColgp_Array2OfPnt interpolationPoints(1, lu, 1, lv); TColStd_Array2OfReal zPoints(1, lu, 1, lv); //Base::Console().Message("lu=%d, lv=%d\n", lu, lv); Standard_Integer index1 = 0; Standard_Integer index2 = 0; for (Py::List::iterator it1 = list.begin(); it1 != list.end(); ++it1) { index1++; index2=0; Py::List row(*it1); for (Py::List::iterator it2 = row.begin(); it2 != row.end(); ++it2) { index2++; if(len == 5){ Py::Vector v(*it2); Base::Vector3d pnt = v.toVector(); gp_Pnt newPoint(pnt.x,pnt.y,pnt.z); interpolationPoints.SetValue(index1, index2, newPoint); } else { Standard_Real val = PyFloat_AsDouble((*it2).ptr()); zPoints.SetValue(index1, index2, val); } } } if(continuity<0 || continuity>3){ Standard_Failure::Raise("continuity must be between 0 and 3"); } GeomAbs_Shape c; switch(continuity){ case 0: c = GeomAbs_C0; case 1: c = GeomAbs_C1; case 2: c = GeomAbs_C2; case 3: c = GeomAbs_C3; } if (interpolationPoints.RowLength() < 2 || interpolationPoints.ColLength() < 2) { Standard_Failure::Raise("not enough points given"); } GeomAPI_PointsToBSplineSurface surInterpolation; if(len == 5){ surInterpolation.Init(interpolationPoints, degMin, degMax, c, tol3d); } else { surInterpolation.Init(zPoints, X0, dX, Y0, dY, degMin, degMax, c, tol3d); } Handle_Geom_BSplineSurface sur(surInterpolation.Surface()); this->getGeomBSplineSurfacePtr()->setHandle(sur); Py_Return; } catch (Standard_Failure) { Handle_Standard_Failure e = Standard_Failure::Caught(); std::string err = e->GetMessageString(); if (err.empty()) err = e->DynamicType()->Name(); PyErr_SetString(PyExc_Exception, err.c_str()); return 0; } }
PyObject* BSplineCurve2dPy::interpolate(PyObject *args, PyObject *kwds) { PyObject* obj; PyObject* par = 0; double tol3d = Precision::Approximation(); PyObject* periodic = Py_False; PyObject* t1 = 0; PyObject* t2 = 0; PyObject* ts = 0; PyObject* fl = 0; static char* kwds_interp[] = {"Points", "PeriodicFlag", "Tolerance", "InitialTangent", "FinalTangent", "Tangents", "TangentFlags", "Parameters", NULL}; if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|O!dO!O!OOO",kwds_interp, &obj, &PyBool_Type, &periodic, &tol3d, Base::Vector2dPy::type_object(), &t1, Base::Vector2dPy::type_object(), &t2, &ts, &fl, &par)) return 0; try { Py::Sequence list(obj); Handle_TColgp_HArray1OfPnt2d interpolationPoints = new TColgp_HArray1OfPnt2d(1, list.size()); Standard_Integer index = 1; for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) { Base::Vector2d pnt = Py::Vector2d(*it).getCxxObject()->value(); interpolationPoints->SetValue(index++, gp_Pnt2d(pnt.x,pnt.y)); } 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)); } } std::unique_ptr<Geom2dAPI_Interpolate> aBSplineInterpolation; if (parameters.IsNull()) { aBSplineInterpolation.reset(new Geom2dAPI_Interpolate(interpolationPoints, PyObject_IsTrue(periodic) ? Standard_True : Standard_False, tol3d)); } else { aBSplineInterpolation.reset(new Geom2dAPI_Interpolate(interpolationPoints, parameters, PyObject_IsTrue(periodic) ? Standard_True : Standard_False, tol3d)); } if (t1 && t2) { Base::Vector2d v1 = Py::Vector2d(t1).getCxxObject()->value(); Base::Vector2d v2 = Py::Vector2d(t2).getCxxObject()->value(); gp_Vec2d initTangent(v1.x,v1.y), finalTangent(v2.x,v2.y); aBSplineInterpolation->Load(initTangent, finalTangent); } else if (ts && fl) { Py::Sequence tlist(ts); TColgp_Array1OfVec2d tangents(1, tlist.size()); Standard_Integer index = 1; for (Py::Sequence::iterator it = tlist.begin(); it != tlist.end(); ++it) { Base::Vector2d vec = Py::Vector2d(*it).getCxxObject()->value(); tangents.SetValue(index++, gp_Vec2d(vec.x,vec.y)); } 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); } aBSplineInterpolation->Perform(); if (aBSplineInterpolation->IsDone()) { Handle_Geom2d_BSplineCurve aBSplineCurve(aBSplineInterpolation->Curve()); this->getGeom2dBSplineCurvePtr()->setHandle(aBSplineCurve); Py_Return; } else { Standard_Failure::Raise("failed to interpolate points"); return 0; // goes to the catch block } } catch (Standard_Failure) { Handle_Standard_Failure e = Standard_Failure::Caught(); std::string err = e->GetMessageString(); if (err.empty()) err = e->DynamicType()->Name(); PyErr_SetString(PartExceptionOCCError, err.c_str()); return 0; } }