b311480e |
1 | // Created on: 1994-02-07 |
2 | // Created by: Modelistation |
3 | // Copyright (c) 1994-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 | |
7fd59977 |
21 | |
22 | |
23 | #include <BRepIntCurveSurface_Inter.ixx> |
24 | #include <Geom_Line.hxx> |
25 | #include <TopAbs_ShapeEnum.hxx> |
26 | #include <TopoDS.hxx> |
27 | #include <TopoDS_Face.hxx> |
28 | #include <BRepAdaptor_Surface.hxx> |
29 | #include <BRepAdaptor_HSurface.hxx> |
30 | #include <GeomAdaptor_HCurve.hxx> |
31 | #include <BRepTopAdaptor_TopolTool.hxx> |
32 | #include <BRepAdaptor_HSurface.hxx> |
33 | |
34 | //modified by NIZNHY-PKV Sun Dec 15 16:57:10 2002 f |
35 | /* |
36 | static Standard_Real currentU,currentV; |
37 | TopAbs_State currentstate; |
38 | static Handle(BRepTopAdaptor_TopolTool) FastClass |
39 | = new BRepTopAdaptor_TopolTool(); |
40 | |
41 | static Handle(BRepAdaptor_HSurface) SurfForFastClass |
42 | = new BRepAdaptor_HSurface(); |
43 | */ |
44 | //modified by NIZNHY-PKV Sun Dec 15 16:57:14 2002 t |
45 | |
46 | //=========================================================================== |
47 | //function :BRepIntCurveSurface_Inter::BRepIntCurveSurface_Inte |
48 | //purpose : |
49 | //=========================================================================== |
50 | BRepIntCurveSurface_Inter::BRepIntCurveSurface_Inter() |
51 | : empty(Standard_True) |
52 | { |
53 | //modified by NIZNHY-PKV Sun Dec 15 16:58:10 2002 f |
54 | FastClass = new BRepTopAdaptor_TopolTool(); |
55 | SurfForFastClass = new BRepAdaptor_HSurface(); |
56 | //modified by NIZNHY-PKV Sun Dec 15 16:58:13 2002 t |
57 | } |
58 | |
59 | void BRepIntCurveSurface_Inter::Init(const TopoDS_Shape& ashape, |
60 | const GeomAdaptor_Curve& acurve, |
61 | const Standard_Real tol) { |
62 | empty = Standard_False; |
63 | curveisaline = Standard_False; |
64 | curve = acurve; |
65 | explorer.Init(ashape,TopAbs_FACE); |
66 | currentnbpoints = 0; |
67 | tolerance = tol; |
68 | Find(); |
69 | } |
70 | |
71 | void BRepIntCurveSurface_Inter::Init(const TopoDS_Shape& ashape, |
72 | const gp_Lin& aline, |
73 | const Standard_Real tol) { |
74 | empty = Standard_False; |
75 | curveisaline = Standard_True; |
76 | line = aline; |
77 | Handle(Geom_Line) geomline = new Geom_Line(aline); |
78 | curve.Load(geomline); |
79 | explorer.Init(ashape,TopAbs_FACE); |
80 | currentnbpoints = 0; |
81 | tolerance = tol; |
82 | Find(); |
83 | } |
84 | |
85 | Standard_Boolean BRepIntCurveSurface_Inter::More() const { |
86 | return(explorer.More()); |
87 | } |
88 | |
89 | void BRepIntCurveSurface_Inter::Next() { |
90 | Find(); |
91 | } |
92 | |
93 | void BRepIntCurveSurface_Inter::Find() { |
94 | |
95 | static Standard_Real UMin = 0.0; |
96 | static Standard_Real UMax = 0.0; |
97 | static Standard_Real VMin = 0.0; |
98 | static Standard_Real VMax = 0.0; |
99 | static Standard_Real PeriodU = 0.0; |
100 | static Standard_Real PeriodV = 0.0; |
101 | |
102 | if(currentnbpoints) { |
103 | while(currentindex < currentnbpoints) { |
104 | currentindex++; |
105 | Standard_Real U = intcs.Point(currentindex).U(); |
106 | Standard_Real V = intcs.Point(currentindex).V(); |
107 | //------------------------------------------------------- |
0d969553 |
108 | //-- Try to reframe point U,V in the face UV |
7fd59977 |
109 | //-- |
110 | if(PeriodU) { |
111 | while(U>UMin) |
112 | U-=PeriodU; |
113 | } |
114 | if(PeriodV) { |
115 | while(V>VMin) |
116 | V-=PeriodV; |
117 | } |
118 | // Standard_Real UInit = U; |
119 | Standard_Real VInit = V; |
0d969553 |
120 | do { //-- Loop on U |
7fd59977 |
121 | V = VInit; |
0d969553 |
122 | do { //-- Loop on V |
7fd59977 |
123 | gp_Pnt2d Puv(U,V); |
124 | //--- |
125 | //-- classifier.Perform(TopoDS::Face(explorer.Current()),Puv,tolerance); |
126 | currentstate = FastClass->Classify(Puv,tolerance); //-- MODIF |
127 | //-- TopAbs_State currentstate = classifier.State(); |
128 | |
129 | if(currentstate == TopAbs_ON || currentstate == TopAbs_IN) { |
130 | currentU = U; |
131 | currentV = V; |
132 | return; |
133 | } |
134 | V+=PeriodV; |
135 | } |
136 | while(PeriodV && V< VMax); |
137 | U+=PeriodU; |
138 | } |
139 | while(PeriodU && U<UMax); |
140 | } |
141 | explorer.Next(); |
142 | } |
143 | |
144 | if(explorer.More()) { |
145 | //--------------------------------------------- |
146 | BRepAdaptor_Surface brepadaptsurf; |
147 | |
148 | TopoDS_Face face=TopoDS::Face(explorer.Current()); |
149 | face.Orientation(TopAbs_FORWARD); |
150 | |
151 | brepadaptsurf.Initialize(face,Standard_True); |
152 | //---------------------------------------------- |
0d969553 |
153 | //-- Update variables PeriodU,PeriodV |
7fd59977 |
154 | //-- |
155 | |
156 | SurfForFastClass->ChangeSurface().Initialize(face); //-- MODIF |
157 | // SurfForFastClass->ChangeSurface().Initialize(TopoDS::Face(face)); //-- MODIF |
158 | FastClass->Initialize(SurfForFastClass); //-- MODIF |
159 | |
160 | if( brepadaptsurf.Surface().IsUPeriodic()) { |
161 | PeriodU = brepadaptsurf.Surface().UPeriod(); |
162 | UMin = brepadaptsurf.Surface().FirstUParameter(); |
163 | UMax = brepadaptsurf.Surface().LastUParameter(); |
164 | } |
165 | else { |
166 | PeriodU = 0.0; |
167 | } |
168 | if( brepadaptsurf.Surface().IsVPeriodic()) { |
169 | PeriodV = brepadaptsurf.Surface().VPeriod(); |
170 | VMin = brepadaptsurf.Surface().FirstVParameter(); |
171 | VMax = brepadaptsurf.Surface().LastVParameter(); |
172 | } |
173 | else { |
174 | PeriodV = 0.0; |
175 | } |
176 | |
177 | //---------------------------------------------- |
178 | Handle(GeomAdaptor_HCurve) HC = new GeomAdaptor_HCurve(curve); |
179 | Handle(BRepAdaptor_HSurface) HS = new BRepAdaptor_HSurface(brepadaptsurf); |
180 | //---------------------------------------------- |
181 | //-- intcs.Perform(curve,brepadaptsurf); |
182 | intcs.Perform(HC,HS); |
183 | |
184 | currentindex = 0; |
185 | currentnbpoints = intcs.NbPoints(); |
186 | if(currentnbpoints) { |
187 | Find(); |
188 | } |
189 | else { |
190 | explorer.Next(); |
191 | Find(); |
192 | } |
193 | } |
194 | else { |
195 | currentnbpoints=0; |
196 | } |
197 | } |
198 | |
199 | |
200 | IntCurveSurface_IntersectionPoint BRepIntCurveSurface_Inter::Point() const { |
201 | if(currentindex==0) |
202 | StdFail_NotDone::Raise(); |
203 | const IntCurveSurface_IntersectionPoint& ICPS = intcs.Point(currentindex); |
204 | return(IntCurveSurface_IntersectionPoint(ICPS.Pnt(), |
205 | currentU, // ICPS.U(), |
206 | currentV, // ICPS.V(), |
207 | ICPS.W(), |
208 | ICPS.Transition())); |
209 | //-- return(intcs.Point(currentindex)); |
210 | } |
211 | |
212 | Standard_Real BRepIntCurveSurface_Inter::U() const { |
213 | if(currentindex==0) |
214 | StdFail_NotDone::Raise(); |
215 | //-- return(intcs.Point(currentindex).U()); |
216 | return(currentU); |
217 | } |
218 | |
219 | Standard_Real BRepIntCurveSurface_Inter::V() const { |
220 | if(currentindex==0) |
221 | StdFail_NotDone::Raise(); |
222 | //-- return(intcs.Point(currentindex).V()); |
223 | return(currentV); |
224 | } |
225 | |
226 | Standard_Real BRepIntCurveSurface_Inter::W() const { |
227 | if(currentindex==0) |
228 | StdFail_NotDone::Raise(); |
229 | return(intcs.Point(currentindex).W()); |
230 | } |
231 | |
232 | TopAbs_State BRepIntCurveSurface_Inter::State() const { |
233 | if(currentindex==0) |
234 | StdFail_NotDone::Raise(); |
235 | //-- return(classifier.State()); |
236 | return(currentstate); |
237 | } |
238 | |
239 | IntCurveSurface_TransitionOnCurve BRepIntCurveSurface_Inter::Transition() const { |
240 | if(currentindex==0) |
241 | StdFail_NotDone::Raise(); |
242 | return(intcs.Point(currentindex).Transition()); |
243 | } |
244 | |
245 | const TopoDS_Face& BRepIntCurveSurface_Inter::Face() const { |
246 | return(TopoDS::Face(explorer.Current())); |
247 | } |
248 | |
249 | const gp_Pnt& BRepIntCurveSurface_Inter::Pnt() const { |
250 | if(currentindex==0) |
251 | StdFail_NotDone::Raise(); |
252 | return(intcs.Point(currentindex).Pnt()); |
253 | } |