0023948: Wrong intersection between a surface of revolution and a plane.
[occt.git] / src / GeomPlate / GeomPlate_PlateG1Criterion.cxx
CommitLineData
b311480e 1// Created on: 1997-03-05
2// Created by: Joelle CHAUVET
3// Copyright (c) 1997-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 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
973c2be1 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.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
17#include <GeomPlate_PlateG1Criterion.ixx>
18#include <AdvApp2Var_Criterion.hxx>
19#include <TColgp_SequenceOfXY.hxx>
20#include <TColgp_SequenceOfXYZ.hxx>
21#include <gp_Vec.hxx>
22#include <gp_XY.hxx>
23#include <gp_Pnt.hxx>
24#include <TColStd_HArray1OfReal.hxx>
25#include <PLib.hxx>
26
27
28// static Standard_Boolean first = Standard_True;
29
30
31//============================================================================
32//function : GeomPlate_PlateG1Criterion
33//purpose :
34//============================================================================
35
36
b311480e 37GeomPlate_PlateG1Criterion::
7fd59977 38GeomPlate_PlateG1Criterion(const TColgp_SequenceOfXY& Data,
39 const TColgp_SequenceOfXYZ& G1Data,
40 const Standard_Real Maximum,
41 const AdvApp2Var_CriterionType Type,
42 const AdvApp2Var_CriterionRepartition Repart)
43{
44 myData=Data;
45 myXYZ=G1Data;
46 myMaxValue = Maximum;
47 myType = Type;
48 myRepartition = Repart;
49}
50
51
52//============================================================================
53//function : Value
54//purpose :
55//============================================================================
56
57void GeomPlate_PlateG1Criterion::Value(AdvApp2Var_Patch& P,
58 const AdvApp2Var_Context& C) const
59{
60 Standard_Real UInt[2],VInt[2];
61 Standard_Integer MaxNbCoeff[2], NbCoeff[2];
62 Standard_Real * adrCoeff = NULL ;
63 adrCoeff = (Standard_Real *) &P.Coefficients(1,C) ->ChangeArray1()(P.Coefficients(1,C)->Lower());
64
65 MaxNbCoeff[0] = C.ULimit();
66 MaxNbCoeff[1] = C.VLimit();
67 NbCoeff[0] = P.NbCoeffInU();
68 NbCoeff[1] = P.NbCoeffInV();
69 UInt[0] = P.U0();
70 UInt[1] = P.U1();
71 VInt[0] = P.V0();
72 VInt[1] = P.V1();
73
74 Standard_Real up,vp, ang = 0.;
75
76 Standard_Integer dimension = 3 * NbCoeff[1];
77 TColStd_Array1OfReal Patch(1, NbCoeff[0] * dimension);
78 TColStd_Array1OfReal Curve(1, 2*dimension);
79 TColStd_Array1OfReal Point(1, 3);
80 Standard_Real * Coeffs = (Standard_Real *) &Patch.ChangeValue(1);
7fd59977 81 Standard_Real * Digit = (Standard_Real *) &Point.ChangeValue(1);
82
83 Standard_Integer k1, k2, pos, ll=1;
84 for (k1 = 1; k1 <= NbCoeff[0]; k1++) {
85// JAG 99.04.29 pos = 3*(MaxNbCoeff[0])*(k1-1);
86 pos = 3*(MaxNbCoeff[1])*(k1-1);
87 for (k2 = 1; k2 <= NbCoeff[1]; k2++, pos+=3 ) {
88 Patch(ll) = adrCoeff[pos];
89 Patch(ll+1) = adrCoeff[pos+1];
90 Patch(ll+2) = adrCoeff[pos+2];
91 ll += 3;
92 }
93 }
94
95 Standard_Integer i, NbCtr = myData.Length();
96 for(i=1; i<=NbCtr; i++) {
97 gp_Vec v1s,v2s,v3s;
98 gp_Vec v3h(myXYZ.Value(i).X(),myXYZ.Value(i).Y(),myXYZ.Value(i).Z());
99 gp_XY P2d = myData.Value(i);
100 if ( UInt[0]<P2d.X() && P2d.X()<UInt[1]
101 && VInt[0]<P2d.Y() && P2d.Y()<VInt[1] ) {
102// u,v recadres sur (-1,1)
103 up = (2*P2d.X()-UInt[0]-UInt[1])
104 / (UInt[1]-UInt[0]) ;
105 vp = (2*P2d.Y()-VInt[0]-VInt[1])
106 / (VInt[1]-VInt[0]) ;
107 PLib::EvalPoly2Var(up,vp,
108 1,0,
109 NbCoeff[0]-1,NbCoeff[1]-1,3,
110 Coeffs[0],
111 Digit[0]);
112
113 v1s.SetCoord(1,Digit[0]);
114 v1s.SetCoord(2,Digit[1]);
115 v1s.SetCoord(3,Digit[2]);
116
117 PLib::EvalPoly2Var(up,vp,
118 0,1,
119 NbCoeff[0]-1,NbCoeff[1]-1,3,
120 Coeffs[0],
121 Digit[0]);
122
123 v2s.SetCoord(1,Digit[0]);
124 v2s.SetCoord(2,Digit[1]);
125 v2s.SetCoord(3,Digit[2]);
126
127 v3s=v1s^v2s;
c6541a0c
D
128 if( v3s.Angle(v3h)>(M_PI/2)) {
129 if ((M_PI-v3s.Angle(v3h))>ang) {
130 ang=(M_PI-v3s.Angle(v3h));
7fd59977 131 }
132 }
133 else {
134 if(v3s.Angle(v3h)>ang) {
135 ang=v3s.Angle(v3h);
136 }
137 }
138 }
139 }
140 P.SetCritValue(ang);
141}
142
143
144//============================================================================
145//function : IsSatisfied
146//purpose :
147//============================================================================
148
149Standard_Boolean GeomPlate_PlateG1Criterion::IsSatisfied(const AdvApp2Var_Patch& P) const
150{
151 return (P.CritValue() < myMaxValue);
152}
153