This commit is contained in:
jgv 2020-02-20 18:30:10 +03:00
parent 7c35075817
commit 7384cd8a0e

View File

@ -85,6 +85,33 @@
#include <TColgp_SequenceOfPnt2d.hxx>
static Standard_Real ComputeMaxTolOfFace(const TopoDS_Face& theFace)
{
Standard_Real MaxTol = BRep_Tool::Tolerance(theFace);
TopTools_IndexedMapOfShape aMap;
TopExp::MapShapes(theFace, TopAbs_EDGE, aMap);
for (Standard_Integer i = 1; i <= aMap.Extent(); i++)
{
const TopoDS_Edge& anEdge = TopoDS::Edge(aMap(i));
Standard_Real aTol = BRep_Tool::Tolerance(anEdge);
if (aTol > MaxTol)
MaxTol = aTol;
}
aMap.Clear();
TopExp::MapShapes(theFace, TopAbs_VERTEX, aMap);
for (Standard_Integer i = 1; i <= aMap.Extent(); i++)
{
const TopoDS_Vertex& aVertex = TopoDS::Vertex(aMap(i));
Standard_Real aTol = BRep_Tool::Tolerance(aVertex);
if (aTol > MaxTol)
MaxTol = aTol;
}
return MaxTol;
}
//=======================================================================
//function : FixResult
//purpose : auxiliary
@ -243,51 +270,85 @@ TopoDS_Shape BlockFix::RefillProblemFaces (const TopoDS_Shape& aShape)
TopTools_ListIteratorOfListOfShape itl(theFaces);
for (; itl.More(); itl.Next())
{
const TopoDS_Face& aFace = TopoDS::Face(itl.Value());
BRepOffsetAPI_MakeFilling Filler;
for (Explo.Init(aFace, TopAbs_EDGE); Explo.More(); Explo.Next())
TopoDS_Face aFace = TopoDS::Face(itl.Value());
aFace.Orientation(TopAbs_FORWARD);
Standard_Real MaxTolOfFace = ComputeMaxTolOfFace(aFace);
BRepAdaptor_Surface BAsurf(aFace, Standard_False);
BRepOffsetAPI_MakeFilling Filler(3, 10);
TopExp_Explorer Explo(aFace, TopAbs_EDGE);
for (; Explo.More(); Explo.Next())
{
const TopoDS_Edge& anEdge = TopoDS::Edge(Explo.Current());
if (!BRep_Tool::Degenerated(anEdge))
if (BRep_Tool::Degenerated(anEdge) ||
BRepTools::IsReallyClosed(anEdge, aFace))
continue;
Filler.Add(anEdge, GeomAbs_C0);
}
Standard_Real Umin, Umax, Vmin, Vmax;
BRepTools::UVBounds(aFace, Umin, Umax, Vmin, Vmax);
//Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace);
Standard_Integer i, j;
for (i = 1; i < NbSamples; i++)
for (j = 1; j < NbSamples; j++) {
/*
gp_Pnt aPoint = aSurf->Value(Umin + i*(Umax-Umin)/NbSamples,
Vmin + j*(Vmax-Vmin)/NbSamples);
Filler.Add(aPoint);
*/
Filler.Add(Umin + i*(Umax-Umin)/NbSamples,
Vmin + j*(Vmax-Vmin)/NbSamples,
aFace, GeomAbs_G1);
Standard_Real DeltaU = (Umax - Umin)/NbSamples,
DeltaV = (Vmax - Vmin)/NbSamples;
for (Standard_Integer i = 1; i < NbSamples; i++)
for (Standard_Integer j = 1; j < NbSamples; j++) {
Filler.Add(Umin + i*DeltaU, Vmin + j*DeltaV, aFace, GeomAbs_G1);
}
Filler.Build();
if (Filler.IsDone())
{
for (Explo.Init(aFace, TopAbs_EDGE); Explo.More(); Explo.Next())
TopoDS_Face aNewFace = TopoDS::Face(Filler.Shape());
aNewFace.Orientation(TopAbs_FORWARD);
Handle(Geom_Surface) aNewSurf = BRep_Tool::Surface(aNewFace);
GeomAdaptor_Surface GAnewsurf(aNewSurf);
Extrema_ExtPS Projector;
Projector.Initialize(GAnewsurf, GAnewsurf.FirstUParameter(), GAnewsurf.LastUParameter(),
GAnewsurf.FirstVParameter(), GAnewsurf.LastVParameter(),
Precision::Confusion(), Precision::Confusion());
Standard_Real MaxSqDist = 0.;
for (Standard_Integer i = 0; i < NbSamples; i++)
for (Standard_Integer j = 0; j < NbSamples; j++)
{
const TopoDS_Edge& anEdge = TopoDS::Edge(Explo.Current());
gp_Pnt aPoint = BAsurf.Value(Umin + DeltaU/2 + i*DeltaU,
Vmin + DeltaV/2 + j*DeltaV);
Projector.Perform(aPoint);
if (Projector.IsDone())
{
Standard_Real LocalMinSqDist = RealLast();
for (Standard_Integer ind = 1; ind <= Projector.NbExt(); ind++)
{
Standard_Real aSqDist = Projector.SquareDistance(ind);
if (aSqDist < LocalMinSqDist)
LocalMinSqDist = aSqDist;
}
if (!Precision::IsInfinite(LocalMinSqDist) &&
LocalMinSqDist > MaxSqDist)
MaxSqDist = LocalMinSqDist;
}
}
Standard_Real MaxDist = Sqrt(MaxSqDist);
if (MaxDist < Max(1.e-4, 1.5*MaxTolOfFace))
{
TopTools_IndexedMapOfShape Emap;
TopExp::MapShapes(aFace, TopAbs_EDGE, Emap);
for (Standard_Integer i = 1; i <= Emap.Extent(); i++)
{
TopoDS_Edge anEdge = TopoDS::Edge(Emap(i));
anEdge.Orientation(TopAbs_FORWARD);
TopTools_ListOfShape Ledge;
if (!BRep_Tool::Degenerated(anEdge))
if (!BRep_Tool::Degenerated(anEdge) &&
!BRepTools::IsReallyClosed(anEdge, aFace))
{
const TopTools_ListOfShape& Ledges = Filler.Generated(anEdge);
if (!Ledges.IsEmpty()) {
TopoDS_Shape NewEdge = Ledges.First();
TopoDS_Edge NewEdge = TopoDS::Edge(Ledges.First());
Ledge.Append(NewEdge.Oriented(TopAbs_FORWARD));
}
}
aSubst.Substitute(anEdge, Ledge);
}
TopTools_ListOfShape Lface;
TopoDS_Face NewFace = TopoDS::Face(Filler.Shape());
NewFace.Orientation(TopAbs_FORWARD);
BRepAdaptor_Surface NewBAsurf(NewFace);
BRepAdaptor_Surface NewBAsurf(aNewFace);
gp_Pnt MidPnt;
gp_Vec D1U, D1V, Normal, NewNormal;
Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace);
@ -298,11 +359,12 @@ TopoDS_Shape BlockFix::RefillProblemFaces (const TopoDS_Shape& aShape)
MidPnt, D1U, D1V);
NewNormal = D1U ^ D1V;
if (Normal * NewNormal < 0.)
NewFace.Reverse();
Lface.Append(NewFace);
aNewFace.Reverse();
Lface.Append(aNewFace);
aSubst.Substitute(aFace, Lface);
}
}
}
aSubst.Build(aShape);
TopoDS_Shape Result = aShape;