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,
70                                    const Handle(Adaptor3d_HSurface)& Caro2,
71                                    const Standard_Real TolTangency,
72                                    const Standard_Real Epsilon,
73                                    const Standard_Real Deflection,
74                                    const Standard_Real Increment);
75 
76   //! Returns the intersection line containing the exact
77   //! point Poin. This line is a polygonal line.
78   //! Deflection is the maximum deflection admitted between two
79   //! consecutive points on the resulting polyline.
80   //! TolTangency is the tolerance to find a tangent point.
81   //! Func is the criterion which has to be evaluated at each
82   //! solution point (each point of the line).
83   //! The line found starts at a point on or in 2 natural domains
84   //! of surfaces. It can be closed in the
85   //! standard case if it is open it stops and begins at the
86   //! border of one of the domains. If an open line
87   //! stops at the middle of a domain, one stops at the tangent point.
88   //! Epsilon is SquareTolerance of points confusion.
89   Standard_EXPORT IntWalk_PWalking(const Handle(Adaptor3d_HSurface)& Caro1,
90                                    const Handle(Adaptor3d_HSurface)& Caro2,
91                                    const Standard_Real TolTangency,
92                                    const Standard_Real Epsilon,
93                                    const Standard_Real Deflection,
94                                    const Standard_Real Increment,
95                                    const Standard_Real U1,
96                                    const Standard_Real V1,
97                                    const Standard_Real U2,
98                                    const Standard_Real V2);
99 
100   //! calculate the line of intersection
101   Standard_EXPORT void Perform (const TColStd_Array1OfReal& ParDep);
102 
103   //! calculate the line of intersection. The regulation
104   //! of steps is done using min and max values on u and
105   //! v.  (if this data is not presented as in the
106   //! previous method, the initial steps are calculated
107   //! starting from min and max uv of faces).
108   Standard_EXPORT void Perform (const TColStd_Array1OfReal& ParDep,
109                                 const Standard_Real u1min,
110                                 const Standard_Real v1min,
111                                 const Standard_Real u2min,
112                                 const Standard_Real v2min,
113                                 const Standard_Real u1max,
114                                 const Standard_Real v1max,
115                                 const Standard_Real u2max,
116                                 const Standard_Real v2max);
117 
118   //! calculate the first point of a line of intersection
119   Standard_EXPORT Standard_Boolean PerformFirstPoint (const TColStd_Array1OfReal& ParDep,
120                                                       IntSurf_PntOn2S& FirstPoint);
121 
122   //! Returns true if the calculus was successful.
123     Standard_Boolean IsDone() const;
124 
125   //! Returns the number of points of the resulting polyline.
126   //! An exception is raised if IsDone returns False.
127     Standard_Integer NbPoints() const;
128 
129   //! Returns the point of range Index on the polyline.
130   //! An exception is raised if IsDone returns False.
131   //! An exception is raised if Index<=0 or Index>NbPoints.
132     const IntSurf_PntOn2S& Value (const Standard_Integer Index) const;
133 
134     const Handle(IntSurf_LineOn2S)& Line() const;
135 
136   //! Returns True if the surface are tangent at the first point
137   //! of the line.
138   //! An exception is raised if IsDone returns False.
139     Standard_Boolean TangentAtFirst() const;
140 
141   //! Returns true if the surface are tangent at the last point
142   //! of the line.
143   //! An exception is raised if IsDone returns False.
144     Standard_Boolean TangentAtLast() const;
145 
146   //! Returns True if the line is closed.
147   //! An exception is raised if IsDone returns False.
148     Standard_Boolean IsClosed() const;
149 
150     const gp_Dir& TangentAtLine (Standard_Integer& Index) const;
151 
152   Standard_EXPORT   IntWalk_StatusDeflection TestDeflection (const IntImp_ConstIsoparametric ChoixIso,
153                                                              const IntWalk_StatusDeflection  theStatus);
154 
155   Standard_EXPORT Standard_Boolean TestArret (const Standard_Boolean DejaReparti,
156                                               TColStd_Array1OfReal& Param,
157                                               IntImp_ConstIsoparametric& ChoixIso);
158 
159   Standard_EXPORT void RepartirOuDiviser (Standard_Boolean& DejaReparti,
160                                           IntImp_ConstIsoparametric& ChoixIso,
161                                           Standard_Boolean& Arrive);
162 
163   //! Inserts thePOn2S in the end of line
164   void AddAPoint (const IntSurf_PntOn2S& thePOn2S);
165 
166   //! Removes point with index theIndex from line.
167   //! If theIndex is greater than the number of points in line
168   //! then the last point will be removed.
169   //! theIndex must be started with 1.
RemoveAPoint(const Standard_Integer theIndex)170   void RemoveAPoint(const Standard_Integer theIndex)
171   {
172     const Standard_Integer anIdx = Min(theIndex, line->NbPoints());
173 
174     if (anIdx < 1)
175       return;
176 
177     if (anIdx <= myTangentIdx)
178     {
179       myTangentIdx--;
180 
181       if (myTangentIdx < 1)
182         myTangentIdx = 1;
183     }
184 
185     line->RemovePoint(anIdx);
186   }
187 
188   Standard_EXPORT Standard_Boolean PutToBoundary (const Handle(Adaptor3d_HSurface)& theASurf1,
189                                                   const Handle(Adaptor3d_HSurface)& theASurf2);
190 
191   Standard_EXPORT Standard_Boolean SeekAdditionalPoints (const Handle(Adaptor3d_HSurface)& theASurf1,
192                                                          const Handle(Adaptor3d_HSurface)& theASurf2,
193                                                          const Standard_Integer theMinNbPoints);
194 
MaxStep(Standard_Integer theIndex)195   Standard_Real MaxStep(Standard_Integer theIndex)
196   {
197     Standard_OutOfRange_Raise_if ((theIndex < 0) || (theIndex > 3),
198                                   "IntWalk_PWalking::MaxStep() - index is out of range");
199     return pasInit[theIndex];
200   }
201 
202 
203 
204 protected:
205   Standard_EXPORT void ComputePasInit(const Standard_Real theDeltaU1,
206                                       const Standard_Real theDeltaV1,
207                                       const Standard_Real theDeltaU2,
208                                       const Standard_Real theDeltaV2);
209 
210   //! Uses Gradient method in order to find intersection point between the given surfaces
211   //! Arrays theInit (initial point to be precise) and theStep0 (steps-array) must contain
212   //! four items and must be filled strictly in following order:
213   //! {U-parameter on S1, V-parameter on S1, U-parameter on S2, V-parameter on S2}
214   Standard_EXPORT Standard_Boolean DistanceMinimizeByGradient(const Handle(Adaptor3d_HSurface)& theASurf1,
215                                                               const Handle(Adaptor3d_HSurface)& theASurf2,
216                                                               TColStd_Array1OfReal& theInit,
217                                                               const Standard_Real* theStep0 = 0);
218 
219   //! Finds the point on theASurf which is the nearest point to theP0.
220   //! theU0 and theV0 must be initialized (before calling the method) by initial
221   //! parameters on theASurf. Their values are changed while algorithm being launched.
222   //! Array theStep0 (steps-array) must contain two items and must be filled strictly in following order:
223   //! {U-parameter, V-parameter}
224   Standard_EXPORT Standard_Boolean DistanceMinimizeByExtrema (const Handle(Adaptor3d_HSurface)& theASurf,
225                                                               const gp_Pnt& theP0,
226                                                               Standard_Real& theU0,
227                                                               Standard_Real& theV0,
228                                                               const Standard_Real* theStep0 = 0);
229 
230   //! Searches an intersection point which lies on the some surface boundary.
231   //! Found point (in case of successful result) is added in the line.
232   //! theU1, theV1, theU2 and theV2 parameters are initial parameters in
233   //! for used numeric algorithms. If isTheFirst == TRUE then
234   //! a point on theASurf1 is searched. Otherwise, the point on theASurf2 is searched.
235   //!
236   //! ATTENTION!!!
237   //!   This method can delete some points from the curve if it is necessary
238   //!   (in order to obtain correct result after insertion).
239   //!   Returns TRUE in case of success adding (i.e. can return FALSE even after
240   //!   removing some points).
241   Standard_EXPORT Standard_Boolean SeekPointOnBoundary (const Handle(Adaptor3d_HSurface)& theASurf1,
242                                                         const Handle(Adaptor3d_HSurface)& theASurf2,
243                                                         const Standard_Real theU1,
244                                                         const Standard_Real theV1,
245                                                         const Standard_Real theU2,
246                                                         const Standard_Real theV2,
247                                                         const Standard_Boolean isTheFirst);
248 
249 
250   // Method to handle single singular point. Sub-method in SeekPointOnBoundary.
251   Standard_EXPORT Standard_Boolean HandleSingleSingularPoint(const Handle(Adaptor3d_HSurface) &theASurf1,
252                                                              const Handle(Adaptor3d_HSurface) &theASurf2,
253                                                              const Standard_Real the3DTol,
254                                                              TColStd_Array1OfReal &thePnt);
255 
256   Standard_EXPORT Standard_Boolean ExtendLineInCommonZone (const IntImp_ConstIsoparametric theChoixIso,
257                                                            const Standard_Boolean theDirectionFlag);
258 
259 private:
260   Standard_Boolean done;
261   Handle(IntSurf_LineOn2S) line;
262   Standard_Boolean close;
263   Standard_Boolean tgfirst;
264   Standard_Boolean tglast;
265 
266   //! Index of point on the surface boundary.
267   //! It is used for transition computation
268   Standard_Integer myTangentIdx;
269 
270   //! Tangent to WLine in the point with index myTangentIdx
271   gp_Dir tgdir;
272 
273   Standard_Real fleche;
274   Standard_Real pasMax;
275   Standard_Real tolconf;
276   Standard_Real myTolTang;
277   Standard_Real pasuv[4];
278   Standard_Real myStepMin[4];
279   Standard_Real pasSav[4];
280   Standard_Real pasInit[4];
281   Standard_Real Um1;
282   Standard_Real UM1;
283   Standard_Real Vm1;
284   Standard_Real VM1;
285   Standard_Real Um2;
286   Standard_Real UM2;
287   Standard_Real Vm2;
288   Standard_Real VM2;
289   Standard_Real ResoU1;
290   Standard_Real ResoU2;
291   Standard_Real ResoV1;
292   Standard_Real ResoV2;
293   Standard_Integer sensCheminement;
294   IntImp_ConstIsoparametric choixIsoSav;
295   IntSurf_PntOn2S previousPoint;
296   Standard_Boolean previoustg;
297   gp_Dir previousd;
298   gp_Dir2d previousd1;
299   gp_Dir2d previousd2;
300   gp_Dir2d firstd1;
301   gp_Dir2d firstd2;
302   IntWalk_TheInt2S myIntersectionOn2S;
303   Standard_Integer STATIC_BLOCAGE_SUR_PAS_TROP_GRAND;
304   Standard_Integer STATIC_PRECEDENT_INFLEXION;
305 
306 
307 };
308 
309 
310 #include <IntWalk_PWalking.lxx>
311 
312 
313 
314 
315 
316 #endif // _IntWalk_PWalking_HeaderFile
317