0031668: Visualization - WebGL sample doesn't work on Emscripten 1.39
[occt.git] / src / GeomConvert / GeomConvert.hxx
CommitLineData
42cf5bc1 1// Created on: 1991-10-03
2// Created by: JeanClaude VAUTHIER
3// Copyright (c) 1991-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 _GeomConvert_HeaderFile
18#define _GeomConvert_HeaderFile
19
20#include <Standard.hxx>
21#include <Standard_DefineAlloc.hxx>
22#include <Standard_Handle.hxx>
23
24#include <Standard_Integer.hxx>
25#include <Standard_Boolean.hxx>
26#include <Standard_Real.hxx>
27#include <Convert_ParameterisationType.hxx>
28#include <TColGeom_Array1OfBSplineCurve.hxx>
29#include <TColStd_Array1OfReal.hxx>
30#include <TColGeom_HArray1OfBSplineCurve.hxx>
31#include <TColStd_HArray1OfInteger.hxx>
32class Geom_BSplineCurve;
33class Geom_BSplineSurface;
34class Geom_Curve;
35class Geom_Surface;
36class GeomConvert_BSplineCurveKnotSplitting;
37class GeomConvert_BSplineSurfaceKnotSplitting;
38class GeomConvert_BSplineCurveToBezierCurve;
39class GeomConvert_CompCurveToBSplineCurve;
40class GeomConvert_BSplineSurfaceToBezierSurface;
41class GeomConvert_CompBezierSurfacesToBSplineSurface;
42class GeomConvert_ApproxSurface;
43class GeomConvert_ApproxCurve;
44
45
46//! The GeomConvert package provides some global functions as follows
47//! - converting classical Geom curves into BSpline curves,
48//! - segmenting BSpline curves, particularly at knots
49//! values: this function may be used in conjunction with the
50//! GeomConvert_BSplineCurveKnotSplitting
51//! class to segment a BSpline curve into arcs which
52//! comply with required continuity levels,
53//! - converting classical Geom surfaces into BSpline surfaces, and
54//! - segmenting BSpline surfaces, particularly at
55//! knots values: this function may be used in conjunction with the
56//! GeomConvert_BSplineSurfaceKnotSplitting
57//! class to segment a BSpline surface into patches
58//! which comply with required continuity levels.
59//! All geometric entities used in this package are bounded.
60//!
61//! References :
62//! . Generating the Bezier Points of B-spline curves and surfaces
63//! (Wolfgang Bohm) CAGD volume 13 number 6 november 1981
64//! . On NURBS: A Survey (Leslie Piegl) IEEE Computer Graphics and
65//! Application January 1991
66//! . Curve and surface construction using rational B-splines
67//! (Leslie Piegl and Wayne Tiller) CAD Volume 19 number 9 november
68//! 1987
69//! . A survey of curve and surface methods in CAGD (Wolfgang BOHM)
70//! CAGD 1 1984
71class GeomConvert
72{
73public:
74
75 DEFINE_STANDARD_ALLOC
76
77
78 //! Convert a curve from Geom by an approximation method
79 //!
80 //! This method computes the arc of B-spline curve between the two
81 //! knots FromK1 and ToK2. If C is periodic the arc has the same
82 //! orientation as C if SameOrientation = Standard_True.
83 //! If C is not periodic SameOrientation is not used for the
84 //! computation and C is oriented from the knot fromK1 to the knot toK2.
85 //! We just keep the local definition of C between the knots
86 //! FromK1 and ToK2. The returned B-spline curve has its first
87 //! and last knots with a multiplicity equal to degree + 1, where
88 //! degree is the polynomial degree of C.
89 //! The indexes of the knots FromK1 and ToK2 doesn't include the
90 //! repetition of multiple knots in their definition.
91 //! Raised if FromK1 = ToK2
92 //! Raised if FromK1 or ToK2 are out of the bounds
93 //! [FirstUKnotIndex, LastUKnotIndex]
4a361058 94 Standard_EXPORT static Handle(Geom_BSplineCurve) SplitBSplineCurve (const Handle(Geom_BSplineCurve)& C,
95 const Standard_Integer FromK1,
96 const Standard_Integer ToK2,
97 const Standard_Boolean SameOrientation = Standard_True);
42cf5bc1 98
99
100 //! This function computes the segment of B-spline curve between the
101 //! parametric values FromU1, ToU2.
102 //! If C is periodic the arc has the same orientation as C if
103 //! SameOrientation = True.
104 //! If C is not periodic SameOrientation is not used for the
105 //! computation and C is oriented fromU1 toU2.
106 //! If U1 and U2 and two parametric values we consider that
107 //! U1 = U2 if Abs (U1 - U2) <= ParametricTolerance and
108 //! ParametricTolerance must be greater or equal to Resolution
109 //! from package gp.
110 //!
111 //! Raised if FromU1 or ToU2 are out of the parametric bounds of the
112 //! curve (The tolerance criterion is ParametricTolerance).
113 //! Raised if Abs (FromU1 - ToU2) <= ParametricTolerance
114 //! Raised if ParametricTolerance < Resolution from gp.
4a361058 115 Standard_EXPORT static Handle(Geom_BSplineCurve) SplitBSplineCurve (const Handle(Geom_BSplineCurve)& C,
116 const Standard_Real FromU1,
117 const Standard_Real ToU2,
118 const Standard_Real ParametricTolerance,
119 const Standard_Boolean SameOrientation = Standard_True);
42cf5bc1 120
121
122 //! Computes the B-spline surface patche between the knots values
123 //! FromUK1, ToUK2, FromVK1, ToVK2.
124 //! If S is periodic in one direction the patche has the same
125 //! orientation as S in this direction if the flag is true in this
126 //! direction (SameUOrientation, SameVOrientation).
127 //! If S is not periodic SameUOrientation and SameVOrientation are not
128 //! used for the computation and S is oriented FromUK1 ToUK2 and
129 //! FromVK1 ToVK2.
130 //! Raised if
131 //! FromUK1 = ToUK2 or FromVK1 = ToVK2
132 //! FromUK1 or ToUK2 are out of the bounds
133 //! [FirstUKnotIndex, LastUKnotIndex]
134 //! FromVK1 or ToVK2 are out of the bounds
135 //! [FirstVKnotIndex, LastVKnotIndex]
4a361058 136 Standard_EXPORT static Handle(Geom_BSplineSurface) SplitBSplineSurface (const Handle(Geom_BSplineSurface)& S,
137 const Standard_Integer FromUK1,
138 const Standard_Integer ToUK2,
139 const Standard_Integer FromVK1,
140 const Standard_Integer ToVK2,
141 const Standard_Boolean SameUOrientation = Standard_True,
142 const Standard_Boolean SameVOrientation = Standard_True);
42cf5bc1 143
144
145 //! This method splits a B-spline surface patche between the
146 //! knots values FromK1, ToK2 in one direction.
147 //! If USplit = True then the splitting direction is the U parametric
148 //! direction else it is the V parametric direction.
149 //! If S is periodic in the considered direction the patche has the
150 //! same orientation as S in this direction if SameOrientation is True
151 //! If S is not periodic in this direction SameOrientation is not used
152 //! for the computation and S is oriented FromK1 ToK2.
153 //! Raised if FromK1 = ToK2 or if
154 //! FromK1 or ToK2 are out of the bounds
155 //! [FirstUKnotIndex, LastUKnotIndex] in the
156 //! considered parametric direction.
4a361058 157 Standard_EXPORT static Handle(Geom_BSplineSurface) SplitBSplineSurface (const Handle(Geom_BSplineSurface)& S,
158 const Standard_Integer FromK1,
159 const Standard_Integer ToK2,
160 const Standard_Boolean USplit,
161 const Standard_Boolean SameOrientation = Standard_True);
42cf5bc1 162
163
164 //! This method computes the B-spline surface patche between the
165 //! parametric values FromU1, ToU2, FromV1, ToV2.
166 //! If S is periodic in one direction the patche has the same
167 //! orientation as S in this direction if the flag is True in this
168 //! direction (SameUOrientation, SameVOrientation).
169 //! If S is not periodic SameUOrientation and SameVOrientation are not
170 //! used for the computation and S is oriented FromU1 ToU2 and
171 //! FromV1 ToV2.
172 //! If U1 and U2 and two parametric values we consider that U1 = U2 if
173 //! Abs (U1 - U2) <= ParametricTolerance and ParametricTolerance must
174 //! be greater or equal to Resolution from package gp.
175 //!
176 //! Raised if FromU1 or ToU2 or FromV1 or ToU2 are out of the
177 //! parametric bounds of the surface (the tolerance criterion is
178 //! ParametricTolerance).
179 //! Raised if Abs (FromU1 - ToU2) <= ParametricTolerance or
180 //! Abs (FromV1 - ToV2) <= ParametricTolerance.
181 //! Raised if ParametricTolerance < Resolution.
4a361058 182 Standard_EXPORT static Handle(Geom_BSplineSurface) SplitBSplineSurface (const Handle(Geom_BSplineSurface)& S,
183 const Standard_Real FromU1,
184 const Standard_Real ToU2,
185 const Standard_Real FromV1,
186 const Standard_Real ToV2,
187 const Standard_Real ParametricTolerance,
188 const Standard_Boolean SameUOrientation = Standard_True,
189 const Standard_Boolean SameVOrientation = Standard_True);
42cf5bc1 190
191
192 //! This method splits the B-spline surface S in one direction
193 //! between the parametric values FromParam1, ToParam2.
194 //! If USplit = True then the Splitting direction is the U parametric
195 //! direction else it is the V parametric direction.
196 //! If S is periodic in the considered direction the patche has
197 //! the same orientation as S in this direction if SameOrientation
198 //! is true.
199 //! If S is not periodic in the considered direction SameOrientation
200 //! is not used for the computation and S is oriented FromParam1
201 //! ToParam2.
202 //! If U1 and U2 and two parametric values we consider that U1 = U2
203 //! if Abs (U1 - U2) <= ParametricTolerance and ParametricTolerance
204 //! must be greater or equal to Resolution from package gp.
205 //!
206 //! Raises if FromParam1 or ToParam2 are out of the parametric bounds
207 //! of the surface in the considered direction.
208 //! Raises if Abs (FromParam1 - ToParam2) <= ParametricTolerance.
4a361058 209 Standard_EXPORT static Handle(Geom_BSplineSurface) SplitBSplineSurface (const Handle(Geom_BSplineSurface)& S,
210 const Standard_Real FromParam1,
211 const Standard_Real ToParam2,
212 const Standard_Boolean USplit,
213 const Standard_Real ParametricTolerance,
214 const Standard_Boolean SameOrientation = Standard_True);
42cf5bc1 215
216 //! This function converts a non infinite curve from
217 //! Geom into a B-spline curve. C must be an ellipse or a
218 //! circle or a trimmed conic or a trimmed line or a Bezier
219 //! curve or a trimmed Bezier curve or a BSpline curve or a
220 //! trimmed BSpline curve or an OffsetCurve. The returned B-spline is
221 //! not periodic except if C is a Circle or an Ellipse. If
222 //! the Parameterisation is QuasiAngular than the returned
223 //! curve is NOT periodic in case a periodic Geom_Circle or
224 //! Geom_Ellipse. For TgtThetaOver2_1 and TgtThetaOver2_2 the
225 //! method raises an exception in case of a periodic
226 //! Geom_Circle or a Geom_Ellipse ParameterisationType applies
227 //! only if the curve is a Circle or an ellipse :
228 //! TgtThetaOver2, -- TgtThetaOver2_1, -- TgtThetaOver2_2, --
229 //! TgtThetaOver2_3, -- TgtThetaOver2_4,
230 //!
231 //! Purpose: this is the classical rational parameterisation
232 //! 2
233 //! 1 - t
234 //! cos(theta) = ------
235 //! 2
236 //! 1 + t
237 //!
238 //! 2t
239 //! sin(theta) = ------
240 //! 2
241 //! 1 + t
242 //!
243 //! t = tan (theta/2)
244 //!
245 //! with TgtThetaOver2 the routine will compute the number of spans
246 //! using the rule num_spans = [ (ULast - UFirst) / 1.2 ] + 1
247 //! with TgtThetaOver2_N, N spans will be forced: an error will
248 //! be raized if (ULast - UFirst) >= PI and N = 1,
249 //! ULast - UFirst >= 2 PI and N = 2
250 //!
251 //! QuasiAngular,
252 //! here t is a rational function that approximates
253 //! theta ----> tan(theta/2).
254 //! Neverthless the composing with above function yields exact
255 //! functions whose square sum up to 1
256 //! RationalC1 ;
257 //! t is replaced by a polynomial function of u so as to grant
258 //! C1 contiuity across knots.
259 //! Exceptions
260 //! Standard_DomainError:
261 //! - if the curve C is infinite, or
262 //! - if C is a (complete) circle or ellipse, and Parameterisation is equal to
263 //! Convert_TgtThetaOver2_1 or Convert_TgtThetaOver2_2.
264 //! Standard_ConstructionError:
265 //! - if C is a (complete) circle or ellipse, and if Parameterisation is not equal to
266 //! Convert_TgtThetaOver2, Convert_RationalC1,
267 //! Convert_QuasiAngular (the curve is converted
268 //! in these three cases) or to Convert_TgtThetaOver2_1 or
269 //! Convert_TgtThetaOver2_2 (another exception is raised in these two cases).
270 //! - if C is a trimmed circle or ellipse, if Parameterisation is equal to
271 //! Convert_TgtThetaOver2_1 and if U2 - U1 > 0.9999 * Pi, where U1 and U2 are
272 //! respectively the first and the last parameters of the
273 //! trimmed curve (this method of parameterization
274 //! cannot be used to convert a half-circle or a half-ellipse, for example), or
275 //! - if C is a trimmed circle or ellipse, if
276 //! Parameterisation is equal to Convert_TgtThetaOver2_2 and U2 - U1 >
277 //! 1.9999 * Pi where U1 and U2 are
278 //! respectively the first and the last parameters of the
279 //! trimmed curve (this method of parameterization
280 //! cannot be used to convert a quasi-complete circle or ellipse).
4a361058 281 Standard_EXPORT static Handle(Geom_BSplineCurve) CurveToBSplineCurve (const Handle(Geom_Curve)& C,
282 const Convert_ParameterisationType Parameterisation = Convert_TgtThetaOver2);
42cf5bc1 283
284
285 //! This algorithm converts a non infinite surface from Geom
286 //! into a B-spline surface.
287 //! S must be a trimmed plane or a trimmed cylinder or a trimmed cone
288 //! or a trimmed sphere or a trimmed torus or a sphere or a torus or
289 //! a Bezier surface of a trimmed Bezier surface or a trimmed swept
290 //! surface with a corresponding basis curve which can be turned into
291 //! a B-spline curve (see the method CurveToBSplineCurve).
292 //! Raises DomainError if the type of the surface is not previously defined.
293 Standard_EXPORT static Handle(Geom_BSplineSurface) SurfaceToBSplineSurface (const Handle(Geom_Surface)& S);
294
295 //! This Method concatenates G1 the ArrayOfCurves as far
296 //! as it is possible.
297 //! ArrayOfCurves[0..N-1]
298 //! ArrayOfToler contains the biggest tolerance of the two
299 //! points shared by two consecutives curves.
300 //! Its dimension: [0..N-2]
4a361058 301 //! ClosedFlag indicates if the ArrayOfCurves is closed.
302 //! In this case ClosedTolerance contains the biggest tolerance
42cf5bc1 303 //! of the two points which are at the closure.
304 //! Otherwise its value is 0.0
4a361058 305 //! ClosedFlag becomes False on the output
306 //! if it is impossible to build closed curve.
307 Standard_EXPORT static void ConcatG1 (TColGeom_Array1OfBSplineCurve& ArrayOfCurves,
308 const TColStd_Array1OfReal& ArrayOfToler,
309 Handle(TColGeom_HArray1OfBSplineCurve)& ArrayOfConcatenated,
310 Standard_Boolean& ClosedFlag,
311 const Standard_Real ClosedTolerance);
42cf5bc1 312
313 //! This Method concatenates C1 the ArrayOfCurves as far
314 //! as it is possible.
315 //! ArrayOfCurves[0..N-1]
316 //! ArrayOfToler contains the biggest tolerance of the two
317 //! points shared by two consecutives curves.
318 //! Its dimension: [0..N-2]
4a361058 319 //! ClosedFlag indicates if the ArrayOfCurves is closed.
320 //! In this case ClosedTolerance contains the biggest tolerance
42cf5bc1 321 //! of the two points which are at the closure.
322 //! Otherwise its value is 0.0
4a361058 323 //! ClosedFlag becomes False on the output
324 //! if it is impossible to build closed curve.
325 Standard_EXPORT static void ConcatC1 (TColGeom_Array1OfBSplineCurve& ArrayOfCurves,
326 const TColStd_Array1OfReal& ArrayOfToler,
327 Handle(TColStd_HArray1OfInteger)& ArrayOfIndices,
328 Handle(TColGeom_HArray1OfBSplineCurve)& ArrayOfConcatenated,
329 Standard_Boolean& ClosedFlag,
330 const Standard_Real ClosedTolerance);
42cf5bc1 331
332 //! This Method concatenates C1 the ArrayOfCurves as far
333 //! as it is possible.
334 //! ArrayOfCurves[0..N-1]
335 //! ArrayOfToler contains the biggest tolerance of the two
336 //! points shared by two consecutives curves.
337 //! Its dimension: [0..N-2]
4a361058 338 //! ClosedFlag indicates if the ArrayOfCurves is closed.
339 //! In this case ClosedTolerance contains the biggest tolerance
42cf5bc1 340 //! of the two points which are at the closure.
341 //! Otherwise its value is 0.0
4a361058 342 //! ClosedFlag becomes False on the output
343 //! if it is impossible to build closed curve.
344 Standard_EXPORT static void ConcatC1 (TColGeom_Array1OfBSplineCurve& ArrayOfCurves,
345 const TColStd_Array1OfReal& ArrayOfToler,
346 Handle(TColStd_HArray1OfInteger)& ArrayOfIndices,
347 Handle(TColGeom_HArray1OfBSplineCurve)& ArrayOfConcatenated,
348 Standard_Boolean& ClosedFlag,
349 const Standard_Real ClosedTolerance,
350 const Standard_Real AngularTolerance);
42cf5bc1 351
352 //! This Method reduces as far as it is possible the
353 //! multiplicities of the knots of the BSpline BS.(keeping the
354 //! geometry). It returns a new BSpline which could still be C0.
355 //! tolerance is a geometrical tolerance.
356 //! The Angular toleranceis in radians and mesures the angle of
357 //! the tangents on the left and on the right to decide if the
358 //! curve is G1 or not at a given point
4a361058 359 Standard_EXPORT static void C0BSplineToC1BSplineCurve (Handle(Geom_BSplineCurve)& BS,
360 const Standard_Real tolerance,
361 const Standard_Real AngularTolerance = 1.0e-7);
42cf5bc1 362
363 //! This Method reduces as far as it is possible the
364 //! multiplicities of the knots of the BSpline BS.(keeping the geometry).
365 //! It returns an array of BSpline C1. tolerance is a geometrical tolerance.
4a361058 366 Standard_EXPORT static void C0BSplineToArrayOfC1BSplineCurve (const Handle(Geom_BSplineCurve)& BS,
367 Handle(TColGeom_HArray1OfBSplineCurve)& tabBS,
368 const Standard_Real tolerance);
42cf5bc1 369
370 //! This Method reduces as far as it is possible the
371 //! multiplicities of the knots of the BSpline BS.(keeping the
372 //! geometry). It returns an array of BSpline C1. tolerance is a
373 //! geometrical tolerance : it allows for the maximum deformation
374 //! The Angular tolerance is in radians and mesures the angle of
375 //! the tangents on the left and on the right to decide if the curve
376 //! is C1 or not at a given point
4a361058 377 Standard_EXPORT static void C0BSplineToArrayOfC1BSplineCurve (const Handle(Geom_BSplineCurve)& BS,
378 Handle(TColGeom_HArray1OfBSplineCurve)& tabBS,
379 const Standard_Real AngularTolerance,
380 const Standard_Real tolerance);
42cf5bc1 381
382
383
384
385protected:
386
387
388
389
390
391private:
392
393
394
395
396friend class GeomConvert_BSplineCurveKnotSplitting;
397friend class GeomConvert_BSplineSurfaceKnotSplitting;
398friend class GeomConvert_BSplineCurveToBezierCurve;
399friend class GeomConvert_CompCurveToBSplineCurve;
400friend class GeomConvert_BSplineSurfaceToBezierSurface;
401friend class GeomConvert_CompBezierSurfacesToBSplineSurface;
402friend class GeomConvert_ApproxSurface;
403friend class GeomConvert_ApproxCurve;
404
405};
406
407
408
409
410
411
412
413#endif // _GeomConvert_HeaderFile