Integration of OCCT 6.5.0 from SVN
[occt.git] / src / HLRBRep / HLRBRep_Surface.cxx
CommitLineData
7fd59977 1// File: HLRBRep_Surface.cxx
2// Created: Fri Mar 13 11:08:32 1992
3// Author: Christophe MARION
4// <cma@sdsun2>
5
6#include <HLRBRep_Surface.ixx>
7#include <HLRBRep_BSurfaceTool.hxx>
8#include <gp_Pln.hxx>
9#include <GProp_PEquation.hxx>
10#include <TColgp_Array1OfPnt.hxx>
11#include <BRepClass_FaceClassifier.hxx>
12#include <HLRAlgo_Projector.hxx>
13#include <HLRBRep_Curve.hxx>
14#include <TColStd_Array2OfReal.hxx>
15#include <Geom_BSplineSurface.hxx>
16#include <Geom_BezierSurface.hxx>
17
18//=======================================================================
19//function : HLRBRep_Surface
20//purpose :
21//=======================================================================
22
23HLRBRep_Surface::HLRBRep_Surface ()
24{
25}
26
27//=======================================================================
28//function : Surface
29//purpose :
30//=======================================================================
31
32void HLRBRep_Surface::Surface (const TopoDS_Face& F)
33{
34 mySurf.Initialize(F,Standard_False);
35 GeomAbs_SurfaceType typ = HLRBRep_BSurfaceTool::GetType(mySurf);
36 switch (typ) {
37
38 case GeomAbs_Plane :
39 case GeomAbs_Cylinder :
40 case GeomAbs_Cone :
41 case GeomAbs_Sphere :
42 case GeomAbs_Torus :
43 // unchanged type
44 myType = typ;
45 break;
46
47 case GeomAbs_BezierSurface :
48 if (HLRBRep_BSurfaceTool::UDegree(mySurf) == 1 &&
49 HLRBRep_BSurfaceTool::VDegree(mySurf) == 1) {
50 myType = GeomAbs_Plane;
51 }
52 else
53 myType = typ;
54 break;
55
56 default :
57 myType = GeomAbs_OtherSurface;
58 break;
59 }
60}
61
62//=======================================================================
63//function : SideRowsOfPoles
64//purpose :
65//=======================================================================
66
67Standard_Boolean
68HLRBRep_Surface::SideRowsOfPoles (const Standard_Real tol,
69 const Standard_Integer nbuPoles,
70 const Standard_Integer nbvPoles,
71 TColgp_Array2OfPnt& Pnt) const
72{
73 Standard_Integer iu,iv;
74 Standard_Real x0,y0,x,y,z;
75 Standard_Boolean result;
76 Standard_Real tole = (Standard_Real)tol;
77 const gp_Trsf& T = ((HLRAlgo_Projector*) myProj)->Transformation();
78
79 for (iu = 1; iu <= nbuPoles; iu++) {
80
81 for (iv = 1; iv <= nbvPoles; iv++)
82 Pnt(iu,iv).Transform(T);
83 }
84 result = Standard_True;
85
86 for (iu = 1; iu <= nbuPoles && result; iu++) { // Side iso u ?
87 Pnt(iu,1).Coord(x0,y0,z);
88
89 for (iv = 2; iv <= nbvPoles && result; iv++) {
90 Pnt(iu,iv).Coord(x,y,z);
91 result = Abs(x-x0) < tole && Abs(y-y0) < tole;
92 }
93 }
94 if (result) return result;
95 result = Standard_True;
96
97 for (iv = 1; iv <= nbvPoles && result; iv++) { // Side iso v ?
98 Pnt(1,iv).Coord(x0,y0,z);
99
100 for (iu = 2; iu <= nbuPoles && result; iu++) {
101 Pnt(iu,iv).Coord(x,y,z);
102 result = Abs(x-x0) < tole && Abs(y-y0) < tole;
103 }
104 }
105 if (result) return result;
106
107 // Are the Poles in a Side Plane ?
108 TColgp_Array1OfPnt p(1,nbuPoles*nbvPoles);
109 Standard_Integer i = 0;
110
111 for (iu = 1; iu <= nbuPoles; iu++) {
112
113 for (iv = 1; iv <= nbvPoles; iv++) {
114 i++;
115 p(i) = Pnt(iu,iv);
116 }
117 }
118
119 GProp_PEquation Pl(p,(Standard_Real)tol);
120 if (Pl.IsPlanar())
121 result = Abs(Pl.Plane().Axis().Direction().Z()) < 0.0001;
122
123 return result;
124}
125
126//=======================================================================
127//function : IsSide
128//purpose :
129//=======================================================================
130
131Standard_Boolean
132HLRBRep_Surface::IsSide (const Standard_Real tolF,
133 const Standard_Real toler) const
134{
135 gp_Pnt Pt;
136 gp_Vec D;
137 Standard_Real r;
138
139 if (myType == GeomAbs_Plane) {
140 gp_Pln Pl = Plane();
141 gp_Ax1 A = Pl.Axis();
142 Pt = A.Location();
143 D = A.Direction();
144 Pt.Transform(((HLRAlgo_Projector*) myProj)->Transformation());
145 D .Transform(((HLRAlgo_Projector*) myProj)->Transformation());
146 if (((HLRAlgo_Projector*) myProj)->Perspective()) {
147 r = D.Z() * ((HLRAlgo_Projector*) myProj)->Focus() -
148 ( D.X() * Pt.X() + D.Y() * Pt.Y() + D.Z() * Pt.Z() );
149 }
150 else r= D.Z();
151 return Abs(r) < toler;
152 }
153 else if (myType == GeomAbs_Cylinder) {
154 if (((HLRAlgo_Projector*) myProj)->Perspective()) return Standard_False;
155 gp_Cylinder Cyl = HLRBRep_BSurfaceTool::Cylinder(mySurf);
156 gp_Ax1 A = Cyl.Axis();
157 D = A.Direction();
158 D .Transform(((HLRAlgo_Projector*) myProj)->Transformation());
159 r = Sqrt(D.X() * D.X() + D.Y() * D.Y());
160 return r < toler;
161 }
162 else if (myType == GeomAbs_Cone) {
163 if (!((HLRAlgo_Projector*) myProj)->Perspective()) return Standard_False;
164 gp_Cone Con = HLRBRep_BSurfaceTool::Cone(mySurf);
165 Pt = Con.Apex();
166 Pt.Transform(((HLRAlgo_Projector*) myProj)->Transformation());
167 Standard_Real tol = 0.001;
168 return Pt.IsEqual(gp_Pnt(0,0,((HLRAlgo_Projector*) myProj)->Focus()),tol);
169 }
170 else if (myType == GeomAbs_BezierSurface) {
171 if (((HLRAlgo_Projector*) myProj)->Perspective()) return Standard_False;
172 Standard_Integer nu = HLRBRep_BSurfaceTool::NbUPoles(mySurf);
173 Standard_Integer nv = HLRBRep_BSurfaceTool::NbVPoles(mySurf);
174 TColgp_Array2OfPnt Pnt(1,nu,1,nv);
175 HLRBRep_BSurfaceTool::Bezier(mySurf)->Poles(Pnt);
176 return SideRowsOfPoles (tolF,nu,nv,Pnt);
177 }
178 else if (myType == GeomAbs_BSplineSurface) {
179 if (((HLRAlgo_Projector*) myProj)->Perspective()) return Standard_False;
180 Standard_Integer nu = HLRBRep_BSurfaceTool::NbUPoles(mySurf);
181 Standard_Integer nv = HLRBRep_BSurfaceTool::NbVPoles(mySurf);
182 TColgp_Array2OfPnt Pnt(1,nu,1,nv);
183 TColStd_Array2OfReal W(1,nu,1,nv);
184 HLRBRep_BSurfaceTool::BSpline(mySurf)->Poles(Pnt);
185 HLRBRep_BSurfaceTool::BSpline(mySurf)->Weights(W);
186 return SideRowsOfPoles (tolF,nu,nv,Pnt);
187 }
188 else return Standard_False;
189}
190
191//=======================================================================
192//function : IsAbove
193//purpose :
194//=======================================================================
195
196Standard_Boolean
197HLRBRep_Surface::IsAbove (const Standard_Boolean back,
198 const Standard_Address A,
199 const Standard_Real tol) const
200{
201 Standard_Boolean planar = (myType == GeomAbs_Plane);
202 if (planar) {
203 gp_Pln Pl = Plane();
204 Standard_Real a,b,c,d;
205 Pl.Coefficients(a,b,c,d);
206 Standard_Real u,u1,u2,dd,x,y,z;
207 gp_Pnt P;
208 u1 = ((HLRBRep_Curve*)A)->Parameter3d
209 (((HLRBRep_Curve*)A)->FirstParameter());
210 u2 = ((HLRBRep_Curve*)A)->Parameter3d
211 (((HLRBRep_Curve*)A)->LastParameter());
212 u=u1;
213 ((HLRBRep_Curve*)A)->D0(u,P);
214 P.Coord(x,y,z);
215 dd = a*x + b*y + c*z + d;
216 if (back) dd = -dd;
217 if (dd < -tol) return Standard_False;
218 if (((HLRBRep_Curve*)A)->GetType() != GeomAbs_Line) {
219 Standard_Integer nbPnt = 30;
220 Standard_Real step = (u2-u1)/(nbPnt+1);
221 for (Standard_Integer i = 1; i <= nbPnt; i++) {
222 u += step;
223 ((HLRBRep_Curve*)A)->D0(u,P);
224 P.Coord(x,y,z);
225 dd = a*x + b*y + c*z + d;
226 if (back) dd = -dd;
227 if (dd < -tol) return Standard_False;
228 }
229 }
230 u = u2;
231 ((HLRBRep_Curve*)A)->D0(u,P);
232 P.Coord(x,y,z);
233 dd = a*x + b*y + c*z + d;
234 if (back) dd = -dd;
235 if (dd < -tol) return Standard_False;
236 return Standard_True;
237 }
238 else return Standard_False;
239}
240
241//=======================================================================
242//function : Value
243//purpose :
244//=======================================================================
245
246gp_Pnt HLRBRep_Surface::Value (const Standard_Real U,
247 const Standard_Real V) const
248{
249 gp_Pnt P;
250 D0(U,V,P);
251 return P;
252}
253
254//=======================================================================
255//function : Plane
256//purpose :
257//=======================================================================
258
259gp_Pln HLRBRep_Surface::Plane () const
260{
261 GeomAbs_SurfaceType typ = HLRBRep_BSurfaceTool::GetType(mySurf);
262 switch (typ) {
263 case GeomAbs_BezierSurface :
264 {
265 gp_Pnt P;
266 gp_Vec D1U;
267 gp_Vec D1V;
268 D1(0.5,0.5,P,D1U,D1V);
269 return gp_Pln(P,gp_Dir(D1U.Crossed(D1V)));
270 }
271
272 default :
273 return HLRBRep_BSurfaceTool::Plane(mySurf);
274 }
275}
276