Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-21 09:17:40

0001 // Created on: 1999-03-03
0002 // Created by: Fabrice SERVANT
0003 // Copyright (c) 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 _IntPolyh_MaillageAffinage_HeaderFile
0018 #define _IntPolyh_MaillageAffinage_HeaderFile
0019 
0020 #include <Adaptor3d_Surface.hxx>
0021 #include <Bnd_Box.hxx>
0022 #include <IntPolyh_ArrayOfPoints.hxx>
0023 #include <IntPolyh_ArrayOfEdges.hxx>
0024 #include <IntPolyh_ArrayOfTriangles.hxx>
0025 #include <NCollection_List.hxx>
0026 #include <IntPolyh_Couple.hxx>
0027 #include <NCollection_Array1.hxx>
0028 #include <IntPolyh_ArrayOfPointNormal.hxx>
0029 #include <IntPolyh_ArrayOfSectionLines.hxx>
0030 #include <IntPolyh_ArrayOfTangentZones.hxx>
0031 
0032 class IntPolyh_StartPoint;
0033 
0034 //! Low-level algorithm to compute intersection of the surfaces
0035 //! by computing the intersection of their triangulations.
0036 class IntPolyh_MaillageAffinage
0037 {
0038 public:
0039   DEFINE_STANDARD_ALLOC
0040 
0041   Standard_EXPORT IntPolyh_MaillageAffinage(const occ::handle<Adaptor3d_Surface>& S1,
0042                                             const int                             NbSU1,
0043                                             const int                             NbSV1,
0044                                             const occ::handle<Adaptor3d_Surface>& S2,
0045                                             const int                             NbSU2,
0046                                             const int                             NbSV2,
0047                                             const int                             PRINT);
0048 
0049   Standard_EXPORT IntPolyh_MaillageAffinage(const occ::handle<Adaptor3d_Surface>& S1,
0050                                             const occ::handle<Adaptor3d_Surface>& S2,
0051                                             const int                             PRINT);
0052 
0053   //! Makes the sampling of the surface -
0054   //! Fills the arrays with the parametric values of the sampling points (triangulation nodes).
0055   Standard_EXPORT void MakeSampling(const int                   SurfID,
0056                                     NCollection_Array1<double>& theUPars,
0057                                     NCollection_Array1<double>& theVPars);
0058 
0059   //! Computes points on one surface and fills an array of points;
0060   //! standard (default) method
0061   Standard_EXPORT void FillArrayOfPnt(const int SurfID);
0062 
0063   //! isShiftFwd flag is added. The purpose is to define shift
0064   //! of points along normal to the surface in this point. The
0065   //! shift length represents maximal deflection of triangulation.
0066   //! The direction (forward or reversed regarding to normal
0067   //! direction) is defined by isShiftFwd flag.
0068   //! Compute points on one surface and fill an array of points;
0069   //! advanced method
0070   Standard_EXPORT void FillArrayOfPnt(const int SurfID, const bool isShiftFwd);
0071 
0072   //! Compute points on one surface and fill an array of points;
0073   //! If given, <theDeflTol> is the deflection tolerance of the given sampling.
0074   //! standard (default) method
0075   Standard_EXPORT void FillArrayOfPnt(const int                         SurfID,
0076                                       const NCollection_Array1<double>& Upars,
0077                                       const NCollection_Array1<double>& Vpars,
0078                                       const double*                     theDeflTol = nullptr);
0079 
0080   //! isShiftFwd flag is added. The purpose is to define shift
0081   //! of points along normal to the surface in this point. The
0082   //! shift length represents maximal deflection of triangulation.
0083   //! The direction (forward or reversed regarding to normal
0084   //! direction) is defined by isShiftFwd flag.
0085   //! Compute points on one surface and fill an array of points;
0086   //! If given, <theDeflTol> is the deflection tolerance of the given sampling.
0087   //! advanced method
0088   Standard_EXPORT void FillArrayOfPnt(const int                         SurfID,
0089                                       const bool                        isShiftFwd,
0090                                       const NCollection_Array1<double>& Upars,
0091                                       const NCollection_Array1<double>& Vpars,
0092                                       const double*                     theDeflTol = nullptr);
0093 
0094   //! Fills the array of points for the surface taking into account the shift
0095   Standard_EXPORT void FillArrayOfPnt(const int                          SurfID,
0096                                       const bool                         isShiftFwd,
0097                                       const IntPolyh_ArrayOfPointNormal& thePoints,
0098                                       const NCollection_Array1<double>&  theUPars,
0099                                       const NCollection_Array1<double>&  theVPars,
0100                                       const double                       theDeflTol);
0101 
0102   //! Looks for the common box of the surfaces and marks the points
0103   //! of the surfaces inside that common box for possible intersection
0104   Standard_EXPORT void CommonBox();
0105 
0106   //! Compute the common box which is the intersection
0107   //! of the two bounding boxes, and mark the points of
0108   //! the two surfaces that are inside.
0109   Standard_EXPORT void CommonBox(const Bnd_Box& B1,
0110                                  const Bnd_Box& B2,
0111                                  double&        xMin,
0112                                  double&        yMin,
0113                                  double&        zMin,
0114                                  double&        xMax,
0115                                  double&        yMax,
0116                                  double&        zMax);
0117 
0118   //! Compute edges from the array of points
0119   Standard_EXPORT void FillArrayOfEdges(const int SurfID);
0120 
0121   //! Compute triangles from the array of points, and
0122   //! mark the triangles that use marked points by the
0123   //! CommonBox function.
0124   Standard_EXPORT void FillArrayOfTriangles(const int SurfID);
0125 
0126   //! Refine systematicaly all marked triangles of both surfaces
0127   Standard_EXPORT void CommonPartRefinement();
0128 
0129   //! Refine systematicaly all marked triangles of ONE surface
0130   Standard_EXPORT void LocalSurfaceRefinement(const int SurfId);
0131 
0132   //! Compute deflection for all triangles of one
0133   //! surface,and sort min and max of deflections
0134   Standard_EXPORT void ComputeDeflections(const int SurfID);
0135 
0136   //! Refine both surfaces using BoundSortBox as
0137   //! rejection. The criterions used to refine a
0138   //! triangle are: The deflection The size of the
0139   //! bounding boxes (one surface may be very small
0140   //! compared to the other)
0141   Standard_EXPORT void TrianglesDeflectionsRefinementBSB();
0142 
0143   //! This function checks if two triangles are in contact or not,
0144   //! return 1 if yes, return 0 if not.
0145   Standard_EXPORT int TriContact(const IntPolyh_Point& P1,
0146                                  const IntPolyh_Point& P2,
0147                                  const IntPolyh_Point& P3,
0148                                  const IntPolyh_Point& Q1,
0149                                  const IntPolyh_Point& Q2,
0150                                  const IntPolyh_Point& Q3,
0151                                  double&               Angle) const;
0152 
0153   Standard_EXPORT int TriangleEdgeContact(const int                TriSurfID,
0154                                           const int                EdgeIndice,
0155                                           const IntPolyh_Triangle& Tri1,
0156                                           const IntPolyh_Triangle& Tri2,
0157                                           const IntPolyh_Point&    P1,
0158                                           const IntPolyh_Point&    P2,
0159                                           const IntPolyh_Point&    P3,
0160                                           const IntPolyh_Point&    C1,
0161                                           const IntPolyh_Point&    C2,
0162                                           const IntPolyh_Point&    C3,
0163                                           const IntPolyh_Point&    Pe1,
0164                                           const IntPolyh_Point&    Pe2,
0165                                           const IntPolyh_Point&    E,
0166                                           const IntPolyh_Point&    N,
0167                                           IntPolyh_StartPoint&     SP1,
0168                                           IntPolyh_StartPoint&     SP2) const;
0169 
0170   //! From two triangles compute intersection points.
0171   //! If we found more than two intersection points
0172   //! that means that those triangles are coplanar
0173   Standard_EXPORT int StartingPointsResearch(const int            T1,
0174                                              const int            T2,
0175                                              IntPolyh_StartPoint& SP1,
0176                                              IntPolyh_StartPoint& SP2) const;
0177 
0178   //! from two triangles and an intersection point I
0179   //! search the other point (if it exists).
0180   //! This function is used by StartPointChain
0181   Standard_EXPORT int NextStartingPointsResearch(const int                  T1,
0182                                                  const int                  T2,
0183                                                  const IntPolyh_StartPoint& SPInit,
0184                                                  IntPolyh_StartPoint&       SPNext) const;
0185 
0186   //! Analyse each couple of triangles from the two -- array of triangles,
0187   //! to see if they are in contact, and compute the incidence.
0188   //! Then put couples in contact in the array of couples
0189   Standard_EXPORT int TriangleCompare();
0190 
0191   //! Loop on the array of couples. Compute StartPoints.
0192   //! Try to chain the StartPoints into SectionLines or
0193   //! put the point in the ArrayOfTangentZones if
0194   //! chaining it, is not possible.
0195   Standard_EXPORT int StartPointsChain(IntPolyh_ArrayOfSectionLines& TSectionLines,
0196                                        IntPolyh_ArrayOfTangentZones& TTangentZones);
0197 
0198   //! Mainly used by StartPointsChain(), this function
0199   //! try to compute the next StartPoint.
0200   Standard_EXPORT int GetNextChainStartPoint(const IntPolyh_StartPoint&    SPInit,
0201                                              IntPolyh_StartPoint&          SPNext,
0202                                              IntPolyh_SectionLine&         MySectionLine,
0203                                              IntPolyh_ArrayOfTangentZones& TTangentZones,
0204                                              const bool                    Prepend = false);
0205 
0206   Standard_EXPORT const IntPolyh_ArrayOfPoints& GetArrayOfPoints(const int SurfID) const;
0207 
0208   Standard_EXPORT const IntPolyh_ArrayOfEdges& GetArrayOfEdges(const int SurfID) const;
0209 
0210   Standard_EXPORT const IntPolyh_ArrayOfTriangles& GetArrayOfTriangles(const int SurfID) const;
0211 
0212   Standard_EXPORT int GetFinTE(const int SurfID) const;
0213 
0214   Standard_EXPORT int GetFinTT(const int SurfID) const;
0215 
0216   Standard_EXPORT Bnd_Box GetBox(const int SurfID) const;
0217 
0218   //! This method returns list of couples of contact triangles.
0219   Standard_EXPORT NCollection_List<IntPolyh_Couple>& GetCouples();
0220 
0221   Standard_EXPORT void SetEnlargeZone(const bool EnlargeZone);
0222 
0223   Standard_EXPORT bool GetEnlargeZone() const;
0224 
0225   //! returns FlecheMin
0226   Standard_EXPORT double GetMinDeflection(const int SurfID) const;
0227 
0228   //! returns FlecheMax
0229   Standard_EXPORT double GetMaxDeflection(const int SurfID) const;
0230 
0231 private:
0232   occ::handle<Adaptor3d_Surface> MaSurface1;
0233   occ::handle<Adaptor3d_Surface> MaSurface2;
0234   Bnd_Box                        MyBox1;
0235   Bnd_Box                        MyBox2;
0236   int                            NbSamplesU1;
0237   int                            NbSamplesU2;
0238   int                            NbSamplesV1;
0239   int                            NbSamplesV2;
0240   double                         FlecheMax1;
0241   double                         FlecheMax2;
0242   double                         FlecheMin1;
0243   double                         FlecheMin2;
0244   // For the arrays of Points, Edges and Triangles we need instant access to the items.
0245   // Moreover, we might add new items during refinement process in case the deflection
0246   // is too big, thus the vectors should be used.
0247   IntPolyh_ArrayOfPoints    TPoints1;
0248   IntPolyh_ArrayOfPoints    TPoints2;
0249   IntPolyh_ArrayOfEdges     TEdges1;
0250   IntPolyh_ArrayOfEdges     TEdges2;
0251   IntPolyh_ArrayOfTriangles TTriangles1;
0252   IntPolyh_ArrayOfTriangles TTriangles2;
0253   // The intersecting triangles are just filled and then
0254   // sequentially analyzed, thus we might use the list.
0255   NCollection_List<IntPolyh_Couple> TTrianglesContacts;
0256 
0257   bool myEnlargeZone;
0258 };
0259 
0260 #endif // _IntPolyh_MaillageAffinage_HeaderFile