Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-16 09:16:34

0001 // Created on: 2015-04-26
0002 // Created by: Denis BOGOLEPOV
0003 // Copyright (c) 2015 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_OverlapTool_HeaderFile
0017 #define _BRepExtrema_OverlapTool_HeaderFile
0018 
0019 #include <BRepExtrema_TriangleSet.hxx>
0020 #include <BRepExtrema_ElementFilter.hxx>
0021 #include <NCollection_DataMap.hxx>
0022 #include <TColStd_PackedMapOfInteger.hxx>
0023 #include <BVH_Traverse.hxx>
0024 
0025 //! Enables storing of individual overlapped triangles (useful for debug).
0026 // #define OVERLAP_TOOL_OUTPUT_TRIANGLES
0027 
0028 //! Tool class for for detection of overlapping of two BVH primitive sets.
0029 //! This tool is not intended to be used independently, and is integrated
0030 //! in other classes, implementing algorithms based on shape tessellation
0031 //! (BRepExtrema_ShapeProximity and BRepExtrema_SelfIntersection).
0032 //!
0033 //! Note that input element sets may correspond to different shapes or to
0034 //! the same shape. In first case, tessellations of two given shapes will
0035 //! be tested for intersection (or overlapping, if tolerance is not zero).
0036 //! In second case, tessellation of single shape will be tested for self-
0037 //! intersections. Please note that algorithm results are approximate and
0038 //! depend greatly on the quality of input tessellation(s).
0039 class BRepExtrema_OverlapTool : public BVH_PairTraverse<double, 3>
0040 {
0041 public:
0042   //! Creates new uninitialized overlap tool.
0043   BRepExtrema_OverlapTool();
0044 
0045   //! Creates new overlap tool for the given element sets.
0046   BRepExtrema_OverlapTool(const occ::handle<BRepExtrema_TriangleSet>& theSet1,
0047                           const occ::handle<BRepExtrema_TriangleSet>& theSet2);
0048 
0049 public:
0050   //! Loads the given element sets into the overlap tool.
0051   void LoadTriangleSets(const occ::handle<BRepExtrema_TriangleSet>& theSet1,
0052                         const occ::handle<BRepExtrema_TriangleSet>& theSet2);
0053 
0054   //! Performs searching of overlapped mesh elements.
0055   void Perform(const double theTolerance = 0.0);
0056 
0057   //! Is overlap test completed?
0058   bool IsDone() const { return myIsDone; }
0059 
0060   //! Marks test results as outdated.
0061   void MarkDirty() { myIsDone = false; }
0062 
0063   //! Returns set of overlapped sub-shapes of 1st shape (currently only faces are detected).
0064   const NCollection_DataMap<int, TColStd_PackedMapOfInteger>& OverlapSubShapes1() const
0065   {
0066     return myOverlapSubShapes1;
0067   }
0068 
0069   //! Returns set of overlapped sub-shapes of 2nd shape (currently only faces are detected).
0070   const NCollection_DataMap<int, TColStd_PackedMapOfInteger>& OverlapSubShapes2() const
0071   {
0072     return myOverlapSubShapes2;
0073   }
0074 
0075 #ifdef OVERLAP_TOOL_OUTPUT_TRIANGLES
0076   //! Returns set of overlapped triangles from the 1st shape (for debug).
0077   const TColStd_PackedMapOfInteger& OverlapTriangles1() const { return myOverlapTriangles1; }
0078 
0079   //! Returns set of overlapped triangles from the 2nd shape (for debug).
0080   const TColStd_PackedMapOfInteger& OverlapTriangles2() const { return myOverlapTriangles2; }
0081 #endif
0082 
0083   //! Sets filtering tool for preliminary checking pairs of mesh elements.
0084   void SetElementFilter(BRepExtrema_ElementFilter* theFilter) { myFilter = theFilter; }
0085 
0086 public: //! @name Reject/Accept implementations
0087   //! Defines the rules for node rejection by bounding box
0088   Standard_EXPORT bool RejectNode(const BVH_Vec3d& theCornerMin1,
0089                                   const BVH_Vec3d& theCornerMax1,
0090                                   const BVH_Vec3d& theCornerMin2,
0091                                   const BVH_Vec3d& theCornerMax2,
0092                                   double&) const override;
0093   //! Defines the rules for leaf acceptance
0094   Standard_EXPORT bool Accept(const int theLeaf1, const int theLeaf2) override;
0095 
0096 protected:
0097   //! Performs narrow-phase of overlap test (exact intersection).
0098   void intersectTrianglesExact(const int theTrgIdx1, const int theTrgIdx2);
0099 
0100   //! Performs narrow-phase of overlap test (intersection with non-zero tolerance).
0101   void intersectTrianglesToler(const int theTrgIdx1, const int theTrgIdx2, const double theToler);
0102 
0103 private:
0104   //! Set of all mesh elements (triangles) of the 1st shape.
0105   occ::handle<BRepExtrema_TriangleSet> mySet1;
0106   //! Set of all mesh elements (triangles) of the 2nd shape.
0107   occ::handle<BRepExtrema_TriangleSet> mySet2;
0108 
0109   //! Filter for preliminary checking pairs of mesh elements.
0110   BRepExtrema_ElementFilter* myFilter;
0111 
0112   //! Resulted set of overlapped sub-shapes of 1st shape (only faces).
0113   NCollection_DataMap<int, TColStd_PackedMapOfInteger> myOverlapSubShapes1;
0114   //! Resulted set of overlapped sub-shapes of 2nd shape (only faces).
0115   NCollection_DataMap<int, TColStd_PackedMapOfInteger> myOverlapSubShapes2;
0116 
0117 #ifdef OVERLAP_TOOL_OUTPUT_TRIANGLES
0118   //! Set of overlapped elements from the 1st shape (only triangles).
0119   TColStd_PackedMapOfInteger myOverlapTriangles1;
0120   //! Set of overlapped elements from the 2nd shape (only triangles).
0121   TColStd_PackedMapOfInteger myOverlapTriangles2;
0122 #endif
0123 
0124   //! Is overlap test test completed?
0125   bool myIsDone;
0126 
0127   double myTolerance;
0128 };
0129 
0130 #endif // _BRepExtrema_OverlapTool_HeaderFile