1 // Created by: Eugeny MALTCHIKOV
2 // Copyright (c) 2013-2014 OPEN CASCADE SAS
3 //
4 // This file is part of Open CASCADE Technology software library.
5 //
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
11 //
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
14 
15 #ifndef _IntTools_EdgeEdge_HeaderFile
16 #define _IntTools_EdgeEdge_HeaderFile
17 
18 #include <Standard.hxx>
19 #include <Standard_DefineAlloc.hxx>
20 #include <Standard_Handle.hxx>
21 
22 #include <TopoDS_Edge.hxx>
23 #include <BRepAdaptor_Curve.hxx>
24 #include <Standard_Real.hxx>
25 #include <IntTools_Range.hxx>
26 #include <Standard_Boolean.hxx>
27 #include <Standard_Integer.hxx>
28 #include <IntTools_SequenceOfCommonPrts.hxx>
29 #include <IntTools_SequenceOfRanges.hxx>
30 #include <TopAbs_ShapeEnum.hxx>
31 class Geom_Curve;
32 class Bnd_Box;
33 
34 
35 
36 //! The class provides Edge/Edge intersection algorithm
37 //! based on the intersection between edges bounding boxes.
38 class IntTools_EdgeEdge
39 {
40 public:
41 
42   DEFINE_STANDARD_ALLOC
43 
44 
45 
46   //! Empty constructor
47   IntTools_EdgeEdge();
48 
49   //! Destructor
50   ~IntTools_EdgeEdge();
51 
52   //! Constructor
53   IntTools_EdgeEdge(const TopoDS_Edge& theEdge1, const TopoDS_Edge& theEdge2);
54 
55 
56   //! Constructor
57   IntTools_EdgeEdge(const TopoDS_Edge& theEdge1, const Standard_Real aT11,
58       const Standard_Real aT12, const TopoDS_Edge& theEdge2,
59       const Standard_Real aT21, const Standard_Real aT22);
60 
61 
62   //! Sets the first edge
63   void SetEdge1(const TopoDS_Edge& theEdge);
64 
65 
66   //! Sets the first edge and its range
67   void SetEdge1(const TopoDS_Edge& theEdge, const Standard_Real aT1, const Standard_Real aT2);
68 
69 
70   //! Sets the range for the first edge
71   void SetRange1(const IntTools_Range& theRange1);
72 
73 
74   //! Sets the range for the first edge
75   void SetRange1(const Standard_Real aT1, const Standard_Real aT2);
76 
77 
78   //! Sets the second edge
79   void SetEdge2(const TopoDS_Edge& theEdge);
80 
81 
82   //! Sets the first edge and its range
83   void SetEdge2(const TopoDS_Edge& theEdge, const Standard_Real aT1, const Standard_Real aT2);
84 
85 
86   //! Sets the range for the second edge
87   void SetRange2(const IntTools_Range& theRange);
88 
89 
90   //! Sets the range for the second edge
91   void SetRange2(const Standard_Real aT1, const Standard_Real aT2);
92 
93 
94   //! Sets the Fuzzy value
95   void SetFuzzyValue (const Standard_Real theFuzz);
96 
97 
98   //! Performs the intersection between edges
99   Standard_EXPORT void Perform();
100 
101 
102   //! Returns TRUE if common part(s) is(are) found
103   Standard_Boolean IsDone() const;
104 
105 
106   //! Returns Fuzzy value
107   Standard_Real FuzzyValue() const;
108 
109 
110   //! Returns common parts
111   const IntTools_SequenceOfCommonPrts& CommonParts() const;
112 
113 
114   //! Sets the flag myQuickCoincidenceCheck
UseQuickCoincidenceCheck(const Standard_Boolean bFlag)115   void UseQuickCoincidenceCheck (const Standard_Boolean bFlag) {
116     myQuickCoincidenceCheck=bFlag;
117   }
118 
119   //! Returns the flag myQuickCoincidenceCheck
IsCoincidenceCheckedQuickly()120   Standard_Boolean IsCoincidenceCheckedQuickly () {
121     return myQuickCoincidenceCheck;
122   }
123 
124 protected:
125 
126 
127 
128   //! Checks the data
129   void CheckData();
130 
131 
132   //! Prepares the data
133   Standard_EXPORT void Prepare();
134 
135 
136   //! Computes Line/Line intersection.
137   Standard_EXPORT void ComputeLineLine();
138 
139 
140   //! Intermediate function
141   Standard_EXPORT void FindSolutions (IntTools_SequenceOfRanges& theRanges1,
142     IntTools_SequenceOfRanges& theRanges2, Standard_Boolean& bSplit2);
143 
144 
145   //! Looking for the exact intersection ranges
146   Standard_EXPORT void FindSolutions (
147     const IntTools_Range& theR1, const Bnd_Box& theBox1,
148     const IntTools_Range& theR2, const Bnd_Box& theBox2,
149     IntTools_SequenceOfRanges& theRanges1, IntTools_SequenceOfRanges& theRanges2);
150 
151 
152   //! Merges found solutions
153   Standard_EXPORT void MergeSolutions (const IntTools_SequenceOfRanges& theRanges1,
154     const IntTools_SequenceOfRanges& theRanges2, const Standard_Boolean bSplit2);
155 
156 
157   //! Looking for the range of the edge which is in the box
158   Standard_EXPORT static Standard_Boolean FindParameters(const BRepAdaptor_Curve& theBAC,
159     const Standard_Real aT1, const Standard_Real aT2, const Standard_Real theTol,
160     const Standard_Real theRes, const Standard_Real thePTol,
161     const Standard_Real theResCoeff, const Bnd_Box& theCBox,
162     Standard_Real& aTB1, Standard_Real& aTB2);
163 
164 
165   //! Checks if edges coincide on the ranges
166   Standard_EXPORT Standard_Integer CheckCoincidence (const Standard_Real aT11,
167     const Standard_Real aT12, const Standard_Real aT21, const Standard_Real aT22,
168     const Standard_Real theCriteria, const Standard_Real theCurveRes1);
169 
170 
171   //! Adds common part of the given type to myCommonParts
172   Standard_EXPORT void AddSolution (const Standard_Real aT11, const Standard_Real aT12,
173     const Standard_Real aT21, const Standard_Real aT22, const TopAbs_ShapeEnum theType);
174 
175 
176   //! Looking for the minimal distance between edges on the ranges
177   Standard_EXPORT void FindBestSolution (const Standard_Real aT11, const Standard_Real aT12,
178     const Standard_Real aT21, const Standard_Real aT22,
179     Standard_Real& aT1, Standard_Real& aT2);
180 
181 
182   //! Checks is there an intersection between edges on the given ranges
183   //! (for nearly conicident edges)
184   Standard_EXPORT Standard_Boolean IsIntersection (const Standard_Real aT11,
185     const Standard_Real aT12, const Standard_Real aT21, const Standard_Real aT22);
186 
187   //! Checks if the edges are coincident really.
188   Standard_EXPORT Standard_Boolean IsCoincident();
189 
190   TopoDS_Edge myEdge1;
191   TopoDS_Edge myEdge2;
192   Handle(Geom_Curve) myGeom1;
193   Handle(Geom_Curve) myGeom2;
194   BRepAdaptor_Curve myCurve1;
195   BRepAdaptor_Curve myCurve2;
196   Standard_Real myTol1;
197   Standard_Real myTol2;
198   Standard_Real myTol;
199   Standard_Real myFuzzyValue;
200   Standard_Real myRes1;
201   Standard_Real myRes2;
202   Standard_Real myResCoeff1;
203   Standard_Real myResCoeff2;
204   Standard_Real myPTol1;
205   Standard_Real myPTol2;
206   IntTools_Range myRange1;
207   IntTools_Range myRange2;
208   Standard_Boolean mySwap;
209   Standard_Integer myErrorStatus;
210   IntTools_SequenceOfCommonPrts myCommonParts;
211 
212   //! Allows avoiding use Edge-Edge intersection
213   //! algorithm (i.e. speeding up the Boolean algorithm)
214   //! if the edges are coincided really.
215   //! If it is not evidently set of this flag should
216   //! be avoided (otherwise, the performance of
217   //! Boolean algorithm will be slower).
218   Standard_Boolean myQuickCoincidenceCheck;
219 
220 private:
221 
222 };
223 
224 #include <IntTools_EdgeEdge.lxx>
225 
226 #endif // _IntTools_EdgeEdge_HeaderFile
227