1 // Created on: 1997-12-24
2 // Created by: Prestataire Xuan PHAM PHU
3 // Copyright (c) 1997-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 <BRep_Tool.hxx>
19 #include <BRepAdaptor_Curve.hxx>
20 #include <BRepAdaptor_Curve2d.hxx>
22 #include <Precision.hxx>
23 #include <Standard_ProgramError.hxx>
25 #include <TopoDS_Shape.hxx>
26 #include <TopOpeBRepDS_CurvePointInterference.hxx>
27 #include <TopOpeBRepDS_define.hxx>
28 #include <TopOpeBRepDS_Edge3dInterferenceTool.hxx>
29 #include <TopOpeBRepDS_EdgeVertexInterference.hxx>
30 #include <TopOpeBRepDS_Interference.hxx>
31 #include <TopOpeBRepTool_EXPORT.hxx>
32 #include <TopOpeBRepTool_TOOL.hxx>
34 #define M_FORWARD(st) (st == TopAbs_FORWARD)
35 #define M_REVERSED(st) (st == TopAbs_REVERSED)
37 static void FUN_Raise()
39 Standard_ProgramError::Raise("Edge3dInterferenceTool");
41 cout <<" ************** Failure in Edge3dInterferenceTool"<<endl;
46 #define VERTEXonref (1)
47 #define VERTEXonOO (2)
48 #define VERTEXonOref (3)
52 // POINT :<Eref> interfers with <E> at a point
53 // <Eref> interfers with <E> at a vertex V,
54 // VERTEXonref : V is on shape of <Eref>
55 // VERTEXonOO : V is on shape of <E>
56 // VERTEXonOref : V is on 2 shapes.
58 // myVonOO : only for VERTEXonOO || VERTEXonOref
61 // myP3d : only for POINT || VERTEXonref
64 static Standard_Boolean FUN_hasparam(const Handle(TopOpeBRepDS_Interference)& I, Standard_Real& paronE)
66 // prequesitory : shapes <SIX> -> edge <E>
67 // ? <paronE> = parameter of <G> on <E>
68 TopOpeBRepDS_Kind GT = I->GeometryType();
69 Standard_Boolean point = (GT == TopOpeBRepDS_POINT);
70 Standard_Boolean vertex = (GT == TopOpeBRepDS_VERTEX);
72 Handle(TopOpeBRepDS_CurvePointInterference) CPI =
73 Handle(TopOpeBRepDS_CurvePointInterference)::DownCast(I);
74 if (CPI.IsNull()) return Standard_False;
75 paronE = CPI->Parameter();
78 Handle(TopOpeBRepDS_EdgeVertexInterference) EVI =
79 Handle(TopOpeBRepDS_EdgeVertexInterference)::DownCast(I);
80 if (EVI.IsNull()) return Standard_False;
81 paronE = EVI->Parameter();
86 static Standard_Boolean FUN_paronOOE
87 (const TopoDS_Edge& OOE,const Standard_Integer IsVertex, const TopoDS_Shape& VonOO, const gp_Pnt& P3d,
88 Standard_Real& paronOOE)
90 Standard_Boolean ok = Standard_False;
91 Standard_Boolean hasVonOO = (IsVertex > 1);
92 if (hasVonOO) ok = FUN_tool_parVonE(TopoDS::Vertex(VonOO),OOE,paronOOE);
94 Standard_Real dist; ok = FUN_tool_projPonE(P3d,OOE,paronOOE,dist);
95 Standard_Real tol1 = BRep_Tool::Tolerance(OOE);
96 Standard_Real tol2 = tol1*1.e3;
97 Standard_Real tol = tol2; if (tol > 1.e-2) tol = 1.e-2;
99 cout<<"$$$$$$$$$$$$$$$$$$$$$$$$ FUN_paronOOE : dist "<<dist<<" tol1 "<<tol1<<endl;
100 cout<<"$$$$$$$$$$$$$$$$$$$$$$$$ FUN_paronOOE : dist "<<dist<<" tol "<<tol<<endl;
102 if (ok) ok = (dist <= tol);
107 static Standard_Boolean FUN_keepIonF
108 (const gp_Vec& tgref, const Standard_Real& parE, const TopoDS_Edge& E, const TopoDS_Face& F,
109 const Standard_Real& tola)
110 // returns true if an interference I=(TonF,G=point/vertex,S=<E>)
111 // is to add to the Edge3dInterferenceTool resolving 3d complex transitions
114 gp_Vec tmp; Standard_Boolean ok = TopOpeBRepTool_TOOL::TggeomE(parE,E,tmp);
115 if (!ok) return Standard_False;
116 gp_Dir tgE = gp_Dir(tmp);
117 Standard_Real prod = Abs(tgref.Dot(tgE));
118 if (Abs(1-prod) < tola) return Standard_False; // <Eref> & <E> are tangent edges
119 gp_Vec dd; ok = FUN_tool_nggeomF(parE,E,F,dd); gp_Dir ngF(dd);
120 if (!ok) return Standard_False;
121 prod = Abs((tgref^tgE).Dot(ngF));
122 if (Abs(1-prod) < tola) return Standard_False;
123 return Standard_True;
126 // ----------------------------------------------------------------------
127 // EDGE/FACE interferences reducing :
129 // ----------------------------------------------------------------------
131 //=======================================================================
132 //function : TopOpeBRepDS_Edge3dInterferenceTool
134 //=======================================================================
136 TopOpeBRepDS_Edge3dInterferenceTool::TopOpeBRepDS_Edge3dInterferenceTool()
137 : myFaceOriented(0),myrefdef(Standard_False)
142 //=======================================================================
143 //function : InitPointVertex
144 //purpose : Initializes reference data for edge/face complex transition
145 //=======================================================================
146 // I = (TonF, G=POINT/VERTEX, S=<E>) interference on <Eref>
147 // G has parameter <paronEref> on <Eref>, <paronE> on <E>
149 void TopOpeBRepDS_Edge3dInterferenceTool::InitPointVertex
150 (const Standard_Integer IsVertex, const TopoDS_Shape& VonOO)
152 myIsVertex = IsVertex;
153 if (IsVertex > 1) myVonOO = VonOO;
156 //=======================================================================
158 //purpose : Initializes reference data for edge/face complex transition
159 //=======================================================================
160 // I = (T on <F>, G=POINT/VERTEX, S=<E>) interference on <Eref>
161 // G has parameter <paronEref> on <Eref>, <paronE> on <E>
162 // -- <E> is edge of <F> --
164 void TopOpeBRepDS_Edge3dInterferenceTool::Init
165 (const TopoDS_Shape& Eref,
166 const TopoDS_Shape& E, const TopoDS_Shape& F,
167 const Handle(TopOpeBRepDS_Interference)& I)
169 const TopoDS_Edge& EEref = TopoDS::Edge(Eref);
170 const TopoDS_Edge& EE = TopoDS::Edge(E);
171 const TopoDS_Face& FF = TopoDS::Face(F);
172 myrefdef = Standard_False;
174 myTole = Precision::Angular(); // NYI
176 Standard_Real pref=0.0; Standard_Boolean ok = ::FUN_hasparam(I, pref);
177 if (!ok) {FUN_Raise(); return;}
180 BRepAdaptor_Curve BC(EEref);
181 myP3d = BC.Value(pref);
183 gp_Vec tmp; ok = TopOpeBRepTool_TOOL::TggeomE(pref,EEref,tmp);
184 if (!ok) {FUN_Raise(); return;}
187 Standard_Real pOO; ok = ::FUN_paronOOE(EE,myIsVertex,myVonOO,myP3d,pOO);
188 if (!ok) {FUN_Raise(); return;}
189 ok = TopOpeBRepTool_TOOL::TggeomE(pOO,EE,tmp);
190 if (!ok) {FUN_Raise(); return;}
193 Standard_Real dot = tgref.Dot(tgOO);
195 Standard_Real tola = Precision::Confusion();
196 Standard_Boolean Esdm = (Abs(dot) < tola);
198 // NYI : il faut rejeter les interf I = (T,G,S=E) / E sdm with Eref
201 ok = ::FUN_keepIonF(tgref,pOO,EE,FF,myTole);
203 // <Eref> is tangent to <F>,
204 // If the transition is FORWARD or REVERSED, it describes a 2d
205 // transition (while crossing <E> on <F>), we do not keep it.
206 const TopAbs_Orientation& O = I->Transition().Orientation(TopAbs_IN);
207 Standard_Boolean is2d = M_FORWARD(O) || M_REVERSED(O);
210 myrefdef = Standard_True;
212 // <myFaceOriented> :
213 myFaceOriented = I->Transition().Index();
218 gp_Dir Norm = tgOO^tgref;
219 myTool.Reset(tgOO, Norm);
223 //=======================================================================
226 //=======================================================================
227 // I = (T on <F>, G=POINT/VERTEX, S=<E>) interference on <Eref>
228 void TopOpeBRepDS_Edge3dInterferenceTool::Add
229 (const TopoDS_Shape& Eref,const TopoDS_Shape& E, const TopoDS_Shape& F,const Handle(TopOpeBRepDS_Interference)& I)
236 if (!myrefdef) return;
238 const TopoDS_Edge& EE = TopoDS::Edge(E);
239 const TopoDS_Face& FF = TopoDS::Face(F);
241 Standard_Real pOO; Standard_Boolean ok = ::FUN_paronOOE(EE,myIsVertex,myVonOO,myP3d,pOO);
245 BRepAdaptor_Curve2d BC2d(EE,FF);
246 uv = BC2d.Value(pOO);
249 ok = ::FUN_keepIonF(myTgtref,pOO,EE,FF,myTole);
251 const TopAbs_Orientation& O = I->Transition().Orientation(TopAbs_IN);
252 Standard_Boolean is2d = M_FORWARD(O) || M_REVERSED(O);
256 TopAbs_Orientation oriloc = I->Transition().Orientation(TopAbs_IN);
257 TopAbs_Orientation oritan; ok = FUN_tool_orientEinFFORWARD(EE, FF, oritan); // xpu : 30/12/97
260 gp_Dir Norm(FUN_tool_nggeomF(uv,FF));
261 myTool.Compare(myTole, Norm, oriloc, oritan);
265 //=======================================================================
266 //function : Transition
268 //=======================================================================
270 void TopOpeBRepDS_Edge3dInterferenceTool::Transition(const Handle(TopOpeBRepDS_Interference)& I) const
272 TopOpeBRepDS_Transition& T = I->ChangeTransition();
273 I->Support(myFaceOriented);
275 TopAbs_State stb = myTool.StateBefore();
276 TopAbs_State sta = myTool.StateAfter();