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 | |
7fd59977 |
15 | #include <DrawTrSurf_BSplineCurve.ixx> |
16 | #include <Draw_MarkerShape.hxx> |
17 | #include <Geom_BSplineCurve.hxx> |
18 | #include <gp_Pnt2d.hxx> |
19 | |
20 | |
21 | #include <TColgp_Array1OfPnt.hxx> |
22 | #include <TColStd_Array1OfReal.hxx> |
23 | |
24 | |
b311480e |
25 | DrawTrSurf_BSplineCurve::DrawTrSurf_BSplineCurve ( |
7fd59977 |
26 | const Handle(Geom_BSplineCurve)& C) : |
27 | DrawTrSurf_Curve (C, Draw_vert, 16, 0.05, 1) { |
28 | |
29 | drawKnots = Standard_True; |
30 | knotsForm = Draw_Losange; |
31 | knotsLook = Draw_violet; |
32 | knotsDim = 5; |
33 | drawPoles = Standard_True; |
34 | polesLook = Draw_rouge; |
35 | } |
36 | |
37 | |
38 | |
39 | |
40 | DrawTrSurf_BSplineCurve::DrawTrSurf_BSplineCurve ( |
41 | const Handle(Geom_BSplineCurve)& C, const Draw_Color& CurvColor, |
42 | const Draw_Color& PolesColor, const Draw_Color& KnotsColor, |
43 | const Draw_MarkerShape KnotsShape, const Standard_Integer KnotsSize, |
44 | const Standard_Boolean ShowPoles, const Standard_Boolean ShowKnots, |
45 | const Standard_Integer Discret, const Standard_Real Deflection, |
46 | const Standard_Integer DrawMode) |
47 | : DrawTrSurf_Curve (C , CurvColor, Discret, Deflection, DrawMode) { |
48 | |
49 | drawKnots = ShowKnots; |
50 | knotsForm = KnotsShape; |
51 | knotsLook = KnotsColor; |
52 | knotsDim = KnotsSize; |
53 | drawPoles = ShowPoles; |
54 | polesLook = PolesColor; |
55 | } |
56 | |
57 | |
58 | |
59 | void DrawTrSurf_BSplineCurve::DrawOn (Draw_Display& dis) const { |
60 | |
61 | |
62 | Handle(Geom_BSplineCurve) C = Handle(Geom_BSplineCurve)::DownCast(curv); |
63 | if (drawPoles) { |
64 | Standard_Integer NbPoles = C->NbPoles(); |
65 | dis.SetColor(polesLook); |
66 | TColgp_Array1OfPnt CPoles (1, NbPoles); |
67 | C->Poles (CPoles); |
68 | dis.MoveTo(CPoles(1)); |
69 | for (Standard_Integer i = 2; i <= NbPoles; i++) { |
70 | dis.DrawTo(CPoles(i)); |
71 | } |
72 | if (C->IsPeriodic()) |
73 | dis.DrawTo(CPoles(1)); |
74 | } |
75 | |
76 | DrawTrSurf_Curve::DrawOn(dis); |
77 | |
78 | if (drawKnots) { |
79 | Standard_Integer NbKnots = C->NbKnots(); |
80 | TColStd_Array1OfReal CKnots (1, NbKnots); |
81 | C->Knots (CKnots); |
82 | dis.SetColor(knotsLook); |
83 | Standard_Integer first = C->FirstUKnotIndex(); |
84 | Standard_Integer last = C->LastUKnotIndex(); |
85 | for (Standard_Integer i = first; i <= last; i++) { |
86 | dis.DrawMarker (C->Value (CKnots (i)), knotsForm, knotsDim); |
87 | } |
88 | } |
89 | } |
90 | |
91 | |
92 | void DrawTrSurf_BSplineCurve::DrawOn ( |
93 | |
94 | Draw_Display& dis, |
95 | const Standard_Boolean ShowPoles, |
96 | const Standard_Boolean ShowKnots |
97 | ) const { |
98 | |
99 | |
100 | Handle(Geom_BSplineCurve) C = Handle(Geom_BSplineCurve)::DownCast(curv); |
101 | if (drawPoles && ShowPoles) { |
102 | Standard_Integer NbPoles = C->NbPoles(); |
103 | dis.SetColor(polesLook); |
104 | TColgp_Array1OfPnt CPoles (1, NbPoles); |
105 | C->Poles (CPoles); |
106 | dis.MoveTo(CPoles(1)); |
107 | for (Standard_Integer i = 2; i <= NbPoles; i++) { |
108 | dis.DrawTo(CPoles(i)); |
109 | } |
110 | } |
111 | |
112 | DrawTrSurf_Curve::DrawOn(dis); |
113 | |
114 | if (drawKnots && ShowKnots) { |
115 | Standard_Integer NbKnots = C->NbKnots(); |
116 | TColStd_Array1OfReal CKnots (1, NbKnots); |
117 | C->Knots (CKnots); |
118 | dis.SetColor(knotsLook); |
119 | for (Standard_Integer i = 1; i <= NbKnots; i++) { |
120 | dis.DrawMarker (C->Value (CKnots (i)), knotsForm, knotsDim); |
121 | } |
122 | } |
123 | } |
124 | |
125 | |
126 | |
127 | |
128 | void DrawTrSurf_BSplineCurve::DrawOn ( |
129 | |
130 | Draw_Display& dis, |
131 | const Standard_Real U1, |
132 | const Standard_Real U2, |
133 | const Standard_Integer Pindex, |
134 | const Standard_Boolean ShowPoles, |
135 | const Standard_Boolean ShowKnots |
136 | ) const { |
137 | |
138 | |
139 | Handle(Geom_BSplineCurve) C = Handle(Geom_BSplineCurve)::DownCast(curv); |
140 | Standard_Real Eps1 = Abs(Epsilon (U1)); |
141 | Standard_Real Eps2 = Abs(Epsilon (U2)); |
142 | Standard_Integer I1, J1, I2, J2; |
143 | C->LocateU (U1, Eps1, I1, J1); |
144 | C->LocateU (U2, Eps2, I2, J2); |
145 | Standard_Integer ka = C->FirstUKnotIndex (); |
146 | Standard_Integer kb = C->LastUKnotIndex (); |
147 | |
148 | |
149 | if (drawPoles && ShowPoles) { |
150 | Standard_Integer NbPoles = C->NbPoles(); |
151 | dis.SetColor(polesLook); |
152 | TColgp_Array1OfPnt CPoles (1, NbPoles); |
153 | C->Poles (CPoles); |
154 | if (Pindex == 0) { |
155 | dis.MoveTo(CPoles(1)); |
156 | for (Standard_Integer i = 2; i <= NbPoles; i++) { |
157 | dis.DrawTo(CPoles(i)); |
158 | } |
159 | } |
160 | else if (Pindex == 1) { |
161 | dis.MoveTo(CPoles(1)); |
162 | dis.DrawTo(CPoles(2)); |
163 | } |
164 | else if (Pindex == NbPoles) { |
165 | dis.MoveTo(CPoles(NbPoles-1)); |
166 | dis.DrawTo(CPoles(NbPoles)); |
167 | } |
168 | else { |
169 | dis.MoveTo(CPoles(Pindex-1)); |
170 | dis.DrawTo(CPoles(Pindex)); |
171 | dis.DrawTo(CPoles(Pindex+1)); |
172 | } |
173 | } |
174 | |
175 | |
176 | |
177 | dis.SetColor(look); |
178 | Standard_Integer Degree = C->Degree(); |
179 | |
180 | if (Degree == 1) { |
181 | dis.MoveTo(C->Value(U1)); |
182 | dis.DrawTo(C->Value(U2)); |
183 | } |
184 | else { |
185 | Standard_Integer NbPoints; |
186 | Standard_Integer Discret = GetDiscretisation(); |
187 | Standard_Real Ustart = C->Knot (ka); |
188 | Standard_Real Uend = C->Knot (kb); |
189 | Standard_Real Du, U, Ua, Ub, Uk1, Uk2; |
190 | |
191 | if (I1 > ka) { ka = I1; Uk1 = U1; } |
192 | else { |
193 | U = U1; |
194 | NbPoints = (Standard_Integer) Abs (Discret * (U1 - Ustart) / (Ustart - Uend)); |
195 | NbPoints = Max (NbPoints, 30); |
196 | Du = (Ustart - U1) / NbPoints; |
197 | dis.MoveTo(C->Value (U)); |
198 | for (Standard_Integer i = 1; i <= NbPoints - 2; i++) { |
199 | U+= Du; |
200 | dis.DrawTo(C->Value (U)); |
201 | } |
202 | dis.DrawTo(C->Value (Ustart)); |
203 | Uk1 = Ustart; |
204 | } |
205 | |
206 | if (J2 < kb) { kb = J2; Uk2 = U2; } |
207 | else { |
208 | Uk2 = Uend; |
209 | U = Uend; |
210 | NbPoints = (Standard_Integer) Abs (Discret * (U2 - Uend) / (Ustart - Uend)); |
211 | NbPoints = Max (NbPoints, 30); |
212 | Du = (U2 - Uend) / NbPoints; |
213 | dis.MoveTo(C->Value (U)); |
214 | for (Standard_Integer i = 1; i <= NbPoints - 2; i++) { |
215 | U+= Du; |
216 | dis.DrawTo(C->Value (U)); |
217 | } |
218 | dis.DrawTo(C->Value (U2)); |
219 | } |
220 | |
221 | |
222 | for (Standard_Integer k = ka; k < kb; k++) { |
223 | if (k == ka) { |
224 | Ua = Uk1; |
225 | Ub = C->Knot (k+1); |
226 | } |
227 | else if (k == kb-1) { |
228 | Ua = C->Knot (k); |
229 | Ub = Uk2; |
230 | } |
231 | else { |
232 | Ua = C->Knot (k); |
233 | Ub = C->Knot (k+1); |
234 | } |
235 | U = Ua; |
236 | NbPoints = (Standard_Integer) Abs (Discret * (Ua - Ub) / (Ustart - Uend)); |
237 | NbPoints = Max (NbPoints, 30); |
238 | Du = (Ub - Ua) / NbPoints; |
239 | dis.MoveTo(C->Value (U)); |
240 | for (Standard_Integer i = 1; i <= NbPoints - 2; i++) { |
241 | U+= Du; |
242 | dis.DrawTo(C->Value (U)); |
243 | } |
244 | dis.DrawTo(C->Value (Ub)); |
245 | } |
246 | } |
247 | |
248 | |
249 | if (drawKnots && ShowKnots) { |
250 | Standard_Integer NbKnots = C->NbKnots(); |
251 | TColStd_Array1OfReal CKnots (1, NbKnots); |
252 | C->Knots (CKnots); |
253 | dis.SetColor(knotsLook); |
254 | for (Standard_Integer i = J1; i <= I2; i++) { |
255 | dis.DrawMarker (C->Value (CKnots (i)), knotsForm, knotsDim); |
256 | } |
257 | } |
258 | |
259 | } |
260 | |
261 | |
262 | |
263 | void DrawTrSurf_BSplineCurve::ShowPoles () { drawPoles = Standard_True; } |
264 | |
265 | |
266 | void DrawTrSurf_BSplineCurve::ShowKnots () { drawKnots = Standard_True; } |
267 | |
268 | |
269 | void DrawTrSurf_BSplineCurve::ClearPoles () { drawPoles = Standard_False; } |
270 | |
271 | |
272 | void DrawTrSurf_BSplineCurve::ClearKnots () { drawKnots = Standard_False; } |
273 | |
274 | |
275 | void DrawTrSurf_BSplineCurve::FindPole ( |
276 | const Standard_Real X, const Standard_Real Y, const Draw_Display& D, const Standard_Real XPrec, |
277 | Standard_Integer& Index) const { |
278 | |
279 | Handle(Geom_BSplineCurve) bc = Handle(Geom_BSplineCurve)::DownCast(curv); |
280 | Standard_Real Prec = XPrec / D.Zoom(); |
281 | gp_Pnt2d p1(X/D.Zoom(),Y/D.Zoom()); |
282 | Index++; |
283 | Standard_Integer NbPoles = bc->NbPoles(); |
284 | while (Index <= NbPoles) { |
285 | if (D.Project(bc->Pole(Index)).Distance(p1) <= Prec) |
286 | return; |
287 | Index++; |
288 | } |
289 | Index = 0; |
290 | } |
291 | |
292 | |
293 | void DrawTrSurf_BSplineCurve::FindKnot ( |
294 | const Standard_Real X, const Standard_Real Y, const Draw_Display& D, const Standard_Real Prec, |
295 | Standard_Integer& Index) const { |
296 | |
297 | Handle(Geom_BSplineCurve) bc = Handle(Geom_BSplineCurve)::DownCast(curv); |
298 | gp_Pnt2d p1(X,Y); |
299 | Index++; |
300 | Standard_Integer NbKnots = bc->NbKnots(); |
301 | while (Index <= NbKnots) { |
302 | if (D.Project(bc->Value(bc->Knot(Index))).Distance(p1) <= Prec) |
303 | return; |
304 | Index++; |
305 | } |
306 | Index = 0; |
307 | } |
308 | |
309 | |
310 | //======================================================================= |
311 | //function : Copy |
312 | //purpose : |
313 | //======================================================================= |
314 | |
315 | Handle(Draw_Drawable3D) DrawTrSurf_BSplineCurve::Copy()const |
316 | { |
317 | Handle(DrawTrSurf_BSplineCurve) DC = new DrawTrSurf_BSplineCurve |
318 | (Handle(Geom_BSplineCurve)::DownCast(curv->Copy()), |
319 | look,polesLook,knotsLook,knotsForm,knotsDim, |
320 | drawPoles,drawKnots, |
321 | GetDiscretisation(),GetDeflection(),GetDrawMode()); |
322 | |
323 | return DC; |
324 | } |
325 | |
326 | |