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>
23 #include <TopoDS_Iterator.hxx>
25 #include <TopTools_ListOfShape.hxx>
26 #include <TopTools_ListIteratorOfListOfShape.hxx>
27 #include <TopTools_IndexedMapOfShape.hxx>
29 #include <BRep_Tool.hxx>
30 #include <BRep_Builder.hxx>
31 #include <BRepTools.hxx>
33 #include <BOPTools_Tools2D.hxx>
34 #include <IntTools_Context.hxx>
36 #include <GEOMAlgo_PassKey.hxx>
37 #include <GEOMAlgo_IndexedDataMapOfPassKeyListOfShape.hxx>
40 void GetCount(const TopoDS_Shape& aS,
41 Standard_Integer& iCnt);
43 //=======================================================================
44 //function : IsCompositeShape
46 //=======================================================================
47 Standard_Boolean GEOMAlgo_Tools::IsCompositeShape(const TopoDS_Shape& aS)
49 Standard_Boolean bRet;
50 Standard_Integer iCnt;
60 //=======================================================================
63 //=======================================================================
64 void GetCount(const TopoDS_Shape& aS,
65 Standard_Integer& iCnt)
72 if (aTS==TopAbs_SHAPE) {
75 if (aTS!=TopAbs_COMPOUND) {
81 for (; aIt.More(); aIt.Next()) {
82 const TopoDS_Shape& aSx=aIt.Value();
87 //=======================================================================
88 //function : RefineSDShapes
90 //=======================================================================
91 Standard_Integer GEOMAlgo_Tools::RefineSDShapes(GEOMAlgo_IndexedDataMapOfPassKeyListOfShape &aMPKLE,
92 const Standard_Real aTol,
93 IntTools_Context& aCtx)
95 Standard_Integer i, aNbE, iErr, j, aNbEE, aNbToAdd;
96 TopTools_IndexedDataMapOfShapeListOfShape aMEE, aMSDE, aMEToAdd;
100 aNbE=aMPKLE.Extent();
101 for (i=1; i<=aNbE; ++i) {
102 TopTools_ListOfShape& aLSDE=aMPKLE.ChangeFromIndex(i);
105 iErr=GEOMAlgo_Tools::FindSDShapes(aLSDE, aTol, aMEE, aCtx);
112 continue; // nothing to do
115 for (j=1; j<=aNbEE; ++j) {
116 TopTools_ListOfShape& aLEE=aMEE.ChangeFromIndex(j);
123 const TopoDS_Shape& aE1=aLEE.First();
124 aMEToAdd.Add(aE1, aLEE);
129 aNbToAdd=aMEToAdd.Extent();
134 for (i=1; i<=aNbToAdd; ++i) {
135 GEOMAlgo_PassKey aPKE1;
137 const TopoDS_Shape& aE1=aMEToAdd.FindKey(i);
138 const TopTools_ListOfShape& aLE=aMEToAdd(i);
141 aMPKLE.Add(aPKE1, aLE);
146 //=======================================================================
147 //function : FindSDShapes
149 //=======================================================================
150 Standard_Integer GEOMAlgo_Tools::FindSDShapes(const TopTools_ListOfShape& aLE,
151 const Standard_Real aTol,
152 TopTools_IndexedDataMapOfShapeListOfShape& aMEE,
153 IntTools_Context& aCtx)
155 Standard_Integer aNbE, aNbEProcessed, aNbESD, iErr;
156 TopTools_ListOfShape aLESD;
157 TopTools_ListIteratorOfListOfShape aIt, aIt1;
158 TopTools_IndexedMapOfShape aMProcessed;
159 TopAbs_ShapeEnum aType;
165 //modified by NIZNHY-PKV Thu Dec 30 10:56:52 2004 f
167 return 0; // Nothing to do
169 //modified by NIZNHY-PKV Thu Dec 30 10:56:56 2004 t
172 aNbEProcessed=aMProcessed.Extent();
173 if (aNbEProcessed==aNbE) {
178 for (; aIt.More(); aIt.Next()) {
179 const TopoDS_Shape& aS=aIt.Value();
181 if (aMProcessed.Contains(aS)) {
185 //modified by NIZNHY-PKV Thu Dec 30 10:57:01 2004 f
186 aType=aS.ShapeType();
187 if (aType==TopAbs_EDGE) {
188 const TopoDS_Edge& aE=TopoDS::Edge(aS);
189 if (BRep_Tool::Degenerated(aE)) {
194 //modified by NIZNHY-PKV Thu Dec 30 10:57:03 2004 t
197 iErr=GEOMAlgo_Tools::FindSDShapes(aS, aLE, aTol, aLESD, aCtx);
202 aNbESD=aLESD.Extent();
209 aIt1.Initialize(aLESD);
210 for (; aIt1.More(); aIt1.Next()) {
211 const TopoDS_Shape& aE1=aIt1.Value();
212 aMProcessed.Add(aE1);
218 //=======================================================================
219 //function : FindSDShapes
221 //=======================================================================
222 Standard_Integer GEOMAlgo_Tools::FindSDShapes(const TopoDS_Shape& aE1,
223 const TopTools_ListOfShape& aLE,
224 const Standard_Real aTol,
225 TopTools_ListOfShape& aLESD,
226 IntTools_Context& aCtx)
228 Standard_Boolean bIsDone;
229 Standard_Real aTol2, aD2;
231 TopTools_ListIteratorOfListOfShape aIt;
234 GEOMAlgo_Tools::PointOnShape(aE1, aP1);
237 for (; aIt.More(); aIt.Next()) {
238 const TopoDS_Shape& aE2=aIt.Value();
239 if (aE2.IsSame(aE1)) {
243 bIsDone=GEOMAlgo_Tools::ProjectPointOnShape(aP1, aE2, aP2, aCtx);
247 aD2=aP1.SquareDistance(aP2);
256 //=======================================================================
257 //function : ProjectPointOnShape
259 //=======================================================================
260 Standard_Boolean GEOMAlgo_Tools::ProjectPointOnShape(const gp_Pnt& aP1,
261 const TopoDS_Shape& aS,
263 IntTools_Context& aCtx)
265 Standard_Boolean bIsDone=Standard_False;
267 TopAbs_ShapeEnum aType;
269 aType=aS.ShapeType();
272 const TopoDS_Edge& aE2=TopoDS::Edge(aS);
274 bIsDone=aCtx.ProjectPointOnEdge(aP1, aE2, aT2);
279 GEOMAlgo_Tools::PointOnEdge(aE2, aT2, aP2);
284 const TopoDS_Face& aF2=TopoDS::Face(aS);
285 GeomAPI_ProjectPointOnSurf& aProj=aCtx.ProjPS(aF2);
288 bIsDone=aProj.IsDone();
293 aP2=aProj.NearestPoint();
302 //=======================================================================
303 //function : PointOnShape
305 //=======================================================================
306 void GEOMAlgo_Tools::PointOnShape(const TopoDS_Shape& aS,
309 TopAbs_ShapeEnum aType;
311 aP3D.SetCoord(99.,99.,99.);
312 aType=aS.ShapeType();
315 const TopoDS_Edge& aE=TopoDS::Edge(aS);
316 GEOMAlgo_Tools::PointOnEdge(aE, aP3D);
321 const TopoDS_Face& aF=TopoDS::Face(aS);
322 GEOMAlgo_Tools::PointOnFace(aF, aP3D);
330 //=======================================================================
331 //function : PointOnFace
333 //=======================================================================
334 void GEOMAlgo_Tools::PointOnFace(const TopoDS_Face& aF,
337 Standard_Real aU, aV, aUMin, aUMax, aVMin, aVMax;
339 BRepTools::UVBounds(aF, aUMin, aUMax, aVMin, aVMax);
341 aU=BOPTools_Tools2D::IntermediatePoint(aUMin, aUMax);
342 aV=BOPTools_Tools2D::IntermediatePoint(aVMin, aVMax);
344 GEOMAlgo_Tools::PointOnFace(aF, aU, aV, aP3D);
346 //=======================================================================
347 //function : PointOnFace
349 //=======================================================================
350 void GEOMAlgo_Tools::PointOnFace(const TopoDS_Face& aF,
351 const Standard_Real aU,
352 const Standard_Real aV,
355 Handle(Geom_Surface) aS;
357 aS=BRep_Tool::Surface(aF);
358 aS->D0(aU, aV, aP3D);
360 //=======================================================================
361 //function : PointOnEdge
363 //=======================================================================
364 void GEOMAlgo_Tools::PointOnEdge(const TopoDS_Edge& aE,
367 Standard_Real aTx, aT1, aT2;
369 BRep_Tool::Curve(aE, aT1, aT2);
370 aTx=BOPTools_Tools2D::IntermediatePoint(aT1, aT2);
371 GEOMAlgo_Tools::PointOnEdge(aE, aTx, aP3D);
373 //=======================================================================
374 //function : PointOnEdge
376 //=======================================================================
377 void GEOMAlgo_Tools::PointOnEdge(const TopoDS_Edge& aE,
378 const Standard_Real aT,
381 Standard_Real aT1, aT2;
382 Handle(Geom_Curve) aC3D;
384 aC3D=BRep_Tool::Curve(aE, aT1, aT2);
387 //=======================================================================
388 //function : RefinePCurveForEdgeOnFace
390 //=======================================================================
391 void GEOMAlgo_Tools::RefinePCurveForEdgeOnFace(const TopoDS_Edge& aE,
392 const TopoDS_Face& aF,
393 const Standard_Real aUMin,
394 const Standard_Real aUMax)
396 Standard_Real aT1, aT2, aTx, aUx, aTol, aTwoPI;
398 Handle(Geom_Surface) aS;
399 Handle(Geom2d_Curve) aC2D;
404 aC2D=BRep_Tool::CurveOnSurface(aE, aF, aT1, aT2);
405 if (!aC2D.IsNull()) {
406 if (BRep_Tool::IsClosed(aE, aF)) {
409 aTx=BOPTools_Tools2D::IntermediatePoint(aT1, aT2);
412 if (aUx < aUMin || aUx > aUMax) {
414 Handle(Geom2d_Curve) aC2Dx;
416 aTol=BRep_Tool::Tolerance(aE);
417 aBB.UpdateEdge(aE, aC2Dx, aF, aTol);
421 //=======================================================================
422 //function : IsUPeriodic
424 //=======================================================================
425 Standard_Boolean GEOMAlgo_Tools::IsUPeriodic(const Handle(Geom_Surface) &aS)
427 Standard_Boolean bRet;
428 GeomAbs_SurfaceType aType;
429 GeomAdaptor_Surface aGAS;
432 aType=aGAS.GetType();
433 bRet=(aType==GeomAbs_Cylinder||
434 aType==GeomAbs_Cone ||
435 aType==GeomAbs_Sphere);