1 // File: GEOMAlgo_Tools.cxx
2 // Created: Mon Dec 6 11:35:29 2004
3 // Author: Peter KURNEV
6 #include <GEOMAlgo_Tools.ixx>
9 #include <gp_Pnt2d.hxx>
11 #include <Geom_Surface.hxx>
12 #include <Geom_Curve.hxx>
13 #include <Geom2d_Curve.hxx>
14 #include <GeomAdaptor_Surface.hxx>
16 #include <GeomAPI_ProjectPointOnSurf.hxx>
18 #include <TopAbs_ShapeEnum.hxx>
21 #include <TopoDS_Shape.hxx>
22 #include <TopoDS_Edge.hxx>
24 #include <TopTools_ListOfShape.hxx>
25 #include <TopTools_ListIteratorOfListOfShape.hxx>
26 #include <TopTools_IndexedMapOfShape.hxx>
28 #include <BRep_Tool.hxx>
29 #include <BRep_Builder.hxx>
30 #include <BRepTools.hxx>
32 #include <BOPTools_Tools2D.hxx>
33 #include <IntTools_Context.hxx>
35 #include <GEOMAlgo_PassKey.hxx>
36 #include <GEOMAlgo_IndexedDataMapOfPassKeyListOfShape.hxx>
38 //=======================================================================
39 //function : RefineSDShapes
41 //=======================================================================
42 Standard_Integer GEOMAlgo_Tools::RefineSDShapes(GEOMAlgo_IndexedDataMapOfPassKeyListOfShape &aMPKLE,
43 const Standard_Real aTol,
44 IntTools_Context& aCtx)
46 Standard_Integer i, aNbE, iErr, j, aNbEE, aNbToAdd;
47 TopTools_IndexedDataMapOfShapeListOfShape aMEE, aMSDE, aMEToAdd;
52 for (i=1; i<=aNbE; ++i) {
53 TopTools_ListOfShape& aLSDE=aMPKLE.ChangeFromIndex(i);
56 iErr=GEOMAlgo_Tools::FindSDShapes(aLSDE, aTol, aMEE, aCtx);
63 continue; // nothing to do
66 for (j=1; j<=aNbEE; ++j) {
67 TopTools_ListOfShape& aLEE=aMEE.ChangeFromIndex(j);
74 const TopoDS_Shape& aE1=aLEE.First();
75 aMEToAdd.Add(aE1, aLEE);
80 aNbToAdd=aMEToAdd.Extent();
85 for (i=1; i<=aNbToAdd; ++i) {
86 GEOMAlgo_PassKey aPKE1;
88 const TopoDS_Shape& aE1=aMEToAdd.FindKey(i);
89 const TopTools_ListOfShape& aLE=aMEToAdd(i);
92 aMPKLE.Add(aPKE1, aLE);
97 //=======================================================================
98 //function : FindSDShapes
100 //=======================================================================
101 Standard_Integer GEOMAlgo_Tools::FindSDShapes(const TopTools_ListOfShape& aLE,
102 const Standard_Real aTol,
103 TopTools_IndexedDataMapOfShapeListOfShape& aMEE,
104 IntTools_Context& aCtx)
106 Standard_Integer aNbE, aNbEProcessed, aNbESD, iErr;
107 TopTools_ListOfShape aLESD;
108 TopTools_ListIteratorOfListOfShape aIt, aIt1;
109 TopTools_IndexedMapOfShape aMProcessed;
110 TopAbs_ShapeEnum aType;
116 //modified by NIZNHY-PKV Thu Dec 30 10:56:52 2004 f
118 return 0; // Nothing to do
120 //modified by NIZNHY-PKV Thu Dec 30 10:56:56 2004 t
123 aNbEProcessed=aMProcessed.Extent();
124 if (aNbEProcessed==aNbE) {
129 for (; aIt.More(); aIt.Next()) {
130 const TopoDS_Shape& aS=aIt.Value();
132 if (aMProcessed.Contains(aS)) {
136 //modified by NIZNHY-PKV Thu Dec 30 10:57:01 2004 f
137 aType=aS.ShapeType();
138 if (aType==TopAbs_EDGE) {
139 const TopoDS_Edge& aE=TopoDS::Edge(aS);
140 if (BRep_Tool::Degenerated(aE)) {
145 //modified by NIZNHY-PKV Thu Dec 30 10:57:03 2004 t
148 iErr=GEOMAlgo_Tools::FindSDShapes(aS, aLE, aTol, aLESD, aCtx);
153 aNbESD=aLESD.Extent();
160 aIt1.Initialize(aLESD);
161 for (; aIt1.More(); aIt1.Next()) {
162 const TopoDS_Shape& aE1=aIt1.Value();
163 aMProcessed.Add(aE1);
169 //=======================================================================
170 //function : FindSDShapes
172 //=======================================================================
173 Standard_Integer GEOMAlgo_Tools::FindSDShapes(const TopoDS_Shape& aE1,
174 const TopTools_ListOfShape& aLE,
175 const Standard_Real aTol,
176 TopTools_ListOfShape& aLESD,
177 IntTools_Context& aCtx)
179 Standard_Boolean bIsDone;
180 Standard_Real aTol2, aD2;
182 TopTools_ListIteratorOfListOfShape aIt;
185 GEOMAlgo_Tools::PointOnShape(aE1, aP1);
188 for (; aIt.More(); aIt.Next()) {
189 const TopoDS_Shape& aE2=aIt.Value();
190 if (aE2.IsSame(aE1)) {
194 bIsDone=GEOMAlgo_Tools::ProjectPointOnShape(aP1, aE2, aP2, aCtx);
198 aD2=aP1.SquareDistance(aP2);
207 //=======================================================================
208 //function : ProjectPointOnShape
210 //=======================================================================
211 Standard_Boolean GEOMAlgo_Tools::ProjectPointOnShape(const gp_Pnt& aP1,
212 const TopoDS_Shape& aS,
214 IntTools_Context& aCtx)
216 Standard_Boolean bIsDone=Standard_False;
218 TopAbs_ShapeEnum aType;
220 aType=aS.ShapeType();
223 const TopoDS_Edge& aE2=TopoDS::Edge(aS);
225 bIsDone=aCtx.ProjectPointOnEdge(aP1, aE2, aT2);
230 GEOMAlgo_Tools::PointOnEdge(aE2, aT2, aP2);
235 const TopoDS_Face& aF2=TopoDS::Face(aS);
236 GeomAPI_ProjectPointOnSurf& aProj=aCtx.ProjPS(aF2);
239 bIsDone=aProj.IsDone();
244 aP2=aProj.NearestPoint();
253 //=======================================================================
254 //function : PointOnShape
256 //=======================================================================
257 void GEOMAlgo_Tools::PointOnShape(const TopoDS_Shape& aS,
260 TopAbs_ShapeEnum aType;
262 aP3D.SetCoord(99.,99.,99.);
263 aType=aS.ShapeType();
266 const TopoDS_Edge& aE=TopoDS::Edge(aS);
267 GEOMAlgo_Tools::PointOnEdge(aE, aP3D);
272 const TopoDS_Face& aF=TopoDS::Face(aS);
273 GEOMAlgo_Tools::PointOnFace(aF, aP3D);
281 //=======================================================================
282 //function : PointOnFace
284 //=======================================================================
285 void GEOMAlgo_Tools::PointOnFace(const TopoDS_Face& aF,
288 Standard_Real aU, aV, aUMin, aUMax, aVMin, aVMax;
290 BRepTools::UVBounds(aF, aUMin, aUMax, aVMin, aVMax);
292 aU=BOPTools_Tools2D::IntermediatePoint(aUMin, aUMax);
293 aV=BOPTools_Tools2D::IntermediatePoint(aVMin, aVMax);
295 GEOMAlgo_Tools::PointOnFace(aF, aU, aV, aP3D);
297 //=======================================================================
298 //function : PointOnFace
300 //=======================================================================
301 void GEOMAlgo_Tools::PointOnFace(const TopoDS_Face& aF,
302 const Standard_Real aU,
303 const Standard_Real aV,
306 Handle(Geom_Surface) aS;
308 aS=BRep_Tool::Surface(aF);
309 aS->D0(aU, aV, aP3D);
311 //=======================================================================
312 //function : PointOnEdge
314 //=======================================================================
315 void GEOMAlgo_Tools::PointOnEdge(const TopoDS_Edge& aE,
318 Standard_Real aTx, aT1, aT2;
320 BRep_Tool::Curve(aE, aT1, aT2);
321 aTx=BOPTools_Tools2D::IntermediatePoint(aT1, aT2);
322 GEOMAlgo_Tools::PointOnEdge(aE, aTx, aP3D);
324 //=======================================================================
325 //function : PointOnEdge
327 //=======================================================================
328 void GEOMAlgo_Tools::PointOnEdge(const TopoDS_Edge& aE,
329 const Standard_Real aT,
332 Standard_Real aT1, aT2;
333 Handle(Geom_Curve) aC3D;
335 aC3D=BRep_Tool::Curve(aE, aT1, aT2);
338 //=======================================================================
339 //function : RefinePCurveForEdgeOnFace
341 //=======================================================================
342 void GEOMAlgo_Tools::RefinePCurveForEdgeOnFace(const TopoDS_Edge& aE,
343 const TopoDS_Face& aF,
344 const Standard_Real aUMin,
345 const Standard_Real aUMax)
347 Standard_Real aT1, aT2, aTx, aUx, aTol, aTwoPI;
349 Handle(Geom_Surface) aS;
350 Handle(Geom2d_Curve) aC2D;
355 aC2D=BRep_Tool::CurveOnSurface(aE, aF, aT1, aT2);
356 if (!aC2D.IsNull()) {
357 if (BRep_Tool::IsClosed(aE, aF)) {
360 aTx=BOPTools_Tools2D::IntermediatePoint(aT1, aT2);
363 if (aUx < aUMin || aUx > aUMax) {
365 Handle(Geom2d_Curve) aC2Dx;
367 aTol=BRep_Tool::Tolerance(aE);
368 aBB.UpdateEdge(aE, aC2Dx, aF, aTol);
372 //=======================================================================
373 //function : IsUPeriodic
375 //=======================================================================
376 Standard_Boolean GEOMAlgo_Tools::IsUPeriodic(const Handle(Geom_Surface) &aS)
378 Standard_Boolean bRet;
379 GeomAbs_SurfaceType aType;
380 GeomAdaptor_Surface aGAS;
383 aType=aGAS.GetType();
384 bRet=(aType==GeomAbs_Cylinder||
385 aType==GeomAbs_Cone ||
386 aType==GeomAbs_Sphere);