Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-22 08:57:10

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_ProximityDistTool_HeaderFile
0017 #define _BRepExtrema_ProximityDistTool_HeaderFile
0018 
0019 #include <BRepExtrema_ElementFilter.hxx>
0020 #include <NCollection_DataMap.hxx>
0021 #include <TColStd_PackedMapOfInteger.hxx>
0022 #include <BRepExtrema_TriangleSet.hxx>
0023 #include <BVH_Distance.hxx>
0024 #include <BVH_Tools.hxx>
0025 #include <Poly_Triangulation.hxx>
0026 
0027 //! Tool class for computation the proximity distance from first
0028 //! primitive set to second one that is the maximal from minimum
0029 //! perpendicular distances. If no perpendicular distance is found, the
0030 //! minimum distance will be returned.
0031 //! This tool is not intended to be used independently, and is integrated
0032 //! in other classes, implementing algorithms based on shape tessellation
0033 //! (BRepExtrema_ProximityValueTool).
0034 //!
0035 //! Please note that algorithm results are approximate and depend greatly
0036 //! on the quality of input tessellation(s).
0037 class BRepExtrema_ProximityDistTool
0038     : public BVH_Distance<double, 3, BVH_Vec3d, BRepExtrema_TriangleSet>
0039 {
0040 public:
0041   typedef typename BVH_Tools<double, 3>::BVH_PrjStateInTriangle BVH_PrjState;
0042 
0043   enum ProxPnt_Status
0044   {
0045     ProxPnt_Status_BORDER,
0046     ProxPnt_Status_MIDDLE,
0047     ProxPnt_Status_UNKNOWN
0048   };
0049 
0050 public:
0051   //! Struct with information about projection point state from 2nd BVH,
0052   //! providing proximity point of 2nd shape
0053   struct PrjState
0054   {
0055     PrjState()
0056         : myTrgIdx(0),
0057           myPrjState(BVH_PrjState::BVH_PrjStateInTriangle_INNER),
0058           myNumberOfFirstNode(0),
0059           myNumberOfLastNode(0)
0060     {
0061     }
0062 
0063     PrjState(const int          theTrgIdx,
0064              const BVH_PrjState thePrjState,
0065              const int          theNumberOfFirstNode,
0066              const int          theNumberOfLastNode)
0067         : myTrgIdx(theTrgIdx),
0068           myPrjState(thePrjState),
0069           myNumberOfFirstNode(theNumberOfFirstNode),
0070           myNumberOfLastNode(theNumberOfLastNode)
0071     {
0072     }
0073 
0074     int GetTrgIdx() const { return myTrgIdx; }
0075 
0076     BVH_PrjState GetPrjState() const { return myPrjState; }
0077 
0078     int GetNumberOfFirstNode() const { return myNumberOfFirstNode; }
0079 
0080     int GetNumberOfLastNode() const { return myNumberOfLastNode; }
0081 
0082   private:
0083     int          myTrgIdx;   //!< Index of triangle on which the projection is located
0084     BVH_PrjState myPrjState; //!< Position of a projection on the triangle (vertex, edge, inner)
0085                              // clang-format off
0086     int myNumberOfFirstNode; //!< The 1st vtx of the triangle edge on which the projection is located
0087     int myNumberOfLastNode; //!< The 2nd vtx of the triangle edge on which the projection is located
0088                              // clang-format on
0089   };
0090 
0091 public:
0092   //! Creates new uninitialized tool.
0093   Standard_EXPORT BRepExtrema_ProximityDistTool();
0094 
0095   //! Creates new tool for the given element sets.
0096   Standard_EXPORT BRepExtrema_ProximityDistTool(
0097     const occ::handle<BRepExtrema_TriangleSet>&     theSet1,
0098     const int                                       theNbSamples1,
0099     const BVH_Array3d&                              theAddVertices1,
0100     const NCollection_DynamicArray<ProxPnt_Status>& theAddStatus1,
0101     const occ::handle<BRepExtrema_TriangleSet>&     theSet2,
0102     const NCollection_DynamicArray<TopoDS_Shape>&   theShapeList1,
0103     const NCollection_DynamicArray<TopoDS_Shape>&   theShapeList2);
0104 
0105 public:
0106   //! Loads the given element sets into the tool.
0107   Standard_EXPORT void LoadTriangleSets(const occ::handle<BRepExtrema_TriangleSet>& theSet1,
0108                                         const occ::handle<BRepExtrema_TriangleSet>& theSet2);
0109 
0110   //! Loads the given list of subshapes into the tool.
0111   Standard_EXPORT void LoadShapeLists(const NCollection_DynamicArray<TopoDS_Shape>& theShapeList1,
0112                                       const NCollection_DynamicArray<TopoDS_Shape>& theShapeList2);
0113 
0114   //! Loads given additional vertices and their statuses.
0115   void LoadAdditionalPointsFirstSet(const BVH_Array3d&                              theAddVertices1,
0116                                     const NCollection_DynamicArray<ProxPnt_Status>& theAddStatus1);
0117 
0118   //! Performs searching of the proximity distance.
0119   Standard_EXPORT void Perform();
0120 
0121 public: //! @name Reject/Accept implementations
0122   //! Defines the rules for node rejection by bounding box.
0123   Standard_EXPORT bool RejectNode(const BVH_Vec3d& theCornerMin,
0124                                   const BVH_Vec3d& theCornerMax,
0125                                   double&          theMetric) const override;
0126 
0127   //! Defines the rules for leaf acceptance.
0128   Standard_EXPORT bool Accept(const int theSgmIdx, const double&) override;
0129 
0130 public:
0131   //! Returns true if the node is on the boarder.
0132   Standard_EXPORT static bool IsNodeOnBorder(const int                              theNodeIdx,
0133                                              const occ::handle<Poly_Triangulation>& theTr);
0134 
0135   //! Returns true if the edge is on the boarder.
0136   Standard_EXPORT static bool IsEdgeOnBorder(const int theTrgIdx,
0137                                              const int theFirstEdgeNodeIdx,
0138                                              const int theSecondEdgeNodeIdx,
0139                                              const occ::handle<Poly_Triangulation>& theTr);
0140 
0141 public:
0142   //! Returns points on triangles sets, which provide the proximity distance.
0143   void ProximityPoints(BVH_Vec3d& thePoint1, BVH_Vec3d& thePoint2) const
0144   {
0145     thePoint1 = myPnt1;
0146     thePoint2 = myPnt2;
0147   }
0148 
0149   //! Returns status of points on triangles sets, which provide the proximity distance.
0150   void ProximityPointsStatus(ProxPnt_Status& thePointStatus1, ProxPnt_Status& thePointStatus2) const
0151   {
0152     thePointStatus1 = myPntStatus1;
0153     thePointStatus2 = myPntStatus2;
0154   }
0155 
0156   //! Returns the computed distance
0157   double ProximityDistance() const { return myProxDist; }
0158 
0159 protected:
0160   //! Computes the distance between object and BVH tree.
0161   Standard_EXPORT double ComputeDistance();
0162 
0163   //! Defines the status of proximity points.
0164   Standard_EXPORT void DefineStatusProxPnt();
0165 
0166 private:
0167   //! Goes through vertices from the 1st set.
0168   void goThroughtSet1(const BVH_Array3d& aVertices1, const bool theIsAdditionalSet);
0169 
0170   //! Defines the status of proximity point from 1st BVH.
0171   void defineStatusProxPnt1();
0172 
0173   //! Defines the status of proximity point from 2nd BVH.
0174   void defineStatusProxPnt2();
0175 
0176 protected:
0177   // clang-format off
0178   double myMinDistance; //!< Minimal distance from point to BVH, could be not equal to myDistance
0179   // clang-format on
0180   BVH_Vec3d myMinDistPoint; //!< Point on BVH providing the minimal distance
0181 
0182   BVH_Vec3d myExtremaPoint; //!< Point on BVH providing the extrema
0183 
0184   double myProxDist; //!< Proximity distance
0185 
0186   //! Proximity points
0187   BVH_Vec3d myPnt1, myPnt2;
0188 
0189   //! Proximity points' status
0190   ProxPnt_Status myPntStatus1, myPntStatus2;
0191 
0192 private:
0193   //! Set of all mesh elements (triangles) of the 1st shape.
0194   occ::handle<BRepExtrema_TriangleSet> mySet1;
0195   //! Set of all mesh elements (triangles) of the 2nd shape.
0196   occ::handle<BRepExtrema_TriangleSet> mySet2;
0197 
0198   //! List of subshapes of the 1st shape.
0199   NCollection_DynamicArray<TopoDS_Shape> myShapeList1;
0200   //! List of subshapes of the 2nd shape.
0201   NCollection_DynamicArray<TopoDS_Shape> myShapeList2;
0202 
0203   int myNbSamples1; //!< Number of samples points on the first shape
0204 
0205   //! Is vertex corresponding to proximity point of 1st shape from additional set
0206   int         myIsProxVtx1FromAddSet;
0207   BVH_Array3d myAddVertices1; //!< Additional vertices on the 1st shape
0208                               // clang-format off
0209   NCollection_DynamicArray<ProxPnt_Status> myAddStatus1; //!< Status of additional vertices on the 1st shape
0210                               // clang-format on
0211 
0212   //! Vertex index from 1st BVH corresponding to proximity point of 1st shape
0213   int myProxVtxIdx1;
0214 
0215   //! Information of projection point state from 2nd BVH providing proximity point of 2nd shape
0216   PrjState myProxPrjState;
0217 
0218   //! Information of projection point state from 2nd BVH providing the extrema
0219   PrjState myExtPrjState;
0220 
0221   //! Information of projection point state from 2nd BVH providing the minimal distance
0222   PrjState myMinPrjState;
0223 };
0224 
0225 #endif // _BRepExtrema_ProximityDistTool_HeaderFile