#include <GCPnts_QuasiUniformDeflection.hxx>
#include <GCPnts_UniformDeflection.hxx>
#include <GCPnts_TangentialDeflection.hxx>
+#include <GCPnts_DistFunction.hxx>
#include <GeomAPI_ExtremaCurveCurve.hxx>
#include <gce_MakeLin.hxx>
#include <TColStd_Array1OfBoolean.hxx>
//epa test
#include <BRepBuilderAPI_MakeEdge.hxx>
#include <AIS_Shape.hxx>
+#include <TopoDS.hxx>
#include <TopoDS_Edge.hxx>
+#include <TopoDS_Wire.hxx>
+#include <BRepAdaptor_HCompCurve.hxx>
#include <GeomLProp_CLProps.hxx>
#include <GCPnts_AbscissaPoint.hxx>
#include <GCPnts_UniformAbscissa.hxx>
ONE = 2;
}
else {
- di << "gproject wait 2 or 3 arguments" << "\n";
+ di << "gproject wait 2 or 3 arguments\n";
return 1;
}
Standard_Integer k;
Standard_Real Udeb, Ufin, UIso, VIso;
- Standard_Integer Only2d, Only3d;
+ Standard_Boolean Only2d, Only3d;
gp_Pnt2d P2d, Pdeb, Pfin;
gp_Pnt P;
Handle(Adaptor2d_HCurve2d) HPCur;
Sprintf(newname,"%s_%d",name,k);
Sprintf(newname1,"%s2d_%d",name,k);
if(Projector.IsSinglePnt(k, P2d)){
-// cout<<"Part "<<k<<" of the projection is punctual"<<endl;
+// std::cout<<"Part "<<k<<" of the projection is punctual"<<std::endl;
Projector.GetSurface()->D0(P2d.X(), P2d.Y(), P);
DrawTrSurf::Set(temp, P);
DrawTrSurf::Set(temp1, P2d);
- di<<temp<<" is 3d projected curve"<<"\n";
- di<<temp1<<" is pcurve"<<"\n";
+ di<<temp<<" is 3d projected curve\n";
+ di<<temp1<<" is pcurve\n";
}
else {
Only2d = Only3d = Standard_False;
gp_Dir2d Dir; // Only for isoparametric projection
if (Projector.IsUIso(k, UIso)) {
-// cout<<"Part "<<k<<" of the projection is U-isoparametric curve"<<endl;
+// std::cout<<"Part "<<k<<" of the projection is U-isoparametric curve"<<std::endl;
Projector.D0(Udeb, Pdeb);
Projector.D0(Ufin, Pfin);
Udeb = Pdeb.Y();
Only3d = Standard_True;
}
else if(Projector.IsVIso(k, VIso)) {
-// cout<<"Part "<<k<<" of the projection is V-isoparametric curve"<<endl;
+// std::cout<<"Part "<<k<<" of the projection is V-isoparametric curve"<<std::endl;
Projector.D0(Udeb, Pdeb);
Projector.D0(Ufin, Pfin);
Udeb = Pdeb.X();
Handle(Geom_Curve) OutCur = new Geom_TrimmedCurve(GeomAdaptor::MakeCurve(hcur->Curve()), Ufin, Udeb);
DrawTrSurf::Set(temp, OutCur);
DrawTrSurf::Set(temp1, PCur2d);
- di<<temp<<" is 3d projected curve"<<"\n";
- di<<temp1<<" is pcurve"<<"\n";
+ di<<temp<<" is 3d projected curve\n";
+ di<<temp1<<" is pcurve\n";
return 0;
}
else {
- Approx_CurveOnSurface appr(HPCur, hsur, Udeb, Ufin, myTol3d,
- myContinuity, myMaxDegree, myMaxSeg,
- Only3d, Only2d);
+ Approx_CurveOnSurface appr(HPCur, hsur, Udeb, Ufin, myTol3d);
+ appr.Perform(myMaxSeg, myMaxDegree, myContinuity, Only3d, Only2d);
if(!Only3d) {
PCur2d = appr.Curve2d();
di << " Error in 2d is " << appr.MaxError2dU()
DrawTrSurf::Set(temp, appr.Curve3d());
}
DrawTrSurf::Set(temp1, PCur2d);
- di<<temp<<" is 3d projected curve"<<"\n";
- di<<temp1<<" is pcurve"<<"\n";
+ di<<temp<<" is 3d projected curve\n";
+ di<<temp1<<" is pcurve\n";
}
}
}
{
if ( n == 1) {
- di << "project result2d c3d surf [-e p] [-v n] [-t tol]" << "\n";
- di << " -e p : extent the surface of <p>%" << "\n";
- di << " -v n : verify the projection at <n> points." << "\n";
- di << " -t tol : set the tolerance for approximation" << "\n";
+ di << "project result2d c3d surf [-e p] [-v n] [-t tol]\n";
+ di << " -e p : extent the surface of <p>%\n";
+ di << " -v n : verify the projection at <n> points.\n";
+ di << " -t tol : set the tolerance for approximation\n";
return 0;
}
GeomProjLib::Curve2d(GC, GS, U1, U2, V1, V2, tolerance);
if ( G2d.IsNull() ) {
- di << "\n" << "Projection Failed" << "\n";
+ di << "\nProjection Failed\n";
return 1;
}
else {
}
if ( Verif) { // verify the projection on n points
if ( NbPoints <= 0) {
- di << " n must be positive" << "\n";
+ di << " n must be positive\n";
return 0;
}
gp_Pnt P1,P2;
Handle(Geom_Plane) Pl = Handle(Geom_Plane)::DownCast(S);
if ( Pl.IsNull()) {
- di << " The surface must be a plane" << "\n";
+ di << " The surface must be a plane\n";
return 1;
}
}
}
else {
- di << " Bisec has failed !!" << "\n";
+ di << " Bisec has failed !!\n";
return 1;
}
}
}
}
else {
- di << " Bisec has failed !!" << "\n";
+ di << " Bisec has failed !!\n";
return 1;
}
}
}
}
else {
- di << " Bisec has failed !!" << "\n";
+ di << " Bisec has failed !!\n";
return 1;
}
}
}
}
else {
- di << " Bisec has failed !!" << "\n";
+ di << " Bisec has failed !!\n";
return 1;
}
}
else {
- di << " args must be line/circle/point line/circle/point" << "\n";
+ di << " args must be line/circle/point line/circle/point\n";
return 1;
}
}
}
}
else {
- di << " Bisec has failed !!" << "\n";
+ di << " Bisec has failed !!\n";
return 1;
}
}
solution(Bis.ThisSolution(),a[1],0);
}
else {
- di << " Bisec has failed !!" << "\n";
+ di << " Bisec has failed !!\n";
return 1;
}
}
}
else {
- di << " the second arg must be line/circle/point " << "\n";
+ di << " the second arg must be line/circle/point \n";
}
}
else if ( ip1) {
}
}
else {
- di << " Bisec has failed !!" << "\n";
+ di << " Bisec has failed !!\n";
return 1;
}
}
solution(Bis.ThisSolution(),a[1],0);
}
else {
- di << " Bisec has failed !!" << "\n";
+ di << " Bisec has failed !!\n";
return 1;
}
}
DrawTrSurf::Set(a[1],new Geom2d_Line(Bis.ThisSolution()));
}
else {
- di << " Bisec has failed !!" << "\n";
+ di << " Bisec has failed !!\n";
return 1;
}
}
else {
- di << " the second arg must be line/circle/point " << "\n";
+ di << " the second arg must be line/circle/point \n";
return 1;
}
}
else {
- di << " args must be line/circle/point line/circle/point" << "\n";
+ di << " args must be line/circle/point line/circle/point\n";
return 1;
}
if ( NbSol >= 2) {
- di << "There are " << NbSol << " Solutions." << "\n";
+ di << "There are " << NbSol << " Solutions.\n";
}
else {
- di << "There is " << NbSol << " Solution." << "\n";
+ di << "There is " << NbSol << " Solution.\n";
}
return 0;
Draw::Repaint();
}
else {
- di << "Not enought degree of freedom increase degree please" << "\n";
+ di << "Not enought degree of freedom increase degree please\n";
}
//Static method computing deviation of curve and polyline
#include <math_PSO.hxx>
#include <math_PSOParticlesPool.hxx>
-#include <math_MultipleVarFunctionWithHessian.hxx>
-#include <math_NewtonMinimum.hxx>
+#include <math_MultipleVarFunction.hxx>
+#include <math_BrentMinimum.hxx>
-class aMaxCCDist : public math_MultipleVarFunctionWithHessian
-{
-public:
- aMaxCCDist(const Handle(Geom_Curve)& theCurve,
- const Handle(Geom_BSplineCurve)& thePnts)
-: myCurve(theCurve),
- myPnts(thePnts)
- {
- }
-
- virtual Standard_Boolean Value (const math_Vector& X,
- Standard_Real& F)
- {
- if (!CheckInputData(X(1)))
- {
- return Standard_False;
- }
- F = -myCurve->Value(X(1)).SquareDistance(myPnts->Value(X(1)));
- return Standard_True;
- }
-
-
- virtual Standard_Boolean Gradient (const math_Vector& X, math_Vector& G)
- {
- if (!CheckInputData(X(1)))
- {
- return Standard_False;
- }
- gp_Pnt aPnt1, aPnt2;
- gp_Vec aVec1, aVec2;
- myCurve->D1(X(1), aPnt1, aVec1);
- myPnts->D1 (X(1), aPnt2, aVec2);
-
- G(1) = 2 * (aPnt1.X() - aPnt2.X()) * (aVec1.X() - aVec2.X())
- + 2 * (aPnt1.Y() - aPnt2.Y()) * (aVec1.Y() - aVec2.Y())
- + 2 * (aPnt1.Z() - aPnt2.Z()) * (aVec1.Z() - aVec2.Z());
- G(1) *= -1.0; // Maximum search.
+static Standard_Real CompLocalDev(const Adaptor3d_Curve& theCurve,
+ const Standard_Real u1, const Standard_Real u2);
- return Standard_True;
- }
-
- virtual Standard_Boolean Values (const math_Vector& X, Standard_Real& F, math_Vector& G, math_Matrix& H)
- {
- if (Value(X, F) && Gradient(X, G))
- {
- gp_Pnt aPnt1, aPnt2;
- gp_Vec aVec11, aVec12, aVec21, aVec22;
- myCurve->D2(X(1), aPnt1, aVec11, aVec12);
- myPnts->D2 (X(1), aPnt2, aVec21, aVec22);
-
- H(1,1) = 2 * (aVec11.X() - aVec21.X()) * (aVec11.X() - aVec21.X())
- + 2 * (aVec11.Y() - aVec21.Y()) * (aVec11.Y() - aVec21.Y())
- + 2 * (aVec11.Z() - aVec21.Z()) * (aVec11.Z() - aVec21.Z())
- + 2 * (aPnt1.X() - aPnt2.X()) * (aVec12.X() - aVec22.X())
- + 2 * (aPnt1.Y() - aPnt2.Y()) * (aVec12.Y() - aVec22.Y())
- + 2 * (aPnt1.Z() - aPnt2.Z()) * (aVec12.Z() - aVec22.Z());
- H(1,1) *= -1.0; // Maximum search.
-
- return Standard_True;
- }
- return Standard_False;
- }
-
- virtual Standard_Boolean Values (const math_Vector& X, Standard_Real& F, math_Vector& G)
- {
- return (Value(X, F) && Gradient(X, G));
- }
-
- virtual Standard_Integer NbVariables() const
- {
- return 1;
- }
-
-private:
- aMaxCCDist & operator = (const aMaxCCDist & theOther);
-
- Standard_Boolean CheckInputData(Standard_Real theParam)
- {
- if (theParam < myCurve->FirstParameter() ||
- theParam > myCurve->LastParameter())
- return Standard_False;
- return Standard_True;
- }
-
- const Handle(Geom_Curve)& myCurve;
- const Handle(Geom_BSplineCurve)& myPnts;
-};
-
-
-static void ComputeDeviation(const Handle(Geom_Curve)& theCurve,
+static void ComputeDeviation(const Adaptor3d_Curve& theCurve,
const Handle(Geom_BSplineCurve)& thePnts,
Standard_Real& theDmax,
Standard_Real& theUfMax,
Standard_Integer nbp = thePnts->NbKnots();
TColStd_Array1OfReal aKnots(1, nbp);
thePnts->Knots(aKnots);
- math_Vector aLowBorder(1,1);
- math_Vector aUppBorder(1,1);
- math_Vector aSteps(1,1);
Standard_Integer i;
for(i = 1; i < nbp; ++i)
{
- aLowBorder(1) = aKnots(i);
- aUppBorder(1) = aKnots(i+1);
- aSteps(1) =(aUppBorder(1) - aLowBorder(1)) * 0.01; // Run PSO on even distribution with 100 points.
-
- Standard_Real aValue;
- math_Vector aT(1,1);
- aMaxCCDist aFunc(theCurve, thePnts);
- math_PSO aFinder(&aFunc, aLowBorder, aUppBorder, aSteps); // Choose 32 best points from 100 above.
- aFinder.Perform(aSteps, aValue, aT);
- Standard_Real d = 0.;
-
- math_NewtonMinimum anOptLoc(aFunc);
- anOptLoc.Perform(aFunc, aT);
-
- if (anOptLoc.IsDone())
+ Standard_Real u1 = aKnots(i), u2 = aKnots(i+1);
+ Standard_Real d = CompLocalDev(theCurve, u1, u2);
+ if(d > theDmax)
{
- d = -anOptLoc.Minimum();
- if(d > theDmax)
- {
- theDmax = d;
- theUfMax = aLowBorder(1);
- theUlMax = aUppBorder(1);
- theImax = i;
- }
+ theDmax = d;
+ theImax = i;
+ theUfMax = u1;
+ theUlMax = u2;
}
}
- theDmax = Sqrt(theDmax); // Convert to Euclidean distance.
}
+Standard_Real CompLocalDev(const Adaptor3d_Curve& theCurve,
+ const Standard_Real u1, const Standard_Real u2)
+{
+ math_Vector aLowBorder(1,1);
+ math_Vector aUppBorder(1,1);
+ math_Vector aSteps(1,1);
+ //
+ aLowBorder(1) = u1;
+ aUppBorder(1) = u2;
+ aSteps(1) =(aUppBorder(1) - aLowBorder(1)) * 0.01; // Run PSO on even distribution with 100 points.
+ //
+ GCPnts_DistFunction aFunc1(theCurve, u1, u2);
+ //
+ Standard_Real aValue;
+ math_Vector aT(1,1);
+ GCPnts_DistFunctionMV aFunc(aFunc1);
+
+ math_PSO aFinder(&aFunc, aLowBorder, aUppBorder, aSteps); // Choose 32 best points from 100 above.
+ aFinder.Perform(aSteps, aValue, aT);
+ Standard_Real d = 0.;
+
+ Standard_Real d1, d2;
+ Standard_Real x1 = Max(u1, aT(1) - aSteps(1));
+ Standard_Boolean Ok = aFunc1.Value(x1, d1);
+ if(!Ok)
+ {
+ return Sqrt(-aValue);
+ }
+ Standard_Real x2 = Min(u2, aT(1) + aSteps(1));
+ Ok = aFunc1.Value(x2, d2);
+ if(!Ok)
+ {
+ return Sqrt(-aValue);
+ }
+ if(!(d1 > aValue && d2 > aValue))
+ {
+ Standard_Real dmin = Min(d1, Min(aValue, d2));
+ return Sqrt(-dmin);
+ }
+
+ math_BrentMinimum anOptLoc(Precision::PConfusion());
+ anOptLoc.Perform(aFunc1, x1, aT(1), x2);
+
+ if (anOptLoc.IsDone())
+ {
+ d = -anOptLoc.Minimum();
+ }
+ else
+ {
+ d = -aValue;
+ }
+ return Sqrt(d);
+}
//=======================================================================
//function : crvpoints
Standard_Integer i, nbp;
Standard_Real defl;
+ Handle(Adaptor3d_HCurve) aHCurve;
Handle(Geom_Curve) C = DrawTrSurf::GetCurve(a[2]);
+ if (C.IsNull())
+ {
+ // try getting a wire
+ TopoDS_Wire aWire = TopoDS::Wire(DBRep::Get(a[2], TopAbs_WIRE));
+ if (aWire.IsNull())
+ {
+ std::cout << "cannot evaluate the argument " << a[2] << " as a curve" << std::endl;
+ return 1;
+ }
+ BRepAdaptor_CompCurve aCompCurve(aWire);
+ aHCurve = new BRepAdaptor_HCompCurve(aCompCurve);
+ }
+ else
+ {
+ aHCurve = new GeomAdaptor_HCurve(C);
+ }
+
defl = Draw::Atof(a[3]);
- GeomAdaptor_Curve GAC(C);
- GCPnts_QuasiUniformDeflection PntGen(GAC, defl);
+ GCPnts_QuasiUniformDeflection PntGen(aHCurve->Curve(), defl);
if(!PntGen.IsDone()) {
- di << "Points generation failed" << "\n";
+ di << "Points generation failed\n";
return 1;
}
Standard_Integer imax = 0;
//check deviation
- ComputeDeviation(C,aPnts,dmax,ufmax,ulmax,imax);
+ ComputeDeviation(aHCurve->Curve(), aPnts, dmax, ufmax, ulmax, imax);
di << "Max defl: " << dmax << " " << ufmax << " " << ulmax << " " << imax << "\n";
return 0;
static Standard_Integer crvtpoints (Draw_Interpretor& di, Standard_Integer n, const char** a)
{
- Standard_Integer i, nbp;
+ Standard_Integer i, nbp, aMinPntsNb = 2;
Standard_Real defl, angle = Precision::Angular();
+ Handle(Adaptor3d_HCurve) aHCurve;
Handle(Geom_Curve) C = DrawTrSurf::GetCurve(a[2]);
+ if (C.IsNull())
+ {
+ // try getting a wire
+ TopoDS_Wire aWire = TopoDS::Wire(DBRep::Get(a[2], TopAbs_WIRE));
+ if (aWire.IsNull())
+ {
+ std::cout << "cannot evaluate the argument " << a[2] << " as a curve" << std::endl;
+ return 1;
+ }
+ BRepAdaptor_CompCurve aCompCurve(aWire);
+ aHCurve = new BRepAdaptor_HCompCurve(aCompCurve);
+ }
+ else
+ {
+ aHCurve = new GeomAdaptor_HCurve(C);
+ }
defl = Draw::Atof(a[3]);
- if(n > 3)
+ if(n > 4)
angle = Draw::Atof(a[4]);
- GeomAdaptor_Curve GAC(C);
- GCPnts_TangentialDeflection PntGen(GAC, angle, defl, 2);
+ if(n > 5)
+ aMinPntsNb = Draw::Atoi (a[5]);
+
+ GCPnts_TangentialDeflection PntGen(aHCurve->Curve(), angle, defl, aMinPntsNb);
nbp = PntGen.NbPoints();
di << "Nb points : " << nbp << "\n";
Standard_Integer imax = 0;
//check deviation
- ComputeDeviation(C,aPnts,dmax,ufmax,ulmax,imax);
+ ComputeDeviation(aHCurve->Curve(), aPnts, dmax, ufmax, ulmax, imax);
+ //
di << "Max defl: " << dmax << " " << ufmax << " " << ulmax << " " << imax << "\n";
return 0;
ellip = DrawTrSurf::GetBSplineCurve(a[1]);
if (ellip.IsNull())
{
- di << " BSpline is NULL "<<"\n";
+ di << " BSpline is NULL \n";
return 1;
}*/
ellip = DrawTrSurf::GetCurve(a[1]);
if (ellip.IsNull())
{
- di << " Curve is NULL "<<"\n";
+ di << " Curve is NULL \n";
return 1;
}
}
}
- catch (Standard_Failure )
+ catch (Standard_Failure const&)
{
- di << " Standard Failure " <<"\n";
+ di << " Standard Failure \n";
}
return 0;
}
DBRep::Set("Ellipse",edge_curve);
}
- catch(Standard_Failure)
+ catch(Standard_Failure const&)
{
- di << " Standard Failure "<<"\n";
+ di << " Standard Failure \n";
}
try
}
}
- catch (Standard_Failure )
+ catch (Standard_Failure const&)
{
- di << " Standard Failure " <<"\n";
+ di << " Standard Failure \n";
}
return 0;
}
Standard_Real dmax = 0., ufmax = 0., ulmax = 0.;
Standard_Integer imax = 0;
- ComputeDeviation(C,aPnts,dmax,ufmax,ulmax,imax);
+ ComputeDeviation(GeomAdaptor_Curve(C),aPnts,dmax,ufmax,ulmax,imax);
di << "Max defl: " << dmax << " " << ufmax << " " << ulmax << " " << imax << "\n";
return 0;
}//else if (n == 8 || n == 9 || n == 12 || n == 13 || n == 16 || n == 17)
else
{
- di<<"incorrect number of arguments"<<"\n";
+ di<<"incorrect number of arguments\n";
return 1;
}
//
if (!Inters.IsDone())
{
- di<<"No intersections found!"<<"\n";
+ di<<"No intersections found!\n";
return 1;
}
//
if (!Inters.IsDone())
{
- di<<"No intersections found!"<<"\n";
+ di<<"No intersections found!\n";
return 1;
}
Standard_Integer Compt = 1;
if(nblines >= 1)
- cout << " Lines: " << endl;
+ std::cout << " Lines: " << std::endl;
for (i = 1; i <= nblines; i++, Compt++)
{
}
if(nbpoints >= 1)
- cout << " Points: " << endl;
+ std::cout << " Points: " << std::endl;
const Standard_Integer imax = nblines+nbpoints;
intersection,g);
theCommands.Add("crvpoints",
- "crvpoints result curv deflection",
+ "crvpoints result <curve or wire> deflection",
__FILE__,
crvpoints,g);
theCommands.Add("crvtpoints",
- "crvtpoints result curv deflection angular deflection - tangential deflection points",
+ "crvtpoints result <curve or wire> deflection angular deflection - tangential deflection points",
__FILE__,
crvtpoints,g);