1 // Created on: 1993-06-17
2 // Created by: Jean Yves LEBEY
3 // Copyright (c) 1993-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #include <TopOpeBRepBuild_PaveClassifier.ixx>
18 #include <TopOpeBRepBuild_Pave.hxx>
21 #include <TopoDS_Vertex.hxx>
22 #include <BRep_Tool.hxx>
24 #include <Geom_Curve.hxx>
25 #include <Precision.hxx>
29 extern Standard_Boolean TopOpeBRepTool_GettraceVC();
30 extern Standard_Boolean TopOpeBRepTool_GettraceCLOV();
33 //=======================================================================
34 //function : TopOpeBRepBuild_PaveClassifier
36 //=======================================================================
38 TopOpeBRepBuild_PaveClassifier::TopOpeBRepBuild_PaveClassifier
39 (const TopoDS_Shape& E) :
40 myEdgePeriodic(Standard_False),
41 mySameParameters(Standard_False),
42 myClosedVertices(Standard_False)
44 myEdge = TopoDS::Edge(E);
46 if ( ! BRep_Tool::Degenerated(myEdge) ) {
49 Handle(Geom_Curve) C = BRep_Tool::Curve(myEdge,loc,f,l);
51 if (C->IsPeriodic()) {
53 TopExp::Vertices(myEdge,v1,v2); // v1 FORWARD, v2 REVERSED
54 if ( !v1.IsNull() && !v2.IsNull() ) {
55 // --- the edge has vertices
57 Standard_Real fC = C->FirstParameter();
58 Standard_Real lC = C->LastParameter();
60 myEdgePeriodic = mySameParameters = v1.IsSame(v2);
61 if ( mySameParameters ) {
62 myFirst = BRep_Tool::Parameter(v1,myEdge);
66 // --- the edge has no vertices
69 myEdgePeriodic = Standard_True;
70 mySameParameters = Standard_False;
76 if (TopOpeBRepTool_GettraceVC()) {
79 cout<<"VC : periodic edge : myFirst "<<myFirst<<" myPeriod "<<myPeriod<<endl;
80 if (mySameParameters)cout<<"VC same parameters "<<endl;
81 else cout<<"VC no same parameters"<<endl;
84 cout<<"VC : non periodic edge : f "<<f<<" l "<<l<<endl;
93 //=======================================================================
94 //function : CompareOnNonPeriodic
96 //=======================================================================
98 TopAbs_State TopOpeBRepBuild_PaveClassifier::CompareOnNonPeriodic()
101 TopAbs_State state = TopAbs_UNKNOWN;
102 Standard_Boolean lower=Standard_False;
104 case TopAbs_FORWARD : lower = Standard_False; break;
105 case TopAbs_REVERSED : lower = Standard_True; break;
106 case TopAbs_INTERNAL : state = TopAbs_IN; break;
107 case TopAbs_EXTERNAL : state = TopAbs_OUT; break;
110 if (state == TopAbs_UNKNOWN) {
112 if ( myO1 == myO2 ) state = TopAbs_IN;
113 else state = TopAbs_OUT;
115 else if (myP1 < myP2) {
116 if (lower) state = TopAbs_IN;
117 else state = TopAbs_OUT;
120 if (lower) state = TopAbs_OUT;
121 else state = TopAbs_IN;
126 if (TopOpeBRepTool_GettraceVC()) {
128 if (myP1 == myP2) cout<<" p1 = p2";
129 else if (myP1 < myP2) cout<<" p1 < p2";
130 else if (myP1 > myP2) cout<<" p1 > p2";
131 cout<<" --> state "; TopAbs::Print(state,cout); cout<<endl;
138 //=======================================================================
139 //function : AdjustCase
141 //=======================================================================
143 Standard_Real TopOpeBRepBuild_PaveClassifier::AdjustCase(const Standard_Real p1,
144 const TopAbs_Orientation o,
145 const Standard_Real first,
146 const Standard_Real period,
147 const Standard_Real tol,
148 Standard_Integer& cas)
151 if ( Abs(p1-first) < tol ) { // p1 is first
152 if (o == TopAbs_REVERSED) {
161 else { // p1 is not on first
162 Standard_Real last = first+period;
163 if ( Abs(p1-last) < tol ) { // p1 is on last
167 else { // p1 is not on last
168 p2 = ElCLib::InPeriod(p1,first,last);
175 //=======================================================================
176 //function : AdjustOnPeriodic
177 //purpose : (private)
178 //=======================================================================
180 void TopOpeBRepBuild_PaveClassifier::AdjustOnPeriodic()
182 if ( ! ToAdjustOnPeriodic() ) return;
185 Standard_Real p1 = myP1, p2 = myP2;
188 Standard_Real tol = Precision::PConfusion();
190 if (mySameParameters) {
191 myP1 = AdjustCase(myP1,myO1,myFirst,myPeriod,tol,myCas1);
192 myP2 = AdjustCase(myP2,myO2,myFirst,myPeriod,tol,myCas2);
194 else if (myO1 != myO2 ) {
195 if (myO1 == TopAbs_FORWARD) myP2 = AdjustCase(myP2,myO2,myP1,myPeriod,tol,myCas2);
196 if (myO2 == TopAbs_FORWARD) myP1 = AdjustCase(myP1,myO1,myP2,myPeriod,tol,myCas1);
200 if (TopOpeBRepTool_GettraceVC()) {
201 cout<<"p1 "<<p1<<" ";TopAbs::Print(myO1,cout);cout<<" --> "<<myP1<<endl;
202 cout<<"p2 "<<p2<<" ";TopAbs::Print(myO2,cout);cout<<" --> "<<myP2<<endl;
208 //=======================================================================
209 //function : ToAdjustOnPeriodic
210 //purpose : (private)
211 //=======================================================================
213 Standard_Boolean TopOpeBRepBuild_PaveClassifier::ToAdjustOnPeriodic() const
215 Standard_Boolean toadjust = ( (mySameParameters) || (myO1 != myO2 ) );
219 //=======================================================================
220 //function : CompareOnPeriodic
222 //=======================================================================
224 TopAbs_State TopOpeBRepBuild_PaveClassifier::CompareOnPeriodic()
228 if ( ToAdjustOnPeriodic() ) {
229 state = CompareOnNonPeriodic();
231 else if (myO1 == TopAbs_FORWARD) {
235 else if (myO1 == TopAbs_REVERSED) {
245 if (TopOpeBRepTool_GettraceVC()) {
246 cout<<"VC_P : cas "<<myCas1<<"__"<<myCas2;
247 cout<<" --> state "; TopAbs::Print(state,cout); cout<<endl;
255 //=======================================================================
258 //=======================================================================
260 TopAbs_State TopOpeBRepBuild_PaveClassifier::Compare
261 (const Handle(TopOpeBRepBuild_Loop)& L1,
262 const Handle(TopOpeBRepBuild_Loop)& L2)
264 const Handle(TopOpeBRepBuild_Pave)& PV1 =
265 *((Handle(TopOpeBRepBuild_Pave)*)&(L1));
266 const Handle(TopOpeBRepBuild_Pave)& PV2 =
267 *((Handle(TopOpeBRepBuild_Pave)*)&(L2));
269 myCas1 = myCas2 = 0; // debug
270 myO1 = PV1->Vertex().Orientation();
271 myO2 = PV2->Vertex().Orientation();
272 myP1 = PV1->Parameter();
273 myP2 = PV2->Parameter();
276 if (TopOpeBRepTool_GettraceVC()) {
277 cout<<endl<<"VC : "<<myP1<<" "<<myP2<<" ";
278 TopAbs::Print(myO1,cout); cout<<" "; TopAbs::Print(myO2,cout);
279 cout<<" (p "<<myEdgePeriodic;
280 cout<<" s "<<mySameParameters<<" c "<<myClosedVertices<<")"<<endl;
284 if ( myEdgePeriodic && ToAdjustOnPeriodic() ) {
290 state = CompareOnPeriodic();
292 state = CompareOnNonPeriodic();
295 if (TopOpeBRepTool_GettraceVC()) {
296 cout<<"VC : --> final state "; TopAbs::Print(state,cout); cout<<endl;
304 //=======================================================================
305 //function : SetFirstParameter
307 //=======================================================================
308 void TopOpeBRepBuild_PaveClassifier::SetFirstParameter
309 (const Standard_Real P)
312 mySameParameters = Standard_True;
315 if (TopOpeBRepTool_GettraceVC())
316 cout<<endl<<"VC : set first parameter "<<myFirst<<endl;
321 //=======================================================================
322 //function : ClosedVertices
324 //=======================================================================
326 void TopOpeBRepBuild_PaveClassifier::ClosedVertices
327 (const Standard_Boolean Closed)
329 myClosedVertices = Closed;
331 if (TopOpeBRepTool_GettraceCLOV()) {
332 myEdgePeriodic = Closed;
333 cout<<"::::::::::::::::::::::::"<<endl;
334 cout<<"VC : myClosedVertices"<<myClosedVertices<<endl;
335 cout<<"VC : myEdgePeriodic "<<myEdgePeriodic<<endl;
336 cout<<"::::::::::::::::::::::::"<<endl;