1 -- Created on: 1995-10-20
2 -- Created by: Laurent BOURESCHE
3 -- Copyright (c) 1995-1999 Matra Datavision
4 -- Copyright (c) 1999-2012 OPEN CASCADE SAS
6 -- The content of this file is subject to the Open CASCADE Technology Public
7 -- License Version 6.5 (the "License"). You may not use the content of this file
8 -- except in compliance with the License. Please obtain a copy of the License
9 -- at http://www.opencascade.org and read it completely before using this file.
11 -- The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 -- main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 -- The Original Code and all software distributed under the License is
15 -- distributed on an "AS IS" basis, without warranty of any kind, and the
16 -- Initial Developer hereby disclaims all such warranties, including without
17 -- limitation, any warranties of merchantability, fitness for a particular
18 -- purpose or non-infringement. Please see the License for the specific terms
19 -- and conditions governing the rights and limitations under the License.
22 class BSpline from Law inherits TShared from MMgt
24 ---Purpose : Definition of the 1D B_spline curve.
26 -- Uniform or non-uniform
27 -- Rational or non-rational
28 -- Periodic or non-periodic
30 -- a b-spline curve is defined by :
32 -- The Degree (up to 25)
34 -- The Poles (and the weights if it is rational)
36 -- The Knots and Multiplicities
38 -- The knot vector is an increasing sequence of
39 -- reals without repetition. The multiplicities are
40 -- the repetition of the knots.
42 -- If the knots are regularly spaced (the difference
43 -- of two consecutive knots is a constant), the
44 -- knots repartition is :
46 -- - Uniform if all multiplicities are 1.
48 -- - Quasi-uniform if all multiplicities are 1
49 -- but the first and the last which are Degree+1.
51 -- - PiecewiseBezier if all multiplicites are
52 -- Degree but the first and the last which are
55 -- The curve may be periodic.
57 -- On a periodic curve if there are k knots and p
58 -- poles. the period is knot(k) - knot(1)
60 -- the poles and knots are infinite vectors with :
62 -- knot(i+k) = knot(i) + period
64 -- pole(i+p) = pole(i)
68 -- . A survey of curve and surface methods in CADG Wolfgang BOHM
70 -- . On de Boor-like algorithms and blossoming Wolfgang BOEHM
72 -- . Blossoming and knot insertion algorithms for B-spline curves
74 -- . Modelisation des surfaces en CAO, Henri GIAUME Peugeot SA
75 -- . Curves and Surfaces for Computer Aided Geometric Design,
76 -- a practical guide Gerald Farin
79 Array1OfInteger from TColStd,
80 Array1OfReal from TColStd,
81 HArray1OfInteger from TColStd,
82 HArray1OfReal from TColStd,
83 BSplKnotDistribution from GeomAbs,
87 ConstructionError from Standard,
88 DimensionError from Standard,
89 DomainError from Standard,
90 OutOfRange from Standard,
91 RangeError from Standard,
92 NoSuchObject from Standard
97 Create (Poles : Array1OfReal from TColStd;
98 Knots : Array1OfReal from TColStd;
99 Multiplicities : Array1OfInteger from TColStd;
101 Periodic : Boolean = Standard_False)
103 returns mutable BSpline from Law
105 ---Purpose : Creates a non-rational B_spline curve on the
106 -- basis <Knots, Multiplicities> of degree <Degree>.
108 raises ConstructionError;
110 -- The following conditions must be verified.
112 -- 0 < Degree <= MaxDegree.
114 -- Knots.Length() == Mults.Length() >= 2
116 -- Knots(i) < Knots(i+1) (Knots are increasing)
118 -- 1 <= Mults(i) <= Degree
120 -- On a non periodic curve the first and last multiplicities
121 -- may be Degree+1 (this is even recommanded if you want the
122 -- curve to start and finish on the first and last pole).
124 -- On a periodic curve the first and the last multicities
127 -- on non-periodic curves
129 -- Poles.Length() == Sum(Mults(i)) - Degree - 1 >= 2
131 -- on periodic curves
133 -- Poles.Length() == Sum(Mults(i)) except the first or last
136 Create (Poles : Array1OfReal from TColStd;
137 Weights : Array1OfReal from TColStd;
138 Knots : Array1OfReal from TColStd;
139 Multiplicities : Array1OfInteger from TColStd;
141 Periodic : Boolean = Standard_False)
143 returns mutable BSpline from Law
145 ---Purpose : Creates a rational B_spline curve on the basis
146 -- <Knots, Multiplicities> of degree <Degree>.
148 raises ConstructionError;
150 -- The following conditions must be verified.
152 -- 0 < Degree <= MaxDegree.
154 -- Weights.Length() == Poles.Length()
156 -- Knots.Length() == Mults.Length() >= 2
158 -- Knots(i) < Knots(i+1) (Knots are increasing)
160 -- 1 <= Mults(i) <= Degree
162 -- On a non periodic curve the first and last multiplicities
163 -- may be Degree+1 (this is even recommanded if you want the
164 -- curve to start and finish on the first and last pole).
166 -- On a periodic curve the first and the last multicities
169 -- on non-periodic curves
171 -- Poles.Length() == Sum(Mults(i)) - Degree - 1 >= 2
173 -- on periodic curves
175 -- Poles.Length() == Sum(Mults(i)) except the first or last
178 IncreaseDegree (me : mutable; Degree : Integer)
180 ---Purpose: Increase the degree to <Degree>. Nothing is done
181 -- if <Degree> is lower or equal to the current
184 raises ConstructionError;
186 -- Raised if Degree is greater than MaxDegree.
189 IncreaseMultiplicity (me : mutable; Index : Integer; M : Integer)
191 ---Purpose :Increases the multiplicity of the knot <Index> to
194 -- If <M> is lower or equal to the current
195 -- multiplicity nothing is done. If <M> is higher than
196 -- the degree the degree is used.
200 ---Purpose: If <Index> is not in [FirstUKnotIndex, LastUKnotIndex]
203 IncreaseMultiplicity (me : mutable; I1, I2 : Integer; M : Integer)
205 ---Purpose :Increases the multiplicities of the knots in
208 -- For each knot if <M> is lower or equal to the
209 -- current multiplicity nothing is done. If <M> is
210 -- higher than the degree the degree is used.
214 ---Purpose: If <I1,I2> are not in [FirstUKnotIndex, LastUKnotIndex]
217 IncrementMultiplicity (me : mutable; I1, I2 : Integer; M : Integer)
219 ---Purpose :Increment the multiplicities of the knots in
222 -- If <M> is not positive nithing is done.
224 -- For each knot the resulting multiplicity is
225 -- limited to the Degree.
229 ---Purpose: If <I1,I2> are not in [FirstUKnotIndex, LastUKnotIndex]
232 InsertKnot (me : mutable;
235 ParametricTolerance : Real = 0.0;
236 Add : Boolean = Standard_True);
238 ---Purpose: Inserts a knot value in the sequence of knots. If
239 -- <U> is an existing knot the multiplicity is
242 -- If U is not on the parameter range nothing is
245 -- If the multiplicity is negative or null nothing is
246 -- done. The new multiplicity is limited to the
249 -- The tolerance criterion for knots equality is
250 -- the max of Epsilon(U) and ParametricTolerance.
253 InsertKnots (me : mutable; Knots : Array1OfReal from TColStd;
254 Mults : Array1OfInteger from TColStd;
255 ParametricTolerance : Real = 0.0;
256 Add : Boolean = Standard_False);
258 ---Purpose: Inserts a set of knots values in the sequence of
261 -- For each U = Knots(i), M = Mults(i)
263 -- If <U> is an existing knot the multiplicity is
264 -- increased by <M> if <Add> is True, increased to
265 -- <M> if <Add> is False.
267 -- If U is not on the parameter range nothing is
270 -- If the multiplicity is negative or null nothing is
271 -- done. The new multiplicity is limited to the
274 -- The tolerance criterion for knots equality is
275 -- the max of Epsilon(U) and ParametricTolerance.
278 RemoveKnot(me : mutable; Index : Integer;
280 Tolerance : Real) returns Boolean
282 ---Purpose : Decrement the knots multiplicity to <M>. If M is
283 -- 0 the knot is removed. The Poles sequence is
286 -- As there are two ways to compute the new poles the
287 -- average is computed if the distance is lower than
288 -- the <Tolerance>, else False is returned.
290 -- A low tolerance is used to prevent the modification
293 -- A high tolerance is used to "smooth" the curve.
297 -- Raised if Index is not in the range
298 -- [FirstUKnotIndex, LastUKnotIndex]
301 ---Purpose : pole insertion and pole removing
302 -- this operation is limited to the Uniform or QuasiUniform
303 -- BSplineCurve. The knot values are modified . If the BSpline is
304 -- NonUniform or Piecewise Bezier an exception Construction error
308 Reverse (me : mutable);
310 -- Changes the direction of parametrization of <me>. The Knot
311 -- sequence is modified, the FirstParameter and the
312 -- LastParameter are not modified. The StartPoint of the
313 -- initial curve becomes the EndPoint of the reversed curve
314 -- and the EndPoint of the initial curve becomes the StartPoint
315 -- of the reversed curve.
318 ReversedParameter(me; U : Real) returns Real;
319 ---Purpose: Returns the parameter on the reversed curve for
320 -- the point of parameter U on <me>.
322 -- returns UFirst + ULast - U
325 Segment (me : mutable; U1, U2 : Real)
327 -- Segments the curve between U1 and U2.
328 -- The control points are modified, the first and the last point
331 -- Even if <me> is not closed it can become closed after the
332 -- segmentation for example if U1 or U2 are out of the bounds
333 -- of the curve <me> or if the curve makes loop.
334 -- After the segmentation the length of a curve can be null.
336 raises DomainError from Standard;
338 ---Purpose: raises if U2 < U1.
341 SetKnot (me : mutable; Index : Integer; K : Real)
342 ---Purpose : Changes the knot of range Index.
343 -- The multiplicity of the knot is not modified.
344 raises ConstructionError,
345 ---Purpose : Raised if K >= Knots(Index+1) or K <= Knots(Index-1).
347 ---Purpose : Raised if Index < 1 || Index > NbKnots
350 SetKnots (me : mutable; K : Array1OfReal from TColStd)
351 ---Purpose : Changes all the knots of the curve
352 -- The multiplicity of the knots are not modified.
353 raises ConstructionError,
355 -- Raised if there is an index such that K (Index+1) <= K (Index).
358 -- Raised if K.Lower() < 1 or K.Upper() > NbKnots
361 SetKnot (me : mutable; Index : Integer; K : Real; M : Integer)
363 -- Changes the knot of range Index with its multiplicity.
364 -- You can increase the multiplicity of a knot but it is
365 -- not allowed to decrease the multiplicity of an existing knot.
366 raises ConstructionError,
368 -- Raised if K >= Knots(Index+1) or K <= Knots(Index-1).
369 -- Raised if M is greater than Degree or lower than the previous
370 -- multiplicity of knot of range Index.
372 ---Purpose : Raised if Index < 1 || Index > NbKnots
375 PeriodicNormalization(me ; U : in out Real) ;
377 ---Purpose : returns the parameter normalized within
378 -- the period if the curve is periodic : otherwise
379 -- does not do anything
382 SetPeriodic (me : mutable)
384 -- Makes a closed B-spline into a periodic curve. The curve is
385 -- periodic if the knot sequence is periodic and if the curve is
386 -- closed (The tolerance criterion is Resolution from gp).
387 -- The period T is equal to Knot(LastUKnotIndex) -
388 -- Knot(FirstUKnotIndex). A periodic B-spline can be uniform
390 raises ConstructionError;
391 ---Purpose : Raised if the curve is not closed.
394 SetOrigin (me : mutable; Index : Integer)
395 ---Purpose: Set the origin of a periodic curve at Knot(index)
396 -- KnotVector and poles are modified.
398 ---Purpose: Raised if the curve is not periodic
400 ---Purpose: Raised if index not in the range
401 -- [FirstUKnotIndex , LastUKnotIndex]
404 SetNotPeriodic (me : mutable);
406 -- Makes a non periodic curve. If the curve was non periodic
407 -- the curve is not modified.
410 SetPole (me : mutable; Index : Integer; P : Real)
411 ---Purpose : Substitutes the Pole of range Index with P.
414 -- Raised if Index < 1 || Index > NbPoles
417 SetPole (me : mutable; Index : Integer; P : Real; Weight : Real)
419 -- Substitutes the pole and the weight of range Index.
420 -- If the curve <me> is not rational it can become rational
421 -- If the curve was rational it can become non rational
424 -- Raised if Index < 1 || Index > NbPoles
426 ---Purpose : Raised if Weight <= 0.0
429 SetWeight (me : mutable; Index : Integer; Weight : Real)
431 -- Changes the weight for the pole of range Index.
432 -- If the curve was non rational it can become rational.
433 -- If the curve was rational it can become non rational.
436 -- Raised if Index < 1 || Index > NbPoles
438 ---Purpose : Raised if Weight <= 0.0
441 IsCN (me; N : Integer) returns Boolean
443 -- Returns the continuity of the curve, the curve is at least C0.
445 ---Purpose : Raised if N < 0.
448 IsClosed (me) returns Boolean;
450 -- Returns true if the distance between the first point and the
451 -- last point of the curve is lower or equal to Resolution
454 -- The first and the last point can be different from the first
455 -- pole and the last pole of the curve.
458 IsPeriodic (me) returns Boolean;
459 ---Purpose : Returns True if the curve is periodic.
462 IsRational (me) returns Boolean;
464 -- Returns True if the weights are not identical.
465 -- The tolerance criterion is Epsilon of the class Real.
467 IsCacheValid(me; Parameter : Real) returns Boolean
470 -- Tells whether the Cache is valid for the
472 -- Warnings : the parameter must be normalized within
473 -- the period if the curve is periodic. Otherwise
474 -- the answer will be false
478 Continuity (me) returns Shape from GeomAbs;
480 -- Returns the global continuity of the curve :
481 -- C0 : only geometric continuity,
482 -- C1 : continuity of the first derivative all along the Curve,
483 -- C2 : continuity of the second derivative all along the Curve,
484 -- C3 : continuity of the third derivative all along the Curve,
485 -- CN : the order of continuity is infinite.
486 -- For a B-spline curve of degree d if a knot Ui has a
487 -- multiplicity p the B-spline curve is only Cd-p continuous
488 -- at Ui. So the global continuity of the curve can't be greater
489 -- than Cd-p where p is the maximum multiplicity of the interior
490 -- Knots. In the interior of a knot span the curve is infinitely
491 -- continuously differentiable.
494 Degree (me) returns Integer;
497 -------------------------------------------------
498 ---Purpose : Computation of value and derivatives
499 -------------------------------------------------
501 Value(me ; U : Real) returns Real from Standard;
503 D0 (me ; U : Real; P : out Real);
505 D1 (me; U : Real; P : out Real; V1 : out Real);
507 D2 (me; U : Real; P : out Real; V1, V2 : out Real);
509 D3 (me; U : Real; P : out Real; V1, V2, V3 : out Real);
511 DN (me; U : Real; N : Integer) returns Real;
514 ------------------------------------------------------------------
516 -- The following functions computes the point of parameter U and
517 -- the derivatives at this point on the B-spline curve arc
518 -- defined between the knot FromK1 and the knot ToK2. U can be
519 -- out of bounds [Knot (FromK1), Knot (ToK2)] but for the
520 -- computation we only use the definition of the curve between
521 -- these two knots. This method is useful to compute local
522 -- derivative, if the order of continuity of the whole curve is
523 -- not greater enough. Inside the parametric domain Knot
524 -- (FromK1), Knot (ToK2) the evaluations are the same as if we
525 -- consider the whole definition of the curve. Of course the
526 -- evaluations are different outside this parametric domain.
527 ------------------------------------------------------------------
529 LocalValue (me; U : Real; FromK1, ToK2 : Integer) returns Real;
531 LocalD0 (me; U : Real; FromK1, ToK2 : Integer; P : out Real);
533 LocalD1 (me; U : Real; FromK1, ToK2 : Integer; P, V1 : out Real);
535 LocalD2 (me; U : Real; FromK1, ToK2 : Integer; P, V1, V2 : out Real);
537 LocalD3 (me; U : Real; FromK1, ToK2 : Integer; P, V1, V2, V3 : out Real);
539 LocalDN (me; U : Real; FromK1, ToK2 : Integer; N : Integer) returns Real;
542 EndPoint (me) returns Real;
544 -- Returns the last point of the curve.
546 -- The last point of the curve is different from the last
547 -- pole of the curve if the multiplicity of the last knot
548 -- is lower than Degree.
551 FirstUKnotIndex (me) returns Integer;
553 -- For a B-spline curve the first parameter (which gives the start
554 -- point of the curve) is a knot value but if the multiplicity of
555 -- the first knot index is lower than Degree + 1 it is not the
556 -- first knot of the curve. This method computes the index of the
557 -- knot corresponding to the first parameter.
560 FirstParameter (me) returns Real;
562 -- Computes the parametric value of the start point of the curve.
563 -- It is a knot value.
566 Knot (me; Index : Integer) returns Real
568 -- Returns the knot of range Index. When there is a knot
569 -- with a multiplicity greater than 1 the knot is not repeated.
570 -- The method Multiplicity can be used to get the multiplicity
573 ---Purpose : Raised if Index < 1 or Index > NbKnots
576 Knots (me; K : out Array1OfReal from TColStd)
577 ---Purpose : returns the knot values of the B-spline curve;
578 raises DimensionError;
580 -- Raised if the length of K is not equal to the number of knots.
583 KnotSequence (me; K : out Array1OfReal from TColStd)
584 ---Purpose : Returns the knots sequence.
585 -- In this sequence the knots with a multiplicity greater than 1
588 -- K = {k1, k1, k1, k2, k3, k3, k4, k4, k4}
589 raises DimensionError;
591 -- Raised if the length of K is not equal to NbPoles + Degree + 1
595 KnotDistribution (me) returns BSplKnotDistribution from GeomAbs;
597 -- Returns NonUniform or Uniform or QuasiUniform or PiecewiseBezier.
598 -- If all the knots differ by a positive constant from the
599 -- preceding knot the BSpline Curve can be :
600 -- - Uniform if all the knots are of multiplicity 1,
601 -- - QuasiUniform if all the knots are of multiplicity 1 except for
602 -- the first and last knot which are of multiplicity Degree + 1,
603 -- - PiecewiseBezier if the first and last knots have multiplicity
604 -- Degree + 1 and if interior knots have multiplicity Degree
605 -- A piecewise Bezier with only two knots is a BezierCurve.
606 -- else the curve is non uniform.
607 -- The tolerance criterion is Epsilon from class Real.
610 LastUKnotIndex (me) returns Integer;
612 -- For a BSpline curve the last parameter (which gives the
613 -- end point of the curve) is a knot value but if the
614 -- multiplicity of the last knot index is lower than
615 -- Degree + 1 it is not the last knot of the curve. This
616 -- method computes the index of the knot corresponding to
617 -- the last parameter.
620 LastParameter (me) returns Real;
622 -- Computes the parametric value of the end point of the curve.
623 -- It is a knot value.
628 ParametricTolerance : Real;
629 I1, I2 : in out Integer;
630 WithKnotRepetition : Boolean = Standard_False);
632 -- Locates the parametric value U in the sequence of knots.
633 -- If "WithKnotRepetition" is True we consider the knot's
634 -- representation with repetition of multiple knot value,
635 -- otherwise we consider the knot's representation with
636 -- no repetition of multiple knot values.
637 -- Knots (I1) <= U <= Knots (I2)
638 -- . if I1 = I2 U is a knot value (the tolerance criterion
639 -- ParametricTolerance is used).
640 -- . if I1 < 1 => U < Knots (1) - Abs(ParametricTolerance)
641 -- . if I2 > NbKnots => U > Knots (NbKnots) + Abs(ParametricTolerance)
644 Multiplicity (me; Index : Integer) returns Integer
646 -- Returns the multiplicity of the knots of range Index.
648 ---Purpose : Raised if Index < 1 or Index > NbKnots
651 Multiplicities (me; M : out Array1OfInteger from TColStd)
653 -- Returns the multiplicity of the knots of the curve.
654 raises DimensionError;
656 -- Raised if the length of M is not equal to NbKnots.
659 NbKnots (me) returns Integer;
661 -- Returns the number of knots. This method returns the number of
662 -- knot without repetition of multiple knots.
665 NbPoles (me) returns Integer;
666 ---Purpose : Returns the number of poles
669 Pole (me; Index : Integer) returns Real
670 ---Purpose : Returns the pole of range Index.
672 ---Purpose : Raised if Index < 1 or Index > NbPoles.
675 Poles (me; P : out Array1OfReal from TColStd)
676 ---Purpose : Returns the poles of the B-spline curve;
677 raises DimensionError;
679 -- Raised if the length of P is not equal to the number of poles.
682 StartPoint (me) returns Real;
684 -- Returns the start point of the curve.
686 -- This point is different from the first pole of the curve if the
687 -- multiplicity of the first knot is lower than Degree.
690 Weight (me; Index : Integer) returns Real
691 ---Purpose : Returns the weight of the pole of range Index .
693 ---Purpose : Raised if Index < 1 or Index > NbPoles.
696 Weights (me; W : out Array1OfReal from TColStd)
697 ---Purpose : Returns the weights of the B-spline curve;
698 raises DimensionError;
700 -- Raised if the length of W is not equal to NbPoles.
703 MaxDegree (myclass) returns Integer;
705 -- Returns the value of the maximum degree of the normalized
706 -- B-spline basis functions in this package.
708 MovePointAndTangent (me : mutable;
714 EndingCondition : Integer;
715 ErrorStatus : out Integer)
718 -- Changes the value of the Law at parameter U to NewValue.
719 -- and makes its derivative at U be derivative.
720 -- StartingCondition = -1 means first can move
721 -- EndingCondition = -1 means last point can move
722 -- StartingCondition = 0 means the first point cannot move
723 -- EndingCondition = 0 means the last point cannot move
724 -- StartingCondition = 1 means the first point and tangent cannot move
725 -- EndingCondition = 1 means the last point and tangent cannot move
727 -- ErrorStatus != 0 means that there are not enought degree of freedom
728 -- with the constrain to deform the curve accordingly
732 Resolution(me ; Tolerance3D : Real;
733 UTolerance : out Real);
734 ---Purpose: given Tolerance3D returns UTolerance
735 -- such that if f(t) is the curve we have
736 -- | t1 - t0| < Utolerance ===>
737 -- |f(t1) - f(t0)| < Tolerance3D
740 Copy (me) returns mutable like me;
743 UpdateKnots(me : mutable)
744 ---Purpose : Recompute the flatknots, the knotsdistribution, the
753 knotSet : BSplKnotDistribution from GeomAbs;
754 smooth : Shape from GeomAbs;
756 poles : HArray1OfReal from TColStd;
757 weights : HArray1OfReal from TColStd;
758 flatknots : HArray1OfReal from TColStd;
759 knots : HArray1OfReal from TColStd;
760 mults : HArray1OfInteger from TColStd;