1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-14 13:30:48 +03:00

Coding - Apply .clang-format formatting #286

Update empty method guards to new style with regex (see PR).
Used clang-format 18.1.8.
New actions to validate code formatting is added.
Update .clang-format with disabling of include sorting.
  It is temporary changes, then include will be sorted.
Apply formatting for /src and /tools folder.
The files with .hxx,.cxx,.lxx,.h,.pxx,.hpp,*.cpp extensions.
This commit is contained in:
dpasukhi
2025-01-25 20:15:22 +00:00
parent dbba6f1289
commit a5a7b3185b
14005 changed files with 1273539 additions and 1195567 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -1,5 +1,5 @@
// Created on: 1991-10-03
// Created by: JeanClaude VAUTHIER
// Created by: JeanClaude VAUTHIER
// Copyright (c) 1991-1999 Matra Datavision
// Copyright (c) 1999-2014 OPEN CASCADE SAS
//
@@ -34,7 +34,6 @@ class Geom_BSplineSurface;
class Geom_Curve;
class Geom_Surface;
//! The GeomConvert package provides some global functions as follows
//! - converting classical Geom curves into BSpline curves,
//! - segmenting BSpline curves, particularly at knots
@@ -60,13 +59,11 @@ class Geom_Surface;
//! 1987
//! . A survey of curve and surface methods in CAGD (Wolfgang BOHM)
//! CAGD 1 1984
class GeomConvert
class GeomConvert
{
public:
DEFINE_STANDARD_ALLOC
//! Convert a curve from Geom by an approximation method
//!
//! This method computes the arc of B-spline curve between the two
@@ -83,11 +80,11 @@ public:
//! Raised if FromK1 = ToK2
//! Raised if FromK1 or ToK2 are out of the bounds
//! [FirstUKnotIndex, LastUKnotIndex]
Standard_EXPORT static Handle(Geom_BSplineCurve) SplitBSplineCurve (const Handle(Geom_BSplineCurve)& C,
const Standard_Integer FromK1,
const Standard_Integer ToK2,
const Standard_Boolean SameOrientation = Standard_True);
Standard_EXPORT static Handle(Geom_BSplineCurve) SplitBSplineCurve(
const Handle(Geom_BSplineCurve)& C,
const Standard_Integer FromK1,
const Standard_Integer ToK2,
const Standard_Boolean SameOrientation = Standard_True);
//! This function computes the segment of B-spline curve between the
//! parametric values FromU1, ToU2.
@@ -104,12 +101,12 @@ public:
//! curve (The tolerance criterion is ParametricTolerance).
//! Raised if Abs (FromU1 - ToU2) <= ParametricTolerance
//! Raised if ParametricTolerance < Resolution from gp.
Standard_EXPORT static Handle(Geom_BSplineCurve) SplitBSplineCurve (const Handle(Geom_BSplineCurve)& C,
const Standard_Real FromU1,
const Standard_Real ToU2,
const Standard_Real ParametricTolerance,
const Standard_Boolean SameOrientation = Standard_True);
Standard_EXPORT static Handle(Geom_BSplineCurve) SplitBSplineCurve(
const Handle(Geom_BSplineCurve)& C,
const Standard_Real FromU1,
const Standard_Real ToU2,
const Standard_Real ParametricTolerance,
const Standard_Boolean SameOrientation = Standard_True);
//! Computes the B-spline surface patche between the knots values
//! FromUK1, ToUK2, FromVK1, ToVK2.
@@ -125,14 +122,14 @@ public:
//! [FirstUKnotIndex, LastUKnotIndex]
//! FromVK1 or ToVK2 are out of the bounds
//! [FirstVKnotIndex, LastVKnotIndex]
Standard_EXPORT static Handle(Geom_BSplineSurface) SplitBSplineSurface (const Handle(Geom_BSplineSurface)& S,
const Standard_Integer FromUK1,
const Standard_Integer ToUK2,
const Standard_Integer FromVK1,
const Standard_Integer ToVK2,
const Standard_Boolean SameUOrientation = Standard_True,
const Standard_Boolean SameVOrientation = Standard_True);
Standard_EXPORT static Handle(Geom_BSplineSurface) SplitBSplineSurface(
const Handle(Geom_BSplineSurface)& S,
const Standard_Integer FromUK1,
const Standard_Integer ToUK2,
const Standard_Integer FromVK1,
const Standard_Integer ToVK2,
const Standard_Boolean SameUOrientation = Standard_True,
const Standard_Boolean SameVOrientation = Standard_True);
//! This method splits a B-spline surface patche between the
//! knots values FromK1, ToK2 in one direction.
@@ -146,12 +143,12 @@ public:
//! FromK1 or ToK2 are out of the bounds
//! [FirstUKnotIndex, LastUKnotIndex] in the
//! considered parametric direction.
Standard_EXPORT static Handle(Geom_BSplineSurface) SplitBSplineSurface (const Handle(Geom_BSplineSurface)& S,
const Standard_Integer FromK1,
const Standard_Integer ToK2,
const Standard_Boolean USplit,
const Standard_Boolean SameOrientation = Standard_True);
Standard_EXPORT static Handle(Geom_BSplineSurface) SplitBSplineSurface(
const Handle(Geom_BSplineSurface)& S,
const Standard_Integer FromK1,
const Standard_Integer ToK2,
const Standard_Boolean USplit,
const Standard_Boolean SameOrientation = Standard_True);
//! This method computes the B-spline surface patche between the
//! parametric values FromU1, ToU2, FromV1, ToV2.
@@ -171,15 +168,15 @@ public:
//! Raised if Abs (FromU1 - ToU2) <= ParametricTolerance or
//! Abs (FromV1 - ToV2) <= ParametricTolerance.
//! Raised if ParametricTolerance < Resolution.
Standard_EXPORT static Handle(Geom_BSplineSurface) SplitBSplineSurface (const Handle(Geom_BSplineSurface)& S,
const Standard_Real FromU1,
const Standard_Real ToU2,
const Standard_Real FromV1,
const Standard_Real ToV2,
const Standard_Real ParametricTolerance,
const Standard_Boolean SameUOrientation = Standard_True,
const Standard_Boolean SameVOrientation = Standard_True);
Standard_EXPORT static Handle(Geom_BSplineSurface) SplitBSplineSurface(
const Handle(Geom_BSplineSurface)& S,
const Standard_Real FromU1,
const Standard_Real ToU2,
const Standard_Real FromV1,
const Standard_Real ToV2,
const Standard_Real ParametricTolerance,
const Standard_Boolean SameUOrientation = Standard_True,
const Standard_Boolean SameVOrientation = Standard_True);
//! This method splits the B-spline surface S in one direction
//! between the parametric values FromParam1, ToParam2.
@@ -198,13 +195,14 @@ public:
//! Raises if FromParam1 or ToParam2 are out of the parametric bounds
//! of the surface in the considered direction.
//! Raises if Abs (FromParam1 - ToParam2) <= ParametricTolerance.
Standard_EXPORT static Handle(Geom_BSplineSurface) SplitBSplineSurface (const Handle(Geom_BSplineSurface)& S,
const Standard_Real FromParam1,
const Standard_Real ToParam2,
const Standard_Boolean USplit,
const Standard_Real ParametricTolerance,
const Standard_Boolean SameOrientation = Standard_True);
Standard_EXPORT static Handle(Geom_BSplineSurface) SplitBSplineSurface(
const Handle(Geom_BSplineSurface)& S,
const Standard_Real FromParam1,
const Standard_Real ToParam2,
const Standard_Boolean USplit,
const Standard_Real ParametricTolerance,
const Standard_Boolean SameOrientation = Standard_True);
//! This function converts a non infinite curve from
//! Geom into a B-spline curve. C must be an ellipse or a
//! circle or a trimmed conic or a trimmed line or a Bezier
@@ -270,9 +268,9 @@ public:
//! respectively the first and the last parameters of the
//! trimmed curve (this method of parameterization
//! cannot be used to convert a quasi-complete circle or ellipse).
Standard_EXPORT static Handle(Geom_BSplineCurve) CurveToBSplineCurve (const Handle(Geom_Curve)& C,
const Convert_ParameterisationType Parameterisation = Convert_TgtThetaOver2);
Standard_EXPORT static Handle(Geom_BSplineCurve) CurveToBSplineCurve(
const Handle(Geom_Curve)& C,
const Convert_ParameterisationType Parameterisation = Convert_TgtThetaOver2);
//! This algorithm converts a non infinite surface from Geom
//! into a B-spline surface.
@@ -282,8 +280,9 @@ public:
//! surface with a corresponding basis curve which can be turned into
//! a B-spline curve (see the method CurveToBSplineCurve).
//! Raises DomainError if the type of the surface is not previously defined.
Standard_EXPORT static Handle(Geom_BSplineSurface) SurfaceToBSplineSurface (const Handle(Geom_Surface)& S);
Standard_EXPORT static Handle(Geom_BSplineSurface) SurfaceToBSplineSurface(
const Handle(Geom_Surface)& S);
//! This Method concatenates G1 the ArrayOfCurves as far
//! as it is possible.
//! ArrayOfCurves[0..N-1]
@@ -296,12 +295,12 @@ public:
//! Otherwise its value is 0.0
//! ClosedFlag becomes False on the output
//! if it is impossible to build closed curve.
Standard_EXPORT static void ConcatG1 (TColGeom_Array1OfBSplineCurve& ArrayOfCurves,
const TColStd_Array1OfReal& ArrayOfToler,
Handle(TColGeom_HArray1OfBSplineCurve)& ArrayOfConcatenated,
Standard_Boolean& ClosedFlag,
const Standard_Real ClosedTolerance);
Standard_EXPORT static void ConcatG1(TColGeom_Array1OfBSplineCurve& ArrayOfCurves,
const TColStd_Array1OfReal& ArrayOfToler,
Handle(TColGeom_HArray1OfBSplineCurve)& ArrayOfConcatenated,
Standard_Boolean& ClosedFlag,
const Standard_Real ClosedTolerance);
//! This Method concatenates C1 the ArrayOfCurves as far
//! as it is possible.
//! ArrayOfCurves[0..N-1]
@@ -314,13 +313,13 @@ public:
//! Otherwise its value is 0.0
//! ClosedFlag becomes False on the output
//! if it is impossible to build closed curve.
Standard_EXPORT static void ConcatC1 (TColGeom_Array1OfBSplineCurve& ArrayOfCurves,
const TColStd_Array1OfReal& ArrayOfToler,
Handle(TColStd_HArray1OfInteger)& ArrayOfIndices,
Handle(TColGeom_HArray1OfBSplineCurve)& ArrayOfConcatenated,
Standard_Boolean& ClosedFlag,
const Standard_Real ClosedTolerance);
Standard_EXPORT static void ConcatC1(TColGeom_Array1OfBSplineCurve& ArrayOfCurves,
const TColStd_Array1OfReal& ArrayOfToler,
Handle(TColStd_HArray1OfInteger)& ArrayOfIndices,
Handle(TColGeom_HArray1OfBSplineCurve)& ArrayOfConcatenated,
Standard_Boolean& ClosedFlag,
const Standard_Real ClosedTolerance);
//! This Method concatenates C1 the ArrayOfCurves as far
//! as it is possible.
//! ArrayOfCurves[0..N-1]
@@ -333,14 +332,14 @@ public:
//! Otherwise its value is 0.0
//! ClosedFlag becomes False on the output
//! if it is impossible to build closed curve.
Standard_EXPORT static void ConcatC1 (TColGeom_Array1OfBSplineCurve& ArrayOfCurves,
const TColStd_Array1OfReal& ArrayOfToler,
Handle(TColStd_HArray1OfInteger)& ArrayOfIndices,
Handle(TColGeom_HArray1OfBSplineCurve)& ArrayOfConcatenated,
Standard_Boolean& ClosedFlag,
const Standard_Real ClosedTolerance,
const Standard_Real AngularTolerance);
Standard_EXPORT static void ConcatC1(TColGeom_Array1OfBSplineCurve& ArrayOfCurves,
const TColStd_Array1OfReal& ArrayOfToler,
Handle(TColStd_HArray1OfInteger)& ArrayOfIndices,
Handle(TColGeom_HArray1OfBSplineCurve)& ArrayOfConcatenated,
Standard_Boolean& ClosedFlag,
const Standard_Real ClosedTolerance,
const Standard_Real AngularTolerance);
//! This Method reduces as far as it is possible the
//! multiplicities of the knots of the BSpline BS.(keeping the
//! geometry). It returns a new BSpline which could still be C0.
@@ -348,17 +347,19 @@ public:
//! The Angular toleranceis in radians and measures the angle of
//! the tangents on the left and on the right to decide if the
//! curve is G1 or not at a given point
Standard_EXPORT static void C0BSplineToC1BSplineCurve (Handle(Geom_BSplineCurve)& BS,
const Standard_Real tolerance,
const Standard_Real AngularTolerance = 1.0e-7);
Standard_EXPORT static void C0BSplineToC1BSplineCurve(
Handle(Geom_BSplineCurve)& BS,
const Standard_Real tolerance,
const Standard_Real AngularTolerance = 1.0e-7);
//! This Method reduces as far as it is possible the
//! multiplicities of the knots of the BSpline BS.(keeping the geometry).
//! It returns an array of BSpline C1. tolerance is a geometrical tolerance.
Standard_EXPORT static void C0BSplineToArrayOfC1BSplineCurve (const Handle(Geom_BSplineCurve)& BS,
Handle(TColGeom_HArray1OfBSplineCurve)& tabBS,
const Standard_Real tolerance);
Standard_EXPORT static void C0BSplineToArrayOfC1BSplineCurve(
const Handle(Geom_BSplineCurve)& BS,
Handle(TColGeom_HArray1OfBSplineCurve)& tabBS,
const Standard_Real tolerance);
//! This Method reduces as far as it is possible the
//! multiplicities of the knots of the BSpline BS.(keeping the
//! geometry). It returns an array of BSpline C1. tolerance is a
@@ -366,11 +367,11 @@ public:
//! The Angular tolerance is in radians and measures the angle of
//! the tangents on the left and on the right to decide if the curve
//! is C1 or not at a given point
Standard_EXPORT static void C0BSplineToArrayOfC1BSplineCurve (const Handle(Geom_BSplineCurve)& BS,
Handle(TColGeom_HArray1OfBSplineCurve)& tabBS,
const Standard_Real AngularTolerance,
const Standard_Real tolerance);
Standard_EXPORT static void C0BSplineToArrayOfC1BSplineCurve(
const Handle(Geom_BSplineCurve)& BS,
Handle(TColGeom_HArray1OfBSplineCurve)& tabBS,
const Standard_Real AngularTolerance,
const Standard_Real tolerance);
};
#endif // _GeomConvert_HeaderFile

File diff suppressed because it is too large Load Diff

View File

@@ -14,7 +14,6 @@
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <Adaptor3d_Curve.hxx>
#include <AdvApprox_ApproxAFunction.hxx>
#include <AdvApprox_PrefAndRec.hxx>
@@ -29,162 +28,184 @@
#include <TColStd_HArray1OfReal.hxx>
//=======================================================================
//class : GeomConvert_ApproxCurve_Eval
//purpose: evaluator class for approximation
// class : GeomConvert_ApproxCurve_Eval
// purpose: evaluator class for approximation
//=======================================================================
class GeomConvert_ApproxCurve_Eval : public AdvApprox_EvaluatorFunction
{
public:
GeomConvert_ApproxCurve_Eval (const Handle(Adaptor3d_Curve)& theFunc,
Standard_Real First, Standard_Real Last)
: fonct(theFunc) { StartEndSav[0] = First; StartEndSav[1] = Last; }
virtual void Evaluate (Standard_Integer *Dimension,
Standard_Real StartEnd[2],
Standard_Real *Parameter,
Standard_Integer *DerivativeRequest,
Standard_Real *Result, // [Dimension]
Standard_Integer *ErrorCode);
private:
public:
GeomConvert_ApproxCurve_Eval(const Handle(Adaptor3d_Curve)& theFunc,
Standard_Real First,
Standard_Real Last)
: fonct(theFunc)
{
StartEndSav[0] = First;
StartEndSav[1] = Last;
}
virtual void Evaluate(Standard_Integer* Dimension,
Standard_Real StartEnd[2],
Standard_Real* Parameter,
Standard_Integer* DerivativeRequest,
Standard_Real* Result, // [Dimension]
Standard_Integer* ErrorCode);
private:
Handle(Adaptor3d_Curve) fonct;
Standard_Real StartEndSav[2];
Standard_Real StartEndSav[2];
};
void GeomConvert_ApproxCurve_Eval::Evaluate (Standard_Integer *Dimension,
Standard_Real StartEnd[2],
Standard_Real *Param, // Parameter at which evaluation
Standard_Integer *Order, // Derivative Request
Standard_Real *Result,// [Dimension]
Standard_Integer *ErrorCode)
void GeomConvert_ApproxCurve_Eval::Evaluate(Standard_Integer* Dimension,
Standard_Real StartEnd[2],
Standard_Real* Param, // Parameter at which evaluation
Standard_Integer* Order, // Derivative Request
Standard_Real* Result, // [Dimension]
Standard_Integer* ErrorCode)
{
*ErrorCode = 0;
*ErrorCode = 0;
Standard_Real par = *Param;
// Dimension is incorrect
if (*Dimension!=3) {
// Dimension is incorrect
if (*Dimension != 3)
{
*ErrorCode = 1;
}
if(StartEnd[0] != StartEndSav[0] || StartEnd[1]!= StartEndSav[1])
{
fonct = fonct->Trim(StartEnd[0],StartEnd[1],Precision::PConfusion());
StartEndSav[0]=StartEnd[0];
StartEndSav[1]=StartEnd[1];
}
if (StartEnd[0] != StartEndSav[0] || StartEnd[1] != StartEndSav[1])
{
fonct = fonct->Trim(StartEnd[0], StartEnd[1], Precision::PConfusion());
StartEndSav[0] = StartEnd[0];
StartEndSav[1] = StartEnd[1];
}
gp_Pnt pnt;
gp_Vec v1, v2;
switch (*Order) {
case 0:
pnt = fonct->Value(par);
Result[0] = pnt.X();
Result[1] = pnt.Y();
Result[2] = pnt.Z();
break;
case 1:
fonct->D1(par, pnt, v1);
Result[0] = v1.X();
Result[1] = v1.Y();
Result[2] = v1.Z();
break;
case 2:
fonct->D2(par, pnt, v1, v2);
Result[0] = v2.X();
Result[1] = v2.Y();
Result[2] = v2.Z();
break;
default:
Result[0] = Result[1] = Result[2] = 0.;
*ErrorCode = 3;
break;
switch (*Order)
{
case 0:
pnt = fonct->Value(par);
Result[0] = pnt.X();
Result[1] = pnt.Y();
Result[2] = pnt.Z();
break;
case 1:
fonct->D1(par, pnt, v1);
Result[0] = v1.X();
Result[1] = v1.Y();
Result[2] = v1.Z();
break;
case 2:
fonct->D2(par, pnt, v1, v2);
Result[0] = v2.X();
Result[1] = v2.Y();
Result[2] = v2.Z();
break;
default:
Result[0] = Result[1] = Result[2] = 0.;
*ErrorCode = 3;
break;
}
}
GeomConvert_ApproxCurve::GeomConvert_ApproxCurve(const Handle(Geom_Curve)& Curve,const Standard_Real Tol3d,const GeomAbs_Shape Order,const Standard_Integer MaxSegments,const Standard_Integer MaxDegree)
GeomConvert_ApproxCurve::GeomConvert_ApproxCurve(const Handle(Geom_Curve)& Curve,
const Standard_Real Tol3d,
const GeomAbs_Shape Order,
const Standard_Integer MaxSegments,
const Standard_Integer MaxDegree)
{
Handle(GeomAdaptor_Curve) HCurve = new GeomAdaptor_Curve (Curve);
Handle(GeomAdaptor_Curve) HCurve = new GeomAdaptor_Curve(Curve);
Approximate(HCurve, Tol3d, Order, MaxSegments, MaxDegree);
}
GeomConvert_ApproxCurve::GeomConvert_ApproxCurve(const Handle(Adaptor3d_Curve)& Curve,const Standard_Real Tol3d,const GeomAbs_Shape Order,const Standard_Integer MaxSegments,const Standard_Integer MaxDegree)
GeomConvert_ApproxCurve::GeomConvert_ApproxCurve(const Handle(Adaptor3d_Curve)& Curve,
const Standard_Real Tol3d,
const GeomAbs_Shape Order,
const Standard_Integer MaxSegments,
const Standard_Integer MaxDegree)
{
Approximate(Curve, Tol3d, Order, MaxSegments, MaxDegree);
}
void GeomConvert_ApproxCurve::Approximate(
const Handle(Adaptor3d_Curve)& theCurve,
const Standard_Real theTol3d,
const GeomAbs_Shape theOrder,
const Standard_Integer theMaxSegments,
const Standard_Integer theMaxDegree)
void GeomConvert_ApproxCurve::Approximate(const Handle(Adaptor3d_Curve)& theCurve,
const Standard_Real theTol3d,
const GeomAbs_Shape theOrder,
const Standard_Integer theMaxSegments,
const Standard_Integer theMaxDegree)
{
// Initialisation of input parameters of AdvApprox
Standard_Integer Num1DSS=0, Num2DSS=0, Num3DSS=1;
Standard_Integer Num1DSS = 0, Num2DSS = 0, Num3DSS = 1;
Handle(TColStd_HArray1OfReal) OneDTolNul, TwoDTolNul;
Handle(TColStd_HArray1OfReal) ThreeDTol = new TColStd_HArray1OfReal(1,Num3DSS);
Handle(TColStd_HArray1OfReal) ThreeDTol = new TColStd_HArray1OfReal(1, Num3DSS);
ThreeDTol->Init(theTol3d);
Standard_Real First = theCurve->FirstParameter();
Standard_Real Last = theCurve->LastParameter();
Standard_Integer NbInterv_C2 = theCurve->NbIntervals(GeomAbs_C2);
TColStd_Array1OfReal CutPnts_C2(1, NbInterv_C2+1);
theCurve->Intervals(CutPnts_C2,GeomAbs_C2);
Standard_Integer NbInterv_C3 = theCurve->NbIntervals(GeomAbs_C3);
TColStd_Array1OfReal CutPnts_C3(1, NbInterv_C3+1);
theCurve->Intervals(CutPnts_C3,GeomAbs_C3);
Standard_Integer NbInterv_C2 = theCurve->NbIntervals(GeomAbs_C2);
TColStd_Array1OfReal CutPnts_C2(1, NbInterv_C2 + 1);
theCurve->Intervals(CutPnts_C2, GeomAbs_C2);
Standard_Integer NbInterv_C3 = theCurve->NbIntervals(GeomAbs_C3);
TColStd_Array1OfReal CutPnts_C3(1, NbInterv_C3 + 1);
theCurve->Intervals(CutPnts_C3, GeomAbs_C3);
AdvApprox_PrefAndRec CutTool(CutPnts_C2,CutPnts_C3);
AdvApprox_PrefAndRec CutTool(CutPnts_C2, CutPnts_C3);
myMaxError = 0;
GeomConvert_ApproxCurve_Eval ev (theCurve, First, Last);
AdvApprox_ApproxAFunction aApprox (Num1DSS, Num2DSS, Num3DSS,
OneDTolNul, TwoDTolNul, ThreeDTol,
First, Last, theOrder,
theMaxDegree, theMaxSegments,
ev, CutTool);
GeomConvert_ApproxCurve_Eval ev(theCurve, First, Last);
AdvApprox_ApproxAFunction aApprox(Num1DSS,
Num2DSS,
Num3DSS,
OneDTolNul,
TwoDTolNul,
ThreeDTol,
First,
Last,
theOrder,
theMaxDegree,
theMaxSegments,
ev,
CutTool);
myIsDone = aApprox.IsDone();
myIsDone = aApprox.IsDone();
myHasResult = aApprox.HasResult();
if (myHasResult) {
TColgp_Array1OfPnt Poles(1,aApprox.NbPoles());
aApprox.Poles(1,Poles);
Handle(TColStd_HArray1OfReal) Knots = aApprox.Knots();
Handle(TColStd_HArray1OfInteger) Mults = aApprox.Multiplicities();
Standard_Integer Degree = aApprox.Degree();
if (myHasResult)
{
TColgp_Array1OfPnt Poles(1, aApprox.NbPoles());
aApprox.Poles(1, Poles);
Handle(TColStd_HArray1OfReal) Knots = aApprox.Knots();
Handle(TColStd_HArray1OfInteger) Mults = aApprox.Multiplicities();
Standard_Integer Degree = aApprox.Degree();
myBSplCurve = new Geom_BSplineCurve(Poles, Knots->Array1(), Mults->Array1(), Degree);
myMaxError = aApprox.MaxError(3, 1);
}
myMaxError = aApprox.MaxError(3, 1);
}
}
Handle(Geom_BSplineCurve) GeomConvert_ApproxCurve::Curve() const
Handle(Geom_BSplineCurve) GeomConvert_ApproxCurve::Curve() const
{
return myBSplCurve;
}
Standard_Boolean GeomConvert_ApproxCurve::IsDone() const
Standard_Boolean GeomConvert_ApproxCurve::IsDone() const
{
return myIsDone;
return myIsDone;
}
Standard_Boolean GeomConvert_ApproxCurve::HasResult() const
Standard_Boolean GeomConvert_ApproxCurve::HasResult() const
{
return myHasResult;
return myHasResult;
}
Standard_Real GeomConvert_ApproxCurve::MaxError() const
Standard_Real GeomConvert_ApproxCurve::MaxError() const
{
return myMaxError;
}
void GeomConvert_ApproxCurve::Dump(Standard_OStream& o) const
void GeomConvert_ApproxCurve::Dump(Standard_OStream& o) const
{
o << "******* Dump of ApproxCurve *******" << std::endl;
o << "*******Error " << MaxError() << std::endl;
}

View File

@@ -26,13 +26,11 @@ class Geom_Curve;
//! A framework to convert a 3D curve to a 3D BSpline.
//! This is done by approximation to a BSpline curve within a given tolerance.
class GeomConvert_ApproxCurve
class GeomConvert_ApproxCurve
{
public:
DEFINE_STANDARD_ALLOC
//! Constructs a curve approximation framework defined by -
//! - the conic Curve,
//! - the tolerance value Tol3d,
@@ -41,8 +39,12 @@ public:
//! MaxSegments allowed in the resulting BSpline curve, and
//! - the highest degree MaxDeg which the
//! polynomial defining the BSpline curve may have.
Standard_EXPORT GeomConvert_ApproxCurve(const Handle(Geom_Curve)& Curve, const Standard_Real Tol3d, const GeomAbs_Shape Order, const Standard_Integer MaxSegments, const Standard_Integer MaxDegree);
Standard_EXPORT GeomConvert_ApproxCurve(const Handle(Geom_Curve)& Curve,
const Standard_Real Tol3d,
const GeomAbs_Shape Order,
const Standard_Integer MaxSegments,
const Standard_Integer MaxDegree);
//! Constructs a curve approximation framework defined by -
//! - the Curve,
//! - the tolerance value Tol3d,
@@ -51,56 +53,45 @@ public:
//! MaxSegments allowed in the resulting BSpline curve, and
//! - the highest degree MaxDeg which the
//! polynomial defining the BSpline curve may have.
Standard_EXPORT GeomConvert_ApproxCurve(const Handle(Adaptor3d_Curve)& Curve, const Standard_Real Tol3d, const GeomAbs_Shape Order, const Standard_Integer MaxSegments, const Standard_Integer MaxDegree);
Standard_EXPORT GeomConvert_ApproxCurve(const Handle(Adaptor3d_Curve)& Curve,
const Standard_Real Tol3d,
const GeomAbs_Shape Order,
const Standard_Integer MaxSegments,
const Standard_Integer MaxDegree);
//! Returns the BSpline curve resulting from the approximation algorithm.
Standard_EXPORT Handle(Geom_BSplineCurve) Curve() const;
//! returns Standard_True if the approximation has
//! been done within required tolerance
Standard_EXPORT Standard_Boolean IsDone() const;
//! Returns Standard_True if the approximation did come out
//! with a result that is not NECESSARELY within the required tolerance
Standard_EXPORT Standard_Boolean HasResult() const;
//! Returns the greatest distance between a point on the
//! source conic and the BSpline curve resulting from the
//! approximation. (>0 when an approximation
//! has been done, 0 if no approximation)
Standard_EXPORT Standard_Real MaxError() const;
//! Print on the stream o information about the object
Standard_EXPORT void Dump (Standard_OStream& o) const;
Standard_EXPORT void Dump(Standard_OStream& o) const;
protected:
private:
//! Converts a curve to B-spline
Standard_EXPORT void Approximate (const Handle(Adaptor3d_Curve)& theCurve, const Standard_Real theTol3d, const GeomAbs_Shape theOrder, const Standard_Integer theMaxSegments, const Standard_Integer theMaxDegree);
Standard_EXPORT void Approximate(const Handle(Adaptor3d_Curve)& theCurve,
const Standard_Real theTol3d,
const GeomAbs_Shape theOrder,
const Standard_Integer theMaxSegments,
const Standard_Integer theMaxDegree);
Standard_Boolean myIsDone;
Standard_Boolean myHasResult;
Standard_Boolean myIsDone;
Standard_Boolean myHasResult;
Handle(Geom_BSplineCurve) myBSplCurve;
Standard_Real myMaxError;
Standard_Real myMaxError;
};
#endif // _GeomConvert_ApproxCurve_HeaderFile

View File

@@ -29,418 +29,444 @@ class GeomConvert_ApproxSurface_Eval : public AdvApp2Var_EvaluatorFunc2Var
{
public:
GeomConvert_ApproxSurface_Eval(const Handle(Adaptor3d_Surface)& theAdaptor)
: myAdaptor(theAdaptor)
{
}
GeomConvert_ApproxSurface_Eval (const Handle(Adaptor3d_Surface)& theAdaptor)
: myAdaptor (theAdaptor) {}
virtual void Evaluate (Standard_Integer* theDimension,
Standard_Real* theUStartEnd,
Standard_Real* theVStartEnd,
Standard_Integer* theFavorIso,
Standard_Real* theConstParam,
Standard_Integer* theNbParams,
Standard_Real* theParameters,
Standard_Integer* theUOrder,
Standard_Integer* theVOrder,
Standard_Real* theResult,
Standard_Integer* theErrorCode) const;
virtual void Evaluate(Standard_Integer* theDimension,
Standard_Real* theUStartEnd,
Standard_Real* theVStartEnd,
Standard_Integer* theFavorIso,
Standard_Real* theConstParam,
Standard_Integer* theNbParams,
Standard_Real* theParameters,
Standard_Integer* theUOrder,
Standard_Integer* theVOrder,
Standard_Real* theResult,
Standard_Integer* theErrorCode) const;
private:
mutable Handle(Adaptor3d_Surface) myAdaptor;
};
void GeomConvert_ApproxSurface_Eval::Evaluate (Standard_Integer * Dimension,
// Dimension
Standard_Real * UStartEnd,
// StartEnd[2] in U
Standard_Real * VStartEnd,
// StartEnd[2] in V
Standard_Integer * FavorIso,
// Choice of constante, 1 for U, 2 for V
Standard_Real * ConstParam,
// Value of constant parameter
Standard_Integer * NbParams,
// Number of parameters N
Standard_Real * Parameters,
// Values of parameters,
Standard_Integer * UOrder,
// Derivative Request in U
Standard_Integer * VOrder,
// Derivative Request in V
Standard_Real * Result,
// Result[Dimension,N]
Standard_Integer * ErrorCode) const
// Error Code
{
void GeomConvert_ApproxSurface_Eval::Evaluate(Standard_Integer* Dimension,
// Dimension
Standard_Real* UStartEnd,
// StartEnd[2] in U
Standard_Real* VStartEnd,
// StartEnd[2] in V
Standard_Integer* FavorIso,
// Choice of constante, 1 for U, 2 for V
Standard_Real* ConstParam,
// Value of constant parameter
Standard_Integer* NbParams,
// Number of parameters N
Standard_Real* Parameters,
// Values of parameters,
Standard_Integer* UOrder,
// Derivative Request in U
Standard_Integer* VOrder,
// Derivative Request in V
Standard_Real* Result,
// Result[Dimension,N]
Standard_Integer* ErrorCode) const
// Error Code
{
*ErrorCode = 0;
// Standard_Integer idim;
// Standard_Integer idim;
Standard_Integer jpar;
Standard_Real Upar,Vpar;
Standard_Real Upar, Vpar;
// Dimension incorrecte
if (*Dimension!=3) {
// Dimension incorrecte
if (*Dimension != 3)
{
*ErrorCode = 1;
}
// Parametres incorrects
/* if (*FavorIso==1) {
Upar = *ConstParam;
if (( Upar < UStartEnd[0] ) || ( Upar > UStartEnd[1] )) {
*ErrorCode = 2;
}
for (jpar=1;jpar<=*NbParams;jpar++) {
Vpar = Parameters[jpar-1];
if (( Vpar < VStartEnd[0] ) || ( Vpar > VStartEnd[1] )) {
*ErrorCode = 2;
}
}
}
else {
Vpar = *ConstParam;
if (( Vpar < VStartEnd[0] ) || ( Vpar > VStartEnd[1] )) {
*ErrorCode = 2;
}
for (jpar=1;jpar<=*NbParams;jpar++) {
Upar = Parameters[jpar-1];
// Parametres incorrects
/* if (*FavorIso==1) {
Upar = *ConstParam;
if (( Upar < UStartEnd[0] ) || ( Upar > UStartEnd[1] )) {
*ErrorCode = 2;
}
}
}*/
for (jpar=1;jpar<=*NbParams;jpar++) {
Vpar = Parameters[jpar-1];
if (( Vpar < VStartEnd[0] ) || ( Vpar > VStartEnd[1] )) {
*ErrorCode = 2;
}
}
}
else {
Vpar = *ConstParam;
if (( Vpar < VStartEnd[0] ) || ( Vpar > VStartEnd[1] )) {
*ErrorCode = 2;
}
for (jpar=1;jpar<=*NbParams;jpar++) {
Upar = Parameters[jpar-1];
if (( Upar < UStartEnd[0] ) || ( Upar > UStartEnd[1] )) {
*ErrorCode = 2;
}
}
}*/
// Initialisation
// Initialisation
myAdaptor = myAdaptor->UTrim (UStartEnd[0], UStartEnd[1], Precision::PConfusion());
myAdaptor = myAdaptor->VTrim (VStartEnd[0], VStartEnd[1], Precision::PConfusion());
/*
for (idim=1;idim<=*Dimension;idim++) {
for (jpar=1;jpar<=*NbParams;jpar++) {
Result[idim-1+(jpar-1)*(*Dimension)] = 0.;
}
}*/
myAdaptor = myAdaptor->UTrim(UStartEnd[0], UStartEnd[1], Precision::PConfusion());
myAdaptor = myAdaptor->VTrim(VStartEnd[0], VStartEnd[1], Precision::PConfusion());
/*
for (idim=1;idim<=*Dimension;idim++) {
for (jpar=1;jpar<=*NbParams;jpar++) {
Result[idim-1+(jpar-1)*(*Dimension)] = 0.;
}
}*/
Standard_Integer Order = *UOrder + *VOrder;
gp_Pnt pnt;
gp_Vec vect, v1, v2, v3, v4, v5, v6, v7, v8, v9;
Standard_Integer Order = *UOrder + *VOrder;
gp_Pnt pnt;
gp_Vec vect, v1, v2, v3, v4, v5, v6, v7, v8, v9;
if (*FavorIso==1) {
Upar = *ConstParam;
switch (Order) {
case 0 :
for (jpar=1;jpar<=*NbParams;jpar++) {
Vpar = Parameters[jpar-1];
pnt = myAdaptor->Value (Upar, Vpar);
Result[(jpar-1)*(*Dimension)] = pnt.X();
Result[1+(jpar-1)*(*Dimension)] = pnt.Y();
Result[2+(jpar-1)*(*Dimension)] = pnt.Z();
if (*FavorIso == 1)
{
Upar = *ConstParam;
switch (Order)
{
case 0:
for (jpar = 1; jpar <= *NbParams; jpar++)
{
Vpar = Parameters[jpar - 1];
pnt = myAdaptor->Value(Upar, Vpar);
Result[(jpar - 1) * (*Dimension)] = pnt.X();
Result[1 + (jpar - 1) * (*Dimension)] = pnt.Y();
Result[2 + (jpar - 1) * (*Dimension)] = pnt.Z();
}
break;
case 1:
for (jpar = 1; jpar <= *NbParams; jpar++)
{
Vpar = Parameters[jpar - 1];
myAdaptor->D1(Upar, Vpar, pnt, v1, v2);
if (*UOrder == 1)
{
Result[(jpar - 1) * (*Dimension)] = v1.X();
Result[1 + (jpar - 1) * (*Dimension)] = v1.Y();
Result[2 + (jpar - 1) * (*Dimension)] = v1.Z();
}
else
{
Result[(jpar - 1) * (*Dimension)] = v2.X();
Result[1 + (jpar - 1) * (*Dimension)] = v2.Y();
Result[2 + (jpar - 1) * (*Dimension)] = v2.Z();
}
}
break;
case 2:
for (jpar = 1; jpar <= *NbParams; jpar++)
{
Vpar = Parameters[jpar - 1];
myAdaptor->D2(Upar, Vpar, pnt, v1, v2, v3, v4, v5);
if (*UOrder == 2)
{
Result[(jpar - 1) * (*Dimension)] = v3.X();
Result[1 + (jpar - 1) * (*Dimension)] = v3.Y();
Result[2 + (jpar - 1) * (*Dimension)] = v3.Z();
}
else if (*UOrder == 1)
{
Result[(jpar - 1) * (*Dimension)] = v5.X();
Result[1 + (jpar - 1) * (*Dimension)] = v5.Y();
Result[2 + (jpar - 1) * (*Dimension)] = v5.Z();
}
else if (*UOrder == 0)
{
Result[(jpar - 1) * (*Dimension)] = v4.X();
Result[1 + (jpar - 1) * (*Dimension)] = v4.Y();
Result[2 + (jpar - 1) * (*Dimension)] = v4.Z();
}
}
break;
case 3:
for (jpar = 1; jpar <= *NbParams; jpar++)
{
Vpar = Parameters[jpar - 1];
myAdaptor->D3(Upar, Vpar, pnt, v1, v2, v3, v4, v5, v6, v7, v8, v9);
if (*UOrder == 2)
{
Result[(jpar - 1) * (*Dimension)] = v8.X();
Result[1 + (jpar - 1) * (*Dimension)] = v8.Y();
Result[2 + (jpar - 1) * (*Dimension)] = v8.Z();
}
else if (*UOrder == 1)
{
Result[(jpar - 1) * (*Dimension)] = v9.X();
Result[1 + (jpar - 1) * (*Dimension)] = v9.Y();
Result[2 + (jpar - 1) * (*Dimension)] = v9.Z();
}
}
break;
case 4:
for (jpar = 1; jpar <= *NbParams; jpar++)
{
Vpar = Parameters[jpar - 1];
vect = myAdaptor->DN(Upar, Vpar, *UOrder, *VOrder);
Result[(jpar - 1) * (*Dimension)] = vect.X();
Result[1 + (jpar - 1) * (*Dimension)] = vect.Y();
Result[2 + (jpar - 1) * (*Dimension)] = vect.Z();
}
break;
}
break;
case 1 :
for (jpar=1;jpar<=*NbParams;jpar++) {
Vpar = Parameters[jpar-1];
myAdaptor->D1 (Upar, Vpar, pnt, v1, v2);
if (*UOrder==1) {
Result[(jpar-1)*(*Dimension)] = v1.X();
Result[1+(jpar-1)*(*Dimension)] = v1.Y();
Result[2+(jpar-1)*(*Dimension)] = v1.Z();
}
else {
Result[(jpar-1)*(*Dimension)] = v2.X();
Result[1+(jpar-1)*(*Dimension)] = v2.Y();
Result[2+(jpar-1)*(*Dimension)] = v2.Z();
}
}
break;
case 2 :
for (jpar=1;jpar<=*NbParams;jpar++) {
Vpar = Parameters[jpar-1];
myAdaptor->D2 (Upar, Vpar, pnt, v1, v2, v3, v4, v5);
if (*UOrder==2) {
Result[(jpar-1)*(*Dimension)] = v3.X();
Result[1+(jpar-1)*(*Dimension)] = v3.Y();
Result[2+(jpar-1)*(*Dimension)] = v3.Z();
}
else if (*UOrder==1) {
Result[(jpar-1)*(*Dimension)] = v5.X();
Result[1+(jpar-1)*(*Dimension)] = v5.Y();
Result[2+(jpar-1)*(*Dimension)] = v5.Z();
}
else if (*UOrder==0) {
Result[(jpar-1)*(*Dimension)] = v4.X();
Result[1+(jpar-1)*(*Dimension)] = v4.Y();
Result[2+(jpar-1)*(*Dimension)] = v4.Z();
}
}
break;
case 3 :
for (jpar=1;jpar<=*NbParams;jpar++) {
Vpar = Parameters[jpar-1];
myAdaptor->D3 (Upar, Vpar, pnt, v1, v2, v3, v4, v5, v6, v7, v8, v9);
if (*UOrder==2) {
Result[(jpar-1)*(*Dimension)] = v8.X();
Result[1+(jpar-1)*(*Dimension)] = v8.Y();
Result[2+(jpar-1)*(*Dimension)] = v8.Z();
}
else if (*UOrder==1) {
Result[(jpar-1)*(*Dimension)] = v9.X();
Result[1+(jpar-1)*(*Dimension)] = v9.Y();
Result[2+(jpar-1)*(*Dimension)] = v9.Z();
}
}
break;
case 4 :
for (jpar=1;jpar<=*NbParams;jpar++) {
Vpar = Parameters[jpar-1];
vect = myAdaptor->DN (Upar, Vpar, *UOrder, *VOrder);
Result[(jpar-1)*(*Dimension)] = vect.X();
Result[1+(jpar-1)*(*Dimension)] = vect.Y();
Result[2+(jpar-1)*(*Dimension)] = vect.Z();
}
break;
}
}
else {
Vpar = *ConstParam;
switch (Order) {
case 0 :
for (jpar=1;jpar<=*NbParams;jpar++) {
Upar = Parameters[jpar-1];
pnt = myAdaptor->Value (Upar, Vpar);
Result[(jpar-1)*(*Dimension)] = pnt.X();
Result[1+(jpar-1)*(*Dimension)] = pnt.Y();
Result[2+(jpar-1)*(*Dimension)] = pnt.Z();
else
{
Vpar = *ConstParam;
switch (Order)
{
case 0:
for (jpar = 1; jpar <= *NbParams; jpar++)
{
Upar = Parameters[jpar - 1];
pnt = myAdaptor->Value(Upar, Vpar);
Result[(jpar - 1) * (*Dimension)] = pnt.X();
Result[1 + (jpar - 1) * (*Dimension)] = pnt.Y();
Result[2 + (jpar - 1) * (*Dimension)] = pnt.Z();
}
break;
case 1:
for (jpar = 1; jpar <= *NbParams; jpar++)
{
Upar = Parameters[jpar - 1];
myAdaptor->D1(Upar, Vpar, pnt, v1, v2);
if (*UOrder == 1)
{
Result[(jpar - 1) * (*Dimension)] = v1.X();
Result[1 + (jpar - 1) * (*Dimension)] = v1.Y();
Result[2 + (jpar - 1) * (*Dimension)] = v1.Z();
}
else
{
Result[(jpar - 1) * (*Dimension)] = v2.X();
Result[1 + (jpar - 1) * (*Dimension)] = v2.Y();
Result[2 + (jpar - 1) * (*Dimension)] = v2.Z();
}
}
break;
case 2:
for (jpar = 1; jpar <= *NbParams; jpar++)
{
Upar = Parameters[jpar - 1];
myAdaptor->D2(Upar, Vpar, pnt, v1, v2, v3, v4, v5);
if (*UOrder == 2)
{
Result[(jpar - 1) * (*Dimension)] = v3.X();
Result[1 + (jpar - 1) * (*Dimension)] = v3.Y();
Result[2 + (jpar - 1) * (*Dimension)] = v3.Z();
}
else if (*UOrder == 1)
{
Result[(jpar - 1) * (*Dimension)] = v5.X();
Result[1 + (jpar - 1) * (*Dimension)] = v5.Y();
Result[2 + (jpar - 1) * (*Dimension)] = v5.Z();
}
else if (*UOrder == 0)
{
Result[(jpar - 1) * (*Dimension)] = v4.X();
Result[1 + (jpar - 1) * (*Dimension)] = v4.Y();
Result[2 + (jpar - 1) * (*Dimension)] = v4.Z();
}
}
break;
case 3:
for (jpar = 1; jpar <= *NbParams; jpar++)
{
Upar = Parameters[jpar - 1];
myAdaptor->D3(Upar, Vpar, pnt, v1, v2, v3, v4, v5, v6, v7, v8, v9);
if (*UOrder == 2)
{
Result[(jpar - 1) * (*Dimension)] = v8.X();
Result[1 + (jpar - 1) * (*Dimension)] = v8.Y();
Result[2 + (jpar - 1) * (*Dimension)] = v8.Z();
}
else if (*UOrder == 1)
{
Result[(jpar - 1) * (*Dimension)] = v9.X();
Result[1 + (jpar - 1) * (*Dimension)] = v9.Y();
Result[2 + (jpar - 1) * (*Dimension)] = v9.Z();
}
}
break;
case 4:
for (jpar = 1; jpar <= *NbParams; jpar++)
{
Upar = Parameters[jpar - 1];
vect = myAdaptor->DN(Upar, Vpar, *UOrder, *VOrder);
Result[(jpar - 1) * (*Dimension)] = vect.X();
Result[1 + (jpar - 1) * (*Dimension)] = vect.Y();
Result[2 + (jpar - 1) * (*Dimension)] = vect.Z();
}
break;
}
break;
case 1 :
for (jpar=1;jpar<=*NbParams;jpar++) {
Upar = Parameters[jpar-1];
myAdaptor->D1 (Upar, Vpar, pnt, v1, v2);
if (*UOrder==1) {
Result[(jpar-1)*(*Dimension)] = v1.X();
Result[1+(jpar-1)*(*Dimension)] = v1.Y();
Result[2+(jpar-1)*(*Dimension)] = v1.Z();
}
else {
Result[(jpar-1)*(*Dimension)] = v2.X();
Result[1+(jpar-1)*(*Dimension)] = v2.Y();
Result[2+(jpar-1)*(*Dimension)] = v2.Z();
}
}
break;
case 2 :
for (jpar=1;jpar<=*NbParams;jpar++) {
Upar = Parameters[jpar-1];
myAdaptor->D2 (Upar, Vpar, pnt, v1, v2, v3, v4, v5);
if (*UOrder==2) {
Result[(jpar-1)*(*Dimension)] = v3.X();
Result[1+(jpar-1)*(*Dimension)] = v3.Y();
Result[2+(jpar-1)*(*Dimension)] = v3.Z();
}
else if (*UOrder==1) {
Result[(jpar-1)*(*Dimension)] = v5.X();
Result[1+(jpar-1)*(*Dimension)] = v5.Y();
Result[2+(jpar-1)*(*Dimension)] = v5.Z();
}
else if (*UOrder==0) {
Result[(jpar-1)*(*Dimension)] = v4.X();
Result[1+(jpar-1)*(*Dimension)] = v4.Y();
Result[2+(jpar-1)*(*Dimension)] = v4.Z();
}
}
break;
case 3 :
for (jpar=1;jpar<=*NbParams;jpar++) {
Upar = Parameters[jpar-1];
myAdaptor->D3 (Upar, Vpar, pnt, v1, v2, v3, v4, v5, v6, v7, v8, v9);
if (*UOrder==2) {
Result[(jpar-1)*(*Dimension)] = v8.X();
Result[1+(jpar-1)*(*Dimension)] = v8.Y();
Result[2+(jpar-1)*(*Dimension)] = v8.Z();
}
else if (*UOrder==1) {
Result[(jpar-1)*(*Dimension)] = v9.X();
Result[1+(jpar-1)*(*Dimension)] = v9.Y();
Result[2+(jpar-1)*(*Dimension)] = v9.Z();
}
}
break;
case 4 :
for (jpar=1;jpar<=*NbParams;jpar++) {
Upar = Parameters[jpar-1];
vect = myAdaptor->DN (Upar, Vpar, *UOrder, *VOrder);
Result[(jpar-1)*(*Dimension)] = vect.X();
Result[1+(jpar-1)*(*Dimension)] = vect.Y();
Result[2+(jpar-1)*(*Dimension)] = vect.Z();
}
break;
}
}
}
//=======================================================================
//function : GeomConvert_ApproxSurface
//purpose :
//=======================================================================
//=================================================================================================
GeomConvert_ApproxSurface::GeomConvert_ApproxSurface(const Handle(Geom_Surface)& Surf,
const Standard_Real Tol3d,
const GeomAbs_Shape UContinuity,
const GeomAbs_Shape VContinuity,
const Standard_Integer MaxDegU,
const Standard_Integer MaxDegV,
const Standard_Integer MaxSegments,
const Standard_Integer PrecisCode)
const Standard_Real Tol3d,
const GeomAbs_Shape UContinuity,
const GeomAbs_Shape VContinuity,
const Standard_Integer MaxDegU,
const Standard_Integer MaxDegV,
const Standard_Integer MaxSegments,
const Standard_Integer PrecisCode)
{
Handle(Adaptor3d_Surface) aSurfAdaptor = new GeomAdaptor_Surface (Surf);
Approximate(aSurfAdaptor, Tol3d, UContinuity, VContinuity, MaxDegU, MaxDegV, MaxSegments, PrecisCode);
Handle(Adaptor3d_Surface) aSurfAdaptor = new GeomAdaptor_Surface(Surf);
Approximate(aSurfAdaptor,
Tol3d,
UContinuity,
VContinuity,
MaxDegU,
MaxDegV,
MaxSegments,
PrecisCode);
}
GeomConvert_ApproxSurface::GeomConvert_ApproxSurface(const Handle(Adaptor3d_Surface)& Surf,
const Standard_Real Tol3d,
const GeomAbs_Shape UContinuity,
const GeomAbs_Shape VContinuity,
const Standard_Integer MaxDegU,
const Standard_Integer MaxDegV,
const Standard_Integer MaxSegments,
const Standard_Integer PrecisCode)
const Standard_Real Tol3d,
const GeomAbs_Shape UContinuity,
const GeomAbs_Shape VContinuity,
const Standard_Integer MaxDegU,
const Standard_Integer MaxDegV,
const Standard_Integer MaxSegments,
const Standard_Integer PrecisCode)
{
Approximate(Surf, Tol3d, UContinuity, VContinuity, MaxDegU, MaxDegV, MaxSegments, PrecisCode);
}
void GeomConvert_ApproxSurface::Approximate(const Handle(Adaptor3d_Surface)& theSurf,
const Standard_Real theTol3d,
const GeomAbs_Shape theUContinuity,
const GeomAbs_Shape theVContinuity,
const Standard_Integer theMaxDegU,
const Standard_Integer theMaxDegV,
const Standard_Integer theMaxSegments,
const Standard_Integer thePrecisCode)
const Standard_Real theTol3d,
const GeomAbs_Shape theUContinuity,
const GeomAbs_Shape theVContinuity,
const Standard_Integer theMaxDegU,
const Standard_Integer theMaxDegV,
const Standard_Integer theMaxSegments,
const Standard_Integer thePrecisCode)
{
Standard_Real U0 = theSurf->FirstUParameter();
Standard_Real U1 = theSurf->LastUParameter();
Standard_Real V0 = theSurf->FirstVParameter();
Standard_Real V1 = theSurf->LastVParameter();
// " Init des nombres de sous-espaces et des tolerances"
Standard_Integer nb1 = 0, nb2 = 0, nb3 = 1;
Handle(TColStd_HArray1OfReal) nul1 = new TColStd_HArray1OfReal(1,1);
// " Init des nombres de sous-espaces et des tolerances"
Standard_Integer nb1 = 0, nb2 = 0, nb3 = 1;
Handle(TColStd_HArray1OfReal) nul1 = new TColStd_HArray1OfReal(1, 1);
nul1->SetValue(1, 0.);
Handle(TColStd_HArray2OfReal) nul2 = new TColStd_HArray2OfReal(1,1,1,4);
Handle(TColStd_HArray2OfReal) nul2 = new TColStd_HArray2OfReal(1, 1, 1, 4);
nul2->SetValue(1, 1, 0.);
nul2->SetValue(1, 2, 0.);
nul2->SetValue(1, 3, 0.);
nul2->SetValue(1, 4, 0.);
Handle(TColStd_HArray1OfReal) eps3D = new TColStd_HArray1OfReal(1,1);
Handle(TColStd_HArray1OfReal) eps3D = new TColStd_HArray1OfReal(1, 1);
eps3D->SetValue(1, theTol3d);
Handle(TColStd_HArray2OfReal) epsfr = new TColStd_HArray2OfReal(1,1,1,4);
Handle(TColStd_HArray2OfReal) epsfr = new TColStd_HArray2OfReal(1, 1, 1, 4);
epsfr->SetValue(1, 1, theTol3d);
epsfr->SetValue(1, 2, theTol3d);
epsfr->SetValue(1, 3, theTol3d);
epsfr->SetValue(1, 4, theTol3d);
// " Init du type d'iso"
GeomAbs_IsoType IsoType = GeomAbs_IsoV;
// " Init du type d'iso"
GeomAbs_IsoType IsoType = GeomAbs_IsoV;
Standard_Integer NbDec;
NbDec = theSurf->NbUIntervals(GeomAbs_C2);
TColStd_Array1OfReal UDec_C2(1, NbDec+1);
TColStd_Array1OfReal UDec_C2(1, NbDec + 1);
theSurf->UIntervals(UDec_C2, GeomAbs_C2);
NbDec = theSurf->NbVIntervals(GeomAbs_C2);
TColStd_Array1OfReal VDec_C2(1, NbDec+1);
TColStd_Array1OfReal VDec_C2(1, NbDec + 1);
theSurf->VIntervals(VDec_C2, GeomAbs_C2);
NbDec = theSurf->NbUIntervals(GeomAbs_C3);
TColStd_Array1OfReal UDec_C3(1, NbDec+1);
TColStd_Array1OfReal UDec_C3(1, NbDec + 1);
theSurf->UIntervals(UDec_C3, GeomAbs_C3);
NbDec = theSurf->NbVIntervals(GeomAbs_C3);
TColStd_Array1OfReal VDec_C3(1, NbDec+1);
TColStd_Array1OfReal VDec_C3(1, NbDec + 1);
theSurf->VIntervals(VDec_C3, GeomAbs_C3);
// Approximation avec decoupe preferentiel
// Approximation avec decoupe preferentiel
// aux lieux de discontinuitees C2
AdvApprox_PrefAndRec pUDec(UDec_C2,UDec_C3);
AdvApprox_PrefAndRec pVDec(VDec_C2,VDec_C3);
AdvApprox_PrefAndRec pUDec(UDec_C2, UDec_C3);
AdvApprox_PrefAndRec pVDec(VDec_C2, VDec_C3);
//POP pour WNT
GeomConvert_ApproxSurface_Eval ev (theSurf);
AdvApp2Var_ApproxAFunc2Var approx(nb1, nb2, nb3,
nul1,nul1,eps3D,
nul2,nul2,epsfr,
U0,U1,V0,V1,
IsoType,theUContinuity,theVContinuity,thePrecisCode,
theMaxDegU,theMaxDegV,theMaxSegments,ev,
pUDec,pVDec);
// POP pour WNT
GeomConvert_ApproxSurface_Eval ev(theSurf);
AdvApp2Var_ApproxAFunc2Var approx(nb1,
nb2,
nb3,
nul1,
nul1,
eps3D,
nul2,
nul2,
epsfr,
U0,
U1,
V0,
V1,
IsoType,
theUContinuity,
theVContinuity,
thePrecisCode,
theMaxDegU,
theMaxDegV,
theMaxSegments,
ev,
pUDec,
pVDec);
myMaxError = approx.MaxError(3,1);
myMaxError = approx.MaxError(3, 1);
myBSplSurf = approx.Surface(1);
myIsDone = approx.IsDone();
myHasResult = approx.HasResult();
}
//=================================================================================================
//=======================================================================
//function : Surface
//purpose :
//=======================================================================
Handle(Geom_BSplineSurface) GeomConvert_ApproxSurface::Surface() const
Handle(Geom_BSplineSurface) GeomConvert_ApproxSurface::Surface() const
{
return myBSplSurf;
}
//=======================================================================
//function : IsDone
//purpose :
//=======================================================================
//=================================================================================================
Standard_Boolean GeomConvert_ApproxSurface::IsDone() const
Standard_Boolean GeomConvert_ApproxSurface::IsDone() const
{
return myIsDone;
}
//=======================================================================
//function : HasResult
//purpose :
//=======================================================================
//=================================================================================================
Standard_Boolean GeomConvert_ApproxSurface::HasResult() const
Standard_Boolean GeomConvert_ApproxSurface::HasResult() const
{
return myHasResult;
}
//=======================================================================
//function : MaxError
//purpose :
//=======================================================================
//=================================================================================================
Standard_Real GeomConvert_ApproxSurface::MaxError() const
Standard_Real GeomConvert_ApproxSurface::MaxError() const
{
return myMaxError;
}
//=======================================================================
//function : Dump
//purpose :
//=======================================================================
void GeomConvert_ApproxSurface::Dump(Standard_OStream& o) const
//=================================================================================================
void GeomConvert_ApproxSurface::Dump(Standard_OStream& o) const
{
o<<std::endl;
if (!myHasResult) { o<<"No result"<<std::endl; }
else {
o<<"Result max error :"<< myMaxError <<std::endl;
}
o<<std::endl;
o << std::endl;
if (!myHasResult)
{
o << "No result" << std::endl;
}
else
{
o << "Result max error :" << myMaxError << std::endl;
}
o << std::endl;
}

View File

@@ -27,13 +27,11 @@ class Geom_Surface;
//! A framework to convert a surface to a BSpline
//! surface. This is done by approximation to a BSpline
//! surface within a given tolerance.
class GeomConvert_ApproxSurface
class GeomConvert_ApproxSurface
{
public:
DEFINE_STANDARD_ALLOC
//! Constructs a surface approximation framework defined by
//! - the conic Surf
//! - the tolerance value Tol3d
@@ -45,8 +43,15 @@ public:
//! - the maximum number of segments MaxSegments
//! allowed in the resulting BSpline curve
//! - the index of precision PrecisCode.
Standard_EXPORT GeomConvert_ApproxSurface(const Handle(Geom_Surface)& Surf, const Standard_Real Tol3d, const GeomAbs_Shape UContinuity, const GeomAbs_Shape VContinuity, const Standard_Integer MaxDegU, const Standard_Integer MaxDegV, const Standard_Integer MaxSegments, const Standard_Integer PrecisCode);
Standard_EXPORT GeomConvert_ApproxSurface(const Handle(Geom_Surface)& Surf,
const Standard_Real Tol3d,
const GeomAbs_Shape UContinuity,
const GeomAbs_Shape VContinuity,
const Standard_Integer MaxDegU,
const Standard_Integer MaxDegV,
const Standard_Integer MaxSegments,
const Standard_Integer PrecisCode);
//! Constructs a surface approximation framework defined by
//! - the Surf
//! - the tolerance value Tol3d
@@ -58,56 +63,51 @@ public:
//! - the maximum number of segments MaxSegments
//! allowed in the resulting BSpline curve
//! - the index of precision PrecisCode.
Standard_EXPORT GeomConvert_ApproxSurface(const Handle(Adaptor3d_Surface)& Surf, const Standard_Real Tol3d, const GeomAbs_Shape UContinuity, const GeomAbs_Shape VContinuity, const Standard_Integer MaxDegU, const Standard_Integer MaxDegV, const Standard_Integer MaxSegments, const Standard_Integer PrecisCode);
Standard_EXPORT GeomConvert_ApproxSurface(const Handle(Adaptor3d_Surface)& Surf,
const Standard_Real Tol3d,
const GeomAbs_Shape UContinuity,
const GeomAbs_Shape VContinuity,
const Standard_Integer MaxDegU,
const Standard_Integer MaxDegV,
const Standard_Integer MaxSegments,
const Standard_Integer PrecisCode);
//! Returns the BSpline surface resulting from the approximation algorithm.
Standard_EXPORT Handle(Geom_BSplineSurface) Surface() const;
//! Returns Standard_True if the approximation has be done
Standard_EXPORT Standard_Boolean IsDone() const;
//! Returns true if the approximation did come out with a result that
//! is not NECESSARILY within the required tolerance or a result
//! that is not recognized with the wished continuities.
Standard_EXPORT Standard_Boolean HasResult() const;
//! Returns the greatest distance between a point on the
//! source conic surface and the BSpline surface
//! resulting from the approximation (>0 when an approximation
//! has been done, 0 if no approximation )
Standard_EXPORT Standard_Real MaxError() const;
//! Prints on the stream o information on the current state of the object.
Standard_EXPORT void Dump (Standard_OStream& o) const;
Standard_EXPORT void Dump(Standard_OStream& o) const;
protected:
private:
//! Converts a surface to B-spline
Standard_EXPORT void Approximate (const Handle(Adaptor3d_Surface)& theSurf, const Standard_Real theTol3d, const GeomAbs_Shape theUContinuity, const GeomAbs_Shape theVContinuity, const Standard_Integer theMaxDegU, const Standard_Integer theMaxDegV, const Standard_Integer theMaxSegments, const Standard_Integer thePrecisCode);
Standard_EXPORT void Approximate(const Handle(Adaptor3d_Surface)& theSurf,
const Standard_Real theTol3d,
const GeomAbs_Shape theUContinuity,
const GeomAbs_Shape theVContinuity,
const Standard_Integer theMaxDegU,
const Standard_Integer theMaxDegV,
const Standard_Integer theMaxSegments,
const Standard_Integer thePrecisCode);
Standard_Boolean myIsDone;
Standard_Boolean myHasResult;
Standard_Boolean myIsDone;
Standard_Boolean myHasResult;
Handle(Geom_BSplineSurface) myBSplSurf;
Standard_Real myMaxError;
Standard_Real myMaxError;
};
#endif // _GeomConvert_ApproxSurface_HeaderFile

View File

@@ -12,103 +12,104 @@
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
//Jean-Claude Vauthier 27 November 1991
//Passage sur C1 Aout 1992
// Jean-Claude Vauthier 27 November 1991
// Passage sur C1 Aout 1992
#include <BSplCLib.hxx>
#include <Geom_BSplineCurve.hxx>
#include <GeomConvert_BSplineCurveKnotSplitting.hxx>
#include <Standard_RangeError.hxx>
typedef TColStd_Array1OfInteger Array1OfInteger;
typedef TColStd_HArray1OfInteger HArray1OfInteger;
typedef TColStd_Array1OfInteger Array1OfInteger;
typedef TColStd_HArray1OfInteger HArray1OfInteger;
GeomConvert_BSplineCurveKnotSplitting::GeomConvert_BSplineCurveKnotSplitting (
GeomConvert_BSplineCurveKnotSplitting::GeomConvert_BSplineCurveKnotSplitting(
const Handle(Geom_BSplineCurve)& BasisCurve,
const Standard_Integer ContinuityRange
const Handle(Geom_BSplineCurve)& BasisCurve,
const Standard_Integer ContinuityRange
) {
)
{
if (ContinuityRange < 0) throw Standard_RangeError();
if (ContinuityRange < 0)
throw Standard_RangeError();
Standard_Integer FirstIndex = BasisCurve->FirstUKnotIndex();
Standard_Integer LastIndex = BasisCurve->LastUKnotIndex();
Standard_Integer Degree = BasisCurve->Degree();
if (ContinuityRange == 0) {
splitIndexes = new HArray1OfInteger (1, 2);
splitIndexes->SetValue (1, FirstIndex);
splitIndexes->SetValue (2, LastIndex);
if (ContinuityRange == 0)
{
splitIndexes = new HArray1OfInteger(1, 2);
splitIndexes->SetValue(1, FirstIndex);
splitIndexes->SetValue(2, LastIndex);
}
else {
else
{
Standard_Integer NbKnots = BasisCurve->NbKnots();
Array1OfInteger Mults (1, NbKnots);
BasisCurve->Multiplicities (Mults);
Standard_Integer Mmax = BSplCLib::MaxKnotMult (Mults, FirstIndex, LastIndex);
if (Degree - Mmax >= ContinuityRange) {
splitIndexes = new HArray1OfInteger (1, 2);
splitIndexes->SetValue (1, FirstIndex);
splitIndexes->SetValue (2, LastIndex);
Array1OfInteger Mults(1, NbKnots);
BasisCurve->Multiplicities(Mults);
Standard_Integer Mmax = BSplCLib::MaxKnotMult(Mults, FirstIndex, LastIndex);
if (Degree - Mmax >= ContinuityRange)
{
splitIndexes = new HArray1OfInteger(1, 2);
splitIndexes->SetValue(1, FirstIndex);
splitIndexes->SetValue(2, LastIndex);
}
else {
Array1OfInteger Split (1, LastIndex - FirstIndex + 1);
else
{
Array1OfInteger Split(1, LastIndex - FirstIndex + 1);
Standard_Integer NbSplit = 1;
Standard_Integer Index = FirstIndex;
Split (NbSplit) = Index;
Split(NbSplit) = Index;
Index++;
NbSplit++;
while (Index < LastIndex) {
if (Degree - Mults (Index) < ContinuityRange) {
Split (NbSplit) = Index;
while (Index < LastIndex)
{
if (Degree - Mults(Index) < ContinuityRange)
{
Split(NbSplit) = Index;
NbSplit++;
}
Index++;
}
Split (NbSplit) = Index;
splitIndexes = new HArray1OfInteger (1, NbSplit);
for (Standard_Integer i = 1; i <= NbSplit; i++) {
splitIndexes->SetValue (i, Split (i));
Split(NbSplit) = Index;
splitIndexes = new HArray1OfInteger(1, NbSplit);
for (Standard_Integer i = 1; i <= NbSplit; i++)
{
splitIndexes->SetValue(i, Split(i));
}
}
}
}
Standard_Integer GeomConvert_BSplineCurveKnotSplitting::NbSplits() const
{
Standard_Integer GeomConvert_BSplineCurveKnotSplitting::NbSplits () const {
return splitIndexes->Length();
return splitIndexes->Length();
}
Standard_Integer GeomConvert_BSplineCurveKnotSplitting::SplitValue(
Standard_Integer GeomConvert_BSplineCurveKnotSplitting::SplitValue (
const Standard_Integer Index
const Standard_Integer Index
) const
{
) const {
Standard_RangeError_Raise_if (
Index < 1 || Index > splitIndexes->Length(), " ");
return splitIndexes->Value (Index);
Standard_RangeError_Raise_if(Index < 1 || Index > splitIndexes->Length(), " ");
return splitIndexes->Value(Index);
}
void GeomConvert_BSplineCurveKnotSplitting::Splitting(
Array1OfInteger& SplitValues
void GeomConvert_BSplineCurveKnotSplitting::Splitting (
) const
{
Array1OfInteger& SplitValues
) const {
for (Standard_Integer i = 1; i <= splitIndexes->Length(); i++){
SplitValues (i) = splitIndexes->Value (i);
for (Standard_Integer i = 1; i <= splitIndexes->Length(); i++)
{
SplitValues(i) = splitIndexes->Value(i);
}
}

View File

@@ -25,7 +25,6 @@
#include <TColStd_Array1OfInteger.hxx>
class Geom_BSplineCurve;
//! An algorithm to determine points at which a BSpline
//! curve should be split in order to obtain arcs of the same continuity.
//! If you require curves with a minimum continuity for
@@ -46,13 +45,11 @@ class Geom_BSplineCurve;
//! required degree of continuity,
//! - implementing the computation algorithm, and
//! - consulting the results.
class GeomConvert_BSplineCurveKnotSplitting
class GeomConvert_BSplineCurveKnotSplitting
{
public:
DEFINE_STANDARD_ALLOC
//! Determines points at which the BSpline curve
//! BasisCurve should be split in order to obtain arcs
//! with a degree of continuity equal to ContinuityRange.
@@ -63,8 +60,9 @@ public:
//! SplitBSplineCurve (provided by the package GeomConvert) to split the curve.
//! Exceptions
//! Standard_RangeError if ContinuityRange is less than zero.
Standard_EXPORT GeomConvert_BSplineCurveKnotSplitting(const Handle(Geom_BSplineCurve)& BasisCurve, const Standard_Integer ContinuityRange);
Standard_EXPORT GeomConvert_BSplineCurveKnotSplitting(const Handle(Geom_BSplineCurve)& BasisCurve,
const Standard_Integer ContinuityRange);
//! Returns the number of points at which the analyzed
//! BSpline curve should be split, in order to obtain arcs
//! with the continuity required by this framework.
@@ -72,7 +70,7 @@ public:
//! the first and last points of the curve, which bound the
//! first and last arcs, are counted among these splitting points.
Standard_EXPORT Standard_Integer NbSplits() const;
//! Loads the SplitValues table with the split knots
//! values computed in this framework. Each value in the
//! table is an index in the knots table of the BSpline
@@ -89,8 +87,8 @@ public:
//! - 1, and
//! - the number of split points computed in this
//! framework (as given by the function NbSplits).
Standard_EXPORT void Splitting (TColStd_Array1OfInteger& SplitValues) const;
Standard_EXPORT void Splitting(TColStd_Array1OfInteger& SplitValues) const;
//! Returns the split knot of index Index to the split knots
//! table computed in this framework. The returned value
//! is an index in the knots table of the BSpline curve
@@ -104,30 +102,11 @@ public:
//! Exceptions
//! Standard_RangeError if Index is less than 1 or
//! greater than the number of split knots computed in this framework.
Standard_EXPORT Standard_Integer SplitValue (const Standard_Integer Index) const;
Standard_EXPORT Standard_Integer SplitValue(const Standard_Integer Index) const;
protected:
private:
Handle(TColStd_HArray1OfInteger) splitIndexes;
};
#endif // _GeomConvert_BSplineCurveKnotSplitting_HeaderFile

View File

@@ -14,7 +14,6 @@
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <Geom_BezierCurve.hxx>
#include <Geom_BSplineCurve.hxx>
#include <GeomConvert_BSplineCurveToBezierCurve.hxx>
@@ -23,128 +22,118 @@
#include <TColgp_Array1OfPnt.hxx>
#include <TColStd_Array1OfReal.hxx>
//=======================================================================
//function : GeomConvert_BSplineCurveToBezierCurve
//purpose :
//=======================================================================
GeomConvert_BSplineCurveToBezierCurve::GeomConvert_BSplineCurveToBezierCurve (const Handle(Geom_BSplineCurve)& BasisCurve)
//=================================================================================================
GeomConvert_BSplineCurveToBezierCurve::GeomConvert_BSplineCurveToBezierCurve(
const Handle(Geom_BSplineCurve)& BasisCurve)
{
myCurve = Handle(Geom_BSplineCurve)::DownCast(BasisCurve->Copy());
myCurve = Handle(Geom_BSplineCurve)::DownCast(BasisCurve->Copy());
Standard_Real Uf = myCurve->FirstParameter();
Standard_Real Ul = myCurve->LastParameter();
myCurve->Segment(Uf,Ul);
myCurve->Segment(Uf, Ul);
myCurve->IncreaseMultiplicity(myCurve->FirstUKnotIndex(),
myCurve->LastUKnotIndex(),
myCurve->Degree());
myCurve->LastUKnotIndex(),
myCurve->Degree());
}
//=======================================================================
//function : GeomConvert_BSplineCurveToBezierCurve
//purpose :
// function : GeomConvert_BSplineCurveToBezierCurve
// purpose :
// 01/12/1997 PMN: On elimine d'eventuelles micro-courbe PRO11516
//=======================================================================Real I
GeomConvert_BSplineCurveToBezierCurve::GeomConvert_BSplineCurveToBezierCurve
(const Handle(Geom_BSplineCurve)& BasisCurve,
const Standard_Real U1,
const Standard_Real U2,
const Standard_Real ParametricTolerance)
GeomConvert_BSplineCurveToBezierCurve::GeomConvert_BSplineCurveToBezierCurve(
const Handle(Geom_BSplineCurve)& BasisCurve,
const Standard_Real U1,
const Standard_Real U2,
const Standard_Real ParametricTolerance)
{
if (U2 - U1 < ParametricTolerance)
throw Standard_DomainError("GeomConvert_BSplineCurveToBezierSurface");
throw Standard_DomainError("GeomConvert_BSplineCurveToBezierSurface");
Standard_Real Uf = U1, Ul = U2;
Standard_Real PTol = ParametricTolerance/2 ;
Standard_Real Uf = U1, Ul = U2;
Standard_Real PTol = ParametricTolerance / 2;
Standard_Integer I1, I2;
myCurve = Handle(Geom_BSplineCurve)::DownCast(BasisCurve->Copy());
myCurve->LocateU(U1, PTol, I1, I2);
if (I1==I2) { // On est sur le noeud
if ( myCurve->Knot(I1) > U1) Uf = myCurve->Knot(I1);
if (I1 == I2)
{ // On est sur le noeud
if (myCurve->Knot(I1) > U1)
Uf = myCurve->Knot(I1);
}
myCurve->LocateU(U2, PTol, I1, I2);
if (I1==I2) { // On est sur le noeud
if ( myCurve->Knot(I1) < U2) Ul = myCurve->Knot(I1);
if (I1 == I2)
{ // On est sur le noeud
if (myCurve->Knot(I1) < U2)
Ul = myCurve->Knot(I1);
}
myCurve->Segment(Uf,Ul);
myCurve->Segment(Uf, Ul);
myCurve->IncreaseMultiplicity(myCurve->FirstUKnotIndex(),
myCurve->LastUKnotIndex(),
myCurve->Degree());
myCurve->LastUKnotIndex(),
myCurve->Degree());
}
//=================================================================================================
//=======================================================================
//function : Arc
//purpose :
//=======================================================================
Handle(Geom_BezierCurve) GeomConvert_BSplineCurveToBezierCurve::Arc
(const Standard_Integer Index)
Handle(Geom_BezierCurve) GeomConvert_BSplineCurveToBezierCurve::Arc(const Standard_Integer Index)
{
if ( Index < 1 || Index > myCurve->NbKnots()-1) {
if (Index < 1 || Index > myCurve->NbKnots() - 1)
{
throw Standard_OutOfRange("GeomConvert_BSplineCurveToBezierCurve");
}
Standard_Integer Deg = myCurve->Degree();
TColgp_Array1OfPnt Poles(1,Deg+1);
TColgp_Array1OfPnt Poles(1, Deg + 1);
Handle(Geom_BezierCurve) C;
if ( myCurve->IsRational()) {
TColStd_Array1OfReal Weights(1,Deg+1);
for ( Standard_Integer i = 1; i <= Deg+1; i++) {
Poles(i) = myCurve->Pole(i+Deg*(Index-1));
Weights(i) = myCurve->Weight(i+Deg*(Index-1));
if (myCurve->IsRational())
{
TColStd_Array1OfReal Weights(1, Deg + 1);
for (Standard_Integer i = 1; i <= Deg + 1; i++)
{
Poles(i) = myCurve->Pole(i + Deg * (Index - 1));
Weights(i) = myCurve->Weight(i + Deg * (Index - 1));
}
C = new Geom_BezierCurve(Poles,Weights);
C = new Geom_BezierCurve(Poles, Weights);
}
else {
for ( Standard_Integer i = 1; i <= Deg+1; i++) {
Poles(i) = myCurve->Pole(i+Deg*(Index-1));
else
{
for (Standard_Integer i = 1; i <= Deg + 1; i++)
{
Poles(i) = myCurve->Pole(i + Deg * (Index - 1));
}
C = new Geom_BezierCurve(Poles);
}
return C;
}
//=================================================================================================
//=======================================================================
//function : Arcs
//purpose :
//=======================================================================
void GeomConvert_BSplineCurveToBezierCurve::Arcs
(TColGeom_Array1OfBezierCurve& Curves)
void GeomConvert_BSplineCurveToBezierCurve::Arcs(TColGeom_Array1OfBezierCurve& Curves)
{
Standard_Integer n = NbArcs();
for ( Standard_Integer i = 1; i <= n; i++) {
for (Standard_Integer i = 1; i <= n; i++)
{
Curves(i) = Arc(i);
}
}
}
//=======================================================================
//function : Knots
//purpose :
//=======================================================================
//=================================================================================================
void GeomConvert_BSplineCurveToBezierCurve::Knots
(TColStd_Array1OfReal& TKnots) const
void GeomConvert_BSplineCurveToBezierCurve::Knots(TColStd_Array1OfReal& TKnots) const
{
Standard_Integer ii, kk;
for (ii = 1, kk = TKnots.Lower();
ii <=myCurve->NbKnots(); ii++, kk++)
Standard_Integer ii, kk;
for (ii = 1, kk = TKnots.Lower(); ii <= myCurve->NbKnots(); ii++, kk++)
TKnots(kk) = myCurve->Knot(ii);
}
//=======================================================================
//function : NbArcs
//purpose :
//=======================================================================
//=================================================================================================
Standard_Integer GeomConvert_BSplineCurveToBezierCurve::NbArcs() const
Standard_Integer GeomConvert_BSplineCurveToBezierCurve::NbArcs() const
{
return (myCurve->NbKnots()-1);
return (myCurve->NbKnots() - 1);
}

View File

@@ -27,7 +27,6 @@
class Geom_BSplineCurve;
class Geom_BezierCurve;
//! An algorithm to convert a BSpline curve into a series
//! of adjacent Bezier curves.
//! A BSplineCurveToBezierCurve object provides a framework for:
@@ -37,17 +36,16 @@ class Geom_BezierCurve;
//! References :
//! Generating the Bezier points of B-spline curves and surfaces
//! (Wolfgang Bohm) CAD volume 13 number 6 november 1981
class GeomConvert_BSplineCurveToBezierCurve
class GeomConvert_BSplineCurveToBezierCurve
{
public:
DEFINE_STANDARD_ALLOC
//! Computes all the data needed to convert the
//! BSpline curve BasisCurve into a series of adjacent Bezier arcs.
Standard_EXPORT GeomConvert_BSplineCurveToBezierCurve(const Handle(Geom_BSplineCurve)& BasisCurve);
Standard_EXPORT GeomConvert_BSplineCurveToBezierCurve(
const Handle(Geom_BSplineCurve)& BasisCurve);
//! Computes all the data needed to convert
//! the portion of the BSpline curve BasisCurve
//! limited by the two parameter values U1 and U2 into a series of adjacent Bezier arcs.
@@ -61,8 +59,11 @@ public:
//! curve [FirstParameter, LastParameter]. The Tolerance criterion
//! is ParametricTolerance.
//! Raised if Abs (U2 - U1) <= ParametricTolerance.
Standard_EXPORT GeomConvert_BSplineCurveToBezierCurve(const Handle(Geom_BSplineCurve)& BasisCurve, const Standard_Real U1, const Standard_Real U2, const Standard_Real ParametricTolerance);
Standard_EXPORT GeomConvert_BSplineCurveToBezierCurve(const Handle(Geom_BSplineCurve)& BasisCurve,
const Standard_Real U1,
const Standard_Real U2,
const Standard_Real ParametricTolerance);
//! Constructs and returns the Bezier curve of index
//! Index to the table of adjacent Bezier arcs
//! computed by this algorithm.
@@ -72,8 +73,8 @@ public:
//! Standard_OutOfRange if Index is less than 1 or
//! greater than the number of adjacent Bezier arcs
//! computed by this algorithm.
Standard_EXPORT Handle(Geom_BezierCurve) Arc (const Standard_Integer Index);
Standard_EXPORT Handle(Geom_BezierCurve) Arc(const Standard_Integer Index);
//! Constructs all the Bezier curves whose data is
//! computed by this algorithm and loads these curves into the Curves table.
//! The Bezier curves have the same orientation as the
@@ -84,14 +85,13 @@ public:
//! - 1 , and
//! - the number of adjacent Bezier arcs computed by
//! this algorithm (as given by the function NbArcs).
Standard_EXPORT void Arcs (TColGeom_Array1OfBezierCurve& Curves);
Standard_EXPORT void Arcs(TColGeom_Array1OfBezierCurve& Curves);
//! This methode returns the bspline's knots associated to
//! the converted arcs
//! Raised if the length of Curves is not equal to
//! NbArcs + 1.
Standard_EXPORT void Knots (TColStd_Array1OfReal& TKnots) const;
Standard_EXPORT void Knots(TColStd_Array1OfReal& TKnots) const;
//! Returns the number of BezierCurve arcs.
//! If at the creation time you have decomposed the basis curve
@@ -103,28 +103,9 @@ public:
//! one.
Standard_EXPORT Standard_Integer NbArcs() const;
protected:
private:
Handle(Geom_BSplineCurve) myCurve;
};
#endif // _GeomConvert_BSplineCurveToBezierCurve_HeaderFile

View File

@@ -12,166 +12,174 @@
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
//Jean-Claude Vauthier 28 Novembre 1991
//Passage sur C1 Aout 1992
// Jean-Claude Vauthier 28 Novembre 1991
// Passage sur C1 Aout 1992
#include <BSplCLib.hxx>
#include <Geom_BSplineSurface.hxx>
#include <GeomConvert_BSplineSurfaceKnotSplitting.hxx>
#include <Standard_RangeError.hxx>
typedef TColStd_Array1OfInteger Array1OfInteger;
typedef TColStd_Array1OfInteger Array1OfInteger;
typedef TColStd_HArray1OfInteger HArray1OfInteger;
GeomConvert_BSplineSurfaceKnotSplitting::
GeomConvert_BSplineSurfaceKnotSplitting (
GeomConvert_BSplineSurfaceKnotSplitting::GeomConvert_BSplineSurfaceKnotSplitting(
const Handle(Geom_BSplineSurface)& BasisSurface,
const Standard_Integer UContinuityRange,
const Standard_Integer VContinuityRange
const Handle(Geom_BSplineSurface)& BasisSurface,
const Standard_Integer UContinuityRange,
const Standard_Integer VContinuityRange
) {
)
{
if (UContinuityRange < 0 || VContinuityRange < 0) {
if (UContinuityRange < 0 || VContinuityRange < 0)
{
throw Standard_RangeError();
}
Standard_Integer FirstUIndex = BasisSurface->FirstUKnotIndex ();
Standard_Integer LastUIndex = BasisSurface->LastUKnotIndex ();
Standard_Integer FirstVIndex = BasisSurface->FirstVKnotIndex ();
Standard_Integer LastVIndex = BasisSurface->LastVKnotIndex ();
Standard_Integer UDegree = BasisSurface->UDegree ();
Standard_Integer VDegree = BasisSurface->VDegree ();
Standard_Integer FirstUIndex = BasisSurface->FirstUKnotIndex();
Standard_Integer LastUIndex = BasisSurface->LastUKnotIndex();
Standard_Integer FirstVIndex = BasisSurface->FirstVKnotIndex();
Standard_Integer LastVIndex = BasisSurface->LastVKnotIndex();
Standard_Integer UDegree = BasisSurface->UDegree();
Standard_Integer VDegree = BasisSurface->VDegree();
Standard_Integer i;
if (UContinuityRange == 0) {
usplitIndexes = new HArray1OfInteger (1, 2);
usplitIndexes->SetValue (1, FirstUIndex);
usplitIndexes->SetValue (2, LastUIndex);
if (UContinuityRange == 0)
{
usplitIndexes = new HArray1OfInteger(1, 2);
usplitIndexes->SetValue(1, FirstUIndex);
usplitIndexes->SetValue(2, LastUIndex);
}
else {
else
{
Standard_Integer NbUKnots = BasisSurface->NbUKnots();
Array1OfInteger UMults (1, NbUKnots);
BasisSurface->UMultiplicities (UMults);
Standard_Integer Mmax = BSplCLib::MaxKnotMult (UMults, FirstUIndex, LastUIndex);
if (UDegree - Mmax >= UContinuityRange) {
usplitIndexes = new HArray1OfInteger (1, 2);
usplitIndexes->SetValue (1, FirstUIndex);
usplitIndexes->SetValue (2, LastUIndex);
Array1OfInteger UMults(1, NbUKnots);
BasisSurface->UMultiplicities(UMults);
Standard_Integer Mmax = BSplCLib::MaxKnotMult(UMults, FirstUIndex, LastUIndex);
if (UDegree - Mmax >= UContinuityRange)
{
usplitIndexes = new HArray1OfInteger(1, 2);
usplitIndexes->SetValue(1, FirstUIndex);
usplitIndexes->SetValue(2, LastUIndex);
}
else {
Array1OfInteger USplit (1, LastUIndex - FirstUIndex + 1);
else
{
Array1OfInteger USplit(1, LastUIndex - FirstUIndex + 1);
Standard_Integer NbUSplit = 1;
Standard_Integer UIndex = FirstUIndex;
USplit (NbUSplit) = UIndex;
Standard_Integer UIndex = FirstUIndex;
USplit(NbUSplit) = UIndex;
UIndex++;
NbUSplit++;
while (UIndex < LastUIndex) {
if (UDegree - UMults(UIndex) < UContinuityRange) {
USplit (NbUSplit) = UIndex;
while (UIndex < LastUIndex)
{
if (UDegree - UMults(UIndex) < UContinuityRange)
{
USplit(NbUSplit) = UIndex;
NbUSplit++;
}
UIndex++;
}
USplit (NbUSplit) = UIndex;
usplitIndexes = new HArray1OfInteger (1, NbUSplit);
for (i = 1; i <= NbUSplit; i++) {
usplitIndexes->SetValue (i, USplit (i));
USplit(NbUSplit) = UIndex;
usplitIndexes = new HArray1OfInteger(1, NbUSplit);
for (i = 1; i <= NbUSplit; i++)
{
usplitIndexes->SetValue(i, USplit(i));
}
}
}
if (VContinuityRange == 0) {
vsplitIndexes = new HArray1OfInteger (1, 2);
vsplitIndexes->SetValue (1, FirstVIndex);
vsplitIndexes->SetValue (2, LastVIndex);
if (VContinuityRange == 0)
{
vsplitIndexes = new HArray1OfInteger(1, 2);
vsplitIndexes->SetValue(1, FirstVIndex);
vsplitIndexes->SetValue(2, LastVIndex);
}
else {
else
{
Standard_Integer NbVKnots = BasisSurface->NbVKnots();
Array1OfInteger VMults (1, NbVKnots);
BasisSurface->VMultiplicities (VMults);
Standard_Integer Mmax = BSplCLib::MaxKnotMult (VMults, FirstVIndex, LastVIndex);
if (VDegree - Mmax >= VContinuityRange) {
usplitIndexes = new HArray1OfInteger (1, 2);
usplitIndexes->SetValue (1, FirstVIndex);
usplitIndexes->SetValue (2, LastVIndex);
Array1OfInteger VMults(1, NbVKnots);
BasisSurface->VMultiplicities(VMults);
Standard_Integer Mmax = BSplCLib::MaxKnotMult(VMults, FirstVIndex, LastVIndex);
if (VDegree - Mmax >= VContinuityRange)
{
usplitIndexes = new HArray1OfInteger(1, 2);
usplitIndexes->SetValue(1, FirstVIndex);
usplitIndexes->SetValue(2, LastVIndex);
}
else {
Array1OfInteger VSplit (1, LastVIndex - FirstVIndex + 1);
Standard_Integer NbVSplit = 1;
Standard_Integer VIndex = FirstVIndex;
VSplit (NbVSplit) = VIndex;
else
{
Array1OfInteger VSplit(1, LastVIndex - FirstVIndex + 1);
Standard_Integer NbVSplit = 1;
Standard_Integer VIndex = FirstVIndex;
VSplit(NbVSplit) = VIndex;
VIndex++;
NbVSplit++;
while (VIndex < LastVIndex) {
if (VDegree - VMults (VIndex) < VContinuityRange) {
VSplit (NbVSplit) = VIndex;
while (VIndex < LastVIndex)
{
if (VDegree - VMults(VIndex) < VContinuityRange)
{
VSplit(NbVSplit) = VIndex;
NbVSplit++;
}
VIndex++;
}
VSplit (NbVSplit) = VIndex;
vsplitIndexes = new HArray1OfInteger (1, NbVSplit);
for (i = 1; i <= NbVSplit; i++) {
vsplitIndexes->SetValue (i, VSplit (i));
VSplit(NbVSplit) = VIndex;
vsplitIndexes = new HArray1OfInteger(1, NbVSplit);
for (i = 1; i <= NbVSplit; i++)
{
vsplitIndexes->SetValue(i, VSplit(i));
}
}
}
}
Standard_Integer GeomConvert_BSplineSurfaceKnotSplitting::NbUSplits () const {
return usplitIndexes->Length();
Standard_Integer GeomConvert_BSplineSurfaceKnotSplitting::NbUSplits() const
{
return usplitIndexes->Length();
}
Standard_Integer GeomConvert_BSplineSurfaceKnotSplitting::NbVSplits () const {
return vsplitIndexes->Length();
Standard_Integer GeomConvert_BSplineSurfaceKnotSplitting::NbVSplits() const
{
return vsplitIndexes->Length();
}
Standard_Integer GeomConvert_BSplineSurfaceKnotSplitting::USplitValue(
Standard_Integer GeomConvert_BSplineSurfaceKnotSplitting::USplitValue (
const Standard_Integer UIndex
const Standard_Integer UIndex
) const
{
) const {
Standard_RangeError_Raise_if (
UIndex < 1 || UIndex > usplitIndexes->Length(), " ");
return usplitIndexes->Value (UIndex);
Standard_RangeError_Raise_if(UIndex < 1 || UIndex > usplitIndexes->Length(), " ");
return usplitIndexes->Value(UIndex);
}
Standard_Integer GeomConvert_BSplineSurfaceKnotSplitting::VSplitValue(
const Standard_Integer VIndex
Standard_Integer GeomConvert_BSplineSurfaceKnotSplitting::VSplitValue (
) const
{
const Standard_Integer VIndex
) const {
Standard_RangeError_Raise_if (
VIndex < 1 || VIndex > vsplitIndexes->Length(), " ");
return vsplitIndexes->Value (VIndex);
Standard_RangeError_Raise_if(VIndex < 1 || VIndex > vsplitIndexes->Length(), " ");
return vsplitIndexes->Value(VIndex);
}
void GeomConvert_BSplineSurfaceKnotSplitting::Splitting(
void GeomConvert_BSplineSurfaceKnotSplitting::Splitting (
Array1OfInteger& USplit,
Array1OfInteger& VSplit
Array1OfInteger& USplit,
Array1OfInteger& VSplit
) const {
Standard_Integer i ;
for ( i = 1; i <= usplitIndexes->Length(); i++){
USplit (i) = usplitIndexes->Value (i);
) const
{
Standard_Integer i;
for (i = 1; i <= usplitIndexes->Length(); i++)
{
USplit(i) = usplitIndexes->Value(i);
}
for (i = 1; i <= vsplitIndexes->Length(); i++){
VSplit (i) = vsplitIndexes->Value (i);
for (i = 1; i <= vsplitIndexes->Length(); i++)
{
VSplit(i) = vsplitIndexes->Value(i);
}
}

View File

@@ -25,7 +25,6 @@
#include <TColStd_Array1OfInteger.hxx>
class Geom_BSplineSurface;
//! An algorithm to determine isoparametric curves along
//! which a BSpline surface should be split in order to
//! obtain patches of the same continuity. The continuity order is given at the
@@ -48,13 +47,11 @@ class Geom_BSplineSurface;
//! local derivatives on the surface you don't need to create the
//! BSpline patches, you can use the functions LocalD1, LocalD2,
//! LocalD3, LocalDN of the class BSplineSurface from package Geom.
class GeomConvert_BSplineSurfaceKnotSplitting
class GeomConvert_BSplineSurfaceKnotSplitting
{
public:
DEFINE_STANDARD_ALLOC
//! Determines the u- and v-isoparametric curves
//! along which the BSpline surface BasisSurface
//! should be split in order to obtain patches with a
@@ -73,8 +70,11 @@ public:
//! Exceptions
//! Standard_RangeError if UContinuityRange or
//! VContinuityRange is less than zero.
Standard_EXPORT GeomConvert_BSplineSurfaceKnotSplitting(const Handle(Geom_BSplineSurface)& BasisSurface, const Standard_Integer UContinuityRange, const Standard_Integer VContinuityRange);
Standard_EXPORT GeomConvert_BSplineSurfaceKnotSplitting(
const Handle(Geom_BSplineSurface)& BasisSurface,
const Standard_Integer UContinuityRange,
const Standard_Integer VContinuityRange);
//! Returns the number of u-isoparametric curves
//! along which the analysed BSpline surface should be
//! split in order to obtain patches with the continuity
@@ -84,7 +84,7 @@ public:
//! Note that the four curves which bound the surface are
//! counted among these splitting curves.
Standard_EXPORT Standard_Integer NbUSplits() const;
//! Returns the number of v-isoparametric curves
//! along which the analysed BSpline surface should be
//! split in order to obtain patches with the continuity
@@ -94,7 +94,7 @@ public:
//! Note that the four curves which bound the surface are
//! counted among these splitting curves.
Standard_EXPORT Standard_Integer NbVSplits() const;
//! Loads the USplit and VSplit tables with the split
//! knots values computed in this framework. Each value
//! in these tables is an index in the knots table
@@ -121,8 +121,9 @@ public:
//! - the number of split knots in the v parametric
//! direction computed in this framework (as given
//! by the function NbVSplits).
Standard_EXPORT void Splitting (TColStd_Array1OfInteger& USplit, TColStd_Array1OfInteger& VSplit) const;
Standard_EXPORT void Splitting(TColStd_Array1OfInteger& USplit,
TColStd_Array1OfInteger& VSplit) const;
//! Returns the split knot of index UIndex
//! to the split knots table for the u parametric direction
//! computed in this framework. The returned value is
@@ -135,8 +136,8 @@ public:
//! Exceptions
//! Standard_RangeError if UIndex is less than 1 or greater than the number
//! of split knots for the u parametric direction computed in this framework.
Standard_EXPORT Standard_Integer USplitValue (const Standard_Integer UIndex) const;
Standard_EXPORT Standard_Integer USplitValue(const Standard_Integer UIndex) const;
//! Returns the split knot of index VIndex
//! to the split knots table for the v parametric direction
//! computed in this framework. The returned value is
@@ -149,31 +150,12 @@ public:
//! Exceptions
//! Standard_RangeError if VIndex is less than 1 or greater than the number
//! of split knots for the v parametric direction computed in this framework.
Standard_EXPORT Standard_Integer VSplitValue (const Standard_Integer VIndex) const;
Standard_EXPORT Standard_Integer VSplitValue(const Standard_Integer VIndex) const;
protected:
private:
Handle(TColStd_HArray1OfInteger) usplitIndexes;
Handle(TColStd_HArray1OfInteger) vsplitIndexes;
};
#endif // _GeomConvert_BSplineSurfaceKnotSplitting_HeaderFile

View File

@@ -14,7 +14,6 @@
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <Geom_BezierSurface.hxx>
#include <Geom_BSplineSurface.hxx>
#include <GeomConvert_BSplineSurfaceToBezierSurface.hxx>
@@ -23,112 +22,117 @@
#include <TColgp_Array2OfPnt.hxx>
#include <TColStd_Array2OfReal.hxx>
//=======================================================================
//function : GeomConvert_BSplineSurfaceToBezierSurface
//purpose :
//=======================================================================
GeomConvert_BSplineSurfaceToBezierSurface::GeomConvert_BSplineSurfaceToBezierSurface(const Handle(Geom_BSplineSurface)& BasisSurface)
//=================================================================================================
GeomConvert_BSplineSurfaceToBezierSurface::GeomConvert_BSplineSurfaceToBezierSurface(
const Handle(Geom_BSplineSurface)& BasisSurface)
{
mySurface = Handle(Geom_BSplineSurface)::DownCast(BasisSurface->Copy());
Standard_Real U1,U2,V1,V2;
mySurface->Bounds(U1,U2,V1,V2);
mySurface->Segment(U1,U2,V1,V2);
Standard_Real U1, U2, V1, V2;
mySurface->Bounds(U1, U2, V1, V2);
mySurface->Segment(U1, U2, V1, V2);
mySurface->IncreaseUMultiplicity(mySurface->FirstUKnotIndex(),
mySurface->LastUKnotIndex(),
mySurface->UDegree());
mySurface->LastUKnotIndex(),
mySurface->UDegree());
mySurface->IncreaseVMultiplicity(mySurface->FirstVKnotIndex(),
mySurface->LastVKnotIndex(),
mySurface->VDegree());
mySurface->LastVKnotIndex(),
mySurface->VDegree());
}
//=================================================================================================
//=======================================================================
//function : GeomConvert_BSplineSurfaceToBezierSurface
//purpose :
//=======================================================================
GeomConvert_BSplineSurfaceToBezierSurface::GeomConvert_BSplineSurfaceToBezierSurface
(const Handle(Geom_BSplineSurface)& BasisSurface,
const Standard_Real U1,
const Standard_Real U2,
const Standard_Real V1,
const Standard_Real V2,
const Standard_Real ParametricTolerance)
GeomConvert_BSplineSurfaceToBezierSurface::GeomConvert_BSplineSurfaceToBezierSurface(
const Handle(Geom_BSplineSurface)& BasisSurface,
const Standard_Real U1,
const Standard_Real U2,
const Standard_Real V1,
const Standard_Real V2,
const Standard_Real ParametricTolerance)
{
if ( (U2 - U1 < ParametricTolerance) ||
(V2 - V1 < ParametricTolerance) )
throw Standard_DomainError("GeomConvert_BSplineSurfaceToBezierSurface");
if ((U2 - U1 < ParametricTolerance) || (V2 - V1 < ParametricTolerance))
throw Standard_DomainError("GeomConvert_BSplineSurfaceToBezierSurface");
Standard_Real Uf=U1, Ul=U2, Vf=V1, Vl=V2, PTol = ParametricTolerance/2;
Standard_Real Uf = U1, Ul = U2, Vf = V1, Vl = V2, PTol = ParametricTolerance / 2;
Standard_Integer I1, I2;
mySurface = Handle(Geom_BSplineSurface)::DownCast(BasisSurface->Copy());
mySurface->LocateU(U1, PTol, I1, I2);
if (I1==I2) { // On est sur le noeud
if ( mySurface->UKnot(I1) > U1) Uf = mySurface->UKnot(I1);
}
if (I1 == I2)
{ // On est sur le noeud
if (mySurface->UKnot(I1) > U1)
Uf = mySurface->UKnot(I1);
}
mySurface->LocateU(U2, PTol, I1, I2);
if (I1==I2) { // On est sur le noeud
if ( mySurface->UKnot(I1) < U2) Ul = mySurface->UKnot(I1);
if (I1 == I2)
{ // On est sur le noeud
if (mySurface->UKnot(I1) < U2)
Ul = mySurface->UKnot(I1);
}
mySurface->LocateV(V1, PTol, I1, I2);
if (I1==I2) { // On est sur le noeud
if ( mySurface->VKnot(I1) > V1) Vf = mySurface->VKnot(I1);
}
if (I1 == I2)
{ // On est sur le noeud
if (mySurface->VKnot(I1) > V1)
Vf = mySurface->VKnot(I1);
}
mySurface->LocateV(V2, PTol, I1, I2);
if (I1==I2) { // On est sur le noeud
if ( mySurface->VKnot(I1) < V2) Vl = mySurface->VKnot(I1);
if (I1 == I2)
{ // On est sur le noeud
if (mySurface->VKnot(I1) < V2)
Vl = mySurface->VKnot(I1);
}
mySurface->Segment(Uf, Ul, Vf, Vl);
mySurface->IncreaseUMultiplicity(mySurface->FirstUKnotIndex(),
mySurface->LastUKnotIndex(),
mySurface->UDegree());
mySurface->LastUKnotIndex(),
mySurface->UDegree());
mySurface->IncreaseVMultiplicity(mySurface->FirstVKnotIndex(),
mySurface->LastVKnotIndex(),
mySurface->VDegree());
mySurface->LastVKnotIndex(),
mySurface->VDegree());
}
//=================================================================================================
//=======================================================================
//function : Patch
//purpose :
//=======================================================================
Handle(Geom_BezierSurface) GeomConvert_BSplineSurfaceToBezierSurface::Patch
(const Standard_Integer UIndex,
const Standard_Integer VIndex)
Handle(Geom_BezierSurface) GeomConvert_BSplineSurfaceToBezierSurface::Patch(
const Standard_Integer UIndex,
const Standard_Integer VIndex)
{
if (UIndex < 1 || UIndex > mySurface->NbUKnots()-1 ||
VIndex < 1 || VIndex > mySurface->NbVKnots()-1 ) {
if (UIndex < 1 || UIndex > mySurface->NbUKnots() - 1 || VIndex < 1
|| VIndex > mySurface->NbVKnots() - 1)
{
throw Standard_OutOfRange("GeomConvert_BSplineSurfaceToBezierSurface");
}
Standard_Integer UDeg = mySurface->UDegree();
Standard_Integer VDeg = mySurface->VDegree();
TColgp_Array2OfPnt Poles(1,UDeg+1,1,VDeg+1);
TColgp_Array2OfPnt Poles(1, UDeg + 1, 1, VDeg + 1);
Handle(Geom_BezierSurface) S;
if ( mySurface->IsURational() || mySurface->IsVRational()) {
TColStd_Array2OfReal Weights(1,UDeg+1,1,VDeg+1);
for ( Standard_Integer i = 1; i <= UDeg+1; i++) {
Standard_Integer CurI = i+UDeg*(UIndex-1);
for ( Standard_Integer j = 1; j <= VDeg+1; j++) {
Poles(i,j) = mySurface->Pole(CurI,j+VDeg*(VIndex-1));
Weights(i,j) = mySurface->Weight(CurI,j+VDeg*(VIndex-1));
if (mySurface->IsURational() || mySurface->IsVRational())
{
TColStd_Array2OfReal Weights(1, UDeg + 1, 1, VDeg + 1);
for (Standard_Integer i = 1; i <= UDeg + 1; i++)
{
Standard_Integer CurI = i + UDeg * (UIndex - 1);
for (Standard_Integer j = 1; j <= VDeg + 1; j++)
{
Poles(i, j) = mySurface->Pole(CurI, j + VDeg * (VIndex - 1));
Weights(i, j) = mySurface->Weight(CurI, j + VDeg * (VIndex - 1));
}
}
S = new Geom_BezierSurface(Poles,Weights);
S = new Geom_BezierSurface(Poles, Weights);
}
else {
for ( Standard_Integer i = 1; i <= UDeg+1; i++) {
Standard_Integer CurI = i+UDeg*(UIndex-1);
for ( Standard_Integer j = 1; j <= VDeg+1; j++) {
Poles(i,j) = mySurface->Pole(CurI,j+VDeg*(VIndex-1));
else
{
for (Standard_Integer i = 1; i <= UDeg + 1; i++)
{
Standard_Integer CurI = i + UDeg * (UIndex - 1);
for (Standard_Integer j = 1; j <= VDeg + 1; j++)
{
Poles(i, j) = mySurface->Pole(CurI, j + VDeg * (VIndex - 1));
}
}
S = new Geom_BezierSurface(Poles);
@@ -136,71 +140,49 @@ Handle(Geom_BezierSurface) GeomConvert_BSplineSurfaceToBezierSurface::Patch
return S;
}
//=================================================================================================
//=======================================================================
//function : Patches
//purpose :
//=======================================================================
void GeomConvert_BSplineSurfaceToBezierSurface::Patches
(TColGeom_Array2OfBezierSurface& Surfaces)
void GeomConvert_BSplineSurfaceToBezierSurface::Patches(TColGeom_Array2OfBezierSurface& Surfaces)
{
Standard_Integer NbU = NbUPatches();
Standard_Integer NbV = NbVPatches();
for (Standard_Integer i = 1; i <= NbU; i++) {
for (Standard_Integer j = 1; j <= NbV; j++) {
Surfaces(i,j) = Patch(i,j);
for (Standard_Integer i = 1; i <= NbU; i++)
{
for (Standard_Integer j = 1; j <= NbV; j++)
{
Surfaces(i, j) = Patch(i, j);
}
}
}
//=======================================================================
//function : UKnots
//purpose :
//=======================================================================
//=================================================================================================
void GeomConvert_BSplineSurfaceToBezierSurface::UKnots
(TColStd_Array1OfReal& TKnots) const
void GeomConvert_BSplineSurfaceToBezierSurface::UKnots(TColStd_Array1OfReal& TKnots) const
{
Standard_Integer ii, kk;
for (ii = 1, kk = TKnots.Lower();
ii <= mySurface->NbUKnots(); ii++, kk++)
Standard_Integer ii, kk;
for (ii = 1, kk = TKnots.Lower(); ii <= mySurface->NbUKnots(); ii++, kk++)
TKnots(kk) = mySurface->UKnot(ii);
}
//=======================================================================
//function : VKnots
//purpose :
//=======================================================================
//=================================================================================================
void GeomConvert_BSplineSurfaceToBezierSurface::VKnots
(TColStd_Array1OfReal& TKnots) const
void GeomConvert_BSplineSurfaceToBezierSurface::VKnots(TColStd_Array1OfReal& TKnots) const
{
Standard_Integer ii, kk;
for (ii = 1, kk = TKnots.Lower();
ii <= mySurface->NbVKnots(); ii++, kk++)
Standard_Integer ii, kk;
for (ii = 1, kk = TKnots.Lower(); ii <= mySurface->NbVKnots(); ii++, kk++)
TKnots(kk) = mySurface->VKnot(ii);
}
//=======================================================================
//function : NbUPatches
//purpose :
//=======================================================================
//=================================================================================================
Standard_Integer GeomConvert_BSplineSurfaceToBezierSurface::NbUPatches() const
Standard_Integer GeomConvert_BSplineSurfaceToBezierSurface::NbUPatches() const
{
return (mySurface->NbUKnots()-1);
return (mySurface->NbUKnots() - 1);
}
//=================================================================================================
//=======================================================================
//function : NbVPatches
//purpose :
//=======================================================================
Standard_Integer GeomConvert_BSplineSurfaceToBezierSurface::NbVPatches() const
Standard_Integer GeomConvert_BSplineSurfaceToBezierSurface::NbVPatches() const
{
return (mySurface->NbVKnots()-1);
return (mySurface->NbVKnots() - 1);
}

View File

@@ -27,8 +27,6 @@
class Geom_BSplineSurface;
class Geom_BezierSurface;
//! This algorithm converts a B-spline surface into several
//! Bezier surfaces. It uses an algorithm of knot insertion.
//! A BSplineSurfaceToBezierSurface object provides a framework for:
@@ -38,13 +36,11 @@ class Geom_BezierSurface;
//! References :
//! Generating the Bezier points of B-spline curves and surfaces
//! (Wolfgang Bohm) CAD volume 13 number 6 november 1981
class GeomConvert_BSplineSurfaceToBezierSurface
class GeomConvert_BSplineSurfaceToBezierSurface
{
public:
DEFINE_STANDARD_ALLOC
//! Computes all the data needed to convert
//! - the BSpline surface BasisSurface into a series of adjacent Bezier surfaces.
//! The result consists of a grid of BasisSurface patches
@@ -59,8 +55,9 @@ public:
//! the number of computed Bezier patches, and then to
//! construct each individual Bezier surface (or all Bezier surfaces).
//! Note: ParametricTolerance is not used.
Standard_EXPORT GeomConvert_BSplineSurfaceToBezierSurface(const Handle(Geom_BSplineSurface)& BasisSurface);
Standard_EXPORT GeomConvert_BSplineSurfaceToBezierSurface(
const Handle(Geom_BSplineSurface)& BasisSurface);
//! Computes all the data needed to convert
//! the patch of the BSpline surface BasisSurface
//! limited by the two parameter values U1 and U2 in
@@ -85,8 +82,14 @@ public:
//! ParametricTolerance.
//! Raised if U2 - U1 <= ParametricTolerance or
//! V2 - V1 <= ParametricTolerance.
Standard_EXPORT GeomConvert_BSplineSurfaceToBezierSurface(const Handle(Geom_BSplineSurface)& BasisSurface, const Standard_Real U1, const Standard_Real U2, const Standard_Real V1, const Standard_Real V2, const Standard_Real ParametricTolerance);
Standard_EXPORT GeomConvert_BSplineSurfaceToBezierSurface(
const Handle(Geom_BSplineSurface)& BasisSurface,
const Standard_Real U1,
const Standard_Real U2,
const Standard_Real V1,
const Standard_Real V2,
const Standard_Real ParametricTolerance);
//! Constructs and returns the Bezier surface of indices
//! (UIndex, VIndex) to the patch grid computed on the
//! BSpline surface analyzed by this algorithm.
@@ -110,8 +113,9 @@ public:
//! of columns in the patch grid computed on the
//! BSpline surface analyzed by this algorithm (as
//! returned by the function NbVPatches).
Standard_EXPORT Handle(Geom_BezierSurface) Patch (const Standard_Integer UIndex, const Standard_Integer VIndex);
Standard_EXPORT Handle(Geom_BezierSurface) Patch(const Standard_Integer UIndex,
const Standard_Integer VIndex);
//! Constructs all the Bezier surfaces whose data is
//! computed by this algorithm, and loads them into the Surfaces table.
//! These Bezier surfaces have the same orientation as
@@ -135,20 +139,19 @@ public:
//! v parametric direction of the patch grid computed
//! on the BSpline surface, analyzed by this algorithm
//! (as given by the function NbVPatches) as column bounds.
Standard_EXPORT void Patches (TColGeom_Array2OfBezierSurface& Surfaces);
Standard_EXPORT void Patches(TColGeom_Array2OfBezierSurface& Surfaces);
//! This methode returns the bspline's u-knots associated to
//! the converted Patches
//! Raised if the length of Curves is not equal to
//! NbUPatches + 1.
Standard_EXPORT void UKnots (TColStd_Array1OfReal& TKnots) const;
Standard_EXPORT void UKnots(TColStd_Array1OfReal& TKnots) const;
//! This methode returns the bspline's v-knots associated to
//! the converted Patches
//! Raised if the length of Curves is not equal to
//! NbVPatches + 1.
Standard_EXPORT void VKnots (TColStd_Array1OfReal& TKnots) const;
Standard_EXPORT void VKnots(TColStd_Array1OfReal& TKnots) const;
//! Returns the number of Bezier surfaces in the U direction.
//! If at the creation time you have decomposed the basis Surface
@@ -159,7 +162,6 @@ public:
//! number of Bezier surfaces NbUPatches is equal to the number of
//! UKnots less one.
Standard_EXPORT Standard_Integer NbUPatches() const;
//! Returns the number of Bezier surfaces in the V direction.
//! If at the creation time you have decomposed the basis surface
@@ -171,28 +173,9 @@ public:
//! VKnots less one.
Standard_EXPORT Standard_Integer NbVPatches() const;
protected:
private:
Handle(Geom_BSplineSurface) mySurface;
};
#endif // _GeomConvert_BSplineSurfaceToBezierSurface_HeaderFile

View File

@@ -14,7 +14,6 @@
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <Geom_BezierSurface.hxx>
#include <Geom_BSplineSurface.hxx>
#include <Geom_Curve.hxx>
@@ -30,49 +29,53 @@
#include <TColStd_HArray1OfReal.hxx>
// ============================================================================
GeomConvert_CompBezierSurfacesToBSplineSurface::
GeomConvert_CompBezierSurfacesToBSplineSurface(const TColGeom_Array2OfBezierSurface& Beziers)
GeomConvert_CompBezierSurfacesToBSplineSurface::GeomConvert_CompBezierSurfacesToBSplineSurface(
const TColGeom_Array2OfBezierSurface& Beziers)
// ============================================================================
{
Standard_Integer ii;
myDone = Standard_True;
// Choix des noeuds
myUKnots = new (TColStd_HArray1OfReal) (1, Beziers.ColLength()+1);
for (ii=0; ii<myUKnots->Length(); ii++) { myUKnots->SetValue(ii+1, ii); }
// Choix des noeuds
myUKnots = new (TColStd_HArray1OfReal)(1, Beziers.ColLength() + 1);
for (ii = 0; ii < myUKnots->Length(); ii++)
{
myUKnots->SetValue(ii + 1, ii);
}
myVKnots = new (TColStd_HArray1OfReal) (1, Beziers.RowLength()+1);
for (ii=0; ii<myVKnots->Length(); ii++) { myVKnots->SetValue(ii+1, ii); }
myVKnots = new (TColStd_HArray1OfReal)(1, Beziers.RowLength() + 1);
for (ii = 0; ii < myVKnots->Length(); ii++)
{
myVKnots->SetValue(ii + 1, ii);
}
// Calcul des Poles
Perform(Beziers);
}
// ============================================================================
GeomConvert_CompBezierSurfacesToBSplineSurface::
GeomConvert_CompBezierSurfacesToBSplineSurface(
const TColGeom_Array2OfBezierSurface& Beziers,
const Standard_Real Tolerance,
const Standard_Boolean RemoveKnots)
GeomConvert_CompBezierSurfacesToBSplineSurface::GeomConvert_CompBezierSurfacesToBSplineSurface(
const TColGeom_Array2OfBezierSurface& Beziers,
const Standard_Real Tolerance,
const Standard_Boolean RemoveKnots)
// ============================================================================
{
Standard_Integer ii, jj, multU=0, multV, minus;
Standard_Boolean Ok;
gp_Vec vec;
Standard_Real V1, V2, V3, Ratio, L1, L2, Tol, val;
gp_Pnt P1, P2, P3;
Standard_Integer ii, jj, multU = 0, multV, minus;
Standard_Boolean Ok;
gp_Vec vec;
Standard_Real V1, V2, V3, Ratio, L1, L2, Tol, val;
gp_Pnt P1, P2, P3;
Handle(Geom_Curve) FirstCurve, SecondCurve;
myDone = Standard_True;
// Choix des noeuds
// Choix des noeuds
myUKnots = new (TColStd_HArray1OfReal) (1, Beziers.ColLength()+1);
myVKnots = new (TColStd_HArray1OfReal) (1, Beziers.RowLength()+1);
myUKnots = new (TColStd_HArray1OfReal)(1, Beziers.ColLength() + 1);
myVKnots = new (TColStd_HArray1OfReal)(1, Beziers.RowLength() + 1);
// --> en U
myUKnots->SetValue(1, 0);
jj = myVKnots->Length()/2;
jj = myVKnots->Length() / 2;
FirstCurve = Beziers(1, jj)->VIso(0.3);
FirstCurve->D0(0, P1);
FirstCurve->D0(0.5, P2);
@@ -83,42 +86,49 @@ GeomConvert_CompBezierSurfacesToBSplineSurface(
V1 = vec.Magnitude();
// si la Parametrisation est trop bizzare on garde la pseudo-longueur
if ((V1 > 1000 * L1) || (V1 < L1 * 1.e-3)) V1 = L1;
for (ii=2; ii<myUKnots->Length(); ii++) {
if ((V1 > 1000 * L1) || (V1 < L1 * 1.e-3))
V1 = L1;
SecondCurve = Beziers(ii, jj)->VIso(0.3);
for (ii = 2; ii < myUKnots->Length(); ii++)
{
SecondCurve = Beziers(ii, jj)->VIso(0.3);
SecondCurve->D1(0, P1, vec);
V2 = vec.Magnitude();
SecondCurve->D0(0.5, P2);
SecondCurve->D1(1, P3, vec);
V3 = vec.Magnitude();
L2 = P1.Distance(P2) + P2.Distance(P3);
// On calcul le ratio, en evitant les cas tordus...
if ((V2 > 1000 * L2) || (V2 < L2 * 1.e-3)) V2 = L2;
if ((V3 > 1000 * L2) || (V3 < L2 * 1.e-3)) V3 = L2;
if ((V2 > 1000 * L2) || (V2 < L2 * 1.e-3))
V2 = L2;
if ((V3 > 1000 * L2) || (V3 < L2 * 1.e-3))
V3 = L2;
Ratio = 1;
if ( (V1 > Precision::Confusion()) && (V2 > Precision::Confusion()) ) {
if ((V1 > Precision::Confusion()) && (V2 > Precision::Confusion()))
{
Ratio = V2 / V1;
}
if ( (Ratio < Precision::Confusion())
|| (Ratio > 1/Precision::Confusion()) ) {Ratio = 1;}
if ((Ratio < Precision::Confusion()) || (Ratio > 1 / Precision::Confusion()))
{
Ratio = 1;
}
// On en deduit un nouveau noeud
val = myUKnots->Value(ii);
myUKnots->SetValue(ii+1, val + Ratio*(val- myUKnots->Value(ii-1)) );
val = myUKnots->Value(ii);
myUKnots->SetValue(ii + 1, val + Ratio * (val - myUKnots->Value(ii - 1)));
// Et c'est reparti, pour un tour
L1 = L2;
V1 = V3;
L1 = L2;
V1 = V3;
FirstCurve = SecondCurve;
}
// --> en V
myVKnots->SetValue(1, 0);
ii = myUKnots->Length()/2;
ii = myUKnots->Length() / 2;
FirstCurve = Beziers(ii, 1)->UIso(0.3);
FirstCurve->D0(0, P1);
FirstCurve->D0(0.5, P2);
@@ -129,36 +139,43 @@ GeomConvert_CompBezierSurfacesToBSplineSurface(
V1 = vec.Magnitude();
// si la Parametrisation est trop bizzare on garde la pseudo-longueur
if ((V1 > 1000 * L1) || (V1 < L1 * 1.e-3)) V1 = L1;
for (jj=2; jj<myVKnots->Length(); jj++) {
if ((V1 > 1000 * L1) || (V1 < L1 * 1.e-3))
V1 = L1;
SecondCurve = Beziers(ii, jj)->UIso(0.3);
for (jj = 2; jj < myVKnots->Length(); jj++)
{
SecondCurve = Beziers(ii, jj)->UIso(0.3);
SecondCurve->D1(0, P1, vec);
V2 = vec.Magnitude();
SecondCurve->D0(0.5, P2);
SecondCurve->D1(1, P3, vec);
V3 = vec.Magnitude();
L2 = P1.Distance(P2) + P2.Distance(P3);
// On calcul le ratio, en evitant les cas tordus...
if ((V2 > 1000 * L2) || (V2 < L2 * 1.e-3)) V2 = L2;
if ((V3 > 1000 * L2) || (V3 < L2 * 1.e-3)) V3 = L2;
if ((V2 > 1000 * L2) || (V2 < L2 * 1.e-3))
V2 = L2;
if ((V3 > 1000 * L2) || (V3 < L2 * 1.e-3))
V3 = L2;
Ratio = 1;
if ( (V1 > Precision::Confusion()) && (V2 > Precision::Confusion()) ) {
if ((V1 > Precision::Confusion()) && (V2 > Precision::Confusion()))
{
Ratio = V2 / V1;
}
if ( (Ratio < Precision::Confusion())
|| (Ratio > 1/Precision::Confusion()) ) {Ratio = 1;}
if ((Ratio < Precision::Confusion()) || (Ratio > 1 / Precision::Confusion()))
{
Ratio = 1;
}
// On en deduit un nouveau noeud
val = myVKnots->Value(jj);
myVKnots->SetValue(jj+1, val + Ratio*(val-myVKnots->Value(jj-1)) );
val = myVKnots->Value(jj);
myVKnots->SetValue(jj + 1, val + Ratio * (val - myVKnots->Value(jj - 1)));
// Et c'est reparti, pour un tour
L1 = L2;
V1 = V3;
L1 = L2;
V1 = V3;
FirstCurve = SecondCurve;
}
@@ -166,73 +183,76 @@ GeomConvert_CompBezierSurfacesToBSplineSurface(
Perform(Beziers);
// Reduction de la multiplicite
Handle(Geom_BSplineSurface) Surface = new (Geom_BSplineSurface)
(myPoles->Array2(),
myUKnots->Array1(),
myVKnots->Array1(),
myUMults->Array1(),
myVMults->Array1(),
myUDegree,
myVDegree);
Handle(Geom_BSplineSurface) Surface = new (Geom_BSplineSurface)(myPoles->Array2(),
myUKnots->Array1(),
myVKnots->Array1(),
myUMults->Array1(),
myVMults->Array1(),
myUDegree,
myVDegree);
if (RemoveKnots) minus = 0;
else minus = 1;
if (RemoveKnots)
minus = 0;
else
minus = 1;
for (ii=myUKnots->Length()-1; ii>1; ii--) {
Ok=Standard_True;
Tol = Tolerance/2;
multU = myUMults->Value(ii)-1;
for ( ; Ok && multU > minus; multU--, Tol/=2) {
for (ii = myUKnots->Length() - 1; ii > 1; ii--)
{
Ok = Standard_True;
Tol = Tolerance / 2;
multU = myUMults->Value(ii) - 1;
for (; Ok && multU > minus; multU--, Tol /= 2)
{
Ok = Surface->RemoveUKnot(ii, multU, Tol);
}
}
for (ii=myVKnots->Length()-1; ii>1; ii--) {
Ok=Standard_True;
Tol = Tolerance/2;
multV = myVMults->Value(ii)-1;
for ( ; Ok && multU > minus; multV--, Tol/=2) {
for (ii = myVKnots->Length() - 1; ii > 1; ii--)
{
Ok = Standard_True;
Tol = Tolerance / 2;
multV = myVMults->Value(ii) - 1;
for (; Ok && multU > minus; multV--, Tol /= 2)
{
Ok = Surface->RemoveVKnot(ii, multV, Tol);
}
}
}
// Les nouveaux champs sont arrivees ....
myPoles = new (TColgp_HArray2OfPnt) (1, Surface->NbUPoles(), 1, Surface->NbVPoles());
Surface->Poles( myPoles->ChangeArray2());
myPoles = new (TColgp_HArray2OfPnt)(1, Surface->NbUPoles(), 1, Surface->NbVPoles());
Surface->Poles(myPoles->ChangeArray2());
myUMults = new (TColStd_HArray1OfInteger) (1, Surface->NbUKnots());
myVMults = new (TColStd_HArray1OfInteger) (1, Surface->NbVKnots());
myUKnots = new (TColStd_HArray1OfReal) (1, Surface->NbUKnots());
myVKnots = new (TColStd_HArray1OfReal) (1, Surface->NbVKnots());
myUMults = new (TColStd_HArray1OfInteger)(1, Surface->NbUKnots());
myVMults = new (TColStd_HArray1OfInteger)(1, Surface->NbVKnots());
myUKnots = new (TColStd_HArray1OfReal)(1, Surface->NbUKnots());
myVKnots = new (TColStd_HArray1OfReal)(1, Surface->NbVKnots());
Surface->UMultiplicities( myUMults->ChangeArray1());
Surface->VMultiplicities( myVMults->ChangeArray1());
Surface->UKnots( myUKnots->ChangeArray1());
Surface->VKnots( myVKnots->ChangeArray1());
Surface->UMultiplicities(myUMults->ChangeArray1());
Surface->VMultiplicities(myVMults->ChangeArray1());
Surface->UKnots(myUKnots->ChangeArray1());
Surface->VKnots(myVKnots->ChangeArray1());
}
// ============================================================================
GeomConvert_CompBezierSurfacesToBSplineSurface::
GeomConvert_CompBezierSurfacesToBSplineSurface(
const TColGeom_Array2OfBezierSurface& Beziers,
const TColStd_Array1OfReal& UKnots,
const TColStd_Array1OfReal& VKnots,
const GeomAbs_Shape UContinuity,
const GeomAbs_Shape VContinuity,
const Standard_Real Tolerance)
GeomConvert_CompBezierSurfacesToBSplineSurface::GeomConvert_CompBezierSurfacesToBSplineSurface(
const TColGeom_Array2OfBezierSurface& Beziers,
const TColStd_Array1OfReal& UKnots,
const TColStd_Array1OfReal& VKnots,
const GeomAbs_Shape UContinuity,
const GeomAbs_Shape VContinuity,
const Standard_Real Tolerance)
// ============================================================================
{
Standard_Integer decu=0, decv=0;
Standard_Integer decu = 0, decv = 0;
Standard_Boolean Ok;
myDone = Standard_True;
// Recuperation des noeuds
myUKnots = new (TColStd_HArray1OfReal) (1, Beziers.ColLength()+1);
myUKnots->ChangeArray1() = UKnots;
// Recuperation des noeuds
myUKnots = new (TColStd_HArray1OfReal)(1, Beziers.ColLength() + 1);
myUKnots->ChangeArray1() = UKnots;
myVKnots = new (TColStd_HArray1OfReal) (1, Beziers.RowLength()+1);
myVKnots = new (TColStd_HArray1OfReal)(1, Beziers.RowLength() + 1);
myVKnots->ChangeArray1() = VKnots;
// Calcul des Poles
@@ -240,217 +260,242 @@ GeomConvert_CompBezierSurfacesToBSplineSurface(
// Obtention des bonne continuitee
switch ( UContinuity ) {
case GeomAbs_C0 :
decu = 0;
break;
case GeomAbs_C1 :
decu = 1;
break;
case GeomAbs_C2 :
decu = 2;
break;
case GeomAbs_C3 :
decu = 3;
break;
default:
throw Standard_ConstructionError(
"GeomConvert_CompBezierSurfacesToBSpl:: UContinuity error");
}
switch ( VContinuity ) {
case GeomAbs_C0 :
decv = 0;
break;
case GeomAbs_C1 :
decv = 1;
break;
case GeomAbs_C2 :
decv = 2;
break;
case GeomAbs_C3 :
decv = 3;
break;
default:
throw Standard_ConstructionError(
"GeomConvert_CompBezierSurfacesToBSpl:: VContinuity error");
switch (UContinuity)
{
case GeomAbs_C0:
decu = 0;
break;
case GeomAbs_C1:
decu = 1;
break;
case GeomAbs_C2:
decu = 2;
break;
case GeomAbs_C3:
decu = 3;
break;
default:
throw Standard_ConstructionError("GeomConvert_CompBezierSurfacesToBSpl:: UContinuity error");
}
if ( (decu>0) || (decv>0) ) {
switch (VContinuity)
{
case GeomAbs_C0:
decv = 0;
break;
case GeomAbs_C1:
decv = 1;
break;
case GeomAbs_C2:
decv = 2;
break;
case GeomAbs_C3:
decv = 3;
break;
default:
throw Standard_ConstructionError("GeomConvert_CompBezierSurfacesToBSpl:: VContinuity error");
}
if ((decu > 0) || (decv > 0))
{
Standard_Integer ii;
Standard_Integer multU = myUDegree - decu;
Standard_ConstructionError_Raise_if(
((multU <= 0) && (myUKnots->Length()>2)) ,
"GeomConvert_CompBezierSurfacesToBSpl:: UContinuity or Udeg error");
Standard_ConstructionError_Raise_if(
((multU <= 0) && (myUKnots->Length() > 2)),
"GeomConvert_CompBezierSurfacesToBSpl:: UContinuity or Udeg error");
Standard_Integer multV = myVDegree - decv;
Standard_ConstructionError_Raise_if(
((multV <= 0) && (myVKnots->Length()>2)) ,
"GeomConvert_CompBezierSurfacesToBSpl:: VContinuity or Vdeg error");
((multV <= 0) && (myVKnots->Length() > 2)),
"GeomConvert_CompBezierSurfacesToBSpl:: VContinuity or Vdeg error");
Handle(Geom_BSplineSurface) Surface = new (Geom_BSplineSurface)
(myPoles->Array2(),
myUKnots->Array1(),
myVKnots->Array1(),
myUMults->Array1(),
myVMults->Array1(),
myUDegree,
myVDegree);
Handle(Geom_BSplineSurface) Surface = new (Geom_BSplineSurface)(myPoles->Array2(),
myUKnots->Array1(),
myVKnots->Array1(),
myUMults->Array1(),
myVMults->Array1(),
myUDegree,
myVDegree);
if (decu>0) {
for (ii=2; ii<myUKnots->Length(); ii++) {
if (decu > 0)
{
for (ii = 2; ii < myUKnots->Length(); ii++)
{
Ok = Surface->RemoveUKnot(ii, multU, Tolerance);
if (!Ok) {myDone = Ok;}
if (!Ok)
{
myDone = Ok;
}
}
}
}
if (decv>0) {
for (ii=2; ii<myVKnots->Length(); ii++) {
if (decv > 0)
{
for (ii = 2; ii < myVKnots->Length(); ii++)
{
Ok = Surface->RemoveVKnot(ii, multV, Tolerance);
if (!Ok) {myDone = Ok;}
if (!Ok)
{
myDone = Ok;
}
}
}
}
// Les nouveaux champs sont arrivees ....
myPoles = new (TColgp_HArray2OfPnt) (1, Surface->NbUPoles(), 1, Surface->NbVPoles());
Surface->Poles( myPoles->ChangeArray2());
Surface->UMultiplicities( myUMults->ChangeArray1());
Surface->VMultiplicities( myVMults->ChangeArray1());
// Les nouveaux champs sont arrivees ....
myPoles = new (TColgp_HArray2OfPnt)(1, Surface->NbUPoles(), 1, Surface->NbVPoles());
Surface->Poles(myPoles->ChangeArray2());
Surface->UMultiplicities(myUMults->ChangeArray1());
Surface->VMultiplicities(myVMults->ChangeArray1());
}
}
// ================================================================================
void GeomConvert_CompBezierSurfacesToBSplineSurface::Perform(
const TColGeom_Array2OfBezierSurface& Beziers)
const TColGeom_Array2OfBezierSurface& Beziers)
// ================================================================================
{
Standard_Integer IU, IV;
// (1) Determination des degrees et si le resultat est rationnel.
isrational = Standard_False;
myUDegree = 1;
myVDegree = 1;
myUDegree = 1;
myVDegree = 1;
for (IU=Beziers.LowerRow(); IU <=Beziers.UpperRow(); IU++) {
for (IV=Beziers.LowerCol(); IV <=Beziers.UpperCol(); IV++) {
if ( Beziers(IU, IV)-> IsURational()
|| Beziers(IU, IV)-> IsVRational()) { isrational = Standard_True;}
for (IU = Beziers.LowerRow(); IU <= Beziers.UpperRow(); IU++)
{
for (IV = Beziers.LowerCol(); IV <= Beziers.UpperCol(); IV++)
{
if (Beziers(IU, IV)->IsURational() || Beziers(IU, IV)->IsVRational())
{
isrational = Standard_True;
}
myUDegree = ( Beziers(IU, IV)->UDegree() > myUDegree ) ?
Beziers(IU, IV)->UDegree() : myUDegree;
myUDegree = (Beziers(IU, IV)->UDegree() > myUDegree) ? Beziers(IU, IV)->UDegree() : myUDegree;
myVDegree = ( Beziers(IU, IV)->VDegree() > myVDegree ) ?
Beziers(IU, IV)->VDegree() : myVDegree;
myVDegree = (Beziers(IU, IV)->VDegree() > myVDegree) ? Beziers(IU, IV)->VDegree() : myVDegree;
}
}
Standard_NotImplemented_Raise_if(isrational,
"CompBezierSurfacesToBSpl : rational !");
Standard_NotImplemented_Raise_if(isrational, "CompBezierSurfacesToBSpl : rational !");
// (2) Boucle sur les carreaux -----------------------------
Handle(Geom_BezierSurface) Patch;
Standard_Integer UIndex, VIndex, uindex, vindex, udeb, vdeb;
Standard_Integer upol, vpol, ii;
Standard_Integer UIndex, VIndex, uindex, vindex, udeb, vdeb;
Standard_Integer upol, vpol, ii;
myPoles =
new (TColgp_HArray2OfPnt)(1,
(myUDegree + 1) * Beziers.ColLength() - myUKnots->Length() + 2,
1,
(myVDegree + 1) * Beziers.RowLength() - myVKnots->Length() + 2);
myPoles = new (TColgp_HArray2OfPnt)
( 1, (myUDegree+1)*Beziers.ColLength() - myUKnots->Length() + 2 ,
1, (myVDegree+1)*Beziers.RowLength() - myVKnots->Length() + 2 );
for (IU = Beziers.LowerRow(); IU <= Beziers.UpperRow(); IU++)
{
UIndex = (IU - 1) * myUDegree + 1;
for (IV = Beziers.LowerCol(); IV <= Beziers.UpperCol(); IV++)
{
for (IU=Beziers.LowerRow(); IU <=Beziers.UpperRow(); IU++) {
UIndex = (IU-1)*myUDegree + 1;
for (IV=Beziers.LowerCol(); IV <=Beziers.UpperCol(); IV++) {
Patch = Beziers(IU, IV);
VIndex = (IV - 1) * myVDegree + 1;
Patch = Beziers(IU, IV);
VIndex = (IV-1)*myVDegree + 1;
// (2.1) Augmentation du degree
// (2.1) Augmentation du degree
Patch->Increase(myUDegree, myVDegree);
// (2.2) Poles a recopier
if (IU==1) {udeb = 1;}
else {udeb = 2;}
if (IV==1) {vdeb = 1;}
else {vdeb = 2;}
// (2.2) Poles a recopier
if (IU == 1)
{
udeb = 1;
}
else
{
udeb = 2;
}
if (IV == 1)
{
vdeb = 1;
}
else
{
vdeb = 2;
}
uindex = UIndex + udeb -1;
uindex = UIndex + udeb - 1;
for (upol = udeb; upol <= myUDegree+1; upol++, uindex++ ) {
vindex = VIndex + vdeb - 1;
for (vpol = vdeb; vpol <= myVDegree+1; vpol++, vindex++) {
myPoles->ChangeValue(uindex, vindex) = Patch->Pole(upol, vpol);
}
}
for (upol = udeb; upol <= myUDegree + 1; upol++, uindex++)
{
vindex = VIndex + vdeb - 1;
for (vpol = vdeb; vpol <= myVDegree + 1; vpol++, vindex++)
{
myPoles->ChangeValue(uindex, vindex) = Patch->Pole(upol, vpol);
}
}
// (2.3) Poles a sommer
if (udeb==2) {
vindex = VIndex + vdeb - 1;
for (vpol = vdeb; vpol <= myVDegree+1; vpol++, vindex++) {
myPoles->ChangeValue(UIndex, vindex).ChangeCoord() +=
Patch->Pole(1, vpol).Coord();
}
}
// (2.3) Poles a sommer
if (udeb == 2)
{
vindex = VIndex + vdeb - 1;
for (vpol = vdeb; vpol <= myVDegree + 1; vpol++, vindex++)
{
myPoles->ChangeValue(UIndex, vindex).ChangeCoord() += Patch->Pole(1, vpol).Coord();
}
}
if (vdeb==2) {
uindex = UIndex + udeb - 1;
for (upol = udeb; upol <= myUDegree+1; upol++, uindex++) {
myPoles->ChangeValue(uindex, VIndex).ChangeCoord() +=
Patch->Pole(upol, 1).Coord();
}
}
if (vdeb == 2)
{
uindex = UIndex + udeb - 1;
for (upol = udeb; upol <= myUDegree + 1; upol++, uindex++)
{
myPoles->ChangeValue(uindex, VIndex).ChangeCoord() += Patch->Pole(upol, 1).Coord();
}
}
if (udeb==2 && vdeb==2) {
myPoles->ChangeValue(UIndex, VIndex).ChangeCoord() +=
Patch->Pole(1, 1).Coord();
}
if (udeb == 2 && vdeb == 2)
{
myPoles->ChangeValue(UIndex, VIndex).ChangeCoord() += Patch->Pole(1, 1).Coord();
}
}
}
// (3) Elimination des redondances
// car dans la boucle precedente on compte :
// car dans la boucle precedente on compte :
// - 2 fois les poles associes aux noeuds simples
// - 4 fois les poles associes aux doubles noeuds (en U et V)
// (3.1) Elimination en U
for ( UIndex = myUDegree+1, ii=2;
ii< myUKnots->Length();
ii++, UIndex+=myUDegree) {
for (vpol = 1; vpol<=myPoles->UpperCol(); vpol++) {
myPoles->ChangeValue(UIndex, vpol).ChangeCoord() *= 0.5;
}
}
for (UIndex = myUDegree + 1, ii = 2; ii < myUKnots->Length(); ii++, UIndex += myUDegree)
{
for (vpol = 1; vpol <= myPoles->UpperCol(); vpol++)
{
myPoles->ChangeValue(UIndex, vpol).ChangeCoord() *= 0.5;
}
}
// (3.2) Elimination en V
for ( VIndex = myVDegree+1, ii=2;
ii< myVKnots->Length();
ii++, VIndex += myVDegree) {
for (upol = 1; upol<=myPoles->UpperRow(); upol++) {
myPoles->ChangeValue(upol, VIndex).ChangeCoord() *= 0.5;
}
}
for (VIndex = myVDegree + 1, ii = 2; ii < myVKnots->Length(); ii++, VIndex += myVDegree)
{
for (upol = 1; upol <= myPoles->UpperRow(); upol++)
{
myPoles->ChangeValue(upol, VIndex).ChangeCoord() *= 0.5;
}
}
// (4) Init des multiplicites
myUMults = new (TColStd_HArray1OfInteger) (1, myUKnots->Length());
myUMults->Init( myUDegree);
myUMults->SetValue(1, myUDegree+1);
myUMults->SetValue( myUMults->Upper(), myUDegree+1);
// (4) Init des multiplicites
myUMults = new (TColStd_HArray1OfInteger)(1, myUKnots->Length());
myUMults->Init(myUDegree);
myUMults->SetValue(1, myUDegree + 1);
myUMults->SetValue(myUMults->Upper(), myUDegree + 1);
myVMults = new (TColStd_HArray1OfInteger) (1, myVKnots->Length());
myVMults->Init( myVDegree);
myVMults->SetValue(1, myVDegree+1);
myVMults->SetValue(myVMults->Upper(), myVDegree+1);
myVMults = new (TColStd_HArray1OfInteger)(1, myVKnots->Length());
myVMults->Init(myVDegree);
myVMults->SetValue(1, myVDegree + 1);
myVMults->SetValue(myVMults->Upper(), myVDegree + 1);
}
// ========================================================================
Standard_Boolean GeomConvert_CompBezierSurfacesToBSplineSurface::IsDone() const
// ========================================================================
{
return myDone;
return myDone;
}

View File

@@ -29,7 +29,6 @@
#include <TColStd_Array1OfReal.hxx>
#include <GeomAbs_Shape.hxx>
//! An algorithm to convert a grid of adjacent
//! non-rational Bezier surfaces (with continuity CM) into a
//! BSpline surface (with continuity CM).
@@ -53,13 +52,11 @@
//! UIndex [1, NbUPatches] Udirection
//!
//! Warning! Patches must have compatible parametrization
class GeomConvert_CompBezierSurfacesToBSplineSurface
class GeomConvert_CompBezierSurfacesToBSplineSurface
{
public:
DEFINE_STANDARD_ALLOC
//! Computes all the data needed to build a "C0"
//! continuous BSpline surface equivalent to the grid of
//! adjacent non-rational Bezier surfaces Beziers.
@@ -114,14 +111,18 @@ public:
//! Exceptions
//! Standard_NotImplemented if one of the Bezier
//! surfaces of the Beziers grid is rational.
Standard_EXPORT GeomConvert_CompBezierSurfacesToBSplineSurface(const TColGeom_Array2OfBezierSurface& Beziers);
Standard_EXPORT GeomConvert_CompBezierSurfacesToBSplineSurface(
const TColGeom_Array2OfBezierSurface& Beziers);
//! Build an Ci uniform (Rational) BSpline surface
//! The highest Continuity Ci is imposed, like the
//! maximal deformation is lower than <Tolerance>.
//! Warning: The Continuity C0 is imposed without any check.
Standard_EXPORT GeomConvert_CompBezierSurfacesToBSplineSurface(const TColGeom_Array2OfBezierSurface& Beziers, const Standard_Real Tolerance, const Standard_Boolean RemoveKnots = Standard_True);
Standard_EXPORT GeomConvert_CompBezierSurfacesToBSplineSurface(
const TColGeom_Array2OfBezierSurface& Beziers,
const Standard_Real Tolerance,
const Standard_Boolean RemoveKnots = Standard_True);
//! Computes all the data needed to construct a BSpline
//! surface equivalent to the adjacent non-rational
//! Bezier surfaces Beziers grid.
@@ -208,55 +209,60 @@ public:
//! degree in the v parametric direction (in the Beziers grid), minus 1 .
//! Standard_NotImplemented if one of the Bezier
//! surfaces in the Beziers grid is rational.
Standard_EXPORT GeomConvert_CompBezierSurfacesToBSplineSurface(const TColGeom_Array2OfBezierSurface& Beziers, const TColStd_Array1OfReal& UKnots, const TColStd_Array1OfReal& VKnots, const GeomAbs_Shape UContinuity = GeomAbs_C0, const GeomAbs_Shape VContinuity = GeomAbs_C0, const Standard_Real Tolerance = 1.0e-4);
Standard_EXPORT GeomConvert_CompBezierSurfacesToBSplineSurface(
const TColGeom_Array2OfBezierSurface& Beziers,
const TColStd_Array1OfReal& UKnots,
const TColStd_Array1OfReal& VKnots,
const GeomAbs_Shape UContinuity = GeomAbs_C0,
const GeomAbs_Shape VContinuity = GeomAbs_C0,
const Standard_Real Tolerance = 1.0e-4);
//! Returns the number of knots in the U direction
//! of the BSpline surface whose data is computed in this framework.
Standard_Integer NbUKnots() const;
Standard_Integer NbUKnots() const;
//! Returns number of poles in the U direction
//! of the BSpline surface whose data is computed in this framework.
Standard_Integer NbUPoles() const;
Standard_Integer NbUPoles() const;
//! Returns the number of knots in the V direction
//! of the BSpline surface whose data is computed in this framework.
Standard_Integer NbVKnots() const;
Standard_Integer NbVKnots() const;
//! Returns the number of poles in the V direction
//! of the BSpline surface whose data is computed in this framework.
Standard_Integer NbVPoles() const;
Standard_Integer NbVPoles() const;
//! Returns the table of poles of the BSpline surface
//! whose data is computed in this framework.
const Handle(TColgp_HArray2OfPnt)& Poles() const;
const Handle(TColgp_HArray2OfPnt)& Poles() const;
//! Returns the knots table for the u parametric
//! direction of the BSpline surface whose data is computed in this framework.
const Handle(TColStd_HArray1OfReal)& UKnots() const;
const Handle(TColStd_HArray1OfReal)& UKnots() const;
//! Returns the degree for the u parametric
//! direction of the BSpline surface whose data is computed in this framework.
Standard_Integer UDegree() const;
Standard_Integer UDegree() const;
//! Returns the knots table for the v parametric
//! direction of the BSpline surface whose data is computed in this framework.
const Handle(TColStd_HArray1OfReal)& VKnots() const;
const Handle(TColStd_HArray1OfReal)& VKnots() const;
//! Returns the degree for the v parametric
//! direction of the BSpline surface whose data is computed in this framework.
Standard_Integer VDegree() const;
Standard_Integer VDegree() const;
//! Returns the multiplicities table for the u
//! parametric direction of the knots of the BSpline
//! surface whose data is computed in this framework.
const Handle(TColStd_HArray1OfInteger)& UMultiplicities() const;
const Handle(TColStd_HArray1OfInteger)& UMultiplicities() const;
//! -- Returns the multiplicities table for the v
//! parametric direction of the knots of the BSpline
//! surface whose data is computed in this framework.
const Handle(TColStd_HArray1OfInteger)& VMultiplicities() const;
const Handle(TColStd_HArray1OfInteger)& VMultiplicities() const;
//! Returns true if the conversion was successful.
//! Unless an exception was raised at the time of
//! construction, the conversion of the Bezier surface
@@ -270,40 +276,22 @@ public:
//! does not satisfy all the initial constraints.
Standard_EXPORT Standard_Boolean IsDone() const;
protected:
private:
//! It used internally by the constructors.
Standard_EXPORT void Perform (const TColGeom_Array2OfBezierSurface& Beziers);
Standard_EXPORT void Perform(const TColGeom_Array2OfBezierSurface& Beziers);
Standard_Integer myUDegree;
Standard_Integer myVDegree;
Standard_Integer myUDegree;
Standard_Integer myVDegree;
Handle(TColStd_HArray1OfInteger) myVMults;
Handle(TColStd_HArray1OfInteger) myUMults;
Handle(TColStd_HArray1OfReal) myUKnots;
Handle(TColStd_HArray1OfReal) myVKnots;
Handle(TColgp_HArray2OfPnt) myPoles;
Standard_Boolean isrational;
Standard_Boolean myDone;
Handle(TColStd_HArray1OfReal) myUKnots;
Handle(TColStd_HArray1OfReal) myVKnots;
Handle(TColgp_HArray2OfPnt) myPoles;
Standard_Boolean isrational;
Standard_Boolean myDone;
};
#include <GeomConvert_CompBezierSurfacesToBSplineSurface.lxx>
#endif // _GeomConvert_CompBezierSurfacesToBSplineSurface_HeaderFile

View File

@@ -18,90 +18,83 @@
#include <TColgp_HArray2OfPnt.hxx>
// ================================================================================
inline Standard_Integer
GeomConvert_CompBezierSurfacesToBSplineSurface::NbUKnots() const
inline Standard_Integer GeomConvert_CompBezierSurfacesToBSplineSurface::NbUKnots() const
// ================================================================================
{
return myUKnots->Length();
}
// ================================================================================
inline Standard_Integer
GeomConvert_CompBezierSurfacesToBSplineSurface::NbUPoles() const
inline Standard_Integer GeomConvert_CompBezierSurfacesToBSplineSurface::NbUPoles() const
// ================================================================================
{
return myPoles->ColLength();
return myPoles->ColLength();
}
// ================================================================================
inline Standard_Integer
GeomConvert_CompBezierSurfacesToBSplineSurface::NbVKnots() const
inline Standard_Integer GeomConvert_CompBezierSurfacesToBSplineSurface::NbVKnots() const
// ================================================================================
{
return myVKnots->Length();
}
// ================================================================================
inline Standard_Integer
GeomConvert_CompBezierSurfacesToBSplineSurface::NbVPoles() const
inline Standard_Integer GeomConvert_CompBezierSurfacesToBSplineSurface::NbVPoles() const
// ================================================================================
{
return myPoles->RowLength();
return myPoles->RowLength();
}
// ================================================================================
inline const Handle(TColgp_HArray2OfPnt)&
GeomConvert_CompBezierSurfacesToBSplineSurface::Poles() const
inline const Handle(TColgp_HArray2OfPnt)& GeomConvert_CompBezierSurfacesToBSplineSurface::Poles()
const
// ================================================================================
{
return myPoles;
return myPoles;
}
// ================================================================================
inline const Handle(TColStd_HArray1OfReal)&
GeomConvert_CompBezierSurfacesToBSplineSurface::UKnots() const
// ================================================================================
inline const Handle(TColStd_HArray1OfReal)& GeomConvert_CompBezierSurfacesToBSplineSurface::UKnots()
const
// ================================================================================
{
return myUKnots;
return myUKnots;
}
// ================================================================================
inline Standard_Integer
GeomConvert_CompBezierSurfacesToBSplineSurface::UDegree() const
// ================================================================================
inline Standard_Integer GeomConvert_CompBezierSurfacesToBSplineSurface::UDegree() const
// ================================================================================
{
return myUDegree;
return myUDegree;
}
// ================================================================================
inline const Handle(TColStd_HArray1OfReal)&
GeomConvert_CompBezierSurfacesToBSplineSurface::VKnots() const
inline const Handle(TColStd_HArray1OfReal)& GeomConvert_CompBezierSurfacesToBSplineSurface::VKnots()
const
// ================================================================================
{
return myVKnots;
return myVKnots;
}
// ================================================================================
inline Standard_Integer
GeomConvert_CompBezierSurfacesToBSplineSurface::VDegree() const
// ================================================================================
inline Standard_Integer GeomConvert_CompBezierSurfacesToBSplineSurface::VDegree() const
// ================================================================================
{
return myVDegree;
return myVDegree;
}
// ================================================================================
inline const Handle(TColStd_HArray1OfInteger)&
GeomConvert_CompBezierSurfacesToBSplineSurface::UMultiplicities() const
inline const Handle(TColStd_HArray1OfInteger)& GeomConvert_CompBezierSurfacesToBSplineSurface::
UMultiplicities() const
// ================================================================================
{
return myUMults;
}
// ================================================================================
inline const Handle(TColStd_HArray1OfInteger)&
GeomConvert_CompBezierSurfacesToBSplineSurface::VMultiplicities() const
inline const Handle(TColStd_HArray1OfInteger)& GeomConvert_CompBezierSurfacesToBSplineSurface::
VMultiplicities() const
// ================================================================================
{
return myVMults;
}

View File

@@ -28,58 +28,52 @@
#include <TColStd_Array1OfInteger.hxx>
#include <TColStd_Array1OfReal.hxx>
//=======================================================================
//function : constructor
//purpose :
//=======================================================================
GeomConvert_CompCurveToBSplineCurve::GeomConvert_CompCurveToBSplineCurve (const Convert_ParameterisationType theParameterisation)
: myTol (Precision::Confusion()),
myType (theParameterisation)
//=================================================================================================
GeomConvert_CompCurveToBSplineCurve::GeomConvert_CompCurveToBSplineCurve(
const Convert_ParameterisationType theParameterisation)
: myTol(Precision::Confusion()),
myType(theParameterisation)
{
//
}
//=======================================================================
//function : constructor
//purpose :
//=======================================================================
GeomConvert_CompCurveToBSplineCurve::
GeomConvert_CompCurveToBSplineCurve(const Handle(Geom_BoundedCurve)& BasisCurve,
const Convert_ParameterisationType Parameterisation) :
myTol(Precision::Confusion()),
myType(Parameterisation)
{
Handle(Geom_BSplineCurve) Bs =
Handle(Geom_BSplineCurve)::DownCast(BasisCurve);
if (!Bs.IsNull()) {
myCurve = Handle(Geom_BSplineCurve)::DownCast(BasisCurve->Copy());
}
else {
myCurve = GeomConvert::CurveToBSplineCurve (BasisCurve, myType);
}
}
//=================================================================================================
//=======================================================================
//function : Add
//purpose :
//=======================================================================
Standard_Boolean GeomConvert_CompCurveToBSplineCurve::
Add(const Handle(Geom_BoundedCurve)& NewCurve,
const Standard_Real Tolerance,
const Standard_Boolean After,
const Standard_Boolean WithRatio,
const Standard_Integer MinM)
GeomConvert_CompCurveToBSplineCurve::GeomConvert_CompCurveToBSplineCurve(
const Handle(Geom_BoundedCurve)& BasisCurve,
const Convert_ParameterisationType Parameterisation)
: myTol(Precision::Confusion()),
myType(Parameterisation)
{
// conversion
Handle(Geom_BSplineCurve) Bs = Handle(Geom_BSplineCurve)::DownCast (NewCurve);
Handle(Geom_BSplineCurve) Bs = Handle(Geom_BSplineCurve)::DownCast(BasisCurve);
if (!Bs.IsNull())
{
Bs = Handle(Geom_BSplineCurve)::DownCast (NewCurve->Copy());
myCurve = Handle(Geom_BSplineCurve)::DownCast(BasisCurve->Copy());
}
else
{
Bs = GeomConvert::CurveToBSplineCurve (NewCurve, myType);
myCurve = GeomConvert::CurveToBSplineCurve(BasisCurve, myType);
}
}
//=================================================================================================
Standard_Boolean GeomConvert_CompCurveToBSplineCurve::Add(const Handle(Geom_BoundedCurve)& NewCurve,
const Standard_Real Tolerance,
const Standard_Boolean After,
const Standard_Boolean WithRatio,
const Standard_Integer MinM)
{
// conversion
Handle(Geom_BSplineCurve) Bs = Handle(Geom_BSplineCurve)::DownCast(NewCurve);
if (!Bs.IsNull())
{
Bs = Handle(Geom_BSplineCurve)::DownCast(NewCurve->Copy());
}
else
{
Bs = GeomConvert::CurveToBSplineCurve(NewCurve, myType);
}
if (myCurve.IsNull())
{
@@ -92,150 +86,175 @@ Add(const Handle(Geom_BoundedCurve)& NewCurve,
Standard_Integer LBs = Bs->NbPoles(), LCb = myCurve->NbPoles();
avant = (( myCurve->Pole(1).Distance(Bs->Pole(1)) < myTol)||
( myCurve->Pole(1).Distance(Bs->Pole(LBs))< myTol));
apres = (( myCurve->Pole(LCb).Distance(Bs->Pole(1)) < myTol) ||
( myCurve->Pole(LCb).Distance(Bs->Pole(LBs))< myTol));
avant = ((myCurve->Pole(1).Distance(Bs->Pole(1)) < myTol)
|| (myCurve->Pole(1).Distance(Bs->Pole(LBs)) < myTol));
apres = ((myCurve->Pole(LCb).Distance(Bs->Pole(1)) < myTol)
|| (myCurve->Pole(LCb).Distance(Bs->Pole(LBs)) < myTol));
// myCurve est (sera) elle fermee ?
if (avant && apres) { // On leve l'ambiguite
if (After) avant = Standard_False;
else apres = Standard_False;
if (avant && apres)
{ // On leve l'ambiguite
if (After)
avant = Standard_False;
else
apres = Standard_False;
}
// Ajout Apres ?
if ( apres) {
if (myCurve->Pole(LCb).Distance(Bs->Pole(LBs)) < myTol) {Bs->Reverse();}
if (apres)
{
if (myCurve->Pole(LCb).Distance(Bs->Pole(LBs)) < myTol)
{
Bs->Reverse();
}
Add(myCurve, Bs, Standard_True, WithRatio, MinM);
return Standard_True;
}
// Ajout avant ?
else if (avant) {
if (myCurve->Pole(1).Distance(Bs->Pole(1)) < myTol) {Bs->Reverse();}
// Ajout avant ?
else if (avant)
{
if (myCurve->Pole(1).Distance(Bs->Pole(1)) < myTol)
{
Bs->Reverse();
}
Add(Bs, myCurve, Standard_False, WithRatio, MinM);
return Standard_True;
}
return Standard_False;
}
void GeomConvert_CompCurveToBSplineCurve::Add(
Handle(Geom_BSplineCurve)& FirstCurve,
Handle(Geom_BSplineCurve)& SecondCurve,
const Standard_Boolean After,
const Standard_Boolean WithRatio,
const Standard_Integer MinM)
void GeomConvert_CompCurveToBSplineCurve::Add(Handle(Geom_BSplineCurve)& FirstCurve,
Handle(Geom_BSplineCurve)& SecondCurve,
const Standard_Boolean After,
const Standard_Boolean WithRatio,
const Standard_Integer MinM)
{
// Harmonisation des degres.
// Harmonisation des degres.
Standard_Integer Deg = Max(FirstCurve->Degree(), SecondCurve->Degree());
if (FirstCurve->Degree() < Deg) { FirstCurve->IncreaseDegree(Deg); }
if (SecondCurve->Degree() < Deg) { SecondCurve->IncreaseDegree(Deg); }
if (FirstCurve->Degree() < Deg)
{
FirstCurve->IncreaseDegree(Deg);
}
if (SecondCurve->Degree() < Deg)
{
SecondCurve->IncreaseDegree(Deg);
}
// Declarationd
Standard_Real L1, L2;
Standard_Integer ii, jj;
Standard_Real Ratio=1, Ratio1, Ratio2, Delta1, Delta2;
Standard_Integer NbP1 = FirstCurve->NbPoles(), NbP2 = SecondCurve->NbPoles();
Standard_Integer NbK1 = FirstCurve->NbKnots(), NbK2 = SecondCurve->NbKnots();
TColStd_Array1OfReal Noeuds (1, NbK1+NbK2-1);
TColgp_Array1OfPnt Poles (1, NbP1+ NbP2-1);
TColStd_Array1OfReal Poids (1, NbP1+ NbP2-1);
TColStd_Array1OfInteger Mults (1, NbK1+NbK2-1);
// Declarationd
Standard_Real L1, L2;
Standard_Integer ii, jj;
Standard_Real Ratio = 1, Ratio1, Ratio2, Delta1, Delta2;
Standard_Integer NbP1 = FirstCurve->NbPoles(), NbP2 = SecondCurve->NbPoles();
Standard_Integer NbK1 = FirstCurve->NbKnots(), NbK2 = SecondCurve->NbKnots();
TColStd_Array1OfReal Noeuds(1, NbK1 + NbK2 - 1);
TColgp_Array1OfPnt Poles(1, NbP1 + NbP2 - 1);
TColStd_Array1OfReal Poids(1, NbP1 + NbP2 - 1);
TColStd_Array1OfInteger Mults(1, NbK1 + NbK2 - 1);
// Ratio de reparametrisation (C1 si possible)
if (WithRatio) {
if (WithRatio)
{
L1 = FirstCurve->DN(FirstCurve->LastParameter(), 1).Magnitude();
L2 = SecondCurve->DN(SecondCurve->FirstParameter(), 1). Magnitude();
if ( (L1 > Precision::Confusion()) && (L2 > Precision::Confusion()) ) {
L2 = SecondCurve->DN(SecondCurve->FirstParameter(), 1).Magnitude();
if ((L1 > Precision::Confusion()) && (L2 > Precision::Confusion()))
{
Ratio = L1 / L2;
}
if ( (Ratio < Precision::Confusion()) || (Ratio > 1/Precision::Confusion()) ) {Ratio = 1;}
if ((Ratio < Precision::Confusion()) || (Ratio > 1 / Precision::Confusion()))
{
Ratio = 1;
}
}
if (After) {
// On ne bouge pas la premiere courbe
if (After)
{
// On ne bouge pas la premiere courbe
Ratio1 = 1;
Delta1 = 0;
Ratio2 = 1/Ratio;
Delta2 = Ratio2*SecondCurve->Knot(1) - FirstCurve->Knot(NbK1);
Ratio2 = 1 / Ratio;
Delta2 = Ratio2 * SecondCurve->Knot(1) - FirstCurve->Knot(NbK1);
}
else {
// On ne bouge pas la seconde courbe
else
{
// On ne bouge pas la seconde courbe
Ratio1 = Ratio;
Delta1 = Ratio1*FirstCurve->Knot(NbK1) - SecondCurve->Knot(1);
Delta1 = Ratio1 * FirstCurve->Knot(NbK1) - SecondCurve->Knot(1);
Ratio2 = 1;
Delta2 = 0;
}
}
// Les Noeuds
// Les Noeuds
Standard_Real eps;
for (ii=1; ii<=NbK1; ii++) {
Noeuds(ii) = Ratio1*FirstCurve->Knot(ii) - Delta1;
if(ii > 1) {
eps = Epsilon (Abs(Noeuds(ii-1)));
if( eps < 5.e-10 ) eps = 5.e-10;
if(Noeuds(ii) - Noeuds(ii-1) <= eps) {
Noeuds(ii) += eps;
for (ii = 1; ii <= NbK1; ii++)
{
Noeuds(ii) = Ratio1 * FirstCurve->Knot(ii) - Delta1;
if (ii > 1)
{
eps = Epsilon(Abs(Noeuds(ii - 1)));
if (eps < 5.e-10)
eps = 5.e-10;
if (Noeuds(ii) - Noeuds(ii - 1) <= eps)
{
Noeuds(ii) += eps;
}
}
Mults(ii) = FirstCurve->Multiplicity(ii);
}
Mults(NbK1) = FirstCurve->Degree();
for (ii=2, jj=NbK1+1; ii<=NbK2; ii++, jj++) {
Noeuds(jj) = Ratio2*SecondCurve->Knot(ii) - Delta2;
eps = Epsilon (Abs(Noeuds(jj-1)));
if( eps < 5.e-10 ) eps = 5.e-10;
if(Noeuds(jj) - Noeuds(jj-1) <= eps) {
for (ii = 2, jj = NbK1 + 1; ii <= NbK2; ii++, jj++)
{
Noeuds(jj) = Ratio2 * SecondCurve->Knot(ii) - Delta2;
eps = Epsilon(Abs(Noeuds(jj - 1)));
if (eps < 5.e-10)
eps = 5.e-10;
if (Noeuds(jj) - Noeuds(jj - 1) <= eps)
{
Noeuds(jj) += eps;
}
Mults(jj) = SecondCurve->Multiplicity(ii);
}
Ratio = FirstCurve->Weight(NbP1) ;
Ratio /= SecondCurve->Weight(1) ;
// Les Poles et Poids
for (ii=1; ii<NbP1; ii++) {
Poles(ii) = FirstCurve->Pole(ii);
Poids(ii) = FirstCurve->Weight(ii);
}
for (ii=1, jj=NbP1; ii<=NbP2; ii++, jj++) {
Poles(jj) = SecondCurve->Pole(ii);
//
// attentiion les poids ne se raccord pas forcement C0
// d'ou Ratio
//
Poids(jj) = Ratio * SecondCurve->Weight(ii);
}
// Creation de la BSpline
myCurve = new (Geom_BSplineCurve) (Poles, Poids, Noeuds, Mults, Deg);
// Reduction eventuelle de la multiplicite jusqu'a MinM
Ratio = FirstCurve->Weight(NbP1);
Ratio /= SecondCurve->Weight(1);
// Les Poles et Poids
for (ii = 1; ii < NbP1; ii++)
{
Poles(ii) = FirstCurve->Pole(ii);
Poids(ii) = FirstCurve->Weight(ii);
}
for (ii = 1, jj = NbP1; ii <= NbP2; ii++, jj++)
{
Poles(jj) = SecondCurve->Pole(ii);
//
// attentiion les poids ne se raccord pas forcement C0
// d'ou Ratio
//
Poids(jj) = Ratio * SecondCurve->Weight(ii);
}
// Creation de la BSpline
myCurve = new (Geom_BSplineCurve)(Poles, Poids, Noeuds, Mults, Deg);
// Reduction eventuelle de la multiplicite jusqu'a MinM
Standard_Boolean Ok = Standard_True;
Standard_Integer M = Mults(NbK1);
while ( (M>MinM) && Ok) {
Standard_Integer M = Mults(NbK1);
while ((M > MinM) && Ok)
{
M--;
Ok = myCurve->RemoveKnot(NbK1, M, myTol);
}
}
//=======================================================================
//function : BSplineCurve
//purpose :
//=======================================================================
//=================================================================================================
Handle(Geom_BSplineCurve) GeomConvert_CompCurveToBSplineCurve::BSplineCurve() const
Handle(Geom_BSplineCurve) GeomConvert_CompCurveToBSplineCurve::BSplineCurve() const
{
return myCurve;
return myCurve;
}
//=======================================================================
//function : Clear
//purpose :
//=======================================================================
//=================================================================================================
void GeomConvert_CompCurveToBSplineCurve::Clear()
{

View File

@@ -26,23 +26,23 @@
class Geom_BSplineCurve;
class Geom_BoundedCurve;
//! Algorithm converts and concat several curve in an BSplineCurve
class GeomConvert_CompCurveToBSplineCurve
class GeomConvert_CompCurveToBSplineCurve
{
public:
DEFINE_STANDARD_ALLOC
//! Initialize the algorithme
//! - Parameterisation is used to convert
Standard_EXPORT GeomConvert_CompCurveToBSplineCurve(const Convert_ParameterisationType Parameterisation = Convert_TgtThetaOver2);
Standard_EXPORT GeomConvert_CompCurveToBSplineCurve(
const Convert_ParameterisationType Parameterisation = Convert_TgtThetaOver2);
//! Initialize the algorithme with one curve
//! - Parameterisation is used to convert
Standard_EXPORT GeomConvert_CompCurveToBSplineCurve(const Handle(Geom_BoundedCurve)& BasisCurve, const Convert_ParameterisationType Parameterisation = Convert_TgtThetaOver2);
Standard_EXPORT GeomConvert_CompCurveToBSplineCurve(
const Handle(Geom_BoundedCurve)& BasisCurve,
const Convert_ParameterisationType Parameterisation = Convert_TgtThetaOver2);
//! Append a curve in the BSpline Return False if the
//! curve is not G0 with the BSplineCurve. Tolerance
//! is used to check continuity and decrease
@@ -53,40 +53,29 @@ public:
//! parameterization. Setting WithRatio to Standard_False may greatly
//! decrease the speed of algorithms like CPnts_AbscissaPoint::AdvPerform
//! when applied to the resulting curve.
Standard_EXPORT Standard_Boolean Add (const Handle(Geom_BoundedCurve)& NewCurve, const Standard_Real Tolerance, const Standard_Boolean After = Standard_False, const Standard_Boolean WithRatio = Standard_True, const Standard_Integer MinM = 0);
Standard_EXPORT Standard_Boolean Add(const Handle(Geom_BoundedCurve)& NewCurve,
const Standard_Real Tolerance,
const Standard_Boolean After = Standard_False,
const Standard_Boolean WithRatio = Standard_True,
const Standard_Integer MinM = 0);
Standard_EXPORT Handle(Geom_BSplineCurve) BSplineCurve() const;
//! Clear a result curve
Standard_EXPORT void Clear();
protected:
private:
//! Concat two BSplineCurves.
Standard_EXPORT void Add (Handle(Geom_BSplineCurve)& FirstCurve, Handle(Geom_BSplineCurve)& SecondCurve, const Standard_Boolean After, const Standard_Boolean WithRatio, const Standard_Integer MinM);
Standard_EXPORT void Add(Handle(Geom_BSplineCurve)& FirstCurve,
Handle(Geom_BSplineCurve)& SecondCurve,
const Standard_Boolean After,
const Standard_Boolean WithRatio,
const Standard_Integer MinM);
Handle(Geom_BSplineCurve) myCurve;
Standard_Real myTol;
Handle(Geom_BSplineCurve) myCurve;
Standard_Real myTol;
Convert_ParameterisationType myType;
};
#endif // _GeomConvert_CompCurveToBSplineCurve_HeaderFile

View File

@@ -13,6 +13,7 @@
#ifndef _GeomConvert_ConvType_HeaderFile
#define _GeomConvert_ConvType_HeaderFile
enum GeomConvert_ConvType
{
GeomConvert_Target,

File diff suppressed because it is too large Load Diff

View File

@@ -1,18 +1,18 @@
// Created: 2001-05-21
//
// Copyright (c) 2001-2013 OPEN CASCADE SAS
//
// This file is part of commercial software by OPEN CASCADE SAS,
// furnished in accordance with the terms and conditions of the contract
// and with the inclusion of this copyright notice.
// This file or any part thereof may not be provided or otherwise
// made available to any third party.
//
// No ownership title to the software is transferred hereby.
//
// OPEN CASCADE SAS makes no representation or warranties with respect to the
// performance of this software, and specifically disclaims any responsibility
// for any damages, special or consequential, connected with its use.
// Created: 2001-05-21
//
// Copyright (c) 2001-2013 OPEN CASCADE SAS
//
// This file is part of commercial software by OPEN CASCADE SAS,
// furnished in accordance with the terms and conditions of the contract
// and with the inclusion of this copyright notice.
// This file or any part thereof may not be provided or otherwise
// made available to any third party.
//
// No ownership title to the software is transferred hereby.
//
// OPEN CASCADE SAS makes no representation or warranties with respect to the
// performance of this software, and specifically disclaims any responsibility
// for any damages, special or consequential, connected with its use.
#ifndef _GeomConvert_CurveToAnaCurve_HeaderFile
#define _GeomConvert_CurveToAnaCurve_HeaderFile
@@ -32,102 +32,112 @@ class gp_Lin;
class gp_Pnt;
class gp_Circ;
class GeomConvert_CurveToAnaCurve
class GeomConvert_CurveToAnaCurve
{
public:
DEFINE_STANDARD_ALLOC
Standard_EXPORT GeomConvert_CurveToAnaCurve();
Standard_EXPORT GeomConvert_CurveToAnaCurve(const Handle(Geom_Curve)& C);
Standard_EXPORT void Init (const Handle(Geom_Curve)& C);
Standard_EXPORT void Init(const Handle(Geom_Curve)& C);
//! Converts me to analytical if possible with given
//! tolerance. The new first and last parameters are
//! returned to newF, newL
Standard_EXPORT Standard_Boolean ConvertToAnalytical (const Standard_Real theTol, Handle(Geom_Curve)& theResultCurve, const Standard_Real F, const Standard_Real L, Standard_Real& newF, Standard_Real& newL);
Standard_EXPORT static Handle(Geom_Curve) ComputeCurve (const Handle(Geom_Curve)& curve, const Standard_Real tolerance,
const Standard_Real c1, const Standard_Real c2, Standard_Real& cf, Standard_Real& cl,
Standard_Real& theGap, const GeomConvert_ConvType theCurvType = GeomConvert_MinGap, const GeomAbs_CurveType theTarget = GeomAbs_Line);
Standard_EXPORT Standard_Boolean ConvertToAnalytical(const Standard_Real theTol,
Handle(Geom_Curve)& theResultCurve,
const Standard_Real F,
const Standard_Real L,
Standard_Real& newF,
Standard_Real& newL);
Standard_EXPORT static Handle(Geom_Curve) ComputeCurve(
const Handle(Geom_Curve)& curve,
const Standard_Real tolerance,
const Standard_Real c1,
const Standard_Real c2,
Standard_Real& cf,
Standard_Real& cl,
Standard_Real& theGap,
const GeomConvert_ConvType theCurvType = GeomConvert_MinGap,
const GeomAbs_CurveType theTarget = GeomAbs_Line);
//! Tries to convert the given curve to circle with given
//! tolerance. Returns NULL curve if conversion is
//! not possible.
Standard_EXPORT static Handle(Geom_Curve) ComputeCircle (const Handle(Geom_Curve)& curve, const Standard_Real tolerance, const Standard_Real c1, const Standard_Real c2, Standard_Real& cf, Standard_Real& cl, Standard_Real& Deviation);
Standard_EXPORT static Handle(Geom_Curve) ComputeCircle(const Handle(Geom_Curve)& curve,
const Standard_Real tolerance,
const Standard_Real c1,
const Standard_Real c2,
Standard_Real& cf,
Standard_Real& cl,
Standard_Real& Deviation);
//! Tries to convert the given curve to ellipse with given
//! tolerance. Returns NULL curve if conversion is
//! not possible.
Standard_EXPORT static Handle(Geom_Curve) ComputeEllipse (const Handle(Geom_Curve)& curve, const Standard_Real tolerance, const Standard_Real c1, const Standard_Real c2, Standard_Real& cf, Standard_Real& cl, Standard_Real& Deviation);
Standard_EXPORT static Handle(Geom_Curve) ComputeEllipse(const Handle(Geom_Curve)& curve,
const Standard_Real tolerance,
const Standard_Real c1,
const Standard_Real c2,
Standard_Real& cf,
Standard_Real& cl,
Standard_Real& Deviation);
//! Tries to convert the given curve to line with given
//! tolerance. Returns NULL curve if conversion is
//! not possible.
Standard_EXPORT static Handle(Geom_Line) ComputeLine (const Handle(Geom_Curve)& curve, const Standard_Real tolerance, const Standard_Real c1, const Standard_Real c2, Standard_Real& cf, Standard_Real& cl, Standard_Real& Deviation);
Standard_EXPORT static Handle(Geom_Line) ComputeLine(const Handle(Geom_Curve)& curve,
const Standard_Real tolerance,
const Standard_Real c1,
const Standard_Real c2,
Standard_Real& cf,
Standard_Real& cl,
Standard_Real& Deviation);
//! Returns true if the set of points is linear with given
//! tolerance
Standard_EXPORT static Standard_Boolean IsLinear (const TColgp_Array1OfPnt& aPoints, const Standard_Real tolerance, Standard_Real& Deviation);
Standard_EXPORT static Standard_Boolean IsLinear(const TColgp_Array1OfPnt& aPoints,
const Standard_Real tolerance,
Standard_Real& Deviation);
//! Creates line on two points.
//! Resulting parameters returned
Standard_EXPORT static gp_Lin GetLine(const gp_Pnt& P1, const gp_Pnt& P2, Standard_Real& cf, Standard_Real& cl);
Standard_EXPORT static gp_Lin GetLine(const gp_Pnt& P1,
const gp_Pnt& P2,
Standard_Real& cf,
Standard_Real& cl);
//! Creates circle on points. Returns true if OK.
Standard_EXPORT static Standard_Boolean GetCircle(gp_Circ& Circ, const gp_Pnt& P0, const gp_Pnt& P1, const gp_Pnt& P2);
Standard_EXPORT static Standard_Boolean GetCircle(gp_Circ& Circ,
const gp_Pnt& P0,
const gp_Pnt& P1,
const gp_Pnt& P2);
//! Returns maximal deviation of converted surface from the original
//! one computed by last call to ConvertToAnalytical
Standard_Real Gap() const
{
return myGap;
}
Standard_Real Gap() const { return myGap; }
//! Returns conversion type
GeomConvert_ConvType GetConvType() const
{
return myConvType;
}
//! Returns conversion type
GeomConvert_ConvType GetConvType() const { return myConvType; }
//! Sets type of conversion
void SetConvType(const GeomConvert_ConvType theConvType)
{
myConvType = theConvType;
}
void SetConvType(const GeomConvert_ConvType theConvType) { myConvType = theConvType; }
//! Returns target curve type
GeomAbs_CurveType GetTarget() const
{
return myTarget;
}
//! Returns target curve type
GeomAbs_CurveType GetTarget() const { return myTarget; }
//! Sets target curve type
void SetTarget(const GeomAbs_CurveType theTarget)
{
myTarget = theTarget;
}
void SetTarget(const GeomAbs_CurveType theTarget) { myTarget = theTarget; }
protected:
private:
Handle(Geom_Curve) myCurve;
Standard_Real myGap;
Handle(Geom_Curve) myCurve;
Standard_Real myGap;
GeomConvert_ConvType myConvType;
GeomAbs_CurveType myTarget;
GeomAbs_CurveType myTarget;
};
#endif // _GeomConvert_CurveToAnaCurve_HeaderFile

View File

@@ -12,7 +12,6 @@
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <GeomConvert_FuncConeLSDist.hxx>
#include <gp_Pnt.hxx>
#include <gp_Vec.hxx>
@@ -20,42 +19,36 @@
#include <math_Vector.hxx>
#include <ElSLib.hxx>
//=======================================================================
//function : GeomConvert_FuncConeLSDist
//purpose :
//=======================================================================
GeomConvert_FuncConeLSDist::GeomConvert_FuncConeLSDist(
const Handle(TColgp_HArray1OfXYZ)& thePoints,
const gp_Dir& theDir):
myPoints(thePoints), myDir(theDir)
//=================================================================================================
GeomConvert_FuncConeLSDist::GeomConvert_FuncConeLSDist(const Handle(TColgp_HArray1OfXYZ)& thePoints,
const gp_Dir& theDir)
: myPoints(thePoints),
myDir(theDir)
{
}
//=======================================================================
//function : NbVariables
//purpose :
//=======================================================================
Standard_Integer GeomConvert_FuncConeLSDist::NbVariables () const
//=================================================================================================
Standard_Integer GeomConvert_FuncConeLSDist::NbVariables() const
{
return 5;
}
//=======================================================================
//function : Value
//purpose :
//=======================================================================
//=================================================================================================
Standard_Boolean GeomConvert_FuncConeLSDist::Value(const math_Vector& X, Standard_Real& F)
{
gp_Pnt aLoc(X(1), X(2), X(3));
gp_Pnt aLoc(X(1), X(2), X(3));
Standard_Real aSemiAngle = X(4), anR = X(5);
gp_Ax3 aPos(aLoc, myDir);
gp_Ax3 aPos(aLoc, myDir);
F = 0.;
Standard_Integer i;
for (i = myPoints->Lower(); i <= myPoints->Upper(); ++i)
{
Standard_Real u, v;
gp_Pnt aPi(myPoints->Value(i));
gp_Pnt aPi(myPoints->Value(i));
ElSLib::ConeParameters(aPos, anR, aSemiAngle, aPi, u, v);
gp_Pnt aPp;
ElSLib::ConeD0(u, v, aPos, anR, aSemiAngle, aPp);
@@ -64,5 +57,3 @@ Standard_Boolean GeomConvert_FuncConeLSDist::Value(const math_Vector& X, Standar
return Standard_True;
}

View File

@@ -23,44 +23,34 @@
#include <math_Vector.hxx>
#include <gp_Dir.hxx>
//! Function for search of Cone canonic parameters: coordinates of center local coordinate system,
//! Function for search of Cone canonic parameters: coordinates of center local coordinate system,
//! direction of axis, radius and semi-angle from set of points
//! by least square method.
//!
//!
//!
class GeomConvert_FuncConeLSDist : public math_MultipleVarFunction
{
public:
DEFINE_STANDARD_ALLOC
//! Constructor.
Standard_EXPORT GeomConvert_FuncConeLSDist() {};
Standard_EXPORT GeomConvert_FuncConeLSDist(const Handle(TColgp_HArray1OfXYZ)& thePoints,
const gp_Dir& theDir);
const gp_Dir& theDir);
void SetPoints(const Handle(TColgp_HArray1OfXYZ)& thePoints)
{
myPoints = thePoints;
}
void SetPoints(const Handle(TColgp_HArray1OfXYZ)& thePoints) { myPoints = thePoints; }
void SetDir(const gp_Dir& theDir)
{
myDir = theDir;
}
void SetDir(const gp_Dir& theDir) { myDir = theDir; }
//! Number of variables.
Standard_EXPORT Standard_Integer NbVariables() const Standard_OVERRIDE;
//! Value.
Standard_EXPORT Standard_Boolean Value(const math_Vector& X,Standard_Real& F) Standard_OVERRIDE;
Standard_EXPORT Standard_Boolean Value(const math_Vector& X, Standard_Real& F) Standard_OVERRIDE;
private:
Handle(TColgp_HArray1OfXYZ) myPoints;
gp_Dir myDir;
gp_Dir myDir;
};
#endif // _GeomConvert_FuncConeLSDist_HeaderFile

View File

@@ -12,62 +12,54 @@
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <GeomConvert_FuncCylinderLSDist.hxx>
#include <gp_Pnt.hxx>
#include <gp_Vec.hxx>
#include <math_Vector.hxx>
//=======================================================================
//function : GeomConvert_FuncCylinderLSDist
//purpose :
//=======================================================================
//=================================================================================================
GeomConvert_FuncCylinderLSDist::GeomConvert_FuncCylinderLSDist(
const Handle(TColgp_HArray1OfXYZ)& thePoints,
const gp_Dir& theDir):
myPoints(thePoints), myDir(theDir)
const Handle(TColgp_HArray1OfXYZ)& thePoints,
const gp_Dir& theDir)
: myPoints(thePoints),
myDir(theDir)
{
}
//=======================================================================
//function : NbVariables
//purpose :
//=======================================================================
Standard_Integer GeomConvert_FuncCylinderLSDist::NbVariables () const
//=================================================================================================
Standard_Integer GeomConvert_FuncCylinderLSDist::NbVariables() const
{
return 4;
}
//=======================================================================
//function : Value
//purpose :
//=======================================================================
Standard_Boolean GeomConvert_FuncCylinderLSDist::Value(const math_Vector& X,Standard_Real& F)
//=================================================================================================
Standard_Boolean GeomConvert_FuncCylinderLSDist::Value(const math_Vector& X, Standard_Real& F)
{
gp_XYZ aLoc(X(1), X(2), X(3));
Standard_Real anR2 = X(4)*X(4);
gp_XYZ aLoc(X(1), X(2), X(3));
Standard_Real anR2 = X(4) * X(4);
F = 0.;
Standard_Integer i;
for (i = myPoints->Lower(); i <= myPoints->Upper(); ++i)
{
gp_Vec aV(myPoints->Value(i) - aLoc);
gp_Vec aV(myPoints->Value(i) - aLoc);
Standard_Real aD2 = aV.CrossSquareMagnitude(myDir);
Standard_Real d = aD2 - anR2;
Standard_Real d = aD2 - anR2;
F += d * d;
}
return Standard_True;
}
//=======================================================================
//function : Gradient
//purpose :
//=======================================================================
Standard_Boolean GeomConvert_FuncCylinderLSDist::Gradient(const math_Vector& X,math_Vector& G)
//=================================================================================================
Standard_Boolean GeomConvert_FuncCylinderLSDist::Gradient(const math_Vector& X, math_Vector& G)
{
gp_XYZ aLoc(X(1), X(2), X(3));
gp_XYZ aLoc(X(1), X(2), X(3));
Standard_Real anR = X(4), anR2 = anR * anR;
Standard_Real x = myDir.X(), y = myDir.Y(), z = myDir.Z();
G.Init(0.);
@@ -75,15 +67,12 @@ Standard_Boolean GeomConvert_FuncCylinderLSDist::Gradient(const math_Vector& X,m
Standard_Integer i;
for (i = myPoints->Lower(); i <= myPoints->Upper(); ++i)
{
gp_Vec aV(myPoints->Value(i) - aLoc);
gp_Vec aV(myPoints->Value(i) - aLoc);
Standard_Real aD2 = aV.CrossSquareMagnitude(myDir);
Standard_Real d = aD2 - anR2;
Standard_Real Dx0 = 2.*(aV.Z()*x - aV.X()*z)*z
-2.*(aV.X()*y - aV.Y()*x)*y;
Standard_Real Dy0 = -2.*(aV.Y()*z - aV.Z()*y)*z
+2.*(aV.X()*y - aV.Y()*x)*x;
Standard_Real Dz0 = 2.*(aV.Y()*z - aV.Z()*y)*y
-2.*(aV.Z()*x - aV.X()*z)*x;
Standard_Real d = aD2 - anR2;
Standard_Real Dx0 = 2. * (aV.Z() * x - aV.X() * z) * z - 2. * (aV.X() * y - aV.Y() * x) * y;
Standard_Real Dy0 = -2. * (aV.Y() * z - aV.Z() * y) * z + 2. * (aV.X() * y - aV.Y() * x) * x;
Standard_Real Dz0 = 2. * (aV.Y() * z - aV.Z() * y) * y - 2. * (aV.Z() * x - aV.X() * z) * x;
G(1) += d * Dx0;
G(2) += d * Dy0;
@@ -93,18 +82,18 @@ Standard_Boolean GeomConvert_FuncCylinderLSDist::Gradient(const math_Vector& X,m
}
G *= 2;
G(6) *= -2.*anR;
G(6) *= -2. * anR;
return Standard_True;
}
//=======================================================================
//function : Values
//purpose :
//=======================================================================
Standard_Boolean GeomConvert_FuncCylinderLSDist::Values(const math_Vector& X,Standard_Real& F,math_Vector& G)
//=================================================================================================
Standard_Boolean GeomConvert_FuncCylinderLSDist::Values(const math_Vector& X,
Standard_Real& F,
math_Vector& G)
{
gp_XYZ aLoc(X(1), X(2), X(3));
gp_XYZ aLoc(X(1), X(2), X(3));
Standard_Real anR = X(4), anR2 = anR * anR;
Standard_Real x = myDir.X(), y = myDir.Y(), z = myDir.Z();
@@ -113,15 +102,12 @@ Standard_Boolean GeomConvert_FuncCylinderLSDist::Values(const math_Vector& X,Sta
Standard_Integer i;
for (i = myPoints->Lower(); i <= myPoints->Upper(); ++i)
{
gp_Vec aV(myPoints->Value(i) - aLoc);
gp_Vec aV(myPoints->Value(i) - aLoc);
Standard_Real aD2 = aV.CrossSquareMagnitude(myDir);
Standard_Real d = aD2 - anR2;
Standard_Real Dx0 = 2.*(aV.Z()*x - aV.X()*z)*z
- 2.*(aV.X()*y - aV.Y()*x)*y;
Standard_Real Dy0 = -2.*(aV.Y()*z - aV.Z()*y)*z
+ 2.*(aV.X()*y - aV.Y()*x)*x;
Standard_Real Dz0 = 2.*(aV.Y()*z - aV.Z()*y)*y
- 2.*(aV.Z()*x - aV.X()*z)*x;
Standard_Real d = aD2 - anR2;
Standard_Real Dx0 = 2. * (aV.Z() * x - aV.X() * z) * z - 2. * (aV.X() * y - aV.Y() * x) * y;
Standard_Real Dy0 = -2. * (aV.Y() * z - aV.Z() * y) * z + 2. * (aV.X() * y - aV.Y() * x) * x;
Standard_Real Dz0 = 2. * (aV.Y() * z - aV.Z() * y) * y - 2. * (aV.Z() * x - aV.X() * z) * x;
G(1) += d * Dx0;
G(2) += d * Dy0;
@@ -133,8 +119,7 @@ Standard_Boolean GeomConvert_FuncCylinderLSDist::Values(const math_Vector& X,Sta
}
G *= 2;
G(4) *= -2.*anR;
G(4) *= -2. * anR;
return true;
}

View File

@@ -23,20 +23,17 @@
#include <math_Vector.hxx>
#include <gp_Dir.hxx>
//! Function for search of cylinder canonic parameters: coordinates of center local coordinate system,
//! direction of axis and radius from set of points
//! by least square method.
//!
//! Function for search of cylinder canonic parameters: coordinates of center local coordinate
//! system, direction of axis and radius from set of points by least square method.
//!
//! The class inherits math_MultipleVarFunctionWithGradient and thus is intended
//! for use in math_BFGS algorithm.
//!
//! Parametrisation:
//! Cylinder is defined by its axis and radius. Axis is defined by 3 cartesian coordinates at location x0, y0, z0
//! and direction, which is constant and set by user:
//! dir.x, dir.y, dir.z
//! The criteria is:
//! F(x0, y0, z0, theta, phi, R) = Sum[|(P(i) - Loc)^dir|^2 - R^2]^2 => min
//! P(i) is i-th sample point, Loc, dir - axis location and direction, R - radius
//! Cylinder is defined by its axis and radius. Axis is defined by 3 cartesian coordinates at
//! location x0, y0, z0 and direction, which is constant and set by user: dir.x, dir.y, dir.z The
//! criteria is: F(x0, y0, z0, theta, phi, R) = Sum[|(P(i) - Loc)^dir|^2 - R^2]^2 => min P(i) is
//! i-th sample point, Loc, dir - axis location and direction, R - radius
//!
//! The square vector product |(P(i) - Loc)^dir|^2 is:
//!
@@ -45,7 +42,7 @@
//! [(x - x0)*dir.y - (y - y0)*dir.x]^2
//!
//! First derivative of square vector product are:
//! Dx0 = 2*[(z - z0)*dir.x - (x - x0)*dir.z]*dir.z
//! Dx0 = 2*[(z - z0)*dir.x - (x - x0)*dir.z]*dir.z
//! -2*[(x - x0)*dir.y - (y - y0)*dir.x]*dir.y
//! Dy0 = -2*[(y - y0)*dir.z - (z - z0)*dir.y]*dir.z
//! +2*[(x - x0)*dir.y - (y - y0)*dir.x]*dir.x
@@ -60,41 +57,34 @@
class GeomConvert_FuncCylinderLSDist : public math_MultipleVarFunctionWithGradient
{
public:
DEFINE_STANDARD_ALLOC
//! Constructor.
Standard_EXPORT GeomConvert_FuncCylinderLSDist() {};
Standard_EXPORT GeomConvert_FuncCylinderLSDist(const Handle(TColgp_HArray1OfXYZ)& thePoints,
const gp_Dir& theDir);
const gp_Dir& theDir);
void SetPoints(const Handle(TColgp_HArray1OfXYZ)& thePoints)
{
myPoints = thePoints;
}
void SetPoints(const Handle(TColgp_HArray1OfXYZ)& thePoints) { myPoints = thePoints; }
void SetDir(const gp_Dir& theDir)
{
myDir = theDir;
}
void SetDir(const gp_Dir& theDir) { myDir = theDir; }
//! Number of variables.
Standard_EXPORT Standard_Integer NbVariables() const Standard_OVERRIDE;
//! Value.
Standard_EXPORT Standard_Boolean Value(const math_Vector& X,Standard_Real& F) Standard_OVERRIDE;
Standard_EXPORT Standard_Boolean Value(const math_Vector& X, Standard_Real& F) Standard_OVERRIDE;
//! Gradient.
Standard_EXPORT Standard_Boolean Gradient(const math_Vector& X,math_Vector& G) Standard_OVERRIDE;
Standard_EXPORT Standard_Boolean Gradient(const math_Vector& X, math_Vector& G) Standard_OVERRIDE;
//! Value and gradient.
Standard_EXPORT Standard_Boolean Values(const math_Vector& X,Standard_Real& F,math_Vector& G) Standard_OVERRIDE;
Standard_EXPORT Standard_Boolean Values(const math_Vector& X,
Standard_Real& F,
math_Vector& G) Standard_OVERRIDE;
private:
Handle(TColgp_HArray1OfXYZ) myPoints;
gp_Dir myDir;
gp_Dir myDir;
};
#endif // _GeomConvert_FuncCylinderLSDist_HeaderFile

View File

@@ -14,38 +14,32 @@
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <GeomConvert_FuncSphereLSDist.hxx>
#include <gp_Pnt.hxx>
#include <gp_Vec.hxx>
#include <math_Vector.hxx>
//=======================================================================
//function : GeomConvert_FuncSphereLSDist
//purpose :
//=======================================================================
GeomConvert_FuncSphereLSDist::GeomConvert_FuncSphereLSDist(const Handle(TColgp_HArray1OfXYZ)& thePoints):
myPoints(thePoints)
//=================================================================================================
GeomConvert_FuncSphereLSDist::GeomConvert_FuncSphereLSDist(
const Handle(TColgp_HArray1OfXYZ)& thePoints)
: myPoints(thePoints)
{
}
//=======================================================================
//function : NbVariables
//purpose :
//=======================================================================
Standard_Integer GeomConvert_FuncSphereLSDist::NbVariables () const
//=================================================================================================
Standard_Integer GeomConvert_FuncSphereLSDist::NbVariables() const
{
return 4;
}
//=======================================================================
//function : Value
//purpose :
//=======================================================================
Standard_Boolean GeomConvert_FuncSphereLSDist::Value(const math_Vector& X,Standard_Real& F)
//=================================================================================================
Standard_Boolean GeomConvert_FuncSphereLSDist::Value(const math_Vector& X, Standard_Real& F)
{
gp_XYZ aLoc(X(1), X(2), X(3));
Standard_Real anR2 = X(4)*X(4);
gp_XYZ aLoc(X(1), X(2), X(3));
Standard_Real anR2 = X(4) * X(4);
F = 0.;
Standard_Integer i;
@@ -58,22 +52,20 @@ Standard_Boolean GeomConvert_FuncSphereLSDist::Value(const math_Vector& X,Standa
return Standard_True;
}
//=======================================================================
//function : Gradient
//purpose :
//=======================================================================
Standard_Boolean GeomConvert_FuncSphereLSDist::Gradient(const math_Vector& X,math_Vector& G)
//=================================================================================================
Standard_Boolean GeomConvert_FuncSphereLSDist::Gradient(const math_Vector& X, math_Vector& G)
{
gp_XYZ aLoc(X(1), X(2), X(3));
gp_XYZ aLoc(X(1), X(2), X(3));
Standard_Real anR = X(4), anR2 = anR * anR;
G.Init(0.);
Standard_Integer i;
for (i = myPoints->Lower(); i <= myPoints->Upper(); ++i)
{
gp_XYZ dLoc = myPoints->Value(i) - aLoc;
Standard_Real d = dLoc.SquareModulus() - anR2;
gp_XYZ dLoc = myPoints->Value(i) - aLoc;
Standard_Real d = dLoc.SquareModulus() - anR2;
G(1) += d * dLoc.X();
G(2) += d * dLoc.Y();
G(3) += d * dLoc.Z();
@@ -85,13 +77,13 @@ Standard_Boolean GeomConvert_FuncSphereLSDist::Gradient(const math_Vector& X,mat
return Standard_True;
}
//=======================================================================
//function : Values
//purpose :
//=======================================================================
Standard_Boolean GeomConvert_FuncSphereLSDist::Values(const math_Vector& X,Standard_Real& F,math_Vector& G)
//=================================================================================================
Standard_Boolean GeomConvert_FuncSphereLSDist::Values(const math_Vector& X,
Standard_Real& F,
math_Vector& G)
{
gp_XYZ aLoc(X(1), X(2), X(3));
gp_XYZ aLoc(X(1), X(2), X(3));
Standard_Real anR = X(4), anR2 = anR * anR;
G.Init(0.);
@@ -99,8 +91,8 @@ Standard_Boolean GeomConvert_FuncSphereLSDist::Values(const math_Vector& X,Stand
Standard_Integer i;
for (i = myPoints->Lower(); i <= myPoints->Upper(); ++i)
{
gp_XYZ dLoc = myPoints->Value(i) - aLoc;
Standard_Real d = dLoc.SquareModulus() - anR2;
gp_XYZ dLoc = myPoints->Value(i) - aLoc;
Standard_Real d = dLoc.SquareModulus() - anR2;
G(1) += d * dLoc.X();
G(2) += d * dLoc.Y();
G(3) += d * dLoc.Z();
@@ -112,4 +104,3 @@ Standard_Boolean GeomConvert_FuncSphereLSDist::Values(const math_Vector& X,Stand
return true;
}

View File

@@ -23,19 +23,19 @@
#include <TColgp_HArray1OfXYZ.hxx>
#include <math_Vector.hxx>
//! Function for search of sphere canonic parameters: coordinates of center and radius from set of moints
//! by least square method.
//! Function for search of sphere canonic parameters: coordinates of center and radius from set of
//! moints by least square method.
//! //!
//! The class inherits math_MultipleVarFunctionWithGradient and thus is intended
//! for use in math_BFGS algorithm.
//!
//! The criteria is:
//! F(x0, y0, z0, R) = Sum[(x(i) - x0)^2 + (y(i) - y0)^2 + (z(i) - z0)^2 - R^2]^2 => min,
//! x(i), y(i), z(i) - coordinates of sample points, x0, y0, z0, R - coordinates of center and radius of sphere,
//! which must be defined
//! x(i), y(i), z(i) - coordinates of sample points, x0, y0, z0, R - coordinates of center and
//! radius of sphere, which must be defined
//!
//! The first derivative are:
//! dF/dx0 : G1(x0, y0, z0, R) = -4*Sum{[...]*(x(i) - x0)}
//! dF/dx0 : G1(x0, y0, z0, R) = -4*Sum{[...]*(x(i) - x0)}
//! dF/dy0 : G2(x0, y0, z0, R) = -4*Sum{[...]*(y(i) - y0)}
//! dF/dz0 : G3(x0, y0, z0, R) = -4*Sum{[...]*(z(i) - z0)}
//! dF/dR : G4(x0, y0, z0, R) = -4*R*Sum[...]
@@ -44,34 +44,30 @@
class GeomConvert_FuncSphereLSDist : public math_MultipleVarFunctionWithGradient
{
public:
DEFINE_STANDARD_ALLOC
//! Constructor.
Standard_EXPORT GeomConvert_FuncSphereLSDist() {};
Standard_EXPORT GeomConvert_FuncSphereLSDist(const Handle(TColgp_HArray1OfXYZ)& thePoints);
void SetPoints(const Handle(TColgp_HArray1OfXYZ)& thePoints)
{
myPoints = thePoints;
}
void SetPoints(const Handle(TColgp_HArray1OfXYZ)& thePoints) { myPoints = thePoints; }
//! Number of variables.
Standard_EXPORT Standard_Integer NbVariables() const Standard_OVERRIDE;
//! Value.
Standard_EXPORT Standard_Boolean Value(const math_Vector& X,Standard_Real& F) Standard_OVERRIDE;
Standard_EXPORT Standard_Boolean Value(const math_Vector& X, Standard_Real& F) Standard_OVERRIDE;
//! Gradient.
Standard_EXPORT Standard_Boolean Gradient(const math_Vector& X,math_Vector& G) Standard_OVERRIDE;
Standard_EXPORT Standard_Boolean Gradient(const math_Vector& X, math_Vector& G) Standard_OVERRIDE;
//! Value and gradient.
Standard_EXPORT Standard_Boolean Values(const math_Vector& X,Standard_Real& F,math_Vector& G) Standard_OVERRIDE;
Standard_EXPORT Standard_Boolean Values(const math_Vector& X,
Standard_Real& F,
math_Vector& G) Standard_OVERRIDE;
private:
Handle(TColgp_HArray1OfXYZ) myPoints;
};
#endif // _GeomConvert_FuncSphereLSDist_HeaderFile

File diff suppressed because it is too large Load Diff

View File

@@ -1,18 +1,18 @@
// Created: 1998-06-03
//
// Copyright (c) 1999-2013 OPEN CASCADE SAS
//
// This file is part of commercial software by OPEN CASCADE SAS,
// furnished in accordance with the terms and conditions of the contract
// and with the inclusion of this copyright notice.
// This file or any part thereof may not be provided or otherwise
// made available to any third party.
//
// No ownership title to the software is transferred hereby.
//
// OPEN CASCADE SAS makes no representation or warranties with respect to the
// performance of this software, and specifically disclaims any responsibility
// for any damages, special or consequential, connected with its use.
// Created: 1998-06-03
//
// Copyright (c) 1999-2013 OPEN CASCADE SAS
//
// This file is part of commercial software by OPEN CASCADE SAS,
// furnished in accordance with the terms and conditions of the contract
// and with the inclusion of this copyright notice.
// This file or any part thereof may not be provided or otherwise
// made available to any third party.
//
// No ownership title to the software is transferred hereby.
//
// OPEN CASCADE SAS makes no representation or warranties with respect to the
// performance of this software, and specifically disclaims any responsibility
// for any damages, special or consequential, connected with its use.
#ifndef _GeomConvert_SurfToAnaSurf_HeaderFile
#define _GeomConvert_SurfToAnaSurf_HeaderFile
@@ -34,102 +34,110 @@ class Geom_Circle;
//! precision. Conversion is done only the surface is bspline
//! of bezier and this can be approximated by some analytical
//! surface with that precision.
class GeomConvert_SurfToAnaSurf
class GeomConvert_SurfToAnaSurf
{
public:
DEFINE_STANDARD_ALLOC
Standard_EXPORT GeomConvert_SurfToAnaSurf();
Standard_EXPORT GeomConvert_SurfToAnaSurf(const Handle(Geom_Surface)& S);
Standard_EXPORT void Init (const Handle(Geom_Surface)& S);
Standard_EXPORT void Init(const Handle(Geom_Surface)& S);
void SetConvType(const GeomConvert_ConvType theConvType = GeomConvert_Simplest)
{
myConvType = theConvType;
}
void SetTarget(const GeomAbs_SurfaceType theSurfType = GeomAbs_Plane)
{
myTarget = theSurfType;
}
void SetTarget(const GeomAbs_SurfaceType theSurfType = GeomAbs_Plane) { myTarget = theSurfType; }
//! Returns maximal deviation of converted surface from the original
//! one computed by last call to ConvertToAnalytical
Standard_Real Gap() const
{
return myGap;
}
Standard_Real Gap() const { return myGap; }
//! Tries to convert the Surface to an Analytic form
//! Returns the result
//! In case of failure, returns a Null Handle
//!
Standard_EXPORT Handle(Geom_Surface) ConvertToAnalytical (const Standard_Real InitialToler);
Standard_EXPORT Handle(Geom_Surface) ConvertToAnalytical (const Standard_Real InitialToler,
const Standard_Real Umin, const Standard_Real Umax,
const Standard_Real Vmin, const Standard_Real Vmax);
Standard_EXPORT Handle(Geom_Surface) ConvertToAnalytical(const Standard_Real InitialToler);
Standard_EXPORT Handle(Geom_Surface) ConvertToAnalytical(const Standard_Real InitialToler,
const Standard_Real Umin,
const Standard_Real Umax,
const Standard_Real Vmin,
const Standard_Real Vmax);
//! Returns true if surfaces is same with the given tolerance
Standard_EXPORT static Standard_Boolean IsSame (const Handle(Geom_Surface)& S1, const Handle(Geom_Surface)& S2, const Standard_Real tol);
Standard_EXPORT static Standard_Boolean IsSame(const Handle(Geom_Surface)& S1,
const Handle(Geom_Surface)& S2,
const Standard_Real tol);
//! Returns true, if surface is canonical
Standard_EXPORT static Standard_Boolean IsCanonical (const Handle(Geom_Surface)& S);
Standard_EXPORT static Standard_Boolean IsCanonical(const Handle(Geom_Surface)& S);
private:
//!static method for checking surface of revolution
//!To avoid two-parts cone-like surface
//! static method for checking surface of revolution
//! To avoid two-parts cone-like surface
static void CheckVTrimForRevSurf(const Handle(Geom_SurfaceOfRevolution)& aRevSurf,
Standard_Real& V1, Standard_Real& V2);
Standard_Real& V1,
Standard_Real& V2);
//!static method to try create cylindrical or conical surface
static Handle(Geom_Surface) TryCylinerCone(const Handle(Geom_Surface)& theSurf, const Standard_Boolean theVCase,
const Handle(Geom_Curve)& theUmidiso, const Handle(Geom_Curve)& theVmidiso,
const Standard_Real theU1, const Standard_Real theU2, const Standard_Real theV1, const Standard_Real theV2,
const Standard_Real theToler);
//! static method to try create cylindrical or conical surface
static Handle(Geom_Surface) TryCylinerCone(const Handle(Geom_Surface)& theSurf,
const Standard_Boolean theVCase,
const Handle(Geom_Curve)& theUmidiso,
const Handle(Geom_Curve)& theVmidiso,
const Standard_Real theU1,
const Standard_Real theU2,
const Standard_Real theV1,
const Standard_Real theV2,
const Standard_Real theToler);
//!static method to try create cylinrical surface using least square method
//! static method to try create cylinrical surface using least square method
static Standard_Boolean GetCylByLS(const Handle(TColgp_HArray1OfXYZ)& thePoints,
const Standard_Real theTol,
gp_Ax3& thePos, Standard_Real& theR,
Standard_Real& theGap);
const Standard_Real theTol,
gp_Ax3& thePos,
Standard_Real& theR,
Standard_Real& theGap);
//!static method to try create cylinrical surface based on its Gauss field
static Handle(Geom_Surface) TryCylinderByGaussField(const Handle(Geom_Surface)& theSurf,
const Standard_Real theU1, const Standard_Real theU2, const Standard_Real theV1, const Standard_Real theV2,
const Standard_Real theToler, const Standard_Integer theNbU = 20, const Standard_Integer theNbV = 20,
const Standard_Boolean theLeastSquare = Standard_False);
//! static method to try create cylinrical surface based on its Gauss field
static Handle(Geom_Surface) TryCylinderByGaussField(
const Handle(Geom_Surface)& theSurf,
const Standard_Real theU1,
const Standard_Real theU2,
const Standard_Real theV1,
const Standard_Real theV2,
const Standard_Real theToler,
const Standard_Integer theNbU = 20,
const Standard_Integer theNbV = 20,
const Standard_Boolean theLeastSquare = Standard_False);
//! static method to try create toroidal surface.
//! In case <isTryUMajor> = Standard_True try to use V isoline radius as minor radaius.
static Handle(Geom_Surface) TryTorusSphere(const Handle(Geom_Surface)& theSurf,
const Handle(Geom_Circle)& circle,
const Handle(Geom_Circle)& otherCircle,
const Standard_Real Param1,
const Standard_Real Param2,
const Standard_Real aParam1ToCrv,
const Standard_Real aParam2ToCrv,
const Standard_Real toler,
const Standard_Boolean isTryUMajor);
const Handle(Geom_Circle)& circle,
const Handle(Geom_Circle)& otherCircle,
const Standard_Real Param1,
const Standard_Real Param2,
const Standard_Real aParam1ToCrv,
const Standard_Real aParam2ToCrv,
const Standard_Real toler,
const Standard_Boolean isTryUMajor);
static Standard_Real ComputeGap(const Handle(Geom_Surface)& theSurf,
const Standard_Real theU1, const Standard_Real theU2, const Standard_Real theV1, const Standard_Real theV2,
const Handle(Geom_Surface)& theNewSurf, const Standard_Real theTol = RealLast());
const Standard_Real theU1,
const Standard_Real theU2,
const Standard_Real theV1,
const Standard_Real theV2,
const Handle(Geom_Surface)& theNewSurf,
const Standard_Real theTol = RealLast());
protected:
private:
Handle(Geom_Surface) mySurf;
Standard_Real myGap;
Standard_Real myGap;
GeomConvert_ConvType myConvType;
GeomAbs_SurfaceType myTarget;
GeomAbs_SurfaceType myTarget;
};
#endif // _GeomConvert_SurfToAnaSurf_HeaderFile

View File

@@ -37,26 +37,26 @@
// Method : RadianToDegree
// Purpose:
// ============================================================================
Handle(Geom2d_Curve) GeomConvert_Units::RadianToDegree(
const Handle(Geom2d_Curve) & theCurve2d,
const Handle(Geom_Surface) & theSurf,
const Standard_Real theLengthFactor,
const Standard_Real theFactorRadianDegree)
Handle(Geom2d_Curve) GeomConvert_Units::RadianToDegree(const Handle(Geom2d_Curve)& theCurve2d,
const Handle(Geom_Surface)& theSurf,
const Standard_Real theLengthFactor,
const Standard_Real theFactorRadianDegree)
{
Handle(Geom2d_Curve) aCurve2d = Handle(Geom2d_Curve)::DownCast(theCurve2d->Copy());
Standard_Real uFact = 1.;
Standard_Real vFact = 1.;
Standard_Real LengthFact = 1. / theLengthFactor;
Standard_Real AngleFact = theFactorRadianDegree; // 180./PI; pilotable
Handle(Geom2d_Curve) aCurve2d = Handle(Geom2d_Curve)::DownCast(theCurve2d->Copy());
Standard_Real uFact = 1.;
Standard_Real vFact = 1.;
Standard_Real LengthFact = 1. / theLengthFactor;
Standard_Real AngleFact = theFactorRadianDegree; // 180./PI; pilotable
gp_Pnt2d Pt1;
gp_XY pXY;
gp_GTrsf2d tMatu, tMatv;
gp_Pnt2d Pt1;
gp_XY pXY;
gp_GTrsf2d tMatu, tMatv;
// theSurf is a CylindricalSurface or a ConicalSurface or
// a ToroidalSurface or a SphericalSurface or
// a SurfaceOfRevolution
if (theSurf->IsKind(STANDARD_TYPE(Geom_SphericalSurface)) || theSurf->IsKind(STANDARD_TYPE(Geom_ToroidalSurface)))
if (theSurf->IsKind(STANDARD_TYPE(Geom_SphericalSurface))
|| theSurf->IsKind(STANDARD_TYPE(Geom_ToroidalSurface)))
{
uFact = vFact = AngleFact;
}
@@ -72,14 +72,15 @@ Handle(Geom2d_Curve) GeomConvert_Units::RadianToDegree(
else if (theSurf->IsKind(STANDARD_TYPE(Geom_ConicalSurface)))
{
Handle(Geom_ConicalSurface) conicS = Handle(Geom_ConicalSurface)::DownCast(theSurf);
Standard_Real semAng = conicS->SemiAngle();
uFact = AngleFact;
vFact = LengthFact * Cos(semAng);
Standard_Real semAng = conicS->SemiAngle();
uFact = AngleFact;
vFact = LengthFact * Cos(semAng);
}
else if (theSurf->IsKind(STANDARD_TYPE(Geom_Plane)))
{
uFact = vFact = LengthFact;
if (aCurve2d->IsKind(STANDARD_TYPE(Geom2d_Circle)) || aCurve2d->IsKind(STANDARD_TYPE(Geom2d_Ellipse)))
if (aCurve2d->IsKind(STANDARD_TYPE(Geom2d_Circle))
|| aCurve2d->IsKind(STANDARD_TYPE(Geom2d_Ellipse)))
{
gp_Trsf2d aT;
aT.SetScale(gp::Origin2d(), LengthFact);
@@ -87,19 +88,20 @@ Handle(Geom2d_Curve) GeomConvert_Units::RadianToDegree(
return aCurve2d;
}
}
else {
else
{
return aCurve2d;
}
if (aCurve2d->IsKind(STANDARD_TYPE(Geom2d_Line)))
{
Handle(Geom2d_Line) aLine2d = Handle(Geom2d_Line)::DownCast(aCurve2d);
gp_Pnt2d myLoc = aLine2d->Location();
gp_Dir2d myDir = aLine2d->Direction();
gp_Pnt2d myNewLoc;
myNewLoc.SetCoord(myLoc.X()*uFact, myLoc.Y()*vFact);
gp_Pnt2d myLoc = aLine2d->Location();
gp_Dir2d myDir = aLine2d->Direction();
gp_Pnt2d myNewLoc;
myNewLoc.SetCoord(myLoc.X() * uFact, myLoc.Y() * vFact);
gp_Dir2d myNewDir;
myNewDir.SetCoord(myDir.X()*uFact, myDir.Y()*vFact);
myNewDir.SetCoord(myDir.X() * uFact, myDir.Y() * vFact);
Handle(Geom2d_Line) myNewLine2d = Handle(Geom2d_Line)::DownCast(aLine2d->Copy());
myNewLine2d->SetLocation(myNewLoc);
myNewLine2d->SetDirection(myNewDir);
@@ -107,10 +109,11 @@ Handle(Geom2d_Curve) GeomConvert_Units::RadianToDegree(
}
else if (aCurve2d->IsKind(STANDARD_TYPE(Geom2d_Conic)))
{
if (aCurve2d->IsKind(STANDARD_TYPE(Geom2d_Circle)) || aCurve2d->IsKind(STANDARD_TYPE(Geom2d_Ellipse)))
if (aCurve2d->IsKind(STANDARD_TYPE(Geom2d_Circle))
|| aCurve2d->IsKind(STANDARD_TYPE(Geom2d_Ellipse)))
{
Handle(Geom2d_BSplineCurve) aBSpline2d = Geom2dConvert::CurveToBSplineCurve(aCurve2d);
aCurve2d = aBSpline2d;
aCurve2d = aBSpline2d;
}
else if (aCurve2d->IsKind(STANDARD_TYPE(Geom2d_Parabola)))
{
@@ -135,8 +138,7 @@ Handle(Geom2d_Curve) GeomConvert_Units::RadianToDegree(
{
if (aCurve2d->IsKind(STANDARD_TYPE(Geom2d_BSplineCurve)))
{
Handle(Geom2d_BSplineCurve) aBSpline2d =
Handle(Geom2d_BSplineCurve)::DownCast(aCurve2d);
Handle(Geom2d_BSplineCurve) aBSpline2d = Handle(Geom2d_BSplineCurve)::DownCast(aCurve2d);
Handle(Geom2d_BSplineCurve) myNewBSpline2d =
Handle(Geom2d_BSplineCurve)::DownCast(aBSpline2d->Copy());
Standard_Integer nbPol = aBSpline2d->NbPoles();
@@ -150,7 +152,8 @@ Handle(Geom2d_Curve) GeomConvert_Units::RadianToDegree(
}
return myNewBSpline2d;
}
else {
else
{
#ifdef OCCT_DEBUG
std::cout << "PCURVE of Other Types of Bounded Curve in U or V Periodic Surface" << std::endl;
std::cout << "Parameters Not transformed to Degree" << std::endl;
@@ -162,32 +165,31 @@ Handle(Geom2d_Curve) GeomConvert_Units::RadianToDegree(
// ============================================================================
// Method : DegreeToRadian
// Purpose: 1. Change definition of the pcurves according to LengthFactor
// Purpose: 1. Change definition of the pcurves according to LengthFactor
// 2. STEP cylinder, torus, cone and sphere are parametrized
// from 0 to 360 degree
// Then pcurves parameter have to be transformed
// Then pcurves parameter have to be transformed
// from DEGREE to RADIAN
// ============================================================================
Handle(Geom2d_Curve) GeomConvert_Units::DegreeToRadian(
const Handle(Geom2d_Curve) & thePcurve,
const Handle(Geom_Surface) & theSurface,
const Standard_Real theLengthFactor,
const Standard_Real theFactorRadianDegree)
Handle(Geom2d_Curve) GeomConvert_Units::DegreeToRadian(const Handle(Geom2d_Curve)& thePcurve,
const Handle(Geom_Surface)& theSurface,
const Standard_Real theLengthFactor,
const Standard_Real theFactorRadianDegree)
{
Handle(Geom2d_Curve) aPcurve = Handle(Geom2d_Curve)::DownCast(thePcurve->Copy());
Standard_Real uFact = 1.;
Standard_Real vFact = 1.;
Standard_Real LengthFact = theLengthFactor;
Standard_Real AngleFact = theFactorRadianDegree; // PI/180.; pilotable
Handle(Geom2d_Curve) aPcurve = Handle(Geom2d_Curve)::DownCast(thePcurve->Copy());
Standard_Real uFact = 1.;
Standard_Real vFact = 1.;
Standard_Real LengthFact = theLengthFactor;
Standard_Real AngleFact = theFactorRadianDegree; // PI/180.; pilotable
gp_Pnt2d Pt1;
gp_XY pXY;
gp_GTrsf2d tMatu, tMatv;
gp_Pnt2d Pt1;
gp_XY pXY;
gp_GTrsf2d tMatu, tMatv;
// What to change ??
if (theSurface->IsKind(STANDARD_TYPE(Geom_SphericalSurface)) ||
theSurface->IsKind(STANDARD_TYPE(Geom_ToroidalSurface)))
if (theSurface->IsKind(STANDARD_TYPE(Geom_SphericalSurface))
|| theSurface->IsKind(STANDARD_TYPE(Geom_ToroidalSurface)))
{
uFact = vFact = AngleFact;
}
@@ -203,14 +205,15 @@ Handle(Geom2d_Curve) GeomConvert_Units::DegreeToRadian(
else if (theSurface->IsKind(STANDARD_TYPE(Geom_ConicalSurface)))
{
Handle(Geom_ConicalSurface) conicS = Handle(Geom_ConicalSurface)::DownCast(theSurface);
Standard_Real semAng = conicS->SemiAngle();
uFact = AngleFact;
vFact = LengthFact / Cos(semAng);
Standard_Real semAng = conicS->SemiAngle();
uFact = AngleFact;
vFact = LengthFact / Cos(semAng);
}
else if (theSurface->IsKind(STANDARD_TYPE(Geom_Plane)))
{
uFact = vFact = LengthFact;
if (aPcurve->IsKind(STANDARD_TYPE(Geom2d_Circle)) || aPcurve->IsKind(STANDARD_TYPE(Geom2d_Ellipse)))
if (aPcurve->IsKind(STANDARD_TYPE(Geom2d_Circle))
|| aPcurve->IsKind(STANDARD_TYPE(Geom2d_Ellipse)))
{
gp_Trsf2d aT;
aT.SetScale(gp::Origin2d(), LengthFact);
@@ -225,10 +228,11 @@ Handle(Geom2d_Curve) GeomConvert_Units::DegreeToRadian(
if (aPcurve->IsKind(STANDARD_TYPE(Geom2d_Conic)))
{
if (aPcurve->IsKind(STANDARD_TYPE(Geom2d_Circle)) || aPcurve->IsKind(STANDARD_TYPE(Geom2d_Ellipse)))
if (aPcurve->IsKind(STANDARD_TYPE(Geom2d_Circle))
|| aPcurve->IsKind(STANDARD_TYPE(Geom2d_Ellipse)))
{
Handle(Geom2d_BSplineCurve) aBSpline2d = Geom2dConvert::CurveToBSplineCurve(aPcurve);
aPcurve = aBSpline2d;
aPcurve = aBSpline2d;
}
else if (aPcurve->IsKind(STANDARD_TYPE(Geom2d_Parabola)))
{
@@ -261,10 +265,10 @@ Handle(Geom2d_Curve) GeomConvert_Units::DegreeToRadian(
gp_Dir2d myDir = aLine2d->Direction();
gp_Pnt2d myNewLoc;
myNewLoc.SetCoord(myLoc.X()*uFact, myLoc.Y()*vFact);
myNewLoc.SetCoord(myLoc.X() * uFact, myLoc.Y() * vFact);
gp_Dir2d myNewDir;
myNewDir.SetCoord(myDir.X()*uFact, myDir.Y()*vFact);
myNewDir.SetCoord(myDir.X() * uFact, myDir.Y() * vFact);
aLine2d->SetLocation(myNewLoc);
aLine2d->SetDirection(myNewDir);
@@ -302,13 +306,13 @@ Handle(Geom2d_Curve) GeomConvert_Units::DegreeToRadian(
// Method : MirrorPCurve
// Purpose:
// ============================================================================
Handle(Geom2d_Curve) GeomConvert_Units::MirrorPCurve(const Handle(Geom2d_Curve) & theCurve)
Handle(Geom2d_Curve) GeomConvert_Units::MirrorPCurve(const Handle(Geom2d_Curve)& theCurve)
{
Handle(Geom2d_Curve) theMirrored = Handle(Geom2d_Curve)::DownCast(theCurve->Copy());
gp_Trsf2d T;
gp_Pnt2d Loc(0., 0.);
gp_Dir2d Dir(1., 0.);
gp_Ax2d ax2(Loc, Dir);
gp_Trsf2d T;
gp_Pnt2d Loc(0., 0.);
gp_Dir2d Dir(1., 0.);
gp_Ax2d ax2(Loc, Dir);
T.SetMirror(ax2);
theMirrored->Transform(T);
return theMirrored;

View File

@@ -22,26 +22,24 @@ class Geom_Surface;
class GeomConvert_Units
{
public:
DEFINE_STANDARD_ALLOC
//! Convert 2d curve for change angle unit from radian to degree
//! Convert 2d curve for change angle unit from radian to degree
Standard_EXPORT static Handle(Geom2d_Curve) RadianToDegree(
const Handle(Geom2d_Curve)& theCurve,
const Handle(Geom_Surface)& theSurface,
const Standard_Real theLengthFactor,
const Standard_Real theFactorRadianDegree);
const Standard_Real theLengthFactor,
const Standard_Real theFactorRadianDegree);
//! Convert 2d curve for change angle unit from degree to radian
Standard_EXPORT static Handle(Geom2d_Curve) DegreeToRadian(
const Handle(Geom2d_Curve)& theCurve,
const Handle(Geom_Surface)& theSurface,
const Standard_Real theLengthFactor,
const Standard_Real theFactorRadianDegree);
const Standard_Real theLengthFactor,
const Standard_Real theFactorRadianDegree);
//! return 2d curve as 'mirror' for given
Standard_EXPORT static Handle(Geom2d_Curve) MirrorPCurve(const Handle(Geom2d_Curve)& theCurve);
};
#endif // _GeomConvert_Units_HeaderFile