b311480e |
1 | // Copyright (c) 1995-1999 Matra Datavision |
973c2be1 |
2 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
3 | // |
973c2be1 |
4 | // This file is part of Open CASCADE Technology software library. |
b311480e |
5 | // |
d5f74e42 |
6 | // This library is free software; you can redistribute it and/or modify it under |
7 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
8 | // by the Free Software Foundation, with special exception defined in the file |
9 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
10 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
11 | // |
973c2be1 |
12 | // Alternatively, this file may be used under the terms of Open CASCADE |
13 | // commercial license or contractual agreement. |
b311480e |
14 | |
42cf5bc1 |
15 | |
16 | #include <Adaptor3d_IsoCurve.hxx> |
17 | #include <Draw_Color.hxx> |
18 | #include <Draw_Display.hxx> |
19 | #include <Draw_Drawable3D.hxx> |
20 | #include <Draw_MarkerShape.hxx> |
7fd59977 |
21 | #include <DrawTrSurf_BSplineCurve.hxx> |
42cf5bc1 |
22 | #include <DrawTrSurf_BSplineSurface.hxx> |
7fd59977 |
23 | #include <Geom_BSplineSurface.hxx> |
7fd59977 |
24 | #include <GeomAdaptor_HSurface.hxx> |
25 | #include <GeomAdaptor_Surface.hxx> |
7fd59977 |
26 | #include <gp_Pnt2d.hxx> |
42cf5bc1 |
27 | #include <Standard_Type.hxx> |
7fd59977 |
28 | #include <TColgp_Array2OfPnt.hxx> |
29 | #include <TColStd_Array1OfReal.hxx> |
30 | |
92efcf78 |
31 | IMPLEMENT_STANDARD_RTTIEXT(DrawTrSurf_BSplineSurface,DrawTrSurf_Surface) |
32 | |
b311480e |
33 | DrawTrSurf_BSplineSurface::DrawTrSurf_BSplineSurface ( |
7fd59977 |
34 | const Handle(Geom_BSplineSurface)& S) |
35 | : DrawTrSurf_Surface (S, S->NbUKnots()-2, S->NbVKnots()-2, |
36 | Draw_jaune, Draw_bleu, 30, 0.05, 0){ |
37 | |
38 | drawPoles = Standard_True; |
39 | drawKnots = Standard_True; |
40 | knotsIsos = Standard_True; |
41 | knotsForm = Draw_Losange; |
42 | knotsLook = Draw_violet; |
43 | knotsDim = 5; |
44 | polesLook = Draw_rouge; |
45 | } |
46 | |
47 | |
48 | |
49 | |
50 | DrawTrSurf_BSplineSurface::DrawTrSurf_BSplineSurface ( |
51 | const Handle(Geom_BSplineSurface)& S, const Draw_Color& BoundsColor, |
52 | const Draw_Color& IsosColor, const Draw_Color& PolesColor, |
53 | const Draw_Color& KnotsColor, const Draw_MarkerShape KnotsShape, |
54 | const Standard_Integer KnotsSize, const Standard_Boolean ShowPoles, const Standard_Boolean ShowKnots, |
55 | const Standard_Integer Discret, const Standard_Real Deflection, const Standard_Integer DrawMode) |
56 | : DrawTrSurf_Surface (S, S->NbUKnots()-2, S->NbVKnots()-2, BoundsColor, |
57 | IsosColor, Discret, Deflection, DrawMode){ |
58 | |
59 | knotsIsos = Standard_True; |
60 | drawPoles = ShowPoles; |
61 | drawKnots = ShowKnots; |
62 | knotsForm = KnotsShape; |
63 | knotsLook = KnotsColor; |
64 | knotsDim = KnotsSize; |
65 | polesLook = PolesColor; |
66 | } |
67 | |
68 | |
69 | |
70 | DrawTrSurf_BSplineSurface::DrawTrSurf_BSplineSurface ( |
71 | const Handle(Geom_BSplineSurface)& S, const Standard_Integer NbUIsos, |
72 | const Standard_Integer NbVIsos, const Draw_Color& BoundsColor, |
73 | const Draw_Color& IsosColor, const Draw_Color& PolesColor, |
74 | const Draw_Color& KnotsColor, const Draw_MarkerShape KnotsShape, |
75 | const Standard_Integer KnotsSize, const Standard_Boolean ShowPoles, const Standard_Boolean ShowKnots, |
76 | const Standard_Integer Discret, const Standard_Real Deflection, const Standard_Integer DrawMode) |
77 | : DrawTrSurf_Surface (S, Abs(NbUIsos), Abs(NbVIsos), BoundsColor, |
78 | IsosColor, Discret, Deflection, DrawMode){ |
79 | |
80 | knotsIsos = Standard_False; |
81 | drawPoles = ShowPoles; |
82 | drawKnots = ShowKnots; |
83 | knotsForm = KnotsShape; |
84 | knotsLook = KnotsColor; |
85 | knotsDim = KnotsSize; |
86 | polesLook = PolesColor; |
87 | } |
88 | |
89 | |
90 | |
91 | |
92 | void DrawTrSurf_BSplineSurface::DrawOn (Draw_Display& dis) const { |
93 | |
94 | Handle(Geom_BSplineSurface) S = Handle(Geom_BSplineSurface)::DownCast(surf); |
95 | Standard_Integer i, j; |
96 | |
97 | Standard_Real Ua,Ub,Va,Vb; |
98 | S->Bounds(Ua,Ub,Va,Vb); |
99 | |
100 | if (drawPoles) { |
101 | Standard_Integer NbUPoles = S->NbUPoles(); |
102 | Standard_Integer NbVPoles = S->NbVPoles(); |
103 | dis.SetColor(polesLook); |
104 | TColgp_Array2OfPnt SPoles (1, NbUPoles, 1, NbVPoles); |
105 | S->Poles (SPoles); |
106 | for (j = 1; j <= NbVPoles; j++) { |
107 | dis.MoveTo(SPoles(1, j)); |
108 | for (i = 2; i <= NbUPoles; i++) { |
109 | dis.DrawTo(SPoles(i, j)); |
110 | } |
111 | if (S->IsUPeriodic()) |
112 | dis.DrawTo(SPoles(1,j)); |
113 | } |
114 | for (i = 1; i <= NbUPoles; i++) { |
115 | dis.MoveTo(SPoles(i, 1)); |
116 | for (j = 2; j <= NbVPoles; j++) { |
117 | dis.DrawTo(SPoles(i, j)); |
118 | } |
119 | if (S->IsVPeriodic()) |
120 | dis.DrawTo(SPoles(i,1)); |
121 | } |
122 | } |
123 | |
124 | |
125 | if (knotsIsos) { |
126 | Standard_Integer first, last; |
127 | Handle(GeomAdaptor_HSurface) HS = new GeomAdaptor_HSurface(); |
128 | HS->ChangeSurface().Load(surf); |
129 | |
130 | Adaptor3d_IsoCurve C(HS); |
131 | |
132 | dis.SetColor(isosLook); |
133 | first = S->FirstUKnotIndex() + 1; |
134 | last = S->LastUKnotIndex() - 1; |
135 | for (i = first; i <= last; i++) { |
136 | DrawIsoCurveOn(C,GeomAbs_IsoU,S->UKnot(i),Va,Vb,dis); |
137 | } |
138 | first = S->FirstVKnotIndex() + 1; |
139 | last = S->LastVKnotIndex() - 1; |
140 | for (j = first; j <= last; j++) { |
141 | DrawIsoCurveOn(C,GeomAbs_IsoV,S->VKnot(j),Ua,Ub,dis); |
142 | } |
143 | } |
144 | |
145 | DrawTrSurf_Surface::DrawOn(dis,!knotsIsos); |
146 | |
147 | if (drawKnots) { |
148 | Standard_Integer first, last; |
149 | Standard_Integer NbUKnots = S->NbUKnots(); |
150 | TColStd_Array1OfReal SUKnots (1, NbUKnots); |
151 | S->UKnots (SUKnots); |
152 | dis.SetColor(knotsLook); |
153 | first = S->FirstUKnotIndex(); |
154 | last = S->LastUKnotIndex(); |
155 | for (i = first; i <= last; i++) { |
156 | dis.DrawMarker (S->Value (SUKnots(i), Va), knotsForm, knotsDim); |
157 | } |
158 | Standard_Integer NbVKnots = S->NbVKnots(); |
159 | TColStd_Array1OfReal SVKnots (1, NbVKnots); |
160 | S->VKnots (SVKnots); |
161 | dis.SetColor(knotsLook); |
162 | first = S->FirstVKnotIndex(); |
163 | last = S->LastVKnotIndex(); |
164 | for (j = first; j <= last; j++) { |
165 | dis.DrawMarker (S->Value (Ua, SVKnots(j)), knotsForm, knotsDim); |
166 | } |
167 | } |
168 | } |
169 | |
170 | |
171 | |
172 | |
173 | |
174 | |
175 | |
176 | void DrawTrSurf_BSplineSurface::ShowPoles () { drawPoles = Standard_True; } |
177 | |
178 | |
179 | void DrawTrSurf_BSplineSurface::ShowKnots () { drawKnots = Standard_True; } |
180 | |
181 | |
182 | void DrawTrSurf_BSplineSurface::ClearPoles () { drawPoles = Standard_False; } |
183 | |
184 | |
185 | void DrawTrSurf_BSplineSurface::ShowKnotsIsos () { |
186 | knotsIsos = Standard_True; |
187 | Handle(Geom_BSplineSurface) S = Handle(Geom_BSplineSurface)::DownCast(surf); |
188 | nbUIsos = S->NbUKnots()-2; |
189 | nbVIsos = S->NbVKnots()-2; |
190 | } |
191 | |
192 | |
193 | |
194 | void DrawTrSurf_BSplineSurface::ClearIsos () { |
195 | |
196 | knotsIsos = Standard_False; |
197 | nbUIsos = 0; |
198 | nbVIsos = 0; |
199 | } |
200 | |
201 | |
202 | void DrawTrSurf_BSplineSurface::ShowIsos ( |
203 | const Standard_Integer Nu, const Standard_Integer Nv) { |
204 | |
205 | knotsIsos = Standard_False; |
206 | nbUIsos = Abs(Nu); |
207 | nbVIsos = Abs(Nv); |
208 | } |
209 | |
210 | |
211 | void DrawTrSurf_BSplineSurface::ClearKnots () { drawKnots = Standard_False; } |
212 | |
213 | |
214 | void DrawTrSurf_BSplineSurface::FindPole ( |
215 | const Standard_Real X, const Standard_Real Y, const Draw_Display& D, const Standard_Real XPrec, |
216 | Standard_Integer& UIndex, Standard_Integer& VIndex) const { |
217 | |
218 | Handle(Geom_BSplineSurface) bs = Handle(Geom_BSplineSurface)::DownCast(surf); |
219 | gp_Pnt2d p1(X/D.Zoom(),Y/D.Zoom()); |
220 | Standard_Real Prec = XPrec / D.Zoom(); |
221 | UIndex++; |
222 | VIndex++; |
223 | Standard_Integer NbUPoles = bs->NbUPoles(); |
224 | Standard_Integer NbVPoles = bs->NbVPoles(); |
225 | while (VIndex <= NbVPoles) { |
226 | while (UIndex <= NbUPoles) { |
227 | if (D.Project(bs->Pole(UIndex, VIndex)).Distance(p1) <= Prec) |
228 | return; |
229 | UIndex++; |
230 | } |
231 | UIndex = 1; |
232 | VIndex++; |
233 | } |
234 | UIndex = VIndex = 0; |
235 | } |
236 | |
237 | |
238 | |
239 | void DrawTrSurf_BSplineSurface::FindUKnot ( |
240 | const Standard_Real X, const Standard_Real Y, const Draw_Display& D, const Standard_Real Prec, |
241 | Standard_Integer& UIndex) const { |
242 | |
243 | Handle(Geom_BSplineSurface) bs = Handle(Geom_BSplineSurface)::DownCast(surf); |
244 | gp_Pnt2d p1(X,Y); |
245 | UIndex++; |
246 | Standard_Integer NbUKnots = bs->NbUKnots(); |
247 | Standard_Real U1, U2, V1, V2; |
248 | surf->Bounds (U1, U2, V1, V2); |
249 | while (UIndex <= NbUKnots) { |
250 | if (D.Project(bs->Value(bs->UKnot(UIndex), V1)).Distance(p1) <= Prec) |
251 | return; |
252 | UIndex++; |
253 | } |
254 | UIndex = 0; |
255 | } |
256 | |
257 | |
258 | void DrawTrSurf_BSplineSurface::FindVKnot ( |
259 | const Standard_Real X, const Standard_Real Y, const Draw_Display& D, const Standard_Real Prec, |
260 | Standard_Integer& VIndex) const { |
261 | |
262 | |
263 | Handle(Geom_BSplineSurface) bs = Handle(Geom_BSplineSurface)::DownCast(surf); |
264 | gp_Pnt2d p1(X,Y); |
265 | VIndex++; |
266 | Standard_Integer NbVKnots = bs->NbVKnots(); |
267 | Standard_Real U1, U2, V1, V2; |
268 | surf->Bounds (U1, U2, V1, V2); |
269 | while (VIndex <= NbVKnots) { |
270 | if (D.Project(bs->Value(U1, bs->VKnot(VIndex))).Distance(p1) <= Prec) |
271 | return; |
272 | VIndex++; |
273 | } |
274 | VIndex = 0; |
275 | } |
276 | |
277 | |
278 | |
279 | //======================================================================= |
280 | //function : Copy |
281 | //purpose : |
282 | //======================================================================= |
283 | |
284 | Handle(Draw_Drawable3D) DrawTrSurf_BSplineSurface::Copy()const |
285 | { |
286 | Handle(DrawTrSurf_BSplineSurface) DS; |
287 | if (!knotsIsos) |
288 | DS = new DrawTrSurf_BSplineSurface |
289 | (Handle(Geom_BSplineSurface)::DownCast(surf->Copy()), |
290 | nbUIsos,nbVIsos, |
291 | boundsLook,isosLook,polesLook,knotsLook, |
292 | knotsForm,knotsDim,drawPoles,drawKnots, |
293 | GetDiscretisation(),GetDeflection(),GetDrawMode()); |
294 | else |
295 | DS = new DrawTrSurf_BSplineSurface |
296 | (Handle(Geom_BSplineSurface)::DownCast(surf->Copy()), |
297 | boundsLook,isosLook,polesLook,knotsLook, |
298 | knotsForm,knotsDim,drawPoles,drawKnots, |
299 | GetDiscretisation(),GetDeflection(),GetDrawMode()); |
300 | |
301 | return DS; |
302 | |
303 | } |
304 | |
305 | |