/* module functions */ static PyObject * approxSurface(PyObject *self, PyObject *args) { PyObject *o; int orderU=4,orderV=4; int pointsU=6,pointsV=6; if (!PyArg_ParseTuple(args, "O|iiii",&o,&orderU,&orderV,&pointsU,&pointsV)) return NULL; PY_TRY { Py::Sequence l(o); TColgp_Array1OfPnt clPoints(0, l.size()-1); int index=0; for (Py::Sequence::iterator it = l.begin(); it != l.end(); ++it) { Py::Tuple t(*it); clPoints(index++) = gp_Pnt( (double)Py::Float(t.getItem(0)), (double)Py::Float(t.getItem(1)), (double)Py::Float(t.getItem(2))); } Reen::BSplineParameterCorrection pc(orderU,orderV,pointsU,pointsV); 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); if (!hSurf.IsNull()) { return new Part::BSplineSurfacePy(new Part::GeomBSplineSurface(hSurf)); } PyErr_SetString(PyExc_Exception, "Computation of B-Spline surface failed"); return 0; } PY_CATCH; }
//================================================================ // Function : Convert_Presentation::drawSurfaceAndItsBSpline // Purpose : //================================================================ void Convert_Presentation::drawSurfaceAndItsBSpline(Handle_Geom_Surface theSurface, const Standard_CString theName, TCollection_AsciiString& theText) { TCollection_AsciiString aTitle ("Converting "); aTitle += theName; aTitle += " to BSpline surface"; theText += EOL " Handle_Geom_BSplineSurface aBSplineSurface = " EOL " GeomConvert::SurfaceToBSplineSurface(aSurface);" EOL; setResultTitle (aTitle.ToCString()); setResultText (theText.ToCString()); drawSurface (theSurface, SurfaceColor); if (WAIT_A_LITTLE) return; Handle_Geom_BSplineSurface aBSplineSurface = GeomConvert::SurfaceToBSplineSurface(theSurface); _ASSERTE(!aBSplineSurface.IsNull()); drawSurface (aBSplineSurface, BSplineSurfaceColor); }
PyObject* PlateSurfacePy::makeApprox(PyObject *args, PyObject* kwds) { static char* kwds_Parameter[] = {"Tol3d","MaxSegments","MaxDegree","MaxDistance", "CritOrder","Continuity","EnlargeCoeff",NULL}; double tol3d=0.01; int maxSeg=9; int maxDegree=3; double dmax = 0.0001; int critOrder=0; char* cont = "C1"; double enlargeCoeff = 1.1; if (!PyArg_ParseTupleAndKeywords(args, kwds, "|diidisd", kwds_Parameter, &tol3d, &maxSeg, &maxDegree, &dmax, &critOrder, &cont, &enlargeCoeff)) return 0; GeomAbs_Shape continuity; std::string uc = cont; if (uc == "C0") continuity = GeomAbs_C0; else if (uc == "C1") continuity = GeomAbs_C1; else if (uc == "C2") continuity = GeomAbs_C2; else if (uc == "C3") continuity = GeomAbs_C3; else if (uc == "CN") continuity = GeomAbs_CN; else if (uc == "G1") continuity = GeomAbs_G1; else continuity = GeomAbs_C1; PY_TRY { GeomPlate_MakeApprox approx(Handle_GeomPlate_Surface::DownCast(getGeomPlateSurfacePtr()->handle()), tol3d, maxSeg, maxDegree, dmax, critOrder, continuity, enlargeCoeff); Handle_Geom_BSplineSurface hSurf = approx.Surface(); if (!hSurf.IsNull()) { return new Part::BSplineSurfacePy(new Part::GeomBSplineSurface(hSurf)); } PyErr_SetString(PyExc_RuntimeError, "Approximation of B-Spline surface failed"); return 0; } PY_CATCH_OCC; }
Py::Object approxSurface(const Py::Tuple& args, const Py::Dict& kwds) { PyObject *o; // spline parameters int uDegree = 3; int vDegree = 3; int uPoles = 6; int vPoles = 6; // smoothing PyObject* smooth = Py_True; double weight = 0.1; double grad = 1.0; //0.5 double bend = 0.0; //0.2 // other parameters int iteration = 5; PyObject* correction = Py_True; double factor = 1.0; static char* kwds_approx[] = {"Points", "UDegree", "VDegree", "NbUPoles", "NbVPoles", "Smooth", "Weight", "Grad", "Bend", "Iterations", "Correction", "PatchFactor", NULL}; if (!PyArg_ParseTupleAndKeywords(args.ptr(), kwds.ptr(), "O|iiiiO!dddiO!d",kwds_approx, &o,&uDegree,&vDegree,&uPoles,&vPoles, &PyBool_Type,&smooth,&weight,&grad,&bend, &iteration,&PyBool_Type,&correction,&factor)) throw Py::Exception(); double curvdiv = 1.0 - (grad + bend); int uOrder = uDegree + 1; int vOrder = vDegree + 1; // error checking if (grad < 0.0 || grad > 1.0) { throw Py::ValueError("Value of Grad out of range [0,1]"); } if (bend < 0.0 || bend > 1.0) { throw Py::ValueError("Value of Bend out of range [0,1]"); } if (curvdiv < 0.0 || curvdiv > 1.0) { throw Py::ValueError("Sum of Grad and Bend out of range [0,1]"); } if (uDegree < 1 || uOrder > uPoles) { throw Py::ValueError("Value of uDegree out of range [1,NbUPoles-1]"); } if (vDegree < 1 || vOrder > vPoles) { throw Py::ValueError("Value of vDegree out of range [1,NbVPoles-1]"); } try { Py::Sequence l(o); TColgp_Array1OfPnt clPoints(0, l.size()-1); if (clPoints.Length() < uPoles * vPoles) { throw Py::ValueError("Too less data points for the specified number of poles"); } int index=0; for (Py::Sequence::iterator it = l.begin(); it != l.end(); ++it) { Py::Tuple t(*it); clPoints(index++) = gp_Pnt( (double)Py::Float(t.getItem(0)), (double)Py::Float(t.getItem(1)), (double)Py::Float(t.getItem(2))); } Reen::BSplineParameterCorrection pc(uOrder,vOrder,uPoles,vPoles); Handle_Geom_BSplineSurface hSurf; pc.EnableSmoothing(PyObject_IsTrue(smooth) ? true : false, weight, grad, bend, curvdiv); hSurf = pc.CreateSurface(clPoints, iteration, PyObject_IsTrue(correction) ? true : false, factor); if (!hSurf.IsNull()) { return Py::asObject(new Part::BSplineSurfacePy(new Part::GeomBSplineSurface(hSurf))); } throw Py::RuntimeError("Computation of B-Spline surface failed"); } catch (Standard_Failure &e) { std::string str; Standard_CString msg = e.GetMessageString(); str += typeid(e).name(); str += " "; if (msg) {str += msg;} else {str += "No OCCT Exception Message";} throw Py::RuntimeError(str); } catch (const Base::Exception &e) { throw Py::RuntimeError(e.what()); } catch (...) { throw Py::RuntimeError("Unknown C++ exception"); } }