Part: GeomBSpline extension for basic BSPline Sketcher support

==============================================================

1) Basic set/get interface for poles, weights, knots and multiplicities

2) Introduction of GeomBoundedCurve class replicating OCC hierarchy. Why? To provide seamless start/end point interface for any bounded curve, i.e. Bezier, BSpline,

Note: The ArcOfConic start/end point interface relies on GeomTrimmedCurve, and introduces CCW/CW correcting code which relies on Axis. Axis are introduced in GeomConic and are
not part of GeomBounded.

Note 2: In the future, it may be thought to make GeomArcOfConic (the equivalent of GeomTrimmedCurve) deriving from GeomBoundedCurve, as to fully replicate OCC hierarchy. GeomBoundedCurve
defines the functions as virtual to allow seamless integration.
This commit is contained in:
Abdullah Tahiri 2017-01-04 23:47:15 +01:00
parent 6ab6603f2e
commit b277620138
3 changed files with 179 additions and 4 deletions

View File

@ -460,6 +460,7 @@ PyMODINIT_FUNC initPart()
Part::Geometry ::init();
Part::GeomPoint ::init();
Part::GeomCurve ::init();
Part::GeomBoundedCurve ::init();
Part::GeomBezierCurve ::init();
Part::GeomBSplineCurve ::init();
Part::GeomConic ::init();

View File

@ -421,10 +421,37 @@ bool GeomCurve::closestParameterToBasicCurve(const Base::Vector3d& point, double
}
}
// -------------------------------------------------
TYPESYSTEM_SOURCE_ABSTRACT(Part::GeomBoundedCurve, Part::GeomCurve)
GeomBoundedCurve::GeomBoundedCurve()
{
}
GeomBoundedCurve::~GeomBoundedCurve()
{
}
Base::Vector3d GeomBoundedCurve::getStartPoint() const
{
Handle_Geom_BoundedCurve curve = Handle_Geom_BoundedCurve::DownCast(handle());
gp_Pnt pnt = curve->StartPoint();
return Base::Vector3d(pnt.X(), pnt.Y(), pnt.Z());
}
Base::Vector3d GeomBoundedCurve::getEndPoint() const
{
Handle_Geom_BoundedCurve curve = Handle_Geom_BoundedCurve::DownCast(handle());
gp_Pnt pnt = curve->EndPoint();
return Base::Vector3d(pnt.X(), pnt.Y(), pnt.Z());
}
// -------------------------------------------------
TYPESYSTEM_SOURCE(Part::GeomBezierCurve,Part::GeomCurve)
TYPESYSTEM_SOURCE(Part::GeomBezierCurve,Part::GeomBoundedCurve)
GeomBezierCurve::GeomBezierCurve()
{
@ -473,7 +500,7 @@ PyObject *GeomBezierCurve::getPyObject(void)
// -------------------------------------------------
TYPESYSTEM_SOURCE(Part::GeomBSplineCurve,Part::GeomCurve)
TYPESYSTEM_SOURCE(Part::GeomBSplineCurve,Part::GeomBoundedCurve)
GeomBSplineCurve::GeomBSplineCurve()
{
@ -538,6 +565,27 @@ void GeomBSplineCurve::setPole(int index, const Base::Vector3d& pole, double wei
}
}
void GeomBSplineCurve::setPoles(const std::vector<Base::Vector3d>& poles, const std::vector<double>& weights)
{
Standard_Integer index=0;
std::vector<Base::Vector3d>::const_iterator it1;
std::vector<double>::const_iterator it2;
for(it1 = poles.begin(), it2 = weights.begin(); it1 != poles.end() && it2 != weights.end(); ++it1, ++it2, index++){
setPole(index, (*it1), (*it2) );
}
}
void GeomBSplineCurve::setPoles(const std::vector<Base::Vector3d>& poles)
{
Standard_Integer index=0;
for(std::vector<Base::Vector3d>::const_iterator it1 = poles.begin(); it1 != poles.end(); ++it1, index++){
setPole(index, (*it1));
}
}
std::vector<Base::Vector3d> GeomBSplineCurve::getPoles() const
{
std::vector<Base::Vector3d> poles;
@ -552,6 +600,109 @@ std::vector<Base::Vector3d> GeomBSplineCurve::getPoles() const
return poles;
}
std::vector<double> GeomBSplineCurve::getWeights() const
{
std::vector<double> weights;
weights.reserve(myCurve->NbPoles());
TColStd_Array1OfReal w(1,myCurve->NbPoles());
myCurve->Weights(w);
for (Standard_Integer i=w.Lower(); i<=w.Upper(); i++) {
const Standard_Real& real = w(i);
weights.push_back(real);
}
return weights;
}
void GeomBSplineCurve::setWeights(const std::vector<double>& weights)
{
try {
Standard_Integer index=0;
for(std::vector<double>::const_iterator it = weights.begin(); it != weights.end(); ++it, index++){
myCurve->SetWeight(index,(*it));
}
}
catch (Standard_Failure) {
Handle_Standard_Failure e = Standard_Failure::Caught();
std::cout << e->GetMessageString() << std::endl;
}
}
void GeomBSplineCurve::setKnot(int index, const double val, int mult)
{
try {
if (mult < 0)
myCurve->SetKnot(index+1, val);
else
myCurve->SetKnot(index+1, val, mult);
}
catch (Standard_Failure) {
Handle_Standard_Failure e = Standard_Failure::Caught();
std::cout << e->GetMessageString() << std::endl;
}
}
void GeomBSplineCurve::setKnots(const std::vector<double>& knots)
{
Standard_Integer index=0;
for(std::vector<double>::const_iterator it1 = knots.begin(); it1 != knots.end(); ++it1, index++){
setKnot(index, (*it1));
}
}
void GeomBSplineCurve::setKnots(const std::vector<double>& knots, const std::vector<int> multiplicities)
{
Standard_Integer index=0;
std::vector<double>::const_iterator it1;
std::vector<int>::const_iterator it2;
for(it1 = knots.begin(), it2 = multiplicities.begin(); it1 != knots.end() && it2 != multiplicities.end(); ++it1, ++it2, index++){
setKnot(index, (*it1), (*it2) );
}
}
std::vector<double> GeomBSplineCurve::getKnots() const
{
std::vector<double> knots;
knots.reserve(myCurve->NbKnots());
TColStd_Array1OfReal k(1,myCurve->NbKnots());
myCurve->Knots(k);
for (Standard_Integer i=k.Lower(); i<=k.Upper(); i++) {
const Standard_Real& real = k(i);
knots.push_back(real);
}
return knots;
}
std::vector<int> GeomBSplineCurve::getMultiplicities() const
{
std::vector<int> mults;
mults.reserve(myCurve->NbKnots());
TColStd_Array1OfInteger m(1,myCurve->NbKnots());
myCurve->Multiplicities(m);
for (Standard_Integer i=m.Lower(); i<=m.Upper(); i++) {
const Standard_Integer& nm = m(i);
mults.push_back(nm);
}
return mults;
}
int GeomBSplineCurve::getDegree() const
{
return myCurve->Degree();
}
bool GeomBSplineCurve::IsPeriodic() const
{
return myCurve->IsPeriodic()==Standard_True;
}
bool GeomBSplineCurve::join(const Handle_Geom_BSplineCurve& spline)
{
GeomConvert_CompCurveToBSplineCurve ccbc(this->myCurve);

View File

@ -130,7 +130,19 @@ public:
bool closestParameterToBasicCurve(const Base::Vector3d& point, double &u) const;
};
class PartExport GeomBezierCurve : public GeomCurve
class PartExport GeomBoundedCurve : public GeomCurve
{
TYPESYSTEM_HEADER();
public:
GeomBoundedCurve();
virtual ~GeomBoundedCurve();
// Geometry helper
virtual Base::Vector3d getStartPoint() const;
virtual Base::Vector3d getEndPoint() const;
};
class PartExport GeomBezierCurve : public GeomBoundedCurve
{
TYPESYSTEM_HEADER();
public:
@ -153,7 +165,7 @@ private:
Handle_Geom_BezierCurve myCurve;
};
class PartExport GeomBSplineCurve : public GeomCurve
class PartExport GeomBSplineCurve : public GeomBoundedCurve
{
TYPESYSTEM_HEADER();
public:
@ -183,7 +195,18 @@ public:
int countPoles() const;
void setPole(int index, const Base::Vector3d&, double weight=-1);
void setPoles(const std::vector<Base::Vector3d>& poles, const std::vector<double>& weights);
void setPoles(const std::vector<Base::Vector3d>& poles);
void setWeights(const std::vector<double>& weights);
void setKnot(int index, const double val, int mult=-1);
void setKnots(const std::vector<double>& knots);
void setKnots(const std::vector<double>& knots, const std::vector<int> multiplicities);
std::vector<Base::Vector3d> getPoles() const;
std::vector<double> getWeights() const;
std::vector<double> getKnots() const;
std::vector<int> getMultiplicities() const;
int getDegree() const;
bool IsPeriodic() const;
bool join(const Handle_Geom_BSplineCurve&);
void makeC1Continuous(double, double);
std::list<Geometry*> toBiArcs(double tolerance) const;