1 // Created on: 1996-04-02
2 // Created by: Jacques GOUSSARD
3 // Copyright (c) 1996-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
9 // under the terms of the GNU Lesser General Public 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.
19 #include <TopExp_Explorer.hxx>
20 #include <BRep_Tool.hxx>
21 #include <BRep_Builder.hxx>
22 #include <Geom2d_Curve.hxx>
23 #include <gp_Pnt2d.hxx>
24 #include <BRepAdaptor_Curve2d.hxx>
25 #include <BRepAdaptor_HSurface.hxx>
26 #include <BRepAdaptor_HCurve2d.hxx>
27 #include <Geom2dInt_GInter.hxx>
28 #include <Geom_Curve.hxx>
30 #include <TopTools_MapOfShape.hxx>
34 #include <TopoDS_Vertex.hxx>
35 #include <Precision.hxx>
40 //=======================================================================
43 //=======================================================================
45 Standard_Boolean LocOpe::Closed(const TopoDS_Wire& W,
49 TopExp::Vertices(W,Vf,Vl);
51 return Standard_False;
54 // On recherche l`edge contenant Vf FORWARD
56 TopExp_Explorer exp,exp2;
57 for (exp.Init(W.Oriented(TopAbs_FORWARD),TopAbs_EDGE);
58 exp.More();exp.Next()) {
59 for (exp2.Init(exp.Current(),TopAbs_VERTEX);exp2.More();exp2.Next()) {
60 if (exp2.Current().IsSame(Vf) &&
61 exp2.Current().Orientation() == TopAbs_FORWARD) {
69 TopoDS_Edge Ef = TopoDS::Edge(exp.Current());
71 // On recherche l`edge contenant Vl REVERSED
73 for (exp.Init(W.Oriented(TopAbs_FORWARD),TopAbs_EDGE);
74 exp.More();exp.Next()) {
75 for (exp2.Init(exp.Current(),TopAbs_VERTEX);exp2.More();exp2.Next()) {
76 if (exp2.Current().IsSame(Vl) &&
77 exp2.Current().Orientation() == TopAbs_REVERSED) {
85 TopoDS_Edge El = TopoDS::Edge(exp.Current());
89 Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(Ef,F,f,l);
90 if (Ef.Orientation() == TopAbs_FORWARD) {
96 C2d = BRep_Tool::CurveOnSurface(El,F,f,l);
97 if (El.Orientation() == TopAbs_FORWARD) {
104 if (pf.Distance(pl) <= Precision::PConfusion(Precision::Confusion())) {
105 return Standard_True;
107 return Standard_False;
111 //=======================================================================
114 //=======================================================================
116 Standard_Boolean LocOpe::Closed(const TopoDS_Edge& E,
117 const TopoDS_Face& F)
122 B.Add(W,E.Oriented(TopAbs_FORWARD));
123 return LocOpe::Closed(W,F);
128 //=======================================================================
131 //=======================================================================
133 Standard_Boolean LocOpe::TgtFaces(const TopoDS_Edge& E,
134 const TopoDS_Face& F1,
135 const TopoDS_Face& F2)
137 BRepAdaptor_Surface bs(F1, Standard_False);
139 Standard_Real ta = 0.0001;
143 Handle(BRepAdaptor_HSurface) HS1 = new BRepAdaptor_HSurface(F1);
144 Handle(BRepAdaptor_HSurface) HS2 = new BRepAdaptor_HSurface(F2);
145 e.Orientation(TopAbs_FORWARD);
146 Handle(BRepAdaptor_HCurve2d) HC2d = new BRepAdaptor_HCurve2d();
147 Handle(BRepAdaptor_HCurve2d) HC2d2 = new BRepAdaptor_HCurve2d();
148 HC2d->ChangeCurve2d().Initialize(e,F1);
149 HC2d2->ChangeCurve2d().Initialize(e,F2);
152 // Adaptor3d_CurveOnSurface C1(HC2d,HS1);
154 Standard_Boolean rev1 = (F1.Orientation() == TopAbs_REVERSED);
155 Standard_Boolean rev2 = (F2.Orientation() == TopAbs_REVERSED);
156 Standard_Real f,l,eps,angmin = M_PI,angmax = -M_PI,ang;
157 BRep_Tool::Range(e,f,l);
160 f += eps; // pour eviter de faire des calculs sur les
161 l -= eps; // pointes des carreaux pointus.
167 Standard_Real uu, vv;
168 Standard_Real angle[21];
171 for(i = 0; i <= 20; i++){
174 HS1->D1(p.X(),p.Y(),pp1,du,dv);
175 d1 = (du.Crossed(dv)).Normalized();
176 if(rev1) d1.Reverse();
179 HS2->D1(uu,vv,pp1,du,dv);
180 d2 = (du.Crossed(dv)).Normalized();
181 if(rev2) d2.Reverse();
184 if(ang <= angmin) angmin = ang;
185 if(ang >= angmax) angmax = ang;
191 //=======================================================================
192 //function : SampleEdges
194 //=======================================================================
196 void LocOpe::SampleEdges(const TopoDS_Shape& theShape,
197 TColgp_SequenceOfPnt& theSeq)
200 TopTools_MapOfShape theMap;
202 TopExp_Explorer exp(theShape,TopAbs_EDGE);
204 Handle(Geom_Curve) C;
205 Standard_Real f,l,prm;
208 // Computes points on edge, but does not take the extremities into account
209 for (; exp.More(); exp.Next()) {
210 const TopoDS_Edge& edg = TopoDS::Edge(exp.Current());
211 if (!theMap.Add(edg)) {
214 if (!BRep_Tool::Degenerated(edg)) {
215 C = BRep_Tool::Curve(edg,Loc,f,l);
216 C = Handle(Geom_Curve)::
217 DownCast(C->Transformed(Loc.Transformation()));
218 Standard_Real delta = (l - f)/NECHANT*0.123456;
219 for (i=1; i<NECHANT; i++) {
220 prm = delta + ((NECHANT-i)*f+i*l)/NECHANT;
221 theSeq.Append(C->Value(prm));
227 for (exp.Init(theShape,TopAbs_VERTEX); exp.More(); exp.Next()) {
228 if (theMap.Add(exp.Current())) {
229 theSeq.Append(BRep_Tool::Pnt(TopoDS::Vertex(exp.Current())));
239 Standard_Boolean LocOpe::IsInside(const TopoDS_Face& F1,
240 const TopoDS_Face& F2)
242 Standard_Boolean Result = Standard_True;
244 TopExp_Explorer exp1, exp2;
246 for(exp1.Init(F1, TopAbs_EDGE); exp1.More(); exp1.Next()) {
247 TopoDS_Edge e1 = TopoDS::Edge(exp1.Current());
248 BRepAdaptor_Curve2d C1(e1, F1);
249 for(exp2.Init(F2, TopAbs_EDGE); exp2.More(); exp2.Next()) {
250 TopoDS_Edge e2 = TopoDS::Edge(exp2.Current());
251 BRepAdaptor_Curve2d C2(e2, F2);
253 C.Perform(C1, C2, Precision::Confusion(), Precision::Confusion());
254 if(!C.IsEmpty()) Result = Standard_False;
255 if(Result == Standard_False) {
256 for(exp3.Init(e2, TopAbs_VERTEX); exp3.More(); exp3.Next()) {
261 if(Result == Standard_False) break;