7fd59977 |
1 | // File: ShapeUpgrade_FixSmallBezierCurves.cxx |
2 | // Created: Wed Jun 7 17:54:42 2000 |
3 | // Author: Galina KULIKOVA |
4 | // <gka@zamox.nnov.matra-dtv.fr> |
5 | |
6 | |
7 | #include <ShapeUpgrade_FixSmallBezierCurves.ixx> |
8 | #include <TopoDS_Edge.hxx> |
9 | #include <Geom_Curve.hxx> |
10 | #include <Geom2d_Curve.hxx> |
11 | #include <gp_Pnt.hxx> |
12 | #include <ShapeAnalysis_Edge.hxx> |
13 | #include <TopExp.hxx> |
14 | #include <BRep_Tool.hxx> |
15 | #include <gp_Pnt2d.hxx> |
16 | #include <Geom2dConvert_ApproxCurve.hxx> |
17 | #include <TColGeom_HArray1OfCurve.hxx> |
18 | #include <ShapeExtend.hxx> |
19 | #include <TColGeom2d_HArray1OfCurve.hxx> |
20 | #include <GeomAdaptor_Surface.hxx> |
21 | #include <Geom_Surface.hxx> |
22 | #include <BRep_Tool.hxx> |
23 | #include <TopoDS.hxx> |
24 | #include <TopoDS_Shape.hxx> |
25 | #include <Geom2d_TrimmedCurve.hxx> |
26 | #include <GeomAbs_Shape.hxx> |
27 | #include <TopLoc_Location.hxx> |
28 | #include <GeomConvert_ApproxCurve.hxx> |
29 | #include <Geom_TrimmedCurve.hxx> |
30 | #include <GeomConvert_ApproxCurve.hxx> |
31 | #include <ShapeUpgrade_SplitCurve3d.hxx> |
32 | #include <ShapeUpgrade_SplitCurve2d.hxx> |
33 | #include <GeomAdaptor_Surface.hxx> |
34 | #include <Standard_ErrorHandler.hxx> |
35 | #include <Standard_Failure.hxx> |
36 | ShapeUpgrade_FixSmallBezierCurves::ShapeUpgrade_FixSmallBezierCurves() |
37 | { |
38 | } |
39 | |
40 | Standard_Boolean ShapeUpgrade_FixSmallBezierCurves::Approx(Handle(Geom_Curve)& Curve3d,Handle(Geom2d_Curve)& Curve2d,Handle(Geom2d_Curve)& Curve2dR,Standard_Real& First,Standard_Real& Last) |
41 | { |
42 | |
43 | ShapeAnalysis_Edge sae; |
44 | Handle(Geom_Curve) c3d; |
45 | Standard_Real f,l; |
46 | if(sae.Curve3d(myEdge,c3d,f,l,Standard_False)) { |
47 | if(First < f) |
48 | First = f; |
49 | if(Last > l) |
50 | Last =l; |
51 | Handle(Geom_TrimmedCurve) trc = new Geom_TrimmedCurve(c3d,First,Last); |
52 | GeomAbs_Shape aCont = (GeomAbs_Shape)trc->Continuity(); |
53 | if(aCont == GeomAbs_C3 || aCont == GeomAbs_CN) |
54 | aCont = GeomAbs_C2; |
55 | try { |
56 | OCC_CATCH_SIGNALS |
57 | GeomConvert_ApproxCurve AproxCurve(trc,Precision(),aCont,1,9); |
58 | if(AproxCurve.IsDone()) { |
59 | Handle(Geom_Curve) newCurve = AproxCurve.Curve(); |
60 | mySplitCurve3dTool->Init(AproxCurve.Curve(),First,Last); |
61 | mySplitCurve3dTool->Perform(Standard_True); |
62 | if (!mySplitCurve3dTool->Status ( ShapeExtend_FAIL )) { |
63 | Handle(TColGeom_HArray1OfCurve) theSegments3d; |
64 | theSegments3d = mySplitCurve3dTool->GetCurves(); |
65 | if(theSegments3d->Length() >1) return Standard_False; |
66 | Curve3d = theSegments3d->Value(1); |
67 | } |
68 | } |
69 | } |
70 | catch (Standard_Failure) { |
71 | #ifdef DEB |
72 | cout << "Warning: ShapeUpgrade_FixSmallBezierCurve::Approx(): Exception in Segment :"; |
73 | Standard_Failure::Caught()->Print(cout); cout << endl; |
74 | #endif |
75 | return Standard_False; |
76 | } |
77 | } |
78 | if ( myFace.IsNull() ) return Standard_True; |
79 | Handle(Geom2d_Curve) c2d; |
80 | TopLoc_Location L; |
81 | Handle(Geom_Surface) aSurf = BRep_Tool::Surface(myFace,L); |
82 | GeomAdaptor_Surface ads(aSurf);// = new GeomAdaptor_Surface(aSurf); |
83 | Standard_Real prec = Max(ads.UResolution(Precision()),ads.VResolution(Precision())); |
84 | if(sae.PCurve(myEdge,myFace,c2d,f,l,Standard_False)) { |
85 | if(First < f) |
86 | First = f; |
87 | if(Last > l) |
88 | Last =l; |
89 | Handle(Geom2d_TrimmedCurve) trc2d = new Geom2d_TrimmedCurve(c2d,First,Last); |
90 | GeomAbs_Shape aCont = (GeomAbs_Shape)trc2d->Continuity(); |
91 | try { |
92 | OCC_CATCH_SIGNALS |
93 | Geom2dConvert_ApproxCurve AproxCurve2d(trc2d,prec,aCont,1,9); |
94 | if(AproxCurve2d.IsDone()) { |
95 | Handle(Geom2d_Curve) newCurve = AproxCurve2d.Curve(); |
96 | mySplitCurve2dTool->Init(AproxCurve2d.Curve(),First,Last); |
97 | mySplitCurve2dTool->Perform(Standard_True); |
98 | if ( mySplitCurve2dTool->Status ( ShapeExtend_FAIL )) |
99 | return Standard_False; |
100 | Handle(TColGeom2d_HArray1OfCurve) theSegments2d; |
101 | theSegments2d = mySplitCurve2dTool->GetCurves(); |
102 | if(theSegments2d->Length() >1) return Standard_False; //ShapeAnalysis_Surface |
103 | Curve2d = theSegments2d->Value(1); |
104 | } |
105 | } |
106 | catch (Standard_Failure) { |
107 | #ifdef DEB |
108 | cout << "Warning: ShapeUpgrade_FixSmallBezierCurve::Approx(): Exception in Segment :"; |
109 | Standard_Failure::Caught()->Print(cout); cout << endl; |
110 | #endif |
111 | return Standard_False; |
112 | } |
113 | } |
114 | Standard_Boolean isSeam = BRep_Tool::IsClosed ( myEdge, myFace ); |
115 | if ( isSeam ) { |
116 | Handle(Geom2d_Curve) c2; |
117 | Standard_Real f2, l2; |
118 | //smh#8 |
119 | TopoDS_Shape tmpE = myEdge.Reversed(); |
120 | TopoDS_Edge erev = TopoDS::Edge (tmpE ); |
121 | if ( sae.PCurve ( erev, myFace, c2, f2, l2, Standard_False) ) { |
122 | if(First > f) |
123 | First = f; |
124 | if(Last > l) |
125 | Last =l; |
126 | Handle(Geom2d_TrimmedCurve) trc2d = new Geom2d_TrimmedCurve(c2,First,Last); |
127 | GeomAbs_Shape aCont = trc2d->Continuity(); |
128 | Geom2dConvert_ApproxCurve AproxCurve2d(trc2d,prec,aCont,1,9); |
129 | try { |
130 | OCC_CATCH_SIGNALS |
131 | if(AproxCurve2d.IsDone()) { |
132 | Handle(Geom2d_Curve) newCurve = AproxCurve2d.Curve(); |
133 | mySplitCurve2dTool->Init(AproxCurve2d.Curve(),First,Last); |
134 | mySplitCurve2dTool->Perform(Standard_True); |
135 | if ( ! mySplitCurve2dTool->Status ( ShapeExtend_DONE )) |
136 | return Standard_False; |
137 | Handle(TColGeom2d_HArray1OfCurve) theSegments2d; |
138 | theSegments2d = mySplitCurve2dTool->GetCurves(); |
139 | if(theSegments2d->Length() >1) return Standard_False; //ShapeAnalysis_Surface |
140 | Curve2dR = theSegments2d->Value(1); |
141 | } |
142 | } |
143 | catch (Standard_Failure) { |
144 | #ifdef DEB |
145 | cout << "Warning: ShapeUpgrade_FixSmallBezierCurve::Approx(): Exception in Segment :"; |
146 | Standard_Failure::Caught()->Print(cout); cout << endl; |
147 | #endif |
148 | return Standard_False; |
149 | } |
150 | } |
151 | } |
152 | return Standard_True; |
153 | } |
154 | |