Skip to content

Commit

Permalink
Part: Bezier serialization support extension to periodic
Browse files Browse the repository at this point in the history
=======================================================

Extension for periodic + suggestions by Werner.
  • Loading branch information
abdullahtahiriyo committed Jan 10, 2017
1 parent 61b685f commit e7dacb9
Showing 1 changed file with 41 additions and 50 deletions.
91 changes: 41 additions & 50 deletions src/Mod/Part/App/Geometry.cpp
Expand Up @@ -813,50 +813,49 @@ void GeomBSplineCurve::Save(Base::Writer& writer) const
GeomCurve::Save(writer);

std::vector<Base::Vector3d> poles = this->getPoles();
std::vector<double> weights = this->getWeights();
std::vector<double> knots = this->getKnots();
std::vector<int> mults = this->getMultiplicities();
int degree = this->getDegree();
std::vector<double> weights = this->getWeights();
std::vector<double> knots = this->getKnots();
std::vector<int> mults = this->getMultiplicities();
int degree = this->getDegree();
bool isperiodic = this->IsPeriodic();

writer.Stream()
<< writer.ind()
<< "<BSplineCurve "
<< "PolesCount=\"" << poles.size() <<
"\" KnotsCount=\"" << knots.size() <<
"\" Degree=\"" << degree <<
"\" IsPeriodic=\"" << (int) isperiodic <<
"\">" << endl;

writer.incInd();
for(std::vector<Base::Vector3d>::const_iterator it = poles.begin(); it != poles.end(); ++it){

std::vector<Base::Vector3d>::const_iterator itp;
std::vector<double>::const_iterator itw;

for(itp = poles.begin(), itw = weights.begin(); itp != poles.end() && itw != weights.end(); ++itp, ++itw){
writer.Stream()
<< writer.ind()
<< "<Pole "
<< "X=\"" << (*it).x <<
"\" Y=\"" << (*it).y <<
"\" Z=\"" << (*it).z <<
"\"/>" << endl;
}
for(std::vector<double>::const_iterator it = weights.begin(); it != weights.end(); ++it){
writer.Stream()
<< writer.ind()
<< "<Weight "
<< "value=\"" << (*it) <<
<< "X=\"" << (*itp).x <<
"\" Y=\"" << (*itp).y <<
"\" Z=\"" << (*itp).z <<
"\" Weight=\"" << (*itw) <<
"\"/>" << endl;
}
for(std::vector<double>::const_iterator it = knots.begin(); it != knots.end(); ++it){

std::vector<double>::const_iterator itk;
std::vector<int>::const_iterator itm;

for(itk = knots.begin(), itm = mults.begin(); itk != knots.end() && itm != mults.end(); ++itk, ++itm){
writer.Stream()
<< writer.ind()
<< "<Knot "
<< "value=\"" << (*it) <<
"\"/>" << endl;
}
for(std::vector<int>::const_iterator it = mults.begin(); it != mults.end(); ++it){
writer.Stream()
<< writer.ind()
<< "<Mult "
<< "value=\"" << (*it) <<
<< "Value=\"" << (*itk)
<< "\" Mult=\"" << (*itm) <<
"\"/>" << endl;
}

writer.decInd();
writer.Stream() << writer.ind() << "</BSplineCurve>" << endl ;
}
Expand All @@ -871,8 +870,8 @@ void GeomBSplineCurve::Restore(Base::XMLReader& reader)
int polescount = reader.getAttributeAsInteger("PolesCount");
int knotscount = reader.getAttributeAsInteger("KnotsCount");
int degree = reader.getAttributeAsInteger("Degree");

// You are here!!
bool isperiodic = (bool) reader.getAttributeAsInteger("IsPeriodic");

// Handle_Geom_BSplineCurve spline = new
// Geom_BSplineCurve(occpoles,occweights,occknots,occmults,degree,
// PyObject_IsTrue(periodic) ? Standard_True : Standard_False,
Expand All @@ -882,39 +881,31 @@ void GeomBSplineCurve::Restore(Base::XMLReader& reader)
TColStd_Array1OfReal w(1,polescount);
TColStd_Array1OfReal k(1,knotscount);
TColStd_Array1OfInteger m(1,knotscount);

for (int i = 1; i <= polescount; i++) {
reader.readElement("Pole");
double X = reader.getAttributeAsFloat("X");
double Y = reader.getAttributeAsFloat("Y");
double Z = reader.getAttributeAsFloat("Z");
p.SetValue(i, gp_Pnt(X,Y,Z));
}

for (int i = 1; i <= polescount; i++) {
reader.readElement("Weight");
double val = reader.getAttributeAsFloat("value");
w.SetValue(i, val);
double X = reader.getAttributeAsFloat("X");
double Y = reader.getAttributeAsFloat("Y");
double Z = reader.getAttributeAsFloat("Z");
double W = reader.getAttributeAsFloat("Weight");
p.SetValue(i, gp_Pnt(X,Y,Z));
w.SetValue(i, W);
}

for (int i = 1; i <= knotscount; i++) {
reader.readElement("Knot");
double val = reader.getAttributeAsFloat("value");
k.SetValue(i, val);
double val = reader.getAttributeAsFloat("Value");
Standard_Integer mult = reader.getAttributeAsInteger("Mult");
k.SetValue(i, val);
m.SetValue(i, mult);
}

for (int i = 1; i <= knotscount; i++) {
reader.readElement("Mult");
double val = reader.getAttributeAsInteger("value");
m.SetValue(i, val);
}


reader.readEndElement("BSplineCurve");
// Geom_BSplineCurve(occpoles,occweights,occknots,occmults,degree,periodic,CheckRational

try {
Handle_Geom_BSplineCurve spline = new Geom_BSplineCurve(p, w, k, m, degree, Standard_False, Standard_False);
Handle_Geom_BSplineCurve spline = new Geom_BSplineCurve(p, w, k, m, degree, isperiodic==true?Standard_True:Standard_False, Standard_False);

if (!spline.IsNull())
this->myCurve = spline;
else
Expand Down

0 comments on commit e7dacb9

Please sign in to comment.