1 // Created on: 1992-03-13
2 // Created by: Christophe MARION
3 // Copyright (c) 1992-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 #include <BRepAdaptor_Surface.hxx>
19 #include <BRepClass_FaceClassifier.hxx>
20 #include <Geom_BezierSurface.hxx>
21 #include <Geom_BSplineSurface.hxx>
25 #include <GProp_PEquation.hxx>
26 #include <HLRAlgo_Projector.hxx>
27 #include <HLRBRep_BSurfaceTool.hxx>
28 #include <HLRBRep_Curve.hxx>
29 #include <HLRBRep_Surface.hxx>
30 #include <Standard_DomainError.hxx>
31 #include <Standard_NoSuchObject.hxx>
32 #include <Standard_OutOfRange.hxx>
33 #include <TColgp_Array1OfPnt.hxx>
34 #include <TColStd_Array2OfReal.hxx>
35 #include <TopoDS_Face.hxx>
37 //=======================================================================
38 //function : HLRBRep_Surface
40 //=======================================================================
41 HLRBRep_Surface::HLRBRep_Surface ()
45 //=======================================================================
48 //=======================================================================
50 void HLRBRep_Surface::Surface (const TopoDS_Face& F)
52 mySurf.Initialize(F,Standard_False);
53 GeomAbs_SurfaceType typ = HLRBRep_BSurfaceTool::GetType(mySurf);
57 case GeomAbs_Cylinder :
65 case GeomAbs_BezierSurface :
66 if (HLRBRep_BSurfaceTool::UDegree(mySurf) == 1 &&
67 HLRBRep_BSurfaceTool::VDegree(mySurf) == 1) {
68 myType = GeomAbs_Plane;
75 myType = GeomAbs_OtherSurface;
80 //=======================================================================
81 //function : SideRowsOfPoles
83 //=======================================================================
86 HLRBRep_Surface::SideRowsOfPoles (const Standard_Real tol,
87 const Standard_Integer nbuPoles,
88 const Standard_Integer nbvPoles,
89 TColgp_Array2OfPnt& Pnt) const
91 Standard_Integer iu,iv;
92 Standard_Real x0,y0,x,y,z;
93 Standard_Boolean result;
94 Standard_Real tole = (Standard_Real)tol;
95 const gp_Trsf& T = ((HLRAlgo_Projector*) myProj)->Transformation();
97 for (iu = 1; iu <= nbuPoles; iu++) {
99 for (iv = 1; iv <= nbvPoles; iv++)
100 Pnt(iu,iv).Transform(T);
102 result = Standard_True;
104 for (iu = 1; iu <= nbuPoles && result; iu++) { // Side iso u ?
105 Pnt(iu,1).Coord(x0,y0,z);
107 for (iv = 2; iv <= nbvPoles && result; iv++) {
108 Pnt(iu,iv).Coord(x,y,z);
109 result = Abs(x-x0) < tole && Abs(y-y0) < tole;
112 if (result) return result;
113 result = Standard_True;
115 for (iv = 1; iv <= nbvPoles && result; iv++) { // Side iso v ?
116 Pnt(1,iv).Coord(x0,y0,z);
118 for (iu = 2; iu <= nbuPoles && result; iu++) {
119 Pnt(iu,iv).Coord(x,y,z);
120 result = Abs(x-x0) < tole && Abs(y-y0) < tole;
123 if (result) return result;
125 // Are the Poles in a Side Plane ?
126 TColgp_Array1OfPnt p(1,nbuPoles*nbvPoles);
127 Standard_Integer i = 0;
129 for (iu = 1; iu <= nbuPoles; iu++) {
131 for (iv = 1; iv <= nbvPoles; iv++) {
137 GProp_PEquation Pl(p,(Standard_Real)tol);
139 result = Abs(Pl.Plane().Axis().Direction().Z()) < 0.0001;
144 //=======================================================================
147 //=======================================================================
150 HLRBRep_Surface::IsSide (const Standard_Real tolF,
151 const Standard_Real toler) const
157 if (myType == GeomAbs_Plane) {
159 gp_Ax1 A = Pl.Axis();
162 Pt.Transform(((HLRAlgo_Projector*) myProj)->Transformation());
163 D .Transform(((HLRAlgo_Projector*) myProj)->Transformation());
164 if (((HLRAlgo_Projector*) myProj)->Perspective()) {
165 r = D.Z() * ((HLRAlgo_Projector*) myProj)->Focus() -
166 ( D.X() * Pt.X() + D.Y() * Pt.Y() + D.Z() * Pt.Z() );
169 return Abs(r) < toler;
171 else if (myType == GeomAbs_Cylinder) {
172 if (((HLRAlgo_Projector*) myProj)->Perspective()) return Standard_False;
173 gp_Cylinder Cyl = HLRBRep_BSurfaceTool::Cylinder(mySurf);
174 gp_Ax1 A = Cyl.Axis();
176 D .Transform(((HLRAlgo_Projector*) myProj)->Transformation());
177 r = Sqrt(D.X() * D.X() + D.Y() * D.Y());
180 else if (myType == GeomAbs_Cone) {
181 if (!((HLRAlgo_Projector*) myProj)->Perspective()) return Standard_False;
182 gp_Cone Con = HLRBRep_BSurfaceTool::Cone(mySurf);
184 Pt.Transform(((HLRAlgo_Projector*) myProj)->Transformation());
185 Standard_Real tol = 0.001;
186 return Pt.IsEqual(gp_Pnt(0,0,((HLRAlgo_Projector*) myProj)->Focus()),tol);
188 else if (myType == GeomAbs_BezierSurface) {
189 if (((HLRAlgo_Projector*) myProj)->Perspective()) return Standard_False;
190 Standard_Integer nu = HLRBRep_BSurfaceTool::NbUPoles(mySurf);
191 Standard_Integer nv = HLRBRep_BSurfaceTool::NbVPoles(mySurf);
192 TColgp_Array2OfPnt Pnt(1,nu,1,nv);
193 HLRBRep_BSurfaceTool::Bezier(mySurf)->Poles(Pnt);
194 return SideRowsOfPoles (tolF,nu,nv,Pnt);
196 else if (myType == GeomAbs_BSplineSurface) {
197 if (((HLRAlgo_Projector*) myProj)->Perspective()) return Standard_False;
198 Standard_Integer nu = HLRBRep_BSurfaceTool::NbUPoles(mySurf);
199 Standard_Integer nv = HLRBRep_BSurfaceTool::NbVPoles(mySurf);
200 TColgp_Array2OfPnt Pnt(1,nu,1,nv);
201 TColStd_Array2OfReal W(1,nu,1,nv);
202 HLRBRep_BSurfaceTool::BSpline(mySurf)->Poles(Pnt);
203 HLRBRep_BSurfaceTool::BSpline(mySurf)->Weights(W);
204 return SideRowsOfPoles (tolF,nu,nv,Pnt);
206 else return Standard_False;
209 //=======================================================================
212 //=======================================================================
215 HLRBRep_Surface::IsAbove (const Standard_Boolean back,
216 const Standard_Address A,
217 const Standard_Real tol) const
219 Standard_Boolean planar = (myType == GeomAbs_Plane);
222 Standard_Real a,b,c,d;
223 Pl.Coefficients(a,b,c,d);
224 Standard_Real u,u1,u2,dd,x,y,z;
226 u1 = ((HLRBRep_Curve*)A)->Parameter3d
227 (((HLRBRep_Curve*)A)->FirstParameter());
228 u2 = ((HLRBRep_Curve*)A)->Parameter3d
229 (((HLRBRep_Curve*)A)->LastParameter());
231 ((HLRBRep_Curve*)A)->D0(u,P);
233 dd = a*x + b*y + c*z + d;
235 if (dd < -tol) return Standard_False;
236 if (((HLRBRep_Curve*)A)->GetType() != GeomAbs_Line) {
237 Standard_Integer nbPnt = 30;
238 Standard_Real step = (u2-u1)/(nbPnt+1);
239 for (Standard_Integer i = 1; i <= nbPnt; i++) {
241 ((HLRBRep_Curve*)A)->D0(u,P);
243 dd = a*x + b*y + c*z + d;
245 if (dd < -tol) return Standard_False;
249 ((HLRBRep_Curve*)A)->D0(u,P);
251 dd = a*x + b*y + c*z + d;
253 if (dd < -tol) return Standard_False;
254 return Standard_True;
256 else return Standard_False;
259 //=======================================================================
262 //=======================================================================
264 gp_Pnt HLRBRep_Surface::Value (const Standard_Real U,
265 const Standard_Real V) const
272 //=======================================================================
275 //=======================================================================
277 gp_Pln HLRBRep_Surface::Plane () const
279 GeomAbs_SurfaceType typ = HLRBRep_BSurfaceTool::GetType(mySurf);
281 case GeomAbs_BezierSurface :
286 D1(0.5,0.5,P,D1U,D1V);
287 return gp_Pln(P,gp_Dir(D1U.Crossed(D1V)));
291 return HLRBRep_BSurfaceTool::Plane(mySurf);