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