1 // Created on: 1995-05-05
2 // Created by: Christophe MARION
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
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.
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.
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.
23 //#define No_Exception
25 #include <HLRAlgo_PolyAlgo.ixx>
26 #include <HLRAlgo_PolyShellData.hxx>
27 #include <HLRAlgo_PolyData.hxx>
28 #include <HLRAlgo_ListOfBPoint.hxx>
29 #include <HLRAlgo_BiPoint.hxx>
30 #include <Precision.hxx>
32 #define EMskGrALin1 ((Standard_Boolean) 8)
33 #define EMskGrALin2 ((Standard_Boolean) 16)
34 #define EMskGrALin3 ((Standard_Boolean) 32)
35 #define FMskHiding ((Standard_Boolean) 256)
37 #define TriNode1 ((Standard_Integer*)TriIndices)[0]
38 #define TriNode2 ((Standard_Integer*)TriIndices)[1]
39 #define TriNode3 ((Standard_Integer*)TriIndices)[2]
40 #define TriFlags ((Standard_Boolean*)TriIndices)[3]
42 #define XV1 myRealPtr[0]
43 #define XV2 myRealPtr[1]
44 #define XV3 myRealPtr[2]
45 #define YV1 myRealPtr[3]
46 #define YV2 myRealPtr[4]
47 #define YV3 myRealPtr[5]
48 #define Param myRealPtr[6]
49 #define myTolParam myRealPtr[7]
50 #define myTolAngular myRealPtr[8]
51 #define myTolerance myRealPtr[9]
53 #define PntX1 ((Standard_Real*)Coordinates)[ 0]
54 #define PntY1 ((Standard_Real*)Coordinates)[ 1]
55 #define PntZ1 ((Standard_Real*)Coordinates)[ 2]
56 #define PntX2 ((Standard_Real*)Coordinates)[ 3]
57 #define PntY2 ((Standard_Real*)Coordinates)[ 4]
58 #define PntZ2 ((Standard_Real*)Coordinates)[ 5]
59 #define PntXP1 ((Standard_Real*)Coordinates)[ 6]
60 #define PntYP1 ((Standard_Real*)Coordinates)[ 7]
61 #define PntZP1 ((Standard_Real*)Coordinates)[ 8]
62 #define PntXP2 ((Standard_Real*)Coordinates)[ 9]
63 #define PntYP2 ((Standard_Real*)Coordinates)[10]
64 #define PntZP2 ((Standard_Real*)Coordinates)[11]
66 #define TotXMin ((Standard_Real*)TotMinMax)[0]
67 #define TotYMin ((Standard_Real*)TotMinMax)[1]
68 #define TotZMin ((Standard_Real*)TotMinMax)[2]
69 #define TotXMax ((Standard_Real*)TotMinMax)[3]
70 #define TotYMax ((Standard_Real*)TotMinMax)[4]
71 #define TotZMax ((Standard_Real*)TotMinMax)[5]
73 #define ShapeIndex ((Standard_Integer*)IndexPtr)[0]
74 #define FaceConex1 ((Standard_Integer*)IndexPtr)[1]
75 #define Face1Pt1 ((Standard_Integer*)IndexPtr)[2]
76 #define Face1Pt2 ((Standard_Integer*)IndexPtr)[3]
77 #define FaceConex2 ((Standard_Integer*)IndexPtr)[4]
78 #define Face2Pt1 ((Standard_Integer*)IndexPtr)[5]
79 #define Face2Pt2 ((Standard_Integer*)IndexPtr)[6]
80 #define MinSeg ((Standard_Integer*)IndexPtr)[7]
81 #define MaxSeg ((Standard_Integer*)IndexPtr)[8]
82 #define SegFlags ((Standard_Integer*)IndexPtr)[9]
84 #define MinShell ((Standard_Integer*)ShellIndices)[0]
85 #define MaxShell ((Standard_Integer*)ShellIndices)[1]
87 #define FIndex ((Standard_Integer*)PolyTIndices)[0]
88 #define MinPolyT ((Standard_Integer*)PolyTIndices)[1]
89 #define MaxPolyT ((Standard_Integer*)PolyTIndices)[2]
91 //static Standard_Integer ERROR = Standard_False;
93 //=======================================================================
94 //function : HLRAlgo_PolyAlgo
96 //=======================================================================
98 HLRAlgo_PolyAlgo::HLRAlgo_PolyAlgo ()
100 myTolParam = 0.00000001;
101 myTolAngular = 0.0001;
104 //=======================================================================
107 //=======================================================================
110 HLRAlgo_PolyAlgo::Init (const Handle(TColStd_HArray1OfTransient)& HShell)
111 { myHShell = HShell; }
113 //=======================================================================
116 //=======================================================================
118 void HLRAlgo_PolyAlgo::Clear ()
120 if (!myHShell.IsNull()) {
126 //=======================================================================
129 //=======================================================================
131 void HLRAlgo_PolyAlgo::Update ()
133 Standard_Integer i,j;
134 Standard_Integer nxMin,nyMin,nzMin,nxMax,nyMax,nzMax;
135 Standard_Real xShellMin,yShellMin,zShellMin;
136 Standard_Real xShellMax,yShellMax,zShellMax;
137 Standard_Real xPolyTMin,yPolyTMin,zPolyTMin;
138 Standard_Real xPolyTMax,yPolyTMax,zPolyTMax;
139 Standard_Real xTrianMin,yTrianMin,zTrianMin;
140 Standard_Real xTrianMax,yTrianMax,zTrianMax;
141 Standard_Real xSegmnMin,ySegmnMin,zSegmnMin;
142 Standard_Real xSegmnMax,ySegmnMax,zSegmnMax;
143 Standard_Real TotMinMax[6];
144 Standard_Real Big = Precision::Infinite();
151 TColStd_Array1OfTransient& Shell = myHShell->ChangeArray1();
152 myNbrShell = Shell.Upper();
153 Handle(HLRAlgo_PolyShellData)* psd1 =
154 (Handle(HLRAlgo_PolyShellData)*)&(Shell.ChangeValue(1));
156 for (i = 1; i <= myNbrShell; i++) {
157 (*psd1)->UpdateGlobalMinMax(&TotMinMax);
161 Standard_Real dx = TotMinMax[3] - TotMinMax[0];
162 Standard_Real dy = TotMinMax[4] - TotMinMax[1];
163 Standard_Real dz = TotMinMax[5] - TotMinMax[2];
164 Standard_Real precad = dx;
165 if (precad < dy) precad = dy;
166 if (precad < dz) precad = dz;
167 myTolerance = precad * myTolParam;
168 precad = precad * 0.01;
169 Standard_Real SurDX = 1020 / (dx + precad);
170 Standard_Real SurDY = 1020 / (dy + precad);
171 Standard_Real SurDZ = 508 / (dz + precad);
172 precad = precad * 0.5;
173 Standard_Real DecaX = - TotMinMax[0] + precad;
174 Standard_Real DecaY = - TotMinMax[1] + precad;
175 Standard_Real DecaZ = - TotMinMax[2] + precad;
177 Handle(HLRAlgo_PolyShellData)* psd2 =
178 (Handle(HLRAlgo_PolyShellData)*)&(Shell.ChangeValue(1));
180 for (i = 1; i <= myNbrShell; i++) {
181 const Standard_Address ShellIndices = (*psd2)->Indices();
189 for (mySegListIt.Initialize((*psd2)->Edges());
191 mySegListIt.Next()) {
192 HLRAlgo_BiPoint& BP = mySegListIt.Value();
193 const Standard_Address Coordinates = BP.Coordinates();
194 const Standard_Address IndexPtr = BP.Indices();
195 if (PntXP1 < PntXP2) { xSegmnMin = PntXP1; xSegmnMax = PntXP2; }
196 else { xSegmnMin = PntXP2; xSegmnMax = PntXP1; }
197 if (PntYP1 < PntYP2) { ySegmnMin = PntYP1; ySegmnMax = PntYP2; }
198 else { ySegmnMin = PntYP2; ySegmnMax = PntYP1; }
199 if (PntZP1 < PntZP2) { zSegmnMin = PntZP1; zSegmnMax = PntZP2; }
200 else { zSegmnMin = PntZP2; zSegmnMax = PntZP1; }
201 nxMin = (Standard_Integer)((DecaX + xSegmnMin) * SurDX);
202 nyMin = (Standard_Integer)((DecaY + ySegmnMin) * SurDY);
203 nzMin = (Standard_Integer)((DecaZ + zSegmnMin) * SurDZ);
204 nxMax = (Standard_Integer)((DecaX + xSegmnMax) * SurDX);
205 nyMax = (Standard_Integer)((DecaY + ySegmnMax) * SurDY);
206 nzMax = (Standard_Integer)((DecaZ + zSegmnMax) * SurDZ);
207 MinSeg = nyMin + (nxMin << 11);
210 MaxSeg = nyMax + (nxMax << 11);
212 MaxSeg += nzMax + 0x00000200;
213 if (xShellMin > xSegmnMin) xShellMin = xSegmnMin;
214 if (xShellMax < xSegmnMax) xShellMax = xSegmnMax;
215 if (yShellMin > ySegmnMin) yShellMin = ySegmnMin;
216 if (yShellMax < ySegmnMax) yShellMax = ySegmnMax;
217 if (zShellMin > zSegmnMin) zShellMin = zSegmnMin;
218 if (zShellMax < zSegmnMax) zShellMax = zSegmnMax;
220 TColStd_Array1OfTransient& Polyg = (*psd2)->PolyData();
221 Standard_Integer nbFace = Polyg.Upper();
222 Standard_Integer nbFaHi = 0;
223 Handle(HLRAlgo_PolyData)* pd;
224 if(nbFace > 0) pd = (Handle(HLRAlgo_PolyData)*)&(Polyg.ChangeValue(1));
226 for (j = 1; j <= nbFace; j++) {
227 if ((*pd)->Hiding()) {
235 Standard_Integer otheri,nbHide = 0;//min,max;
236 Standard_Real X1,X2,X3,Y1,Y2,Y3,Z1,Z2,Z3;
237 Standard_Real dn,dnx,dny,dnz,dx1,dy1,dz1,dx2,dy2,dz2,dx3,dy3;
238 Standard_Real adx1,ady1,adx2,ady2,adx3,ady3;
239 Standard_Real a =0.,b =0.,c =0.,d =0.;
240 const Standard_Address PolyTIndices = (*pd)->Indices();
241 TColgp_Array1OfXYZ & Nodes = (*pd)->Nodes();
242 HLRAlgo_Array1OfTData& TData = (*pd)->TData();
243 HLRAlgo_Array1OfPHDat& PHDat = (*pd)->PHDat();
244 Standard_Integer nbT = TData.Upper();
245 HLRAlgo_TriangleData* TD = &(TData.ChangeValue(1));
247 for (otheri = 1; otheri <= nbT; otheri++) {
248 const Standard_Address TriIndices = TD->Indices();
249 if (TriFlags & FMskHiding) {
250 const gp_XYZ& P1 = Nodes(TriNode1);
251 const gp_XYZ& P2 = Nodes(TriNode2);
252 const gp_XYZ& P3 = Nodes(TriNode3);
262 xTrianMax = xTrianMin = X1;
263 yTrianMax = yTrianMin = Y1;
264 zTrianMax = zTrianMin = Z1;
265 if (xTrianMin > X2) xTrianMin = X2;
266 else if (xTrianMax < X2) xTrianMax = X2;
267 if (yTrianMin > Y2) yTrianMin = Y2;
268 else if (yTrianMax < Y2) yTrianMax = Y2;
269 if (zTrianMin > Z2) zTrianMin = Z2;
270 else if (zTrianMax < Z2) zTrianMax = Z2;
271 if (xTrianMin > X3) xTrianMin = X3;
272 else if (xTrianMax < X3) xTrianMax = X3;
273 if (yTrianMin > Y3) yTrianMin = Y3;
274 else if (yTrianMax < Y3) yTrianMax = Y3;
275 if (zTrianMin > Z3) zTrianMin = Z3;
276 else if (zTrianMax < Z3) zTrianMax = Z3;
277 nxMin = (Standard_Integer)((DecaX + xTrianMin) * SurDX);
278 nyMin = (Standard_Integer)((DecaY + yTrianMin) * SurDY);
279 nzMin = (Standard_Integer)((DecaZ + zTrianMin) * SurDZ);
280 nxMax = (Standard_Integer)((DecaX + xTrianMax) * SurDX);
281 nyMax = (Standard_Integer)((DecaY + yTrianMax) * SurDY);
282 nzMax = (Standard_Integer)((DecaZ + zTrianMax) * SurDZ);
283 Standard_Integer MinTrian,MaxTrian;
284 MinTrian = nyMin + (nxMin << 11);
286 MinTrian += nzMin - 0x00000200;
287 MaxTrian = nyMax + (nxMax << 11);
298 dnx = dy1 * dz2 - dy2 * dz1;
299 dny = dz1 * dx2 - dz2 * dx1;
300 dnz = dx1 * dy2 - dx2 * dy1;
301 dn = sqrt(dnx * dnx + dny * dny + dnz * dnz);
307 d = a * X1 + b * Y1 + c * Z1;
309 PHDat(nbHide).Set(otheri,MinTrian,MaxTrian,a,b,c,d);
312 if (dx1 < 0) adx1 = -dx1;
313 if (dy1 < 0) ady1 = -dy1;
316 if (dx2 < 0) adx2 = -dx2;
317 if (dy2 < 0) ady2 = -dy2;
320 if (dx3 < 0) adx3 = -dx3;
321 if (dy3 < 0) ady3 = -dy3;
322 if (adx1 > ady1) TriFlags |= EMskGrALin1;
323 else TriFlags &= ~EMskGrALin1;
324 if (adx2 > ady2) TriFlags |= EMskGrALin2;
325 else TriFlags &= ~EMskGrALin2;
326 if (adx3 > ady3) TriFlags |= EMskGrALin3;
327 else TriFlags &= ~EMskGrALin3;
328 if (xPolyTMin > xTrianMin) xPolyTMin = xTrianMin;
329 if (xPolyTMax < xTrianMax) xPolyTMax = xTrianMax;
330 if (yPolyTMin > yTrianMin) yPolyTMin = yTrianMin;
331 if (yPolyTMax < yTrianMax) yPolyTMax = yTrianMax;
332 if (zPolyTMin > zTrianMin) zPolyTMin = zTrianMin;
333 if (zPolyTMax < zTrianMax) zPolyTMax = zTrianMax;
337 nxMin = (Standard_Integer)((DecaX + xPolyTMin) * SurDX);
338 nyMin = (Standard_Integer)((DecaY + yPolyTMin) * SurDY);
339 nzMin = (Standard_Integer)((DecaZ + zPolyTMin) * SurDZ);
340 nxMax = (Standard_Integer)((DecaX + xPolyTMax) * SurDX);
341 nyMax = (Standard_Integer)((DecaY + yPolyTMax) * SurDY);
342 nzMax = (Standard_Integer)((DecaZ + zPolyTMax) * SurDZ);
343 MinPolyT = nyMin + (nxMin << 11);
345 MinPolyT += nzMin - 0x00000200;
346 MaxPolyT = nyMax + (nxMax << 11);
349 if (xShellMin > xPolyTMin) xShellMin = xPolyTMin;
350 if (xShellMax < xPolyTMax) xShellMax = xPolyTMax;
351 if (yShellMin > yPolyTMin) yShellMin = yPolyTMin;
352 if (yShellMax < yPolyTMax) yShellMax = yPolyTMax;
353 if (zShellMin > zPolyTMin) zShellMin = zPolyTMin;
354 if (zShellMax < zPolyTMax) zShellMax = zPolyTMax;
359 nxMin = (Standard_Integer)((DecaX + xShellMin) * SurDX);
360 nyMin = (Standard_Integer)((DecaY + yShellMin) * SurDY);
361 nzMin = (Standard_Integer)((DecaZ + zShellMin) * SurDZ);
362 nxMax = (Standard_Integer)((DecaX + xShellMax) * SurDX);
363 nyMax = (Standard_Integer)((DecaY + yShellMax) * SurDY);
364 nzMax = (Standard_Integer)((DecaZ + zShellMax) * SurDZ);
365 MinShell = nyMin + (nxMin << 11);
367 MinShell += nzMin - 0x00000200;
368 MaxShell = nyMax + (nxMax << 11);
371 (*psd2)->UpdateHiding(nbFaHi);
372 TColStd_Array1OfTransient& PolHi = (*psd2)->HidingPolyData();
373 pd = (Handle(HLRAlgo_PolyData)*)&(Polyg.ChangeValue(1));
374 Handle(HLRAlgo_PolyData)* phd =
375 (Handle(HLRAlgo_PolyData)*)&(PolHi.ChangeValue(1));
377 for (j = 1; j <= nbFace; j++) {
378 if ((*pd)->Hiding()) {
386 (*psd2)->UpdateHiding(0);
394 //=======================================================================
395 //function : NextHide
397 //=======================================================================
399 void HLRAlgo_PolyAlgo::NextHide ()
401 myFound = Standard_False;
402 if (myCurShell != 0) {
404 if (mySegListIt.More()) myFound = Standard_True;
409 //POP ADN pour que cela marche sur WNT
410 // while (myCurShell <= myNbrShell && !myFound) {
411 // mySegListIt.Initialize((*(Handle(HLRAlgo_PolyShellData)*)&
412 // (myHShell->ChangeValue(myCurShell)))
414 while (myCurShell <= myNbrShell && !myFound) {
415 Handle(HLRAlgo_PolyShellData) data =
416 Handle(HLRAlgo_PolyShellData)::DownCast(myHShell->Value(myCurShell));
417 mySegListIt.Initialize(data->Edges());
418 if (mySegListIt.More()) myFound = Standard_True;
424 //=======================================================================
427 //=======================================================================
429 void HLRAlgo_PolyAlgo::Hide (Standard_Address& Coordinates,
430 HLRAlgo_EdgeStatus& status,
431 Standard_Integer& Index,
432 Standard_Boolean& reg1,
433 Standard_Boolean& regn,
434 Standard_Boolean& outl,
435 Standard_Boolean& intl)
437 HLRAlgo_BiPoint& BP = mySegListIt.Value();
438 Coordinates = BP.Coordinates();
439 const Standard_Address IndexPtr = BP.Indices();
440 status = HLRAlgo_EdgeStatus(0.,(Standard_ShortReal)myTolParam,1.,(Standard_ShortReal)myTolParam);
449 Standard_Boolean HidingShell;
450 TColStd_Array1OfTransient& Shell = myHShell->ChangeArray1();
451 Handle(HLRAlgo_PolyShellData)* psd =
452 (Handle(HLRAlgo_PolyShellData)*)&(Shell.ChangeValue(1));
454 for (Standard_Integer s = 1; s <= myNbrShell; s++) {
455 if ((*psd)->Hiding()) {
456 const Standard_Address ShellIndices = (*psd)->Indices();
457 if (((MaxShell - MinSeg) & 0x80100200) == 0 &&
458 ((MaxSeg - MinShell) & 0x80100000) == 0) {
459 HidingShell = (s == myCurShell);
460 TColStd_Array1OfTransient& Face = (*psd)->HidingPolyData();
461 Standard_Integer nbFace = Face.Upper();
462 Handle(HLRAlgo_PolyData)* pd =
463 (Handle(HLRAlgo_PolyData)*)&(Face.ChangeValue(1));
465 for (Standard_Integer f = 1; f <= nbFace; f++) {
466 (*pd)->HideByPolyData(Coordinates,
467 (Standard_Address)myRealPtr,
480 //=======================================================================
481 //function : NextShow
483 //=======================================================================
485 void HLRAlgo_PolyAlgo::NextShow ()
487 myFound = Standard_False;
488 if (myCurShell != 0) {
490 if (mySegListIt.More()) myFound = Standard_True;
495 while (myCurShell <= myNbrShell && !myFound) {
496 mySegListIt.Initialize((*(Handle(HLRAlgo_PolyShellData)*)&
497 (myHShell->ChangeValue(myCurShell)))
499 if (mySegListIt.More()) myFound = Standard_True;
505 //=======================================================================
508 //=======================================================================
510 void HLRAlgo_PolyAlgo::Show (Standard_Address& Coordinates,
511 Standard_Integer& Index,
512 Standard_Boolean& reg1,
513 Standard_Boolean& regn,
514 Standard_Boolean& outl,
515 Standard_Boolean& intl)
517 HLRAlgo_BiPoint& BP = mySegListIt.Value();
518 Standard_Address IndexPtr = BP.Indices();
519 Coordinates = BP.Coordinates();