b311480e |
1 | // Created on: 1997-11-10 |
2 | // Created by: Jean Yves LEBEY |
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 <TopOpeBRepDS_define.hxx> |
18 | |
19 | #include <gp_Pnt2d.hxx> |
20 | #include <TopOpeBRepDS_ProcessInterferencesTool.hxx> |
21 | #include <TopOpeBRepDS_FaceEdgeInterference.hxx> |
22 | #include <TopOpeBRepDS_FaceInterferenceTool.hxx> |
23 | #include <TopoDS.hxx> |
24 | #include <TopExp.hxx> |
25 | #include <TopExp_Explorer.hxx> |
26 | #include <TColStd_DataMapIteratorOfDataMapOfIntegerListOfInteger.hxx> |
27 | #include <TColStd_DataMapOfIntegerListOfInteger.hxx> |
28 | #include <TColStd_ListIteratorOfListOfInteger.hxx> |
29 | #include <TColStd_ListOfInteger.hxx> |
30 | #include <TopOpeBRepTool_ShapeTool.hxx> |
31 | #include <BRepAdaptor_Curve.hxx> |
32 | #include <BRepAdaptor_Surface.hxx> |
33 | #include <BRep_Builder.hxx> |
34 | #include <BRep_Tool.hxx> |
35 | #include <BRepClass3d_SolidClassifier.hxx> |
36 | #include <TopoDS_Shell.hxx> |
37 | #include <TopoDS_Solid.hxx> |
38 | #include <gp_Vec.hxx> |
39 | #include <Precision.hxx> |
40 | #include <TopOpeBRepDS_FaceEdgeInterference.hxx> |
41 | #include <TopOpeBRepTool_EXPORT.hxx> |
42 | #include <TopOpeBRepTool_SC.hxx> |
43 | #include <TopOpeBRepTool_box.hxx> |
44 | #include <TopOpeBRepTool_tol.hxx> |
45 | #include <Geom_Curve.hxx> |
46 | #include <Geom_Surface.hxx> |
47 | #include <GeomAPI_ProjectPointOnSurf.hxx> |
48 | #include <BRepTools.hxx> |
49 | #include <GeomProjLib.hxx> |
50 | #include <Geom2d_Curve.hxx> |
51 | #include <ProjLib_ProjectedCurve.hxx> |
52 | #include <Geom_Surface.hxx> |
53 | #include <BRepAdaptor_Surface.hxx> |
54 | #include <BRepAdaptor_Curve.hxx> |
55 | #include <BRepAdaptor_HSurface.hxx> |
56 | #include <BRepAdaptor_HCurve.hxx> |
57 | #include <GeomAdaptor_Curve.hxx> |
58 | #include <GeomAdaptor_HCurve.hxx> |
59 | |
60 | Standard_EXPORT Handle(Geom2d_Curve) MakePCurve(const ProjLib_ProjectedCurve& PC); |
61 | |
62 | static TopAbs_State FUN_staPinF3d(const gp_Pnt& P, const TopoDS_Face& F) |
63 | // prequesitory : the compute of state(P,3dmatter of F) |
64 | // - solid classifier - |
65 | { |
66 | TopAbs_State st = TopAbs_UNKNOWN; |
67 | gp_Pnt2d UV; Standard_Real d = 1.e2; Standard_Boolean ok = FUN_tool_projPonboundedF(P,F,UV,d); |
68 | if (!ok) return st; |
69 | Standard_Real tolF = BRep_Tool::Tolerance(F); |
70 | if (d < tolF) return TopAbs_IN; // TopAbs_ON; |
71 | gp_Pnt pF; FUN_tool_value(UV,F,pF); |
72 | gp_Dir ntF = FUN_tool_nggeomF(UV,F); |
73 | if (F.Orientation() == TopAbs_REVERSED) ntF.Reverse(); |
74 | gp_Dir PpF(gp_Vec(P,pF)); |
75 | Standard_Real dot = ntF.Dot(PpF); |
76 | st = (dot > 0) ? TopAbs_IN : TopAbs_OUT; |
77 | return st; |
78 | } |
79 | |
80 | Standard_EXPORT void FUN_UNKFstasta(const TopoDS_Face& FF,const TopoDS_Face& FS, |
81 | const TopoDS_Edge& EE,const Standard_Boolean EEofFF, |
82 | TopAbs_State& stateb,TopAbs_State& statea, |
83 | TopOpeBRepTool_PShapeClassifier pClassif) |
84 | { |
85 | BRep_Builder BB; |
86 | |
87 | stateb = statea = TopAbs_UNKNOWN; |
88 | Standard_Real fE,lE; Handle(Geom_Curve) CEE = BRep_Tool::Curve(EE,fE,lE); |
89 | |
90 | if (CEE.IsNull()) return; // NYI : get points from 2d curve |
91 | Handle(Geom_Surface) SFF = BRep_Tool::Surface(FF); |
92 | |
93 | Standard_Real ttE = 0.41237118973; Standard_Real parE = (1-ttE)*fE + ttE*lE; |
94 | gp_Pnt PE;gp_Vec VE;CEE->D1(parE,PE,VE); |
95 | |
96 | GeomAPI_ProjectPointOnSurf PonS(PE,SFF); |
97 | if (!PonS.Extrema().IsDone()) return; |
98 | if (PonS.NbPoints() == 0) return; |
99 | |
100 | Standard_Real u,v; PonS.Parameters(1,u,v); |
101 | gp_Vec d1u,d1v;gp_Pnt puv; SFF->D1(u,v,puv,d1u,d1v); |
102 | gp_Vec N = d1u.Crossed(d1v); |
103 | Standard_Real FUMin,FUMax,FVMin,FVMax; |
104 | |
105 | // les bornes de FF |
106 | BRepTools::UVBounds(FF,FUMin,FUMax,FVMin,FVMax); |
107 | |
108 | // les bornes de EE dans FF |
109 | Standard_Real EUMin,EUMax,EVMin,EVMax; |
110 | if (EEofFF) { |
111 | BRepTools::UVBounds(FF,EE,EUMin,EUMax,EVMin,EVMax); |
112 | } |
113 | else { // EE n'est pas une arete de FF => EE est une arete de FS |
114 | Handle(Geom2d_Curve) CEEFFx; |
115 | if (CEE.IsNull()) { |
116 | Standard_Boolean compminmaxUV = Standard_False; |
117 | BRepAdaptor_Surface BAS(FS,compminmaxUV); |
118 | Handle(BRepAdaptor_HSurface) BAHS = new BRepAdaptor_HSurface(BAS); |
119 | BRepAdaptor_Curve AC(EE,FS); |
120 | Handle(BRepAdaptor_HCurve) AHC = new BRepAdaptor_HCurve(AC); |
121 | Standard_Real tolin; FTOL_FaceTolerances3d(FF,FS,tolin); |
122 | ProjLib_ProjectedCurve projcurv(BAHS,AHC,tolin); |
123 | CEEFFx = MakePCurve(projcurv); |
124 | } |
125 | else { |
126 | // modified by NIZHNY-MKK Mon Apr 2 15:41:01 2001.BEGIN |
127 | TopExp_Explorer anExp(FF, TopAbs_EDGE); |
128 | for(; anExp.More(); anExp.Next()) { |
129 | if(EE.IsSame(anExp.Current())) { |
130 | CEEFFx = BRep_Tool::CurveOnSurface(EE, FF, fE, lE); |
131 | } |
132 | } |
133 | if(CEEFFx.IsNull()) { |
134 | // modified by NIZHNY-MKK Mon Apr 2 15:41:16 2001.END |
135 | |
136 | CEEFFx = GeomProjLib::Curve2d(CEE,fE,lE,SFF); |
137 | |
138 | // modified by NIZHNY-MKK Mon Apr 2 15:41:26 2001.BEGIN |
139 | } |
140 | // modified by NIZHNY-MKK Mon Apr 2 15:41:31 2001.END |
141 | } |
142 | if (CEEFFx.IsNull()) return; |
143 | |
144 | TopoDS_Edge EEx; BB.MakeEdge(EEx,CEE,BRep_Tool::Tolerance(EE)); |
145 | TopoDS_Vertex vf,vr; TopExp::Vertices(EE,vf,vr); |
146 | BB.Add(EEx,vf); BB.UpdateVertex(vf,fE,EEx,BRep_Tool::Tolerance(vf)); |
147 | BB.Add(EEx,vr); BB.UpdateVertex(vr,lE,EEx,BRep_Tool::Tolerance(vr)); |
148 | |
149 | TopoDS_Face FFx; BB.MakeFace(FFx,SFF,BRep_Tool::Tolerance(FF)); |
150 | BB.UpdateEdge(EEx,CEEFFx,FFx,BRep_Tool::Tolerance(FF)); |
151 | BRepTools::UVBounds(FFx,EEx,EUMin,EUMax,EVMin,EVMax); |
152 | } |
153 | |
154 | // Standard_Boolean EisoU = (abs(EVMax-EVMin) < Precision::Confusion()); |
155 | Standard_Boolean EisoU = (fabs(EVMax-EVMin) < Precision::Confusion()); |
156 | // Standard_Boolean EisoV = (abs(EUMax-EUMin) < Precision::Confusion()); |
157 | Standard_Boolean EisoV = (fabs(EUMax-EUMin) < Precision::Confusion()); |
158 | // xpu161098 : bad analysis : we should choose smaller factor |
159 | // cto009C1 (FF3,FS10,EG9) |
160 | Standard_Real ttu = 1.e-2; //Standard_Real ttu = 0.1; |
161 | Standard_Real paru = fabs(ttu*(FUMax-FUMin)); |
162 | Standard_Real ttv = 1.e-2;//Standard_Real ttv = 0.1; |
163 | Standard_Real parv = fabs(ttv*(FVMax-FVMin)); |
164 | |
165 | Standard_Real up = u; Standard_Real vp = v; |
166 | if ( EisoV ) up += paru; |
167 | else if ( EisoU ) vp += parv; |
168 | else { up += paru; vp += parv; } |
169 | gp_Pnt Pb; SFF->D0(up,vp,Pb); |
170 | |
171 | Standard_Real um = u; Standard_Real vm = v; |
172 | if ( EisoV ) um -= paru; |
173 | else if ( EisoU ) vm -= parv; |
174 | else { um -= paru; vm -= parv; } |
175 | gp_Pnt Pa; SFF->D0(um,vm,Pa); |
176 | |
177 | Standard_Boolean permute = Standard_False; |
178 | Standard_Real dot; |
179 | gp_Vec VEcroN = VE.Crossed(N); |
180 | if ( EisoV ) { |
181 | dot = VEcroN.Dot(d1u); |
182 | if ( dot < 0.) permute = Standard_True; |
183 | } |
184 | else if ( EisoU ) { |
185 | dot = VEcroN.Dot(d1v); |
186 | if ( dot < 0.) permute = Standard_True; |
187 | } |
188 | else { |
189 | dot = VEcroN.Dot(d1v); |
190 | if ( dot < 0.) permute = Standard_True; |
191 | } |
192 | if (permute) { |
193 | gp_Pnt P; |
194 | P = Pa; |
195 | Pa = Pb; |
196 | Pb = P; |
197 | } |
198 | |
199 | if (pClassif) { |
200 | // xpu151098 : evolution solid classifier (ex cto009H1) |
201 | // MSV : made it! |
202 | pClassif->StateP3DReference(Pb); |
203 | stateb = pClassif->State(); |
204 | pClassif->StateP3DReference(Pa); |
205 | statea = pClassif->State(); |
206 | } |
207 | else { |
208 | stateb = ::FUN_staPinF3d(Pb,FS); |
209 | statea = ::FUN_staPinF3d(Pa,FS); |
210 | } |
211 | } |