1 // Created on: 1991-02-27
2 // Created by: Jean Claude 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 _CPnts_UniformDeflection_HeaderFile
18 #define _CPnts_UniformDeflection_HeaderFile
19 
20 #include <Standard.hxx>
21 #include <Standard_DefineAlloc.hxx>
22 #include <Standard_Handle.hxx>
23 
24 #include <Standard_Boolean.hxx>
25 #include <Standard_Address.hxx>
26 #include <Standard_Real.hxx>
27 #include <Standard_Integer.hxx>
28 #include <gp_Pnt.hxx>
29 class Adaptor3d_Curve;
30 class Adaptor2d_Curve2d;
31 
32 
33 //! This class defines an algorithm to create a set of points
34 //! (with a given chordal deviation) at the
35 //! positions of constant deflection of a given parametrized curve or a trimmed
36 //! circle.
37 //! The continuity of the curve must be at least C2.
38 //!
39 //! the usage of the is the following.
40 //!
41 //! class myUniformDFeflection instantiates
42 //! UniformDeflection(Curve, Tool);
43 //!
44 //! Curve C; // Curve inherits from Curve or Curve2d from Adaptor2d
45 //! myUniformDeflection Iter1;
46 //! DefPntOfmyUniformDeflection P;
47 //!
48 //! for(Iter1.Initialize(C, Deflection, EPSILON, True);
49 //! Iter1.More();
50 //! Iter1.Next()) {
51 //! P = Iter1.Value();
52 //! ... make something with P
53 //! }
54 //! if(!Iter1.IsAllDone()) {
55 //! ... something wrong happened
56 //! }
57 class CPnts_UniformDeflection
58 {
59 public:
60 
61   DEFINE_STANDARD_ALLOC
62 
63 
64   //! creation of a indefinite UniformDeflection
65   Standard_EXPORT CPnts_UniformDeflection();
66 
67   //! Computes a uniform deflection distribution of points
68   //! on the curve <C>.
69   //! <Deflection> defines the constant deflection value.
70   //! The algorithm computes the number of points and the points.
71   //! The curve <C> must be at least C2 else the computation can fail.
72   //! If just some parts of the curve is C2 it is better to give the
73   //! parameters bounds and to use the below constructor .
74   //! if <WithControl> is True, the algorithm controls the estimate
75   //! deflection
76   //! when the curve is singular at the point P(u),the algorithm
77   //! computes the next point as
78   //! P(u + Max(CurrentStep,Abs(LastParameter-FirstParameter)))
79   //! if the singularity is at the first point ,the next point
80   //! calculated is the P(LastParameter)
81   Standard_EXPORT CPnts_UniformDeflection(const Adaptor3d_Curve& C, const Standard_Real Deflection, const Standard_Real Resolution, const Standard_Boolean WithControl);
82 
83   //! As above with 2d curve
84   Standard_EXPORT CPnts_UniformDeflection(const Adaptor2d_Curve2d& C, const Standard_Real Deflection, const Standard_Real Resolution, const Standard_Boolean WithControl);
85 
86 
87   //! Computes an uniform deflection distribution of points on a part of
88   //! the curve <C>. Deflection defines the step between the points.
89   //! <U1> and <U2> define the distribution span.
90   //! <U1> and <U2> must be in the parametric range of the curve.
91   Standard_EXPORT CPnts_UniformDeflection(const Adaptor3d_Curve& C, const Standard_Real Deflection, const Standard_Real U1, const Standard_Real U2, const Standard_Real Resolution, const Standard_Boolean WithControl);
92 
93   //! As above with 2d curve
94   Standard_EXPORT CPnts_UniformDeflection(const Adaptor2d_Curve2d& C, const Standard_Real Deflection, const Standard_Real U1, const Standard_Real U2, const Standard_Real Resolution, const Standard_Boolean WithControl);
95 
96   //! Initialize the algorithms with <C>, <Deflection>, <UStep>,
97   //! <Resolution> and <WithControl>
98   Standard_EXPORT void Initialize (const Adaptor3d_Curve& C, const Standard_Real Deflection, const Standard_Real Resolution, const Standard_Boolean WithControl);
99 
100   //! Initialize the algorithms with <C>, <Deflection>, <UStep>,
101   //! <Resolution> and <WithControl>
102   Standard_EXPORT void Initialize (const Adaptor2d_Curve2d& C, const Standard_Real Deflection, const Standard_Real Resolution, const Standard_Boolean WithControl);
103 
104   //! Initialize the algorithms with <C>, <Deflection>, <UStep>,
105   //! <U1>, <U2> and <WithControl>
106   Standard_EXPORT void Initialize (const Adaptor3d_Curve& C, const Standard_Real Deflection, const Standard_Real U1, const Standard_Real U2, const Standard_Real Resolution, const Standard_Boolean WithControl);
107 
108   //! Initialize the algorithms with <C>, <Deflection>, <UStep>,
109   //! <U1>, <U2> and <WithControl>
110   Standard_EXPORT void Initialize (const Adaptor2d_Curve2d& C, const Standard_Real Deflection, const Standard_Real U1, const Standard_Real U2, const Standard_Real Resolution, const Standard_Boolean WithControl);
111 
112   //! To know if all the calculus were done successfully
113   //! (ie all the points have been computed). The calculus can fail if
114   //! the Curve is not C1 in the considered domain.
115   //! Returns True if the calculus was successful.
116     Standard_Boolean IsAllDone() const;
117 
118   //! go to the next Point.
119     void Next();
120 
121   //! returns True if it exists a next Point.
122   Standard_EXPORT Standard_Boolean More();
123 
124   //! return the computed parameter
125     Standard_Real Value() const;
126 
127   //! return the computed parameter
128     gp_Pnt Point() const;
129 
130 
131 
132 
133 protected:
134 
135 
136 
137 
138 
139 private:
140 
141 
142   //! algorithm
143   Standard_EXPORT void Perform();
144 
145 
146   Standard_Boolean myDone;
147   Standard_Boolean my3d;
148   Standard_Address myCurve;
149   Standard_Boolean myFinish;
150   Standard_Real myTolCur;
151   Standard_Boolean myControl;
152   Standard_Integer myIPoint;
153   Standard_Integer myNbPoints;
154   Standard_Real myParams[3];
155   gp_Pnt myPoints[3];
156   Standard_Real myDwmax;
157   Standard_Real myDeflection;
158   Standard_Real myFirstParam;
159   Standard_Real myLastParam;
160   Standard_Real myDu;
161 
162 
163 };
164 
165 
166 #include <CPnts_UniformDeflection.lxx>
167 
168 
169 
170 
171 
172 #endif // _CPnts_UniformDeflection_HeaderFile
173