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