X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FGEOMAlgo%2FGEOMAlgo_ShapeInfoFiller_1.cxx;h=58d1c3971aee1d9af0d2c2e3cbd00a1eebffa9d6;hb=bef7e3cbcdce0bb09e953394ecdbfb3972a75f27;hp=891b9c772b682e590f15cc4fccc6f64f0abe3b05;hpb=239f8109c64fa0c5a2e1d87a420bad5529b57f48;p=modules%2Fgeom.git diff --git a/src/GEOMAlgo/GEOMAlgo_ShapeInfoFiller_1.cxx b/src/GEOMAlgo/GEOMAlgo_ShapeInfoFiller_1.cxx old mode 100644 new mode 100755 index 891b9c772..58d1c3971 --- a/src/GEOMAlgo/GEOMAlgo_ShapeInfoFiller_1.cxx +++ b/src/GEOMAlgo/GEOMAlgo_ShapeInfoFiller_1.cxx @@ -1,6 +1,27 @@ -#include +// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include #include +#include +#include #include #include @@ -12,6 +33,8 @@ #include +#include + #include #include #include @@ -26,22 +49,31 @@ #include #include + #include +#include +#include #include -#include -#include + +static + Standard_Boolean IsEqual(const gp_Sphere& aSp1, + const gp_Sphere& aSp2, + const Standard_Real aTolDst); //======================================================================= //function : FillDetails -//purpose : +//purpose : //======================================================================= - void GEOMAlgo_ShapeInfoFiller::FillDetails(const TopoDS_Solid& aSd) +void GEOMAlgo_ShapeInfoFiller::FillDetails(const TopoDS_Solid& aSd) { - Standard_Integer i, aNbF, aNbCyl, aNbCon, aNbPgn, aNbRct, aNbCrc, aNbX; + Standard_Boolean bIsStepSphere; + Standard_Integer i, aNbF, aNbCyl, aNbCon, aNbPgn, aNbRct; + Standard_Integer aNbShells, aNbCrc, aNbX; TopoDS_Shape aFCyl, aFCon; TopTools_IndexedMapOfShape aMF; GEOMAlgo_KindOfName aKNF; + GEOMAlgo_KindOfDef aKD; // GEOMAlgo_ShapeInfo& aInfo=myMapInfo.ChangeFromKey(aSd); aInfo.SetKindOfName(GEOMAlgo_KN_UNKNOWN); @@ -53,22 +85,63 @@ return; } // + //modified by NIZNHY-PKV Tue Jun 09 08:35:23 2015f + if (aNbF==2) { + // case requested by the customer + // specific solid that should be treated as a sphere + bIsStepSphere=TreatStepSphere(aSd); + if (bIsStepSphere) { + return; + } + } + //modified by NIZNHY-PKV Tue Jun 09 08:35:28 2015t + // + aKD=GEOMAlgo_KD_SPECIFIED; + for (i=1; i<=aNbF && aKD==GEOMAlgo_KD_SPECIFIED; ++i) { + const TopoDS_Shape& aF=aMF(i); + GEOMAlgo_ShapeInfo& aInfoF=myMapInfo.ChangeFromKey(aF); + aKD=aInfoF.KindOfDef(); + } + if (aKD!=GEOMAlgo_KD_SPECIFIED) { + aInfo.SetKindOfName(GEOMAlgo_KN_SOLID); + return; + } + // + aNbShells=GEOMAlgo_ShapeInfoFiller::NbShells(aSd); + if (aNbShells>1) { + aInfo.SetKindOfName(GEOMAlgo_KN_SOLID); + return; + } + // + // if (aNbF==1) { + // mb: sphere, torus const TopoDS_Shape& aF=aMF(1); GEOMAlgo_ShapeInfo& aInfoF=myMapInfo.ChangeFromKey(aF); aKNF=aInfoF.KindOfName(); // mb: sphere, torus if (aKNF==GEOMAlgo_KN_SPHERE || - aKNF==GEOMAlgo_KN_TORUS) { + aKNF==GEOMAlgo_KN_TORUS) { aInfo.SetKindOfName(aKNF); aInfo.SetLocation(aInfoF.Location()); aInfo.SetPosition(aInfoF.Position()); aInfo.SetRadius1(aInfoF.Radius1()); if(aKNF==GEOMAlgo_KN_TORUS) { - aInfo.SetRadius2(aInfoF.Radius2()); + aInfo.SetRadius2(aInfoF.Radius2()); } return; } } + //modified by NIZNHY-PKV Tue Jun 09 08:36:08 2015f + /* + else if (aNbF==2) { + // specific solid that should be treated as a sphere + bIsStepSphere=TreatStepSphere(aSd); + if (bIsStepSphere) { + return; + } + } + */ + //modified by NIZNHY-PKV Tue Jun 09 08:36:12 2015t // aNbCyl=0; aNbCon=0; @@ -78,7 +151,7 @@ for (i=1; i<=aNbF; ++i) { const TopoDS_Shape& aF=aMF(i); GEOMAlgo_ShapeInfo& aInfoF=myMapInfo.ChangeFromKey(aF); - aKNF=aInfoF.KindOfName(); + aKNF=aInfoF.KindOfName(); if (aKNF==GEOMAlgo_KN_CYLINDER) { aFCyl=aF; ++aNbCyl; @@ -91,11 +164,10 @@ ++aNbCrc; } else if (aKNF==GEOMAlgo_KN_POLYGON || - aKNF==GEOMAlgo_KN_TRIANGLE || - aKNF==GEOMAlgo_KN_QUADRANGLE) { + aKNF==GEOMAlgo_KN_TRIANGLE || + aKNF==GEOMAlgo_KN_QUADRANGLE) { ++aNbPgn; - - } + } else if (aKNF==GEOMAlgo_KN_RECTANGLE) { ++aNbPgn; ++aNbRct; @@ -106,7 +178,7 @@ if (aNbCyl==1 && aNbCrc==2 && aNbX==aNbF) { // cylinder (as they understand it) GEOMAlgo_ShapeInfo& aInfoF=myMapInfo.ChangeFromKey(aFCyl); - aKNF=aInfoF.KindOfName(); + aKNF=aInfoF.KindOfName(); aInfo.SetKindOfName(aKNF); aInfo.SetLocation(aInfoF.Location()); aInfo.SetPosition(aInfoF.Position()); @@ -119,7 +191,7 @@ if (aNbCon==1 && (aNbCrc==1 || aNbCrc==2) && aNbX==aNbF) { // cone GEOMAlgo_ShapeInfo& aInfoF=myMapInfo.ChangeFromKey(aFCon); - aKNF=aInfoF.KindOfName(); + aKNF=aInfoF.KindOfName(); aInfo.SetKindOfName(aKNF); aInfo.SetLocation(aInfoF.Location()); aInfo.SetPosition(aInfoF.Position()); @@ -129,10 +201,14 @@ return; } // + if (aNbF!=aNbPgn) { + return;// -> GEOMAlgo_KN_UNKNOWN + } if (aNbPgn!=6) { aInfo.SetKindOfName(GEOMAlgo_KN_POLYHEDRON); return; } + // aNbPgn==6 if (aNbPgn!=aNbRct) { aInfo.SetKindOfName(GEOMAlgo_KN_POLYHEDRON); return; @@ -179,7 +255,7 @@ // for (j=i+1; j<=aNbF; ++j) { if (aMp.Contains(j)) { - continue; + continue; } // const TopoDS_Shape& aFj=aMF(j); @@ -187,11 +263,14 @@ const gp_Dir& aDNj=aIFj.Position().Direction(); // aDot=aDNi*aDNj; + if (aDot<0.) { + aDot=-aDot; + } if (fabs(1.-aDot)<0.0001) { - aMp.Add(i); - aMp.Add(j); - aMFi.Add(aFi); - break; + aMp.Add(i); + aMp.Add(j); + aMFi.Add(aFi); + break; } // } @@ -201,6 +280,8 @@ return; } // + iMin=-1; + iMax=-1; aDistMin=1.e15; aDistMax=-aDistMin; for (i=0; i myTolerance) { - aInfo.SetKindOfName(GEOMAlgo_KN_QUADRANGLE); - return; + if (aNbV==4 && aNbE==4) { + aIt.Initialize(aF); + if (aIt.More()) { + aW=*((TopoDS_Wire*)&aIt.Value()); + } + // + aWExp.Init(aW, aF); + for (i=0; aWExp.More(); aWExp.Next(), ++i) { + aEx=aWExp.Current(); + const GEOMAlgo_ShapeInfo& aInfoEx=myMapInfo.FindFromKey(aEx); + aDx[i]=aInfoEx.Direction(); + aPx[i]=aInfoEx.Location(); + } + // + Standard_Boolean isRectangle = Standard_True; + for (i=0; i<4; ++i) { + j=(i==3) ? 0 : i+1; + aDot=aDx[i]*aDx[j]; + if (fabs (aDot) > myTolerance) { + isRectangle = Standard_False; + break; + } + } + // + // rectangle + // shift location to the center + aXYZc.SetCoord(0.,0.,0.); + TopExp::MapShapes(aF, TopAbs_VERTEX, aMV); + for (i=1; i<=aNbV; ++i) { + const TopoDS_Vertex& aV=TopoDS::Vertex(aMV(i)); + aP=BRep_Tool::Pnt(aV); + const gp_XYZ& aXYZ=aP.XYZ(); + aXYZc=aXYZc+aXYZ; + } + // + // Location : aPc in center of rectangle + // Position : 0z is plane normal + // 0x is along the first edge (quadrangle) or + // along length (rectangle) + // + aXYZc.Divide(4.); + aPc.SetXYZ(aXYZc); + aDX=aDx[0]; + aInfo.SetLocation(aPc); + + if (isRectangle) { + // Calculate sizes + gp_Lin aL0(aPx[0], aDx[0]); + gp_Lin aL1(aPx[1], aDx[1]); + // + aD0=aL0.Distance(aPc); + aD1=aL1.Distance(aPc); + // + aLength=aD1; + aWidth =aD0; + + if (aD0>aD1) { + aLength=aD0; + aWidth =aD1; + aDX=aDx[1]; + } + // + aLength=2.*aLength; + aWidth =2.*aWidth; + // + aInfo.SetLength(aLength); + aInfo.SetWidth(aWidth); + aInfo.SetKindOfName(GEOMAlgo_KN_RECTANGLE); + } else { + aInfo.SetKindOfName(GEOMAlgo_KN_QUADRANGLE); + } + // + const gp_Dir& aDZ=aPln.Axis().Direction(); + gp_Ax2 aAx2(aPc, aDZ, aDX); + gp_Ax3 aAx3(aAx2); + aInfo.SetPosition(aAx3); + // + }// if (aNbV==4 && aNbE==4) { + return; + }// if (bSegment) { + // + //aInfo.SetKindOfName(GEOMAlgo_KN_PLANE); +} +//======================================================================= +//function : FillDetails +//purpose : +//======================================================================= +void GEOMAlgo_ShapeInfoFiller::FillDetails(const TopoDS_Face& aF, + const gp_Sphere& )//aSph) +{ + + Standard_Integer aNbV, aNbE, aNbSE, aNbDE; + TopoDS_Edge aE; + TopExp_Explorer aExp; + TopTools_MapOfShape aM; + GEOMAlgo_KindOfShape aKSE;//, aKSE; + // + GEOMAlgo_ShapeInfo& aInfo=myMapInfo.ChangeFromKey(aF); + // + aInfo.SetKindOfDef(GEOMAlgo_KD_ARBITRARY); + aNbV=aInfo.NbSubShapes(TopAbs_VERTEX); + aNbE=aInfo.NbSubShapes(TopAbs_EDGE); + if (aNbV==2 && aNbE==3) { + aNbSE=0; + aNbDE=0; + aExp.Init(aF, TopAbs_EDGE); + for (; aExp.More(); aExp.Next()) { + aE=TopoDS::Edge(aExp.Current()); + if(aM.Add(aE)) { + const GEOMAlgo_ShapeInfo& aInfoE=myMapInfo.FindFromKey(aE); + aKSE=aInfoE.KindOfShape(); + // + if (BRep_Tool::IsClosed(aE, aF)) { + ++aNbSE; + } + else if (aKSE==GEOMAlgo_KS_DEGENERATED) { + ++aNbDE; + } } } // - // rectangle - aInfo.SetKindOfName(GEOMAlgo_KN_RECTANGLE); - // - // shift location to the center and calc. sizes - aXYZc.SetCoord(0.,0.,0.); - TopExp::MapShapes(aF, TopAbs_VERTEX, aMV); - for (i=1; i<=aNbV; ++i) { - const TopoDS_Vertex& aV=TopoDS::Vertex(aMV(i)); - aP=BRep_Tool::Pnt(aV); - const gp_XYZ& aXYZ=aP.XYZ(); - aXYZc=aXYZc+aXYZ; - } - // - // Location : aPc in center of rectangle - // Position : 0z is plane normal - // 0x is along length - // - aXYZc.Divide(4.); - aPc.SetXYZ(aXYZc); - // - gp_Lin aL0(aPx[0], aDx[0]); - gp_Lin aL1(aPx[1], aDx[1]); - // - aD0=aL0.Distance(aPc); - aD1=aL1.Distance(aPc); - // - aLength=aD0; - aWidth =aD1; - aDX=aL1.Direction(); - if (aD0aT1) { + aPc=aPC[1]; + } + aHeight=aPC[0].Distance(aPC[1]); + // + gp_Ax3 aAx3=aCyl.Position(); + aAx3.SetLocation(aPc); + // + aInfo.SetPosition(aAx3); + aInfo.SetLocation(aPc); + aInfo.SetHeight(aHeight); + // + aInfo.SetKindOfDef(GEOMAlgo_KD_SPECIFIED); + return; // conventional cylinder + }//if (aNbCE==2 && aNbSE==1) { + }//if (aNbV==2 && aNbE==3) { } //======================================================================= //function : FillDetails -//purpose : +//purpose : //======================================================================= - void GEOMAlgo_ShapeInfoFiller::FillDetails(const TopoDS_Face& aF, - const gp_Cone& )//aCone) +void GEOMAlgo_ShapeInfoFiller::FillDetails(const TopoDS_Face& aF, + const gp_Cone& aCone) { Standard_Integer aNbV, aNbE, aNbCE, aNbSE, aNbDE, i; - Standard_Real aR[3], aHeight; + Standard_Real aR[3], aHeight, aRmin, aRmax; gp_Pnt aPC[3], aPD, aPc, aPX[3]; TopoDS_Vertex aVD; TopoDS_Edge aE; TopoDS_Iterator aIt; TopExp_Explorer aExp; TopTools_MapOfShape aM; - GEOMAlgo_KindOfShape aKS, aKSE; - GEOMAlgo_KindOfName aKN, aKNE; + GEOMAlgo_KindOfShape aKSE; + GEOMAlgo_KindOfName aKNE; GEOMAlgo_KindOfClosed aKCE; // GEOMAlgo_ShapeInfo& aInfo=myMapInfo.ChangeFromKey(aF); - aKN=GEOMAlgo_KN_UNKNOWN; - aInfo.SetKindOfName(aKN); - // - aKS=aInfo.KindOfShape(); - if (aKS!=GEOMAlgo_KS_CONE) { - return; - } // - if (aInfo.KindOfBounds()==GEOMAlgo_KB_INFINITE) { - return; - } + aInfo.SetKindOfDef(GEOMAlgo_KD_ARBITRARY); // aNbV=aInfo.NbSubShapes(TopAbs_VERTEX); aNbE=aInfo.NbSubShapes(TopAbs_EDGE); - if (!(aNbV==2 && aNbE==3)) { - return; - } - // - i=0; - aNbCE=0; - aNbSE=0; - aNbDE=0; - aExp.Init(aF, TopAbs_EDGE); - for (; aExp.More(); aExp.Next()) { - aE=TopoDS::Edge(aExp.Current()); - if(aM.Add(aE)) { - const GEOMAlgo_ShapeInfo& aInfoE=myMapInfo.FindFromKey(aE); - aKNE=aInfoE.KindOfName(); - aKCE=aInfoE.KindOfClosed(); - aKSE=aInfoE.KindOfShape(); - if (aKNE==GEOMAlgo_KN_CIRCLE && aKCE==GEOMAlgo_KC_CLOSED) { - aPC[i]=aInfoE.Location(); - aR[i]=aInfoE.Radius1(); - // - aIt.Initialize(aE); - for (; aIt.More(); aIt.Next()) { - aVD=TopoDS::Vertex(aIt.Value()); - break; - } - aPX[i]=BRep_Tool::Pnt(aVD); - // - ++i; - ++aNbCE; + if (aNbV==2 && aNbE==3) { + i=0; + aNbCE=0; + aNbSE=0; + aNbDE=0; + aExp.Init(aF, TopAbs_EDGE); + for (; aExp.More(); aExp.Next()) { + aE=TopoDS::Edge(aExp.Current()); + if(aM.Add(aE)) { + const GEOMAlgo_ShapeInfo& aInfoE=myMapInfo.FindFromKey(aE); + aKNE=aInfoE.KindOfName(); + aKCE=aInfoE.KindOfClosed(); + aKSE=aInfoE.KindOfShape(); + if (aKNE==GEOMAlgo_KN_CIRCLE && aKCE==GEOMAlgo_KC_CLOSED) { + aPC[i]=aInfoE.Location(); + aR[i]=aInfoE.Radius1(); + // + aIt.Initialize(aE); + if (aIt.More()) { + aVD=*((TopoDS_Vertex*)&aIt.Value()); + } + aPX[i]=BRep_Tool::Pnt(aVD); + // + ++i; + ++aNbCE; + } + else if (aKNE==GEOMAlgo_KN_SEGMENT) { + if (BRep_Tool::IsClosed(aE, aF)) { + ++aNbSE; + } + } + else if (aKSE==GEOMAlgo_KS_DEGENERATED) { + aIt.Initialize(aE); + if (aIt.More()) { + aVD=*((TopoDS_Vertex*)&aIt.Value()); + } + // + aPD=BRep_Tool::Pnt(aVD); + // + ++aNbDE; + } } - else if (aKNE==GEOMAlgo_KN_SEGMENT) { - if (BRep_Tool::IsClosed(aE, aF)) { - ++aNbSE; - } + } + // + if ((aNbCE==2 || (aNbCE==1 && aNbDE==1)) && aNbSE==1) { + if (aNbDE==1) { + aPC[1]=aPD; + aR[1]=0.; } - else if (aKSE==GEOMAlgo_KS_DEGENERATED) { - aIt.Initialize(aE); - for (; aIt.More(); aIt.Next()) { - aVD=TopoDS::Vertex(aIt.Value()); - break; - } - // - aPD=BRep_Tool::Pnt(aVD); - // - ++aNbDE; + // + aHeight=aPC[0].Distance(aPC[1]); + // + + gp_Ax2 aAx2new; + // + if (aR[0]>aR[1]) { + aRmin=aR[1]; + aRmax=aR[0]; + aPc=aPC[0]; + gp_Vec aVz(aPC[0], aPC[1]); + gp_Vec aVx(aPC[0], aPX[0]); + gp_Dir aDz(aVz); + gp_Dir aDx(aVx); + gp_Ax2 aAx2(aPc, aDz, aDx); + aAx2new=aAx2; } - } - } - // - if (!((aNbCE==2 || (aNbCE==1 && aNbDE==1)) && aNbSE==1)) { - return; - } - // - if (aNbDE==1) { - aPC[1]=aPD; - aR[1]=0.; - } + else { + aRmin=aR[0]; + aRmax=aR[1]; + aPc=aPC[1]; + gp_Vec aVz(aPC[1], aPC[0]); + gp_Vec aVx(aPC[1], aPX[1]); + gp_Dir aDz(aVz); + gp_Dir aDx(aVx); + gp_Ax2 aAx2(aPc, aDz, aDx); + aAx2new=aAx2; + } + // + gp_Ax3 aAx3(aAx2new); + aInfo.SetLocation(aPc); + aInfo.SetPosition(aAx3); + aInfo.SetRadius1(aRmax); + aInfo.SetRadius2(aRmin); + aInfo.SetHeight(aHeight); + // + aInfo.SetKindOfDef(GEOMAlgo_KD_SPECIFIED); + return; + }//if ((aNbCE==2 || (aNbCE==1 && aNbDE==1)) && aNbSE==1) { + }//if (aNbV==2 && aNbE==3) { // - aHeight=aPC[0].Distance(aPC[1]); - // - Standard_Real aRmin, aRmax; - gp_Ax2 aAx2new; - // - if (aR[0]>aR[1]) { - aRmin=aR[1]; - aRmax=aR[0]; - aPc=aPC[0]; - gp_Vec aVz(aPC[0], aPC[1]); - gp_Vec aVx(aPC[0], aPX[0]); - gp_Dir aDz(aVz); - gp_Dir aDx(aVx); - gp_Ax2 aAx2(aPc, aDz, aDx); - aAx2new=aAx2; - } - else { - aRmin=aR[0]; - aRmax=aR[1]; - aPc=aPC[1]; - gp_Vec aVz(aPC[1], aPC[0]); - gp_Vec aVx(aPC[1], aPX[1]); - gp_Dir aDz(aVz); - gp_Dir aDx(aVx); - gp_Ax2 aAx2(aPc, aDz, aDx); - aAx2new=aAx2; - } + aInfo.SetRadius1 (aCone.RefRadius()); // - gp_Ax3 aAx3(aAx2new); - aInfo.SetLocation(aPc); - aInfo.SetPosition(aAx3); - aInfo.SetRadius1(aRmax); + aRmin=0.; // ZZ aInfo.SetRadius2(aRmin); - aInfo.SetHeight(aHeight); - // - aInfo.SetKindOfName(GEOMAlgo_KN_CONE); } //======================================================================= //function : FillDetails -//purpose : +//purpose : //======================================================================= - void GEOMAlgo_ShapeInfoFiller::FillDetails(const TopoDS_Face& aF, - const gp_Cylinder& aCyl) +void GEOMAlgo_ShapeInfoFiller::FillDetails(const TopoDS_Face& aF, + const gp_Torus& ) { - Standard_Integer i, aNbV, aNbE, aNbCE, aNbSE; - Standard_Real aT0, aT1, aHeight; - gp_Pnt aPC[3], aPc; + + Standard_Integer aNbV, aNbE, aNbSE; TopoDS_Edge aE; TopExp_Explorer aExp; TopTools_MapOfShape aM; GEOMAlgo_KindOfShape aKS; - GEOMAlgo_KindOfName aKN, aKNE; - GEOMAlgo_KindOfClosed aKCE; - // + // GEOMAlgo_ShapeInfo& aInfo=myMapInfo.ChangeFromKey(aF); - aKN=GEOMAlgo_KN_UNKNOWN; - aInfo.SetKindOfName(aKN); + aInfo.SetKindOfDef(GEOMAlgo_KD_ARBITRARY); // aKS=aInfo.KindOfShape(); - if (aKS!=GEOMAlgo_KS_CYLINDER) { - return; - } - // - if (aInfo.KindOfBounds()==GEOMAlgo_KB_INFINITE) { + if (aKS!=GEOMAlgo_KS_TORUS) { return; } - // + aNbV=aInfo.NbSubShapes(TopAbs_VERTEX); - aNbE=aInfo.NbSubShapes(TopAbs_EDGE); - if (!(aNbV==2 && aNbE==3)) { - return; + aNbE=aInfo.NbSubShapes(TopAbs_EDGE); + + if (aNbV==1 && aNbE==2) { + aNbSE=0; + aExp.Init(aF, TopAbs_EDGE); + for (; aExp.More(); aExp.Next()) { + aE=TopoDS::Edge(aExp.Current()); + if (aM.Add(aE)) { + if (BRep_Tool::IsClosed(aE, aF)) { + ++aNbSE; + } + } + } + // + if (aNbSE==2) { + aInfo.SetKindOfDef(GEOMAlgo_KD_SPECIFIED); + } } +} +//======================================================================= +//function : TreatStepSphere +//purpose : +//======================================================================= +Standard_Boolean GEOMAlgo_ShapeInfoFiller::TreatStepSphere + (const TopoDS_Solid& aSd) +{ + Standard_Boolean bRet, bIsAllowedType, bOnlyClosed, bIsEqual; + Standard_Integer j; + Standard_Real aTol; + Standard_Real aVolume, aVolumeS, dV, aArea, aAreaS, dA; + gp_Sphere aSphere[2]; + GeomAbs_SurfaceType aST; + Handle(Geom_Surface) aS; + GeomAdaptor_Surface aGAS; + TopExp_Explorer aExp; // - i=0; - aNbCE=0; - aNbSE=0; - aExp.Init(aF, TopAbs_EDGE); - for (; aExp.More(); aExp.Next()) { - aE=TopoDS::Edge(aExp.Current()); - if(aM.Add(aE)) { - const GEOMAlgo_ShapeInfo& aInfoE=myMapInfo.FindFromKey(aE); - aKNE=aInfoE.KindOfName(); - aKCE=aInfoE.KindOfClosed(); - if (aKNE==GEOMAlgo_KN_CIRCLE && aKCE==GEOMAlgo_KC_CLOSED) { - aPC[aNbCE]=aInfoE.Location(); - ++aNbCE; - } - else if (aKNE==GEOMAlgo_KN_SEGMENT) { - if (BRep_Tool::IsClosed(aE, aF)) { - ++aNbSE; - } - } + bRet=Standard_False; + aTol=Precision::Confusion(); + // + aExp.Init(aSd, TopAbs_FACE); + for (j=0; aExp.More(); aExp.Next(), ++j) { + const TopoDS_Face& aF=*((TopoDS_Face*)&aExp.Current()); + aS=BRep_Tool::Surface(aF); + aGAS.Load(aS); + aST=aGAS.GetType(); + bIsAllowedType=GEOMAlgo_ShapeInfoFiller::IsAllowedType(aST); + if (!bIsAllowedType) { + return bRet; + } + // + if (aST!=GeomAbs_Sphere) { + return bRet; } + // + aSphere[j]=aGAS.Sphere(); } // - if (!(aNbCE==2 && aNbSE==1)) { - return; + bIsEqual=IsEqual(aSphere[0], aSphere[1], aTol); + if (!bIsEqual) { + return bRet; } // - const gp_Ax1& aAx1=aCyl.Axis(); - const gp_Dir& aDir=aAx1.Direction(); - const gp_Pnt& aPLoc=aAx1.Location(); - gp_Lin aLin(aPLoc, aDir); + //-------------------------------- + GProp_GProps aGProps; + // + bOnlyClosed=Standard_False; // - aT0=ElCLib::Parameter(aLin, aPC[0]); - aT1=ElCLib::Parameter(aLin, aPC[1]); + aVolume=aSphere[0].Volume(); + // + //modified by NIZNHY-PKV Tue Jun 09 08:39:47 2015f + BRepGProp::VolumeProperties(aSd, aGProps, aTol, bOnlyClosed); + //BRepGProp::VolumeProperties(aSd, aGProps, bOnlyClosed); + //modified by NIZNHY-PKV Tue Jun 09 08:39:50 2015t + aVolumeS=aGProps.Mass(); + if (aVolumeS<0.) { + aVolumeS=-aVolumeS; + } // - aPc=aPC[0];; - if (aT0>aT1) { - aPc=aPC[1]; + dV=fabs(aVolumeS-aVolume); + if (dV>aTol) { + return bRet; } - aHeight=aPC[0].Distance(aPC[1]); + //-------------------------------- + aArea=aSphere[0].Area(); // - gp_Ax3 aAx3=aCyl.Position(); - aAx3.SetLocation(aPc); + //modified by NIZNHY-PKV Tue Jun 09 08:23:54 2015f + BRepGProp::SurfaceProperties(aSd, aGProps, aTol); + //BRepGProp::SurfaceProperties(aSd, aGProps); + //modified by NIZNHY-PKV Tue Jun 09 08:23:56 2015t + aAreaS=aGProps.Mass(); // - aInfo.SetKindOfName(GEOMAlgo_KN_CYLINDER); + dA=fabs(aAreaS-aArea); + if (dA>aTol) { + return bRet; + } + // + //-------------------------------- + gp_Pnt aP0; + gp_Ax3 aAx3; + Standard_Real aR1; + // + aP0=aSphere[0].Location(); + aAx3=aSphere[0].Position(); + aR1=aSphere[0].Radius(); + // + GEOMAlgo_ShapeInfo& aInfo=myMapInfo.ChangeFromKey(aSd); + // + aInfo.SetKindOfName(GEOMAlgo_KN_SPHERE); + aInfo.SetLocation(aP0); aInfo.SetPosition(aAx3); - aInfo.SetLocation(aPc); - aInfo.SetHeight(aHeight); + aInfo.SetRadius1(aR1); + // + return !bRet;// true } - //======================================================================= -//function : FillDetails -//purpose : +//function : IsEqual +//purpose : //======================================================================= - void GEOMAlgo_ShapeInfoFiller::FillDetails(const TopoDS_Face& aF, - const gp_Torus& ) +Standard_Boolean IsEqual(const gp_Sphere& aSp1, + const gp_Sphere& aSp2, + const Standard_Real aTolLin) { - Standard_Integer aNbV, aNbE, aNbSE; - TopoDS_Edge aE; - TopExp_Explorer aExp; - TopTools_MapOfShape aM; - GEOMAlgo_KindOfShape aKS; + Standard_Boolean bRet; + Standard_Real aR1, aR2, aD2; // - GEOMAlgo_ShapeInfo& aInfo=myMapInfo.ChangeFromKey(aF); - aInfo.SetKindOfName(GEOMAlgo_KN_UNKNOWN); - // - aKS=aInfo.KindOfShape(); - if (aKS!=GEOMAlgo_KS_TORUS) { - return; + bRet=Standard_False; + aR1=aSp1.Radius(); + aR2=aSp2.Radius(); + if (fabs(aR1-aR2)>aTolLin) { + return bRet; } // - aNbV=aInfo.NbSubShapes(TopAbs_VERTEX); - aNbE=aInfo.NbSubShapes(TopAbs_EDGE); - if (!(aNbV==1 && aNbE==2)) { - return; - } + const gp_Pnt& aPC1=aSp1.Position().Location(); + const gp_Pnt& aPC2=aSp2.Position().Location(); // - aNbSE=0; - aExp.Init(aF, TopAbs_EDGE); - for (; aExp.More(); aExp.Next()) { - aE=TopoDS::Edge(aExp.Current()); - if (aM.Add(aE)) { - //const GEOMAlgo_ShapeInfo& aInfoE=myMapInfo.FindFromKey(aE); - if (BRep_Tool::IsClosed(aE, aF)) { - ++aNbSE; - } - } - } + aD2=aPC1.SquareDistance(aPC2); + bRet=(aD2