0027842: Exception in intersection algorithm if FPE is switched on
[occt.git] / src / IntWalk / IntWalk_PWalking.hxx
1 // Created on: 1992-04-03
2 // Created by: Isabelle GRIGNON
3 // Copyright (c) 1992-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 _IntWalk_PWalking_HeaderFile
18 #define _IntWalk_PWalking_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_Integer.hxx>
26 #include <gp_Dir.hxx>
27 #include <Standard_Real.hxx>
28 #include <IntImp_ConstIsoparametric.hxx>
29 #include <IntSurf_PntOn2S.hxx>
30 #include <gp_Dir2d.hxx>
31 #include <IntWalk_TheInt2S.hxx>
32 #include <TColStd_Array1OfReal.hxx>
33 #include <IntWalk_StatusDeflection.hxx>
34 class IntSurf_LineOn2S;
35 class Standard_OutOfRange;
36 class StdFail_NotDone;
37 class Adaptor3d_HSurface;
38 class IntSurf_PntOn2S;
39 class gp_Dir;
40 class gp_Pnt;
41
42
43 //! This class implements an algorithm to determine the
44 //! intersection between 2 parametrized surfaces, marching from
45 //! a starting point. The intersection line
46 //! starts and ends on the natural surface's  boundaries .
47 class IntWalk_PWalking 
48 {
49 public:
50
51   DEFINE_STANDARD_ALLOC
52
53   
54   //! Constructor used to set the data to compute intersection
55   //! lines between Caro1 and Caro2.
56   //! Deflection is the maximum deflection admitted between two
57   //! consecutive points on the resulting polyline.
58   //! TolTangency is the tolerance to find a tangent point.
59   //! Func is the criterion which has to be evaluated at each
60   //! solution point (each point of the line).
61   //! It is necessary to call the Perform method to compute
62   //! the intersection lines.
63   //! The line found starts at a point on or in 2 natural domains
64   //! of surfaces. It can be closed in the
65   //! standard case if it is open it stops and begins at the
66   //! border of one of the domains. If an open line
67   //! stops at the middle of a domain, one stops at the tangent point.
68   //! Epsilon is SquareTolerance of points confusion.
69   Standard_EXPORT IntWalk_PWalking(const Handle(Adaptor3d_HSurface)& Caro1, const Handle(Adaptor3d_HSurface)& Caro2, const Standard_Real TolTangency, const Standard_Real Epsilon, const Standard_Real Deflection, const Standard_Real Increment);
70   
71   //! Returns the intersection line containing the exact
72   //! point Poin. This line is a polygonal line.
73   //! Deflection is the maximum deflection admitted between two
74   //! consecutive points on the resulting polyline.
75   //! TolTangency is the tolerance to find a tangent point.
76   //! Func is the criterion which has to be evaluated at each
77   //! solution point (each point of the line).
78   //! The line found starts at a point on or in 2 natural domains
79   //! of surfaces. It can be closed in the
80   //! standard case if it is open it stops and begins at the
81   //! border of one of the domains. If an open line
82   //! stops at the middle of a domain, one stops at the tangent point.
83   //! Epsilon is SquareTolerance of points confusion.
84   Standard_EXPORT IntWalk_PWalking(const Handle(Adaptor3d_HSurface)& Caro1, const Handle(Adaptor3d_HSurface)& Caro2, const Standard_Real TolTangency, const Standard_Real Epsilon, const Standard_Real Deflection, const Standard_Real Increment, const Standard_Real U1, const Standard_Real V1, const Standard_Real U2, const Standard_Real V2);
85   
86   //! calculate the line of intersection
87   Standard_EXPORT void Perform (const TColStd_Array1OfReal& ParDep);
88   
89   //! calculate the line of intersection. The regulation
90   //! of steps is done using min and max values on u and
91   //! v.  (if this data is not presented as in the
92   //! previous method, the initial steps are calculated
93   //! starting from min and max uv of faces).
94   Standard_EXPORT void Perform (const TColStd_Array1OfReal& ParDep, const Standard_Real u1min, const Standard_Real v1min, const Standard_Real u2min, const Standard_Real v2min, const Standard_Real u1max, const Standard_Real v1max, const Standard_Real u2max, const Standard_Real v2max);
95   
96   //! calculate the first point of a line of intersection
97   Standard_EXPORT Standard_Boolean PerformFirstPoint (const TColStd_Array1OfReal& ParDep, IntSurf_PntOn2S& FirstPoint);
98   
99   //! Returns true if the calculus was successful.
100     Standard_Boolean IsDone() const;
101   
102   //! Returns the number of points of the resulting polyline.
103   //! An exception is raised if IsDone returns False.
104     Standard_Integer NbPoints() const;
105   
106   //! Returns the point of range Index on the polyline.
107   //! An exception is raised if IsDone returns False.
108   //! An exception is raised if Index<=0 or Index>NbPoints.
109     const IntSurf_PntOn2S& Value (const Standard_Integer Index) const;
110   
111     const Handle(IntSurf_LineOn2S)& Line() const;
112   
113   //! Returns True if the surface are tangent at the first point
114   //! of the line.
115   //! An exception is raised if IsDone returns False.
116     Standard_Boolean TangentAtFirst() const;
117   
118   //! Returns true if the surface are tangent at the last point
119   //! of the line.
120   //! An exception is raised if IsDone returns False.
121     Standard_Boolean TangentAtLast() const;
122   
123   //! Returns True if the line is closed.
124   //! An exception is raised if IsDone returns False.
125     Standard_Boolean IsClosed() const;
126   
127     const gp_Dir& TangentAtLine (Standard_Integer& Index) const;
128   
129   Standard_EXPORT   IntWalk_StatusDeflection TestDeflection (const IntImp_ConstIsoparametric ChoixIso) ;
130   
131   Standard_EXPORT Standard_Boolean TestArret (const Standard_Boolean DejaReparti, TColStd_Array1OfReal& Param, IntImp_ConstIsoparametric& ChoixIso);
132   
133   Standard_EXPORT void RepartirOuDiviser (Standard_Boolean& DejaReparti, IntImp_ConstIsoparametric& ChoixIso, Standard_Boolean& Arrive);
134   
135     void AddAPoint (Handle(IntSurf_LineOn2S)& line, const IntSurf_PntOn2S& POn2S);
136   
137   Standard_EXPORT Standard_Boolean PutToBoundary (const Handle(Adaptor3d_HSurface)& theASurf1, const Handle(Adaptor3d_HSurface)& theASurf2);
138   
139   Standard_EXPORT Standard_Boolean SeekAdditionalPoints (const Handle(Adaptor3d_HSurface)& theASurf1, const Handle(Adaptor3d_HSurface)& theASurf2, const Standard_Integer theMinNbPoints);
140
141   Standard_Real MaxStep(Standard_Integer theIndex)
142   {
143     Standard_OutOfRange_Raise_if((theIndex < 0) || (theIndex > 3), "");
144     return pasInit[theIndex];
145   }
146
147
148
149 protected:
150   Standard_EXPORT void ComputePasInit(const Standard_Real theDeltaU1,
151                                       const Standard_Real theDeltaV1,
152                                       const Standard_Real theDeltaU2,
153                                       const Standard_Real theDeltaV2);
154
155   //! Uses Gradient method in order to find intersection point between the given surfaces
156   //! Arrays theInit (initial point to be precise) and theStep0 (steps-array) must contain
157   //! four items and must be filled strictly in following order:
158   //! {U-parameter on S1, V-parameter on S1, U-parameter on S2, V-parameter on S2}
159   Standard_EXPORT Standard_Boolean DistanceMinimizeByGradient(const Handle(Adaptor3d_HSurface)& theASurf1,
160                                                               const Handle(Adaptor3d_HSurface)& theASurf2,
161                                                               TColStd_Array1OfReal& theInit,
162                                                               const Standard_Real* theStep0 = 0);
163   
164   //! Finds the point on theASurf which is the nearest point to theP0.
165   //! theU0 and theV0 must be initialized (before calling the method) by initial
166   //! parameters on theASurf. Their values are changed while algorithm being launched.
167   //! Array theStep0 (steps-array) must contain two items and must be filled strictly in following order:
168   //! {U-parameter, V-parameter}
169   Standard_EXPORT Standard_Boolean DistanceMinimizeByExtrema (const Handle(Adaptor3d_HSurface)& theASurf,
170                                                               const gp_Pnt& theP0,                                                              
171                                                               Standard_Real& theU0,
172                                                               Standard_Real& theV0,
173                                                               const Standard_Real* theStep0 = 0);
174   
175   //! Searches an intersection point which lies on the some surface boundary.
176   //! Found point (in case of successful result) is added in the line.
177   //! theU1, theV1, theU2 and theV2 parameters are initial parameters in
178   //! for used numeric algorithms. If isTheFirst == TRUE then
179   //! a point on theASurf1 is searched. Otherwise, the point on theASurf2 is searched.
180   Standard_EXPORT Standard_Boolean SeekPointOnBoundary (const Handle(Adaptor3d_HSurface)& theASurf1,
181                                                         const Handle(Adaptor3d_HSurface)& theASurf2,
182                                                         const Standard_Real theU1,
183                                                         const Standard_Real theV1,
184                                                         const Standard_Real theU2,
185                                                         const Standard_Real theV2,
186                                                         const Standard_Boolean isTheFirst);
187
188
189   // Method to handle single singular point. Sub-method in SeekPointOnBoundary.
190   Standard_EXPORT Standard_Boolean HandleSingleSingularPoint(const Handle(Adaptor3d_HSurface) &theASurf1,
191                                                              const Handle(Adaptor3d_HSurface) &theASurf2,
192                                                              const Standard_Real the3DTol,
193                                                              TColStd_Array1OfReal &thePnt);
194   
195   Standard_EXPORT Standard_Boolean ExtendLineInCommonZone (const IntImp_ConstIsoparametric theChoixIso,
196                                                            const Standard_Boolean theDirectionFlag);
197
198 private:
199   Standard_Boolean done;
200   Handle(IntSurf_LineOn2S) line;
201   Standard_Boolean close;
202   Standard_Boolean tgfirst;
203   Standard_Boolean tglast;
204   Standard_Integer indextg;
205   gp_Dir tgdir;
206   Standard_Real fleche;
207   Standard_Real pasMax;
208   Standard_Real tolconf;
209   Standard_Real myTolTang;
210   Standard_Real pasuv[4];
211   Standard_Real myStepMin[4];
212   Standard_Real pasSav[4];
213   Standard_Real pasInit[4];
214   Standard_Real Um1;
215   Standard_Real UM1;
216   Standard_Real Vm1;
217   Standard_Real VM1;
218   Standard_Real Um2;
219   Standard_Real UM2;
220   Standard_Real Vm2;
221   Standard_Real VM2;
222   Standard_Real ResoU1;
223   Standard_Real ResoU2;
224   Standard_Real ResoV1;
225   Standard_Real ResoV2;
226   Standard_Integer sensCheminement;
227   IntImp_ConstIsoparametric choixIsoSav;
228   IntSurf_PntOn2S previousPoint;
229   Standard_Boolean previoustg;
230   gp_Dir previousd;
231   gp_Dir2d previousd1;
232   gp_Dir2d previousd2;
233   gp_Dir2d firstd1;
234   gp_Dir2d firstd2;
235   IntWalk_TheInt2S myIntersectionOn2S;
236   Standard_Integer STATIC_BLOCAGE_SUR_PAS_TROP_GRAND;
237   Standard_Integer STATIC_PRECEDENT_INFLEXION;
238
239
240 };
241
242
243 #include <IntWalk_PWalking.lxx>
244
245
246
247
248
249 #endif // _IntWalk_PWalking_HeaderFile