1 // Created on: 2015-04-26
2 // Created by: Denis BOGOLEPOV
3 // Copyright (c) 2015 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #ifndef _BRepExtrema_SelfIntersection_HeaderFile
17 #define _BRepExtrema_SelfIntersection_HeaderFile
19 #include <BRepExtrema_OverlapTool.hxx>
21 //! Tool class for detection of self-sections in the given shape.
22 //! This class is based on BRepExtrema_OverlapTool and thus uses
23 //! shape tessellation to detect incorrect mesh fragments (pairs
24 //! of overlapped triangles belonging to different faces). Thus,
25 //! a result depends critically on the quality of mesh generator
26 //! (e.g., BREP mesh is not always a good choice, because it can
27 //! contain gaps between adjacent face triangulations, which may
28 //! not share vertices on common edge; thus false overlap can be
29 //! detected). As a result, this tool can be used for relatively
30 //! fast approximated test which provides sub-set of potentially
32 class BRepExtrema_SelfIntersection : public BRepExtrema_ElementFilter
34 friend class BRepExtrema_OverlapTool;
38 //! Creates unitialized self-intersection tool.
39 Standard_EXPORT BRepExtrema_SelfIntersection (const Standard_Real theTolerance = 0.0);
41 //! Creates self-intersection tool for the given shape.
42 Standard_EXPORT BRepExtrema_SelfIntersection (const TopoDS_Shape& theShape, const Standard_Real theTolerance = 0.0);
46 //! Returns tolerance value used for self-intersection test.
47 Standard_Real Tolerance() const
52 //! Sets tolerance value used for self-intersection test.
53 void SetTolerance (const Standard_Real theTolerance)
55 myTolerance = theTolerance;
58 //! Loads shape for detection of self-intersections.
59 Standard_EXPORT Standard_Boolean LoadShape (const TopoDS_Shape& theShape);
61 //! Performs detection of self-intersections.
62 Standard_EXPORT void Perform();
64 //! True if the detection is completed.
65 Standard_Boolean IsDone() const
67 return myOverlapTool.IsDone();
70 //! Returns set of IDs of overlapped sub-shapes (started from 0).
71 const BRepExtrema_MapOfIntegerPackedMapOfInteger& OverlapElements() const
73 return myOverlapTool.OverlapSubShapes1();
76 //! Returns sub-shape from the shape for the given index (started from 0).
77 const TopoDS_Face& GetSubShape (const Standard_Integer theID) const
79 return myFaceList.Value (theID);
82 //! Returns set of all the face triangles of the shape.
83 const Handle(BRepExtrema_TriangleSet)& ElementSet() const
88 #ifdef OVERLAP_TOOL_OUTPUT_TRIANGLES
89 //! Returns set of overlapped mesh elements (only triangles).
90 const TColStd_PackedMapOfInteger& OverlapTriangles() const
92 return myOverlapTool.OverlapTriangles1();
98 //! Filter out correct adjacent mesh elements.
99 Standard_EXPORT virtual BRepExtrema_ElementFilter::FilterResult PreCheckElements (const Standard_Integer theIndex1,
100 const Standard_Integer theIndex2);
102 //! Checks if the given triangles have only single common vertex.
103 Standard_EXPORT BRepExtrema_ElementFilter::FilterResult isRegularSharedVertex (const BVH_Vec3d& theSharedVert,
104 const BVH_Vec3d& theTrng1Vtxs1,
105 const BVH_Vec3d& theTrng1Vtxs2,
106 const BVH_Vec3d& theTrng2Vtxs1,
107 const BVH_Vec3d& theTrng2Vtxs2);
109 //! Checks if the given triangles have only single common edge.
110 Standard_EXPORT BRepExtrema_ElementFilter::FilterResult isRegularSharedEdge (const BVH_Vec3d& theTrng1Vtxs0,
111 const BVH_Vec3d& theTrng1Vtxs1,
112 const BVH_Vec3d& theTrng1Vtxs2,
113 const BVH_Vec3d& theTrng2Vtxs2);
117 //! Self-intersection tolerance.
118 Standard_Real myTolerance;
120 //! Is the input shape inited?
121 Standard_Boolean myIsInit;
123 //! List of triangulated faces of the shape.
124 BRepExtrema_ShapeList myFaceList;
126 //! Set of all the face triangles of the shape.
127 Handle(BRepExtrema_TriangleSet) myElementSet;
129 //! Overlap tool used for self-intersection test.
130 BRepExtrema_OverlapTool myOverlapTool;
134 #endif // _BRepExtrema_SelfIntersection_HeaderFile