Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:03:10

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