Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-24 09:15:14

0001 // Created on: 2022-08-08
0002 // Created by: Kseniya NOSULKO
0003 // Copyright (c) 2022 OPEN CASCADE SAS
0004 //
0005 // This file is part of Open CASCADE Technology software library.
0006 //
0007 // This library is free software; you can redistribute it and/or modify it under
0008 // the terms of the GNU Lesser General Public License version 2.1 as published
0009 // by the Free Software Foundation, with special exception defined in the file
0010 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0011 // distribution for complete text of the license and disclaimer of any warranty.
0012 //
0013 // Alternatively, this file may be used under the terms of Open CASCADE
0014 // commercial license or contractual agreement.
0015 
0016 #ifndef _BRepExtrema_ProximityValueTool_HeaderFile
0017 #define _BRepExtrema_ProximityValueTool_HeaderFile
0018 
0019 #include <BRepExtrema_ProximityDistTool.hxx>
0020 #include <BRepExtrema_TriangleSet.hxx>
0021 #include <NCollection_CellFilter.hxx>
0022 #include <Precision.hxx>
0023 
0024 typedef NCollection_DynamicArray<gp_XYZ> VectorOfPoint;
0025 
0026 //! Inspector for CellFilter algorithm working with gp_XYZ points in 3d space.
0027 //! Used in search of coincidence points with a certain tolerance.
0028 class BRepExtrema_VertexInspector
0029 {
0030 public:
0031   static constexpr int Dimension = 3;
0032 
0033   typedef gp_XYZ Point;
0034   typedef int    Target;
0035 
0036   static double Coord(int i, const Point& thePnt) { return thePnt.Coord(i + 1); }
0037 
0038   static Point Shift(const Point& thePnt, double theTol)
0039   {
0040     return Point(thePnt.X() + theTol, thePnt.Y() + theTol, thePnt.Z() + theTol);
0041   }
0042 
0043   //! Constructor; remembers the tolerance
0044   BRepExtrema_VertexInspector()
0045       : myTol(Precision::SquareConfusion()),
0046         myIsNeedAdd(true)
0047   {
0048   }
0049 
0050   //! Keep the points used for comparison
0051   void Add(const gp_XYZ& thePnt) { myPoints.Append(thePnt); }
0052 
0053   //! Set tolerance for comparison of point coordinates
0054   void SetTol(const double theTol) { myTol = theTol; }
0055 
0056   //! Set current point to search for coincidence
0057   void SetCurrent(const gp_XYZ& theCurPnt)
0058   {
0059     myCurrent   = theCurPnt;
0060     myIsNeedAdd = true;
0061   }
0062 
0063   bool IsNeedAdd() const { return myIsNeedAdd; }
0064 
0065   //! Implementation of inspection method
0066   Standard_EXPORT NCollection_CellFilter_Action Inspect(const int theTarget);
0067 
0068 private:
0069   double        myTol;
0070   bool          myIsNeedAdd;
0071   VectorOfPoint myPoints;
0072   gp_XYZ        myCurrent;
0073 };
0074 
0075 typedef typename BRepExtrema_ProximityDistTool::ProxPnt_Status ProxPnt_Status;
0076 
0077 //! Tool class for computation of the proximity value from one BVH
0078 //! primitive set to another, solving max(min) problem.
0079 //! Handles only edge/edge or face/face cases.
0080 //! This tool is not intended to be used independently, and is integrated
0081 //! in other classes, implementing algorithms based on shape tessellation
0082 //! (BRepExtrema_ShapeProximity and BRepExtrema_SelfIntersection).
0083 //!
0084 //! Please note that algorithm results are approximate and depend greatly
0085 //! on the quality of input tessellation(s).
0086 class BRepExtrema_ProximityValueTool
0087 {
0088 
0089 public:
0090   //! Creates new uninitialized proximity tool.
0091   Standard_EXPORT BRepExtrema_ProximityValueTool();
0092 
0093   //! Creates new proximity tool for the given element sets.
0094   Standard_EXPORT BRepExtrema_ProximityValueTool(
0095     const occ::handle<BRepExtrema_TriangleSet>&   theSet1,
0096     const occ::handle<BRepExtrema_TriangleSet>&   theSet2,
0097     const NCollection_DynamicArray<TopoDS_Shape>& theShapeList1,
0098     const NCollection_DynamicArray<TopoDS_Shape>& theShapeList2);
0099 
0100 public:
0101   //! Loads the given element sets into the proximity tool.
0102   Standard_EXPORT void LoadTriangleSets(const occ::handle<BRepExtrema_TriangleSet>& theSet1,
0103                                         const occ::handle<BRepExtrema_TriangleSet>& theSet2);
0104 
0105   //! Loads the given list of subshapes into the proximity tool.
0106   Standard_EXPORT void LoadShapeLists(const NCollection_DynamicArray<TopoDS_Shape>& theShapeList1,
0107                                       const NCollection_DynamicArray<TopoDS_Shape>& theShapeList2);
0108 
0109   //! Sets number of sample points used for proximity calculation for each shape.
0110   //! If number is less or equal zero, all triangulation nodes are used.
0111   Standard_EXPORT void SetNbSamplePoints(const int theSamples1 = 0, const int theSamples2 = 0);
0112 
0113   //! Performs the computation of the proximity value.
0114   Standard_EXPORT void Perform(double& theTolerance);
0115 
0116   //! Is proximity test completed?
0117   bool IsDone() const { return myIsDone; }
0118 
0119   //! Marks test results as outdated.
0120   void MarkDirty() { myIsDone = false; }
0121 
0122   //! Returns the computed distance.
0123   double Distance() const { return myDistance; }
0124 
0125   //! Returns points on triangles sets, which provide the proximity distance.
0126   void ProximityPoints(gp_Pnt& thePoint1, gp_Pnt& thePoint2) const
0127   {
0128     thePoint1 = myPnt1;
0129     thePoint2 = myPnt2;
0130   }
0131 
0132   //! Returns status of points on triangles sets, which provide the proximity distance.
0133   void ProximityPointsStatus(ProxPnt_Status& thePointStatus1, ProxPnt_Status& thePointStatus2) const
0134   {
0135     thePointStatus1 = myPntStatus1;
0136     thePointStatus2 = myPntStatus2;
0137   }
0138 
0139 private:
0140   //! Gets shape data for further refinement.
0141   bool getInfoForRefinement(const TopoDS_Shape& theShapes,
0142                             TopAbs_ShapeEnum&   theShapeType,
0143                             int&                theNbNodes,
0144                             double&             theStep);
0145 
0146   //! Returns the computed proximity value from first BVH to another one.
0147   double computeProximityDist(const occ::handle<BRepExtrema_TriangleSet>&     theSet1,
0148                               const int                                       theNbSamples1,
0149                               const BVH_Array3d&                              theAddVertices1,
0150                               const NCollection_DynamicArray<ProxPnt_Status>& theAddStatus1,
0151                               const occ::handle<BRepExtrema_TriangleSet>&     theSet2,
0152                               const NCollection_DynamicArray<TopoDS_Shape>&   theShapeList1,
0153                               const NCollection_DynamicArray<TopoDS_Shape>&   theShapeList2,
0154                               BVH_Vec3d&                                      thePoint1,
0155                               BVH_Vec3d&                                      thePoint2,
0156                               ProxPnt_Status&                                 thePointStatus1,
0157                               ProxPnt_Status& thePointStatus2) const;
0158 
0159   //! Gets additional vertices on shapes with refining a coarser one if it's needed.
0160   bool getShapesAdditionalVertices();
0161 
0162   //! Gets additional vertices and their statuses on the edge with the input step.
0163   bool getEdgeAdditionalVertices(const TopoDS_Edge&                        theEdge,
0164                                  const double                              theStep,
0165                                  BVH_Array3d&                              theAddVertices,
0166                                  NCollection_DynamicArray<ProxPnt_Status>& theAddStatuses);
0167 
0168   //! Gets additional vertices and their statuses on the face with the input step (triangle square).
0169   bool getFaceAdditionalVertices(const TopoDS_Face&                        theFace,
0170                                  const double                              theStep,
0171                                  BVH_Array3d&                              theAddVertices,
0172                                  NCollection_DynamicArray<ProxPnt_Status>& theAddStatuses);
0173 
0174   //! Splits the triangle recursively, halving the longest side
0175   //! to the area of the current triangle > input step
0176   void doRecurTrgSplit(const gp_Pnt (&theTrg)[3],
0177                        const ProxPnt_Status (&theEdgesStatus)[3],
0178                        const double                              theTol,
0179                        const double                              theStep,
0180                        BVH_Array3d&                              theAddVertices,
0181                        NCollection_DynamicArray<ProxPnt_Status>& theAddStatuses);
0182 
0183 private:
0184   //! Set of all mesh primitives of the 1st shape.
0185   occ::handle<BRepExtrema_TriangleSet> mySet1;
0186   //! Set of all mesh primitives of the 2nd shape.
0187   occ::handle<BRepExtrema_TriangleSet> mySet2;
0188 
0189   //! List of subshapes of the 1st shape.
0190   NCollection_DynamicArray<TopoDS_Shape> myShapeList1;
0191   //! List of subshapes of the 2nd shape.
0192   NCollection_DynamicArray<TopoDS_Shape> myShapeList2;
0193 
0194   //! The 1st shape.
0195   TopoDS_Shape myShape1;
0196   //! The 2nd shape.
0197   TopoDS_Shape myShape2;
0198 
0199   BVH_Array3d myAddVertices1; //!< Additional vertices on the 1st shape if its mesh is coarser.
0200   BVH_Array3d myAddVertices2; //!< Additional vertices on the 2nd shape if its mesh is coarser.
0201 
0202   // clang-format off
0203   NCollection_DynamicArray<ProxPnt_Status> myAddStatus1; //!< Status of additional vertices on the 1st shape.
0204   NCollection_DynamicArray<ProxPnt_Status> myAddStatus2; //!< Status of additional vertices on the 2nd shape.
0205   // clang-format on
0206 
0207   bool myIsInitS1; //!< Is the 1st shape initialized?
0208   bool myIsInitS2; //!< Is the 2nd shape initialized?
0209 
0210   bool myIsRefinementRequired1; //!< Flag about the need to refine the 1st shape.
0211   bool myIsRefinementRequired2; //!< Flag about the need to refine the 2nd shape.
0212 
0213   int myNbNodes1; //!< Number of nodes in triangulation of the 1st shape.
0214   int myNbNodes2; //!< Number of nodes in triangulation of the 2nd shape.
0215 
0216   double myStep1; //!< Step for getting vertices on the 1st shape.
0217   double myStep2; //!< Step for getting vertices on the 2nd shape.
0218 
0219   NCollection_CellFilter<BRepExtrema_VertexInspector> myCells;
0220   BRepExtrema_VertexInspector                         myInspector;
0221 
0222   TopAbs_ShapeEnum myShapeType1; //!< 1st shape type.
0223   TopAbs_ShapeEnum myShapeType2; //!< 2nd shape type.
0224 
0225   double myDistance; //!< Distance
0226   bool   myIsDone;   //!< State of the algorithm
0227 
0228   int myNbSamples1; //!< Number of samples points on the first shape
0229   int myNbSamples2; //!< Number of samples points on the second shape
0230 
0231   //! Proximity points
0232   gp_Pnt myPnt1, myPnt2;
0233 
0234   //! Proximity points' status
0235   ProxPnt_Status myPntStatus1, myPntStatus2;
0236 };
0237 
0238 #endif // _BRepExtrema_ProximityValueTool_HeaderFile