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