Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 1993-02-03 |
2 | // Created by: Laurent BUCHARD | |
3 | // Copyright (c) 1993-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 | |
7fd59977 | 17 | |
42cf5bc1 | 18 | #include <Adaptor3d_HSurface.hxx> |
19 | #include <Bnd_Array1OfBox.hxx> | |
20 | #include <Bnd_Box.hxx> | |
7fd59977 | 21 | #include <gp_Pnt.hxx> |
22 | #include <gp_Vec.hxx> | |
42cf5bc1 | 23 | #include <gp_XYZ.hxx> |
24 | #include <IntPatch_HInterTool.hxx> | |
25 | #include <IntPatch_Polyhedron.hxx> | |
26 | #include <Precision.hxx> | |
27 | #include <Standard_ConstructionError.hxx> | |
28 | #include <Standard_OutOfRange.hxx> | |
7fd59977 | 29 | #include <TColgp_Array2OfPnt.hxx> |
30 | #include <TColStd_Array2OfReal.hxx> | |
7fd59977 | 31 | |
42cf5bc1 | 32 | #include <stdio.h> |
7fd59977 | 33 | #define MSG_DEBUG 0 |
34 | ||
35 | #define LONGUEUR_MINI_EDGE_TRIANGLE 1e-14 | |
36 | #define DEFLECTION_COEFF 1.1 | |
37 | #define NBMAXUV 30 | |
38 | ||
39 | //================================================================================ | |
40 | static Standard_Integer NbPOnU (const Handle(Adaptor3d_HSurface)& S) | |
41 | { | |
42 | const Standard_Real u0 = S->FirstUParameter(); | |
43 | const Standard_Real u1 = S->LastUParameter(); | |
44 | const Standard_Integer nbpu = IntPatch_HInterTool::NbSamplesU(S,u0,u1); | |
45 | return (nbpu>NBMAXUV? NBMAXUV : nbpu); | |
46 | } | |
47 | //================================================================================ | |
48 | static Standard_Integer NbPOnV (const Handle(Adaptor3d_HSurface)& S) | |
49 | { | |
50 | const Standard_Real v0 = S->FirstVParameter(); | |
51 | const Standard_Real v1 = S->LastVParameter(); | |
52 | const Standard_Integer nbpv = IntPatch_HInterTool::NbSamplesV(S,v0,v1); | |
53 | return (nbpv>NBMAXUV? NBMAXUV : nbpv); | |
54 | } | |
55 | ||
56 | //======================================================================= | |
57 | //function : Destroy | |
58 | //purpose : | |
59 | //======================================================================= | |
60 | void IntPatch_Polyhedron::Destroy() | |
61 | { | |
62 | gp_Pnt *CMyPnts = (gp_Pnt *)C_MyPnts; if(C_MyPnts) delete [] CMyPnts; | |
63 | Standard_Real *CMyU = (Standard_Real *)C_MyU; if(C_MyU) delete [] CMyU; | |
64 | Standard_Real *CMyV = (Standard_Real *)C_MyV; if(C_MyV) delete [] CMyV; | |
65 | C_MyPnts=C_MyU=C_MyV=NULL; | |
66 | } | |
67 | ||
68 | //======================================================================= | |
69 | //function : IntPatch_Polyhedron | |
70 | //purpose : | |
71 | //======================================================================= | |
72 | IntPatch_Polyhedron::IntPatch_Polyhedron (const Handle(Adaptor3d_HSurface)& Surface) | |
73 | : TheDeflection(Epsilon(100.)), | |
74 | nbdeltaU(NbPOnU(Surface)), | |
75 | nbdeltaV(NbPOnV(Surface)), | |
76 | C_MyPnts(NULL),C_MyU(NULL),C_MyV(NULL), | |
77 | UMinSingular(IntPatch_HInterTool::SingularOnVMin(Surface)), | |
78 | UMaxSingular(IntPatch_HInterTool::SingularOnVMin(Surface)), | |
79 | VMinSingular(IntPatch_HInterTool::SingularOnVMin(Surface)), | |
80 | VMaxSingular(IntPatch_HInterTool::SingularOnVMin(Surface)) | |
81 | { | |
82 | const Standard_Integer t = (nbdeltaU+1)*(nbdeltaV+1)+1; | |
83 | gp_Pnt *CMyPnts = new gp_Pnt[t]; | |
84 | Standard_Real *CMyU = new Standard_Real[t]; | |
85 | Standard_Real *CMyV = new Standard_Real[t]; | |
86 | C_MyPnts = CMyPnts; | |
87 | C_MyU = CMyU; | |
88 | C_MyV = CMyV; | |
89 | ||
90 | const Standard_Real u0 = Surface->FirstUParameter(); | |
91 | const Standard_Real u1 = Surface->LastUParameter(); | |
92 | const Standard_Real v0 = Surface->FirstVParameter(); | |
93 | const Standard_Real v1 = Surface->LastVParameter(); | |
94 | ||
95 | const Standard_Real U1mU0sNbdeltaU = (u1-u0)/(Standard_Real)nbdeltaU; | |
96 | const Standard_Real V1mV0sNbdeltaV = (v1-v0)/(Standard_Real)nbdeltaV; | |
97 | ||
98 | gp_Pnt TP; | |
99 | Standard_Real U,V; | |
100 | Standard_Integer i1, i2, Index=1; | |
101 | for (i1 = 0, U = u0; i1 <= nbdeltaU; i1++, U+= U1mU0sNbdeltaU) { | |
102 | for (i2 = 0, V = v0; i2 <= nbdeltaV; i2++, V+= V1mV0sNbdeltaV ) { | |
103 | Surface->D0(U,V,TP); | |
104 | CMyPnts[Index] = TP; | |
105 | CMyU[Index] = U; | |
106 | CMyV[Index] = V; | |
107 | TheBnd.Add(TP); | |
108 | Index++; | |
109 | } | |
110 | } | |
111 | ||
112 | Standard_Real tol=0.0; | |
113 | const Standard_Integer nbtriangles = NbTriangles(); | |
114 | for (i1=1; i1<=nbtriangles; i1++) { | |
115 | const Standard_Real tol1 = DeflectionOnTriangle(Surface,i1); | |
116 | if(tol1>tol) tol=tol1; | |
117 | } | |
118 | ||
119 | tol*=DEFLECTION_COEFF; | |
120 | ||
121 | DeflectionOverEstimation(tol); | |
122 | FillBounding(); | |
123 | } | |
124 | ||
125 | //======================================================================= | |
126 | //function : IntPatch_Polyhedron | |
127 | //purpose : | |
128 | //======================================================================= | |
129 | IntPatch_Polyhedron::IntPatch_Polyhedron (const Handle(Adaptor3d_HSurface)& Surface, | |
130 | const Standard_Integer nbu, | |
131 | const Standard_Integer nbv) | |
132 | : TheDeflection(Epsilon(100.)), | |
133 | nbdeltaU(nbu), | |
134 | nbdeltaV(nbv), | |
135 | C_MyPnts(NULL),C_MyU(NULL),C_MyV(NULL), | |
136 | UMinSingular(IntPatch_HInterTool::SingularOnVMin(Surface)), | |
137 | UMaxSingular(IntPatch_HInterTool::SingularOnVMin(Surface)), | |
138 | VMinSingular(IntPatch_HInterTool::SingularOnVMin(Surface)), | |
139 | VMaxSingular(IntPatch_HInterTool::SingularOnVMin(Surface)) | |
140 | { | |
141 | const Standard_Integer t = (nbdeltaU+1)*(nbdeltaV+1)+1; | |
142 | gp_Pnt *CMyPnts = new gp_Pnt[t]; | |
143 | Standard_Real *CMyU = new Standard_Real[t]; | |
144 | Standard_Real *CMyV = new Standard_Real[t]; | |
145 | C_MyPnts = CMyPnts; | |
146 | C_MyU = CMyU; | |
147 | C_MyV = CMyV; | |
148 | ||
149 | const Standard_Real u0 = Surface->FirstUParameter(); | |
150 | const Standard_Real u1 = Surface->LastUParameter(); | |
151 | const Standard_Real v0 = Surface->FirstVParameter(); | |
152 | const Standard_Real v1 = Surface->LastVParameter(); | |
153 | ||
154 | const Standard_Real U1mU0sNbdeltaU = (u1-u0)/(Standard_Real)nbdeltaU; | |
155 | const Standard_Real V1mV0sNbdeltaV = (v1-v0)/(Standard_Real)nbdeltaV; | |
156 | ||
157 | gp_Pnt TP; | |
158 | Standard_Real U,V; | |
159 | Standard_Integer i1, i2, Index=1; | |
160 | for (i1 = 0, U = u0; i1 <= nbdeltaU; i1++, U+= U1mU0sNbdeltaU) { | |
161 | for (i2 = 0, V = v0; i2 <= nbdeltaV; i2++, V+= V1mV0sNbdeltaV ) { | |
162 | Surface->D0(U,V,TP); | |
163 | CMyPnts[Index] = TP; | |
164 | CMyU[Index] = U; | |
165 | CMyV[Index] = V; | |
166 | TheBnd.Add(TP); | |
167 | Index++; | |
168 | } | |
169 | } | |
170 | ||
171 | Standard_Real tol=0.0; | |
172 | const Standard_Integer nbtriangles = NbTriangles(); | |
173 | for (i1=1; i1<=nbtriangles; i1++) { | |
174 | const Standard_Real tol1 = DeflectionOnTriangle(Surface,i1); | |
175 | if(tol1>tol) tol=tol1; | |
176 | } | |
177 | ||
178 | tol*=DEFLECTION_COEFF; | |
179 | ||
180 | DeflectionOverEstimation(tol); | |
181 | FillBounding(); | |
182 | } | |
183 | ||
184 | ||
185 | //======================================================================= | |
186 | //function : DeflectionOnTriangle | |
187 | //purpose : | |
188 | //======================================================================= | |
189 | ||
190 | Standard_Real IntPatch_Polyhedron::DeflectionOnTriangle | |
191 | (const Handle(Adaptor3d_HSurface)& Surface, | |
192 | const Standard_Integer Triang) const | |
193 | { | |
194 | Standard_Integer i1,i2,i3; | |
195 | ||
196 | Triangle(Triang,i1,i2,i3); | |
197 | //-- Calcul de l eqution du plan | |
198 | Standard_Real u1,v1,u2,v2,u3,v3; | |
199 | gp_Pnt P1,P2,P3; | |
200 | P1 = Point(i1,u1,v1); | |
201 | P2 = Point(i2,u2,v2); | |
202 | P3 = Point(i3,u3,v3); | |
203 | if(P1.SquareDistance(P2)<=LONGUEUR_MINI_EDGE_TRIANGLE) return(0); | |
204 | if(P1.SquareDistance(P3)<=LONGUEUR_MINI_EDGE_TRIANGLE) return(0); | |
205 | if(P2.SquareDistance(P3)<=LONGUEUR_MINI_EDGE_TRIANGLE) return(0); | |
206 | gp_XYZ XYZ1=P2.XYZ()-P1.XYZ(); | |
207 | gp_XYZ XYZ2=P3.XYZ()-P2.XYZ(); | |
208 | gp_XYZ XYZ3=P1.XYZ()-P3.XYZ(); | |
209 | gp_Vec NormalVector((XYZ1^XYZ2)+(XYZ2^XYZ3)+(XYZ3^XYZ1)); | |
df119b4e | 210 | Standard_Real aNormLen = NormalVector.Magnitude(); |
211 | if (aNormLen < gp::Resolution()) { | |
212 | return 0.; | |
213 | } | |
214 | // | |
215 | NormalVector.Divide(aNormLen); | |
7fd59977 | 216 | //-- Calcul du point u,v au centre du triangle |
217 | Standard_Real u = (u1+u2+u3)/3.0; | |
218 | Standard_Real v = (v1+v2+v3)/3.0; | |
219 | gp_Vec P1P(P1,Surface->Value(u,v)); | |
220 | return(Abs(P1P.Dot(NormalVector))); | |
221 | } | |
222 | ||
223 | //======================================================================= | |
224 | //function : Parameters | |
225 | //purpose : | |
226 | //======================================================================= | |
227 | void IntPatch_Polyhedron::Parameters( const Standard_Integer Index | |
228 | ,Standard_Real &U | |
229 | ,Standard_Real &V) const | |
230 | { | |
231 | U = ((Standard_Real *)C_MyU)[Index]; | |
232 | V = ((Standard_Real *)C_MyV)[Index]; | |
233 | } | |
234 | ||
235 | //======================================================================= | |
236 | //function : DeflectionOverEstimation | |
237 | //purpose : | |
238 | //======================================================================= | |
239 | void IntPatch_Polyhedron::DeflectionOverEstimation(const Standard_Real flec) | |
240 | { | |
241 | if(flec<0.0001) { | |
242 | TheDeflection=0.0001; | |
243 | TheBnd.Enlarge(0.0001); | |
244 | } | |
245 | else { | |
246 | TheDeflection=flec; | |
247 | TheBnd.Enlarge(flec); | |
248 | } | |
249 | } | |
250 | ||
251 | //======================================================================= | |
252 | //function : DeflectionOverEstimation | |
253 | //purpose : | |
254 | //======================================================================= | |
255 | Standard_Real IntPatch_Polyhedron::DeflectionOverEstimation() const | |
256 | { | |
257 | return TheDeflection; | |
258 | } | |
259 | ||
260 | //======================================================================= | |
261 | //function : Bounding | |
262 | //purpose : | |
263 | //======================================================================= | |
264 | const Bnd_Box& IntPatch_Polyhedron::Bounding() const | |
265 | { | |
266 | return TheBnd; | |
267 | } | |
268 | ||
269 | //======================================================================= | |
270 | //function : FillBounding | |
271 | //purpose : | |
272 | //======================================================================= | |
273 | void IntPatch_Polyhedron::FillBounding() | |
274 | { | |
275 | TheComponentsBnd=new Bnd_HArray1OfBox(1, NbTriangles()); | |
276 | Bnd_Box Boite; | |
277 | Standard_Integer p1, p2, p3; | |
278 | Standard_Integer nbtriangles = NbTriangles(); | |
279 | for (Standard_Integer iTri=1; iTri<=nbtriangles; iTri++) { | |
280 | Triangle(iTri, p1, p2, p3); | |
281 | Boite.SetVoid(); | |
282 | const gp_Pnt& P1 = Point(p1); | |
283 | const gp_Pnt& P2 = Point(p2); | |
284 | const gp_Pnt& P3 = Point(p3); | |
285 | if(P1.SquareDistance(P2)>LONGUEUR_MINI_EDGE_TRIANGLE) { | |
286 | if(P1.SquareDistance(P3)>LONGUEUR_MINI_EDGE_TRIANGLE) { | |
287 | if(P2.SquareDistance(P3)>LONGUEUR_MINI_EDGE_TRIANGLE) { | |
288 | Boite.Add(P1); | |
289 | Boite.Add(P2); | |
290 | Boite.Add(P3); | |
291 | } | |
292 | } | |
293 | } | |
294 | Boite.Enlarge(TheDeflection); | |
295 | TheComponentsBnd->SetValue(iTri,Boite); | |
296 | } | |
297 | } | |
298 | ||
299 | //======================================================================= | |
300 | //function : ComponentsBounding | |
301 | //purpose : | |
302 | //======================================================================= | |
303 | const Handle(Bnd_HArray1OfBox)& IntPatch_Polyhedron::ComponentsBounding () const | |
304 | { | |
305 | return TheComponentsBnd; | |
306 | } | |
307 | ||
308 | //======================================================================= | |
309 | //function : NbTriangles | |
310 | //purpose : | |
311 | //======================================================================= | |
312 | Standard_Integer IntPatch_Polyhedron::NbTriangles () const | |
313 | { | |
314 | return nbdeltaU*nbdeltaV*2; | |
315 | } | |
316 | ||
317 | //======================================================================= | |
318 | //function : NbPoints | |
319 | //purpose : | |
320 | //======================================================================= | |
321 | Standard_Integer IntPatch_Polyhedron::NbPoints () const | |
322 | { | |
323 | return (nbdeltaU+1)*(nbdeltaV+1); | |
324 | } | |
325 | ||
326 | //======================================================================= | |
327 | //function : TriConnex | |
328 | //purpose : | |
329 | //======================================================================= | |
330 | Standard_Integer IntPatch_Polyhedron::TriConnex (const Standard_Integer Triang, | |
331 | const Standard_Integer Pivot, | |
332 | const Standard_Integer Pedge, | |
333 | Standard_Integer& TriCon, | |
334 | Standard_Integer& OtherP) const { | |
335 | ||
7fd59977 | 336 | Standard_Integer Pivotm1 = Pivot-1; |
337 | Standard_Integer nbdeltaVp1 = nbdeltaV+1; | |
338 | Standard_Integer nbdeltaVm2 = nbdeltaV + nbdeltaV; | |
339 | ||
340 | // Pivot position in the MaTriangle : | |
341 | Standard_Integer ligP = Pivotm1/nbdeltaVp1; | |
342 | Standard_Integer colP = Pivotm1 - ligP * nbdeltaVp1; | |
343 | ||
344 | // Point sur Edge position in the MaTriangle and edge typ : | |
7fd59977 | 345 | Standard_Integer ligE = 0, colE = 0, typE = 0; |
7fd59977 | 346 | if (Pedge!=0) { |
347 | ligE= (Pedge-1)/nbdeltaVp1; | |
348 | colE= (Pedge-1) - (ligE * nbdeltaVp1); | |
349 | // Horizontal | |
350 | if (ligP==ligE) typE=1; | |
351 | // Vertical | |
352 | else if (colP==colE) typE=2; | |
353 | // Oblique | |
354 | else typE=3; | |
355 | } | |
356 | else { | |
357 | typE=0; | |
358 | } | |
359 | ||
360 | // Triangle position General case : | |
7fd59977 | 361 | Standard_Integer linT = 0, colT = 0; |
362 | Standard_Integer linO = 0, colO = 0; | |
7fd59977 | 363 | Standard_Integer t,tt; |
364 | if (Triang!=0) { | |
365 | t = (Triang-1)/(nbdeltaVm2); | |
366 | tt= (Triang-1)-t*nbdeltaVm2; | |
367 | linT= 1+t; | |
368 | colT= 1+tt; | |
369 | if (typE==0) { | |
370 | if (ligP==linT) { | |
371 | ligE=ligP-1; | |
372 | colE=colP-1; | |
373 | typE=3; | |
374 | } | |
375 | else { | |
376 | if (colT==ligP+ligP) { | |
377 | ligE=ligP; | |
378 | colE=colP-1; | |
379 | typE=1; | |
380 | } | |
381 | else { | |
382 | ligE=ligP+1; | |
383 | colE=colP+1; | |
384 | typE=3; | |
385 | } | |
386 | } | |
387 | } | |
388 | switch (typE) { | |
389 | case 1: // Horizontal | |
390 | if (linT==ligP) { | |
391 | linT++; | |
392 | linO=ligP+1; | |
393 | colO=(colP>colE)? colP : colE; //--colO=Max(colP, colE); | |
394 | } | |
395 | else { | |
396 | linT--; | |
397 | linO=ligP-1; | |
398 | colO=(colP<colE)? colP : colE; //--colO=Min(colP, colE); | |
399 | } | |
400 | break; | |
401 | case 2: // Vertical | |
402 | if (colT==(colP+colP)) { | |
403 | colT++; | |
404 | linO=(ligP>ligE)? ligP : ligE; //--linO=Max(ligP, ligE); | |
405 | colO=colP+1;; | |
406 | } | |
407 | else { | |
408 | colT--; | |
409 | linO=(ligP<ligE)? ligP : ligE; //--linO=Min(ligP, ligE); | |
410 | colO=colP-1;; | |
411 | } | |
412 | break; | |
413 | case 3: // Oblique | |
414 | if ((colT&1)==0) { | |
415 | colT--; | |
416 | linO=(ligP>ligE)? ligP : ligE; //--linO=Max(ligP, ligE); | |
417 | colO=(colP<colE)? colP : colE; //--colO=Min(colP, colE); | |
418 | } | |
419 | else { | |
420 | colT++; | |
421 | linO=(ligP<ligE)? ligP : ligE; //--linO=Min(ligP, ligE); | |
422 | colO=(colP>colE)? colP : colE; //--colO=Max(colP, colE); | |
423 | } | |
424 | break; | |
425 | } | |
426 | } | |
427 | else { | |
428 | // Unknown Triangle position : | |
429 | if (Pedge==0) { | |
430 | // Unknown edge : | |
431 | linT=(1>ligP)? 1 : ligP; //--linT=Max(1, ligP); | |
432 | colT=(1>(colP+colP))? 1 : (colP+colP); //--colT=Max(1, colP+colP); | |
433 | if (ligP==0) linO=ligP+1; | |
434 | else linO=ligP-1; | |
435 | colO=colP; | |
436 | } | |
437 | else { | |
438 | // Known edge We take the left or down connectivity : | |
439 | switch (typE) { | |
440 | case 1: // Horizontal | |
441 | linT=ligP+1; | |
442 | colT=(colP>colE)? colP : colE; //--colT=Max(colP,colE); | |
443 | colT+=colT; | |
444 | linO=ligP+1; | |
445 | colO=(colP>colE)? colP : colE; //--colO=Max(colP,colE); | |
446 | break; | |
447 | case 2: // Vertical | |
448 | linT=(ligP>ligE)? ligP : ligE; //--linT=Max(ligP, ligE); | |
449 | colT=colP+colP; | |
450 | linO=(ligP<ligE)? ligP : ligE; //--linO=Min(ligP, ligE); | |
451 | colO=colP-1; | |
452 | break; | |
453 | case 3: // Oblique | |
454 | linT=(ligP>ligE)? ligP : ligE; //--linT=Max(ligP, ligE); | |
455 | colT=colP+colE; | |
456 | linO=(ligP>ligE)? ligP : ligE; //--linO=Max(ligP, ligE); | |
457 | colO=(colP<colE)? colP : colE; //--colO=Min(colP, colE); | |
458 | break; | |
459 | } | |
460 | } | |
461 | } | |
462 | ||
463 | TriCon=(linT-1)*nbdeltaVm2 + colT; | |
464 | ||
465 | if (linT<1) { | |
466 | linO=0; | |
467 | colO=colP+colP-colE; | |
468 | if (colO<0) {colO=0;linO=1;} | |
469 | else if (colO>nbdeltaV) {colO=nbdeltaV;linO=1;} | |
470 | TriCon=0; | |
471 | } | |
472 | else if (linT>nbdeltaU) { | |
473 | linO=nbdeltaU; | |
474 | colO=colP+colP-colE; | |
475 | if (colO<0) {colO=0;linO=nbdeltaU-1;} | |
476 | else if (colO>nbdeltaV) {colO=nbdeltaV;linO=nbdeltaU-1;} | |
477 | TriCon=0; | |
478 | } | |
479 | ||
480 | if (colT<1) { | |
481 | colO=0; | |
482 | linO=ligP+ligP-ligE; | |
483 | if (linO<0) {linO=0;colO=1;} | |
484 | else if (linO>nbdeltaU) {linO=nbdeltaU;colO=1;} | |
485 | TriCon=0; | |
486 | } | |
487 | else if (colT>nbdeltaV) { | |
488 | colO=nbdeltaV; | |
489 | linO=ligP+ligP-ligE; | |
490 | if (linO<0) {linO=0;colO=nbdeltaV-1;} | |
491 | else if (linO>nbdeltaU) {linO=nbdeltaU;colO=nbdeltaV-1;} | |
492 | TriCon=0; | |
493 | } | |
494 | ||
495 | OtherP=linO*nbdeltaVp1 + colO+1; | |
496 | ||
497 | ||
498 | //---------------------------------------------------- | |
499 | //-- Detection des cas ou le triangle retourne est | |
500 | //-- invalide. Dans ce cas, on retourne le triangle | |
501 | //-- suivant par un nouvel appel a TriConnex. | |
502 | //-- | |
503 | //-- Si En entree : Point(Pivot)==Point(Pedge) | |
504 | //-- Alors on retourne OtherP a 0 | |
505 | //-- et Tricon = Triangle | |
506 | //-- | |
507 | if(Point(Pivot).SquareDistance(Point(Pedge))<=LONGUEUR_MINI_EDGE_TRIANGLE) { | |
508 | OtherP=0; | |
509 | TriCon=Triang; | |
510 | #if MSG_DEBUG | |
511 | cout<<" Probleme ds IntCurveSurface_Polyhedron : Pivot et PEdge Confondus "<<endl; | |
512 | #endif | |
513 | return(TriCon); | |
514 | } | |
515 | if(Point(OtherP).SquareDistance(Point(Pedge))<=LONGUEUR_MINI_EDGE_TRIANGLE) { | |
516 | #if MSG_DEBUG | |
517 | cout<<" Probleme ds IntCurveSurface_Polyhedron : OtherP et PEdge Confondus "<<endl; | |
518 | #endif | |
7fd59977 | 519 | return(0); //-- BUG NON CORRIGE ( a revoir le role de nbdeltaU et nbdeltaV) |
96a95605 DB |
520 | // Standard_Integer TempTri,TempOtherP; |
521 | // TempTri = TriCon; | |
522 | // TempOtherP = OtherP; | |
d3f26155 | 523 | // return(TriConnex(TempTri,Pivot,TempOtherP,TriCon,OtherP)); |
7fd59977 | 524 | } |
525 | return TriCon; | |
526 | } | |
527 | ||
528 | ||
529 | ||
530 | //======================================================================= | |
531 | //function : PlaneEquation | |
532 | //purpose : | |
533 | //======================================================================= | |
534 | ||
535 | void IntPatch_Polyhedron::PlaneEquation (const Standard_Integer Triang, | |
536 | gp_XYZ& NormalVector, | |
537 | Standard_Real& PolarDistance) const | |
538 | { | |
539 | Standard_Integer i1,i2,i3; | |
540 | Triangle(Triang,i1,i2,i3); | |
541 | ||
542 | gp_XYZ Pointi1(Point(i1).XYZ()); | |
543 | gp_XYZ Pointi2(Point(i2).XYZ()); | |
544 | gp_XYZ Pointi3(Point(i3).XYZ()); | |
545 | ||
546 | ||
547 | gp_XYZ v1= Pointi2 - Pointi1; | |
548 | gp_XYZ v2= Pointi3 - Pointi2; | |
549 | gp_XYZ v3= Pointi1 - Pointi3; | |
550 | ||
551 | if(v1.SquareModulus()<=LONGUEUR_MINI_EDGE_TRIANGLE) { NormalVector.SetCoord(1.0,0.0,0.0); return; } | |
552 | if(v2.SquareModulus()<=LONGUEUR_MINI_EDGE_TRIANGLE) { NormalVector.SetCoord(1.0,0.0,0.0); return; } | |
553 | if(v3.SquareModulus()<=LONGUEUR_MINI_EDGE_TRIANGLE) { NormalVector.SetCoord(1.0,0.0,0.0); return; } | |
554 | ||
555 | NormalVector= (v1^v2)+(v2^v3)+(v3^v1); | |
df119b4e | 556 | Standard_Real aNormLen = NormalVector.Modulus(); |
557 | if (aNormLen < gp::Resolution()) { | |
558 | PolarDistance = 0.; | |
559 | } | |
560 | else { | |
561 | NormalVector.Divide(aNormLen); | |
562 | PolarDistance = NormalVector * Point(i1).XYZ(); | |
563 | } | |
7fd59977 | 564 | } |
565 | //======================================================================= | |
566 | //function : Contain | |
567 | //purpose : | |
568 | //======================================================================= | |
569 | Standard_Boolean IntPatch_Polyhedron::Contain (const Standard_Integer Triang, | |
570 | const gp_Pnt& ThePnt) const | |
571 | { | |
572 | Standard_Integer i1,i2,i3; | |
573 | Triangle(Triang,i1,i2,i3); | |
574 | gp_XYZ Pointi1(Point(i1).XYZ()); | |
575 | gp_XYZ Pointi2(Point(i2).XYZ()); | |
576 | gp_XYZ Pointi3(Point(i3).XYZ()); | |
577 | ||
578 | gp_XYZ v1=(Pointi2-Pointi1)^(ThePnt.XYZ()-Pointi1); | |
579 | gp_XYZ v2=(Pointi3-Pointi2)^(ThePnt.XYZ()-Pointi2); | |
580 | gp_XYZ v3=(Pointi1-Pointi3)^(ThePnt.XYZ()-Pointi3); | |
581 | if (v1*v2 >= 0. && v2*v3 >= 0. && v3*v1>=0.) | |
582 | return Standard_True; | |
583 | else | |
584 | return Standard_False; | |
585 | } | |
586 | //======================================================================= | |
587 | //function : Dump | |
588 | //purpose : | |
589 | //======================================================================= | |
590 | ||
591 | void IntPatch_Polyhedron::Dump()const | |
592 | { | |
593 | } | |
594 | //======================================================================= | |
595 | //function : Size | |
596 | //purpose : | |
597 | //======================================================================= | |
598 | void IntPatch_Polyhedron::Size(Standard_Integer& nbdu, | |
599 | Standard_Integer& nbdv) const | |
600 | { | |
601 | nbdu=nbdeltaU; | |
602 | nbdv=nbdeltaV; | |
603 | } | |
604 | //======================================================================= | |
605 | //function : Triangle | |
606 | //purpose : | |
607 | //======================================================================= | |
608 | void IntPatch_Polyhedron::Triangle (const Standard_Integer Index, | |
609 | Standard_Integer& P1, | |
610 | Standard_Integer& P2, | |
611 | Standard_Integer& P3) const | |
612 | { | |
613 | Standard_Integer line=1+((Index-1)/(nbdeltaV*2)); | |
614 | Standard_Integer colon=1+((Index-1)%(nbdeltaV*2)); | |
615 | Standard_Integer colpnt=(colon+1)/2; | |
616 | ||
617 | // General formula = (line-1)*(nbdeltaV+1)+colpnt | |
618 | ||
619 | // Position of P1 = MesXYZ(line,colpnt); | |
620 | P1= (line-1)*(nbdeltaV+1) + colpnt; | |
621 | ||
622 | // Position of P2= MesXYZ(line+1,colpnt+((colon-1)%2)); | |
623 | P2= line*(nbdeltaV+1) + colpnt+((colon-1)%2); | |
624 | ||
625 | // Position of P3= MesXYZ(line+(colon%2),colpnt+1); | |
626 | P3= (line-1+(colon%2))*(nbdeltaV+1) + colpnt + 1; | |
627 | //-- printf("\nTriangle %4d P1:%4d P2:%4d P3:%4d",Index,P1,P2,P3); | |
628 | } | |
629 | //======================================================================= | |
630 | //function : Point | |
631 | //======================================================================= | |
632 | const gp_Pnt& IntPatch_Polyhedron::Point( const Standard_Integer Index | |
633 | ,Standard_Real& U | |
634 | ,Standard_Real& V) const | |
635 | { | |
636 | gp_Pnt *CMyPnts = (gp_Pnt *)C_MyPnts; | |
637 | Standard_Real *CMyU = (Standard_Real *)C_MyU; | |
638 | Standard_Real *CMyV = (Standard_Real *)C_MyV; | |
639 | U=CMyU[Index]; | |
640 | V=CMyV[Index]; | |
641 | return CMyPnts[Index]; | |
642 | } | |
643 | //======================================================================= | |
644 | //function : Point | |
645 | //======================================================================= | |
646 | const gp_Pnt& IntPatch_Polyhedron::Point(const Standard_Integer Index) const { | |
647 | gp_Pnt *CMyPnts = (gp_Pnt *)C_MyPnts; | |
648 | return CMyPnts[Index]; | |
649 | } | |
650 | ||
651 | //======================================================================= | |
652 | //function : Point | |
653 | //======================================================================= | |
654 | void IntPatch_Polyhedron::Point (const gp_Pnt& /*p*/, | |
655 | const Standard_Integer /*lig*/, | |
656 | const Standard_Integer /*col*/, | |
657 | const Standard_Real /*u*/, | |
658 | const Standard_Real /*v*/) | |
659 | { | |
660 | //printf("\n IntPatch_Polyhedron::Point : Ne dois pas etre appelle\n"); | |
661 | } | |
662 | ||
663 | //======================================================================= | |
664 | //function : Point | |
665 | //======================================================================= | |
666 | void IntPatch_Polyhedron::Point (const Standard_Integer Index, gp_Pnt& P) const | |
667 | { | |
668 | gp_Pnt *CMyPnts = (gp_Pnt *)C_MyPnts; | |
669 | P = CMyPnts[Index]; | |
670 | } | |
671 | //======================================================================= |