0023634: Eliminate Polyline and Polygon usage in drawers
[occt.git] / src / Prs3d / Prs3d_WFDeflectionRestrictedFace.gxx
CommitLineData
b311480e 1// Copyright (c) 1995-1999 Matra Datavision
2// Copyright (c) 1999-2012 OPEN CASCADE SAS
3//
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.
8//
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.
11//
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.
18
7fd59977 19#include <Hatch_Hatcher.hxx>
7fd59977 20#include <Graphic3d_Group.hxx>
21#include <gp_Pnt.hxx>
22#include <gp_Pnt2d.hxx>
23#include <Prs3d_IsoAspect.hxx>
24#include <Adaptor2d_Curve2d.hxx>
25#include <GCPnts_UniformDeflection.hxx>
26#include <Adaptor3d_IsoCurve.hxx>
27
7fd59977 28
29//=========================================================================
30// function: Add
31// purpose
32//=========================================================================
33void Prs3d_WFDeflectionRestrictedFace::Add
34 (const Handle (Prs3d_Presentation)& aPresentation,
35 const Handle(BRepAdaptor_HSurface)& aFace,
36 const Standard_Boolean DrawUIso,
37 const Standard_Boolean DrawVIso,
38 const Quantity_Length Deflection,
39 const Standard_Integer NBUiso,
40 const Standard_Integer NBViso,
41 const Handle(Prs3d_Drawer)& aDrawer,
42 Prs3d_NListOfSequenceOfPnt& Curves)
43{
7fd59977 44 RestrictionTool ToolRst (aFace);
45 Standard_Real aLimit = aDrawer->MaximalParameterValue();
46
47 // compute bounds of the restriction
48 Standard_Real UMin,UMax,VMin,VMax;
49 Standard_Real u,v,step;
50 Standard_Integer i,nbPoints = 10;
51 UMin = VMin = RealLast();
52 UMax = VMax = RealFirst();
53 gp_Pnt2d P;
54
55 for (ToolRst.Init(); ToolRst.More(); ToolRst.Next()) {
56 Adaptor2d_Curve2dPtr TheRCurve = ToolRst.Value();
57 u = TheRCurve->FirstParameter();
58 v = TheRCurve->LastParameter();
59 if (TheRCurve->GetType() != GeomAbs_Line) {
60 step = ( v - u) / nbPoints;
61 for (i = 0; i <= nbPoints; i++) {
62 TheRCurve->D0(u, P);
63 if (P.X() < UMin) UMin = P.X();
64 if (P.X() > UMax) UMax = P.X();
65 if (P.Y() < VMin) VMin = P.Y();
66 if (P.Y() > VMax) VMax = P.Y();
67 u += step;
68 }
69 }
70 else {
71 TheRCurve->D0(u, P);
72 if (P.X() < UMin) UMin = P.X();
73 if (P.X() > UMax) UMax = P.X();
74 if (P.Y() < VMin) VMin = P.Y();
75 if (P.Y() > VMax) VMax = P.Y();
76
77 TheRCurve->D0(v, P);
78 if (P.X() < UMin) UMin = P.X();
79 if (P.X() > UMax) UMax = P.X();
80 if (P.Y() < VMin) VMin = P.Y();
81 if (P.Y() > VMax) VMax = P.Y();
82 }
83 }
84
7fd59977 85 // load the isos
86 Hatch_Hatcher isobuild(1.e-5,ToolRst.IsOriented());
87 Standard_Boolean UClosed = aFace->IsUClosed();
88 Standard_Boolean VClosed = aFace->IsVClosed();
89
90 if ( ! UClosed ) {
91 UMin = UMin + ( UMax - UMin) /1000.;
92 UMax = UMax - ( UMax - UMin) /1000.;
93 }
94
95 if ( ! VClosed ) {
96 VMin = VMin + ( VMax - VMin) /1000.;
97 VMax = VMax - ( VMax - VMin) /1000.;
98 }
99
100 if (DrawUIso){
101 if (NBUiso > 0) {
102 UClosed = Standard_False; // En attendant un hatcher de course.
103 Standard_Real du= UClosed ? (UMax-UMin)/NBUiso : (UMax-UMin)/(1+NBUiso);
104 for (i=1; i<=NBUiso;i++){
105 isobuild.AddXLine(UMin+du*i);
106 }
107 }
108 }
109 if (DrawVIso){
110 if ( NBViso > 0) {
111 VClosed = Standard_False;
112 Standard_Real dv= VClosed ?(VMax-VMin)/NBViso : (VMax-VMin)/(1+NBViso);
113 for (i=1; i<=NBViso;i++){
114 isobuild.AddYLine(VMin+dv*i);
115 }
116 }
117 }
118
7fd59977 119 // trim the isos
120 gp_Pnt2d P1,P2;
121 Standard_Real U1, U2;
122 gp_Pnt dummypnt;
123 for (ToolRst.Init(); ToolRst.More(); ToolRst.Next()) {
124 TopAbs_Orientation Orient = ToolRst.Orientation();
125 if ( Orient == TopAbs_FORWARD || Orient == TopAbs_REVERSED ) {
126 Adaptor2d_Curve2dPtr TheRCurve = ToolRst.Value();
127 if (TheRCurve->GetType() != GeomAbs_Line) {
128 GCPnts_UniformDeflection UDP(*TheRCurve, Deflection, Standard_False);
129 if (UDP.IsDone()) {
130 Standard_Integer NumberOfPoints = UDP.NbPoints();
131 if ( NumberOfPoints >= 2 ) {
132 dummypnt = UDP.Value(1);
133 P2.SetCoord(dummypnt.X(), dummypnt.Y());
134 for (i = 2; i <= NumberOfPoints; i++) {
135 P1 = P2;
136 dummypnt = UDP.Value(i);
137 P2.SetCoord(dummypnt.X(), dummypnt.Y());
138 if(Orient == TopAbs_FORWARD )
139 isobuild.Trim(P1,P2);
140 else
141 isobuild.Trim(P2,P1);
142 }
143 }
144 }
145 else {
146 cout << "Cannot evaluate curve on surface"<<endl;
147 }
148 }
149 else {
150 U1 = TheRCurve->FirstParameter();
151 U2 = TheRCurve->LastParameter();
152 P1 = TheRCurve->Value(U1);
153 P2 = TheRCurve->Value(U2);
154 if(Orient == TopAbs_FORWARD )
155 isobuild.Trim(P1,P2);
156 else
157 isobuild.Trim(P2,P1);
158 }
159 }
160 }
161
7fd59977 162 // draw the isos
7fd59977 163 Adaptor3d_IsoCurve anIso;
164 anIso.Load(aFace);
165 Standard_Integer NumberOfLines = isobuild.NbLines();
166
167 for (i = 1; i <= NumberOfLines; i++) {
168 Standard_Integer NumberOfIntervals = isobuild.NbIntervals(i);
169 Standard_Real Coord = isobuild.Coordinate(i);
170 for (Standard_Integer j = 1; j <= NumberOfIntervals; j++) {
171 Standard_Real b1=isobuild.Start(i,j),b2=isobuild.End(i,j);
172
173 b1 = b1 == RealFirst() ? - aLimit : b1;
174 b2 = b2 == RealLast() ? aLimit : b2;
175
176 if (isobuild.IsXLine(i))
177 anIso.Load(GeomAbs_IsoU,Coord,b1,b2);
178 else
179 anIso.Load(GeomAbs_IsoV,Coord,b1,b2);
180
181 DrawFaceIso::Add(aPresentation,anIso,Deflection, aLimit);
182 }
183 }
7fd59977 184}
185
186
187//=========================================================================
188// function: Match
189// purpose
190//=========================================================================
191Standard_Boolean Prs3d_WFDeflectionRestrictedFace::Match
192 (const Quantity_Length X,
193 const Quantity_Length Y,
194 const Quantity_Length Z,
195 const Quantity_Length aDistance,
196 const Handle(BRepAdaptor_HSurface)& aFace,
197 const Handle(Prs3d_Drawer)& aDrawer,
198 const Standard_Boolean DrawUIso,
199 const Standard_Boolean DrawVIso,
200 const Quantity_Length Deflection,
201 const Standard_Integer NBUiso,
202 const Standard_Integer NBViso)
203{
204
205 RestrictionTool ToolRst (aFace);
206 const Standard_Real aLimit = aDrawer->MaximalParameterValue();
207
208 // compute bounds of the restriction
209 Standard_Real UMin,UMax,VMin,VMax;
210 Standard_Real u,v,step;
211 Standard_Integer i,nbPoints = 10;
212 UMin = VMin = RealLast();
213 UMax = VMax = RealFirst();
214
215 for (ToolRst.Init(); ToolRst.More(); ToolRst.Next()) {
216 Adaptor2d_Curve2dPtr TheRCurve = ToolRst.Value();
217 u = TheRCurve->FirstParameter();
218 v = TheRCurve->LastParameter();
219 step = ( v - u) / nbPoints;
220 for (i = 0; i <= nbPoints; i++) {
221 gp_Pnt2d P = TheRCurve->Value(u);
222 if (P.X() < UMin) UMin = P.X();
223 if (P.X() > UMax) UMax = P.X();
224 if (P.Y() < VMin) VMin = P.Y();
225 if (P.Y() > VMax) VMax = P.Y();
226 u += step;
227 }
228 }
229
230 // load the isos
231 Hatch_Hatcher isobuild(1.e-5,ToolRst.IsOriented());
232 Standard_Boolean UClosed = aFace->IsUClosed();
233 Standard_Boolean VClosed = aFace->IsVClosed();
234
235 if ( ! UClosed ) {
236 UMin = UMin + ( UMax - UMin) /1000.;
237 UMax = UMax - ( UMax - UMin) /1000.;
238 }
239
240 if ( ! VClosed ) {
241 VMin = VMin + ( VMax - VMin) /1000.;
242 VMax = VMax - ( VMax - VMin) /1000.;
243 }
244
245 if (DrawUIso){
246 if (NBUiso > 0) {
247 UClosed = Standard_False; // En attendant un hatcher de course.
248 Standard_Real du= UClosed ? (UMax-UMin)/NBUiso : (UMax-UMin)/(1+NBUiso);
249 for (i=1; i<=NBUiso;i++){
250 isobuild.AddXLine(UMin+du*i);
251 }
252 }
253 }
254 if (DrawVIso){
255 if ( NBViso > 0) {
256 VClosed = Standard_False;
257 Standard_Real dv= VClosed ?(VMax-VMin)/NBViso : (VMax-VMin)/(1+NBViso);
258 for (i=1; i<=NBViso;i++){
259 isobuild.AddYLine(VMin+dv*i);
260 }
261 }
262 }
263
264 // trim the isos
265 gp_Pnt2d P1,P2;
266 gp_Pnt dummypnt;
267 for (ToolRst.Init(); ToolRst.More(); ToolRst.Next()) {
268 TopAbs_Orientation Orient = ToolRst.Orientation();
269 if ( Orient == TopAbs_FORWARD || Orient == TopAbs_REVERSED ) {
270 Adaptor2d_Curve2dPtr TheRCurve = ToolRst.Value();
271 GCPnts_UniformDeflection UDP(*TheRCurve, Deflection, Standard_False);
272 if (UDP.IsDone()) {
273 Standard_Integer NumberOfPoints = UDP.NbPoints();
274 if ( NumberOfPoints >= 2 ) {
275 dummypnt = UDP.Value(1);
276 P2.SetCoord(dummypnt.X(), dummypnt.Y());
277 for (i = 2; i <= NumberOfPoints; i++) {
278 P1 = P2;
279 dummypnt = UDP.Value(i);
280 P2.SetCoord(dummypnt.X(), dummypnt.Y());
281 if(Orient == TopAbs_FORWARD )
282 isobuild.Trim(P1,P2);
283 else
284 isobuild.Trim(P2,P1);
285 }
286 }
287 }
288 else {
289 cout << "Cannot evaluate curve on surface"<<endl;
290 }
291 }
292 }
293
294 // draw the isos
295
296 Adaptor3d_IsoCurve anIso;
297 anIso.Load(aFace);
298 Standard_Integer NumberOfLines = isobuild.NbLines();
299
300 for (i = 1; i <= NumberOfLines; i++) {
301 Standard_Integer NumberOfIntervals = isobuild.NbIntervals(i);
302 Standard_Real Coord = isobuild.Coordinate(i);
303 for (Standard_Integer j = 1; j <= NumberOfIntervals; j++) {
304 Standard_Real b1=isobuild.Start(i,j),b2=isobuild.End(i,j);
305
306 b1 = b1 == RealFirst() ? - aLimit : b1;
307 b2 = b2 == RealLast() ? aLimit : b2;
308
309 if (isobuild.IsXLine(i))
310 anIso.Load(GeomAbs_IsoU,Coord,b1,b2);
311 else
312 anIso.Load(GeomAbs_IsoV,Coord,b1,b2);
313
314 if (DrawFaceIso::Match(X,Y,Z,aDistance,anIso,Deflection, aLimit))
315 return Standard_True;
316 }
317 }
318 return Standard_False;
319}
320
321
322//=========================================================================
323// function: Add
324// purpose
325//=========================================================================
326void Prs3d_WFDeflectionRestrictedFace::Add
327 (const Handle (Prs3d_Presentation)& aPresentation,
328 const Handle(BRepAdaptor_HSurface)& aFace,
b8ddfc2f 329 const Handle (Prs3d_Drawer)& aDrawer)
330{
7fd59977 331 Prs3d_WFDeflectionRestrictedFace::Add (
332 aPresentation,
333 aFace,
334 Standard_True,
335 Standard_True,
b8ddfc2f 336 aDrawer->MaximalChordialDeviation(),
337 aDrawer->UIsoAspect()->Number(),
338 aDrawer->VIsoAspect()->Number(),
7fd59977 339 aDrawer);
7fd59977 340}
341
342
343//=========================================================================
344// function: AddUIso
345// purpose
346//=========================================================================
347void Prs3d_WFDeflectionRestrictedFace::AddUIso
348 (const Handle (Prs3d_Presentation)& aPresentation,
349 const Handle(BRepAdaptor_HSurface)& aFace,
b8ddfc2f 350 const Handle (Prs3d_Drawer)& aDrawer)
351{
7fd59977 352 Prs3d_WFDeflectionRestrictedFace::Add (
353 aPresentation,
354 aFace,
355 Standard_True,
356 Standard_False,
b8ddfc2f 357 aDrawer->MaximalChordialDeviation(),
358 aDrawer->UIsoAspect()->Number(),
359 aDrawer->VIsoAspect()->Number(),
7fd59977 360 aDrawer);
361}
362
363
364//=========================================================================
365// function: AddVIso
366// purpose
367//=========================================================================
368void Prs3d_WFDeflectionRestrictedFace::AddVIso
369 (const Handle (Prs3d_Presentation)& aPresentation,
370 const Handle(BRepAdaptor_HSurface)& aFace,
b8ddfc2f 371 const Handle (Prs3d_Drawer)& aDrawer)
372{
373 Prs3d_WFDeflectionRestrictedFace::Add (
7fd59977 374 aPresentation,
375 aFace,
376 Standard_False,
377 Standard_True,
b8ddfc2f 378 aDrawer->MaximalChordialDeviation(),
379 aDrawer->UIsoAspect()->Number(),
380 aDrawer->VIsoAspect()->Number(),
7fd59977 381 aDrawer);
382}
383
384
385//=========================================================================
386// function: Match
387// purpose
388//=========================================================================
389Standard_Boolean Prs3d_WFDeflectionRestrictedFace::Match
390 (const Quantity_Length X,
391 const Quantity_Length Y,
392 const Quantity_Length Z,
393 const Quantity_Length aDistance,
394 const Handle(BRepAdaptor_HSurface)& aFace,
b8ddfc2f 395 const Handle (Prs3d_Drawer)& aDrawer)
396{
7fd59977 397 return Prs3d_WFDeflectionRestrictedFace::Match (
398 X,Y,Z,aDistance,
b8ddfc2f 399 aFace,
400 aDrawer,
401 Standard_True,
402 Standard_True,
403 aDrawer->MaximalChordialDeviation(),
404 aDrawer->UIsoAspect()->Number(),
405 aDrawer->VIsoAspect()->Number());
7fd59977 406}
407
408
409//=========================================================================
410// function: MatchUIso
411// purpose
412//=========================================================================
413Standard_Boolean Prs3d_WFDeflectionRestrictedFace::MatchUIso
414 (const Quantity_Length X,
415 const Quantity_Length Y,
416 const Quantity_Length Z,
417 const Quantity_Length aDistance,
418 const Handle(BRepAdaptor_HSurface)& aFace,
b8ddfc2f 419 const Handle (Prs3d_Drawer)& aDrawer)
420{
7fd59977 421 Quantity_Length Deflection = aDrawer->MaximalChordialDeviation();
422 Standard_Integer finu = aDrawer->UIsoAspect()->Number();
423 Standard_Integer finv = aDrawer->VIsoAspect()->Number();
424 return Prs3d_WFDeflectionRestrictedFace::Match (
425 X,Y,Z,aDistance,
b8ddfc2f 426 aFace,
427 aDrawer,
428 Standard_True,
429 Standard_False,
430 Deflection,
431 finu,
432 finv);
7fd59977 433}
434
435
436//=========================================================================
437// function: MatchVIso
438// purpose
439//=========================================================================
440Standard_Boolean Prs3d_WFDeflectionRestrictedFace::MatchVIso
441 (const Quantity_Length X,
442 const Quantity_Length Y,
443 const Quantity_Length Z,
444 const Quantity_Length aDistance,
445 const Handle(BRepAdaptor_HSurface)& aFace,
b8ddfc2f 446 const Handle (Prs3d_Drawer)& aDrawer)
447{
7fd59977 448 return Prs3d_WFDeflectionRestrictedFace::Match (
449 X,Y,Z,aDistance,
b8ddfc2f 450 aFace,
451 aDrawer,
452 Standard_False,
453 Standard_True,
454 aDrawer->MaximalChordialDeviation(),
455 aDrawer->UIsoAspect()->Number(),
456 aDrawer->VIsoAspect()->Number());
7fd59977 457}