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