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