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