42cf5bc1 |
1 | // Created on: 1996-05-14 |
2 | // Created by: Philippe MANGIN / Jeannine PANCIATICI |
3 | // Copyright (c) 1996-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 _AppDef_Variational_HeaderFile |
18 | #define _AppDef_Variational_HeaderFile |
19 | |
20 | #include <Standard.hxx> |
21 | #include <Standard_DefineAlloc.hxx> |
22 | #include <Standard_Handle.hxx> |
23 | |
24 | #include <AppDef_MultiLine.hxx> |
25 | #include <Standard_Integer.hxx> |
26 | #include <TColStd_HArray1OfReal.hxx> |
27 | #include <AppParCurves_HArray1OfConstraintCouple.hxx> |
28 | #include <TColStd_HArray1OfInteger.hxx> |
29 | #include <Standard_Real.hxx> |
30 | #include <GeomAbs_Shape.hxx> |
31 | #include <Standard_Boolean.hxx> |
32 | #include <AppParCurves_MultiBSpCurve.hxx> |
33 | #include <Standard_OStream.hxx> |
34 | #include <TColStd_Array1OfReal.hxx> |
35 | #include <math_Vector.hxx> |
36 | #include <AppParCurves_Constraint.hxx> |
37 | class AppDef_SmoothCriterion; |
38 | class Standard_OutOfRange; |
39 | class Standard_DimensionError; |
40 | class Standard_DomainError; |
41 | class Standard_ConstructionError; |
42 | class StdFail_NotDone; |
43 | class gp_VectorWithNullMagnitude; |
44 | class AppDef_MultiLine; |
45 | class AppParCurves_MultiBSpCurve; |
46 | class math_Matrix; |
47 | class FEmTool_Curve; |
48 | class FEmTool_Assembly; |
49 | class PLib_Base; |
50 | |
51 | |
52 | //! This class is used to smooth N points with constraints |
53 | //! by minimization of quadratic criterium but also |
54 | //! variational criterium in order to obtain " fair Curve " |
55 | //! Computes the approximation of a Multiline by |
56 | //! Variational optimization. |
57 | class AppDef_Variational |
58 | { |
59 | public: |
60 | |
61 | DEFINE_STANDARD_ALLOC |
62 | |
63 | |
64 | //! Constructor. |
65 | //! Initialization of the fields. |
66 | //! warning : Nc0 : number of PassagePoint consraints |
67 | //! Nc2 : number of TangencyPoint constraints |
68 | //! Nc3 : number of CurvaturePoint constraints |
69 | //! if |
70 | //! ((MaxDegree-Continuity)*MaxSegment -Nc0 - 2*Nc1 |
71 | //! -3*Nc2) |
72 | //! is negative |
73 | //! The problem is over-constrained. |
74 | //! |
75 | //! Limitation : The MultiLine from AppDef has to be composed by |
76 | //! only one Line ( Dimension 2 or 3). |
77 | Standard_EXPORT AppDef_Variational(const AppDef_MultiLine& SSP, const Standard_Integer FirstPoint, const Standard_Integer LastPoint, const Handle(AppParCurves_HArray1OfConstraintCouple)& TheConstraints, const Standard_Integer MaxDegree = 14, const Standard_Integer MaxSegment = 100, const GeomAbs_Shape Continuity = GeomAbs_C2, const Standard_Boolean WithMinMax = Standard_False, const Standard_Boolean WithCutting = Standard_True, const Standard_Real Tolerance = 1.0, const Standard_Integer NbIterations = 2); |
78 | |
79 | //! Makes the approximation with the current fields. |
80 | Standard_EXPORT void Approximate(); |
81 | |
82 | //! returns True if the creation is done |
83 | //! and correspond to the current fields. |
84 | Standard_EXPORT Standard_Boolean IsCreated() const; |
85 | |
86 | //! returns True if the approximation is ok |
87 | //! and correspond to the current fields. |
88 | Standard_EXPORT Standard_Boolean IsDone() const; |
89 | |
90 | //! returns True if the problem is overconstrained |
91 | //! in this case, approximation cannot be done. |
92 | Standard_EXPORT Standard_Boolean IsOverConstrained() const; |
93 | |
94 | //! returns all the BSpline curves approximating the |
95 | //! MultiLine from AppDef SSP after minimization of the parameter. |
96 | Standard_EXPORT AppParCurves_MultiBSpCurve Value() const; |
97 | |
98 | //! returns the maximum of the distances between |
99 | //! the points of the multiline and the approximation |
100 | //! curves. |
101 | Standard_EXPORT Standard_Real MaxError() const; |
102 | |
103 | //! returns the index of the MultiPoint of ErrorMax |
104 | Standard_EXPORT Standard_Integer MaxErrorIndex() const; |
105 | |
106 | //! returns the quadratic average of the distances between |
107 | //! the points of the multiline and the approximation |
108 | //! curves. |
109 | Standard_EXPORT Standard_Real QuadraticError() const; |
110 | |
111 | //! returns the distances between the points of the |
112 | //! multiline and the approximation curves. |
113 | Standard_EXPORT void Distance (math_Matrix& mat); |
114 | |
115 | //! returns the average error between |
116 | //! the MultiLine from AppDef and the approximation. |
117 | Standard_EXPORT Standard_Real AverageError() const; |
118 | |
119 | //! returns the parameters uses to the approximations |
120 | Standard_EXPORT const Handle(TColStd_HArray1OfReal)& Parameters() const; |
121 | |
122 | //! returns the knots uses to the approximations |
123 | Standard_EXPORT const Handle(TColStd_HArray1OfReal)& Knots() const; |
124 | |
125 | //! returns the values of the quality criterium. |
126 | Standard_EXPORT void Criterium (Standard_Real& VFirstOrder, Standard_Real& VSecondOrder, Standard_Real& VThirdOrder) const; |
127 | |
128 | //! returns the Weights (as percent) associed to the criterium used in |
129 | //! the optimization. |
130 | Standard_EXPORT void CriteriumWeight (Standard_Real& Percent1, Standard_Real& Percent2, Standard_Real& Percent3) const; |
131 | |
132 | //! returns the Maximum Degree used in the approximation |
133 | Standard_EXPORT Standard_Integer MaxDegree() const; |
134 | |
135 | //! returns the Maximum of segment used in the approximation |
136 | Standard_EXPORT Standard_Integer MaxSegment() const; |
137 | |
138 | //! returns the Continuity used in the approximation |
139 | Standard_EXPORT GeomAbs_Shape Continuity() const; |
140 | |
141 | //! returns if the approximation search to minimize the |
142 | //! maximum Error or not. |
143 | Standard_EXPORT Standard_Boolean WithMinMax() const; |
144 | |
145 | //! returns if the approximation can insert new Knots or not. |
146 | Standard_EXPORT Standard_Boolean WithCutting() const; |
147 | |
148 | //! returns the tolerance used in the approximation. |
149 | Standard_EXPORT Standard_Real Tolerance() const; |
150 | |
151 | //! returns the number of iterations used in the approximation. |
152 | Standard_EXPORT Standard_Integer NbIterations() const; |
153 | |
154 | //! Prints on the stream o information on the current state |
155 | //! of the object. |
156 | //! MaxError,MaxErrorIndex,AverageError,QuadraticError,Criterium |
157 | //! Distances,Degre,Nombre de poles, parametres, noeuds |
158 | Standard_EXPORT void Dump (Standard_OStream& o) const; |
159 | |
160 | //! Define the constraints to approximate |
161 | //! If this value is incompatible with the others fields |
162 | //! this method modify nothing and returns false |
163 | Standard_EXPORT Standard_Boolean SetConstraints (const Handle(AppParCurves_HArray1OfConstraintCouple)& aConstrainst); |
164 | |
165 | //! Defines the parameters used by the approximations. |
166 | Standard_EXPORT void SetParameters (const Handle(TColStd_HArray1OfReal)& param); |
167 | |
168 | //! Defines the knots used by the approximations |
169 | //! If this value is incompatible with the others fields |
170 | //! this method modify nothing and returns false |
171 | Standard_EXPORT Standard_Boolean SetKnots (const Handle(TColStd_HArray1OfReal)& knots); |
172 | |
173 | //! Define the Maximum Degree used in the approximation |
174 | //! If this value is incompatible with the others fields |
175 | //! this method modify nothing and returns false |
176 | Standard_EXPORT Standard_Boolean SetMaxDegree (const Standard_Integer Degree); |
177 | |
178 | //! Define the maximum number of segments used in the approximation |
179 | //! If this value is incompatible with the others fields |
180 | //! this method modify nothing and returns false |
181 | Standard_EXPORT Standard_Boolean SetMaxSegment (const Standard_Integer NbSegment); |
182 | |
183 | //! Define the Continuity used in the approximation |
184 | //! If this value is incompatible with the others fields |
185 | //! this method modify nothing and returns false |
186 | Standard_EXPORT Standard_Boolean SetContinuity (const GeomAbs_Shape C); |
187 | |
188 | //! Define if the approximation search to minimize the |
189 | //! maximum Error or not. |
190 | Standard_EXPORT void SetWithMinMax (const Standard_Boolean MinMax); |
191 | |
192 | //! Define if the approximation can insert new Knots or not. |
193 | //! If this value is incompatible with the others fields |
194 | //! this method modify nothing and returns false |
195 | Standard_EXPORT Standard_Boolean SetWithCutting (const Standard_Boolean Cutting); |
196 | |
197 | //! define the Weights (as percent) associed to the criterium used in |
198 | //! the optimization. |
199 | //! |
200 | //! if Percent <= 0 |
201 | Standard_EXPORT void SetCriteriumWeight (const Standard_Real Percent1, const Standard_Real Percent2, const Standard_Real Percent3); |
202 | |
203 | //! define the Weight (as percent) associed to the |
204 | //! criterium Order used in the optimization : Others |
205 | //! weights are updated. |
206 | //! if Percent < 0 |
207 | //! if Order < 1 or Order > 3 |
208 | Standard_EXPORT void SetCriteriumWeight (const Standard_Integer Order, const Standard_Real Percent); |
209 | |
210 | //! define the tolerance used in the approximation. |
211 | Standard_EXPORT void SetTolerance (const Standard_Real Tol); |
212 | |
213 | //! define the number of iterations used in the approximation. |
214 | //! if Iter < 1 |
215 | Standard_EXPORT void SetNbIterations (const Standard_Integer Iter); |
216 | |
217 | |
218 | |
219 | |
220 | protected: |
221 | |
222 | |
223 | |
224 | |
225 | |
226 | private: |
227 | |
228 | |
229 | Standard_EXPORT void TheMotor (Handle(AppDef_SmoothCriterion)& J, const Standard_Real WQuadratic, const Standard_Real WQuality, Handle(FEmTool_Curve)& TheCurve, TColStd_Array1OfReal& Ecarts); |
230 | |
231 | Standard_EXPORT void Adjusting (Handle(AppDef_SmoothCriterion)& J, Standard_Real& WQuadratic, Standard_Real& WQuality, Handle(FEmTool_Curve)& TheCurve, TColStd_Array1OfReal& Ecarts); |
232 | |
233 | Standard_EXPORT void Optimization (Handle(AppDef_SmoothCriterion)& J, FEmTool_Assembly& A, const Standard_Boolean ToAssemble, const Standard_Real EpsDeg, Handle(FEmTool_Curve)& Curve, const TColStd_Array1OfReal& Parameters) const; |
234 | |
235 | Standard_EXPORT void Project (const Handle(FEmTool_Curve)& C, const TColStd_Array1OfReal& Ti, TColStd_Array1OfReal& ProjTi, TColStd_Array1OfReal& Distance, Standard_Integer& NumPoints, Standard_Real& MaxErr, Standard_Real& QuaErr, Standard_Real& AveErr, const Standard_Integer NbIterations = 2) const; |
236 | |
237 | Standard_EXPORT void ACR (Handle(FEmTool_Curve)& Curve, TColStd_Array1OfReal& Ti, const Standard_Integer Decima) const; |
238 | |
239 | Standard_EXPORT void SplitCurve (const Handle(FEmTool_Curve)& InCurve, const TColStd_Array1OfReal& Ti, const Standard_Real CurveTol, Handle(FEmTool_Curve)& OutCurve, Standard_Boolean& iscut) const; |
240 | |
241 | Standard_EXPORT void Init(); |
242 | |
243 | Standard_EXPORT void InitSmoothCriterion(); |
244 | |
245 | Standard_EXPORT void InitParameters (Standard_Real& Length); |
246 | |
247 | Standard_EXPORT void InitCriterionEstimations (const Standard_Real Length, Standard_Real& J1, Standard_Real& J2, Standard_Real& J3) const; |
248 | |
249 | Standard_EXPORT void EstTangent (const Standard_Integer ipnt, math_Vector& VTang) const; |
250 | |
251 | Standard_EXPORT void EstSecnd (const Standard_Integer ipnt, const math_Vector& VTang1, const math_Vector& VTang2, const Standard_Real Length, math_Vector& VScnd) const; |
252 | |
253 | Standard_EXPORT void InitCutting (const Handle(PLib_Base)& aBase, const Standard_Real CurvTol, Handle(FEmTool_Curve)& aCurve) const; |
254 | |
255 | Standard_EXPORT void AssemblingConstraints (const Handle(FEmTool_Curve)& Curve, const TColStd_Array1OfReal& Parameters, const Standard_Real CBLONG, FEmTool_Assembly& A) const; |
256 | |
257 | Standard_EXPORT Standard_Boolean InitTthetaF (const Standard_Integer ndimen, const AppParCurves_Constraint typcon, const Standard_Integer begin, const Standard_Integer jndex); |
258 | |
259 | |
260 | AppDef_MultiLine mySSP; |
261 | Standard_Integer myNbP3d; |
262 | Standard_Integer myNbP2d; |
263 | Standard_Integer myDimension; |
264 | Standard_Integer myFirstPoint; |
265 | Standard_Integer myLastPoint; |
266 | Standard_Integer myNbPoints; |
267 | Handle(TColStd_HArray1OfReal) myTabPoints; |
268 | Handle(AppParCurves_HArray1OfConstraintCouple) myConstraints; |
269 | Standard_Integer myNbConstraints; |
270 | Handle(TColStd_HArray1OfReal) myTabConstraints; |
271 | Standard_Integer myNbPassPoints; |
272 | Standard_Integer myNbTangPoints; |
273 | Standard_Integer myNbCurvPoints; |
274 | Handle(TColStd_HArray1OfInteger) myTypConstraints; |
275 | Handle(TColStd_HArray1OfReal) myTtheta; |
276 | Handle(TColStd_HArray1OfReal) myTfthet; |
277 | Standard_Integer myMaxDegree; |
278 | Standard_Integer myMaxSegment; |
279 | Standard_Integer myNbIterations; |
280 | Standard_Real myTolerance; |
281 | GeomAbs_Shape myContinuity; |
282 | Standard_Integer myNivCont; |
283 | Standard_Boolean myWithMinMax; |
284 | Standard_Boolean myWithCutting; |
285 | Standard_Real myPercent[3]; |
286 | Standard_Real myCriterium[4]; |
287 | Handle(AppDef_SmoothCriterion) mySmoothCriterion; |
288 | Handle(TColStd_HArray1OfReal) myParameters; |
289 | Handle(TColStd_HArray1OfReal) myKnots; |
290 | AppParCurves_MultiBSpCurve myMBSpCurve; |
291 | Standard_Real myMaxError; |
292 | Standard_Integer myMaxErrorIndex; |
293 | Standard_Real myAverageError; |
294 | Standard_Boolean myIsCreated; |
295 | Standard_Boolean myIsDone; |
296 | Standard_Boolean myIsOverConstr; |
297 | |
298 | |
299 | }; |
300 | |
301 | |
302 | |
303 | |
304 | |
305 | |
306 | |
307 | #endif // _AppDef_Variational_HeaderFile |