8f3ffcd0f4d24a19f740bdf3aefe5709604fb074
[occt.git] / src / GeomPlate / GeomPlate_PlateG0Criterion.cxx
1 // File:        GeomPlate_PlateG0Criterion.cxx
2 // Created:     Wed Mar  5 10:04:41 1997
3 // Author:      Joelle CHAUVET
4 //              <jct@sgi38>
5 //Modified by   Jerome LEMONIER
6 //              Tue Jun 17 10:20:35 1997
7 //              Modification de la comparaison dans la methode
8 //              Value (Appel a des distances remplace par le calcul
9 //              de la distance au carre)
10
11
12 #include <GeomPlate_PlateG0Criterion.ixx>
13 #include <AdvApp2Var_Criterion.hxx>
14 #include <TColgp_SequenceOfXY.hxx>
15 #include <TColgp_SequenceOfXYZ.hxx>
16 #include <gp_Vec.hxx>
17 #include <gp_XY.hxx>
18 #include <gp_Pnt.hxx>
19 #include <TColStd_HArray1OfReal.hxx>
20 #include <PLib.hxx>
21
22
23  
24 //============================================================================
25 //function : GeomPlate_PlateG0Criterion 
26 //purpose  :
27 //============================================================================
28
29
30  GeomPlate_PlateG0Criterion::
31 GeomPlate_PlateG0Criterion(const TColgp_SequenceOfXY& Data,
32                            const TColgp_SequenceOfXYZ& G0Data,
33                            const Standard_Real Maximum,
34                            const AdvApp2Var_CriterionType Type,
35                            const AdvApp2Var_CriterionRepartition Repart)
36 {
37   myData=Data;
38   myXYZ=G0Data;
39   myMaxValue = Maximum;
40   myType = Type;
41   myRepartition = Repart;
42 }
43
44
45 //============================================================================
46 //function : Value
47 //purpose  :
48 //============================================================================
49
50 void GeomPlate_PlateG0Criterion::Value(AdvApp2Var_Patch& P,
51                                        const AdvApp2Var_Context& C) const
52 {
53   Standard_Real UInt[2],VInt[2];
54   Standard_Integer MaxNbCoeff[2], NbCoeff[2];
55   Standard_Real * adrCoeff = NULL ;
56   adrCoeff = (Standard_Real *) &P.Coefficients(1,C) ->ChangeArray1()(P.Coefficients(1,C)->Lower());
57
58   MaxNbCoeff[0] = C.ULimit();
59   MaxNbCoeff[1] = C.VLimit();
60   NbCoeff[0] = P.NbCoeffInU();
61   NbCoeff[1] = P.NbCoeffInV();
62   UInt[0] = P.U0();
63   UInt[1] = P.U1();
64   VInt[0] = P.V0();
65   VInt[1] = P.V1();
66
67   Standard_Real up,vp, dist = 0.;
68   
69   Standard_Integer dimension = 3 * NbCoeff[1];
70   TColStd_Array1OfReal Patch(1, NbCoeff[0] * dimension);
71   TColStd_Array1OfReal Curve(1, dimension);
72   TColStd_Array1OfReal Point(1, 3); 
73   Standard_Real * Coeffs =  (Standard_Real *) &Patch.ChangeValue(1);
74 #ifdef DEB
75   Standard_Real * Result =  
76 #endif
77     (Standard_Real *) &Curve.ChangeValue(1);
78   Standard_Real * Digit  =  (Standard_Real *) &Point.ChangeValue(1);
79   
80   Standard_Integer k1, k2, pos, ll=1;
81   for (k1 = 1; k1 <= NbCoeff[0]; k1++) {
82 // JAG 99.04.29    pos = 3*(MaxNbCoeff[0])*(k1-1);
83     pos = 3*(MaxNbCoeff[1])*(k1-1);
84     for (k2 = 1; k2 <= NbCoeff[1]; k2++, pos+=3 ) {
85       Patch(ll)   =  adrCoeff[pos];
86       Patch(ll+1) =  adrCoeff[pos+1];
87       Patch(ll+2) =  adrCoeff[pos+2];
88       ll += 3;
89     }
90   }
91
92   Standard_Integer i, NbCtr = myData.Length();
93   for(i=1; i<=NbCtr; i++) {
94     gp_XY P2d = myData.Value(i);
95 //    gp_Pnt PP = myXYZ.Value(i);
96     gp_Pnt P3d;
97     if ( UInt[0]<P2d.X() && P2d.X()<UInt[1]
98           && VInt[0]<P2d.Y() && P2d.Y()<VInt[1] ) {
99 //   u,v recadres sur (-1,1)
100       up = (2*P2d.X()-UInt[0]-UInt[1])
101               / (UInt[1]-UInt[0]) ;
102       vp = (2*P2d.Y()-VInt[0]-VInt[1])
103               / (VInt[1]-VInt[0]) ;
104       PLib::EvalPoly2Var(up,vp,
105                          0,0,
106                          NbCoeff[0]-1,NbCoeff[1]-1,3,
107                          Coeffs[0],
108                          Digit[0]);
109
110       P3d.SetCoord(1,Digit[0]);
111       P3d.SetCoord(2,Digit[1]);
112       P3d.SetCoord(3,Digit[2]);
113       Standard_Real x=(P3d.Coord(1)-myXYZ.Value(i).Coord(1)),
114                     y=(P3d.Coord(2)-myXYZ.Value(i).Coord(2)),
115                     z=(P3d.Coord(3)-myXYZ.Value(i).Coord(3)),
116                     DistTmp= x*x+y*y+z*z;
117       if( DistTmp>dist ) {
118           dist = DistTmp;
119       }
120     }
121   }
122   P.SetCritValue(Sqrt(dist));
123 }
124
125
126 //============================================================================
127 //function : IsSatisfied
128 //purpose  :
129 //============================================================================
130
131 Standard_Boolean GeomPlate_PlateG0Criterion::IsSatisfied(const AdvApp2Var_Patch& P) const
132 {
133   return (P.CritValue() < myMaxValue);
134 }
135