mirror of
https://git.salome-platform.org/gitpub/modules/geom.git
synced 2024-12-25 17:00:35 +05:00
Rewrite local function ModifySurface of BlockFix_SphereSpaceModifier
This commit is contained in:
parent
8d33dd3a86
commit
d6f16273ad
@ -38,13 +38,17 @@
|
|||||||
#include <TopoDS_Edge.hxx>
|
#include <TopoDS_Edge.hxx>
|
||||||
#include <TopoDS_Face.hxx>
|
#include <TopoDS_Face.hxx>
|
||||||
#include <TopoDS_Vertex.hxx>
|
#include <TopoDS_Vertex.hxx>
|
||||||
|
#include <TopoDS_Iterator.hxx>
|
||||||
|
|
||||||
#include <BRep_Tool.hxx>
|
#include <BRep_Tool.hxx>
|
||||||
#include <BRep_Builder.hxx>
|
#include <BRep_Builder.hxx>
|
||||||
|
#include <BRepTools.hxx>
|
||||||
|
#include <BRepAdaptor_Curve2d.hxx>
|
||||||
|
#include <BRepTopAdaptor_FClass2d.hxx>
|
||||||
|
|
||||||
#include <BRepGProp.hxx>
|
#include <ElSLib.hxx>
|
||||||
#include <GProp_GProps.hxx>
|
#include <Geom_Circle.hxx>
|
||||||
|
#include <Geom_TrimmedCurve.hxx>
|
||||||
#include <Geom_SphericalSurface.hxx>
|
#include <Geom_SphericalSurface.hxx>
|
||||||
#include <Geom_RectangularTrimmedSurface.hxx>
|
#include <Geom_RectangularTrimmedSurface.hxx>
|
||||||
|
|
||||||
@ -87,64 +91,145 @@ void BlockFix_SphereSpaceModifier::SetTolerance(const Standard_Real Tol)
|
|||||||
//function : NewSurface
|
//function : NewSurface
|
||||||
//purpose :
|
//purpose :
|
||||||
//=======================================================================
|
//=======================================================================
|
||||||
static Standard_Boolean ModifySurface(const TopoDS_Face& aFace,
|
static Standard_Boolean ModifySurface(const TopoDS_Face& theFace,
|
||||||
const Handle(Geom_Surface)& aSurface,
|
const Handle(Geom_Surface)& theSurface,
|
||||||
Handle(Geom_Surface)& aNewSurface)
|
Handle(Geom_Surface)& theNewSurface)
|
||||||
{
|
{
|
||||||
Handle(Geom_Surface) S = aSurface;
|
TopoDS_Face aFace = theFace;
|
||||||
if(S->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) {
|
aFace.Orientation (TopAbs_FORWARD);
|
||||||
|
|
||||||
|
Handle(Geom_Surface) aNewSurface;
|
||||||
|
|
||||||
|
Handle(Geom_Surface) aSurf = theSurface;
|
||||||
|
if (aSurf->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) {
|
||||||
Handle(Geom_RectangularTrimmedSurface) RTS =
|
Handle(Geom_RectangularTrimmedSurface) RTS =
|
||||||
Handle(Geom_RectangularTrimmedSurface)::DownCast(S);
|
Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurf);
|
||||||
S = RTS->BasisSurface();
|
aSurf = RTS->BasisSurface();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(S->IsKind(STANDARD_TYPE(Geom_SphericalSurface))) {
|
if (aSurf->IsKind(STANDARD_TYPE(Geom_SphericalSurface))) {
|
||||||
Standard_Real Umin, Umax, Vmin, Vmax;
|
Standard_Real Umin, Umax, Vmin, Vmax;
|
||||||
ShapeAnalysis::GetFaceUVBounds(aFace,Umin, Umax, Vmin, Vmax);
|
ShapeAnalysis::GetFaceUVBounds (aFace, Umin, Umax, Vmin, Vmax);
|
||||||
Standard_Real PI2 = M_PI/2.;
|
Standard_Real PI2 = M_PI/2.;
|
||||||
if(Vmax > PI2 - Precision::PConfusion() || Vmin < -PI2+::Precision::PConfusion()) {
|
Handle(Geom_SphericalSurface) aSphere = Handle(Geom_SphericalSurface)::DownCast(aSurf);
|
||||||
Handle(Geom_SphericalSurface) aSphere = Handle(Geom_SphericalSurface)::DownCast(S);
|
gp_Sphere sp = aSphere->Sphere();
|
||||||
gp_Sphere sp = aSphere->Sphere();
|
Standard_Real Radius = sp.Radius();
|
||||||
//modified by jgv, 12.11.2012 for issue 21777//
|
gp_Ax3 ax3 = sp.Position();
|
||||||
Standard_Real Radius = sp.Radius();
|
gp_Pnt aCentre = sp.Location();
|
||||||
Standard_Real HalfArea = 2.*M_PI*Radius*Radius;
|
|
||||||
GProp_GProps Properties;
|
TopoDS_Wire aWire = BRepTools::OuterWire (aFace);
|
||||||
BRepGProp::SurfaceProperties(aFace, Properties);
|
BRepTopAdaptor_FClass2d aClassifier (aFace, Precision::PConfusion());
|
||||||
Standard_Real anArea = Properties.Mass();
|
TopTools_MapOfShape aEmap;
|
||||||
Standard_Real AreaTol = Radius*Radius*1.e-6;
|
const Standard_Real anOffsetValue = 0.01*M_PI;
|
||||||
if (anArea > HalfArea - AreaTol) //no chance to avoid singularity
|
for (Standard_Integer ii = 1; ii <= 2; ii++)
|
||||||
return Standard_False;
|
{
|
||||||
///////////////////////////////////////////////
|
TopoDS_Iterator itw (aWire);
|
||||||
gp_Ax3 ax3 = sp.Position();
|
for (; itw.More(); itw.Next())
|
||||||
if(Abs(Vmax-Vmin) < PI2) {
|
{
|
||||||
gp_Ax3 axnew3(ax3.Axis().Location(), ax3.Direction()^ax3.XDirection(),ax3.XDirection());
|
const TopoDS_Edge& anEdge = TopoDS::Edge (itw.Value());
|
||||||
sp.SetPosition(axnew3);
|
if (aEmap.Contains (anEdge) ||
|
||||||
Handle(Geom_SphericalSurface) aNewSphere = new Geom_SphericalSurface(sp);
|
anEdge.Orientation() == TopAbs_INTERNAL ||
|
||||||
aNewSurface = aNewSphere;
|
anEdge.Orientation() == TopAbs_EXTERNAL ||
|
||||||
return Standard_True;
|
BRep_Tool::Degenerated (anEdge) ||
|
||||||
}
|
BRepTools::IsReallyClosed (anEdge, aFace))
|
||||||
else {
|
continue;
|
||||||
gp_Pnt PC = ax3.Location();
|
|
||||||
Standard_Real Vpar;
|
BRepAdaptor_Curve2d aBAcurve2d (anEdge, aFace);
|
||||||
if(fabs(PI2-Vmax)>fabs(-PI2-Vmin))
|
GeomAbs_CurveType aType = aBAcurve2d.GetType();
|
||||||
Vpar = (PI2+Vmax)/2.;
|
if (ii == 1 && aType == GeomAbs_Line) //first pass: consider only curvilinear edges
|
||||||
else
|
continue;
|
||||||
Vpar = (-PI2+Vmin)/2.;
|
|
||||||
Standard_Real Upar = (Umin+Umax)/2.;;
|
Standard_Real aMidPar = (aBAcurve2d.FirstParameter() + aBAcurve2d.LastParameter())/2;
|
||||||
gp_Pnt PN,PX;
|
gp_Pnt2d aMidP2d;
|
||||||
S->D0(Upar,Vpar,PN);
|
gp_Vec2d aTangent;
|
||||||
S->D0(Upar+PI2,0.,PX);
|
aBAcurve2d.D1 (aMidPar, aMidP2d, aTangent);
|
||||||
gp_Dir newNorm(gp_Vec(PC,PN));
|
if (anEdge.Orientation() == TopAbs_REVERSED)
|
||||||
gp_Dir newDirX(gp_Vec(PC,PX));
|
aTangent.Reverse();
|
||||||
gp_Ax3 axnew3(ax3.Axis().Location(), newNorm, newDirX);
|
|
||||||
sp.SetPosition(axnew3);
|
aTangent.Normalize();
|
||||||
Handle(Geom_SphericalSurface) aNewSphere = new Geom_SphericalSurface(sp);
|
gp_Vec2d aNormal (aTangent.Y(), -aTangent.X());
|
||||||
aNewSurface = aNewSphere;
|
aNormal *= anOffsetValue;
|
||||||
return Standard_True;
|
gp_Pnt2d anUpperPole = aMidP2d.Translated (aNormal);
|
||||||
}
|
if (anUpperPole.Y() < -PI2 || anUpperPole.Y() > PI2)
|
||||||
}
|
{
|
||||||
|
aEmap.Add(anEdge);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (anUpperPole.X() < 0.)
|
||||||
|
anUpperPole.SetX (anUpperPole.X() + 2.*M_PI);
|
||||||
|
else if (anUpperPole.X() > 2.*M_PI)
|
||||||
|
anUpperPole.SetX (anUpperPole.X() - 2.*M_PI);
|
||||||
|
|
||||||
|
TopAbs_State aStatus = aClassifier.Perform (anUpperPole);
|
||||||
|
if (aStatus != TopAbs_OUT)
|
||||||
|
{
|
||||||
|
aEmap.Add(anEdge);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
gp_Pnt anUpperPole3d = aSphere->Value (anUpperPole.X(), anUpperPole.Y());
|
||||||
|
gp_Vec aVec (aCentre, anUpperPole3d);
|
||||||
|
aVec.Reverse();
|
||||||
|
gp_Pnt aLowerPole3d = aCentre.Translated (aVec);
|
||||||
|
Standard_Real aU, aV;
|
||||||
|
ElSLib::Parameters (sp, aLowerPole3d, aU, aV);
|
||||||
|
gp_Pnt2d aLowerPole (aU, aV);
|
||||||
|
aStatus = aClassifier.Perform (aLowerPole);
|
||||||
|
if (aStatus != TopAbs_OUT)
|
||||||
|
{
|
||||||
|
aEmap.Add(anEdge);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Build a meridian
|
||||||
|
gp_Vec anUp (aCentre, anUpperPole3d);
|
||||||
|
anUp.Normalize();
|
||||||
|
gp_Pnt aMidPnt = aSphere->Value (aMidP2d.X(), aMidP2d.Y());
|
||||||
|
gp_Vec aMidOnEdge (aCentre, aMidPnt);
|
||||||
|
aMidOnEdge.Normalize();
|
||||||
|
gp_Vec AxisOfCircle = anUp ^ aMidOnEdge;
|
||||||
|
gp_Vec XDirOfCircle = anUp ^ AxisOfCircle;
|
||||||
|
gp_Ax2 anAxis (aCentre, AxisOfCircle, XDirOfCircle);
|
||||||
|
Handle(Geom_Circle) aCircle = new Geom_Circle (anAxis, Radius);
|
||||||
|
Handle(Geom_TrimmedCurve) aMeridian = new Geom_TrimmedCurve (aCircle, -PI2, PI2);
|
||||||
|
|
||||||
|
//Check the meridian
|
||||||
|
Standard_Boolean IsInnerPointFound = Standard_False;
|
||||||
|
Standard_Integer NbSamples = 10;
|
||||||
|
Standard_Real aDelta = M_PI / NbSamples;
|
||||||
|
for (Standard_Integer jj = 1; jj < NbSamples; jj++)
|
||||||
|
{
|
||||||
|
Standard_Real aParam = -PI2 + jj*aDelta;
|
||||||
|
gp_Pnt aPnt = aMeridian->Value (aParam);
|
||||||
|
ElSLib::Parameters (sp, aPnt, aU, aV);
|
||||||
|
gp_Pnt2d aP2d (aU, aV);
|
||||||
|
aStatus = aClassifier.Perform (aP2d);
|
||||||
|
if (aStatus != TopAbs_OUT)
|
||||||
|
{
|
||||||
|
IsInnerPointFound = Standard_True;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (IsInnerPointFound)
|
||||||
|
{
|
||||||
|
aEmap.Add(anEdge);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
gp_Ax3 anAxisOfNewSphere (aCentre, anUp, XDirOfCircle);
|
||||||
|
aNewSurface = new Geom_SphericalSurface (anAxisOfNewSphere, Radius);
|
||||||
|
break;
|
||||||
|
} //for (; itw.More(); itw.Next()) (iteration on outer wire)
|
||||||
|
if (!aNewSurface.IsNull())
|
||||||
|
break;
|
||||||
|
} //for (Standard_Integer ii = 1; ii <= 2; ii++) (two passes)
|
||||||
}
|
}
|
||||||
return Standard_False;
|
|
||||||
|
if (aNewSurface.IsNull())
|
||||||
|
return Standard_False;
|
||||||
|
|
||||||
|
theNewSurface = aNewSurface;
|
||||||
|
return Standard_True;
|
||||||
}
|
}
|
||||||
|
|
||||||
Standard_Boolean BlockFix_SphereSpaceModifier::NewSurface(const TopoDS_Face& F,
|
Standard_Boolean BlockFix_SphereSpaceModifier::NewSurface(const TopoDS_Face& F,
|
||||||
|
Loading…
Reference in New Issue
Block a user