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