|
|
|||
Warning, file /include/opencascade/Geom2d_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-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 <gp_Pnt2d.hxx> 0023 #include <NCollection_Array1.hxx> 0024 #include <Geom2d_BoundedCurve.hxx> 0025 #include <GeomAbs_Shape.hxx> 0026 #include <BSplCLib.hxx> 0027 0028 class gp_Trsf2d; 0029 class Geom2d_Geometry; 0030 0031 namespace Geom2dEval_RepCurveDesc 0032 { 0033 class Base; 0034 } 0035 0036 //! Describes a rational or non-rational Bezier curve 0037 //! - a non-rational Bezier curve is defined by a table 0038 //! of poles (also called control points), 0039 //! - a rational Bezier curve is defined by a table of 0040 //! poles with varying weights. 0041 //! These data are manipulated by two parallel arrays: 0042 //! - the poles table, which is an array of gp_Pnt2d points, and 0043 //! - the weights table, which is an array of reals. 0044 //! The bounds of these arrays are 1 and "the number of poles" of the curve. 0045 //! The poles of the curve are "control points" used to deform the curve. 0046 //! The first pole is the start point of the curve, and the 0047 //! last pole is the end point of the curve. The segment 0048 //! which joins the first pole to the second pole is the 0049 //! tangent to the curve at its start point, and the 0050 //! segment which joins the last pole to the 0051 //! second-from-last pole is the tangent to the curve 0052 //! at its end point. 0053 //! It is more difficult to give a geometric signification 0054 //! to the weights but they are useful for providing 0055 //! exact representations of the arcs of a circle or 0056 //! ellipse. Moreover, if the weights of all the poles are 0057 //! equal, the curve is polynomial; it is therefore a 0058 //! non-rational curve. The non-rational curve is a 0059 //! special and frequently used case. The weights are 0060 //! defined and used only in case of a rational curve. 0061 //! The degree of a Bezier curve is equal to the 0062 //! number of poles, minus 1. It must be greater than or 0063 //! equal to 1. However, the degree of a 0064 //! Geom2d_BezierCurve curve is limited to a value 0065 //! (25) which is defined and controlled by the system. 0066 //! This value is returned by the function MaxDegree. 0067 //! The parameter range for a Bezier curve is [ 0, 1 ]. 0068 //! If the first and last control points of the Bezier 0069 //! curve are the same point then the curve is closed. 0070 //! For example, to create a closed Bezier curve with 0071 //! four control points, you have to give a set of control 0072 //! points P1, P2, P3 and P1. 0073 //! The continuity of a Bezier curve is infinite. 0074 //! It is not possible to build a Bezier curve with 0075 //! negative weights. We consider that a weight value 0076 //! is zero if it is less than or equal to 0077 //! gp::Resolution(). We also consider that 0078 //! two weight values W1 and W2 are equal if: 0079 //! |W2 - W1| <= gp::Resolution(). 0080 //! Warning 0081 //! - When considering the continuity of a closed 0082 //! Bezier curve at the junction point, remember that 0083 //! a curve of this type is never periodic. This means 0084 //! that the derivatives for the parameter u = 0 0085 //! have no reason to be the same as the 0086 //! derivatives for the parameter u = 1 even if the curve is closed. 0087 //! - The length of a Bezier curve can be null. 0088 class Geom2d_BezierCurve : public Geom2d_BoundedCurve 0089 { 0090 0091 public: 0092 //! Creates a non rational Bezier curve with a set of poles : 0093 //! CurvePoles. The weights are defaulted to all being 1. 0094 //! Raises ConstructionError if the number of poles is greater than MaxDegree + 1 0095 //! or lower than 2. 0096 Standard_EXPORT Geom2d_BezierCurve(const NCollection_Array1<gp_Pnt2d>& CurvePoles); 0097 0098 //! Creates a rational Bezier curve with the set of poles 0099 //! CurvePoles and the set of weights PoleWeights. 0100 //! If all the weights are identical the curve is considered 0101 //! as non rational. Raises ConstructionError if the number 0102 //! of poles is greater than MaxDegree + 1 or lower than 2 0103 //! or CurvePoles and CurveWeights have not the same length 0104 //! or one weight value is lower or equal to Resolution from 0105 //! package gp. 0106 Standard_EXPORT Geom2d_BezierCurve(const NCollection_Array1<gp_Pnt2d>& CurvePoles, 0107 const NCollection_Array1<double>& PoleWeights); 0108 0109 //! Copy constructor for optimized copying without validation. 0110 Standard_EXPORT Geom2d_BezierCurve(const Geom2d_BezierCurve& theOther); 0111 0112 //! Returns true if an evaluation representation is attached. 0113 bool HasEvalRepresentation() const { return !myEvalRep.IsNull(); } 0114 0115 //! Returns the current evaluation representation descriptor (may be null). 0116 const occ::handle<Geom2dEval_RepCurveDesc::Base>& EvalRepresentation() const { return myEvalRep; } 0117 0118 //! Sets a new evaluation representation. 0119 //! Validates descriptor data and ensures no circular references. 0120 Standard_EXPORT void SetEvalRepresentation( 0121 const occ::handle<Geom2dEval_RepCurveDesc::Base>& theDesc); 0122 0123 //! Removes the evaluation representation. 0124 void ClearEvalRepresentation() { myEvalRep.Nullify(); } 0125 0126 //! Increases the degree of a bezier curve. Degree is the new 0127 //! degree of <me>. 0128 //! raises ConstructionError if Degree is greater than MaxDegree or lower than 2 0129 //! or lower than the initial degree of <me>. 0130 Standard_EXPORT void Increase(const int Degree); 0131 0132 //! Inserts a pole with its weight in the set of poles after the 0133 //! pole of range Index. If the curve was non rational it can 0134 //! become rational if all the weights are not identical. 0135 //! Raised if Index is not in the range [0, NbPoles] 0136 //! 0137 //! Raised if the resulting number of poles is greater than 0138 //! MaxDegree + 1. 0139 Standard_EXPORT void InsertPoleAfter(const int Index, 0140 const gp_Pnt2d& P, 0141 const double Weight = 1.0); 0142 0143 //! Inserts a pole with its weight in the set of poles after 0144 //! the pole of range Index. If the curve was non rational it 0145 //! can become rational if all the weights are not identical. 0146 //! Raised if Index is not in the range [1, NbPoles+1] 0147 //! 0148 //! Raised if the resulting number of poles is greater than 0149 //! MaxDegree + 1. 0150 Standard_EXPORT void InsertPoleBefore(const int Index, 0151 const gp_Pnt2d& P, 0152 const double Weight = 1.0); 0153 0154 //! Removes the pole of range Index. 0155 //! If the curve was rational it can become non rational. 0156 //! Raised if Index is not in the range [1, NbPoles] 0157 Standard_EXPORT void RemovePole(const int Index); 0158 0159 //! Reverses the direction of parametrization of <me> 0160 //! Value (NewU) = Value (1 - OldU) 0161 Standard_EXPORT void Reverse() final; 0162 0163 //! Returns the parameter on the reversed curve for 0164 //! the point of parameter U on <me>. 0165 //! 0166 //! returns 1-U 0167 Standard_EXPORT double ReversedParameter(const double U) const final; 0168 0169 //! Segments the curve between U1 and U2 which can be out 0170 //! of the bounds of the curve. The curve is oriented from U1 0171 //! to U2. 0172 //! The control points are modified, the first and the last point 0173 //! are not the same but the parametrization range is [0, 1] 0174 //! else it could not be a Bezier curve. 0175 //! Warnings: 0176 //! Even if <me> is not closed it can become closed after the 0177 //! segmentation for example if U1 or U2 are out of the bounds 0178 //! of the curve <me> or if the curve makes loop. 0179 //! After the segmentation the length of a curve can be null. 0180 Standard_EXPORT void Segment(const double U1, const double U2); 0181 0182 //! Substitutes the pole of range index with P. 0183 //! If the curve <me> is rational the weight of range Index 0184 //! is not modified. 0185 //! raiseD if Index is not in the range [1, NbPoles] 0186 Standard_EXPORT void SetPole(const int Index, const gp_Pnt2d& P); 0187 0188 //! Substitutes the pole and the weights of range Index. 0189 //! If the curve <me> is not rational it can become rational 0190 //! if all the weights are not identical. 0191 //! If the curve was rational it can become non rational if 0192 //! all the weights are identical. 0193 //! Raised if Index is not in the range [1, NbPoles] 0194 //! Raised if Weight <= Resolution from package gp 0195 Standard_EXPORT void SetPole(const int Index, const gp_Pnt2d& P, const double Weight); 0196 0197 //! Changes the weight of the pole of range Index. 0198 //! If the curve <me> is not rational it can become rational 0199 //! if all the weights are not identical. 0200 //! If the curve was rational it can become non rational if 0201 //! all the weights are identical. 0202 //! Raised if Index is not in the range [1, NbPoles] 0203 //! Raised if Weight <= Resolution from package gp 0204 Standard_EXPORT void SetWeight(const int Index, const double Weight); 0205 0206 //! Returns True if the distance between the first point 0207 //! and the last point of the curve is lower or equal to 0208 //! the Resolution from package gp. 0209 Standard_EXPORT bool IsClosed() const final; 0210 0211 //! Continuity of the curve, returns True. 0212 Standard_EXPORT bool IsCN(const int N) const final; 0213 0214 //! Returns False. A BezierCurve cannot be periodic in this 0215 //! package 0216 Standard_EXPORT bool IsPeriodic() const final; 0217 0218 //! Returns false if all the weights are identical. The tolerance 0219 //! criterion is Resolution from package gp. 0220 Standard_EXPORT bool IsRational() const; 0221 0222 //! Returns GeomAbs_CN, which is the continuity of any Bezier curve. 0223 Standard_EXPORT GeomAbs_Shape Continuity() const final; 0224 0225 //! Returns the polynomial degree of the curve. It is the number 0226 //! of poles less one. In this package the Degree of a Bezier 0227 //! curve cannot be greater than "MaxDegree". 0228 Standard_EXPORT int Degree() const; 0229 0230 Standard_EXPORT gp_Pnt2d EvalD0(const double U) const final; 0231 0232 Standard_EXPORT Geom2d_Curve::ResD1 EvalD1(const double U) const final; 0233 0234 Standard_EXPORT Geom2d_Curve::ResD2 EvalD2(const double U) const final; 0235 0236 Standard_EXPORT Geom2d_Curve::ResD3 EvalD3(const double U) const final; 0237 0238 //! For this Bezier curve, computes 0239 //! - the point P of parameter U, or 0240 //! - the point P and one or more of the following values: 0241 //! - V1, the first derivative vector, 0242 //! - V2, the second derivative vector, 0243 //! - V3, the third derivative vector. 0244 //! Note: the parameter U can be outside the bounds of the curve. 0245 //! Raises RangeError if N < 1. 0246 Standard_EXPORT gp_Vec2d EvalDN(const double U, const int N) const final; 0247 0248 //! Returns the end point or start point of this Bezier curve. 0249 Standard_EXPORT gp_Pnt2d EndPoint() const final; 0250 0251 //! Returns the value of the first parameter of this Bezier curve. 0252 //! This is 0.0, which gives the start point of this Bezier curve. 0253 Standard_EXPORT double FirstParameter() const final; 0254 0255 //! Returns the value of the last parameter of this Bezier curve. 0256 //! This is 1.0, which gives the end point of this Bezier curve. 0257 Standard_EXPORT double LastParameter() const final; 0258 0259 //! Returns the number of poles for this Bezier curve. 0260 Standard_EXPORT int NbPoles() const; 0261 0262 //! Returns the pole of range Index. 0263 //! Raised if Index is not in the range [1, NbPoles] 0264 Standard_EXPORT const gp_Pnt2d& Pole(const int Index) const; 0265 0266 //! Returns all the poles of the curve. 0267 //! 0268 //! Raised if the length of P is not equal to the number of poles. 0269 Standard_DEPRECATED("use Poles() returning const reference instead") 0270 Standard_EXPORT void Poles(NCollection_Array1<gp_Pnt2d>& P) const; 0271 0272 //! Returns all the poles of the curve. 0273 const NCollection_Array1<gp_Pnt2d>& Poles() const { return myPoles; } 0274 0275 //! Returns Value (U=1), it is the first control point 0276 //! of the curve. 0277 Standard_EXPORT gp_Pnt2d StartPoint() const final; 0278 0279 //! Returns the weight of range Index. 0280 //! Raised if Index is not in the range [1, NbPoles] 0281 Standard_EXPORT double Weight(const int Index) const; 0282 0283 //! Returns all the weights of the curve. 0284 //! 0285 //! Raised if the length of W is not equal to the number of poles. 0286 Standard_DEPRECATED("use Weights() returning const pointer instead") 0287 Standard_EXPORT void Weights(NCollection_Array1<double>& W) const; 0288 0289 //! Returns all the weights of the curve. 0290 const NCollection_Array1<double>* Weights() const 0291 { 0292 return myRational ? &myWeights : BSplCLib::NoWeights(); 0293 } 0294 0295 //! Returns a const reference to the weights array. 0296 //! For rational curves: the internal owning weights array. 0297 //! For non-rational curves: a non-owning view of unit weights from BSplCLib. 0298 //! The array is always sized to match NbPoles(). 0299 //! @warning Do NOT modify elements through the returned reference. 0300 const NCollection_Array1<double>& WeightsArray() const { return myWeights; } 0301 0302 //! Applies the transformation T to this Bezier curve. 0303 Standard_EXPORT void Transform(const gp_Trsf2d& T) final; 0304 0305 //! Returns the value of the maximum polynomial degree of a 0306 //! BezierCurve. This value is 25. 0307 Standard_EXPORT static int MaxDegree(); 0308 0309 //! Computes for this Bezier curve the parametric 0310 //! tolerance UTolerance for a given tolerance 0311 //! Tolerance3D (relative to dimensions in the plane). 0312 //! If f(t) is the equation of this Bezier curve, 0313 //! UTolerance ensures that 0314 //! | t1 - t0| < Utolerance ===> 0315 //! |f(t1) - f(t0)| < ToleranceUV 0316 Standard_EXPORT void Resolution(const double ToleranceUV, double& UTolerance); 0317 0318 //! Creates a new object which is a copy of this Bezier curve. 0319 Standard_EXPORT occ::handle<Geom2d_Geometry> Copy() const final; 0320 0321 //! Dumps the content of me into the stream 0322 Standard_EXPORT void DumpJson(Standard_OStream& theOStream, int theDepth = -1) const final; 0323 0324 //! Returns Bezier knots {0.0, 1.0} as a static array. 0325 Standard_EXPORT const NCollection_Array1<double>& Knots() const; 0326 0327 //! Returns Bezier multiplicities for the current degree. 0328 Standard_EXPORT const NCollection_Array1<int>& Multiplicities() const; 0329 0330 //! Returns Bezier flat knots for the current degree. 0331 Standard_EXPORT const NCollection_Array1<double>& KnotSequence() const; 0332 0333 DEFINE_STANDARD_RTTIEXT(Geom2d_BezierCurve, Geom2d_BoundedCurve) 0334 0335 protected: 0336 //! Set poles to thePoles, weights to theWeights. 0337 //! If theWeights is null the curve is non rational. 0338 //! Update rational and closed. 0339 void init(const NCollection_Array1<gp_Pnt2d>& thePoles, 0340 const NCollection_Array1<double>* theWeights); 0341 0342 private: 0343 NCollection_Array1<gp_Pnt2d> myPoles; 0344 NCollection_Array1<double> myWeights; 0345 occ::handle<Geom2dEval_RepCurveDesc::Base> myEvalRep; 0346 bool myRational = false; 0347 bool myClosed = false; 0348 double myMaxDerivInv = 0.0; 0349 bool myMaxDerivInvOk = false; 0350 }; 0351 0352 #endif // _Geom2d_BezierCurve_HeaderFile
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|