38fedb52924c5d70e5494df95ad8fca48b20887e
[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-2012 OPEN CASCADE SAS
5 //
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
10 //
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 //
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
20
21
22 #ifndef No_Exception
23 #define No_Exception
24 #endif
25 #include <HLRBRep_EdgeIList.ixx>
26
27 #include <TopCnx_EdgeFaceTransition.hxx>
28 #include <HLRAlgo_ListIteratorOfInterferenceList.hxx>
29
30 //=======================================================================
31 //function : AddInterference
32 //purpose  : insert an interference in a sorted list
33 //=======================================================================
34
35 void  HLRBRep_EdgeIList::
36 AddInterference(HLRAlgo_InterferenceList& IL,
37                 const HLRAlgo_Interference& I,
38                 const HLRBRep_EdgeInterferenceTool& T)
39 {
40   HLRAlgo_ListIteratorOfInterferenceList It(IL);
41   Standard_Real p = T.ParameterOfInterference(I);
42   while (It.More()) {
43     if (p < T.ParameterOfInterference(It.Value())) {
44       IL.InsertBefore(I,It);
45       return;
46     }
47     It.Next();
48   }
49   IL.Append(I);
50 }
51
52 //=======================================================================
53 //function : ProcessComplex
54 //purpose  : 
55 //=======================================================================
56 static Standard_Boolean SimilarInterference(const HLRAlgo_Interference& I1,
57                                             const HLRAlgo_Interference& I2)
58 {
59   Standard_Real p1, p2;
60   Standard_Real eps = 1.e-7;
61   TopAbs_Orientation or1, or2;
62   //Standard_Integer l1, l2; //levels
63
64   p1 = I1.Intersection().Parameter();
65   //l1 = I1.Intersection().Level();
66   or1 = I1.Transition();
67
68   p2 = I2.Intersection().Parameter();
69   //l2 = I2.Intersection().Level();
70   or2 = I2.Transition();
71
72   Standard_Boolean IsSimilar = Abs(p1-p2) <= eps && or1 == or2;
73   return IsSimilar;
74   
75 }
76 void  HLRBRep_EdgeIList::
77 ProcessComplex(HLRAlgo_InterferenceList& IL,
78                const HLRBRep_EdgeInterferenceTool& T)
79 {
80   TopCnx_EdgeFaceTransition transTool;
81   gp_Dir TgtE, NormE, TgtI, NormI;
82   const Standard_Real TolAng = 0.0001;
83   Standard_Real CurvE, CurvI;
84   HLRAlgo_ListIteratorOfInterferenceList It1(IL);
85
86   while (It1.More()) {
87     HLRAlgo_ListIteratorOfInterferenceList It2(It1);
88     It2.Next();
89     if (It2.More()) {
90       if (T.SameInterferences(It1.Value(),It2.Value())/* || 
91           SimilarInterference(It1.Value(),It2.Value())*/) {
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                 SimilarInterference(It1.Value(),It2.Value())*/)) break;
106
107           T.InterferenceBoundaryGeometry(It2.Value(),TgtI,NormI,CurvI);
108           transTool.AddInterference(TolAng,
109                                     TgtI,NormI,CurvI,
110                                     It2.Value().Orientation(),
111                                     It2.Value().Transition(),
112                                     It2.Value().BoundaryTransition());
113           IL.Remove(It2);
114         }
115         // get the cumulated results
116         It1.Value().Transition(transTool.Transition());
117         It1.Value().BoundaryTransition(transTool.BoundaryTransition());
118       }
119     }
120     It1.Next();
121   }
122
123 /*  
124   //Removing "coinciding" interference
125
126   Standard_Real p1, p2;
127   Standard_Real eps = 1.e-7;
128   HLRAlgo_InterferenceList ILNew;
129   HLRAlgo_Interference I1, I2;
130   TopAbs_Orientation or1, or2;
131   Standard_Integer l1, l2; //levels
132   It1.Initialize(IL);
133
134   if(It1.More()) {
135     I1 = It1.Value();
136     p1 = I1.Intersection().Parameter();
137     l1 = I1.Intersection().Level();
138     or1 = I1.Transition();
139
140     ILNew.Append(I1);
141     HLRAlgo_ListIteratorOfInterferenceList It2(ILNew);    
142
143     It1.Next(); 
144     
145     while(It1.More()) {
146       I2 = It1.Value();
147       p2 = I2.Intersection().Parameter();
148       l2 = I2.Intersection().Level();
149       or2 = I2.Transition();
150       
151       if(p2 - p1 <= eps && or1 == or2) {
152         ILNew.Remove(It2);
153         if(l2 < l1) {
154           ILNew.Append(I2);
155         }
156         else {
157           ILNew.Append(I1);
158         }
159       }
160       else {
161         ILNew.Append(I2);
162       }
163       It1.Next();
164       if(It2.More()) It2.Next();
165       p1 = p2;
166       l1 = l2;
167       or1 = or2;
168       I1 = I2;
169     }
170
171     IL = ILNew;
172             
173   }
174 */
175
176 }