Add approximate() method to B-spline surface class
This commit is contained in:
parent
48243d6497
commit
70bb37ab9d
|
@ -677,9 +677,33 @@
|
||||||
<UserDocu>Returns a reparametrized copy of this surface</UserDocu>
|
<UserDocu>Returns a reparametrized copy of this surface</UserDocu>
|
||||||
</Documentation>
|
</Documentation>
|
||||||
</Methode>
|
</Methode>
|
||||||
|
<Methode Name="approximate">
|
||||||
|
<Documentation>
|
||||||
|
<UserDocu>
|
||||||
|
approximate(points, degMin, degMax, continuity, tol)
|
||||||
|
approximate(zPoints, degMin, degMax, continuity, tol, X0, dX, Y0, dY)
|
||||||
|
|
||||||
|
Replaces this B-Spline surface by approximating a set of points.
|
||||||
|
continuity is an integer between 0 and 3
|
||||||
|
</UserDocu>
|
||||||
|
</Documentation>
|
||||||
|
</Methode>
|
||||||
<Methode Name="interpolate">
|
<Methode Name="interpolate">
|
||||||
<Documentation>
|
<Documentation>
|
||||||
<UserDocu>Replaces this B-Spline surface by interpolating a set of points.</UserDocu>
|
<UserDocu>
|
||||||
|
interpolate(points)
|
||||||
|
interpolate(zpoints, X0, dX, Y0, dY)
|
||||||
|
|
||||||
|
Replaces this B-Spline surface by interpolating a set of points.
|
||||||
|
The resulting surface is of degree 3 and continuity C2.
|
||||||
|
Arguments:
|
||||||
|
a 2 dimensional array of vectors, that the surface passes through
|
||||||
|
or
|
||||||
|
a 2 dimensional array of floats with the z values,
|
||||||
|
the x starting point X0 (float),
|
||||||
|
the x increment dX (float),
|
||||||
|
the y starting point Y0 and increment dY
|
||||||
|
</UserDocu>
|
||||||
</Documentation>
|
</Documentation>
|
||||||
</Methode>
|
</Methode>
|
||||||
</PythonExport>
|
</PythonExport>
|
||||||
|
|
|
@ -33,6 +33,7 @@
|
||||||
# include <TColgp_Array2OfPnt.hxx>
|
# include <TColgp_Array2OfPnt.hxx>
|
||||||
# include <Precision.hxx>
|
# include <Precision.hxx>
|
||||||
# include <GeomAPI_PointsToBSplineSurface.hxx>
|
# include <GeomAPI_PointsToBSplineSurface.hxx>
|
||||||
|
# include <GeomAbs_Shape.hxx>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <Base/GeometryPyCXX.h>
|
#include <Base/GeometryPyCXX.h>
|
||||||
|
@ -43,6 +44,7 @@
|
||||||
#include "BSplineSurfacePy.h"
|
#include "BSplineSurfacePy.h"
|
||||||
#include "BSplineSurfacePy.cpp"
|
#include "BSplineSurfacePy.cpp"
|
||||||
|
|
||||||
|
|
||||||
using namespace Part;
|
using namespace Part;
|
||||||
|
|
||||||
// returns a string which represents the object e.g. when printed in python
|
// returns a string which represents the object e.g. when printed in python
|
||||||
|
@ -1244,13 +1246,21 @@ PyObject* BSplineSurfacePy::reparametrize(PyObject * args)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PyObject* BSplineSurfacePy::interpolate(PyObject *args)
|
PyObject* BSplineSurfacePy::approximate(PyObject *args)
|
||||||
{
|
{
|
||||||
PyObject* obj;
|
PyObject* obj;
|
||||||
double tol3d = Precision::Approximation();
|
Standard_Integer degMin=0;
|
||||||
PyObject* closed = Py_False;
|
Standard_Integer degMax=0;
|
||||||
PyObject* t1=0; PyObject* t2=0;
|
Standard_Integer continuity=0;
|
||||||
if (!PyArg_ParseTuple(args, "O!",&(PyList_Type), &obj))
|
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;
|
return 0;
|
||||||
try {
|
try {
|
||||||
Py::List list(obj);
|
Py::List list(obj);
|
||||||
|
@ -1258,6 +1268,8 @@ PyObject* BSplineSurfacePy::interpolate(PyObject *args)
|
||||||
Py::List col(list.getItem(0));
|
Py::List col(list.getItem(0));
|
||||||
Standard_Integer lv = col.size();
|
Standard_Integer lv = col.size();
|
||||||
TColgp_Array2OfPnt interpolationPoints(1, lu, 1, lv);
|
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 index1 = 0;
|
||||||
Standard_Integer index2 = 0;
|
Standard_Integer index2 = 0;
|
||||||
|
@ -1267,10 +1279,97 @@ PyObject* BSplineSurfacePy::interpolate(PyObject *args)
|
||||||
Py::List row(*it1);
|
Py::List row(*it1);
|
||||||
for (Py::List::iterator it2 = row.begin(); it2 != row.end(); ++it2) {
|
for (Py::List::iterator it2 = row.begin(); it2 != row.end(); ++it2) {
|
||||||
index2++;
|
index2++;
|
||||||
Py::Vector v(*it2);
|
if(len == 5){
|
||||||
Base::Vector3d pnt = v.toVector();
|
Py::Vector v(*it2);
|
||||||
gp_Pnt newPoint(pnt.x,pnt.y,pnt.z);
|
Base::Vector3d pnt = v.toVector();
|
||||||
interpolationPoints.SetValue(index1, index2, newPoint);
|
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* BSplineSurfacePy::interpolate(PyObject *args)
|
||||||
|
{
|
||||||
|
PyObject* obj;
|
||||||
|
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!|dddd",&(PyList_Type), &obj, &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);
|
||||||
|
|
||||||
|
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 == 1){
|
||||||
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1279,7 +1378,12 @@ PyObject* BSplineSurfacePy::interpolate(PyObject *args)
|
||||||
}
|
}
|
||||||
|
|
||||||
GeomAPI_PointsToBSplineSurface surInterpolation;
|
GeomAPI_PointsToBSplineSurface surInterpolation;
|
||||||
surInterpolation.Interpolate (interpolationPoints);
|
if(len == 1){
|
||||||
|
surInterpolation.Interpolate (interpolationPoints);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
surInterpolation.Interpolate(zPoints, X0, dX, Y0, dY);
|
||||||
|
}
|
||||||
Handle_Geom_BSplineSurface sur(surInterpolation.Surface());
|
Handle_Geom_BSplineSurface sur(surInterpolation.Surface());
|
||||||
this->getGeomBSplineSurfacePtr()->setHandle(sur);
|
this->getGeomBSplineSurfacePtr()->setHandle(sur);
|
||||||
Py_Return;
|
Py_Return;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user