0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[occt.git] / src / BRepExtrema / BRepExtrema_SelfIntersection.hxx
1 // Created on: 2015-04-26
2 // Created by: Denis BOGOLEPOV
3 // Copyright (c) 2015 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
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.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #ifndef _BRepExtrema_SelfIntersection_HeaderFile
17 #define _BRepExtrema_SelfIntersection_HeaderFile
18
19 #include <BRepExtrema_OverlapTool.hxx>
20
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
31 //! overlapped faces.
32 class BRepExtrema_SelfIntersection : public BRepExtrema_ElementFilter
33 {
34   friend class BRepExtrema_OverlapTool;
35
36 public:
37
38   //! Creates unitialized self-intersection tool.
39   Standard_EXPORT BRepExtrema_SelfIntersection (const Standard_Real theTolerance = 0.0);
40
41   //! Creates self-intersection tool for the given shape.
42   Standard_EXPORT BRepExtrema_SelfIntersection (const TopoDS_Shape& theShape, const Standard_Real theTolerance = 0.0);
43
44 public:
45
46   //! Returns tolerance value used for self-intersection test.
47   Standard_Real Tolerance() const
48   {
49     return myTolerance;
50   }
51
52   //! Sets tolerance value used for self-intersection test.
53   void SetTolerance (const Standard_Real theTolerance)
54   {
55     myTolerance = theTolerance;
56   }
57
58   //! Loads shape for detection of self-intersections.
59   Standard_EXPORT Standard_Boolean LoadShape (const TopoDS_Shape& theShape);
60
61   //! Performs detection of self-intersections.
62   Standard_EXPORT void Perform();
63
64   //! True if the detection is completed.
65   Standard_Boolean IsDone() const
66   { 
67     return myOverlapTool.IsDone();
68   }
69
70   //! Returns set of IDs of overlapped sub-shapes (started from 0).
71   const BRepExtrema_MapOfIntegerPackedMapOfInteger& OverlapElements() const
72   {
73     return myOverlapTool.OverlapSubShapes1();
74   }
75
76   //! Returns sub-shape from the shape for the given index (started from 0).
77   const TopoDS_Face& GetSubShape (const Standard_Integer theID) const
78   {
79     return myFaceList.Value (theID);
80   }
81
82   //! Returns set of all the face triangles of the shape.
83   const Handle(BRepExtrema_TriangleSet)& ElementSet() const
84   {
85     return myElementSet;
86   }
87
88 #ifdef OVERLAP_TOOL_OUTPUT_TRIANGLES
89   //! Returns set of overlapped mesh elements (only triangles).
90   const TColStd_PackedMapOfInteger& OverlapTriangles() const
91   {
92     return myOverlapTool.OverlapTriangles1();
93   }
94 #endif
95
96 protected:
97
98   //! Filter out correct adjacent mesh elements.
99   Standard_EXPORT virtual BRepExtrema_ElementFilter::FilterResult PreCheckElements (const Standard_Integer theIndex1,
100                                                                                     const Standard_Integer theIndex2);
101
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);
108
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);
114
115 private:
116
117   //! Self-intersection tolerance.
118   Standard_Real myTolerance;
119
120   //! Is the input shape inited?
121   Standard_Boolean myIsInit;
122
123   //! List of triangulated faces of the shape.
124   BRepExtrema_ShapeList myFaceList;
125
126   //! Set of all the face triangles of the shape.
127   Handle(BRepExtrema_TriangleSet) myElementSet;
128
129   //! Overlap tool used for self-intersection test.
130   BRepExtrema_OverlapTool myOverlapTool;
131
132 };
133
134 #endif // _BRepExtrema_SelfIntersection_HeaderFile