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_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_Vector<gp_XYZ> VectorOfPoint;
0025 
0026 //! Class BRepExtrema_VertexInspector
0027 //!   derived from NCollection_CellFilter_InspectorXYZ
0028 //!   This class define the Inspector interface for CellFilter algorithm,
0029 //!   working with gp_XYZ points in 3d space.
0030 //!   Used in search of coincidence points with a certain tolerance.
0031 class BRepExtrema_VertexInspector : public NCollection_CellFilter_InspectorXYZ
0032 {
0033 public:
0034   typedef Standard_Integer Target;
0035 
0036   //! Constructor; remembers the tolerance
0037   BRepExtrema_VertexInspector()
0038   : myTol (Precision::SquareConfusion()),
0039     myIsNeedAdd (Standard_True)
0040   {}
0041 
0042   //! Keep the points used for comparison
0043   void Add (const gp_XYZ& thePnt)
0044   {
0045     myPoints.Append (thePnt);
0046   }
0047 
0048   //! Set tolerance for comparison of point coordinates
0049   void SetTol (const Standard_Real theTol)
0050   {
0051     myTol = theTol;
0052   }
0053 
0054   //! Set current point to search for coincidence
0055   void SetCurrent (const gp_XYZ& theCurPnt)
0056   {
0057     myCurrent = theCurPnt;
0058     myIsNeedAdd = Standard_True;
0059   }
0060 
0061   Standard_Boolean IsNeedAdd()
0062   {
0063     return myIsNeedAdd;
0064   }
0065 
0066   //! Implementation of inspection method
0067   Standard_EXPORT NCollection_CellFilter_Action Inspect (const Standard_Integer theTarget);
0068 
0069 private:
0070   Standard_Real myTol;
0071   Standard_Boolean myIsNeedAdd;
0072   VectorOfPoint myPoints;
0073   gp_XYZ myCurrent;
0074 };
0075 
0076 typedef NCollection_CellFilter<BRepExtrema_VertexInspector> BRepExtrema_CellFilter;
0077 typedef typename BRepExtrema_ProximityDistTool::ProxPnt_Status ProxPnt_Status;
0078 
0079 //! Tool class for computation of the proximity value from one BVH
0080 //! primitive set to another, solving max(min) problem.
0081 //! Handles only edge/edge or face/face cases.
0082 //! This tool is not intended to be used independently, and is integrated
0083 //! in other classes, implementing algorithms based on shape tessellation
0084 //! (BRepExtrema_ShapeProximity and BRepExtrema_SelfIntersection).
0085 //! 
0086 //! Please note that algorithm results are approximate and depend greatly
0087 //! on the quality of input tessellation(s).
0088 class BRepExtrema_ProximityValueTool
0089 {
0090 
0091 public:
0092 
0093   //! Creates new unitialized proximity tool.
0094   Standard_EXPORT BRepExtrema_ProximityValueTool();
0095 
0096   //! Creates new proximity tool for the given element sets.
0097   Standard_EXPORT BRepExtrema_ProximityValueTool (const Handle(BRepExtrema_TriangleSet)& theSet1,
0098                                                   const Handle(BRepExtrema_TriangleSet)& theSet2,
0099                                                   const BRepExtrema_ShapeList& theShapeList1,
0100                                                   const BRepExtrema_ShapeList& theShapeList2);
0101 
0102 public:
0103 
0104   //! Loads the given element sets into the proximity tool.
0105   Standard_EXPORT void LoadTriangleSets (const Handle (BRepExtrema_TriangleSet)& theSet1,
0106                                          const Handle (BRepExtrema_TriangleSet)& theSet2);
0107 
0108   //! Loads the given list of subshapes into the proximity tool.
0109   Standard_EXPORT void LoadShapeLists (const BRepExtrema_ShapeList& theShapeList1,
0110                                        const BRepExtrema_ShapeList& theShapeList2);
0111 
0112   //! Sets number of sample points used for proximity calculation for each shape.
0113   //! If number is less or equal zero, all triangulation nodes are used.
0114   Standard_EXPORT void SetNbSamplePoints (const Standard_Integer theSamples1 = 0,
0115                                           const Standard_Integer theSamples2 = 0);
0116 
0117   //! Performs the computation of the proximity value.
0118   Standard_EXPORT void Perform (Standard_Real& theTolerance);
0119 
0120   //! Is proximity test completed?
0121   Standard_Boolean IsDone() const { return myIsDone; }
0122 
0123   //! Marks test results as outdated.
0124   void MarkDirty() { myIsDone = Standard_False; }
0125 
0126   //! Returns the computed distance.
0127   Standard_Real Distance() const { return myDistance; }
0128 
0129   //! Returns points on triangles sets, which provide the proximity distance.
0130   void ProximityPoints(gp_Pnt& thePoint1, gp_Pnt& thePoint2) const
0131   {
0132     thePoint1 = myPnt1;
0133     thePoint2 = myPnt2;
0134   }
0135 
0136   //! Returns status of points on triangles sets, which provide the proximity distance.
0137   void ProximityPointsStatus (ProxPnt_Status& thePointStatus1, ProxPnt_Status& thePointStatus2) const
0138   {
0139     thePointStatus1 = myPntStatus1;
0140     thePointStatus2 = myPntStatus2;
0141   }
0142 
0143 private:
0144 
0145   //! Gets shape data for further refinement.
0146   Standard_Boolean getInfoForRefinement (const TopoDS_Shape& theShapes,
0147                                          TopAbs_ShapeEnum& theShapeType,
0148                                          Standard_Integer& theNbNodes,
0149                                          Standard_Real& theStep);
0150 
0151   //! Returns the computed proximity value from first BVH to another one.
0152   Standard_Real computeProximityDist (const Handle(BRepExtrema_TriangleSet)& theSet1,
0153                                       const Standard_Integer theNbSamples1,
0154                                       const BVH_Array3d& theAddVertices1,
0155                                       const NCollection_Vector<ProxPnt_Status>& theAddStatus1,
0156                                       const Handle(BRepExtrema_TriangleSet)& theSet2,
0157                                       const BRepExtrema_ShapeList& theShapeList1,
0158                                       const BRepExtrema_ShapeList& theShapeList2,
0159                                       BVH_Vec3d& thePoint1,
0160                                       BVH_Vec3d& thePoint2,
0161                                       ProxPnt_Status& thePointStatus1,
0162                                       ProxPnt_Status& thePointStatus2) const;
0163 
0164   //! Gets additional vertices on shapes with refining a coarser one if it's needed.
0165   Standard_Boolean getShapesAdditionalVertices();
0166 
0167   //! Gets additional vertices and their statuses on the edge with the input step.
0168   Standard_Boolean getEdgeAdditionalVertices (const TopoDS_Edge& theEdge,
0169                                               const Standard_Real theStep,
0170                                               BVH_Array3d& theAddVertices,
0171                                               NCollection_Vector<ProxPnt_Status>& theAddStatuses);
0172 
0173   //! Gets additional vertices and their statuses on the face with the input step (triangle square).
0174   Standard_Boolean getFaceAdditionalVertices (const TopoDS_Face& theFace,
0175                                               const Standard_Real theStep,
0176                                               BVH_Array3d& theAddVertices,
0177                                               NCollection_Vector<ProxPnt_Status>& theAddStatuses);
0178 
0179   //! Splits the triangle recursively, halving the longest side
0180   //! to the area of ​​the current triangle > input step
0181   void doRecurTrgSplit (const gp_Pnt (&theTrg)[3],
0182                         const ProxPnt_Status (&theEdgesStatus)[3],
0183                         const Standard_Real theTol,
0184                         const Standard_Real theStep,
0185                         BVH_Array3d& theAddVertices,
0186                         NCollection_Vector<ProxPnt_Status>& theAddStatuses);
0187 private:
0188 
0189   //! Set of all mesh primitives of the 1st shape.
0190   Handle(BRepExtrema_TriangleSet) mySet1;
0191   //! Set of all mesh primitives of the 2nd shape.
0192   Handle(BRepExtrema_TriangleSet) mySet2;
0193 
0194   //! List of subshapes of the 1st shape.
0195   BRepExtrema_ShapeList myShapeList1;
0196   //! List of subshapes of the 2nd shape.
0197   BRepExtrema_ShapeList myShapeList2;
0198 
0199   //! The 1st shape.
0200   TopoDS_Shape myShape1;
0201   //! The 2nd shape.
0202   TopoDS_Shape myShape2;
0203 
0204   BVH_Array3d myAddVertices1; //!< Additional vertices on the 1st shape if its mesh is coarser.
0205   BVH_Array3d myAddVertices2; //!< Additional vertices on the 2nd shape if its mesh is coarser.
0206 
0207   NCollection_Vector<ProxPnt_Status> myAddStatus1; //!< Status of additional vertices on the 1st shape.
0208   NCollection_Vector<ProxPnt_Status> myAddStatus2; //!< Status of additional vertices on the 2nd shape.
0209 
0210   Standard_Boolean myIsInitS1; //!< Is the 1st shape initialized?
0211   Standard_Boolean myIsInitS2; //!< Is the 2nd shape initialized?
0212 
0213   Standard_Boolean myIsRefinementRequired1; //!< Flag about the need to refine the 1st shape.
0214   Standard_Boolean myIsRefinementRequired2; //!< Flag about the need to refine the 2nd shape.
0215 
0216   Standard_Integer myNbNodes1; //!< Number of nodes in triangulation of the 1st shape.
0217   Standard_Integer myNbNodes2; //!< Number of nodes in triangulation of the 2nd shape.
0218 
0219   Standard_Real myStep1; //!< Step for getting vertices on the 1st shape.
0220   Standard_Real myStep2; //!< Step for getting vertices on the 2nd shape.
0221 
0222   BRepExtrema_CellFilter myCells;
0223   BRepExtrema_VertexInspector myInspector;
0224 
0225   TopAbs_ShapeEnum myShapeType1; //!< 1st shape type.
0226   TopAbs_ShapeEnum myShapeType2; //!< 2nd shape type.
0227 
0228   Standard_Real myDistance;  //!< Distance
0229   Standard_Boolean myIsDone; //!< State of the algorithm
0230 
0231   Standard_Integer myNbSamples1; //!< Number of samples points on the first shape
0232   Standard_Integer myNbSamples2; //!< Number of samples points on the second shape
0233 
0234   //! Proximity points
0235   gp_Pnt myPnt1, myPnt2;
0236 
0237   //! Proximity points' status
0238   ProxPnt_Status myPntStatus1, myPntStatus2;
0239 
0240 };
0241 
0242 #endif // _BRepExtrema_ProximityValueTool_HeaderFile