Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-06-11 08:33:36

0001 // Created on: 1992-04-03
0002 // Created by: Isabelle GRIGNON
0003 // Copyright (c) 1992-1999 Matra Datavision
0004 // Copyright (c) 1999-2014 OPEN CASCADE SAS
0005 //
0006 // This file is part of Open CASCADE Technology software library.
0007 //
0008 // This library is free software; you can redistribute it and/or modify it under
0009 // the terms of the GNU Lesser General Public License version 2.1 as published
0010 // by the Free Software Foundation, with special exception defined in the file
0011 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0012 // distribution for complete text of the license and disclaimer of any warranty.
0013 //
0014 // Alternatively, this file may be used under the terms of Open CASCADE
0015 // commercial license or contractual agreement.
0016 
0017 #ifndef _IntWalk_PWalking_HeaderFile
0018 #define _IntWalk_PWalking_HeaderFile
0019 
0020 #include <Adaptor3d_Surface.hxx>
0021 #include <gp_Dir.hxx>
0022 #include <IntImp_ConstIsoparametric.hxx>
0023 #include <IntSurf_PntOn2S.hxx>
0024 #include <gp_Dir2d.hxx>
0025 #include <IntWalk_TheInt2S.hxx>
0026 #include <TColStd_Array1OfReal.hxx>
0027 #include <IntWalk_StatusDeflection.hxx>
0028 
0029 class gp_Pnt;
0030 
0031 //! This class implements an algorithm to determine the
0032 //! intersection between 2 parametrized surfaces, marching from
0033 //! a starting point. The intersection line
0034 //! starts and ends on the natural surface's  boundaries .
0035 class IntWalk_PWalking
0036 {
0037 public:
0038   DEFINE_STANDARD_ALLOC
0039 
0040   //! Constructor used to set the data to compute intersection
0041   //! lines between Caro1 and Caro2.
0042   //! Deflection is the maximum deflection admitted between two
0043   //! consecutive points on the resulting polyline.
0044   //! TolTangency is the tolerance to find a tangent point.
0045   //! Func is the criterion which has to be evaluated at each
0046   //! solution point (each point of the line).
0047   //! It is necessary to call the Perform method to compute
0048   //! the intersection lines.
0049   //! The line found starts at a point on or in 2 natural domains
0050   //! of surfaces. It can be closed in the
0051   //! standard case if it is open it stops and begins at the
0052   //! border of one of the domains. If an open line
0053   //! stops at the middle of a domain, one stops at the tangent point.
0054   //! Epsilon is SquareTolerance of points confusion.
0055   Standard_EXPORT IntWalk_PWalking(const Handle(Adaptor3d_Surface)& Caro1,
0056                                    const Handle(Adaptor3d_Surface)& Caro2,
0057                                    const Standard_Real              TolTangency,
0058                                    const Standard_Real              Epsilon,
0059                                    const Standard_Real              Deflection,
0060                                    const Standard_Real              Increment);
0061 
0062   //! Returns the intersection line containing the exact
0063   //! point Poin. This line is a polygonal line.
0064   //! Deflection is the maximum deflection admitted between two
0065   //! consecutive points on the resulting polyline.
0066   //! TolTangency is the tolerance to find a tangent point.
0067   //! Func is the criterion which has to be evaluated at each
0068   //! solution point (each point of the line).
0069   //! The line found starts at a point on or in 2 natural domains
0070   //! of surfaces. It can be closed in the
0071   //! standard case if it is open it stops and begins at the
0072   //! border of one of the domains. If an open line
0073   //! stops at the middle of a domain, one stops at the tangent point.
0074   //! Epsilon is SquareTolerance of points confusion.
0075   Standard_EXPORT IntWalk_PWalking(const Handle(Adaptor3d_Surface)& Caro1,
0076                                    const Handle(Adaptor3d_Surface)& Caro2,
0077                                    const Standard_Real              TolTangency,
0078                                    const Standard_Real              Epsilon,
0079                                    const Standard_Real              Deflection,
0080                                    const Standard_Real              Increment,
0081                                    const Standard_Real              U1,
0082                                    const Standard_Real              V1,
0083                                    const Standard_Real              U2,
0084                                    const Standard_Real              V2);
0085 
0086   //! calculate the line of intersection
0087   Standard_EXPORT void Perform(const TColStd_Array1OfReal& ParDep);
0088 
0089   //! calculate the line of intersection. The regulation
0090   //! of steps is done using min and max values on u and
0091   //! v.  (if this data is not presented as in the
0092   //! previous method, the initial steps are calculated
0093   //! starting from min and max uv of faces).
0094   Standard_EXPORT void Perform(const TColStd_Array1OfReal& ParDep,
0095                                const Standard_Real         u1min,
0096                                const Standard_Real         v1min,
0097                                const Standard_Real         u2min,
0098                                const Standard_Real         v2min,
0099                                const Standard_Real         u1max,
0100                                const Standard_Real         v1max,
0101                                const Standard_Real         u2max,
0102                                const Standard_Real         v2max);
0103 
0104   //! calculate the first point of a line of intersection
0105   Standard_EXPORT Standard_Boolean PerformFirstPoint(const TColStd_Array1OfReal& ParDep,
0106                                                      IntSurf_PntOn2S&            FirstPoint);
0107 
0108   //! Returns true if the calculus was successful.
0109   Standard_Boolean IsDone() const;
0110 
0111   //! Returns the number of points of the resulting polyline.
0112   //! An exception is raised if IsDone returns False.
0113   Standard_Integer NbPoints() const;
0114 
0115   //! Returns the point of range Index on the polyline.
0116   //! An exception is raised if IsDone returns False.
0117   //! An exception is raised if Index<=0 or Index>NbPoints.
0118   const IntSurf_PntOn2S& Value(const Standard_Integer Index) const;
0119 
0120   const Handle(IntSurf_LineOn2S)& Line() const;
0121 
0122   //! Returns True if the surface are tangent at the first point
0123   //! of the line.
0124   //! An exception is raised if IsDone returns False.
0125   Standard_Boolean TangentAtFirst() const;
0126 
0127   //! Returns true if the surface are tangent at the last point
0128   //! of the line.
0129   //! An exception is raised if IsDone returns False.
0130   Standard_Boolean TangentAtLast() const;
0131 
0132   //! Returns True if the line is closed.
0133   //! An exception is raised if IsDone returns False.
0134   Standard_Boolean IsClosed() const;
0135 
0136   const gp_Dir& TangentAtLine(Standard_Integer& Index) const;
0137 
0138   Standard_EXPORT IntWalk_StatusDeflection TestDeflection(const IntImp_ConstIsoparametric ChoixIso,
0139                                                           const IntWalk_StatusDeflection theStatus);
0140 
0141   Standard_EXPORT Standard_Boolean TestArret(const Standard_Boolean     DejaReparti,
0142                                              TColStd_Array1OfReal&      Param,
0143                                              IntImp_ConstIsoparametric& ChoixIso);
0144 
0145   Standard_EXPORT void RepartirOuDiviser(Standard_Boolean&          DejaReparti,
0146                                          IntImp_ConstIsoparametric& ChoixIso,
0147                                          Standard_Boolean&          Arrive);
0148 
0149   //! Inserts thePOn2S in the end of line
0150   void AddAPoint(const IntSurf_PntOn2S& thePOn2S);
0151 
0152   //! Removes point with index theIndex from line.
0153   //! If theIndex is greater than the number of points in line
0154   //! then the last point will be removed.
0155   //! theIndex must be started with 1.
0156   void RemoveAPoint(const Standard_Integer theIndex)
0157   {
0158     const Standard_Integer anIdx = Min(theIndex, line->NbPoints());
0159 
0160     if (anIdx < 1)
0161       return;
0162 
0163     if (anIdx <= myTangentIdx)
0164     {
0165       myTangentIdx--;
0166 
0167       if (myTangentIdx < 1)
0168         myTangentIdx = 1;
0169     }
0170 
0171     line->RemovePoint(anIdx);
0172   }
0173 
0174   Standard_EXPORT Standard_Boolean PutToBoundary(const Handle(Adaptor3d_Surface)& theASurf1,
0175                                                  const Handle(Adaptor3d_Surface)& theASurf2);
0176 
0177   Standard_EXPORT Standard_Boolean SeekAdditionalPoints(const Handle(Adaptor3d_Surface)& theASurf1,
0178                                                         const Handle(Adaptor3d_Surface)& theASurf2,
0179                                                         const Standard_Integer theMinNbPoints);
0180 
0181   Standard_Real MaxStep(Standard_Integer theIndex)
0182   {
0183     Standard_OutOfRange_Raise_if((theIndex < 0) || (theIndex > 3),
0184                                  "IntWalk_PWalking::MaxStep() - index is out of range");
0185     return pasInit[theIndex];
0186   }
0187 
0188 protected:
0189   Standard_EXPORT void ComputePasInit(const Standard_Real theDeltaU1,
0190                                       const Standard_Real theDeltaV1,
0191                                       const Standard_Real theDeltaU2,
0192                                       const Standard_Real theDeltaV2);
0193 
0194   //! Uses Gradient method in order to find intersection point between the given surfaces
0195   //! Arrays theInit (initial point to be precise) and theStep0 (steps-array) must contain
0196   //! four items and must be filled strictly in following order:
0197   //! {U-parameter on S1, V-parameter on S1, U-parameter on S2, V-parameter on S2}
0198   Standard_EXPORT Standard_Boolean
0199     DistanceMinimizeByGradient(const Handle(Adaptor3d_Surface)& theASurf1,
0200                                const Handle(Adaptor3d_Surface)& theASurf2,
0201                                TColStd_Array1OfReal&            theInit,
0202                                const Standard_Real*             theStep0 = 0);
0203 
0204   //! Finds the point on theASurf which is the nearest point to theP0.
0205   //! theU0 and theV0 must be initialized (before calling the method) by initial
0206   //! parameters on theASurf. Their values are changed while algorithm being launched.
0207   //! Array theStep0 (steps-array) must contain two items and must be filled strictly in following
0208   //! order: {U-parameter, V-parameter}
0209   Standard_EXPORT Standard_Boolean
0210     DistanceMinimizeByExtrema(const Handle(Adaptor3d_Surface)& theASurf,
0211                               const gp_Pnt&                    theP0,
0212                               Standard_Real&                   theU0,
0213                               Standard_Real&                   theV0,
0214                               const Standard_Real*             theStep0 = 0);
0215 
0216   //! Searches an intersection point which lies on the some surface boundary.
0217   //! Found point (in case of successful result) is added in the line.
0218   //! theU1, theV1, theU2 and theV2 parameters are initial parameters in
0219   //! for used numeric algorithms. If isTheFirst == TRUE then
0220   //! a point on theASurf1 is searched. Otherwise, the point on theASurf2 is searched.
0221   //!
0222   //! ATTENTION!!!
0223   //!   This method can delete some points from the curve if it is necessary
0224   //!   (in order to obtain correct result after insertion).
0225   //!   Returns TRUE in case of success adding (i.e. can return FALSE even after
0226   //!   removing some points).
0227   Standard_EXPORT Standard_Boolean SeekPointOnBoundary(const Handle(Adaptor3d_Surface)& theASurf1,
0228                                                        const Handle(Adaptor3d_Surface)& theASurf2,
0229                                                        const Standard_Real              theU1,
0230                                                        const Standard_Real              theV1,
0231                                                        const Standard_Real              theU2,
0232                                                        const Standard_Real              theV2,
0233                                                        const Standard_Boolean           isTheFirst);
0234 
0235   // Method to handle single singular point. Sub-method in SeekPointOnBoundary.
0236   Standard_EXPORT Standard_Boolean
0237     HandleSingleSingularPoint(const Handle(Adaptor3d_Surface)& theASurf1,
0238                               const Handle(Adaptor3d_Surface)& theASurf2,
0239                               const Standard_Real              the3DTol,
0240                               TColStd_Array1OfReal&            thePnt);
0241 
0242   Standard_EXPORT Standard_Boolean
0243     ExtendLineInCommonZone(const IntImp_ConstIsoparametric theChoixIso,
0244                            const Standard_Boolean          theDirectionFlag);
0245 
0246 private:
0247   Standard_Boolean         done;
0248   Handle(IntSurf_LineOn2S) line;
0249   Standard_Boolean         close;
0250   Standard_Boolean         tgfirst;
0251   Standard_Boolean         tglast;
0252 
0253   //! Index of point on the surface boundary.
0254   //! It is used for transition computation
0255   Standard_Integer myTangentIdx;
0256 
0257   //! Tangent to WLine in the point with index myTangentIdx
0258   gp_Dir tgdir;
0259 
0260   Standard_Real             fleche;
0261   Standard_Real             pasMax;
0262   Standard_Real             tolconf;
0263   Standard_Real             myTolTang;
0264   Standard_Real             pasuv[4];
0265   Standard_Real             myStepMin[4];
0266   Standard_Real             pasSav[4];
0267   Standard_Real             pasInit[4];
0268   Standard_Real             Um1;
0269   Standard_Real             UM1;
0270   Standard_Real             Vm1;
0271   Standard_Real             VM1;
0272   Standard_Real             Um2;
0273   Standard_Real             UM2;
0274   Standard_Real             Vm2;
0275   Standard_Real             VM2;
0276   Standard_Real             ResoU1;
0277   Standard_Real             ResoU2;
0278   Standard_Real             ResoV1;
0279   Standard_Real             ResoV2;
0280   Standard_Integer          sensCheminement;
0281   IntImp_ConstIsoparametric choixIsoSav;
0282   IntSurf_PntOn2S           previousPoint;
0283   Standard_Boolean          previoustg;
0284   gp_Dir                    previousd;
0285   gp_Dir2d                  previousd1;
0286   gp_Dir2d                  previousd2;
0287   gp_Dir2d                  firstd1;
0288   gp_Dir2d                  firstd2;
0289   IntWalk_TheInt2S          myIntersectionOn2S;
0290   Standard_Integer          STATIC_BLOCAGE_SUR_PAS_TROP_GRAND;
0291   Standard_Integer          STATIC_PRECEDENT_INFLEXION;
0292 };
0293 
0294 #include <IntWalk_PWalking.lxx>
0295 
0296 #endif // _IntWalk_PWalking_HeaderFile