Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/opencascade/Geom_BezierCurve.hxx was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // Created on: 1993-03-09
0002 // Created by: Philippe DAUTRY
0003 // Copyright (c) 1993-1999 Matra Datavision
0004 // Copyright (c) 1999-2014 OPEN CASCADE SAS
0005 //
0006 // This file is part of Open CASCADE Technology software library.
0007 //
0008 // This library is free software; you can redistribute it and/or modify it under
0009 // the terms of the GNU Lesser General Public License version 2.1 as published
0010 // by the Free Software Foundation, with special exception defined in the file
0011 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0012 // distribution for complete text of the license and disclaimer of any warranty.
0013 //
0014 // Alternatively, this file may be used under the terms of Open CASCADE
0015 // commercial license or contractual agreement.
0016 
0017 #ifndef _Geom_BezierCurve_HeaderFile
0018 #define _Geom_BezierCurve_HeaderFile
0019 
0020 #include <Standard.hxx>
0021 
0022 #include <TColgp_HArray1OfPnt.hxx>
0023 #include <Standard_Integer.hxx>
0024 #include <Standard_Real.hxx>
0025 #include <Geom_BoundedCurve.hxx>
0026 #include <TColgp_Array1OfPnt.hxx>
0027 #include <GeomAbs_Shape.hxx>
0028 #include <BSplCLib.hxx>
0029 
0030 class gp_Pnt;
0031 class gp_Vec;
0032 class gp_Trsf;
0033 class Geom_Geometry;
0034 
0035 
0036 class Geom_BezierCurve;
0037 DEFINE_STANDARD_HANDLE(Geom_BezierCurve, Geom_BoundedCurve)
0038 
0039 //! Describes a rational or non-rational Bezier curve
0040 //! - a non-rational Bezier curve is defined by a table of
0041 //! poles (also called control points),
0042 //! - a rational Bezier curve is defined by a table of
0043 //! poles with varying weights.
0044 //! These data are manipulated by two parallel arrays:
0045 //! - the poles table, which is an array of gp_Pnt points, and
0046 //! - the weights table, which is an array of reals.
0047 //! The bounds of these arrays are 1 and "the number of "poles" of the curve.
0048 //! The poles of the curve are "control points" used to deform the curve.
0049 //! The first pole is the start point of the curve, and the
0050 //! last pole is the end point of the curve. The segment
0051 //! that joins the first pole to the second pole is the
0052 //! tangent to the curve at its start point, and the
0053 //! segment that joins the last pole to the
0054 //! second-from-last pole is the tangent to the curve at its end point.
0055 //! It is more difficult to give a geometric signification to
0056 //! the weights but they are useful for providing the exact
0057 //! representations of arcs of a circle or ellipse.
0058 //! Moreover, if the weights of all poles are equal, the
0059 //! curve is polynomial; it is therefore a non-rational
0060 //! curve. The non-rational curve is a special and
0061 //! frequently used case. The weights are defined and
0062 //! used only in the case of a rational curve.
0063 //! The degree of a Bezier curve is equal to the number
0064 //! of poles, minus 1. It must be greater than or equal to
0065 //! 1. However, the degree of a Geom_BezierCurve
0066 //! curve is limited to a value (25) which is defined and
0067 //! controlled by the system. This value is returned by the function MaxDegree.
0068 //! The parameter range for a Bezier curve is [ 0, 1 ].
0069 //! If the first and last control points of the Bezier curve
0070 //! are the same point then the curve is closed. For
0071 //! example, to create a closed Bezier curve with four
0072 //! control points, you have to give the set of control
0073 //! points P1, P2, P3 and P1.
0074 //! The continuity of a Bezier curve is infinite.
0075 //! It is not possible to build a Bezier curve with negative
0076 //! weights. We consider that a weight value is zero if it
0077 //! is less than or equal to gp::Resolution(). We
0078 //! also consider that two weight values W1 and W2 are equal if:
0079 //! |W2 - W1| <= gp::Resolution().
0080 //! Warning
0081 //! - When considering the continuity of a closed Bezier
0082 //! curve at the junction point, remember that a curve
0083 //! of this type is never periodic. This means that the
0084 //! derivatives for the parameter u = 0 have no
0085 //! reason to be the same as the derivatives for the
0086 //! parameter u = 1 even if the curve is closed.
0087 //! - The length of a Bezier curve can be null.
0088 class Geom_BezierCurve : public Geom_BoundedCurve
0089 {
0090 
0091 public:
0092 
0093   
0094   //! Creates a non rational Bezier curve with a set of poles
0095   //! CurvePoles.  The weights are defaulted to all being 1.
0096   //! Raises ConstructionError if the number of poles is greater than MaxDegree + 1
0097   //! or lower than 2.
0098   Standard_EXPORT Geom_BezierCurve(const TColgp_Array1OfPnt& CurvePoles);
0099   
0100   //! Creates a rational Bezier curve with the set of poles
0101   //! CurvePoles and the set of weights  PoleWeights .
0102   //! If all the weights are identical the curve is considered
0103   //! as non rational. Raises ConstructionError if
0104   //! the number of poles is greater than  MaxDegree + 1 or lower
0105   //! than 2 or CurvePoles and CurveWeights have not the same length
0106   //! or one weight value is lower or equal to Resolution from package gp.
0107   Standard_EXPORT Geom_BezierCurve(const TColgp_Array1OfPnt& CurvePoles, const TColStd_Array1OfReal& PoleWeights);
0108   
0109   //! Increases the degree of a bezier curve. Degree is the new
0110   //! degree of <me>. Raises ConstructionError
0111   //! if Degree is greater than MaxDegree or lower than 2
0112   //! or lower than the initial degree of <me>.
0113   Standard_EXPORT void Increase (const Standard_Integer Degree);
0114   
0115   //! Inserts a pole P after the pole of range Index.
0116   //! If the curve <me> is rational the weight value for the new
0117   //! pole of range Index is 1.0.
0118   //! raised if Index is not in the range [1, NbPoles]
0119   //!
0120   //! raised if the resulting number of poles is greater than
0121   //! MaxDegree + 1.
0122   Standard_EXPORT void InsertPoleAfter (const Standard_Integer Index, const gp_Pnt& P);
0123   
0124 
0125   //! Inserts a pole with its weight in the set of poles after the
0126   //! pole of range Index. If the curve was non rational it can
0127   //! become rational if all the weights are not identical.
0128   //! Raised if Index is not in the range [1, NbPoles]
0129   //!
0130   //! Raised if the resulting number of poles is greater than
0131   //! MaxDegree + 1.
0132   //! Raised if Weight is lower or equal to Resolution from package gp.
0133   Standard_EXPORT void InsertPoleAfter (const Standard_Integer Index, const gp_Pnt& P, const Standard_Real Weight);
0134   
0135   //! Inserts a pole P before the pole of range Index.
0136   //! If the curve <me> is rational the weight value for the new
0137   //! pole of range Index is 1.0.
0138   //! Raised if Index is not in the range [1, NbPoles]
0139   //!
0140   //! Raised if the resulting number of poles is greater than
0141   //! MaxDegree + 1.
0142   Standard_EXPORT void InsertPoleBefore (const Standard_Integer Index, const gp_Pnt& P);
0143   
0144 
0145   //! Inserts a pole with its weight in the set of poles after
0146   //! the pole of range Index. If the curve was non rational it
0147   //! can become rational if all the weights are not identical.
0148   //! Raised if Index is not in the range [1, NbPoles]
0149   //!
0150   //! Raised if the resulting number of poles is greater than
0151   //! MaxDegree + 1.
0152   //! Raised if Weight is lower or equal to Resolution from
0153   //! package gp.
0154   Standard_EXPORT void InsertPoleBefore (const Standard_Integer Index, const gp_Pnt& P, const Standard_Real Weight);
0155   
0156   //! Removes the pole of range Index.
0157   //! If the curve was rational it can become non rational.
0158   //! Raised if Index is not in the range [1, NbPoles]
0159   //! Raised if Degree is lower than 2.
0160   Standard_EXPORT void RemovePole (const Standard_Integer Index);
0161   
0162 
0163   //! Reverses the direction of parametrization of <me>
0164   //! Value (NewU) =  Value (1 - OldU)
0165   Standard_EXPORT void Reverse() Standard_OVERRIDE;
0166   
0167   //! Returns the  parameter on the  reversed  curve for
0168   //! the point of parameter U on <me>.
0169   //!
0170   //! returns 1-U
0171   Standard_EXPORT Standard_Real ReversedParameter (const Standard_Real U) const Standard_OVERRIDE;
0172   
0173 
0174   //! Segments the curve between U1 and U2 which can be out
0175   //! of the bounds of the curve. The curve is oriented from U1
0176   //! to U2.
0177   //! The control points are modified, the first and the last point
0178   //! are not the same but the parametrization range is [0, 1]
0179   //! else it could not be a Bezier curve.
0180   //! Warnings :
0181   //! Even if <me> is not closed it can become closed after the
0182   //! segmentation for example if U1 or U2 are out of the bounds
0183   //! of the curve <me> or if the curve makes loop.
0184   //! After the segmentation the length of a curve can be null.
0185   Standard_EXPORT void Segment (const Standard_Real U1, const Standard_Real U2);
0186   
0187 
0188   //! Substitutes the pole of range index with P.
0189   //! If the curve <me> is rational the weight of range Index
0190   //! is not modified.
0191   //! raiseD if Index is not in the range [1, NbPoles]
0192   Standard_EXPORT void SetPole (const Standard_Integer Index, const gp_Pnt& P);
0193   
0194 
0195   //! Substitutes the pole and the weights of range Index.
0196   //! If the curve <me> is not rational it can become rational
0197   //! if all the weights are not identical.
0198   //! If the curve was rational it can become non rational if
0199   //! all the weights are identical.
0200   //! Raised if Index is not in the range [1, NbPoles]
0201   //! Raised if Weight <= Resolution from package gp
0202   Standard_EXPORT void SetPole (const Standard_Integer Index, const gp_Pnt& P, const Standard_Real Weight);
0203   
0204 
0205   //! Changes the weight of the pole of range Index.
0206   //! If the curve <me> is not rational it can become rational
0207   //! if all the weights are not identical.
0208   //! If the curve was rational it can become non rational if
0209   //! all the weights are identical.
0210   //! Raised if Index is not in the range [1, NbPoles]
0211   //! Raised if Weight <= Resolution from package gp
0212   Standard_EXPORT void SetWeight (const Standard_Integer Index, const Standard_Real Weight);
0213   
0214 
0215   //! Returns True if the distance between the first point
0216   //! and the last point of the curve is lower or equal to
0217   //! the Resolution from package gp.
0218   Standard_EXPORT Standard_Boolean IsClosed() const Standard_OVERRIDE;
0219   
0220   //! Continuity of the curve, returns True.
0221   Standard_EXPORT Standard_Boolean IsCN (const Standard_Integer N) const Standard_OVERRIDE;
0222   
0223 
0224   //! Returns True if the parametrization of a curve is periodic.
0225   //! (P(u) = P(u + T) T = constante)
0226   Standard_EXPORT Standard_Boolean IsPeriodic() const Standard_OVERRIDE;
0227   
0228 
0229   //! Returns false if all the weights are identical. The tolerance
0230   //! criterion is Resolution from package gp.
0231   Standard_EXPORT Standard_Boolean IsRational() const;
0232   
0233   //! a Bezier curve is CN
0234   Standard_EXPORT GeomAbs_Shape Continuity() const Standard_OVERRIDE;
0235   
0236   //! Returns the polynomial degree of the curve.
0237   //! it is the number of poles - 1
0238   //! point P and derivatives (V1, V2, V3) computation
0239   //! The Bezier Curve has a Polynomial representation so the
0240   //! parameter U can be out of the bounds of the curve.
0241   Standard_EXPORT Standard_Integer Degree() const;
0242   
0243   Standard_EXPORT void D0 (const Standard_Real U, gp_Pnt& P) const Standard_OVERRIDE;
0244   
0245   Standard_EXPORT void D1 (const Standard_Real U, gp_Pnt& P, gp_Vec& V1) const Standard_OVERRIDE;
0246   
0247   Standard_EXPORT void D2 (const Standard_Real U, gp_Pnt& P, gp_Vec& V1, gp_Vec& V2) const Standard_OVERRIDE;
0248   
0249   //! For this Bezier curve, computes
0250   //! - the point P of parameter U, or
0251   //! - the point P and one or more of the following values:
0252   //! - V1, the first derivative vector,
0253   //! - V2, the second derivative vector,
0254   //! - V3, the third derivative vector.
0255   //! Note: the parameter U can be outside the bounds of the curve.
0256   Standard_EXPORT void D3 (const Standard_Real U, gp_Pnt& P, gp_Vec& V1, gp_Vec& V2, gp_Vec& V3) const Standard_OVERRIDE;
0257   
0258   //! For the point of parameter U of this Bezier curve,
0259   //! computes the vector corresponding to the Nth derivative.
0260   //! Note: the parameter U can be outside the bounds of the curve.
0261   //! Exceptions Standard_RangeError if N is less than 1.
0262   Standard_EXPORT gp_Vec DN (const Standard_Real U, const Standard_Integer N) const Standard_OVERRIDE;
0263   
0264   //! Returns Value (U=0.), it is the first control point of the curve.
0265   Standard_EXPORT gp_Pnt StartPoint() const Standard_OVERRIDE;
0266   
0267   //! Returns Value (U=1.), it is the last control point of the Bezier curve.
0268   Standard_EXPORT gp_Pnt EndPoint() const Standard_OVERRIDE;
0269   
0270   //! Returns the value of the first  parameter of this
0271   //! Bezier curve. This is 0.0, which gives the start point of this Bezier curve
0272   Standard_EXPORT Standard_Real FirstParameter() const Standard_OVERRIDE;
0273   
0274   //! Returns the value of the last parameter of this
0275   //! Bezier curve. This is  1.0, which gives the end point of this Bezier curve.
0276   Standard_EXPORT Standard_Real LastParameter() const Standard_OVERRIDE;
0277   
0278   //! Returns the number of poles of this Bezier curve.
0279   Standard_EXPORT Standard_Integer NbPoles() const;
0280   
0281   //! Returns the pole of range Index.
0282   //! Raised if Index is not in the range [1, NbPoles]
0283   Standard_EXPORT const gp_Pnt& Pole (const Standard_Integer Index) const;
0284   
0285   //! Returns all the poles of the curve.
0286   //!
0287   //! Raised if the length of P is not equal to the number of poles.
0288   Standard_EXPORT void Poles (TColgp_Array1OfPnt& P) const;
0289 
0290     //! Returns all the poles of the curve.
0291   Standard_EXPORT const TColgp_Array1OfPnt& Poles () const;
0292   
0293   //! Returns the weight of range Index.
0294   //! Raised if Index is not in the range [1, NbPoles]
0295   Standard_EXPORT Standard_Real Weight (const Standard_Integer Index) const;
0296   
0297   //! Returns all the weights of the curve.
0298   //!
0299   //! Raised if the length of W is not equal to the number of poles.
0300   Standard_EXPORT void Weights (TColStd_Array1OfReal& W) const;
0301 
0302   //! Returns all the weights of the curve.
0303   const TColStd_Array1OfReal* Weights() const
0304   {
0305     if (!weights.IsNull())
0306       return &weights->Array1();
0307     return BSplCLib::NoWeights();
0308   }
0309 
0310   //! Applies the transformation T to this Bezier curve.
0311   Standard_EXPORT void Transform (const gp_Trsf& T) Standard_OVERRIDE;
0312   
0313 
0314   //! Returns the value of the maximum polynomial degree
0315   //! of any Geom_BezierCurve curve. This value is 25.
0316   Standard_EXPORT static Standard_Integer MaxDegree();
0317   
0318   //! Computes for this Bezier curve the parametric
0319   //! tolerance UTolerance for a given 3D tolerance Tolerance3D.
0320   //! If f(t) is the equation of this Bezier curve,
0321   //! UTolerance ensures that:
0322   //! |t1-t0| < UTolerance ===> |f(t1)-f(t0)| < Tolerance3D
0323   Standard_EXPORT void Resolution (const Standard_Real Tolerance3D, Standard_Real& UTolerance);
0324   
0325   //! Creates a new object which is a copy of this Bezier curve.
0326   Standard_EXPORT Handle(Geom_Geometry) Copy() const Standard_OVERRIDE;
0327 
0328   //! Dumps the content of me into the stream
0329   Standard_EXPORT virtual void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const Standard_OVERRIDE;
0330 
0331 
0332 
0333 
0334   DEFINE_STANDARD_RTTIEXT(Geom_BezierCurve,Geom_BoundedCurve)
0335 
0336 protected:
0337 
0338 
0339 
0340 
0341 private:
0342 
0343   
0344   //! Set  poles  to  Poles,  weights to  Weights  (not
0345   //! copied). If Weights is   null  the  curve is    non
0346   //! rational. Create the arrays of coefficients.  Poles
0347   //! and    Weights  are   assumed   to  have the  first
0348   //! coefficient 1.
0349   //! Update rational and closed.
0350   //!
0351   //! if nbpoles < 2 or nbboles > MaDegree + 1
0352   void Init (const Handle(TColgp_HArray1OfPnt)& Poles, const Handle(TColStd_HArray1OfReal)& Weights);
0353 
0354   Standard_Boolean rational;
0355   Standard_Boolean closed;
0356   Handle(TColgp_HArray1OfPnt) poles;
0357   Handle(TColStd_HArray1OfReal) weights;
0358   Standard_Real maxderivinv;
0359   Standard_Boolean maxderivinvok;
0360 
0361 
0362 };
0363 
0364 
0365 
0366 
0367 
0368 
0369 
0370 #endif // _Geom_BezierCurve_HeaderFile