1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2012 OPEN CASCADE SAS
4 // The content of this file is subject to the Open CASCADE Technology Public
5 // License Version 6.5 (the "License"). You may not use the content of this file
6 // except in compliance with the License. Please obtain a copy of the License
7 // at http://www.opencascade.org and read it completely before using this file.
9 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
10 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12 // The Original Code and all software distributed under the License is
13 // distributed on an "AS IS" basis, without warranty of any kind, and the
14 // Initial Developer hereby disclaims all such warranties, including without
15 // limitation, any warranties of merchantability, fitness for a particular
16 // purpose or non-infringement. Please see the License for the specific terms
17 // and conditions governing the rights and limitations under the License.
19 #include <DrawTrSurf_BSplineSurface.ixx>
20 #include <DrawTrSurf_BSplineCurve.hxx>
21 #include <Geom_BSplineSurface.hxx>
22 #include <Draw_MarkerShape.hxx>
23 #include <GeomAdaptor_HSurface.hxx>
24 #include <GeomAdaptor_Surface.hxx>
25 #include <Adaptor3d_IsoCurve.hxx>
26 #include <gp_Pnt2d.hxx>
28 #include <TColgp_Array2OfPnt.hxx>
29 #include <TColStd_Array1OfReal.hxx>
33 DrawTrSurf_BSplineSurface::DrawTrSurf_BSplineSurface (
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){
38 drawPoles = Standard_True;
39 drawKnots = Standard_True;
40 knotsIsos = Standard_True;
41 knotsForm = Draw_Losange;
42 knotsLook = Draw_violet;
44 polesLook = Draw_rouge;
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){
59 knotsIsos = Standard_True;
60 drawPoles = ShowPoles;
61 drawKnots = ShowKnots;
62 knotsForm = KnotsShape;
63 knotsLook = KnotsColor;
65 polesLook = PolesColor;
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){
80 knotsIsos = Standard_False;
81 drawPoles = ShowPoles;
82 drawKnots = ShowKnots;
83 knotsForm = KnotsShape;
84 knotsLook = KnotsColor;
86 polesLook = PolesColor;
92 void DrawTrSurf_BSplineSurface::DrawOn (Draw_Display& dis) const {
94 Handle(Geom_BSplineSurface) S = Handle(Geom_BSplineSurface)::DownCast(surf);
95 Standard_Integer i, j;
97 Standard_Real Ua,Ub,Va,Vb;
98 S->Bounds(Ua,Ub,Va,Vb);
101 Standard_Integer NbUPoles = S->NbUPoles();
102 Standard_Integer NbVPoles = S->NbVPoles();
103 dis.SetColor(polesLook);
104 TColgp_Array2OfPnt SPoles (1, NbUPoles, 1, NbVPoles);
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));
111 if (S->IsUPeriodic())
112 dis.DrawTo(SPoles(1,j));
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));
119 if (S->IsVPeriodic())
120 dis.DrawTo(SPoles(i,1));
126 Standard_Integer first, last;
127 Handle(GeomAdaptor_HSurface) HS = new GeomAdaptor_HSurface();
128 HS->ChangeSurface().Load(surf);
130 Adaptor3d_IsoCurve C(HS);
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);
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);
145 DrawTrSurf_Surface::DrawOn(dis,!knotsIsos);
148 Standard_Integer first, last;
149 Standard_Integer NbUKnots = S->NbUKnots();
150 TColStd_Array1OfReal SUKnots (1, NbUKnots);
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);
158 Standard_Integer NbVKnots = S->NbVKnots();
159 TColStd_Array1OfReal SVKnots (1, NbVKnots);
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);
176 void DrawTrSurf_BSplineSurface::ShowPoles () { drawPoles = Standard_True; }
179 void DrawTrSurf_BSplineSurface::ShowKnots () { drawKnots = Standard_True; }
182 void DrawTrSurf_BSplineSurface::ClearPoles () { drawPoles = Standard_False; }
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;
194 void DrawTrSurf_BSplineSurface::ClearIsos () {
196 knotsIsos = Standard_False;
202 void DrawTrSurf_BSplineSurface::ShowIsos (
203 const Standard_Integer Nu, const Standard_Integer Nv) {
205 knotsIsos = Standard_False;
211 void DrawTrSurf_BSplineSurface::ClearKnots () { drawKnots = Standard_False; }
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 {
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();
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)
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 {
243 Handle(Geom_BSplineSurface) bs = Handle(Geom_BSplineSurface)::DownCast(surf);
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)
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 {
263 Handle(Geom_BSplineSurface) bs = Handle(Geom_BSplineSurface)::DownCast(surf);
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)
279 //=======================================================================
282 //=======================================================================
284 Handle(Draw_Drawable3D) DrawTrSurf_BSplineSurface::Copy()const
286 Handle(DrawTrSurf_BSplineSurface) DS;
288 DS = new DrawTrSurf_BSplineSurface
289 (Handle(Geom_BSplineSurface)::DownCast(surf->Copy()),
291 boundsLook,isosLook,polesLook,knotsLook,
292 knotsForm,knotsDim,drawPoles,drawKnots,
293 GetDiscretisation(),GetDeflection(),GetDrawMode());
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());