Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-24 09:15:14

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_SelfIntersection_HeaderFile
0017 #define _BRepExtrema_SelfIntersection_HeaderFile
0018 
0019 #include <BRepExtrema_OverlapTool.hxx>
0020 
0021 #include <TopoDS.hxx>
0022 
0023 //! Tool class for detection of self-sections in the given shape.
0024 //! This class is based on BRepExtrema_OverlapTool and thus uses
0025 //! shape tessellation to detect incorrect mesh fragments (pairs
0026 //! of overlapped triangles belonging to different faces). Thus,
0027 //! a result depends critically on the quality of mesh generator
0028 //! (e.g., BREP mesh is not always a good choice, because it can
0029 //! contain gaps between adjacent face triangulations, which may
0030 //! not share vertices on common edge; thus false overlap can be
0031 //! detected). As a result, this tool can be used for relatively
0032 //! fast approximated test which provides sub-set of potentially
0033 //! overlapped faces.
0034 class BRepExtrema_SelfIntersection : public BRepExtrema_ElementFilter
0035 {
0036   friend class BRepExtrema_OverlapTool;
0037 
0038 public:
0039   //! Creates uninitialized self-intersection tool.
0040   Standard_EXPORT BRepExtrema_SelfIntersection(const double theTolerance = 0.0);
0041 
0042   //! Creates self-intersection tool for the given shape.
0043   Standard_EXPORT BRepExtrema_SelfIntersection(const TopoDS_Shape& theShape,
0044                                                const double        theTolerance = 0.0);
0045 
0046 public:
0047   //! Returns tolerance value used for self-intersection test.
0048   double Tolerance() const { return myTolerance; }
0049 
0050   //! Sets tolerance value used for self-intersection test.
0051   void SetTolerance(const double theTolerance) { myTolerance = theTolerance; }
0052 
0053   //! Loads shape for detection of self-intersections.
0054   Standard_EXPORT bool LoadShape(const TopoDS_Shape& theShape);
0055 
0056   //! Performs detection of self-intersections.
0057   Standard_EXPORT void Perform();
0058 
0059   //! True if the detection is completed.
0060   bool IsDone() const { return myOverlapTool.IsDone(); }
0061 
0062   //! Returns set of IDs of overlapped sub-shapes (started from 0).
0063   const NCollection_DataMap<int, TColStd_PackedMapOfInteger>& OverlapElements() const
0064   {
0065     return myOverlapTool.OverlapSubShapes1();
0066   }
0067 
0068   //! Returns sub-shape from the shape for the given index (started from 0).
0069   const TopoDS_Face& GetSubShape(const int theID) const
0070   {
0071     return TopoDS::Face(myFaceList.Value(theID));
0072   }
0073 
0074   //! Returns set of all the face triangles of the shape.
0075   const occ::handle<BRepExtrema_TriangleSet>& ElementSet() const { return myElementSet; }
0076 
0077 #ifdef OVERLAP_TOOL_OUTPUT_TRIANGLES
0078   //! Returns set of overlapped mesh elements (only triangles).
0079   const TColStd_PackedMapOfInteger& OverlapTriangles() const
0080   {
0081     return myOverlapTool.OverlapTriangles1();
0082   }
0083 #endif
0084 
0085 protected:
0086   //! Filter out correct adjacent mesh elements.
0087   Standard_EXPORT BRepExtrema_ElementFilter::FilterResult PreCheckElements(
0088     const int theIndex1,
0089     const int theIndex2) override;
0090 
0091   //! Checks if the given triangles have only single common vertex.
0092   Standard_EXPORT BRepExtrema_ElementFilter::FilterResult isRegularSharedVertex(
0093     const BVH_Vec3d& theSharedVert,
0094     const BVH_Vec3d& theTrng1Vtxs1,
0095     const BVH_Vec3d& theTrng1Vtxs2,
0096     const BVH_Vec3d& theTrng2Vtxs1,
0097     const BVH_Vec3d& theTrng2Vtxs2);
0098 
0099   //! Checks if the given triangles have only single common edge.
0100   Standard_EXPORT BRepExtrema_ElementFilter::FilterResult isRegularSharedEdge(
0101     const BVH_Vec3d& theTrng1Vtxs0,
0102     const BVH_Vec3d& theTrng1Vtxs1,
0103     const BVH_Vec3d& theTrng1Vtxs2,
0104     const BVH_Vec3d& theTrng2Vtxs2);
0105 
0106 private:
0107   //! Self-intersection tolerance.
0108   double myTolerance;
0109 
0110   //! Is the input shape inited?
0111   bool myIsInit;
0112 
0113   //! List of triangulated faces of the shape.
0114   NCollection_DynamicArray<TopoDS_Shape> myFaceList;
0115 
0116   //! Set of all the face triangles of the shape.
0117   occ::handle<BRepExtrema_TriangleSet> myElementSet;
0118 
0119   //! Overlap tool used for self-intersection test.
0120   BRepExtrema_OverlapTool myOverlapTool;
0121 };
0122 
0123 #endif // _BRepExtrema_SelfIntersection_HeaderFile