b311480e |
1 | // Created on: 1991-07-16 |
2 | // Created by: Christophe MARION |
3 | // Copyright (c) 1991-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
8 | // This library is free software; you can redistribute it and/or modify it under |
9 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
10 | // by the Free Software Foundation, with special exception defined in the file |
11 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
12 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
7fd59977 |
16 | |
42cf5bc1 |
17 | |
18 | #include <Adaptor2d_Curve2d.hxx> |
19 | #include <Adaptor3d_Curve.hxx> |
20 | #include <Adaptor3d_IsoCurve.hxx> |
21 | #include <Draw_Display.hxx> |
22 | #include <DrawTrSurf_Drawable.hxx> |
7fd59977 |
23 | #include <GCPnts_UniformDeflection.hxx> |
7fd59977 |
24 | #include <Geom_BezierCurve.hxx> |
25 | #include <Geom_BSplineCurve.hxx> |
42cf5bc1 |
26 | #include <GeomAdaptor_Curve.hxx> |
27 | #include <gp_Pnt.hxx> |
28 | #include <gp_Pnt2d.hxx> |
7fd59977 |
29 | #include <Precision.hxx> |
42cf5bc1 |
30 | #include <Standard_Type.hxx> |
31 | #include <TColStd_Array1OfReal.hxx> |
7fd59977 |
32 | |
33 | //======================================================================= |
34 | //function : DrawTrSurf_Drawable |
35 | //purpose : initialise the discretisation |
36 | //======================================================================= |
7fd59977 |
37 | DrawTrSurf_Drawable::DrawTrSurf_Drawable ( |
38 | |
39 | const Standard_Integer discret, |
40 | const Standard_Real deflection, |
41 | const Standard_Integer DrawMode ) : |
42 | myDrawMode (DrawMode), |
43 | myDiscret(discret), |
44 | myDeflection(deflection) |
45 | { |
46 | } |
47 | |
48 | //======================================================================= |
49 | //function : DrawCurve2dOn |
50 | //purpose : draw a 2D curve |
51 | //======================================================================= |
52 | |
53 | void DrawTrSurf_Drawable::DrawCurve2dOn (Adaptor2d_Curve2d& C, |
54 | Draw_Display& aDisplay) const |
55 | { |
56 | gp_Pnt P; |
57 | |
58 | gp_Pnt2d aPoint2d, |
59 | *aPoint2dPtr ; |
60 | if (myDrawMode == 1) { |
61 | Standard_Real Fleche = myDeflection/aDisplay.Zoom(); |
62 | GCPnts_UniformDeflection LineVu(C,Fleche); |
63 | if (LineVu.IsDone()) { |
64 | P = LineVu.Value(1) ; |
65 | aPoint2dPtr = (gp_Pnt2d *) &P ; |
66 | aDisplay.MoveTo(*aPoint2dPtr); |
67 | for (Standard_Integer i = 2; i <= LineVu.NbPoints(); i++) { |
68 | P = LineVu.Value(i) ; |
69 | aPoint2dPtr = (gp_Pnt2d *) &P ; |
70 | aDisplay.DrawTo(*aPoint2dPtr); |
71 | } |
72 | } |
73 | } |
74 | else { |
75 | Standard_Integer intrv, nbintv = C.NbIntervals(GeomAbs_CN); |
76 | TColStd_Array1OfReal TI(1,nbintv+1); |
77 | C.Intervals(TI,GeomAbs_CN); |
78 | C.D0(C.FirstParameter(),aPoint2d); |
79 | aDisplay.MoveTo(aPoint2d); |
80 | for (intrv = 1; intrv <= nbintv; intrv++) { |
81 | if (C.GetType() != GeomAbs_Line) { |
82 | Standard_Real t = TI(intrv); |
83 | Standard_Real step = (TI(intrv+1) - t) / myDiscret; |
84 | for (Standard_Integer i = 1; i < myDiscret; i++) { |
85 | t += step; |
86 | C.D0(t,aPoint2d); |
87 | aDisplay.DrawTo(aPoint2d); |
88 | } |
89 | } |
90 | C.D0(TI(intrv+1),aPoint2d); |
91 | aDisplay.DrawTo(aPoint2d); |
92 | } |
93 | } |
94 | } |
95 | |
96 | //======================================================================= |
97 | //static function : PlotCurve |
98 | //purpose : draw a 3D curve |
99 | //======================================================================= |
100 | static void PlotCurve (Draw_Display& aDisplay, |
101 | const Adaptor3d_Curve& C, |
102 | Standard_Real& theFirstParam, |
103 | Standard_Real theHalfStep, |
104 | const gp_Pnt& theFirstPnt, |
105 | const gp_Pnt& theLastPnt) |
106 | { |
107 | Standard_Real IsoRatio = 1.001; |
108 | gp_Pnt Pm; |
109 | |
110 | C.D0 (theFirstParam + theHalfStep, Pm); |
111 | |
112 | Standard_Real dfLength = theFirstPnt.Distance(theLastPnt); |
113 | if (dfLength < Precision::Confusion() || |
114 | Pm.Distance(theFirstPnt) + Pm.Distance(theLastPnt) <= IsoRatio*dfLength) { |
115 | aDisplay.DrawTo (theLastPnt); |
116 | } else { |
117 | PlotCurve (aDisplay, C, theFirstParam, theHalfStep/2., theFirstPnt, Pm); |
118 | Standard_Real aLocalF = theFirstParam + theHalfStep; |
119 | PlotCurve (aDisplay, C, aLocalF, theHalfStep/2., Pm, theLastPnt); |
120 | } |
121 | } |
122 | //======================================================================= |
123 | //function : DrawCurveOn |
124 | //purpose : draw a 3D curve |
125 | //======================================================================= |
126 | |
127 | void DrawTrSurf_Drawable::DrawCurveOn (Adaptor3d_Curve& C, |
32ca7a51 |
128 | Draw_Display& aDisplay) const |
7fd59977 |
129 | { |
130 | gp_Pnt P; |
32ca7a51 |
131 | if (myDrawMode == 1) |
132 | { |
7fd59977 |
133 | Standard_Real Fleche = myDeflection/aDisplay.Zoom(); |
134 | GCPnts_UniformDeflection LineVu(C,Fleche); |
32ca7a51 |
135 | if (LineVu.IsDone()) |
136 | { |
7fd59977 |
137 | aDisplay.MoveTo(LineVu.Value(1)); |
32ca7a51 |
138 | for (Standard_Integer i = 2; i <= LineVu.NbPoints(); i++) |
139 | { |
140 | aDisplay.DrawTo(LineVu.Value(i)); |
7fd59977 |
141 | } |
32ca7a51 |
142 | } |
7fd59977 |
143 | } |
32ca7a51 |
144 | else |
145 | { |
146 | Standard_Integer j; |
7fd59977 |
147 | Standard_Integer intrv, nbintv = C.NbIntervals(GeomAbs_CN); |
148 | TColStd_Array1OfReal TI(1,nbintv+1); |
149 | C.Intervals(TI,GeomAbs_CN); |
150 | C.D0(C.FirstParameter(),P); |
151 | aDisplay.MoveTo(P); |
152 | GeomAbs_CurveType CurvType = C.GetType(); |
153 | gp_Pnt aPPnt=P, aNPnt; |
154 | |
32ca7a51 |
155 | for (intrv = 1; intrv <= nbintv; intrv++) |
156 | { |
7fd59977 |
157 | Standard_Real t = TI(intrv); |
158 | Standard_Real step = (TI(intrv+1) - t) / myDiscret; |
159 | |
32ca7a51 |
160 | switch (CurvType) |
161 | { |
162 | case GeomAbs_Line: |
163 | break; |
164 | case GeomAbs_Circle: |
165 | case GeomAbs_Ellipse: |
166 | for (j = 1; j < myDiscret; j++) |
167 | { |
168 | t += step; |
169 | C.D0(t,P); |
170 | aDisplay.DrawTo(P); |
171 | } |
172 | break; |
173 | case GeomAbs_Parabola: |
174 | case GeomAbs_Hyperbola: |
175 | case GeomAbs_BezierCurve: |
176 | case GeomAbs_BSplineCurve: |
1aec3320 |
177 | case GeomAbs_OffsetCurve: |
32ca7a51 |
178 | case GeomAbs_OtherCurve: |
179 | const Standard_Integer nIter = myDiscret/2; |
180 | for (j = 1; j < nIter; j++) |
181 | { |
182 | const Standard_Real t1 = t+step*2.; |
183 | C.D0 (t1, aNPnt); |
7fd59977 |
184 | PlotCurve (aDisplay, C, t, step, aPPnt, aNPnt); |
32ca7a51 |
185 | aPPnt = aNPnt; |
186 | t = t1; |
187 | } |
188 | |
189 | break; |
7fd59977 |
190 | } |
191 | |
192 | C.D0(TI(intrv+1),P); |
32ca7a51 |
193 | PlotCurve (aDisplay, C, t, step, aPPnt, P); |
7fd59977 |
194 | aDisplay.DrawTo(P); |
195 | } |
196 | } |
197 | } |
198 | |
199 | |
200 | //======================================================================= |
201 | //function : DrawIsoCurveOn |
202 | //purpose : |
203 | //======================================================================= |
204 | |
205 | void DrawTrSurf_Drawable::DrawIsoCurveOn(Adaptor3d_IsoCurve& C, |
206 | const GeomAbs_IsoType T, |
207 | const Standard_Real P, |
208 | const Standard_Real F, |
209 | const Standard_Real L, |
210 | Draw_Display& dis) const |
211 | { |
212 | C.Load(T,P,F,L); |
213 | if ((C.GetType() == GeomAbs_BezierCurve) || |
214 | (C.GetType() == GeomAbs_BSplineCurve)) { |
215 | GeomAdaptor_Curve GC; |
216 | if (C.GetType() == GeomAbs_BezierCurve) |
217 | GC.Load(C.Bezier(),F,L); |
218 | else |
219 | GC.Load(C.BSpline(),F,L); |
220 | |
221 | DrawCurveOn(GC,dis); |
222 | } |
223 | else |
224 | DrawCurveOn(C,dis); |
225 | |
226 | } |