Commit | Line | Data |
---|---|---|
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 | // ---------------------------------------------------------------------- | |
24 | Standard_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 | /*// ---------------------------------------------------------------------- | |
35 | Standard_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 | // ---------------------------------------------------------------------- | |
58 | Standard_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 | // ---------------------------------------------------------------------- | |
66 | Standard_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 | Standard_Real v = p2d.Y(); |
83 | Standard_Boolean vpisur2 = (Abs(v-pisur2) < toluv); | |
84 | Standard_Boolean vmoinspisur2 = (Abs(v+pisur2) < toluv); | |
85 | isapex = vpisur2 || vmoinspisur2; | |
86 | } | |
87 | return isapex; | |
88 | } | |
89 | ||
90 | // ---------------------------------------------------------------------- | |
91 | Standard_EXPORT gp_Dir FUN_tool_ngS(const gp_Pnt2d& p2d,const Handle(Geom_Surface)& S) | |
92 | { | |
93 | // ############################### | |
94 | // nyi : all geometries are direct | |
95 | // ############################### | |
96 | gp_Pnt p; gp_Vec d1u,d1v; | |
97 | S->D1(p2d.X(),p2d.Y(),p,d1u,d1v); | |
98 | ||
99 | Standard_Real du = d1u.Magnitude(); | |
100 | Standard_Real dv = d1v.Magnitude(); | |
101 | Standard_Real tol = Precision::Confusion(); | |
102 | Standard_Boolean kpart = (du < tol) || (dv < tol); | |
103 | if (kpart) { | |
104 | GeomAdaptor_Surface GS(S); | |
105 | GeomAbs_SurfaceType ST = GS.GetType(); | |
106 | Standard_Real toluv = 1.e-8; | |
107 | if (ST == GeomAbs_Cone) { | |
108 | Standard_Boolean nullx = (Abs(p2d.X()) < toluv); | |
109 | Standard_Boolean apex = nullx && (Abs(p2d.Y()) < toluv); | |
110 | if (apex) { | |
111 | const gp_Dir& axis = GS.Cone().Axis().Direction(); | |
112 | gp_Vec ng(axis); ng.Reverse(); | |
113 | return ng; | |
114 | } | |
115 | else if (du < tol) { | |
116 | Standard_Real vf = GS.FirstVParameter(); | |
7fd59977 | 117 | Standard_Boolean onvf = Abs(p2d.Y()-vf)<toluv; |
118 | ||
119 | Standard_Real x = p2d.X(); Standard_Real y = p2d.Y(); | |
120 | //NYIXPU : devrait plutot etre fait sur les faces & TopOpeBRepTool_TOOL::minDUV... | |
121 | if (onvf) y += 1.; | |
122 | else y -= 1.; | |
123 | S->D1(x,y,p,d1u,d1v); | |
124 | gp_Vec ng = d1u^d1v; | |
125 | return ng; | |
126 | } | |
127 | } | |
128 | if (ST == GeomAbs_Sphere) { | |
c6541a0c D |
129 | // Standard_Real deuxpi = 2*M_PI; |
130 | Standard_Real pisur2 = M_PI*.5; | |
7fd59977 | 131 | Standard_Real u = p2d.X(),v = p2d.Y(); |
132 | // Standard_Boolean u0 =(Abs(u) < toluv); | |
133 | // Standard_Boolean u2pi=(Abs(u-deuxpi) < toluv); | |
134 | // Standard_Boolean apex = u0 || u2pi; | |
135 | Standard_Boolean vpisur2 = (Abs(v-pisur2) < toluv); | |
136 | Standard_Boolean vmoinspisur2 = (Abs(v+pisur2) < toluv); | |
137 | Standard_Boolean apex = vpisur2 || vmoinspisur2; | |
138 | if (apex) { | |
139 | gp_Pnt center = GS.Sphere().Location(); | |
140 | gp_Pnt value = GS.Value(u,v); | |
141 | gp_Vec ng(center,value); | |
142 | // ng.Reverse(); | |
143 | return ng; | |
144 | } | |
145 | } | |
146 | #ifdef DEB | |
147 | cout<<"FUN_tool_nggeomF NYI"<<endl; | |
148 | #endif | |
149 | return gp_Dir(0,0,1); | |
150 | } | |
151 | ||
152 | gp_Dir udir(d1u); | |
153 | gp_Dir vdir(d1v); | |
154 | gp_Dir ngS(udir^vdir); | |
155 | return ngS; | |
156 | } | |
157 | ||
158 | // ---------------------------------------------------------------------- | |
159 | Standard_EXPORT Standard_Boolean FUN_tool_line(const Handle(Geom_Curve)& C3d) | |
160 | { | |
161 | Handle(Geom_Curve) C = TopOpeBRepTool_ShapeTool::BASISCURVE(C3d); | |
162 | GeomAdaptor_Curve GC(C); | |
163 | Standard_Boolean line = (GC.GetType() == GeomAbs_Line); | |
164 | return line; | |
165 | } | |
166 | ||
167 | // ---------------------------------------------------------------------- | |
168 | Standard_EXPORT Standard_Boolean FUN_quadCT(const GeomAbs_CurveType& CT) | |
169 | { | |
170 | Standard_Boolean isquad = Standard_False; | |
171 | if (CT == GeomAbs_Line) isquad = Standard_True; | |
172 | if (CT == GeomAbs_Circle) isquad = Standard_True; | |
173 | if (CT == GeomAbs_Ellipse) isquad = Standard_True; | |
174 | if (CT == GeomAbs_Hyperbola) isquad = Standard_True; | |
175 | if (CT == GeomAbs_Parabola) isquad = Standard_True; | |
176 | return isquad; | |
177 | } | |
178 | ||
179 | // ---------------------------------------------------------------------- | |
180 | Standard_EXPORT Standard_Boolean FUN_tool_quad(const Handle(Geom_Curve)& C3d) | |
181 | { | |
182 | Handle(Geom_Curve) C = TopOpeBRepTool_ShapeTool::BASISCURVE(C3d); | |
183 | if (C.IsNull()) return Standard_False; | |
184 | GeomAdaptor_Curve GC(C); | |
185 | GeomAbs_CurveType CT = GC.GetType(); | |
186 | Standard_Boolean quad = FUN_quadCT(CT); | |
187 | return quad; | |
188 | } | |
189 | ||
190 | // ---------------------------------------------------------------------- | |
191 | Standard_EXPORT Standard_Boolean FUN_tool_quad(const Handle(Geom2d_Curve)& pc) | |
192 | { | |
193 | Handle(Geom2d_Curve) pcb = BASISCURVE2D(pc); // NYI TopOpeBRepTool_ShapeTool | |
194 | if (pcb.IsNull()) return Standard_False; | |
195 | Geom2dAdaptor_Curve GC2d(pcb); | |
196 | GeomAbs_CurveType typ = GC2d.GetType(); | |
197 | Standard_Boolean isquad = Standard_False; | |
198 | if (typ == GeomAbs_Line) isquad = Standard_True; | |
199 | if (typ == GeomAbs_Circle) isquad = Standard_True; | |
200 | if (typ == GeomAbs_Ellipse) isquad = Standard_True; | |
201 | if (typ == GeomAbs_Hyperbola) isquad = Standard_True; | |
202 | if (typ == GeomAbs_Parabola) isquad = Standard_True; | |
203 | return isquad; | |
204 | } | |
205 | // ---------------------------------------------------------------------- | |
206 | Standard_EXPORT Standard_Boolean FUN_tool_line(const Handle(Geom2d_Curve)& pc) | |
207 | { | |
208 | Handle(Geom2d_Curve) pcb = BASISCURVE2D(pc); // NYI TopOpeBRepTool_ShapeTool | |
209 | if (pcb.IsNull()) return Standard_False; | |
210 | Geom2dAdaptor_Curve GC2d(pcb); | |
211 | GeomAbs_CurveType typ = GC2d.GetType(); | |
6e6cd5d9 | 212 | |
7fd59977 | 213 | if (typ == GeomAbs_Line) return Standard_True; |
214 | ||
215 | return Standard_False ; | |
216 | ||
217 | } | |
218 | ||
219 | // ---------------------------------------------------------------------- | |
220 | Standard_EXPORT Standard_Boolean FUN_tool_quad(const Handle(Geom_Surface)& S) | |
221 | { | |
222 | if (S.IsNull()) return Standard_False; | |
223 | GeomAdaptor_Surface GAS(S); | |
224 | GeomAbs_SurfaceType typ = GAS.GetType(); | |
225 | Standard_Boolean isquad = Standard_False; | |
226 | if (typ == GeomAbs_Plane) isquad = Standard_True; | |
227 | if (typ == GeomAbs_Cylinder) isquad = Standard_True; | |
228 | if (typ == GeomAbs_Cone) isquad = Standard_True; | |
229 | if (typ == GeomAbs_Sphere) isquad = Standard_True; | |
230 | if (typ == GeomAbs_Torus) isquad = Standard_True; | |
231 | return isquad; | |
232 | } | |
233 | ||
234 | ||
235 | // ---------------------------------------------------------------------- | |
236 | Standard_EXPORT Standard_Boolean FUN_tool_closed(const Handle(Geom_Surface)& S, | |
237 | Standard_Boolean& uclosed,Standard_Real& uperiod, | |
238 | Standard_Boolean& vclosed,Standard_Real& vperiod) | |
239 | { | |
240 | uperiod = vperiod = 0.; | |
241 | if (S.IsNull()) return Standard_False; | |
242 | uclosed = S->IsUClosed(); if (uclosed) uclosed = S->IsUPeriodic(); //xpu261098 (BUC60382) | |
243 | if (uclosed) uperiod = S->UPeriod(); | |
244 | vclosed = S->IsVClosed(); if (vclosed) vclosed = S->IsVPeriodic(); | |
245 | if (vclosed) vperiod = S->VPeriod(); | |
246 | Standard_Boolean closed = uclosed || vclosed; | |
247 | return closed; | |
248 | } | |
249 | ||
250 | // ---------------------------------------------------------------------- | |
251 | Standard_EXPORT void FUN_tool_UpdateBnd2d(Bnd_Box2d& B2d,const Bnd_Box2d& newB2d) | |
252 | { | |
253 | // B2d.SetVoid(); -> DOESN'T EMPTY THE BOX | |
254 | B2d = newB2d; | |
255 | } |