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