7fd59977 |
1 | // File: ChFiKPart_ComputeData_Sphere.cxx |
2 | // Created: Tue Nov 22 14:41:44 1994 |
3 | // Author: Laurent BOURESCHE |
4 | // <lbo@phylox> |
5 | |
6 | |
7 | #include <ChFiKPart_ComputeData.jxx> |
8 | #include <Precision.hxx> |
9 | #include <gp.hxx> |
10 | #include <gp_Vec2d.hxx> |
11 | #include <gp_Lin2d.hxx> |
12 | #include <gp_Pnt.hxx> |
13 | #include <gp_Dir.hxx> |
14 | #include <gp_Ax3.hxx> |
15 | #include <gp_Circ.hxx> |
16 | #include <gce_MakeCirc.hxx> |
17 | #include <Geom2d_Curve.hxx> |
18 | #include <Geom2d_Line.hxx> |
19 | #include <Geom_Curve.hxx> |
20 | #include <Geom_Circle.hxx> |
21 | #include <Geom_SphericalSurface.hxx> |
22 | #include <ElSLib.hxx> |
23 | #include <GeomAdaptor_Curve.hxx> |
24 | #include <GeomAdaptor_Surface.hxx> |
25 | #include <ChFiKPart_ComputeData_Fcts.hxx> |
26 | |
27 | //======================================================================= |
28 | //function : ChFiKPart_Sphere |
81bba717 |
29 | //purpose : Construction of a spherical fillet the contours which of |
30 | // are not all isos, from three tops. |
7fd59977 |
31 | //======================================================================= |
32 | |
33 | Standard_Boolean ChFiKPart_Sphere(TopOpeBRepDS_DataStructure& DStr, |
34 | const Handle(ChFiDS_SurfData)& Data, |
35 | const Handle(Adaptor3d_HSurface)& S1, |
36 | const Handle(Adaptor3d_HSurface)& S2, |
37 | const TopAbs_Orientation OrFace1, |
38 | const TopAbs_Orientation OrFace2, |
39 | const TopAbs_Orientation Or1, |
40 | const TopAbs_Orientation, |
41 | const Standard_Real Rad, |
42 | const gp_Pnt2d& PS1, |
43 | const gp_Pnt2d& P1S2, |
44 | const gp_Pnt2d& P2S2) |
45 | { |
81bba717 |
46 | // Construction of the sphere : |
47 | // - pole south on PS1 |
48 | // - origine of u given by P1S2 |
49 | // - u+ to P2S2 |
7fd59977 |
50 | |
51 | Standard_Real ptol = Precision::Confusion(); |
52 | gp_Pnt p1,p2,p3; |
53 | gp_Vec v1,v2; |
54 | S1->D1(PS1.X(),PS1.Y(),p1,v1,v2); |
55 | gp_Dir ds1(v1.Crossed(v2)); |
56 | gp_Dir df1 = ds1; |
57 | gp_Dir dnat1 = ds1; |
58 | if(Or1 == TopAbs_REVERSED) ds1.Reverse(); |
59 | if(OrFace1 == TopAbs_REVERSED) df1.Reverse(); |
60 | S2->D0(P1S2.X(),P1S2.Y(),p2); |
61 | S2->D0(P2S2.X(),P2S2.Y(),p3); |
62 | gp_Circ ci = gce_MakeCirc(p1,p2,p3); |
63 | gp_Dir di = ci.Axis().Direction(); |
64 | gp_Pnt pp = ci.Location(); |
65 | Standard_Real rr = ci.Radius(); |
66 | Standard_Real delta = sqrt(Rad*Rad-rr*rr); |
67 | gp_Pnt cen(pp.X()+delta*di.X(), |
68 | pp.Y()+delta*di.Y(), |
69 | pp.Z()+delta*di.Z()); |
70 | gp_Dir dz(gp_Vec(p1,cen)); |
71 | if(Abs(ds1.Dot(dz)-1.)>ptol){ |
72 | cen.SetCoord(pp.X()-delta*di.X(), |
73 | pp.Y()-delta*di.Y(), |
74 | pp.Z()-delta*di.Z()); |
75 | dz = gp_Dir(gp_Vec(p1,cen)); |
76 | if(Abs(ds1.Dot(dz)-1.)>ptol){ |
77 | #ifdef DEB |
81bba717 |
78 | cout<<"center of the spherical corner not found"<<endl; |
7fd59977 |
79 | #endif |
80 | return Standard_False; |
81 | } |
82 | } |
83 | gp_Dir ddx(gp_Vec(cen,p2)); |
84 | gp_Dir dddx = ddx; |
85 | gp_Dir ddy(gp_Vec(cen,p3)); |
86 | gp_Dir dx = dz.Crossed(ddx.Crossed(dz)); |
87 | gp_Dir ddz = dz.Reversed(); |
88 | gp_Ax3 FilAx3(cen,dz,dx); |
89 | if (FilAx3.YDirection().Dot(ddy) <= 0.){ |
90 | FilAx3.YReverse(); |
91 | ddz.Reverse(); |
92 | dddx.Reverse(); |
93 | } |
94 | Handle(Geom_SphericalSurface) |
95 | gsph = new Geom_SphericalSurface(FilAx3,Rad); |
96 | Data->ChangeSurf(ChFiKPart_IndexSurfaceInDS(gsph,DStr)); |
97 | |
81bba717 |
98 | // the normal of the sphere is compared to the normal of the face |
99 | // oriented to determine the final orientation of the fillet. |
7fd59977 |
100 | Standard_Boolean toreverse = ( ddz.Dot(df1) <= 0. ); |
101 | if (toreverse) { Data->ChangeOrientation() = TopAbs_REVERSED; } |
102 | else { Data->ChangeOrientation() = TopAbs_FORWARD; } |
103 | |
81bba717 |
104 | // Parameters of p2 and p3 are calculated on the Sphere to have |
105 | // ranges of curves. |
7fd59977 |
106 | Standard_Real uu1,vv1,uu2,vv2; |
107 | ElSLib::SphereParameters(FilAx3,Rad,p2,uu1,vv1); |
108 | uu1 = 0.; |
109 | ElSLib::SphereParameters(FilAx3,Rad,p3,uu2,vv2); |
110 | |
81bba717 |
111 | // FaceInterferences are loaded with pcurves and curves 3d. |
7fd59977 |
112 | |
81bba717 |
113 | // Pointed side. |
7fd59977 |
114 | |
115 | Handle(Geom_Curve) C; |
116 | Handle(Geom2d_Curve) C2d; |
c6541a0c |
117 | gp_Pnt2d p2dFil(0.,-M_PI/2.); |
7fd59977 |
118 | gp_Lin2d lin2dFil(p2dFil,gp::DX2d()); |
119 | Handle(Geom2d_Curve) C2dFil = new Geom2d_Line(lin2dFil); |
120 | toreverse = ( ddz.Dot(dnat1) <= 0. ); |
121 | TopAbs_Orientation trans = TopAbs_REVERSED; |
122 | if (toreverse) trans = TopAbs_FORWARD; |
123 | Data->ChangeInterferenceOnS1(). |
124 | SetInterference(ChFiKPart_IndexCurveInDS(C,DStr), |
125 | trans,C2d,C2dFil); |
126 | |
81bba717 |
127 | // The other side. |
7fd59977 |
128 | |
129 | Standard_Real ang = ddx.Angle(ddy); |
130 | gp_Dir dci = ddx.Crossed(ddy); |
131 | gp_Ax2 axci(cen,dci,ddx); |
132 | gp_Circ ci2(axci,Rad); |
133 | C = new Geom_Circle(ci2); |
134 | GeomAdaptor_Surface AS(gsph); |
135 | GeomAdaptor_Curve AC(C,0.,ang); |
136 | ChFiKPart_ProjPC(AC,AS,C2dFil); |
137 | gp_Pnt2d p2dbid = C2dFil->Value(0.); |
138 | gp_Pnt2d pp2dbid(uu1,vv1); |
139 | if(!pp2dbid.IsEqual(p2dbid,ptol)){ |
140 | gp_Vec2d v2dbid(p2dbid,pp2dbid); |
141 | C2dFil->Translate(v2dbid); |
142 | } |
143 | gp_Vec2d v2d(P1S2,P2S2); |
144 | gp_Dir2d d2d(v2d); |
145 | if(Abs(v2d.Magnitude()-ang) <= ptol){ |
146 | gp_Lin2d l2d(P1S2,d2d); |
147 | C2d = new Geom2d_Line(l2d); |
148 | } |
149 | else C2d = ChFiKPart_PCurve(P1S2,P2S2,0.,ang); |
150 | gp_Pnt pp1; |
151 | S2->D1(P1S2.X(),P1S2.Y(),pp1,v1,v2); |
152 | gp_Dir ds2(v1.Crossed(v2)); |
153 | toreverse = (ds2.Dot(dddx) <= 0.); |
154 | trans = TopAbs_REVERSED; |
155 | if (!toreverse) trans = TopAbs_FORWARD; |
156 | Data->ChangeInterferenceOnS2(). |
157 | SetInterference(ChFiKPart_IndexCurveInDS(C,DStr), |
158 | trans,C2d,C2dFil); |
159 | |
160 | Data->ChangeVertexFirstOnS1().SetPoint(p1); |
161 | Data->ChangeVertexLastOnS1().SetPoint(p1); |
162 | Data->ChangeVertexFirstOnS2().SetPoint(p2); |
163 | Data->ChangeVertexLastOnS2().SetPoint(p3); |
164 | Data->ChangeInterferenceOnS1().SetFirstParameter(0.); |
165 | Data->ChangeInterferenceOnS1().SetLastParameter(uu2); |
166 | Data->ChangeInterferenceOnS2().SetFirstParameter(0.); |
167 | Data->ChangeInterferenceOnS2().SetLastParameter(ang); |
168 | |
169 | return Standard_True; |
170 | } |
171 | |
172 | |