0024510: Remove unused local variables
[occt.git] / src / LocOpe / LocOpe.cxx
CommitLineData
b311480e 1// Created on: 1996-04-02
2// Created by: Jacques GOUSSARD
3// Copyright (c) 1996-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//
973c2be1 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.
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 <LocOpe.ixx>
18
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>
29
30#include <TopTools_MapOfShape.hxx>
31
32#include <TopExp.hxx>
33#include <TopoDS.hxx>
34#include <TopoDS_Vertex.hxx>
35#include <Precision.hxx>
36
37#define NECHANT 10
38
39
40//=======================================================================
41//function : Closed
42//purpose :
43//=======================================================================
44
45Standard_Boolean LocOpe::Closed(const TopoDS_Wire& W,
46 const TopoDS_Face& F)
47{
48 TopoDS_Vertex Vf,Vl;
49 TopExp::Vertices(W,Vf,Vl);
50 if (!Vf.IsSame(Vl)) {
51 return Standard_False;
52 }
53
54 // On recherche l`edge contenant Vf FORWARD
55
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) {
62 break;
63 }
64 }
65 if (exp2.More()) {
66 break;
67 }
68 }
69 TopoDS_Edge Ef = TopoDS::Edge(exp.Current());
70
71 // On recherche l`edge contenant Vl REVERSED
72
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) {
78 break;
79 }
80 }
81 if (exp2.More()) {
82 break;
83 }
84 }
85 TopoDS_Edge El = TopoDS::Edge(exp.Current());
86
87 Standard_Real f,l;
88 gp_Pnt2d pf,pl;
89 Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(Ef,F,f,l);
90 if (Ef.Orientation() == TopAbs_FORWARD) {
91 pf = C2d->Value(f);
92 }
93 else {
94 pf = C2d->Value(l);
95 }
96 C2d = BRep_Tool::CurveOnSurface(El,F,f,l);
97 if (El.Orientation() == TopAbs_FORWARD) {
98 pl = C2d->Value(l);
99 }
100 else {
101 pl = C2d->Value(f);
102 }
103
104 if (pf.Distance(pl) <= Precision::PConfusion(Precision::Confusion())) {
105 return Standard_True;
106 }
107 return Standard_False;
108}
109
110
111//=======================================================================
112//function : Closed
113//purpose :
114//=======================================================================
115
116Standard_Boolean LocOpe::Closed(const TopoDS_Edge& E,
117 const TopoDS_Face& F)
118{
119 BRep_Builder B;
120 TopoDS_Wire W;
121 B.MakeWire(W);
122 B.Add(W,E.Oriented(TopAbs_FORWARD));
123 return LocOpe::Closed(W,F);
124}
125
126
127
128//=======================================================================
129//function : Closed
130//purpose :
131//=======================================================================
132
133Standard_Boolean LocOpe::TgtFaces(const TopoDS_Edge& E,
134 const TopoDS_Face& F1,
135 const TopoDS_Face& F2)
136{
137 BRepAdaptor_Surface bs(F1, Standard_False);
138 Standard_Real u;
139 Standard_Real ta = 0.0001;
140
141 TopoDS_Edge e = E;
142
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);
150
151
152// Adaptor3d_CurveOnSurface C1(HC2d,HS1);
153
154 Standard_Boolean rev1 = (F1.Orientation() == TopAbs_REVERSED);
155 Standard_Boolean rev2 = (F2.Orientation() == TopAbs_REVERSED);
c6541a0c 156 Standard_Real f,l,eps,angmin = M_PI,angmax = -M_PI,ang;
7fd59977 157 BRep_Tool::Range(e,f,l);
158
159 eps = (l - f)/100.;
160 f += eps; // pour eviter de faire des calculs sur les
161 l -= eps; // pointes des carreaux pointus.
162 gp_Pnt2d p;
163 gp_Pnt pp1;
164 gp_Vec du,dv;
165 gp_Vec d1,d2;
166
167 Standard_Real uu, vv;
7fd59977 168
169 Standard_Integer i;
170 for(i = 0; i <= 20; i++){
171 u = f + (l-f)*i/20;
172 HC2d->D0(u,p);
173 HS1->D1(p.X(),p.Y(),pp1,du,dv);
174 d1 = (du.Crossed(dv)).Normalized();
175 if(rev1) d1.Reverse();
176 HC2d2->D0(u,p);
177 p.Coord(uu,vv);
178 HS2->D1(uu,vv,pp1,du,dv);
179 d2 = (du.Crossed(dv)).Normalized();
180 if(rev2) d2.Reverse();
181 ang = d1.Angle(d2);
7fd59977 182 if(ang <= angmin) angmin = ang;
183 if(ang >= angmax) angmax = ang;
184 }
185 return (angmax<=ta);
186}
187
188
189//=======================================================================
190//function : SampleEdges
191//purpose :
192//=======================================================================
193
194void LocOpe::SampleEdges(const TopoDS_Shape& theShape,
195 TColgp_SequenceOfPnt& theSeq)
196{
197 theSeq.Clear();
198 TopTools_MapOfShape theMap;
199
200 TopExp_Explorer exp(theShape,TopAbs_EDGE);
201 TopLoc_Location Loc;
202 Handle(Geom_Curve) C;
203 Standard_Real f,l,prm;
204 Standard_Integer i;
205
206 // Computes points on edge, but does not take the extremities into account
207 for (; exp.More(); exp.Next()) {
208 const TopoDS_Edge& edg = TopoDS::Edge(exp.Current());
209 if (!theMap.Add(edg)) {
210 continue;
211 }
212 if (!BRep_Tool::Degenerated(edg)) {
213 C = BRep_Tool::Curve(edg,Loc,f,l);
214 C = Handle(Geom_Curve)::
215 DownCast(C->Transformed(Loc.Transformation()));
216 Standard_Real delta = (l - f)/NECHANT*0.123456;
217 for (i=1; i<NECHANT; i++) {
218 prm = delta + ((NECHANT-i)*f+i*l)/NECHANT;
219 theSeq.Append(C->Value(prm));
220 }
221 }
222 }
223
224 // Adds every vertex
225 for (exp.Init(theShape,TopAbs_VERTEX); exp.More(); exp.Next()) {
226 if (theMap.Add(exp.Current())) {
227 theSeq.Append(BRep_Tool::Pnt(TopoDS::Vertex(exp.Current())));
228 }
229 }
230}
231
232
233
234
235
236/*
237Standard_Boolean LocOpe::IsInside(const TopoDS_Face& F1,
238 const TopoDS_Face& F2)
239{
240 Standard_Boolean Result = Standard_True;
241
242 TopExp_Explorer exp1, exp2;
243
244 for(exp1.Init(F1, TopAbs_EDGE); exp1.More(); exp1.Next()) {
245 TopoDS_Edge e1 = TopoDS::Edge(exp1.Current());
246 BRepAdaptor_Curve2d C1(e1, F1);
247 for(exp2.Init(F2, TopAbs_EDGE); exp2.More(); exp2.Next()) {
248 TopoDS_Edge e2 = TopoDS::Edge(exp2.Current());
249 BRepAdaptor_Curve2d C2(e2, F2);
250 Geom2dInt_GInter C;
251 C.Perform(C1, C2, Precision::Confusion(), Precision::Confusion());
252 if(!C.IsEmpty()) Result = Standard_False;
253 if(Result == Standard_False) {
254 for(exp3.Init(e2, TopAbs_VERTEX); exp3.More(); exp3.Next()) {
255
256 }
257 }
258 }
259 if(Result == Standard_False) break;
260 }
261 return Result;
262}
263
264*/
265
266
267