1 // Created on: 1993-03-09 2 // Created by: Philippe DAUTRY 3 // Copyright (c) 1993-1999 Matra Datavision 4 // Copyright (c) 1999-2014 OPEN CASCADE SAS 5 // 6 // This file is part of Open CASCADE Technology software library. 7 // 8 // This library is free software; you can redistribute it and/or modify it under 9 // the terms of the GNU Lesser General Public License version 2.1 as published 10 // by the Free Software Foundation, with special exception defined in the file 11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT 12 // distribution for complete text of the license and disclaimer of any warranty. 13 // 14 // Alternatively, this file may be used under the terms of Open CASCADE 15 // commercial license or contractual agreement. 16 17 #ifndef _Geom_BezierCurve_HeaderFile 18 #define _Geom_BezierCurve_HeaderFile 19 20 #include <Standard.hxx> 21 #include <Standard_Type.hxx> 22 23 #include <Standard_Boolean.hxx> 24 #include <TColgp_HArray1OfPnt.hxx> 25 #include <TColStd_HArray1OfReal.hxx> 26 #include <Standard_Integer.hxx> 27 #include <Standard_Real.hxx> 28 #include <Geom_BoundedCurve.hxx> 29 #include <TColgp_Array1OfPnt.hxx> 30 #include <TColStd_Array1OfReal.hxx> 31 #include <GeomAbs_Shape.hxx> 32 #include <BSplCLib.hxx> 33 34 class gp_Pnt; 35 class gp_Vec; 36 class gp_Trsf; 37 class Geom_Geometry; 38 39 40 class Geom_BezierCurve; 41 DEFINE_STANDARD_HANDLE(Geom_BezierCurve, Geom_BoundedCurve) 42 43 //! Describes a rational or non-rational Bezier curve 44 //! - a non-rational Bezier curve is defined by a table of 45 //! poles (also called control points), 46 //! - a rational Bezier curve is defined by a table of 47 //! poles with varying weights. 48 //! These data are manipulated by two parallel arrays: 49 //! - the poles table, which is an array of gp_Pnt points, and 50 //! - the weights table, which is an array of reals. 51 //! The bounds of these arrays are 1 and "the number of "poles" of the curve. 52 //! The poles of the curve are "control points" used to deform the curve. 53 //! The first pole is the start point of the curve, and the 54 //! last pole is the end point of the curve. The segment 55 //! that joins the first pole to the second pole is the 56 //! tangent to the curve at its start point, and the 57 //! segment that joins the last pole to the 58 //! second-from-last pole is the tangent to the curve at its end point. 59 //! It is more difficult to give a geometric signification to 60 //! the weights but they are useful for providing the exact 61 //! representations of arcs of a circle or ellipse. 62 //! Moreover, if the weights of all poles are equal, the 63 //! curve is polynomial; it is therefore a non-rational 64 //! curve. The non-rational curve is a special and 65 //! frequently used case. The weights are defined and 66 //! used only in the case of a rational curve. 67 //! The degree of a Bezier curve is equal to the number 68 //! of poles, minus 1. It must be greater than or equal to 69 //! 1. However, the degree of a Geom_BezierCurve 70 //! curve is limited to a value (25) which is defined and 71 //! controlled by the system. This value is returned by the function MaxDegree. 72 //! The parameter range for a Bezier curve is [ 0, 1 ]. 73 //! If the first and last control points of the Bezier curve 74 //! are the same point then the curve is closed. For 75 //! example, to create a closed Bezier curve with four 76 //! control points, you have to give the set of control 77 //! points P1, P2, P3 and P1. 78 //! The continuity of a Bezier curve is infinite. 79 //! It is not possible to build a Bezier curve with negative 80 //! weights. We consider that a weight value is zero if it 81 //! is less than or equal to gp::Resolution(). We 82 //! also consider that two weight values W1 and W2 are equal if: 83 //! |W2 - W1| <= gp::Resolution(). 84 //! Warning 85 //! - When considering the continuity of a closed Bezier 86 //! curve at the junction point, remember that a curve 87 //! of this type is never periodic. This means that the 88 //! derivatives for the parameter u = 0 have no 89 //! reason to be the same as the derivatives for the 90 //! parameter u = 1 even if the curve is closed. 91 //! - The length of a Bezier curve can be null. 92 class Geom_BezierCurve : public Geom_BoundedCurve 93 { 94 95 public: 96 97 98 //! Creates a non rational Bezier curve with a set of poles 99 //! CurvePoles. The weights are defaulted to all being 1. 100 //! Raises ConstructionError if the number of poles is greater than MaxDegree + 1 101 //! or lower than 2. 102 Standard_EXPORT Geom_BezierCurve(const TColgp_Array1OfPnt& CurvePoles); 103 104 //! Creates a rational Bezier curve with the set of poles 105 //! CurvePoles and the set of weights PoleWeights . 106 //! If all the weights are identical the curve is considered 107 //! as non rational. Raises ConstructionError if 108 //! the number of poles is greater than MaxDegree + 1 or lower 109 //! than 2 or CurvePoles and CurveWeights have not the same length 110 //! or one weight value is lower or equal to Resolution from package gp. 111 Standard_EXPORT Geom_BezierCurve(const TColgp_Array1OfPnt& CurvePoles, const TColStd_Array1OfReal& PoleWeights); 112 113 //! Increases the degree of a bezier curve. Degree is the new 114 //! degree of <me>. Raises ConstructionError 115 //! if Degree is greater than MaxDegree or lower than 2 116 //! or lower than the initial degree of <me>. 117 Standard_EXPORT void Increase (const Standard_Integer Degree); 118 119 //! Inserts a pole P after the pole of range Index. 120 //! If the curve <me> is rational the weight value for the new 121 //! pole of range Index is 1.0. 122 //! raised if Index is not in the range [1, NbPoles] 123 //! 124 //! raised if the resulting number of poles is greater than 125 //! MaxDegree + 1. 126 Standard_EXPORT void InsertPoleAfter (const Standard_Integer Index, const gp_Pnt& P); 127 128 129 //! Inserts a pole with its weight in the set of poles after the 130 //! pole of range Index. If the curve was non rational it can 131 //! become rational if all the weights are not identical. 132 //! Raised if Index is not in the range [1, NbPoles] 133 //! 134 //! Raised if the resulting number of poles is greater than 135 //! MaxDegree + 1. 136 //! Raised if Weight is lower or equal to Resolution from package gp. 137 Standard_EXPORT void InsertPoleAfter (const Standard_Integer Index, const gp_Pnt& P, const Standard_Real Weight); 138 139 //! Inserts a pole P before the pole of range Index. 140 //! If the curve <me> is rational the weight value for the new 141 //! pole of range Index is 1.0. 142 //! Raised if Index is not in the range [1, NbPoles] 143 //! 144 //! Raised if the resulting number of poles is greater than 145 //! MaxDegree + 1. 146 Standard_EXPORT void InsertPoleBefore (const Standard_Integer Index, const gp_Pnt& P); 147 148 149 //! Inserts a pole with its weight in the set of poles after 150 //! the pole of range Index. If the curve was non rational it 151 //! can become rational if all the weights are not identical. 152 //! Raised if Index is not in the range [1, NbPoles] 153 //! 154 //! Raised if the resulting number of poles is greater than 155 //! MaxDegree + 1. 156 //! Raised if Weight is lower or equal to Resolution from 157 //! package gp. 158 Standard_EXPORT void InsertPoleBefore (const Standard_Integer Index, const gp_Pnt& P, const Standard_Real Weight); 159 160 //! Removes the pole of range Index. 161 //! If the curve was rational it can become non rational. 162 //! Raised if Index is not in the range [1, NbPoles] 163 //! Raised if Degree is lower than 2. 164 Standard_EXPORT void RemovePole (const Standard_Integer Index); 165 166 167 //! Reverses the direction of parametrization of <me> 168 //! Value (NewU) = Value (1 - OldU) 169 Standard_EXPORT void Reverse() Standard_OVERRIDE; 170 171 //! Returns the parameter on the reversed curve for 172 //! the point of parameter U on <me>. 173 //! 174 //! returns 1-U 175 Standard_EXPORT Standard_Real ReversedParameter (const Standard_Real U) const Standard_OVERRIDE; 176 177 178 //! Segments the curve between U1 and U2 which can be out 179 //! of the bounds of the curve. The curve is oriented from U1 180 //! to U2. 181 //! The control points are modified, the first and the last point 182 //! are not the same but the parametrization range is [0, 1] 183 //! else it could not be a Bezier curve. 184 //! Warnings : 185 //! Even if <me> is not closed it can become closed after the 186 //! segmentation for example if U1 or U2 are out of the bounds 187 //! of the curve <me> or if the curve makes loop. 188 //! After the segmentation the length of a curve can be null. 189 Standard_EXPORT void Segment (const Standard_Real U1, const Standard_Real U2); 190 191 192 //! Substitutes the pole of range index with P. 193 //! If the curve <me> is rational the weight of range Index 194 //! is not modified. 195 //! raiseD if Index is not in the range [1, NbPoles] 196 Standard_EXPORT void SetPole (const Standard_Integer Index, const gp_Pnt& P); 197 198 199 //! Substitutes the pole and the weights of range Index. 200 //! If the curve <me> is not rational it can become rational 201 //! if all the weights are not identical. 202 //! If the curve was rational it can become non rational if 203 //! all the weights are identical. 204 //! Raised if Index is not in the range [1, NbPoles] 205 //! Raised if Weight <= Resolution from package gp 206 Standard_EXPORT void SetPole (const Standard_Integer Index, const gp_Pnt& P, const Standard_Real Weight); 207 208 209 //! Changes the weight of the pole of range Index. 210 //! If the curve <me> is not rational it can become rational 211 //! if all the weights are not identical. 212 //! If the curve was rational it can become non rational if 213 //! all the weights are identical. 214 //! Raised if Index is not in the range [1, NbPoles] 215 //! Raised if Weight <= Resolution from package gp 216 Standard_EXPORT void SetWeight (const Standard_Integer Index, const Standard_Real Weight); 217 218 219 //! Returns True if the distance between the first point 220 //! and the last point of the curve is lower or equal to 221 //! the Resolution from package gp. 222 Standard_EXPORT Standard_Boolean IsClosed() const Standard_OVERRIDE; 223 224 //! Continuity of the curve, returns True. 225 Standard_EXPORT Standard_Boolean IsCN (const Standard_Integer N) const Standard_OVERRIDE; 226 227 228 //! Returns True if the parametrization of a curve is periodic. 229 //! (P(u) = P(u + T) T = constante) 230 Standard_EXPORT Standard_Boolean IsPeriodic() const Standard_OVERRIDE; 231 232 233 //! Returns false if all the weights are identical. The tolerance 234 //! criterion is Resolution from package gp. 235 Standard_EXPORT Standard_Boolean IsRational() const; 236 237 //! a Bezier curve is CN 238 Standard_EXPORT GeomAbs_Shape Continuity() const Standard_OVERRIDE; 239 240 //! Returns the polynomial degree of the curve. 241 //! it is the number of poles - 1 242 //! point P and derivatives (V1, V2, V3) computation 243 //! The Bezier Curve has a Polynomial representation so the 244 //! parameter U can be out of the bounds of the curve. 245 Standard_EXPORT Standard_Integer Degree() const; 246 247 Standard_EXPORT void D0 (const Standard_Real U, gp_Pnt& P) const Standard_OVERRIDE; 248 249 Standard_EXPORT void D1 (const Standard_Real U, gp_Pnt& P, gp_Vec& V1) const Standard_OVERRIDE; 250 251 Standard_EXPORT void D2 (const Standard_Real U, gp_Pnt& P, gp_Vec& V1, gp_Vec& V2) const Standard_OVERRIDE; 252 253 //! For this Bezier curve, computes 254 //! - the point P of parameter U, or 255 //! - the point P and one or more of the following values: 256 //! - V1, the first derivative vector, 257 //! - V2, the second derivative vector, 258 //! - V3, the third derivative vector. 259 //! Note: the parameter U can be outside the bounds of the curve. 260 Standard_EXPORT void D3 (const Standard_Real U, gp_Pnt& P, gp_Vec& V1, gp_Vec& V2, gp_Vec& V3) const Standard_OVERRIDE; 261 262 //! For the point of parameter U of this Bezier curve, 263 //! computes the vector corresponding to the Nth derivative. 264 //! Note: the parameter U can be outside the bounds of the curve. 265 //! Exceptions Standard_RangeError if N is less than 1. 266 Standard_EXPORT gp_Vec DN (const Standard_Real U, const Standard_Integer N) const Standard_OVERRIDE; 267 268 //! Returns Value (U=0.), it is the first control point of the curve. 269 Standard_EXPORT gp_Pnt StartPoint() const Standard_OVERRIDE; 270 271 //! Returns Value (U=1.), it is the last control point of the Bezier curve. 272 Standard_EXPORT gp_Pnt EndPoint() const Standard_OVERRIDE; 273 274 //! Returns the value of the first parameter of this 275 //! Bezier curve. This is 0.0, which gives the start point of this Bezier curve 276 Standard_EXPORT Standard_Real FirstParameter() const Standard_OVERRIDE; 277 278 //! Returns the value of the last parameter of this 279 //! Bezier curve. This is 1.0, which gives the end point of this Bezier curve. 280 Standard_EXPORT Standard_Real LastParameter() const Standard_OVERRIDE; 281 282 //! Returns the number of poles of this Bezier curve. 283 Standard_EXPORT Standard_Integer NbPoles() const; 284 285 //! Returns the pole of range Index. 286 //! Raised if Index is not in the range [1, NbPoles] 287 Standard_EXPORT const gp_Pnt& Pole (const Standard_Integer Index) const; 288 289 //! Returns all the poles of the curve. 290 //! 291 //! Raised if the length of P is not equal to the number of poles. 292 Standard_EXPORT void Poles (TColgp_Array1OfPnt& P) const; 293 294 //! Returns all the poles of the curve. 295 Standard_EXPORT const TColgp_Array1OfPnt& Poles () const; 296 297 //! Returns the weight of range Index. 298 //! Raised if Index is not in the range [1, NbPoles] 299 Standard_EXPORT Standard_Real Weight (const Standard_Integer Index) const; 300 301 //! Returns all the weights of the curve. 302 //! 303 //! Raised if the length of W is not equal to the number of poles. 304 Standard_EXPORT void Weights (TColStd_Array1OfReal& W) const; 305 306 //! Returns all the weights of the curve. Weights() const307 const TColStd_Array1OfReal* Weights() const 308 { 309 if (!weights.IsNull()) 310 return &weights->Array1(); 311 return BSplCLib::NoWeights(); 312 } 313 314 //! Applies the transformation T to this Bezier curve. 315 Standard_EXPORT void Transform (const gp_Trsf& T) Standard_OVERRIDE; 316 317 318 //! Returns the value of the maximum polynomial degree 319 //! of any Geom_BezierCurve curve. This value is 25. 320 Standard_EXPORT static Standard_Integer MaxDegree(); 321 322 //! Computes for this Bezier curve the parametric 323 //! tolerance UTolerance for a given 3D tolerance Tolerance3D. 324 //! If f(t) is the equation of this Bezier curve, 325 //! UTolerance ensures that: 326 //! |t1-t0| < UTolerance ===> |f(t1)-f(t0)| < Tolerance3D 327 Standard_EXPORT void Resolution (const Standard_Real Tolerance3D, Standard_Real& UTolerance); 328 329 //! Creates a new object which is a copy of this Bezier curve. 330 Standard_EXPORT Handle(Geom_Geometry) Copy() const Standard_OVERRIDE; 331 332 //! Dumps the content of me into the stream 333 Standard_EXPORT virtual void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const Standard_OVERRIDE; 334 335 336 337 338 DEFINE_STANDARD_RTTIEXT(Geom_BezierCurve,Geom_BoundedCurve) 339 340 protected: 341 342 343 344 345 private: 346 347 348 //! Set poles to Poles, weights to Weights (not 349 //! copied). If Weights is null the curve is non 350 //! rational. Create the arrays of coefficients. Poles 351 //! and Weights are assumed to have the first 352 //! coefficient 1. 353 //! Update rational and closed. 354 //! 355 //! if nbpoles < 2 or nbboles > MaDegree + 1 356 void Init (const Handle(TColgp_HArray1OfPnt)& Poles, const Handle(TColStd_HArray1OfReal)& Weights); 357 358 Standard_Boolean rational; 359 Standard_Boolean closed; 360 Handle(TColgp_HArray1OfPnt) poles; 361 Handle(TColStd_HArray1OfReal) weights; 362 Standard_Real maxderivinv; 363 Standard_Boolean maxderivinvok; 364 365 366 }; 367 368 369 370 371 372 373 374 #endif // _Geom_BezierCurve_HeaderFile 375