0023948: Wrong intersection between a surface of revolution and a plane.
[occt.git] / src / HLRBRep / HLRBRep_EdgeIList.cxx
1 // Created on: 1997-04-17
2 // Created by: Christophe MARION
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #ifndef No_Exception
18 #define No_Exception
19 #endif
20 #include <HLRBRep_EdgeIList.ixx>
21
22 #include <TopCnx_EdgeFaceTransition.hxx>
23 #include <HLRAlgo_ListIteratorOfInterferenceList.hxx>
24
25 //=======================================================================
26 //function : AddInterference
27 //purpose  : insert an interference in a sorted list
28 //=======================================================================
29
30 void  HLRBRep_EdgeIList::
31 AddInterference(HLRAlgo_InterferenceList& IL,
32                 const HLRAlgo_Interference& I,
33                 const HLRBRep_EdgeInterferenceTool& T)
34 {
35   HLRAlgo_ListIteratorOfInterferenceList It(IL);
36   Standard_Real p = T.ParameterOfInterference(I);
37   while (It.More()) {
38     if (p < T.ParameterOfInterference(It.Value())) {
39       IL.InsertBefore(I,It);
40       return;
41     }
42     It.Next();
43   }
44   IL.Append(I);
45 }
46
47 //=======================================================================
48 //function : ProcessComplex
49 //purpose  : 
50 //=======================================================================
51 #ifdef DEB_SI
52 static Standard_Boolean SimilarInterference(const HLRAlgo_Interference& I1,
53                                             const HLRAlgo_Interference& I2)
54 {
55   Standard_Real p1, p2;
56   Standard_Real eps = 1.e-7;
57   TopAbs_Orientation or1, or2;
58   //Standard_Integer l1, l2; //levels
59
60   p1 = I1.Intersection().Parameter();
61   //l1 = I1.Intersection().Level();
62   or1 = I1.Transition();
63
64   p2 = I2.Intersection().Parameter();
65   //l2 = I2.Intersection().Level();
66   or2 = I2.Transition();
67
68   Standard_Boolean IsSimilar = Abs(p1-p2) <= eps && or1 == or2;
69   return IsSimilar;
70   
71 }
72 #endif
73 void  HLRBRep_EdgeIList::
74 ProcessComplex(HLRAlgo_InterferenceList& IL,
75                const HLRBRep_EdgeInterferenceTool& T)
76 {
77   TopCnx_EdgeFaceTransition transTool;
78   gp_Dir TgtE, NormE, TgtI, NormI;
79   const Standard_Real TolAng = 0.0001;
80   Standard_Real CurvE, CurvI;
81   HLRAlgo_ListIteratorOfInterferenceList It1(IL);
82
83   while (It1.More()) {
84     HLRAlgo_ListIteratorOfInterferenceList It2(It1);
85     It2.Next();
86     if (It2.More()) {
87       if (T.SameInterferences(It1.Value(),It2.Value())
88 #ifdef DEB_SI
89           || SimilarInterference(It1.Value(),It2.Value())
90 #endif
91           )
92 {
93         T.EdgeGeometry(T.ParameterOfInterference(It1.Value()),
94                        TgtE, NormE, CurvE);
95         transTool.Reset(TgtE,NormE,CurvE);
96         T.InterferenceBoundaryGeometry(It1.Value(),TgtI,NormI,CurvI);
97         transTool.AddInterference(TolAng,
98                                   TgtI,NormI,CurvI,
99                                   It1.Value().Orientation(),
100                                   It1.Value().Transition(),
101                                   It1.Value().BoundaryTransition());
102
103         while (It2.More()) {
104           if (!(T.SameInterferences(It1.Value(),It2.Value())
105 #ifdef DEB_SI
106           || SimilarInterference(It1.Value(),It2.Value())
107 #endif
108      )) break;
109
110           T.InterferenceBoundaryGeometry(It2.Value(),TgtI,NormI,CurvI);
111           transTool.AddInterference(TolAng,
112                                     TgtI,NormI,CurvI,
113                                     It2.Value().Orientation(),
114                                     It2.Value().Transition(),
115                                     It2.Value().BoundaryTransition());
116           IL.Remove(It2);
117         }
118         // get the cumulated results
119         It1.Value().Transition(transTool.Transition());
120         It1.Value().BoundaryTransition(transTool.BoundaryTransition());
121       }
122     }
123     It1.Next();
124   }
125
126 /*  
127   //Removing "coinciding" interference
128
129   Standard_Real p1, p2;
130   Standard_Real eps = 1.e-7;
131   HLRAlgo_InterferenceList ILNew;
132   HLRAlgo_Interference I1, I2;
133   TopAbs_Orientation or1, or2;
134   Standard_Integer l1, l2; //levels
135   It1.Initialize(IL);
136
137   if(It1.More()) {
138     I1 = It1.Value();
139     p1 = I1.Intersection().Parameter();
140     l1 = I1.Intersection().Level();
141     or1 = I1.Transition();
142
143     ILNew.Append(I1);
144     HLRAlgo_ListIteratorOfInterferenceList It2(ILNew);    
145
146     It1.Next(); 
147     
148     while(It1.More()) {
149       I2 = It1.Value();
150       p2 = I2.Intersection().Parameter();
151       l2 = I2.Intersection().Level();
152       or2 = I2.Transition();
153       
154       if(p2 - p1 <= eps && or1 == or2) {
155         ILNew.Remove(It2);
156         if(l2 < l1) {
157           ILNew.Append(I2);
158         }
159         else {
160           ILNew.Append(I1);
161         }
162       }
163       else {
164         ILNew.Append(I2);
165       }
166       It1.Next();
167       if(It2.More()) It2.Next();
168       p1 = p2;
169       l1 = l2;
170       or1 = or2;
171       I1 = I2;
172     }
173
174     IL = ILNew;
175             
176   }
177 */
178
179 }