7fd59977 |
1 | // File: DrawTrSurf_Drawable.cxx |
2 | // Created: Tue Jul 16 09:22:44 1991 |
3 | // Author: Christophe MARION |
4 | // <cma@sdsun1> |
5 | |
6 | |
7 | #include <DrawTrSurf_Drawable.ixx> |
8 | #include <GCPnts_UniformDeflection.hxx> |
9 | #include <gp_Pnt.hxx> |
10 | #include <gp_Pnt2d.hxx> |
11 | #include <TColStd_Array1OfReal.hxx> |
12 | #include <GeomAdaptor_Curve.hxx> |
13 | #include <Geom_BezierCurve.hxx> |
14 | #include <Geom_BSplineCurve.hxx> |
15 | #include <Precision.hxx> |
16 | |
17 | |
18 | //======================================================================= |
19 | //function : DrawTrSurf_Drawable |
20 | //purpose : initialise the discretisation |
21 | //======================================================================= |
22 | |
23 | DrawTrSurf_Drawable::DrawTrSurf_Drawable ( |
24 | |
25 | const Standard_Integer discret, |
26 | const Standard_Real deflection, |
27 | const Standard_Integer DrawMode ) : |
28 | myDrawMode (DrawMode), |
29 | myDiscret(discret), |
30 | myDeflection(deflection) |
31 | { |
32 | } |
33 | |
34 | //======================================================================= |
35 | //function : DrawCurve2dOn |
36 | //purpose : draw a 2D curve |
37 | //======================================================================= |
38 | |
39 | void DrawTrSurf_Drawable::DrawCurve2dOn (Adaptor2d_Curve2d& C, |
40 | Draw_Display& aDisplay) const |
41 | { |
42 | gp_Pnt P; |
43 | |
44 | gp_Pnt2d aPoint2d, |
45 | *aPoint2dPtr ; |
46 | if (myDrawMode == 1) { |
47 | Standard_Real Fleche = myDeflection/aDisplay.Zoom(); |
48 | GCPnts_UniformDeflection LineVu(C,Fleche); |
49 | if (LineVu.IsDone()) { |
50 | P = LineVu.Value(1) ; |
51 | aPoint2dPtr = (gp_Pnt2d *) &P ; |
52 | aDisplay.MoveTo(*aPoint2dPtr); |
53 | for (Standard_Integer i = 2; i <= LineVu.NbPoints(); i++) { |
54 | P = LineVu.Value(i) ; |
55 | aPoint2dPtr = (gp_Pnt2d *) &P ; |
56 | aDisplay.DrawTo(*aPoint2dPtr); |
57 | } |
58 | } |
59 | } |
60 | else { |
61 | Standard_Integer intrv, nbintv = C.NbIntervals(GeomAbs_CN); |
62 | TColStd_Array1OfReal TI(1,nbintv+1); |
63 | C.Intervals(TI,GeomAbs_CN); |
64 | C.D0(C.FirstParameter(),aPoint2d); |
65 | aDisplay.MoveTo(aPoint2d); |
66 | for (intrv = 1; intrv <= nbintv; intrv++) { |
67 | if (C.GetType() != GeomAbs_Line) { |
68 | Standard_Real t = TI(intrv); |
69 | Standard_Real step = (TI(intrv+1) - t) / myDiscret; |
70 | for (Standard_Integer i = 1; i < myDiscret; i++) { |
71 | t += step; |
72 | C.D0(t,aPoint2d); |
73 | aDisplay.DrawTo(aPoint2d); |
74 | } |
75 | } |
76 | C.D0(TI(intrv+1),aPoint2d); |
77 | aDisplay.DrawTo(aPoint2d); |
78 | } |
79 | } |
80 | } |
81 | |
82 | //======================================================================= |
83 | //static function : PlotCurve |
84 | //purpose : draw a 3D curve |
85 | //======================================================================= |
86 | static void PlotCurve (Draw_Display& aDisplay, |
87 | const Adaptor3d_Curve& C, |
88 | Standard_Real& theFirstParam, |
89 | Standard_Real theHalfStep, |
90 | const gp_Pnt& theFirstPnt, |
91 | const gp_Pnt& theLastPnt) |
92 | { |
93 | Standard_Real IsoRatio = 1.001; |
94 | gp_Pnt Pm; |
95 | |
96 | C.D0 (theFirstParam + theHalfStep, Pm); |
97 | |
98 | Standard_Real dfLength = theFirstPnt.Distance(theLastPnt); |
99 | if (dfLength < Precision::Confusion() || |
100 | Pm.Distance(theFirstPnt) + Pm.Distance(theLastPnt) <= IsoRatio*dfLength) { |
101 | aDisplay.DrawTo (theLastPnt); |
102 | } else { |
103 | PlotCurve (aDisplay, C, theFirstParam, theHalfStep/2., theFirstPnt, Pm); |
104 | Standard_Real aLocalF = theFirstParam + theHalfStep; |
105 | PlotCurve (aDisplay, C, aLocalF, theHalfStep/2., Pm, theLastPnt); |
106 | } |
107 | } |
108 | //======================================================================= |
109 | //function : DrawCurveOn |
110 | //purpose : draw a 3D curve |
111 | //======================================================================= |
112 | |
113 | void DrawTrSurf_Drawable::DrawCurveOn (Adaptor3d_Curve& C, |
114 | Draw_Display& aDisplay) const |
115 | { |
116 | gp_Pnt P; |
117 | if (myDrawMode == 1) { |
118 | Standard_Real Fleche = myDeflection/aDisplay.Zoom(); |
119 | GCPnts_UniformDeflection LineVu(C,Fleche); |
120 | if (LineVu.IsDone()) { |
121 | aDisplay.MoveTo(LineVu.Value(1)); |
122 | for (Standard_Integer i = 2; i <= LineVu.NbPoints(); i++) { |
123 | aDisplay.DrawTo(LineVu.Value(i)); |
124 | } |
125 | } |
126 | } |
127 | else { |
128 | Standard_Real j; |
129 | Standard_Integer intrv, nbintv = C.NbIntervals(GeomAbs_CN); |
130 | TColStd_Array1OfReal TI(1,nbintv+1); |
131 | C.Intervals(TI,GeomAbs_CN); |
132 | C.D0(C.FirstParameter(),P); |
133 | aDisplay.MoveTo(P); |
134 | GeomAbs_CurveType CurvType = C.GetType(); |
135 | gp_Pnt aPPnt=P, aNPnt; |
136 | |
137 | for (intrv = 1; intrv <= nbintv; intrv++) { |
138 | Standard_Real t = TI(intrv); |
139 | Standard_Real step = (TI(intrv+1) - t) / myDiscret; |
140 | |
141 | switch (CurvType) { |
142 | case GeomAbs_Line : |
143 | break; |
144 | case GeomAbs_Circle : |
145 | case GeomAbs_Ellipse : |
146 | for (j = 1; j < myDiscret; j++) { |
147 | t += step; |
148 | C.D0(t,P); |
149 | aDisplay.DrawTo(P); |
150 | } |
151 | break; |
152 | case GeomAbs_Parabola : |
153 | case GeomAbs_Hyperbola : |
154 | case GeomAbs_BezierCurve : |
155 | case GeomAbs_BSplineCurve : |
156 | case GeomAbs_OtherCurve : |
157 | for (j = 1; j <= myDiscret/2; j++) { |
158 | C.D0 (t+step*2., aNPnt); |
159 | PlotCurve (aDisplay, C, t, step, aPPnt, aNPnt); |
160 | aPPnt = aNPnt; |
161 | t += step*2.; |
162 | } |
163 | break; |
164 | } |
165 | |
166 | C.D0(TI(intrv+1),P); |
167 | aDisplay.DrawTo(P); |
168 | } |
169 | } |
170 | } |
171 | |
172 | |
173 | //======================================================================= |
174 | //function : DrawIsoCurveOn |
175 | //purpose : |
176 | //======================================================================= |
177 | |
178 | void DrawTrSurf_Drawable::DrawIsoCurveOn(Adaptor3d_IsoCurve& C, |
179 | const GeomAbs_IsoType T, |
180 | const Standard_Real P, |
181 | const Standard_Real F, |
182 | const Standard_Real L, |
183 | Draw_Display& dis) const |
184 | { |
185 | C.Load(T,P,F,L); |
186 | if ((C.GetType() == GeomAbs_BezierCurve) || |
187 | (C.GetType() == GeomAbs_BSplineCurve)) { |
188 | GeomAdaptor_Curve GC; |
189 | if (C.GetType() == GeomAbs_BezierCurve) |
190 | GC.Load(C.Bezier(),F,L); |
191 | else |
192 | GC.Load(C.BSpline(),F,L); |
193 | |
194 | DrawCurveOn(GC,dis); |
195 | } |
196 | else |
197 | DrawCurveOn(C,dis); |
198 | |
199 | } |