+ include pcl bspline fit into Reverse Engineering module

This commit is contained in:
wmayer
2015-10-30 22:06:34 +01:00
parent e7d16c5f62
commit 212e2bf19c
4 changed files with 344 additions and 0 deletions

View File

@@ -41,6 +41,7 @@
#include <Mod/Points/App/PointsPy.h>
#include "ApproxSurface.h"
#include "BSplineFitting.h"
#include "SurfaceTriangulation.h"
using namespace Reen;
@@ -60,6 +61,9 @@ public:
add_varargs_method("triangulate",&Module::triangulate,
"triangulate(PointKernel,searchRadius[,mu=2.5])."
);
add_keyword_method("fitBSpline",&Module::fitBSpline,
"fitBSpline(PointKernel)."
);
#endif
initialize("This module is the ReverseEngineering module."); // register with Python
}
@@ -176,6 +180,45 @@ private:
return Py::asObject(new Mesh::MeshPy(mesh));
}
Py::Object fitBSpline(const Py::Tuple& args, const Py::Dict& kwds)
{
PyObject *pcObj;
int degree = 2;
int refinement = 4;
int iterations = 10;
double interiorSmoothness = 0.2;
double interiorWeight = 1.0;
double boundarySmoothness = 0.2;
double boundaryWeight = 0.0;
static char* kwds_approx[] = {"Points", "Degree", "Refinement", "Iterations",
"InteriorSmoothness", "InteriorWeight", "BoundarySmoothness", "BoundaryWeight", NULL};
if (!PyArg_ParseTupleAndKeywords(args.ptr(), kwds.ptr(), "O!|iiidddd", kwds_approx,
&(Points::PointsPy::Type), &pcObj,
&degree, &refinement, &iterations,
&interiorSmoothness, &interiorWeight,
&boundarySmoothness, &boundaryWeight))
throw Py::Exception();
Points::PointsPy* pPoints = static_cast<Points::PointsPy*>(pcObj);
Points::PointKernel* points = pPoints->getPointKernelPtr();
BSplineFitting fit(points->getBasicPoints());
fit.setOrder(degree+1);
fit.setRefinement(refinement);
fit.setIterations(iterations);
fit.setInteriorSmoothness(interiorSmoothness);
fit.setInteriorWeight(interiorWeight);
fit.setBoundarySmoothness(boundarySmoothness);
fit.setBoundaryWeight(boundaryWeight);
Handle(Geom_BSplineSurface) hSurf = fit.perform();
if (!hSurf.IsNull()) {
return Py::asObject(new Part::BSplineSurfacePy(new Part::GeomBSplineSurface(hSurf)));
}
throw Py::RuntimeError("Computation of B-Spline surface failed");
}
#endif
};
} // namespace Reen