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