1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // File: GEOMAlgo_Tools_1.cxx
20 // Created: Thu May 6 10:46:21 2010
21 // Author: Peter KURNEV
23 #include <GEOMAlgo_Tools.hxx>
25 #include <NCollection_DataMap.hxx>
27 #include <gp_Pnt2d.hxx>
30 #include <Geom2dAdaptor_Curve.hxx>
31 #include <Geom2dInt_GInter.hxx>
32 #include <Geom2d_Curve.hxx>
33 #include <Geom_Curve.hxx>
34 #include <Geom_Surface.hxx>
35 #include <GeomAdaptor_Surface.hxx>
37 #include <IntRes2d_Domain.hxx>
38 #include <IntRes2d_IntersectionPoint.hxx>
39 #include <IntRes2d_Transition.hxx>
41 #include <TopoDS_Iterator.hxx>
42 #include <TopoDS_Face.hxx>
43 #include <TopoDS_Wire.hxx>
44 #include <TopoDS_Edge.hxx>
45 #include <TopoDS_Vertex.hxx>
46 #include <TopExp_Explorer.hxx>
48 #include <BRep_Tool.hxx>
49 #include <BRep_Builder.hxx>
51 #include <TopTools_MapOfShape.hxx>
52 #include <TopTools_ShapeMapHasher.hxx>
53 #include <TopTools_ListOfShape.hxx>
54 #include <TopTools_DataMapOfShapeListOfShape.hxx>
55 #include <TopTools_ListOfShape.hxx>
56 #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
57 #include <BRepTools.hxx>
60 inline Standard_Boolean IsEqual(const TopoDS_Shape& aS1,
61 const TopoDS_Shape& aS2) {
62 return TopTools_ShapeMapHasher::IsEqual(aS1, aS2);
66 Standard_Boolean CorrectWire(const TopoDS_Wire& aW,
67 const TopoDS_Face& aF);
69 //=======================================================================
70 //function : CorrectWires
72 //=======================================================================
73 Standard_Boolean GEOMAlgo_Tools::CorrectWires(const TopoDS_Shape& aShape)
75 Standard_Boolean bRet;
78 TopTools_MapOfShape aMF;
79 GeomAdaptor_Surface aGAS;
80 GeomAbs_SurfaceType aTS;
85 aExp.Init(aShape, TopAbs_FACE);
86 for (; aExp.More(); aExp.Next()) {
87 const TopoDS_Face& aF=*((TopoDS_Face*)&aExp.Current());
89 const Handle(Geom_Surface)& aS=BRep_Tool::Surface(aF, aLoc);
92 //modified by NIZNHY-PKV Mon Jul 02 13:58:30 2012f
93 if (aTS==GeomAbs_Cylinder || aTS==GeomAbs_Plane || aTS==GeomAbs_BSplineSurface) {
94 //if (aTS==GeomAbs_Cylinder || aTS==GeomAbs_Plane) {
95 //modified by NIZNHY-PKV Mon Jul 02 13:58:33 2012t
97 for (; aItF.More(); aItF.Next()) {
98 const TopoDS_Wire& aW=*((TopoDS_Wire*)&aItF.Value());
99 if (CorrectWire(aW, aF)) {
109 //=======================================================================
110 //class: GEOMAlgo_InfoEdge
112 //=======================================================================
113 class GEOMAlgo_InfoEdge {
116 GEOMAlgo_InfoEdge() {
121 ~GEOMAlgo_InfoEdge(){
124 void Init(const TopoDS_Edge& aE,
125 const TopoDS_Face& aF);
127 void SetTolInt(const Standard_Real aTolInt) {
131 const Standard_Real TolInt() const {
135 const Geom2dAdaptor_Curve& Adaptor() const {
139 const IntRes2d_Domain& Domain()const {
143 const Handle(Geom2d_Curve)& CurveOnSurface()const {
147 const Handle(Geom_Curve)& Curve()const {
151 Standard_Integer ErrorStatus()const {
152 return myErrorStatus;
156 Standard_Integer myErrorStatus;
157 Standard_Real myTolInt;
158 Geom2dAdaptor_Curve myGAC2D;
159 IntRes2d_Domain myDomain;
160 Handle(Geom2d_Curve) myC2D;
161 Handle(Geom_Curve) myC3D;
164 typedef NCollection_DataMap<TopoDS_Shape, GEOMAlgo_InfoEdge> GEOMAlgo_DataMapOfShapeInfoEdge;
165 typedef GEOMAlgo_DataMapOfShapeInfoEdge::Iterator GEOMAlgo_DataMapIteratorOfDataMapOfShapeInfoEdge;
167 //=======================================================================
170 //=======================================================================
171 void GEOMAlgo_InfoEdge::Init(const TopoDS_Edge& aE,
172 const TopoDS_Face& aF)
174 Standard_Real aT1, aT2, aT1x, aT2x;
175 gp_Pnt2d aP2D1, aP2D2;
179 myC3D=BRep_Tool::Curve(aE, aT1, aT2);
180 myC2D=BRep_Tool::CurveOnSurface(aE ,aF, aT1, aT2);
181 if (!myC2D.IsNull() && aT2>aT1) {
183 if(!myGAC2D.IsPeriodic()) {
184 aT1x=myGAC2D.FirstParameter();
185 aT2x=myGAC2D.LastParameter();
194 BRep_Tool::UVPoints(aE, aF, aP2D1, aP2D2);
195 myDomain.SetValues(aP2D1, aT1, myTolInt, aP2D2, aT2, myTolInt);
203 //=======================================================================
204 //function : CorrectWire
206 //=======================================================================
207 Standard_Boolean CorrectWire(const TopoDS_Wire& aW,
208 const TopoDS_Face& aF)
210 Standard_Boolean bRet;
211 Standard_Real aTolInt;
212 Standard_Integer iErr, aNbV, aNbE;
213 TopoDS_Iterator aItW, aItE;
214 Geom2dInt_GInter aInter;
215 GEOMAlgo_DataMapOfShapeInfoEdge aDMEIE;
216 TopTools_DataMapOfShapeListOfShape aDMVLE;
217 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape aItDMVLE;
223 for (; aItW.More(); aItW.Next()) {
224 const TopoDS_Edge& aE=*((TopoDS_Edge*)&aItW.Value());
227 for (aNbV=0; aItE.More(); aItE.Next(), ++aNbV) {
233 if (!aDMEIE.IsBound(aE)) {
234 GEOMAlgo_InfoEdge aInfoEdge;
236 aInfoEdge.Init (aE, aF);
237 iErr=aInfoEdge.ErrorStatus();
242 aDMEIE.Bind(aE, aInfoEdge);
246 for (; aItE.More(); aItE.Next()) {
247 const TopoDS_Shape& aV=aItE.Value();
248 if (aDMVLE.IsBound(aV)) {
249 TopTools_ListOfShape& aLE=aDMVLE.ChangeFind(aV);
253 TopTools_ListOfShape aLE;
255 aDMVLE.Bind(aV, aLE);
261 Standard_Real aTolV, aD1, aD2, aDmax, aCoeff;
263 Handle(Geom_Surface) aS;
267 aS=BRep_Tool::Surface(aF);
269 aItDMVLE.Initialize(aDMVLE);
270 for(; aItDMVLE.More(); aItDMVLE.Next()) {
271 const TopoDS_Vertex& aV=*((TopoDS_Vertex*)&aItDMVLE.Key());
272 const TopTools_ListOfShape& aLE=aItDMVLE.Value();
278 aPV=BRep_Tool::Pnt(aV);
279 aTolV=BRep_Tool::Tolerance(aV);
281 const TopoDS_Edge& aE1=*((TopoDS_Edge*)&aLE.First());
282 const GEOMAlgo_InfoEdge& aIE1=aDMEIE.Find(aE1);
283 const Geom2dAdaptor_Curve& aGAC1=aIE1.Adaptor();
284 const IntRes2d_Domain& aDomain1=aIE1.Domain();
286 const TopoDS_Edge& aE2=*((TopoDS_Edge*)&aLE.Last());
287 const GEOMAlgo_InfoEdge& aIE2=aDMEIE.Find(aE2);
288 const Geom2dAdaptor_Curve& aGAC2=aIE2.Adaptor();
289 const IntRes2d_Domain& aDomain2=aIE2.Domain();
291 aInter.Perform(aGAC1, aDomain1,aGAC2, aDomain2, aTolInt, aTolInt);
292 if(!aInter.IsDone()) {
296 Standard_Integer i, aNbP;
297 Standard_Real aIP_ParamOnFirst, aIP_ParamOnSecond, aDTresh, aDT;
299 gp_Pnt2d aP2D1, aP2D2;
300 IntRes2d_Transition aTr1, aTr2;
304 aNbP=aInter.NbPoints();
305 for (i=1; i<=aNbP; ++i) {
306 const IntRes2d_IntersectionPoint& aIP = aInter.Point(i);
307 aIP_ParamOnFirst = aIP.ParamOnFirst();
308 aIP_ParamOnSecond = aIP.ParamOnSecond();
309 aTr1 =aIP.TransitionOfFirst();
310 aTr2 =aIP.TransitionOfSecond();
311 if(aTr1.PositionOnCurve()==IntRes2d_Middle ||
312 aTr2.PositionOnCurve()==IntRes2d_Middle) {
314 const Handle(Geom_Curve)& aC3D1=aIE1.Curve();
315 if (!aC3D1.IsNull()) {
316 aP3D1=aC3D1->Value(aIP_ParamOnFirst);
319 aP2D1=aGAC1.Value(aIP_ParamOnFirst);
320 aS->D0(aP2D1.X(), aP2D1.Y(), aP3D1);
323 const Handle(Geom_Curve)& aC3D2=aIE2.Curve();
324 if (!aC3D2.IsNull()) {
325 aP3D2=aC3D2->Value(aIP_ParamOnSecond);
328 aP2D2=aGAC2.Value(aIP_ParamOnSecond);
329 aS->D0(aP2D2.X(), aP2D2.Y(), aP3D2);
332 aD1=aPV.Distance(aP3D1);
333 aD2=aPV.Distance(aP3D2);
334 aDmax=(aD1>aD2)? aD1 : aD2;
335 if (aDmax>aCoeff*aTolV) {
336 //modified by NIZNHY-PKV Mon Jul 02 13:56:35 2012f
342 //if (aDmax<10.*aTolV){
343 //modified by NIZNHY-PKV Mon Jul 02 13:56:40 2012t
344 aBB.UpdateVertex(aV, aDmax);
349 }//for (i=1; i<=aNbP; ++i) {
350 }//for(; aItDMVLE.More(); aItDMVLE.Next()) {