0022792: Globally defined symbol PI conflicts with VTK definition (Intel compiler)
[occt.git] / src / TopOpeBRepTool / TopOpeBRepTool_GEOMETRY.cxx
CommitLineData
7fd59977 1// File: TopOpeBRepTool_GEOMETRY.cxx
2// Created: Tue Oct 6 11:06:01 1998
3// Author: Jean Yves LEBEY
4// <jyl@langdox.paris1.matra-dtv.fr>
5
6#include <TopOpeBRepTool_GEOMETRY.hxx>
7
8#include <Geom2d_Curve.hxx>
9#include <Geom2d_Line.hxx>
10#include <Geom_Curve.hxx>
11#include <Geom_Surface.hxx>
12#include <Geom2dAdaptor_Curve.hxx>
13#include <GeomAdaptor_Curve.hxx>
14#include <GeomAdaptor_Surface.hxx>
15#include <gp_Vec.hxx>
16#include <gp_Cone.hxx>
17#include <gp_Sphere.hxx>
18#include <Geom2d_OffsetCurve.hxx>
19#include <Geom2d_TrimmedCurve.hxx>
20#include <TopOpeBRepTool_ShapeTool.hxx>
21#include <Precision.hxx>
22
23// ----------------------------------------------------------------------
24Standard_EXPORT Handle(Geom2d_Curve) BASISCURVE2D(const Handle(Geom2d_Curve)& C)
25{
26 Handle(Standard_Type) T = C->DynamicType();
27 if ( T == STANDARD_TYPE(Geom2d_OffsetCurve) )
28 return ::BASISCURVE2D(Handle(Geom2d_OffsetCurve)::DownCast(C)->BasisCurve());
29 else if ( T == STANDARD_TYPE(Geom2d_TrimmedCurve) )
30 return ::BASISCURVE2D(Handle(Geom2d_TrimmedCurve)::DownCast(C)->BasisCurve());
31 else return C;
32}
33
34/*// ----------------------------------------------------------------------
35Standard_EXPORT Standard_Boolean FUN_tool_IsUViso(const Handle(Geom2d_Curve)& PC,
36 Standard_Boolean& isoU,Standard_Boolean& isoV,
37 gp_Dir2d& d2d,gp_Pnt2d& o2d)
38{
39 isoU = isoV = Standard_False;
40 if (PC.IsNull()) return Standard_False;
41 Handle(Geom2d_Curve) LLL = BASISCURVE2D(PC);
42 Handle(Standard_Type) T2 = LLL->DynamicType();
43 Standard_Boolean isline2d = (T2 == STANDARD_TYPE(Geom2d_Line));
44 if (!isline2d) return Standard_False;
45
46 Handle(Geom2d_Line) L = Handle(Geom2d_Line)::DownCast(LLL);
47 d2d = L->Direction();
48 isoU = (Abs(d2d.X()) < Precision::Parametric(Precision::Confusion()));
49 isoV = (Abs(d2d.Y()) < Precision::Parametric(Precision::Confusion()));
50 Standard_Boolean isoUV = isoU || isoV;
51 if (!isoUV) return Standard_False;
52
53 o2d = L->Location();
54 return Standard_True;
55}*/
56
57// ----------------------------------------------------------------------
58Standard_EXPORT gp_Dir FUN_tool_dirC(const Standard_Real par,const Handle(Geom_Curve)& C)
59{
60 gp_Pnt p; gp_Vec tgE; C->D1(par,p,tgE);
61 gp_Dir dirC(tgE);
62 return dirC;
63}
64
65// ----------------------------------------------------------------------
66Standard_EXPORT Standard_Boolean FUN_tool_onapex(const gp_Pnt2d& p2d,const Handle(Geom_Surface)& S)
67{
68 Standard_Boolean isapex = Standard_False;
69 GeomAdaptor_Surface GS(S);
70 Standard_Real tol = Precision::Confusion();
71 GeomAbs_SurfaceType ST = GS.GetType();
72 Standard_Real toluv = 1.e-8;
73 if (ST == GeomAbs_Cone) {
74 gp_Cone co = GS.Cone();
75 gp_Pnt apex = co.Apex();
76 gp_Pnt pnt = GS.Value(p2d.X(),p2d.Y());
77 Standard_Real dist = pnt.Distance(apex);
78 isapex = (dist < tol);
79 }
80 if (ST == GeomAbs_Sphere) {
c6541a0c 81 Standard_Real pisur2 = M_PI*.5;
7fd59977 82#ifdef DEB
83 Standard_Real u =
84#endif
85 p2d.X();
86 Standard_Real v = p2d.Y();
87 Standard_Boolean vpisur2 = (Abs(v-pisur2) < toluv);
88 Standard_Boolean vmoinspisur2 = (Abs(v+pisur2) < toluv);
89 isapex = vpisur2 || vmoinspisur2;
90 }
91 return isapex;
92}
93
94// ----------------------------------------------------------------------
95Standard_EXPORT gp_Dir FUN_tool_ngS(const gp_Pnt2d& p2d,const Handle(Geom_Surface)& S)
96{
97 // ###############################
98 // nyi : all geometries are direct
99 // ###############################
100 gp_Pnt p; gp_Vec d1u,d1v;
101 S->D1(p2d.X(),p2d.Y(),p,d1u,d1v);
102
103 Standard_Real du = d1u.Magnitude();
104 Standard_Real dv = d1v.Magnitude();
105 Standard_Real tol = Precision::Confusion();
106 Standard_Boolean kpart = (du < tol) || (dv < tol);
107 if (kpart) {
108 GeomAdaptor_Surface GS(S);
109 GeomAbs_SurfaceType ST = GS.GetType();
110 Standard_Real toluv = 1.e-8;
111 if (ST == GeomAbs_Cone) {
112 Standard_Boolean nullx = (Abs(p2d.X()) < toluv);
113 Standard_Boolean apex = nullx && (Abs(p2d.Y()) < toluv);
114 if (apex) {
115 const gp_Dir& axis = GS.Cone().Axis().Direction();
116 gp_Vec ng(axis); ng.Reverse();
117 return ng;
118 }
119 else if (du < tol) {
120 Standard_Real vf = GS.FirstVParameter();
121#ifdef DEB
122 Standard_Real vl =
123#endif
124 GS.LastVParameter();
125 Standard_Boolean onvf = Abs(p2d.Y()-vf)<toluv;
126
127 Standard_Real x = p2d.X(); Standard_Real y = p2d.Y();
128 //NYIXPU : devrait plutot etre fait sur les faces & TopOpeBRepTool_TOOL::minDUV...
129 if (onvf) y += 1.;
130 else y -= 1.;
131 S->D1(x,y,p,d1u,d1v);
132 gp_Vec ng = d1u^d1v;
133 return ng;
134 }
135 }
136 if (ST == GeomAbs_Sphere) {
c6541a0c
D
137// Standard_Real deuxpi = 2*M_PI;
138 Standard_Real pisur2 = M_PI*.5;
7fd59977 139 Standard_Real u = p2d.X(),v = p2d.Y();
140// Standard_Boolean u0 =(Abs(u) < toluv);
141// Standard_Boolean u2pi=(Abs(u-deuxpi) < toluv);
142// Standard_Boolean apex = u0 || u2pi;
143 Standard_Boolean vpisur2 = (Abs(v-pisur2) < toluv);
144 Standard_Boolean vmoinspisur2 = (Abs(v+pisur2) < toluv);
145 Standard_Boolean apex = vpisur2 || vmoinspisur2;
146 if (apex) {
147 gp_Pnt center = GS.Sphere().Location();
148 gp_Pnt value = GS.Value(u,v);
149 gp_Vec ng(center,value);
150// ng.Reverse();
151 return ng;
152 }
153 }
154#ifdef DEB
155 cout<<"FUN_tool_nggeomF NYI"<<endl;
156#endif
157 return gp_Dir(0,0,1);
158 }
159
160 gp_Dir udir(d1u);
161 gp_Dir vdir(d1v);
162 gp_Dir ngS(udir^vdir);
163 return ngS;
164}
165
166// ----------------------------------------------------------------------
167Standard_EXPORT Standard_Boolean FUN_tool_line(const Handle(Geom_Curve)& C3d)
168{
169 Handle(Geom_Curve) C = TopOpeBRepTool_ShapeTool::BASISCURVE(C3d);
170 GeomAdaptor_Curve GC(C);
171 Standard_Boolean line = (GC.GetType() == GeomAbs_Line);
172 return line;
173}
174
175// ----------------------------------------------------------------------
176Standard_EXPORT Standard_Boolean FUN_quadCT(const GeomAbs_CurveType& CT)
177{
178 Standard_Boolean isquad = Standard_False;
179 if (CT == GeomAbs_Line) isquad = Standard_True;
180 if (CT == GeomAbs_Circle) isquad = Standard_True;
181 if (CT == GeomAbs_Ellipse) isquad = Standard_True;
182 if (CT == GeomAbs_Hyperbola) isquad = Standard_True;
183 if (CT == GeomAbs_Parabola) isquad = Standard_True;
184 return isquad;
185}
186
187// ----------------------------------------------------------------------
188Standard_EXPORT Standard_Boolean FUN_tool_quad(const Handle(Geom_Curve)& C3d)
189{
190 Handle(Geom_Curve) C = TopOpeBRepTool_ShapeTool::BASISCURVE(C3d);
191 if (C.IsNull()) return Standard_False;
192 GeomAdaptor_Curve GC(C);
193 GeomAbs_CurveType CT = GC.GetType();
194 Standard_Boolean quad = FUN_quadCT(CT);
195 return quad;
196}
197
198// ----------------------------------------------------------------------
199Standard_EXPORT Standard_Boolean FUN_tool_quad(const Handle(Geom2d_Curve)& pc)
200{
201 Handle(Geom2d_Curve) pcb = BASISCURVE2D(pc); // NYI TopOpeBRepTool_ShapeTool
202 if (pcb.IsNull()) return Standard_False;
203 Geom2dAdaptor_Curve GC2d(pcb);
204 GeomAbs_CurveType typ = GC2d.GetType();
205 Standard_Boolean isquad = Standard_False;
206 if (typ == GeomAbs_Line) isquad = Standard_True;
207 if (typ == GeomAbs_Circle) isquad = Standard_True;
208 if (typ == GeomAbs_Ellipse) isquad = Standard_True;
209 if (typ == GeomAbs_Hyperbola) isquad = Standard_True;
210 if (typ == GeomAbs_Parabola) isquad = Standard_True;
211 return isquad;
212}
213// ----------------------------------------------------------------------
214Standard_EXPORT Standard_Boolean FUN_tool_line(const Handle(Geom2d_Curve)& pc)
215{
216 Handle(Geom2d_Curve) pcb = BASISCURVE2D(pc); // NYI TopOpeBRepTool_ShapeTool
217 if (pcb.IsNull()) return Standard_False;
218 Geom2dAdaptor_Curve GC2d(pcb);
219 GeomAbs_CurveType typ = GC2d.GetType();
220#ifdef DEB
221 Standard_Boolean isquad = Standard_False;
222#endif
223 if (typ == GeomAbs_Line) return Standard_True;
224
225 return Standard_False ;
226
227}
228
229// ----------------------------------------------------------------------
230Standard_EXPORT Standard_Boolean FUN_tool_quad(const Handle(Geom_Surface)& S)
231{
232 if (S.IsNull()) return Standard_False;
233 GeomAdaptor_Surface GAS(S);
234 GeomAbs_SurfaceType typ = GAS.GetType();
235 Standard_Boolean isquad = Standard_False;
236 if (typ == GeomAbs_Plane) isquad = Standard_True;
237 if (typ == GeomAbs_Cylinder) isquad = Standard_True;
238 if (typ == GeomAbs_Cone) isquad = Standard_True;
239 if (typ == GeomAbs_Sphere) isquad = Standard_True;
240 if (typ == GeomAbs_Torus) isquad = Standard_True;
241 return isquad;
242}
243
244
245// ----------------------------------------------------------------------
246Standard_EXPORT Standard_Boolean FUN_tool_closed(const Handle(Geom_Surface)& S,
247 Standard_Boolean& uclosed,Standard_Real& uperiod,
248 Standard_Boolean& vclosed,Standard_Real& vperiod)
249{
250 uperiod = vperiod = 0.;
251 if (S.IsNull()) return Standard_False;
252 uclosed = S->IsUClosed(); if (uclosed) uclosed = S->IsUPeriodic(); //xpu261098 (BUC60382)
253 if (uclosed) uperiod = S->UPeriod();
254 vclosed = S->IsVClosed(); if (vclosed) vclosed = S->IsVPeriodic();
255 if (vclosed) vperiod = S->VPeriod();
256 Standard_Boolean closed = uclosed || vclosed;
257 return closed;
258}
259
260// ----------------------------------------------------------------------
261Standard_EXPORT void FUN_tool_UpdateBnd2d(Bnd_Box2d& B2d,const Bnd_Box2d& newB2d)
262{
263// B2d.SetVoid(); -> DOESN'T EMPTY THE BOX
264 B2d = newB2d;
265}