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