Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:03:32

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