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