1 // Created on: 1995-05-05
2 // Created by: Christophe MARION
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 //#define No_Exception
22 #include <HLRAlgo_BiPoint.hxx>
23 #include <HLRAlgo_EdgeStatus.hxx>
24 #include <HLRAlgo_ListOfBPoint.hxx>
25 #include <HLRAlgo_PolyAlgo.hxx>
26 #include <HLRAlgo_PolyData.hxx>
27 #include <HLRAlgo_PolyShellData.hxx>
28 #include <Precision.hxx>
29 #include <Standard_Type.hxx>
31 IMPLEMENT_STANDARD_RTTIEXT(HLRAlgo_PolyAlgo,MMgt_TShared)
33 #define EMskGrALin1 ((Standard_Integer) 8)
34 #define EMskGrALin2 ((Standard_Integer) 16)
35 #define EMskGrALin3 ((Standard_Integer) 32)
36 #define FMskHiding ((Standard_Integer) 256)
38 #define TriNode1 ((Standard_Integer*)TriIndices)[0]
39 #define TriNode2 ((Standard_Integer*)TriIndices)[1]
40 #define TriNode3 ((Standard_Integer*)TriIndices)[2]
41 #define TriFlags ((Standard_Integer*)TriIndices)[3]
43 #define XV1 myRealPtr[0]
44 #define XV2 myRealPtr[1]
45 #define XV3 myRealPtr[2]
46 #define YV1 myRealPtr[3]
47 #define YV2 myRealPtr[4]
48 #define YV3 myRealPtr[5]
49 #define Param myRealPtr[6]
50 #define myTolParam myRealPtr[7]
51 #define myTolAngular myRealPtr[8]
52 #define myTolerance myRealPtr[9]
54 #define PntX1 ((Standard_Real*)Coordinates)[ 0]
55 #define PntY1 ((Standard_Real*)Coordinates)[ 1]
56 #define PntZ1 ((Standard_Real*)Coordinates)[ 2]
57 #define PntX2 ((Standard_Real*)Coordinates)[ 3]
58 #define PntY2 ((Standard_Real*)Coordinates)[ 4]
59 #define PntZ2 ((Standard_Real*)Coordinates)[ 5]
60 #define PntXP1 ((Standard_Real*)Coordinates)[ 6]
61 #define PntYP1 ((Standard_Real*)Coordinates)[ 7]
62 #define PntZP1 ((Standard_Real*)Coordinates)[ 8]
63 #define PntXP2 ((Standard_Real*)Coordinates)[ 9]
64 #define PntYP2 ((Standard_Real*)Coordinates)[10]
65 #define PntZP2 ((Standard_Real*)Coordinates)[11]
67 #define TotXMin ((Standard_Real*)TotMinMax)[0]
68 #define TotYMin ((Standard_Real*)TotMinMax)[1]
69 #define TotZMin ((Standard_Real*)TotMinMax)[2]
70 #define TotXMax ((Standard_Real*)TotMinMax)[3]
71 #define TotYMax ((Standard_Real*)TotMinMax)[4]
72 #define TotZMax ((Standard_Real*)TotMinMax)[5]
74 #define ShapeIndex ((Standard_Integer*)IndexPtr)[0]
75 #define FaceConex1 ((Standard_Integer*)IndexPtr)[1]
76 #define Face1Pt1 ((Standard_Integer*)IndexPtr)[2]
77 #define Face1Pt2 ((Standard_Integer*)IndexPtr)[3]
78 #define FaceConex2 ((Standard_Integer*)IndexPtr)[4]
79 #define Face2Pt1 ((Standard_Integer*)IndexPtr)[5]
80 #define Face2Pt2 ((Standard_Integer*)IndexPtr)[6]
81 #define MinSeg ((Standard_Integer*)IndexPtr)[7]
82 #define MaxSeg ((Standard_Integer*)IndexPtr)[8]
83 #define SegFlags ((Standard_Integer*)IndexPtr)[9]
85 #define MinShell ((Standard_Integer*)ShellIndices)[0]
86 #define MaxShell ((Standard_Integer*)ShellIndices)[1]
88 #define FIndex ((Standard_Integer*)PolyTIndices)[0]
89 #define MinPolyT ((Standard_Integer*)PolyTIndices)[1]
90 #define MaxPolyT ((Standard_Integer*)PolyTIndices)[2]
92 //static Standard_Integer ERROR = Standard_False;
94 //=======================================================================
95 //function : HLRAlgo_PolyAlgo
97 //=======================================================================
99 HLRAlgo_PolyAlgo::HLRAlgo_PolyAlgo ()
101 myTolParam = 0.00000001;
102 myTolAngular = 0.0001;
105 //=======================================================================
108 //=======================================================================
111 HLRAlgo_PolyAlgo::Init (const Handle(TColStd_HArray1OfTransient)& HShell)
112 { myHShell = HShell; }
114 //=======================================================================
117 //=======================================================================
119 void HLRAlgo_PolyAlgo::Clear ()
121 if (!myHShell.IsNull()) {
127 //=======================================================================
130 //=======================================================================
132 void HLRAlgo_PolyAlgo::Update ()
134 Standard_Integer i,j;
135 Standard_Integer nxMin,nyMin,nzMin,nxMax,nyMax,nzMax;
136 Standard_Real xShellMin,yShellMin,zShellMin;
137 Standard_Real xShellMax,yShellMax,zShellMax;
138 Standard_Real xPolyTMin,yPolyTMin,zPolyTMin;
139 Standard_Real xPolyTMax,yPolyTMax,zPolyTMax;
140 Standard_Real xTrianMin,yTrianMin,zTrianMin;
141 Standard_Real xTrianMax,yTrianMax,zTrianMax;
142 Standard_Real xSegmnMin,ySegmnMin,zSegmnMin;
143 Standard_Real xSegmnMax,ySegmnMax,zSegmnMax;
144 Standard_Real TotMinMax[6];
145 Standard_Real Big = Precision::Infinite();
152 TColStd_Array1OfTransient& Shell = myHShell->ChangeArray1();
153 myNbrShell = Shell.Upper();
154 Handle(HLRAlgo_PolyShellData)* psd1 =
155 (Handle(HLRAlgo_PolyShellData)*)&(Shell.ChangeValue(1));
157 for (i = 1; i <= myNbrShell; i++) {
158 (*psd1)->UpdateGlobalMinMax(&TotMinMax);
162 Standard_Real dx = TotMinMax[3] - TotMinMax[0];
163 Standard_Real dy = TotMinMax[4] - TotMinMax[1];
164 Standard_Real dz = TotMinMax[5] - TotMinMax[2];
165 Standard_Real precad = dx;
166 if (precad < dy) precad = dy;
167 if (precad < dz) precad = dz;
168 myTolerance = precad * myTolParam;
169 precad = precad * 0.01;
170 Standard_Real SurDX = 1020 / (dx + precad);
171 Standard_Real SurDY = 1020 / (dy + precad);
172 Standard_Real SurDZ = 508 / (dz + precad);
173 precad = precad * 0.5;
174 Standard_Real DecaX = - TotMinMax[0] + precad;
175 Standard_Real DecaY = - TotMinMax[1] + precad;
176 Standard_Real DecaZ = - TotMinMax[2] + precad;
178 Handle(HLRAlgo_PolyShellData)* psd2 =
179 (Handle(HLRAlgo_PolyShellData)*)&(Shell.ChangeValue(1));
181 for (i = 1; i <= myNbrShell; i++) {
182 const Standard_Address ShellIndices = (*psd2)->Indices();
190 for (mySegListIt.Initialize((*psd2)->Edges());
192 mySegListIt.Next()) {
193 HLRAlgo_BiPoint& BP = mySegListIt.Value();
194 const Standard_Address Coordinates = BP.Coordinates();
195 const Standard_Address IndexPtr = BP.Indices();
196 if (PntXP1 < PntXP2) { xSegmnMin = PntXP1; xSegmnMax = PntXP2; }
197 else { xSegmnMin = PntXP2; xSegmnMax = PntXP1; }
198 if (PntYP1 < PntYP2) { ySegmnMin = PntYP1; ySegmnMax = PntYP2; }
199 else { ySegmnMin = PntYP2; ySegmnMax = PntYP1; }
200 if (PntZP1 < PntZP2) { zSegmnMin = PntZP1; zSegmnMax = PntZP2; }
201 else { zSegmnMin = PntZP2; zSegmnMax = PntZP1; }
202 nxMin = (Standard_Integer)((DecaX + xSegmnMin) * SurDX);
203 nyMin = (Standard_Integer)((DecaY + ySegmnMin) * SurDY);
204 nzMin = (Standard_Integer)((DecaZ + zSegmnMin) * SurDZ);
205 nxMax = (Standard_Integer)((DecaX + xSegmnMax) * SurDX);
206 nyMax = (Standard_Integer)((DecaY + ySegmnMax) * SurDY);
207 nzMax = (Standard_Integer)((DecaZ + zSegmnMax) * SurDZ);
208 MinSeg = nyMin + (nxMin << 11);
211 MaxSeg = nyMax + (nxMax << 11);
213 MaxSeg += nzMax + 0x00000200;
214 if (xShellMin > xSegmnMin) xShellMin = xSegmnMin;
215 if (xShellMax < xSegmnMax) xShellMax = xSegmnMax;
216 if (yShellMin > ySegmnMin) yShellMin = ySegmnMin;
217 if (yShellMax < ySegmnMax) yShellMax = ySegmnMax;
218 if (zShellMin > zSegmnMin) zShellMin = zSegmnMin;
219 if (zShellMax < zSegmnMax) zShellMax = zSegmnMax;
221 TColStd_Array1OfTransient& Polyg = (*psd2)->PolyData();
222 Standard_Integer nbFace = Polyg.Upper();
223 Standard_Integer nbFaHi = 0;
224 Handle(HLRAlgo_PolyData)* pd = NULL;
225 if(nbFace > 0) pd = (Handle(HLRAlgo_PolyData)*)&(Polyg.ChangeValue(1));
227 for (j = 1; j <= nbFace; j++) {
228 if ((*pd)->Hiding()) {
236 Standard_Integer otheri,nbHide = 0;//min,max;
237 Standard_Real X1,X2,X3,Y1,Y2,Y3,Z1,Z2,Z3;
238 Standard_Real dn,dnx,dny,dnz,dx1,dy1,dz1,dx2,dy2,dz2,dx3,dy3;
239 Standard_Real adx1,ady1,adx2,ady2,adx3,ady3;
240 Standard_Real a =0.,b =0.,c =0.,d =0.;
241 const Standard_Address PolyTIndices = (*pd)->Indices();
242 TColgp_Array1OfXYZ & Nodes = (*pd)->Nodes();
243 HLRAlgo_Array1OfTData& TData = (*pd)->TData();
244 HLRAlgo_Array1OfPHDat& PHDat = (*pd)->PHDat();
245 Standard_Integer nbT = TData.Upper();
246 HLRAlgo_TriangleData* TD = &(TData.ChangeValue(1));
248 for (otheri = 1; otheri <= nbT; otheri++) {
249 const Standard_Address TriIndices = TD->Indices();
250 if (TriFlags & FMskHiding) {
251 const gp_XYZ& P1 = Nodes(TriNode1);
252 const gp_XYZ& P2 = Nodes(TriNode2);
253 const gp_XYZ& P3 = Nodes(TriNode3);
263 xTrianMax = xTrianMin = X1;
264 yTrianMax = yTrianMin = Y1;
265 zTrianMax = zTrianMin = Z1;
266 if (xTrianMin > X2) xTrianMin = X2;
267 else if (xTrianMax < X2) xTrianMax = X2;
268 if (yTrianMin > Y2) yTrianMin = Y2;
269 else if (yTrianMax < Y2) yTrianMax = Y2;
270 if (zTrianMin > Z2) zTrianMin = Z2;
271 else if (zTrianMax < Z2) zTrianMax = Z2;
272 if (xTrianMin > X3) xTrianMin = X3;
273 else if (xTrianMax < X3) xTrianMax = X3;
274 if (yTrianMin > Y3) yTrianMin = Y3;
275 else if (yTrianMax < Y3) yTrianMax = Y3;
276 if (zTrianMin > Z3) zTrianMin = Z3;
277 else if (zTrianMax < Z3) zTrianMax = Z3;
278 nxMin = (Standard_Integer)((DecaX + xTrianMin) * SurDX);
279 nyMin = (Standard_Integer)((DecaY + yTrianMin) * SurDY);
280 nzMin = (Standard_Integer)((DecaZ + zTrianMin) * SurDZ);
281 nxMax = (Standard_Integer)((DecaX + xTrianMax) * SurDX);
282 nyMax = (Standard_Integer)((DecaY + yTrianMax) * SurDY);
283 nzMax = (Standard_Integer)((DecaZ + zTrianMax) * SurDZ);
284 Standard_Integer MinTrian,MaxTrian;
285 MinTrian = nyMin + (nxMin << 11);
287 MinTrian += nzMin - 0x00000200;
288 MaxTrian = nyMax + (nxMax << 11);
299 dnx = dy1 * dz2 - dy2 * dz1;
300 dny = dz1 * dx2 - dz2 * dx1;
301 dnz = dx1 * dy2 - dx2 * dy1;
302 dn = sqrt(dnx * dnx + dny * dny + dnz * dnz);
308 d = a * X1 + b * Y1 + c * Z1;
310 PHDat(nbHide).Set(otheri,MinTrian,MaxTrian,a,b,c,d);
313 if (dx1 < 0) adx1 = -dx1;
314 if (dy1 < 0) ady1 = -dy1;
317 if (dx2 < 0) adx2 = -dx2;
318 if (dy2 < 0) ady2 = -dy2;
321 if (dx3 < 0) adx3 = -dx3;
322 if (dy3 < 0) ady3 = -dy3;
323 if (adx1 > ady1) TriFlags |= EMskGrALin1;
324 else TriFlags &= ~EMskGrALin1;
325 if (adx2 > ady2) TriFlags |= EMskGrALin2;
326 else TriFlags &= ~EMskGrALin2;
327 if (adx3 > ady3) TriFlags |= EMskGrALin3;
328 else TriFlags &= ~EMskGrALin3;
329 if (xPolyTMin > xTrianMin) xPolyTMin = xTrianMin;
330 if (xPolyTMax < xTrianMax) xPolyTMax = xTrianMax;
331 if (yPolyTMin > yTrianMin) yPolyTMin = yTrianMin;
332 if (yPolyTMax < yTrianMax) yPolyTMax = yTrianMax;
333 if (zPolyTMin > zTrianMin) zPolyTMin = zTrianMin;
334 if (zPolyTMax < zTrianMax) zPolyTMax = zTrianMax;
338 nxMin = (Standard_Integer)((DecaX + xPolyTMin) * SurDX);
339 nyMin = (Standard_Integer)((DecaY + yPolyTMin) * SurDY);
340 nzMin = (Standard_Integer)((DecaZ + zPolyTMin) * SurDZ);
341 nxMax = (Standard_Integer)((DecaX + xPolyTMax) * SurDX);
342 nyMax = (Standard_Integer)((DecaY + yPolyTMax) * SurDY);
343 nzMax = (Standard_Integer)((DecaZ + zPolyTMax) * SurDZ);
344 MinPolyT = nyMin + (nxMin << 11);
346 MinPolyT += nzMin - 0x00000200;
347 MaxPolyT = nyMax + (nxMax << 11);
350 if (xShellMin > xPolyTMin) xShellMin = xPolyTMin;
351 if (xShellMax < xPolyTMax) xShellMax = xPolyTMax;
352 if (yShellMin > yPolyTMin) yShellMin = yPolyTMin;
353 if (yShellMax < yPolyTMax) yShellMax = yPolyTMax;
354 if (zShellMin > zPolyTMin) zShellMin = zPolyTMin;
355 if (zShellMax < zPolyTMax) zShellMax = zPolyTMax;
360 nxMin = (Standard_Integer)((DecaX + xShellMin) * SurDX);
361 nyMin = (Standard_Integer)((DecaY + yShellMin) * SurDY);
362 nzMin = (Standard_Integer)((DecaZ + zShellMin) * SurDZ);
363 nxMax = (Standard_Integer)((DecaX + xShellMax) * SurDX);
364 nyMax = (Standard_Integer)((DecaY + yShellMax) * SurDY);
365 nzMax = (Standard_Integer)((DecaZ + zShellMax) * SurDZ);
366 MinShell = nyMin + (nxMin << 11);
368 MinShell += nzMin - 0x00000200;
369 MaxShell = nyMax + (nxMax << 11);
372 (*psd2)->UpdateHiding(nbFaHi);
373 TColStd_Array1OfTransient& PolHi = (*psd2)->HidingPolyData();
374 pd = (Handle(HLRAlgo_PolyData)*)&(Polyg.ChangeValue(1));
375 Handle(HLRAlgo_PolyData)* phd =
376 (Handle(HLRAlgo_PolyData)*)&(PolHi.ChangeValue(1));
378 for (j = 1; j <= nbFace; j++) {
379 if ((*pd)->Hiding()) {
387 (*psd2)->UpdateHiding(0);
395 //=======================================================================
396 //function : NextHide
398 //=======================================================================
400 void HLRAlgo_PolyAlgo::NextHide ()
402 myFound = Standard_False;
403 if (myCurShell != 0) {
405 if (mySegListIt.More()) myFound = Standard_True;
410 //POP ADN pour que cela marche sur WNT
411 // while (myCurShell <= myNbrShell && !myFound) {
412 // mySegListIt.Initialize((*(Handle(HLRAlgo_PolyShellData)*)&
413 // (myHShell->ChangeValue(myCurShell)))
415 while (myCurShell <= myNbrShell && !myFound) {
416 Handle(HLRAlgo_PolyShellData) data =
417 Handle(HLRAlgo_PolyShellData)::DownCast(myHShell->Value(myCurShell));
418 mySegListIt.Initialize(data->Edges());
419 if (mySegListIt.More()) myFound = Standard_True;
425 //=======================================================================
428 //=======================================================================
430 void HLRAlgo_PolyAlgo::Hide (Standard_Address& Coordinates,
431 HLRAlgo_EdgeStatus& status,
432 Standard_Integer& Index,
433 Standard_Boolean& reg1,
434 Standard_Boolean& regn,
435 Standard_Boolean& outl,
436 Standard_Boolean& intl)
438 HLRAlgo_BiPoint& BP = mySegListIt.Value();
439 Coordinates = BP.Coordinates();
440 const Standard_Address IndexPtr = BP.Indices();
441 status = HLRAlgo_EdgeStatus(0.,(Standard_ShortReal)myTolParam,1.,(Standard_ShortReal)myTolParam);
450 Standard_Boolean HidingShell;
451 TColStd_Array1OfTransient& Shell = myHShell->ChangeArray1();
452 Handle(HLRAlgo_PolyShellData)* psd =
453 (Handle(HLRAlgo_PolyShellData)*)&(Shell.ChangeValue(1));
455 for (Standard_Integer s = 1; s <= myNbrShell; s++) {
456 if ((*psd)->Hiding()) {
457 const Standard_Address ShellIndices = (*psd)->Indices();
458 if (((MaxShell - MinSeg) & 0x80100200) == 0 &&
459 ((MaxSeg - MinShell) & 0x80100000) == 0) {
460 HidingShell = (s == myCurShell);
461 TColStd_Array1OfTransient& Face = (*psd)->HidingPolyData();
462 Standard_Integer nbFace = Face.Upper();
463 Handle(HLRAlgo_PolyData)* pd =
464 (Handle(HLRAlgo_PolyData)*)&(Face.ChangeValue(1));
466 for (Standard_Integer f = 1; f <= nbFace; f++) {
467 (*pd)->HideByPolyData(Coordinates,
468 (Standard_Address)myRealPtr,
481 //=======================================================================
482 //function : NextShow
484 //=======================================================================
486 void HLRAlgo_PolyAlgo::NextShow ()
488 myFound = Standard_False;
489 if (myCurShell != 0) {
491 if (mySegListIt.More()) myFound = Standard_True;
496 while (myCurShell <= myNbrShell && !myFound) {
497 mySegListIt.Initialize((*(Handle(HLRAlgo_PolyShellData)*)&
498 (myHShell->ChangeValue(myCurShell)))
500 if (mySegListIt.More()) myFound = Standard_True;
506 //=======================================================================
509 //=======================================================================
511 void HLRAlgo_PolyAlgo::Show (Standard_Address& Coordinates,
512 Standard_Integer& Index,
513 Standard_Boolean& reg1,
514 Standard_Boolean& regn,
515 Standard_Boolean& outl,
516 Standard_Boolean& intl)
518 HLRAlgo_BiPoint& BP = mySegListIt.Value();
519 Standard_Address IndexPtr = BP.Indices();
520 Coordinates = BP.Coordinates();