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>
10 #include <TColgp_Array2OfPnt.hxx>
11 #include <TColStd_Array1OfReal.hxx>
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){
20 drawPoles = Standard_True;
21 drawKnots = Standard_True;
22 knotsIsos = Standard_True;
23 knotsForm = Draw_Losange;
24 knotsLook = Draw_violet;
26 polesLook = Draw_rouge;
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){
41 knotsIsos = Standard_True;
42 drawPoles = ShowPoles;
43 drawKnots = ShowKnots;
44 knotsForm = KnotsShape;
45 knotsLook = KnotsColor;
47 polesLook = PolesColor;
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){
62 knotsIsos = Standard_False;
63 drawPoles = ShowPoles;
64 drawKnots = ShowKnots;
65 knotsForm = KnotsShape;
66 knotsLook = KnotsColor;
68 polesLook = PolesColor;
74 void DrawTrSurf_BSplineSurface::DrawOn (Draw_Display& dis) const {
76 Handle(Geom_BSplineSurface) S = Handle(Geom_BSplineSurface)::DownCast(surf);
77 Standard_Integer i, j;
79 Standard_Real Ua,Ub,Va,Vb;
80 S->Bounds(Ua,Ub,Va,Vb);
83 Standard_Integer NbUPoles = S->NbUPoles();
84 Standard_Integer NbVPoles = S->NbVPoles();
85 dis.SetColor(polesLook);
86 TColgp_Array2OfPnt SPoles (1, NbUPoles, 1, NbVPoles);
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));
94 dis.DrawTo(SPoles(1,j));
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));
101 if (S->IsVPeriodic())
102 dis.DrawTo(SPoles(i,1));
108 Standard_Integer first, last;
109 Handle(GeomAdaptor_HSurface) HS = new GeomAdaptor_HSurface();
110 HS->ChangeSurface().Load(surf);
112 Adaptor3d_IsoCurve C(HS);
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);
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);
127 DrawTrSurf_Surface::DrawOn(dis,!knotsIsos);
130 Standard_Integer first, last;
131 Standard_Integer NbUKnots = S->NbUKnots();
132 TColStd_Array1OfReal SUKnots (1, NbUKnots);
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);
140 Standard_Integer NbVKnots = S->NbVKnots();
141 TColStd_Array1OfReal SVKnots (1, NbVKnots);
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);
158 void DrawTrSurf_BSplineSurface::ShowPoles () { drawPoles = Standard_True; }
161 void DrawTrSurf_BSplineSurface::ShowKnots () { drawKnots = Standard_True; }
164 void DrawTrSurf_BSplineSurface::ClearPoles () { drawPoles = Standard_False; }
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;
176 void DrawTrSurf_BSplineSurface::ClearIsos () {
178 knotsIsos = Standard_False;
184 void DrawTrSurf_BSplineSurface::ShowIsos (
185 const Standard_Integer Nu, const Standard_Integer Nv) {
187 knotsIsos = Standard_False;
193 void DrawTrSurf_BSplineSurface::ClearKnots () { drawKnots = Standard_False; }
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 {
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();
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)
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 {
225 Handle(Geom_BSplineSurface) bs = Handle(Geom_BSplineSurface)::DownCast(surf);
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)
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 {
245 Handle(Geom_BSplineSurface) bs = Handle(Geom_BSplineSurface)::DownCast(surf);
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)
261 //=======================================================================
264 //=======================================================================
266 Handle(Draw_Drawable3D) DrawTrSurf_BSplineSurface::Copy()const
268 Handle(DrawTrSurf_BSplineSurface) DS;
270 DS = new DrawTrSurf_BSplineSurface
271 (Handle(Geom_BSplineSurface)::DownCast(surf->Copy()),
273 boundsLook,isosLook,polesLook,knotsLook,
274 knotsForm,knotsDim,drawPoles,drawKnots,
275 GetDiscretisation(),GetDeflection(),GetDrawMode());
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());