b311480e |
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 |
5 | // |
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. |
10 | // |
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. |
13 | // |
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. |
20 | |
7fd59977 |
21 | |
22 | #include <TopOpeBRepTool_tol.hxx> |
23 | |
24 | #include <TopoDS.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> |
32 | |
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) |
39 | { |
248622f8 |
40 | Standard_Real aTolF1 = BRep_Tool::Tolerance(myFace1); |
41 | Standard_Real aTolF2 = BRep_Tool::Tolerance(myFace2); |
42 | // |
43 | myTol1 = aTolF1 + aTolF2; |
44 | myTol2 = myTol1; |
45 | |
7fd59977 |
46 | Standard_Real x0,y0,z0,x1,y1,z1,dx,dy,dz; |
47 | Standard_Boolean Box1OK,Box2OK; |
48 | |
49 | if( !B1.IsOpenXmin() && !B1.IsOpenXmax() |
50 | && !B1.IsOpenYmin() && !B1.IsOpenYmax() |
51 | && !B1.IsOpenZmin() && !B1.IsOpenZmax() |
52 | && !B1.IsVoid()) { |
53 | Box1OK=Standard_True; |
54 | } |
55 | else { |
56 | Box1OK=Standard_False; |
57 | } |
58 | |
59 | if( !B2.IsOpenXmin() && !B2.IsOpenXmax() |
60 | && !B2.IsOpenYmin() && !B2.IsOpenYmax() |
61 | && !B2.IsOpenZmin() && !B2.IsOpenZmax() |
62 | && !B2.IsVoid()) { |
63 | Box2OK=Standard_True; |
64 | } |
65 | else { |
66 | Box2OK=Standard_False; |
67 | } |
68 | |
69 | if(Box1OK) { |
70 | B1.Get(x0,y0,z0,x1,y1,z1); |
71 | dx=x1-x0; |
72 | dy=y1-y0; |
73 | dz=z1-z0; |
74 | |
75 | if(Box2OK) { |
76 | B2.Get(x0,y0,z0,x1,y1,z1); |
77 | Standard_Real _dx=x1-x0; |
78 | Standard_Real _dy=y1-y0; |
79 | Standard_Real _dz=z1-z0; |
80 | if(_dx>dx) dx=_dx; |
81 | if(_dy>dy) dy=_dy; |
82 | if(_dz>dz) dz=_dz; |
83 | } |
84 | } |
85 | else { |
86 | if(Box2OK) { |
87 | B2.Get(x0,y0,z0,x1,y1,z1); |
88 | dx=x1-x0; |
89 | dy=y1-y0; |
90 | dz=z1-z0; |
91 | } |
92 | else { |
93 | dx=dy=dz=1.0; |
94 | } |
95 | } |
96 | if(dx<dy) dx=dy; |
97 | if(dx<dz) dx=dz; |
98 | if(dx>1000000.0) dx=1000000.0; //-- if(dx>10000.0) dx=10000.0; |
99 | |
100 | TopExp_Explorer ex; |
101 | Standard_Real tolef1 = Precision::Confusion(); |
102 | for (ex.Init(myFace1,TopAbs_EDGE);ex.More();ex.Next()) { |
103 | Standard_Real tole=BRep_Tool::Tolerance(TopoDS::Edge(ex.Current())); |
104 | if (tole>tolef1) tolef1=tole; |
105 | } |
106 | Standard_Real tolef2 = Precision::Confusion(); |
107 | for (ex.Init(myFace2,TopAbs_EDGE);ex.More();ex.Next()) { |
108 | Standard_Real tole=BRep_Tool::Tolerance(TopoDS::Edge(ex.Current())); |
109 | if (tole>tolef2) tolef2=tole; |
110 | } |
111 | Standard_Real tolef= tolef1; |
112 | if (tolef2>tolef) tolef=tolef2; |
113 | //jmb le 30 juillet 99. on ne multiplie pas la tolerance par la dimension de la piece |
114 | // Standard_Real tolbox = tolef*dx; |
115 | Standard_Real tolbox = tolef; |
7fd59977 |
116 | |
117 | Standard_Real tolmin = Precision::Confusion(); |
7fd59977 |
118 | |
119 | Deflection=0.01; |
120 | MaxUV=0.01; |
121 | Deflection*=dx; |
122 | |
7fd59977 |
123 | Standard_Real MDEFLECTION = Deflection; |
124 | Standard_Real MMAXUV=0.01; |
125 | |
126 | Standard_Real MU0,MU1,MV0,MV1,DP1,DP2,DP; |
127 | MU0=mySurface1.FirstUParameter(); |
128 | MU1=mySurface1.LastUParameter(); |
129 | MV0=mySurface1.FirstVParameter(); |
130 | MV1=mySurface1.LastVParameter(); |
131 | DP1 = MU1-MU0; |
132 | DP2 = MV1-MV0; |
133 | if(DP2<DP1) DP=DP2; else DP=DP1; //-- DP + petit |
134 | |
135 | MU0=mySurface2.FirstUParameter(); |
136 | MU1=mySurface2.LastUParameter(); |
137 | MV0=mySurface2.FirstVParameter(); |
138 | MV1=mySurface2.LastVParameter(); |
139 | DP1 = MU1-MU0; |
140 | DP2 = MV1-MV0; |
141 | if(DP2>DP1) DP1=DP2; //-- DP1 + petit |
142 | if(DP1<DP) DP=DP1; //-- DP + petit |
143 | |
144 | DP*=0.01; |
145 | //jmb le 30 juillet 99 |
146 | // non ! laisser MMAXUV a 0.01 |
147 | // MMAXUV=DP; |
148 | |
149 | #ifdef DEB |
150 | // printf("\n FaceTolerances3d : TOL1 = %5.5eg TOL2=%5.5eg DEFL=%5.5eg MAXUV=%5.5eg\n",MTOL1,MTOL2,MDEFLECTION,0.01); |
151 | #endif |
152 | |
7fd59977 |
153 | if(MMAXUV<1e-3) MMAXUV=1e-3; |
154 | if(MDEFLECTION<1e-3) MDEFLECTION = 1e-3; |
155 | |
7fd59977 |
156 | if(MMAXUV>0.01) MMAXUV=0.01; |
157 | if(MDEFLECTION>0.1) MDEFLECTION = 0.1; |
158 | |
159 | #ifdef DEB |
160 | // printf("TOL1 = %5.5eg TOL2=%5.5eg DEFL=%5.5eg MAXUV=%5.5eg\n",MTOL1,MTOL2,MDEFLECTION,MMAXUV); |
161 | #endif |
162 | |
7fd59977 |
163 | Deflection = MDEFLECTION; |
164 | MaxUV = MMAXUV; |
7fd59977 |
165 | } // FTOL_FaceTolerances |
166 | |
167 | Standard_EXPORT void FTOL_FaceTolerances3d |
168 | (const TopoDS_Face& myFace1, |
169 | const TopoDS_Face& myFace2, |
170 | Standard_Real& Tol) |
171 | { |
172 | const Handle(TopOpeBRepTool_HBoxTool)& hbt = FBOX_GetHBoxTool(); |
173 | Bnd_Box B1, B2; |
174 | if(hbt->HasBox(myFace1)) { |
175 | B1 = hbt->Box(myFace1); |
176 | } |
177 | else { |
178 | B1.Update(0., 0., 0., 1., 1., 1.); |
179 | } |
180 | if(hbt->HasBox(myFace2)) { |
181 | B2 = hbt->Box(myFace2); |
182 | } |
183 | else { |
184 | B2.Update(0., 0., 0., 1., 1., 1.); |
185 | } |
186 | BRepAdaptor_Surface mySurface1; |
187 | BRepAdaptor_Surface mySurface2; |
188 | mySurface1.Initialize(myFace1); |
189 | mySurface2.Initialize(myFace2); |
190 | Standard_Real Deflection=0.01,MaxUV=0.01; |
191 | Standard_Real myTol1,myTol2; |
192 | FTOL_FaceTolerances(B1,B2, |
193 | myFace1,myFace2, |
194 | mySurface1,mySurface2, |
195 | myTol1,myTol2,Deflection,MaxUV); |
196 | myTol1 = (myTol1 > 1.e-4)? 1.e-4: myTol1; |
197 | myTol2 = (myTol2 > 1.e-4)? 1.e-4: myTol2; |
198 | Tol = Max(myTol1,myTol2); |
199 | } |
200 | |
201 | Standard_EXPORT void FTOL_FaceTolerances3d |
202 | (const Bnd_Box& B1, const Bnd_Box& B2, |
203 | const TopoDS_Face& myFace1, const TopoDS_Face& myFace2, |
204 | const BRepAdaptor_Surface& mySurface1, const BRepAdaptor_Surface& mySurface2, |
205 | Standard_Real& myTol1, Standard_Real& myTol2, |
206 | Standard_Real& Deflection, Standard_Real& MaxUV) |
207 | { |
208 | FTOL_FaceTolerances(B1,B2, |
209 | myFace1,myFace2, |
210 | mySurface1,mySurface2, |
211 | myTol1,myTol2, |
212 | Deflection,MaxUV); |
213 | } |
214 | |
215 | Standard_EXPORT void FTOL_FaceTolerances2d |
216 | (const Bnd_Box& B1, |
217 | const Bnd_Box& B2, |
218 | const TopoDS_Face& myFace1, |
219 | const TopoDS_Face& myFace2, |
220 | const BRepAdaptor_Surface& mySurface1, |
221 | const BRepAdaptor_Surface& mySurface2, |
222 | Standard_Real& myTol1, Standard_Real& myTol2) |
223 | { |
224 | Standard_Real BIDDeflection,BIDMaxUV; |
225 | FTOL_FaceTolerances(B1,B2, |
226 | myFace1,myFace2, |
227 | mySurface1,mySurface2, |
228 | myTol1,myTol2, |
229 | BIDDeflection,BIDMaxUV); |
230 | } |