OpenCascade.js
API ReferenceModelingDataTKGeomBase

Approx

OCCT package Approx: Approx_BSplineApproxInterp, Approx_Curve2d, Approx_Curve3d, Approx_CurveOnSurface, and 10 more bound classes.

Approx_BSplineApproxInterp

Constrained least-squares B-spline curve approximation with exact interpolation constraints.
This class fits a B-spline curve through a set of 3D points, where each point can be either approximated (in the least-squares sense) or exactly interpolated. Selected interpolation points can additionally be marked as "kinks" - the solver then inserts high-multiplicity knots at the corresponding parameters to preserve C0 discontinuities.
The algorithm solves a KKT (Karush-Kuhn-Tucker) saddle-point system:

|A^T*AC^TL^T||x||A^T*b| |C00|*|l|=|d| |L00||m||0|

where:

  • A is the basis matrix for approximated points
  • C is the basis matrix for interpolated points
  • L encodes continuity constraints (C1/C2 for closed curves)
  • x are the control point coordinates
  • l, m are Lagrange multipliers
    Usage:
NCollection_Array1<gp_Pnt>aPts(1,100); //...fillpoints... Approx_BSplineApproxInterpanApprox(aPts,20); anApprox.InterpolatePoint(0);//firstpointexact anApprox.InterpolatePoint(99);//lastpointexact anApprox.InterpolatePoint(50,true);//kinkatmidpoint anApprox.Perform(aParams); if(anApprox.IsDone()) { constocc::handle<Geom_BSplineCurve>&aCurve=anApprox.Curve(); doubleaMaxErr=anApprox.MaxError(); }

Constructors(1)

  • constructor(thePoints: NCollection_Array1_gp_Pnt, theNbControlPts: number, theDegree?: number, theContinuousIfClosed?: boolean): Approx_BSplineApproxInterp

    Creates a constrained approximation solver.

    Parameters (4)
    • thePoints
      array of 3D points to fit (1-based indexing)
    • theNbControlPts
      desired number of control points for the B-spline
    • theDegree
      degree of the B-spline (default 3)
    • theContinuousIfClosed
      if true, enforces C2 continuity for closed curves

Instance methods(14)

  • InterpolatePoint(thePointIndex: number, theWithKink?: boolean): void

    Marks a point to be exactly interpolated rather than approximated.

    Parameters (2)
    • thePointIndex
      0-based index of the point
    • theWithKink
      if true, a kink (C0 break) is inserted at this parameter
  • Perform(): void

    Performs the fit using automatically computed parameters. Parameters are computed from input points using current parametrization alpha.

  • Performs the fit with given parameters.

    Parameters (1)
    • theParams
      parameter values for each point (size must match point count)
  • PerformOptimal(theMaxIter: number): void

    Performs the fit with iterative parameter optimization using automatically computed initial parameters.

    Parameters (1)
    • theMaxIter
      maximum number of optimization iterations
  • PerformOptimal(theParams: NCollection_Array1_double, theMaxIter: number): void

    Performs the fit with iterative parameter optimization. Parameters of approximated points are re-projected onto the curve after each iteration to improve the fit.

    Parameters (2)
    • theParams
      initial parameter values
    • theMaxIter
      maximum number of optimization iterations
  • IsDone(): boolean

    Returns true if the fit was successfully computed.

  • Returns the resulting B-spline curve.

  • MaxError(): number

    Returns the maximum approximation error (distance at approximated points).

  • SetParametrizationAlpha(theAlpha: number): void

    Sets the parametrization power for automatic parameter computation. 0.0 = uniform, 0.5 = centripetal (default), 1.0 = chord-length.

    Parameters (1)
    • theAlpha
      parametrization exponent in [0, 1]
  • SetMinPivot(theMinPivot: number): void

    Sets the minimum pivot value for the Gauss solver. Matrices with pivots below this threshold are treated as singular.

    Parameters (1)
    • theMinPivot
      minimum pivot threshold (default 1e-20)
  • SetClosedTolerance(theRelTol: number): void

    Sets the relative tolerance for detecting closed curves. Closedness is detected when first/last points are within theRelTol * (bounding box diagonal).

    Parameters (1)
    • theRelTol
      relative tolerance (default 1e-12)
  • SetKnotInsertionTolerance(theTol: number): void

    Sets the tolerance for detecting duplicate knot positions during insertion.

    Parameters (1)
    • theTol
      knot matching tolerance (default 1e-4)
  • SetConvergenceTolerance(theTol: number): void

    Sets the convergence tolerance for parameter optimization. Optimization stops when relative error reduction falls below this value.

    Parameters (1)
    • theTol
      convergence tolerance (default 1e-3)
  • SetProjectionTolerance(theTol: number): void

    Sets the tolerance for point projection onto curve during optimization.

    Parameters (1)
    • theTol
      projection accuracy (default 1e-6)

Approx_Curve3d

Constructors(1)

Instance methods(4)

  • IsDone(): boolean

    returns true if the approximation has been done within required tolerance

  • HasResult(): boolean

    returns true if the approximation did come out with a result that is not NECESSARILY within the required tolerance

  • MaxError(): number

    returns the Maximum Error (>0 when an approximation has been done, 0 if no approximation)

Approx_CurveOnSurface

Approximation of curve on surface.

Constructors(2)

  • constructor(theC2D: Adaptor2d_Curve2d, theSurf: Adaptor3d_Surface, theFirst: number, theLast: number, theTol: number): Approx_CurveOnSurface

    This constructor does not call perform method.

    Parameters (5)
    • theC2D
      2D Curve to be approximated in 3D.
    • theSurf
      Surface where 2D curve is located.
    • theFirst
      Last parameter of resulting curve.
    • theLast
    • theTol
      Computation tolerance.
  • constructor(C2D: Adaptor2d_Curve2d, Surf: Adaptor3d_Surface, First: number, Last: number, Tol: number, Continuity: GeomAbs_Shape, MaxDegree: number, MaxSegments: number, Only3d?: boolean, Only2d?: boolean): Approx_CurveOnSurface

    This constructor calls perform method. This constructor is deprecated.

    Deprecated
    Parameters (10)
    • C2D
    • Surf
    • First
    • Last
    • Tol
    • Continuity
    • MaxDegree
    • MaxSegments
    • Only3d
    • Only2d

Instance methods(8)

  • IsDone(): boolean
  • HasResult(): boolean
  • MaxError3d(): number
  • MaxError2dU(): number
  • MaxError2dV(): number

    returns the maximum errors relatively to the U component or the V component of the 2d Curve

  • Perform(theMaxSegments: number, theMaxDegree: number, theContinuity: GeomAbs_Shape, theOnly3d?: boolean, theOnly2d?: boolean): void

    Constructs the 3d curve. Input parameters are ignored when the input curve is U-isoline or V-isoline.

    Parameters (5)
    • theMaxSegments
      Maximal number of segments in the resulting spline.
    • theMaxDegree
      Maximal degree of the result.
    • theContinuity
      Resulting continuity.
    • theOnly3d
      Determines building only 3D curve.
    • theOnly2d
      Determines building only 2D curve.

Approx_CurvilinearParameter

Approximation of a Curve to make its parameter be its curvilinear abscissa. If the curve is a curve on a surface S, C2D is the corresponding Pcurve, we consider the curve is given by its representation.

S(C2D(u))

If the curve is a curve on 2 surfaces S1 and S2 and C2D1 C2D2 are the two corresponding Pcurve, we consider the curve is given by its representation

1/2(S1(C2D1(u)+S2(C2D2(u)))

Constructors(3)

Instance methods(8)

  • IsDone(): boolean
  • HasResult(): boolean
  • returns the Bspline curve corresponding to the reparametrized 3D curve

  • MaxError3d(): number

    returns the maximum error on the reparametrized 3D curve

  • returns the BsplineCurve representing the reparametrized 2D curve on the first surface (case of a curve on one or two surfaces)

  • MaxError2d1(): number

    returns the maximum error on the first reparametrized 2D curve

  • returns the BsplineCurve representing the reparametrized 2D curve on the second surface (case of a curve on two surfaces)

  • MaxError2d2(): number

    returns the maximum error on the second reparametrized 2D curve

Approx_CurvlinFunc

defines an abstract curve with curvilinear parametrization

Constructors(3)

Static methods(2)

Instance methods(15)

  • SetTol(Tol: number): void

    --Purpose Update the tolerance to used

    Parameters (1)
    • Tol
  • FirstParameter(): number
  • LastParameter(): number
  • Returns the number of intervals for continuity . May be one if Continuity(me) >= .

    Parameters (1)
    • S
  • Stores in <T> the parameters bounding the intervals of continuity .
    The array must provide enough room to accommodate for the parameters. i.e. T.Length() > NbIntervals()

    Parameters (2)
    • T
      Mutated in place; read the updated value from this argument after the call.
    • S
  • Trim(First: number, Last: number, Tol: number): void

    if First < 0 or Last > 1

    Parameters (3)
    • First
    • Last
    • Tol
  • Length(): void

    Computes length of the curve.

  • Length(C: Adaptor3d_Curve, FirstU: number, LasrU: number): number

    Computes length of the curve segment.

    Parameters (3)
    • C
      Mutated in place; read the updated value from this argument after the call.
    • FirstU
    • LasrU
  • GetLength(): number
  • GetUParameter(C: Adaptor3d_Curve, S: number, NumberOfCurve: number): number

    returns original parameter corresponding S. if Case == 1 computation is performed on myC2D1 and mySurf1, otherwise it is done on myC2D2 and mySurf2.

    Parameters (3)
    • C
      Mutated in place; read the updated value from this argument after the call.
    • S
    • NumberOfCurve
  • GetSParameter(U: number): number

    returns original parameter corresponding S.

    Parameters (1)
    • U
  • EvalCase1(S: number, Order: number, Result: NCollection_Array1_double): boolean

    if myCase != 1

    Parameters (3)
    • S
    • Order
    • Result
      Mutated in place; read the updated value from this argument after the call.
  • EvalCase2(S: number, Order: number, Result: NCollection_Array1_double): boolean

    if myCase != 2

    Parameters (3)
    • S
    • Order
    • Result
      Mutated in place; read the updated value from this argument after the call.
  • EvalCase3(S: number, Order: number, Result: NCollection_Array1_double): boolean

    if myCase != 3

    Parameters (3)
    • S
    • Order
    • Result
      Mutated in place; read the updated value from this argument after the call.

Approx_FitAndDivide

Constructors(2)

Instance methods(13)

  • runs the algorithm after having initialized the fields.

    Parameters (1)
    • Line
  • SetDegrees(degreemin: number, degreemax: number): void

    changes the degrees of the approximation.

    Parameters (2)
    • degreemin
    • degreemax
  • SetTolerances(Tolerance3d: number, Tolerance2d: number): void

    Changes the tolerances of the approximation.

    Parameters (2)
    • Tolerance3d
    • Tolerance2d
  • Changes the constraints of the approximation.

    Parameters (2)
    • FirstC
    • LastC
  • SetMaxSegments(theMaxSegments: number): void

    Changes the max number of segments, which is allowed for cutting.

    Parameters (1)
    • theMaxSegments
  • SetInvOrder(theInvOrder: boolean): void

    Set inverse order of degree selection: if theInvOrdr = true, current degree is chosen by inverse order - from maxdegree to mindegree. By default inverse order is used.

    Parameters (1)
    • theInvOrder
  • SetHangChecking(theHangChecking: boolean): void

    Set value of hang checking flag if this flag = true, possible hang of algorithm is checked and algorithm is forced to stop. By default hang checking is used.

    Parameters (1)
    • theHangChecking
  • returns False if at a moment of the approximation, the status NoApproximation has been sent by the user when more points were needed.

  • returns False if the status NoPointsAdded has been sent.

  • Error(Index: number, tol3d: number, tol2d: number): { tol3d: number; tol2d: number }

    returns the tolerances 2d and 3d of the <Index> MultiCurve.

    Parameters (3)
    • Index
    • tol3d
    • tol2d
    Returns

    A result object with fields:

    • tol3d: updated value from the call.
    • tol2d: updated value from the call.
  • NbMultiCurves(): number

    Returns the number of MultiCurve doing the approximation of the MultiLine.

  • returns the approximation MultiCurve of range <Index>.

    Parameters (1)
    • Index
  • Parameters(Index: number, firstp: number, lastp: number): { firstp: number; lastp: number }
    Parameters (3)
    • Index
    • firstp
    • lastp

Approx_FitAndDivide2d

Constructors(2)

Instance methods(13)

  • runs the algorithm after having initialized the fields.

    Parameters (1)
    • Line
  • SetDegrees(degreemin: number, degreemax: number): void

    changes the degrees of the approximation.

    Parameters (2)
    • degreemin
    • degreemax
  • SetTolerances(Tolerance3d: number, Tolerance2d: number): void

    Changes the tolerances of the approximation.

    Parameters (2)
    • Tolerance3d
    • Tolerance2d
  • Changes the constraints of the approximation.

    Parameters (2)
    • FirstC
    • LastC
  • SetMaxSegments(theMaxSegments: number): void

    Changes the max number of segments, which is allowed for cutting.

    Parameters (1)
    • theMaxSegments
  • SetInvOrder(theInvOrder: boolean): void

    Set inverse order of degree selection: if theInvOrdr = true, current degree is chosen by inverse order - from maxdegree to mindegree. By default inverse order is used.

    Parameters (1)
    • theInvOrder
  • SetHangChecking(theHangChecking: boolean): void

    Set value of hang checking flag if this flag = true, possible hang of algorithm is checked and algorithm is forced to stop. By default hang checking is used.

    Parameters (1)
    • theHangChecking
  • returns False if at a moment of the approximation, the status NoApproximation has been sent by the user when more points were needed.

  • returns False if the status NoPointsAdded has been sent.

  • Error(Index: number, tol3d: number, tol2d: number): { tol3d: number; tol2d: number }

    returns the tolerances 2d and 3d of the <Index> MultiCurve.

    Parameters (3)
    • Index
    • tol3d
    • tol2d
    Returns

    A result object with fields:

    • tol3d: updated value from the call.
    • tol2d: updated value from the call.
  • NbMultiCurves(): number

    Returns the number of MultiCurve doing the approximation of the MultiLine.

  • returns the approximation MultiCurve of range <Index>.

    Parameters (1)
    • Index
  • Parameters(Index: number, firstp: number, lastp: number): { firstp: number; lastp: number }
    Parameters (3)
    • Index
    • firstp
    • lastp

Approx_SameParameter

Approximation of a PCurve on a surface to make its parameter be the same that the parameter of a given 3d reference curve.

Constructors(3)

Instance methods(6)

  • IsDone(): boolean
    Returns

    .false. if calculations failed, .true. if calculations succeed

  • TolReached(): number
    Returns

    tolerance (maximal distance) between 3d curve and curve on surface, generated by 2d curve and surface.

  • IsSameParameter(): boolean

    Tells whether the original data had already the same parameter up to the tolerance : in that case nothing is done.

  • Returns the 2D curve that has the same parameter as the 3D curve once evaluated on the surface up to the specified tolerance.

  • Returns the 3D curve that has the same parameter as the 3D curve once evaluated on the surface up to the specified tolerance.

  • Returns the 3D curve on surface that has the same parameter as the 3D curve up to the specified tolerance.

Approx_SweepApproximation

Approximation of an Surface S(u,v) (and eventually associate 2d Curves) defined by section's law.
This surface is defined by a function F(u, v) where Ft(u) = F(u, t) is a bspline curve. To use this algorithm, you have to implement Ft(u) as a derivative class of Approx_SweepFunction. This algorithm can be used by blending, sweeping...

Constructors(1)

Instance methods(25)

Approx_SweepFunction

defined the function used by SweepApproximation to perform sweeping application.

Static methods(2)

Instance methods(18)

  • D0(Param: number, First: number, Last: number, Poles: NCollection_Array1_gp_Pnt, Poles2d: NCollection_Array1_gp_Pnt2d, Weigths: NCollection_Array1_double): boolean

    compute the section for v = param

    Parameters (6)
    • Param
    • First
    • Last
    • Poles
      Mutated in place; read the updated value from this argument after the call.
    • Poles2d
      Mutated in place; read the updated value from this argument after the call.
    • Weigths
      Mutated in place; read the updated value from this argument after the call.
  • D1(Param: number, First: number, Last: number, Poles: NCollection_Array1_gp_Pnt, DPoles: NCollection_Array1_gp_Vec, Poles2d: NCollection_Array1_gp_Pnt2d, DPoles2d: NCollection_Array1_gp_Vec2d, Weigths: NCollection_Array1_double, DWeigths: NCollection_Array1_double): boolean

    compute the first derivative in v direction of the section for v = param Warning : It used only for C1 or C2 approximation

    Parameters (9)
    • Param
    • First
    • Last
    • Poles
      Mutated in place; read the updated value from this argument after the call.
    • DPoles
      Mutated in place; read the updated value from this argument after the call.
    • Poles2d
      Mutated in place; read the updated value from this argument after the call.
    • DPoles2d
      Mutated in place; read the updated value from this argument after the call.
    • Weigths
      Mutated in place; read the updated value from this argument after the call.
    • DWeigths
      Mutated in place; read the updated value from this argument after the call.
  • compute the second derivative in v direction of the section for v = param Warning : It used only for C2 approximation

    Parameters (12)
    • Param
    • First
    • Last
    • Poles
      Mutated in place; read the updated value from this argument after the call.
    • DPoles
      Mutated in place; read the updated value from this argument after the call.
    • D2Poles
      Mutated in place; read the updated value from this argument after the call.
    • Poles2d
      Mutated in place; read the updated value from this argument after the call.
    • DPoles2d
      Mutated in place; read the updated value from this argument after the call.
    • D2Poles2d
      Mutated in place; read the updated value from this argument after the call.
    • Weigths
      Mutated in place; read the updated value from this argument after the call.
    • DWeigths
      Mutated in place; read the updated value from this argument after the call.
    • D2Weigths
      Mutated in place; read the updated value from this argument after the call.
  • Nb2dCurves(): number

    get the number of 2d curves to approximate.

  • SectionShape(NbPoles: number, NbKnots: number, Degree: number): { NbPoles: number; NbKnots: number; Degree: number }

    get the format of an section

    Parameters (3)
    • NbPoles
    • NbKnots
    • Degree
    Returns

    A result object with fields:

    • NbPoles: updated value from the call.
    • NbKnots: updated value from the call.
    • Degree: updated value from the call.
  • get the Knots of the section

    Parameters (1)
    • TKnots
      Mutated in place; read the updated value from this argument after the call.
  • get the Multplicities of the section

    Parameters (1)
    • TMults
      Mutated in place; read the updated value from this argument after the call.
  • IsRational(): boolean

    Returns if the sections are rational or not.

  • Returns the number of intervals for continuity . May be one if Continuity(me) >= .

    Parameters (1)
    • S
  • Stores in <T> the parameters bounding the intervals of continuity .
    The array must provide enough room to accommodate for the parameters. i.e. T.Length() > NbIntervals()

    Parameters (2)
    • T
      Mutated in place; read the updated value from this argument after the call.
    • S
  • SetInterval(First: number, Last: number): void

    Sets the bounds of the parametric interval on the function This determines the derivatives in these values if the function is not Cn.

    Parameters (2)
    • First
    • Last
  • Resolution(Index: number, Tol: number, TolU: number, TolV: number): { TolU: number; TolV: number }

    Returns the resolutions in the sub-space 2d <Index> This information is useful to find a good tolerance in 2d approximation.

    Parameters (4)
    • Index
    • Tol
    • TolU
    • TolV
    Returns

    A result object with fields:

    • TolU: updated value from the call.
    • TolV: updated value from the call.
  • GetTolerance(BoundTol: number, SurfTol: number, AngleTol: number, Tol3d: NCollection_Array1_double): void

    Returns the tolerance to reach in approximation to satisfy. BoundTol error at the Boundary AngleTol tangent error at the Boundary (in radian) SurfTol error inside the surface.

    Parameters (4)
    • BoundTol
    • SurfTol
    • AngleTol
    • Tol3d
      Mutated in place; read the updated value from this argument after the call.
  • SetTolerance(Tol3d: number, Tol2d: number): void

    Is useful, if (me) have to run numerical algorithm to perform D0, D1 or D2.

    Parameters (2)
    • Tol3d
    • Tol2d
  • Get the barycentre of Surface. An very poor estimation is sufficient. This information is useful to perform well conditioned rational approximation. Warning: Used only if <me> IsRational.

  • MaximalSection(): number

    Returns the length of the greater section. This information is useful to G1's control. Warning: With an little value, approximation can be slower.

  • Compute the minimal value of weight for each poles in all sections. This information is useful to control error in rational approximation. Warning: Used only if <me> IsRational.

    Parameters (1)
    • Weigths
      Mutated in place; read the updated value from this argument after the call.