add methods to convert a curve to a B-Spline or NURBS

This commit is contained in:
wmayer
2017-02-13 10:38:09 +01:00
parent b96b275579
commit becdede5c0
4 changed files with 67 additions and 8 deletions

View File

@@ -95,7 +95,7 @@
# include <GC_MakeSegment.hxx>
# include <Precision.hxx>
# include <GeomAPI_ProjectPointOnCurve.hxx>
# include <ShapeConstruct_Curve.hxx>
#endif
#include <Base/VectorPy.h>
@@ -318,6 +318,21 @@ TopoDS_Shape GeomCurve::toShape() const
return mkBuilder.Shape();
}
GeomBSplineCurve* GeomCurve::toBSpline(double first, double last) const
{
ShapeConstruct_Curve scc;
Handle_Geom_Curve c = Handle_Geom_Curve::DownCast(handle());
Handle_Geom_BSplineCurve spline = scc.ConvertToBSpline(c, first, last, Precision::Confusion());
if (spline.IsNull())
throw Base::RuntimeError("Conversion to B-Spline failed");
return new GeomBSplineCurve(spline);
}
GeomBSplineCurve* GeomCurve::toNurbs(double first, double last) const
{
return toBSpline(first, last);
}
bool GeomCurve::tangent(double u, gp_Dir& dir) const
{
Handle_Geom_Curve c = Handle_Geom_Curve::DownCast(handle());

View File

@@ -97,7 +97,7 @@ public:
virtual Geometry *clone(void) const;
virtual TopoDS_Shape toShape() const;
// Persistence implementer ---------------------
// Persistence implementer ---------------------
virtual unsigned int getMemSize(void) const;
virtual void Save(Base::Writer &/*writer*/) const;
virtual void Restore(Base::XMLReader &/*reader*/);
@@ -113,6 +113,7 @@ private:
Handle_Geom_CartesianPoint myPoint;
};
class GeomBSplineCurve;
class PartExport GeomCurve : public Geometry
{
TYPESYSTEM_HEADER();
@@ -121,6 +122,19 @@ public:
virtual ~GeomCurve();
TopoDS_Shape toShape() const;
/*!
* \brief toBSpline Converts the curve to a B-Spline
* \param This is the start parameter of the curve
* \param This is the end parameter of the curve
* \return a B-Spline curve
*/
GeomBSplineCurve* toBSpline(double first, double last) const;
/*!
The default implementation does the same as \ref toBSpline.
In sub-classes this can be reimplemented to create a real
NURBS curve and not just an approximation.
*/
virtual GeomBSplineCurve* toNurbs(double first, double last) const;
bool tangent(double u, gp_Dir&) const;
Base::Vector3d pointAtParameter(double u) const;
Base::Vector3d firstDerivativeAtParameter(double u) const;

View File

@@ -140,7 +140,15 @@ of the nearest orthogonal projection of the point.</UserDocu>
</UserDocu>
</Documentation>
</Methode>
<Methode Name="approximateBSpline">
<Methode Name="toNurbs">
<Documentation>
<UserDocu>
Converts a curve of any type (only part from First to Last)
toNurbs([Float=First, Float=Last]) -> NURBS curve
</UserDocu>
</Documentation>
</Methode>
<Methode Name="approximateBSpline">
<Documentation>
<UserDocu>
Approximates a curve of any type to a B-Spline curve

View File

@@ -587,11 +587,33 @@ PyObject* GeometryCurvePy::toBSpline(PyObject * args)
v=c->LastParameter();
if (!PyArg_ParseTuple(args, "|dd", &u,&v))
return 0;
ShapeConstruct_Curve scc;
Handle_Geom_BSplineCurve spline = scc.ConvertToBSpline(c, u, v, Precision::Confusion());
if (spline.IsNull())
Standard_NullValue::Raise("Conversion to B-Spline failed");
return new BSplineCurvePy(new GeomBSplineCurve(spline));
GeomBSplineCurve* spline = getGeomCurvePtr()->toBSpline(u, v);
return new BSplineCurvePy(spline);
}
}
catch (Standard_Failure) {
Handle_Standard_Failure e = Standard_Failure::Caught();
PyErr_SetString(PartExceptionOCCError, e->GetMessageString());
return 0;
}
PyErr_SetString(PartExceptionOCCError, "Geometry is not a curve");
return 0;
}
PyObject* GeometryCurvePy::toNurbs(PyObject * args)
{
Handle_Geom_Geometry g = getGeometryPtr()->handle();
Handle_Geom_Curve c = Handle_Geom_Curve::DownCast(g);
try {
if (!c.IsNull()) {
double u,v;
u=c->FirstParameter();
v=c->LastParameter();
if (!PyArg_ParseTuple(args, "|dd", &u,&v))
return 0;
GeomBSplineCurve* spline = getGeomCurvePtr()->toNurbs(u, v);
return new BSplineCurvePy(spline);
}
}
catch (Standard_Failure) {