0022627: Change OCCT memory management defaults
[occt.git] / src / IntPatch / IntPatch_Polyhedron.cxx
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   //-- Calcul du point u,v  au centre du triangle
198   Standard_Real u = (u1+u2+u3)/3.0;
199   Standard_Real v = (v1+v2+v3)/3.0;
200   gp_Vec P1P(P1,Surface->Value(u,v));
201   return(Abs(P1P.Dot(NormalVector)));
202 }
203
204 //=======================================================================
205 //function : Parameters
206 //purpose  : 
207 //=======================================================================
208 void IntPatch_Polyhedron::Parameters( const Standard_Integer Index
209                                      ,Standard_Real &U
210                                      ,Standard_Real &V) const 
211 {
212   U = ((Standard_Real *)C_MyU)[Index];
213   V = ((Standard_Real *)C_MyV)[Index];
214 }
215
216 //=======================================================================
217 //function : DeflectionOverEstimation
218 //purpose  : 
219 //=======================================================================
220 void IntPatch_Polyhedron::DeflectionOverEstimation(const Standard_Real flec)
221 {
222   if(flec<0.0001) {  
223     TheDeflection=0.0001;
224     TheBnd.Enlarge(0.0001);
225   }
226   else { 
227     TheDeflection=flec;
228     TheBnd.Enlarge(flec);
229   }
230 }
231
232 //=======================================================================
233 //function : DeflectionOverEstimation
234 //purpose  :
235 //=======================================================================
236 Standard_Real IntPatch_Polyhedron::DeflectionOverEstimation() const
237 {
238   return TheDeflection;
239 }
240
241 //=======================================================================
242 //function : Bounding
243 //purpose  : 
244 //=======================================================================
245 const Bnd_Box& IntPatch_Polyhedron::Bounding() const
246 {
247   return TheBnd;
248 }
249
250 //=======================================================================
251 //function : FillBounding
252 //purpose  : 
253 //=======================================================================
254 void IntPatch_Polyhedron::FillBounding()
255 {
256   TheComponentsBnd=new Bnd_HArray1OfBox(1, NbTriangles());
257   Bnd_Box Boite;
258   Standard_Integer p1, p2, p3;
259   Standard_Integer nbtriangles = NbTriangles();
260   for (Standard_Integer iTri=1; iTri<=nbtriangles; iTri++) {
261     Triangle(iTri, p1, p2, p3);
262     Boite.SetVoid();
263     const gp_Pnt& P1 = Point(p1);
264     const gp_Pnt& P2 = Point(p2);
265     const gp_Pnt& P3 = Point(p3);
266     if(P1.SquareDistance(P2)>LONGUEUR_MINI_EDGE_TRIANGLE) {
267       if(P1.SquareDistance(P3)>LONGUEUR_MINI_EDGE_TRIANGLE) {
268         if(P2.SquareDistance(P3)>LONGUEUR_MINI_EDGE_TRIANGLE) {
269           Boite.Add(P1);
270           Boite.Add(P2);
271           Boite.Add(P3);
272         }  
273       }
274     }
275     Boite.Enlarge(TheDeflection);
276     TheComponentsBnd->SetValue(iTri,Boite);  
277   }
278 }
279
280 //=======================================================================
281 //function : ComponentsBounding
282 //purpose  : 
283 //=======================================================================
284 const Handle(Bnd_HArray1OfBox)& IntPatch_Polyhedron::ComponentsBounding () const
285 {
286   return TheComponentsBnd;
287 }
288
289 //=======================================================================
290 //function : NbTriangles
291 //purpose  : 
292 //=======================================================================
293 Standard_Integer IntPatch_Polyhedron::NbTriangles () const
294 {
295   return nbdeltaU*nbdeltaV*2;
296 }
297
298 //=======================================================================
299 //function : NbPoints
300 //purpose  : 
301 //=======================================================================
302 Standard_Integer IntPatch_Polyhedron::NbPoints () const
303 {
304   return (nbdeltaU+1)*(nbdeltaV+1);
305 }
306
307 //=======================================================================
308 //function : TriConnex
309 //purpose  : 
310 //=======================================================================
311 Standard_Integer IntPatch_Polyhedron::TriConnex (const Standard_Integer Triang,
312                                                  const Standard_Integer Pivot,
313                                                  const Standard_Integer Pedge,
314                                                  Standard_Integer&      TriCon,
315                                                  Standard_Integer&      OtherP)   const {
316
317   Standard_Integer Pivotm1    = Pivot-1;
318   Standard_Integer nbdeltaVp1 = nbdeltaV+1;
319   Standard_Integer nbdeltaVm2 = nbdeltaV + nbdeltaV;
320
321 // Pivot position in the MaTriangle :
322   Standard_Integer ligP = Pivotm1/nbdeltaVp1;
323   Standard_Integer colP = Pivotm1 - ligP * nbdeltaVp1;
324
325 // Point sur Edge position in the MaTriangle and edge typ :
326 #ifndef DEB
327   Standard_Integer ligE = 0, colE = 0, typE = 0;
328 #else 
329   Standard_Integer ligE, colE, typE;
330 #endif
331   if (Pedge!=0) {
332     ligE= (Pedge-1)/nbdeltaVp1;
333     colE= (Pedge-1) - (ligE * nbdeltaVp1);
334   // Horizontal
335     if      (ligP==ligE) typE=1;
336   // Vertical
337     else if (colP==colE) typE=2;
338   // Oblique
339     else                 typE=3;
340   }
341   else {
342     typE=0;
343   }
344
345 // Triangle position General case :
346 #ifndef DEB
347   Standard_Integer linT = 0, colT = 0;
348   Standard_Integer linO = 0, colO = 0;
349 #else
350   Standard_Integer linT, colT;
351   Standard_Integer linO, colO;
352 #endif
353   Standard_Integer t,tt;
354   if (Triang!=0) {
355     t = (Triang-1)/(nbdeltaVm2);
356     tt= (Triang-1)-t*nbdeltaVm2;
357     linT= 1+t;
358     colT= 1+tt;
359     if (typE==0) {
360       if (ligP==linT) {
361         ligE=ligP-1;
362         colE=colP-1;
363         typE=3;
364       }
365       else {
366         if (colT==ligP+ligP) {
367           ligE=ligP;
368           colE=colP-1;
369           typE=1;
370         }
371         else {
372           ligE=ligP+1;
373           colE=colP+1;
374           typE=3;
375         }
376       }
377     }
378     switch (typE) {
379     case 1:  // Horizontal
380       if (linT==ligP) {
381         linT++;
382         linO=ligP+1;
383         colO=(colP>colE)? colP : colE; //--colO=Max(colP, colE);
384       }
385       else {
386         linT--;
387         linO=ligP-1;
388         colO=(colP<colE)? colP : colE;  //--colO=Min(colP, colE);
389       }
390       break;
391     case 2:  // Vertical
392       if (colT==(colP+colP)) {
393         colT++;
394         linO=(ligP>ligE)? ligP : ligE;  //--linO=Max(ligP, ligE);
395         colO=colP+1;;
396       }
397       else {
398         colT--;
399         linO=(ligP<ligE)? ligP : ligE;  //--linO=Min(ligP, ligE);
400         colO=colP-1;;
401       }
402       break;
403     case 3:  // Oblique
404       if ((colT&1)==0) {
405         colT--;
406         linO=(ligP>ligE)? ligP : ligE;  //--linO=Max(ligP, ligE);
407         colO=(colP<colE)? colP : colE;  //--colO=Min(colP, colE);
408       }
409       else {
410         colT++;
411         linO=(ligP<ligE)? ligP : ligE;  //--linO=Min(ligP, ligE);
412         colO=(colP>colE)? colP : colE;  //--colO=Max(colP, colE);
413       }
414       break;
415     }
416   }
417   else {
418     // Unknown Triangle position :
419     if (Pedge==0) {
420       // Unknown edge :
421       linT=(1>ligP)? 1 : ligP;      //--linT=Max(1, ligP);
422       colT=(1>(colP+colP))? 1 : (colP+colP);       //--colT=Max(1, colP+colP);
423       if (ligP==0) linO=ligP+1;
424       else         linO=ligP-1;
425       colO=colP;
426     }
427     else {
428       // Known edge We take the left or down connectivity :
429       switch (typE) {
430       case 1:  // Horizontal
431         linT=ligP+1;
432         colT=(colP>colE)? colP : colE;  //--colT=Max(colP,colE);
433         colT+=colT;
434         linO=ligP+1;
435         colO=(colP>colE)? colP : colE;  //--colO=Max(colP,colE);
436         break;
437       case 2:  // Vertical
438         linT=(ligP>ligE)? ligP : ligE;  //--linT=Max(ligP, ligE);
439         colT=colP+colP;
440         linO=(ligP<ligE)? ligP : ligE;  //--linO=Min(ligP, ligE);
441         colO=colP-1;
442         break;
443       case 3:  // Oblique
444         linT=(ligP>ligE)? ligP : ligE;  //--linT=Max(ligP, ligE);
445         colT=colP+colE;
446         linO=(ligP>ligE)? ligP : ligE;  //--linO=Max(ligP, ligE);
447         colO=(colP<colE)? colP : colE;  //--colO=Min(colP, colE);
448         break;
449       }
450     }
451   }
452
453   TriCon=(linT-1)*nbdeltaVm2 + colT;
454
455   if (linT<1) {
456     linO=0;
457     colO=colP+colP-colE;
458     if (colO<0) {colO=0;linO=1;}
459     else if (colO>nbdeltaV) {colO=nbdeltaV;linO=1;}
460     TriCon=0;
461   }
462   else if (linT>nbdeltaU) {
463     linO=nbdeltaU;
464     colO=colP+colP-colE;
465     if (colO<0) {colO=0;linO=nbdeltaU-1;}
466     else if (colO>nbdeltaV) {colO=nbdeltaV;linO=nbdeltaU-1;}
467     TriCon=0;
468   }
469
470   if (colT<1) {
471     colO=0;
472     linO=ligP+ligP-ligE;
473     if (linO<0) {linO=0;colO=1;}
474     else if (linO>nbdeltaU) {linO=nbdeltaU;colO=1;}
475     TriCon=0;
476   }
477   else if (colT>nbdeltaV) {
478     colO=nbdeltaV;
479     linO=ligP+ligP-ligE;
480     if (linO<0) {linO=0;colO=nbdeltaV-1;}
481     else if (linO>nbdeltaU) {linO=nbdeltaU;colO=nbdeltaV-1;}
482     TriCon=0;
483   }
484
485   OtherP=linO*nbdeltaVp1 + colO+1;
486
487
488   //----------------------------------------------------
489   //-- Detection des cas ou le triangle retourne est
490   //-- invalide. Dans ce cas, on retourne le triangle
491   //-- suivant par un nouvel appel a TriConnex.
492   //-- 
493   //-- Si En entree : Point(Pivot)==Point(Pedge) 
494   //-- Alors on retourne OtherP a 0 
495   //-- et Tricon = Triangle
496   //--
497   if(Point(Pivot).SquareDistance(Point(Pedge))<=LONGUEUR_MINI_EDGE_TRIANGLE) { 
498     OtherP=0;
499     TriCon=Triang;
500 #if MSG_DEBUG
501     cout<<" Probleme ds IntCurveSurface_Polyhedron : Pivot et PEdge Confondus "<<endl;
502 #endif
503     return(TriCon);
504   }
505   if(Point(OtherP).SquareDistance(Point(Pedge))<=LONGUEUR_MINI_EDGE_TRIANGLE) { 
506 #if MSG_DEBUG
507     cout<<" Probleme ds IntCurveSurface_Polyhedron : OtherP et PEdge Confondus "<<endl;
508 #endif
509     Standard_Integer TempTri,TempOtherP;
510     TempTri = TriCon;
511     TempOtherP = OtherP;
512
513     return(0); //-- BUG NON CORRIGE ( a revoir le role de nbdeltaU et nbdeltaV)
514
515     return(TriConnex(TempTri,Pivot,TempOtherP,TriCon,OtherP));
516   }
517   return TriCon;
518 }
519
520
521
522 //=======================================================================
523 //function : PlaneEquation
524 //purpose  : 
525 //=======================================================================
526
527 void IntPatch_Polyhedron::PlaneEquation (const Standard_Integer Triang,
528                                          gp_XYZ&        NormalVector,
529                                          Standard_Real& PolarDistance)  const
530 {
531   Standard_Integer i1,i2,i3;
532   Triangle(Triang,i1,i2,i3);
533
534   gp_XYZ Pointi1(Point(i1).XYZ());
535   gp_XYZ Pointi2(Point(i2).XYZ());
536   gp_XYZ Pointi3(Point(i3).XYZ());
537   
538
539   gp_XYZ v1= Pointi2 - Pointi1;
540   gp_XYZ v2= Pointi3 - Pointi2;
541   gp_XYZ v3= Pointi1 - Pointi3;
542
543   if(v1.SquareModulus()<=LONGUEUR_MINI_EDGE_TRIANGLE) { NormalVector.SetCoord(1.0,0.0,0.0); return; } 
544   if(v2.SquareModulus()<=LONGUEUR_MINI_EDGE_TRIANGLE) { NormalVector.SetCoord(1.0,0.0,0.0); return; } 
545   if(v3.SquareModulus()<=LONGUEUR_MINI_EDGE_TRIANGLE) { NormalVector.SetCoord(1.0,0.0,0.0); return; } 
546
547   NormalVector= (v1^v2)+(v2^v3)+(v3^v1);
548   NormalVector.Normalize();
549   PolarDistance = NormalVector * Point(i1).XYZ();
550 }
551 //=======================================================================
552 //function : Contain
553 //purpose  : 
554 //=======================================================================
555 Standard_Boolean IntPatch_Polyhedron::Contain (const Standard_Integer Triang,
556                                                const gp_Pnt& ThePnt) const
557 {  
558   Standard_Integer i1,i2,i3;
559   Triangle(Triang,i1,i2,i3);
560   gp_XYZ Pointi1(Point(i1).XYZ());
561   gp_XYZ Pointi2(Point(i2).XYZ());
562   gp_XYZ Pointi3(Point(i3).XYZ());
563   
564   gp_XYZ v1=(Pointi2-Pointi1)^(ThePnt.XYZ()-Pointi1);
565   gp_XYZ v2=(Pointi3-Pointi2)^(ThePnt.XYZ()-Pointi2);
566   gp_XYZ v3=(Pointi1-Pointi3)^(ThePnt.XYZ()-Pointi3);
567   if (v1*v2 >= 0. && v2*v3 >= 0. && v3*v1>=0.) 
568     return Standard_True;
569   else 
570     return Standard_False;
571 }
572 //=======================================================================
573 //function : Dump
574 //purpose  : 
575 //=======================================================================
576
577 void IntPatch_Polyhedron::Dump()const
578 {
579 }
580 //=======================================================================
581 //function : Size
582 //purpose  : 
583 //=======================================================================
584 void IntPatch_Polyhedron::Size(Standard_Integer& nbdu,
585                                Standard_Integer& nbdv) const
586 {
587   nbdu=nbdeltaU;
588   nbdv=nbdeltaV;
589 }
590 //=======================================================================
591 //function : Triangle
592 //purpose  : 
593 //=======================================================================
594 void IntPatch_Polyhedron::Triangle (const Standard_Integer Index,
595                                     Standard_Integer& P1,
596                                     Standard_Integer& P2,
597                                     Standard_Integer& P3) const
598 {
599   Standard_Integer line=1+((Index-1)/(nbdeltaV*2));
600   Standard_Integer colon=1+((Index-1)%(nbdeltaV*2));
601   Standard_Integer colpnt=(colon+1)/2;
602
603 // General formula = (line-1)*(nbdeltaV+1)+colpnt
604   
605 //  Position of P1 = MesXYZ(line,colpnt);
606   P1= (line-1)*(nbdeltaV+1) + colpnt;
607
608 //  Position of P2= MesXYZ(line+1,colpnt+((colon-1)%2));
609   P2= line*(nbdeltaV+1) + colpnt+((colon-1)%2);
610
611 //  Position of P3= MesXYZ(line+(colon%2),colpnt+1);
612   P3= (line-1+(colon%2))*(nbdeltaV+1) + colpnt + 1;
613   //-- printf("\nTriangle %4d    P1:%4d   P2:%4d   P3:%4d",Index,P1,P2,P3);
614 }
615 //=======================================================================
616 //function : Point
617 //=======================================================================
618 const gp_Pnt& IntPatch_Polyhedron::Point( const Standard_Integer Index
619                                          ,Standard_Real& U
620                                          ,Standard_Real& V) const 
621 {
622   gp_Pnt *CMyPnts     = (gp_Pnt *)C_MyPnts;
623   Standard_Real *CMyU = (Standard_Real *)C_MyU;
624   Standard_Real *CMyV = (Standard_Real *)C_MyV;
625   U=CMyU[Index];
626   V=CMyV[Index];
627   return CMyPnts[Index];
628 }
629 //=======================================================================
630 //function : Point
631 //=======================================================================
632 const gp_Pnt& IntPatch_Polyhedron::Point(const Standard_Integer Index) const {
633   gp_Pnt *CMyPnts     = (gp_Pnt *)C_MyPnts;
634   return CMyPnts[Index];
635 }
636
637 //=======================================================================
638 //function : Point
639 //=======================================================================
640 void IntPatch_Polyhedron::Point (const gp_Pnt& /*p*/, 
641                                  const Standard_Integer /*lig*/,
642                                  const Standard_Integer /*col*/,
643                                  const Standard_Real /*u*/,
644                                  const Standard_Real /*v*/) 
645 {
646   //printf("\n IntPatch_Polyhedron::Point : Ne dois pas etre appelle\n");
647 }
648
649 //=======================================================================
650 //function : Point
651 //=======================================================================
652 void IntPatch_Polyhedron::Point (const Standard_Integer Index, gp_Pnt& P) const
653 {
654   gp_Pnt *CMyPnts = (gp_Pnt *)C_MyPnts;
655   P = CMyPnts[Index];
656 }
657 //=======================================================================