1 // Created on: 1997-04-01
2 // Created by: Jean Yves LEBEY
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
22 #include <TopOpeBRepTool_tol.hxx>
25 #include <TopExp_Explorer.hxx>
26 #include <Precision.hxx>
27 #include <BRep_Tool.hxx>
28 #include <TopOpeBRepTool_HBoxTool.hxx>
29 #include <Bnd_Box.hxx>
30 #include <TopOpeBRepTool_box.hxx>
31 #include <TopOpeBRepTool_define.hxx>
33 Standard_EXPORT void FTOL_FaceTolerances
34 (const Bnd_Box& B1, const Bnd_Box& B2,
35 const TopoDS_Face& myFace1, const TopoDS_Face& myFace2,
36 const BRepAdaptor_Surface& mySurface1, const BRepAdaptor_Surface& mySurface2,
37 Standard_Real& myTol1, Standard_Real& myTol2,
38 Standard_Real& Deflection, Standard_Real& MaxUV)
40 // ============================================================
41 // == t o l e r a n c e s d I n t e r s e c t i o n ==
42 // ============================================================
43 Standard_Real x0,y0,z0,x1,y1,z1,dx,dy,dz;
44 Standard_Boolean Box1OK,Box2OK;
46 if( !B1.IsOpenXmin() && !B1.IsOpenXmax()
47 && !B1.IsOpenYmin() && !B1.IsOpenYmax()
48 && !B1.IsOpenZmin() && !B1.IsOpenZmax()
53 Box1OK=Standard_False;
56 if( !B2.IsOpenXmin() && !B2.IsOpenXmax()
57 && !B2.IsOpenYmin() && !B2.IsOpenYmax()
58 && !B2.IsOpenZmin() && !B2.IsOpenZmax()
63 Box2OK=Standard_False;
67 B1.Get(x0,y0,z0,x1,y1,z1);
73 B2.Get(x0,y0,z0,x1,y1,z1);
74 Standard_Real _dx=x1-x0;
75 Standard_Real _dy=y1-y0;
76 Standard_Real _dz=z1-z0;
84 B2.Get(x0,y0,z0,x1,y1,z1);
95 if(dx>1000000.0) dx=1000000.0; //-- if(dx>10000.0) dx=10000.0;
98 Standard_Real tolef1 = Precision::Confusion();
99 for (ex.Init(myFace1,TopAbs_EDGE);ex.More();ex.Next()) {
100 Standard_Real tole=BRep_Tool::Tolerance(TopoDS::Edge(ex.Current()));
101 if (tole>tolef1) tolef1=tole;
103 Standard_Real tolef2 = Precision::Confusion();
104 for (ex.Init(myFace2,TopAbs_EDGE);ex.More();ex.Next()) {
105 Standard_Real tole=BRep_Tool::Tolerance(TopoDS::Edge(ex.Current()));
106 if (tole>tolef2) tolef2=tole;
108 Standard_Real tolef= tolef1;
109 if (tolef2>tolef) tolef=tolef2;
110 //jmb le 30 juillet 99. on ne multiplie pas la tolerance par la dimension de la piece
111 // Standard_Real tolbox = tolef*dx;
112 Standard_Real tolbox = tolef;
116 Standard_Real tolmin = Precision::Confusion();
117 if (tolmin>myTol1) myTol1 = tolmin;
118 if (tolmin>myTol2) myTol2 = tolmin;
124 Standard_Real MTOL1 = Max(myTol1,1e-8);
125 Standard_Real MTOL2 = Max(myTol2,1e-8);
126 Standard_Real MDEFLECTION = Deflection;
127 Standard_Real MMAXUV=0.01;
129 Standard_Real MU0,MU1,MV0,MV1,DP1,DP2,DP;
130 MU0=mySurface1.FirstUParameter();
131 MU1=mySurface1.LastUParameter();
132 MV0=mySurface1.FirstVParameter();
133 MV1=mySurface1.LastVParameter();
136 if(DP2<DP1) DP=DP2; else DP=DP1; //-- DP + petit
138 MU0=mySurface2.FirstUParameter();
139 MU1=mySurface2.LastUParameter();
140 MV0=mySurface2.FirstVParameter();
141 MV1=mySurface2.LastVParameter();
144 if(DP2>DP1) DP1=DP2; //-- DP1 + petit
145 if(DP1<DP) DP=DP1; //-- DP + petit
148 //jmb le 30 juillet 99
149 // non ! laisser MMAXUV a 0.01
153 // printf("\n FaceTolerances3d : TOL1 = %5.5eg TOL2=%5.5eg DEFL=%5.5eg MAXUV=%5.5eg\n",MTOL1,MTOL2,MDEFLECTION,0.01);
156 if(MTOL1>1e-4*dx) MTOL1=1e-4*dx;
157 if(MTOL2>1e-4*dx) MTOL2=1e-4*dx;
158 if(MTOL1<1e-8) MTOL1=1e-8;
159 if(MTOL2<1e-8) MTOL2=1e-8;
160 if(MMAXUV<1e-3) MMAXUV=1e-3;
161 if(MDEFLECTION<1e-3) MDEFLECTION = 1e-3;
163 if(MTOL1>0.5) MTOL1=0.5;
164 if(MTOL2>0.5) MTOL2=0.5;
165 if(MMAXUV>0.01) MMAXUV=0.01;
166 if(MDEFLECTION>0.1) MDEFLECTION = 0.1;
169 // printf("TOL1 = %5.5eg TOL2=%5.5eg DEFL=%5.5eg MAXUV=%5.5eg\n",MTOL1,MTOL2,MDEFLECTION,MMAXUV);
174 Deflection = MDEFLECTION;
177 } // FTOL_FaceTolerances
179 Standard_EXPORT void FTOL_FaceTolerances3d
180 (const TopoDS_Face& myFace1,
181 const TopoDS_Face& myFace2,
184 const Handle(TopOpeBRepTool_HBoxTool)& hbt = FBOX_GetHBoxTool();
186 if(hbt->HasBox(myFace1)) {
187 B1 = hbt->Box(myFace1);
190 B1.Update(0., 0., 0., 1., 1., 1.);
192 if(hbt->HasBox(myFace2)) {
193 B2 = hbt->Box(myFace2);
196 B2.Update(0., 0., 0., 1., 1., 1.);
198 BRepAdaptor_Surface mySurface1;
199 BRepAdaptor_Surface mySurface2;
200 mySurface1.Initialize(myFace1);
201 mySurface2.Initialize(myFace2);
202 Standard_Real Deflection=0.01,MaxUV=0.01;
203 Standard_Real myTol1,myTol2;
204 FTOL_FaceTolerances(B1,B2,
206 mySurface1,mySurface2,
207 myTol1,myTol2,Deflection,MaxUV);
208 myTol1 = (myTol1 > 1.e-4)? 1.e-4: myTol1;
209 myTol2 = (myTol2 > 1.e-4)? 1.e-4: myTol2;
210 Tol = Max(myTol1,myTol2);
213 Standard_EXPORT void FTOL_FaceTolerances3d
214 (const Bnd_Box& B1, const Bnd_Box& B2,
215 const TopoDS_Face& myFace1, const TopoDS_Face& myFace2,
216 const BRepAdaptor_Surface& mySurface1, const BRepAdaptor_Surface& mySurface2,
217 Standard_Real& myTol1, Standard_Real& myTol2,
218 Standard_Real& Deflection, Standard_Real& MaxUV)
220 FTOL_FaceTolerances(B1,B2,
222 mySurface1,mySurface2,
227 Standard_EXPORT void FTOL_FaceTolerances2d
230 const TopoDS_Face& myFace1,
231 const TopoDS_Face& myFace2,
232 const BRepAdaptor_Surface& mySurface1,
233 const BRepAdaptor_Surface& mySurface2,
234 Standard_Real& myTol1, Standard_Real& myTol2)
236 Standard_Real BIDDeflection,BIDMaxUV;
237 FTOL_FaceTolerances(B1,B2,
239 mySurface1,mySurface2,
241 BIDDeflection,BIDMaxUV);