0023634: Eliminate Polyline and Polygon usage in drawers
[occt.git] / src / Prs3d / Prs3d_WFRestrictedFace.gxx
CommitLineData
b311480e 1// Created on: 1994-06-10
2// Created by: Laurent PAINNOT
3// Copyright (c) 1994-1999 Matra Datavision
4// Copyright (c) 1999-2012 OPEN CASCADE SAS
5//
6// The content of this file is subject to the Open CASCADE Technology Public
7// License Version 6.5 (the "License"). You may not use the content of this file
8// except in compliance with the License. Please obtain a copy of the License
9// at http://www.opencascade.org and read it completely before using this file.
10//
11// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13//
14// The Original Code and all software distributed under the License is
15// distributed on an "AS IS" basis, without warranty of any kind, and the
16// Initial Developer hereby disclaims all such warranties, including without
17// limitation, any warranties of merchantability, fitness for a particular
18// purpose or non-infringement. Please see the License for the specific terms
19// and conditions governing the rights and limitations under the License.
20
7fd59977 21
7fd59977 22#include <Hatch_Hatcher.hxx>
7fd59977 23#include <Graphic3d_Group.hxx>
24#include <gp_Pnt.hxx>
25#include <Prs3d_IsoAspect.hxx>
26#include <Adaptor3d_IsoCurve.hxx>
27#include <Bnd_Box2d.hxx>
28#include <BndLib_Add2dCurve.hxx>
29#include <Precision.hxx>
30#include <GeomAdaptor_Curve.hxx>
31#include <Geom_Curve.hxx>
32#include <GeomAbs_SurfaceType.hxx>
33#include <Geom_Surface.hxx>
34
35//=========================================================================
36// function: Add
37// purpose
38//=========================================================================
39void Prs3d_WFRestrictedFace::Add
40 (const Handle (Prs3d_Presentation)& aPresentation,
41 const Handle(BRepAdaptor_HSurface)& aFace,
42 const Standard_Boolean DrawUIso,
43 const Standard_Boolean DrawVIso,
44 const Quantity_Length aDeflection,
45 const Standard_Integer NBUiso,
46 const Standard_Integer NBViso,
47 const Handle(Prs3d_Drawer)& aDrawer,
48 Prs3d_NListOfSequenceOfPnt& Curves)
49{
7fd59977 50 Standard_Real aLimit = aDrawer->MaximalParameterValue();
51 Standard_Integer nbPoints = aDrawer->Discretisation();
52
7fd59977 53 RestrictionTool ToolRst (aFace);
54
55 // compute bounds of the restriction
56 Standard_Real UMin,UMax,VMin,VMax;
57// Standard_Real u,v,step;
58// Standard_Integer i, nbp= 10;
59 Standard_Integer i;
60 gp_Pnt2d P1,P2;
61 Bnd_Box2d B;
62
63 for (ToolRst.Init(); ToolRst.More(); ToolRst.Next()) {
64 Adaptor2d_Curve2dPtr TheRCurve = ToolRst.Value();
65 BndLib_Add2dCurve::Add(*TheRCurve, Precision::PConfusion(), B);
66 }
67 if ( ! B.IsVoid() )
68 B.Get(UMin, VMin, UMax, VMax);
69 else
70 { // no pcurves -- take natural bounds
71 UMin = aFace->Surface().FirstUParameter();
72 VMin = aFace->Surface().FirstVParameter();
73 UMax = aFace->Surface().LastUParameter();
74 VMax = aFace->Surface().LastVParameter();
75 }
76
7fd59977 77 // load the isos
78 Hatch_Hatcher isobuild(1.e-5,ToolRst.IsOriented());
79 Standard_Boolean UClosed = aFace->IsUClosed();
80 Standard_Boolean VClosed = aFace->IsVClosed();
81
82 if ( ! UClosed ) {
83 UMin = UMin + ( UMax - UMin) /1000.;
84 UMax = UMax - ( UMax - UMin) /1000.;
85 }
86
87 if ( ! VClosed ) {
88 VMin = VMin + ( VMax - VMin) /1000.;
89 VMax = VMax - ( VMax - VMin) /1000.;
90 }
91
92 if (DrawUIso){
93 if (NBUiso > 0) {
94 UClosed = Standard_False; // En attendant un hatcher de course.
95 Standard_Real du= UClosed ? (UMax-UMin)/NBUiso : (UMax-UMin)/(1+NBUiso);
96 for (i=1; i<=NBUiso;i++){
97 isobuild.AddXLine(UMin+du*i);
98 }
99 }
100 }
101 if (DrawVIso){
102 if ( NBViso > 0) {
103 VClosed = Standard_False;
104 Standard_Real dv= VClosed ?(VMax-VMin)/NBViso : (VMax-VMin)/(1+NBViso);
105 for (i=1; i<=NBViso;i++){
106 isobuild.AddYLine(VMin+dv*i);
107 }
108 }
109 }
110
7fd59977 111 // trim the isos
112 Standard_Real U1, U2, U, DU;
113
114 for (ToolRst.Init(); ToolRst.More(); ToolRst.Next()) {
115 TopAbs_Orientation Orient = ToolRst.Orientation();
116 if ( Orient == TopAbs_FORWARD || Orient == TopAbs_REVERSED ) {
117 Adaptor2d_Curve2dPtr TheRCurve = ToolRst.Value();
118 U1 = TheRCurve->FirstParameter();
119 U2 = TheRCurve->LastParameter();
120 if (TheRCurve->GetType() != GeomAbs_Line) {
121 DU = (U2-U1)/(nbPoints-1);
122 P2 = TheRCurve->Value(U1);
123 for (i = 2; i <= nbPoints; i++) {
124 U = U1 + (i-1)*DU;
125 P1 = P2;
126 P2 = TheRCurve->Value(U);
127 if(Orient == TopAbs_FORWARD )
128 isobuild.Trim(P1,P2);
129 else
130 isobuild.Trim(P2,P1);
131 }
132 }
133 else {
134 P1 = TheRCurve->Value(U1);
135 P2 = TheRCurve->Value(U2);
136 if(Orient == TopAbs_FORWARD )
137 isobuild.Trim(P1,P2);
138 else
139 isobuild.Trim(P2,P1);
140 }
141 }
142 }
143
7fd59977 144 // draw the isos
7fd59977 145 Adaptor3d_IsoCurve anIso;
146 anIso.Load(aFace);
147 Handle(Geom_Curve) BC;
148 const BRepAdaptor_Surface& BS = *(BRepAdaptor_Surface*)&(aFace->Surface());
149 GeomAbs_SurfaceType thetype = aFace->GetType();
150
151 Standard_Integer NumberOfLines = isobuild.NbLines();
152 Handle(Geom_Surface) GB;
153 if (thetype == GeomAbs_BezierSurface) {
154 GB = BS.Bezier();
155 }
156 else if (thetype == GeomAbs_BSplineSurface){
157 GB = BS.BSpline();
158 }
159
160 for (i = 1; i <= NumberOfLines; i++) {
161 Standard_Integer NumberOfIntervals = isobuild.NbIntervals(i);
162 Standard_Real Coord = isobuild.Coordinate(i);
163 for (Standard_Integer j = 1; j <= NumberOfIntervals; j++) {
164 Standard_Real b1=isobuild.Start(i,j),b2=isobuild.End(i,j);
165
166 if(b1 == RealFirst() || b2 == RealLast())
167 continue;
168 //b1 = b1 == RealFirst() ? - aLimit : b1;
169 //b2 = b2 == RealLast() ? aLimit : b2;
170
171 TColgp_SequenceOfPnt Pnts;
172 if (!GB.IsNull()) {
173 if (isobuild.IsXLine(i))
174 BC = GB->UIso(Coord);
175 else
176 BC = GB->VIso(Coord);
177 //Note that the isos are the part of the shape, it will be displayed after a computation the whole shape
178 //NbPoints = 30 - default parameter for computation of such curves
b8ddfc2f 179 DrawFaceIso::Add(aPresentation,GeomAdaptor_Curve(BC), b1, b2, aDeflection, Pnts, 30, Standard_False);
7fd59977 180 Curves.Append(Pnts);
181 }
182 else {
183 if (isobuild.IsXLine(i))
184 anIso.Load(GeomAbs_IsoU,Coord,b1,b2);
185 else
186 anIso.Load(GeomAbs_IsoV,Coord,b1,b2);
b8ddfc2f 187 DrawFaceIso::Add(aPresentation,anIso, aDeflection, aDrawer, Pnts, Standard_False);
7fd59977 188 Curves.Append(Pnts);
189 }
190 }
191 }
7fd59977 192}
193
194
195//=========================================================================
196// function: Match
197// purpose
198//=========================================================================
199Standard_Boolean Prs3d_WFRestrictedFace::Match
200 (const Quantity_Length X,
201 const Quantity_Length Y,
202 const Quantity_Length Z,
203 const Quantity_Length aDistance,
204 const Handle(BRepAdaptor_HSurface)& aFace,
205 const Standard_Boolean DrawUIso,
206 const Standard_Boolean DrawVIso,
207 const Quantity_Length aDeflection,
208 const Standard_Integer NBUiso,
209 const Standard_Integer NBViso,
210 const Handle(Prs3d_Drawer)& aDrawer)
211{
212 Standard_Real aLimit = aDrawer->MaximalParameterValue();
213 Standard_Integer nbPoints = aDrawer->Discretisation();
214 RestrictionTool ToolRst (aFace);
215
216 // compute bounds of the restriction
217 Standard_Real UMin,UMax,VMin,VMax;
218 Standard_Real u,v,step;
219 Standard_Integer i,nbP = 10;
220 UMin = VMin = RealLast();
221 UMax = VMax = RealFirst();
222 gp_Pnt2d P1,P2;
223
224 for (ToolRst.Init(); ToolRst.More(); ToolRst.Next()) {
225 Adaptor2d_Curve2dPtr TheRCurve = ToolRst.Value();
226 u = TheRCurve->FirstParameter();
227 v = TheRCurve->LastParameter();
228 if (TheRCurve->GetType() != GeomAbs_Line) {
229 step = ( v - u) / nbP;
230 for (i = 0; i <= nbP; i++) {
231 gp_Pnt2d P = TheRCurve->Value(u);
232 if (P.X() < UMin) UMin = P.X();
233 if (P.X() > UMax) UMax = P.X();
234 if (P.Y() < VMin) VMin = P.Y();
235 if (P.Y() > VMax) VMax = P.Y();
236 u += step;
237 }
238 }
239 else {
240 P1 = TheRCurve->Value(u);
241 if (P1.X() < UMin) UMin = P1.X();
242 if (P1.X() > UMax) UMax = P1.X();
243 if (P1.Y() < VMin) VMin = P1.Y();
244 if (P1.Y() > VMax) VMax = P1.Y();
245
246 P2 = TheRCurve->Value(v);
247 if (P2.X() < UMin) UMin = P2.X();
248 if (P2.X() > UMax) UMax = P2.X();
249 if (P2.Y() < VMin) VMin = P2.Y();
250 if (P2.Y() > VMax) VMax = P2.Y();
251 }
252 }
253
254 // load the isos
255 Hatch_Hatcher isobuild(1.e-5,ToolRst.IsOriented());
256 Standard_Boolean UClosed = aFace->IsUClosed();
257 Standard_Boolean VClosed = aFace->IsVClosed();
258
259 if ( ! UClosed ) {
260 UMin = UMin + ( UMax - UMin) /1000.;
261 UMax = UMax - ( UMax - UMin) /1000.;
262 }
263
264 if ( ! VClosed ) {
265 VMin = VMin + ( VMax - VMin) /1000.;
266 VMax = VMax - ( VMax - VMin) /1000.;
267 }
268
269 if (DrawUIso){
270 if (NBUiso > 0) {
271 UClosed = Standard_False; // En attendant un hatcher de course.
272 Standard_Real du= UClosed ? (UMax-UMin)/NBUiso : (UMax-UMin)/(1+NBUiso);
273 for (i=1; i<=NBUiso;i++){
274 isobuild.AddXLine(UMin+du*i);
275 }
276 }
277 }
278 if (DrawVIso){
279 if ( NBViso > 0) {
280 VClosed = Standard_False;
281 Standard_Real dv= VClosed ?(VMax-VMin)/NBViso : (VMax-VMin)/(1+NBViso);
282 for (i=1; i<=NBViso;i++){
283 isobuild.AddYLine(VMin+dv*i);
284 }
285 }
286 }
287
288 // trim the isos
289 Standard_Real U1, U2, U, DU;
290
291 for (ToolRst.Init(); ToolRst.More(); ToolRst.Next()) {
292 TopAbs_Orientation Orient = ToolRst.Orientation();
293 if ( Orient == TopAbs_FORWARD || Orient == TopAbs_REVERSED ) {
294 Adaptor2d_Curve2dPtr TheRCurve = ToolRst.Value();
295 U1 = TheRCurve->FirstParameter();
296 U2 = TheRCurve->LastParameter();
297 if (TheRCurve->GetType() != GeomAbs_Line) {
298 DU = (U2-U1)/(nbPoints-1);
299 P2 = TheRCurve->Value(U1);
300 for (i = 2; i <= nbPoints; i++) {
301 U = U1 + (i-1)*DU;
302 P1 = P2;
303 P2 = TheRCurve->Value(U);
304 if(Orient == TopAbs_FORWARD )
305 isobuild.Trim(P1,P2);
306 else
307 isobuild.Trim(P2,P1);
308 }
309 }
310 else {
311 P1 = TheRCurve->Value(U1);
312 P2 = TheRCurve->Value(U2);
313 if(Orient == TopAbs_FORWARD )
314 isobuild.Trim(P1,P2);
315 else
316 isobuild.Trim(P2,P1);
317 }
318 }
319 }
320
321 // draw the isos
322
323 Adaptor3d_IsoCurve anIso;
324 anIso.Load(aFace);
325 Standard_Integer NumberOfLines = isobuild.NbLines();
326
327 for (i = 1; i <= NumberOfLines; i++) {
328 Standard_Integer NumberOfIntervals = isobuild.NbIntervals(i);
329 Standard_Real Coord = isobuild.Coordinate(i);
330 for (Standard_Integer j = 1; j <= NumberOfIntervals; j++) {
331 Standard_Real b1=isobuild.Start(i,j),b2=isobuild.End(i,j);
332
333 b1 = b1 == RealFirst() ? - aLimit : b1;
334 b2 = b2 == RealLast() ? aLimit : b2;
335
336
337 if (isobuild.IsXLine(i))
338 anIso.Load(GeomAbs_IsoU,Coord,b1,b2);
339 else
340 anIso.Load(GeomAbs_IsoV,Coord,b1,b2);
341
342 if (DrawFaceIso::Match(X,Y,Z,aDistance,anIso,
343 aDeflection, aLimit, nbPoints))
344 return Standard_True;
345
346
347 }
348 }
b8ddfc2f 349 return Standard_False;
7fd59977 350}
351
352
7fd59977 353//=========================================================================
354// function: Add
355// purpose
356//=========================================================================
357void Prs3d_WFRestrictedFace::Add
358 (const Handle (Prs3d_Presentation)& aPresentation,
359 const Handle(BRepAdaptor_HSurface)& aFace,
b8ddfc2f 360 const Handle (Prs3d_Drawer)& aDrawer)
361{
7fd59977 362 Prs3d_NListOfSequenceOfPnt Curves;
363 Prs3d_WFRestrictedFace::Add (
364 aPresentation,
365 aFace,
366 Standard_True,
367 Standard_True,
b8ddfc2f 368 aDrawer->MaximalChordialDeviation(),
369 aDrawer->UIsoAspect()->Number(),
370 aDrawer->VIsoAspect()->Number(),
7fd59977 371 aDrawer,
372 Curves);
7fd59977 373}
374
375
376//=========================================================================
377// function: AddUIso
378// purpose
379//=========================================================================
380void Prs3d_WFRestrictedFace::AddUIso
381 (const Handle (Prs3d_Presentation)& aPresentation,
382 const Handle(BRepAdaptor_HSurface)& aFace,
b8ddfc2f 383 const Handle (Prs3d_Drawer)& aDrawer)
384{
7fd59977 385 Prs3d_NListOfSequenceOfPnt Curves;
386 Prs3d_WFRestrictedFace::Add (
387 aPresentation,
388 aFace,
389 Standard_True,
390 Standard_False,
b8ddfc2f 391 aDrawer->MaximalChordialDeviation(),
392 aDrawer->UIsoAspect()->Number(),
393 aDrawer->VIsoAspect()->Number(),
7fd59977 394 aDrawer,
395 Curves);
396}
397
398
399//=========================================================================
400// function: AddVIso
401// purpose
402//=========================================================================
403void Prs3d_WFRestrictedFace::AddVIso
404 (const Handle (Prs3d_Presentation)& aPresentation,
405 const Handle(BRepAdaptor_HSurface)& aFace,
b8ddfc2f 406 const Handle (Prs3d_Drawer)& aDrawer)
407{
7fd59977 408 Prs3d_NListOfSequenceOfPnt Curves;
409 Prs3d_WFRestrictedFace::Add (
410 aPresentation,
411 aFace,
412 Standard_False,
413 Standard_True,
b8ddfc2f 414 aDrawer->MaximalChordialDeviation(),
415 aDrawer->UIsoAspect()->Number(),
416 aDrawer->VIsoAspect()->Number(),
7fd59977 417 aDrawer,
418 Curves);
419}
420
421
422//=========================================================================
423// function: Match
424// purpose
425//=========================================================================
426Standard_Boolean Prs3d_WFRestrictedFace::Match
427 (const Quantity_Length X,
428 const Quantity_Length Y,
429 const Quantity_Length Z,
430 const Quantity_Length aDistance,
431 const Handle(BRepAdaptor_HSurface)& aFace,
b8ddfc2f 432 const Handle (Prs3d_Drawer)& aDrawer)
433{
7fd59977 434 return Prs3d_WFRestrictedFace::Match (
435 X,Y,Z,aDistance,
b8ddfc2f 436 aFace,
437 Standard_True,
438 Standard_True,
439 aDrawer->MaximalChordialDeviation(),
440 aDrawer->UIsoAspect()->Number(),
441 aDrawer->VIsoAspect()->Number(),
442 aDrawer);
7fd59977 443}
444
445
446//=========================================================================
447// function: MatchUIso
448// purpose
449//=========================================================================
450Standard_Boolean Prs3d_WFRestrictedFace::MatchUIso
451 (const Quantity_Length X,
452 const Quantity_Length Y,
453 const Quantity_Length Z,
454 const Quantity_Length aDistance,
455 const Handle(BRepAdaptor_HSurface)& aFace,
b8ddfc2f 456 const Handle (Prs3d_Drawer)& aDrawer)
457{
7fd59977 458 return Prs3d_WFRestrictedFace::Match (
459 X,Y,Z,aDistance,
b8ddfc2f 460 aFace,
461 Standard_True,
462 Standard_False,
463 aDrawer->MaximalChordialDeviation(),
464 aDrawer->UIsoAspect()->Number(),
465 aDrawer->VIsoAspect()->Number(),
466 aDrawer);
7fd59977 467}
468
469
470//=========================================================================
471// function: MatchVIso
472// purpose
473//=========================================================================
474Standard_Boolean Prs3d_WFRestrictedFace::MatchVIso
475 (const Quantity_Length X,
476 const Quantity_Length Y,
477 const Quantity_Length Z,
478 const Quantity_Length aDistance,
479 const Handle(BRepAdaptor_HSurface)& aFace,
b8ddfc2f 480 const Handle (Prs3d_Drawer)& aDrawer)
481{
7fd59977 482 return Prs3d_WFRestrictedFace::Match (
483 X,Y,Z,aDistance,
b8ddfc2f 484 aFace,
485 Standard_False,
486 Standard_True,
487 aDrawer->MaximalChordialDeviation(),
488 aDrawer->UIsoAspect()->Number(),
489 aDrawer->VIsoAspect()->Number(),
490 aDrawer);
7fd59977 491}