Back to home page

EIC code displayed by LXR

 
 

    


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