1 // Created on: 1993-10-20 2 // Created by: Bruno DUMORTIER 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 _Convert_CompBezierCurvesToBSplineCurve_HeaderFile 18 #define _Convert_CompBezierCurvesToBSplineCurve_HeaderFile 19 20 #include <Standard.hxx> 21 #include <Standard_DefineAlloc.hxx> 22 #include <Standard_Handle.hxx> 23 24 #include <Convert_SequenceOfArray1OfPoles.hxx> 25 #include <TColgp_SequenceOfPnt.hxx> 26 #include <TColStd_SequenceOfReal.hxx> 27 #include <TColStd_SequenceOfInteger.hxx> 28 #include <Standard_Integer.hxx> 29 #include <Standard_Real.hxx> 30 #include <Standard_Boolean.hxx> 31 #include <TColgp_Array1OfPnt.hxx> 32 #include <TColStd_Array1OfReal.hxx> 33 #include <TColStd_Array1OfInteger.hxx> 34 35 36 //! An algorithm to convert a sequence of adjacent 37 //! non-rational Bezier curves into a BSpline curve. 38 //! A CompBezierCurvesToBSplineCurve object provides a framework for: 39 //! - defining the sequence of adjacent non-rational Bezier 40 //! curves to be converted into a BSpline curve, 41 //! - implementing the computation algorithm, and 42 //! - consulting the results. 43 //! Warning 44 //! Do not attempt to convert rational Bezier curves using this type of algorithm. 45 class Convert_CompBezierCurvesToBSplineCurve 46 { 47 public: 48 49 DEFINE_STANDARD_ALLOC 50 51 52 //! Constructs a framework for converting a sequence of 53 //! adjacent non-rational Bezier curves into a BSpline curve. 54 //! Knots will be created on the computed BSpline curve at 55 //! each junction point of two consecutive Bezier curves. The 56 //! degree of continuity of the BSpline curve will be increased at 57 //! the junction point of two consecutive Bezier curves if their 58 //! tangent vectors at this point are parallel. AngularTolerance 59 //! (given in radians, and defaulted to 1.0 e-4) will be used 60 //! to check the parallelism of the two tangent vectors. 61 //! Use the following functions: 62 //! - AddCurve to define in sequence the adjacent Bezier 63 //! curves to be converted, 64 //! - Perform to compute the data needed to build the BSpline curve, 65 //! - and the available consultation functions to access the 66 //! computed data. This data may be used to construct the BSpline curve. 67 Standard_EXPORT Convert_CompBezierCurvesToBSplineCurve(const Standard_Real AngularTolerance = 1.0e-4); 68 69 //! Adds the Bezier curve defined by the table of poles Poles, to 70 //! the sequence (still contained in this framework) of adjacent 71 //! Bezier curves to be converted into a BSpline curve. 72 //! Only polynomial (i.e. non-rational) Bezier curves are 73 //! converted using this framework. 74 //! If this is not the first call to the function (i.e. if this framework 75 //! still contains data in its Bezier curve sequence), the degree 76 //! of continuity of the BSpline curve will be increased at the 77 //! time of computation at the first point of the added Bezier 78 //! curve (i.e. the first point of the Poles table). This will be the 79 //! case if the tangent vector of the curve at this point is 80 //! parallel to the tangent vector at the end point of the 81 //! preceding Bezier curve in the Bezier curve sequence still 82 //! contained in this framework. An angular tolerance given at 83 //! the time of construction of this framework will be used to 84 //! check the parallelism of the two tangent vectors. This 85 //! checking procedure and all related computations will be 86 //! performed by the Perform function. 87 //! When the adjacent Bezier curve sequence is complete, use 88 //! the following functions: 89 //! - Perform to compute the data needed to build the BSpline curve, 90 //! - and the available consultation functions to access the 91 //! computed data. This data may be used to construct the BSpline curve. 92 //! Warning 93 //! The Bezier curve sequence treated by this framework is 94 //! automatically initialized with the first Bezier curve when the 95 //! function is first called. During subsequent use of this function, 96 //! ensure that the first point of the added Bezier curve (i.e. the 97 //! first point of the Poles table) is coincident with the last point 98 //! of the Bezier curve sequence (i.e. the last point of the 99 //! preceding Bezier curve in the sequence) still contained in 100 //! this framework. An error may occur at the time of 101 //! computation if this condition is not satisfied. Particular care 102 //! must be taken with respect to the above, as this condition is 103 //! not checked either when defining the Bezier curve 104 //! sequence or at the time of computation. 105 Standard_EXPORT void AddCurve (const TColgp_Array1OfPnt& Poles); 106 107 //! Computes all the data needed to build a BSpline curve 108 //! equivalent to the adjacent Bezier curve sequence still 109 //! contained in this framework. 110 //! A knot is inserted on the computed BSpline curve at the 111 //! junction point of two consecutive Bezier curves. The 112 //! degree of continuity of the BSpline curve will be increased 113 //! at the junction point of two consecutive Bezier curves if 114 //! their tangent vectors at this point are parallel. An angular 115 //! tolerance given at the time of construction of this 116 //! framework is used to check the parallelism of the two 117 //! tangent vectors. 118 //! Use the available consultation functions to access the 119 //! computed data. This data may then be used to construct 120 //! the BSpline curve. 121 //! Warning 122 //! Make sure that the curves in the Bezier curve sequence 123 //! contained in this framework are adjacent. An error may 124 //! occur at the time of computation if this condition is not 125 //! satisfied. Particular care must be taken with respect to the 126 //! above as this condition is not checked, either when 127 //! defining the Bezier curve sequence or at the time of computation. 128 Standard_EXPORT void Perform(); 129 130 //! Returns the degree of the BSpline curve whose data is 131 //! computed in this framework. 132 //! Warning 133 //! Take particular care not to use this function before the 134 //! computation is performed (Perform function), as this 135 //! condition is not checked and an error may therefore occur. 136 Standard_EXPORT Standard_Integer Degree() const; 137 138 //! Returns the number of poles of the BSpline curve whose 139 //! data is computed in this framework. 140 //! Warning 141 //! Take particular care not to use this function before the 142 //! computation is performed (Perform function), as this 143 //! condition is not checked and an error may therefore occur. 144 Standard_EXPORT Standard_Integer NbPoles() const; 145 146 //! Loads the Poles table with the poles of the BSpline curve 147 //! whose data is computed in this framework. 148 //! Warning 149 //! - Do not use this function before the computation is 150 //! performed (Perform function). 151 //! - The length of the Poles array must be equal to the 152 //! number of poles of the BSpline curve whose data is 153 //! computed in this framework. 154 //! Particular care must be taken with respect to the above, as 155 //! these conditions are not checked, and an error may occur. 156 Standard_EXPORT void Poles (TColgp_Array1OfPnt& Poles) const; 157 158 //! Returns the number of knots of the BSpline curve whose 159 //! data is computed in this framework. 160 //! Warning 161 //! Take particular care not to use this function before the 162 //! computation is performed (Perform function), as this 163 //! condition is not checked and an error may therefore occur. 164 Standard_EXPORT Standard_Integer NbKnots() const; 165 166 167 //! - loads the Knots table with the knots, 168 //! - and loads the Mults table with the corresponding multiplicities 169 //! of the BSpline curve whose data is computed in this framework. 170 //! Warning 171 //! - Do not use this function before the computation is 172 //! performed (Perform function). 173 //! - The length of the Knots and Mults arrays must be equal 174 //! to the number of knots in the BSpline curve whose data is 175 //! computed in this framework. 176 //! Particular care must be taken with respect to the above as 177 //! these conditions are not checked, and an error may occur. 178 Standard_EXPORT void KnotsAndMults (TColStd_Array1OfReal& Knots, TColStd_Array1OfInteger& Mults) const; 179 180 181 182 183 protected: 184 185 186 187 188 189 private: 190 191 192 193 Convert_SequenceOfArray1OfPoles mySequence; 194 TColgp_SequenceOfPnt CurvePoles; 195 TColStd_SequenceOfReal CurveKnots; 196 TColStd_SequenceOfInteger KnotsMultiplicities; 197 Standard_Integer myDegree; 198 Standard_Real myAngular; 199 Standard_Boolean myDone; 200 201 202 }; 203 204 205 206 207 208 209 210 #endif // _Convert_CompBezierCurvesToBSplineCurve_HeaderFile 211