1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-14 13:30:48 +03:00

remarks # 1

This commit is contained in:
isn
2015-08-07 17:22:22 +03:00
parent ac867f3b74
commit 8596ce03fb

View File

@@ -124,7 +124,8 @@
#include <NCollection_DoubleMap.hxx>
#include <TColStd_ListOfInteger.hxx>
#include <NCollection_UBTree.hxx>
#include <NCollection_Array1.hxx>
#include <NCollection_Vector.hxx>
#include <TopTools_Array1OfShape.hxx>
#include <stdio.h>
#ifdef OCCT_DEBUG
@@ -170,13 +171,10 @@ public:
};
public:
BRepFill_BndBoxTreeSelector( TopTools_SequenceOfShape& theSeqOfEdges,
BRepFill_BndBoxTreeSelector( const TopTools_Array1OfShape& theSeqOfEdges,
const TopoDS_Face& theWFace)
: BRepFill_BndBoxTreeSelector::Selector(), mySeqOfEdges (theSeqOfEdges), myWFace (theWFace) {}
BRepFill_BndBoxTreeSelector(const BRepFill_BndBoxTreeSelector& );
BRepFill_BndBoxTreeSelector& operator=(const BRepFill_BndBoxTreeSelector& );
Standard_Boolean Reject (const Bnd_Box2d& theBox) const
{
return (myCBox.IsOut (theBox));
@@ -258,7 +256,7 @@ public:
double TolE1 = BRep_Tool::Tolerance(E1);
double TolE2 = BRep_Tool::Tolerance(E2);
myBuilder.MakeVertex(V, IntPnt, 1.01* ((TolE1 > TolE2 ? TolE1 : TolE2) + (p3d1.Distance(p3d2)/2.)));
myBuilder.MakeVertex(V, IntPnt, 1.01 * (::Max(TolE1, TolE2) + (p3d1.Distance(p3d2)/2.)));
NCollection_List<BRepFill_BndBoxTreeSelector::EdgeParam> aList;
BRepFill_BndBoxTreeSelector::EdgeParam ep;
@@ -386,7 +384,11 @@ public:
}
private:
TopTools_SequenceOfShape& mySeqOfEdges; //edges to be intersected with each other
BRepFill_BndBoxTreeSelector(const BRepFill_BndBoxTreeSelector& );
BRepFill_BndBoxTreeSelector& operator=(const BRepFill_BndBoxTreeSelector& );
private:
const TopTools_Array1OfShape& mySeqOfEdges; //edges to be intersected with each other
const TopoDS_Face& myWFace; //work spine face
NCollection_DataMap<TopoDS_Edge, NCollection_Sequence<double>> myOutMapOfResult; // map "edge to it's intersection parameters"
NCollection_List<BRepFill_BndBoxTreeSelector::EdgeParam> myListOfVertexEdgePar;
@@ -410,12 +412,6 @@ public:
{
//Poly_MakeLoops2D::Helper();
};
Poly_Helper(const Poly_Helper& theOther) : Poly_MakeLoops2D::Helper(theOther), mymN2V (theOther.mymN2V), mymV2E (theOther.mymV2E), mymPL2E (theOther.mymPL2E), mymE2EInfo (theOther.mymE2EInfo),
mymNode2ListOfLinks (theOther.mymNode2ListOfLinks)
{
};
Poly_Helper& operator= (const Poly_Helper &theOther);
virtual const Poly_MakeLoops2D::ListOfLink& GetAdjacentLinks (Standard_Integer theNode) const
{
@@ -435,6 +431,10 @@ public:
return true;
}
private:
Poly_Helper(const Poly_Helper& theOther);
Poly_Helper& operator= (const Poly_Helper &theOther);
private:
TopTools_IndexedMapOfShape& mymN2V; //map 'node to vertex'
TopTools_IndexedDataMapOfShapeListOfShape& mymV2E;
@@ -3080,26 +3080,14 @@ static void QuasiFleche(const Adaptor3d_Curve& C,
}
}
//! Used to remove loops from offset result
static bool RemoveLoops(TopoDS_Shape& theInputSh, const TopoDS_Face& theWorkSpine, const Handle(Geom_Plane)& theRefPlane )
static bool AddIntersectionVertices(const Handle_Geom_Plane& theRefPlane,
const TopoDS_Face& theWorkSpine,
const TopTools_Array1OfShape& Seq,
Handle(BRepTools_ReShape)& reshape,
TopoDS_Wire& aW,
TopTools_IndexedMapOfShape& EdgesInInter,
TopTools_MapOfShape& InterV )
{
Handle(BRepTools_ReShape) ExtReShape = new BRepTools_ReShape;
TopExp_Explorer Exp( theInputSh, TopAbs_WIRE );
for (; Exp.More(); Exp.Next())
{
Handle(BRepTools_ReShape) reshape = new BRepTools_ReShape;
TopoDS_Wire InitialW = TopoDS::Wire( Exp.Current() );
if (!InitialW.Closed())
continue;
TopoDS_Wire aW = TopoDS::Wire( Exp.Current() );
TopExp_Explorer ExpE( aW, TopAbs_EDGE );
TopTools_SequenceOfShape Seq;
for (; ExpE.More(); ExpE.Next())
Seq.Append( ExpE.Current() );
NCollection_DataMap<TopoDS_Edge, NCollection_Sequence<double>> ME2IP; //map edge to params on this edges
gp_Pln pl = theRefPlane->Pln();
@@ -3111,8 +3099,9 @@ static bool RemoveLoops(TopoDS_Shape& theInputSh, const TopoDS_Face& theWorkSpin
BRepFill_BndBoxTreeSelector aSelector(Seq, theWorkSpine);
// Prepare bounding boxes
NCollection_Sequence<Bnd_Box2d> BndBoxesOfEdges;
for (int i = 1; i <= Seq.Length(); i++)
int EdgeSize = Seq.Length();
NCollection_Array1<Bnd_Box2d> BndBoxesOfEdges(1, EdgeSize);
for (int i = 1; i <= EdgeSize; i++)
{
double f, l;
Handle_Geom2d_Curve aCur = BRep_Tool::CurveOnSurface(TopoDS::Edge(Seq(i)), theWorkSpine, f, l );
@@ -3120,7 +3109,7 @@ static bool RemoveLoops(TopoDS_Shape& theInputSh, const TopoDS_Face& theWorkSpin
BndLib_Add2dCurve::Add( aCur, f, l, 0., aBox );
//aBox.Enlarge(1e-4);
aTreeFiller.Add(i, aBox);
BndBoxesOfEdges.Append(aBox);
BndBoxesOfEdges.SetValue(i, aBox);
}
aTreeFiller.Fill();
@@ -3138,29 +3127,25 @@ static bool RemoveLoops(TopoDS_Shape& theInputSh, const TopoDS_Face& theWorkSpin
aSelector.GetListOfVertexEdgePar(LVEP);
if (ME2IP.IsEmpty())
continue; //if no intersection point => go to the next wire
TopTools_MapOfShape InterV;
TopTools_IndexedMapOfShape EdgesInInter;
return false; //if no intersection point => go to the next wire
for (NCollection_DataMap<TopoDS_Edge, NCollection_Sequence<double>>::Iterator aMapIt (ME2IP); aMapIt.More(); aMapIt.Next())
{
TopoDS_Edge E = aMapIt.Key();
NCollection_Sequence<double> Params = aMapIt.Value();
//NCollection_Sequence<double> Params = aMapIt.Value();
Handle_Geom_Curve aCur;
double f, l;
aCur = BRep_Tool::Curve(E, f, l );
//prepare params on the edge
NCollection_Sequence<double> ParamSeq;
NCollection_Sequence<double> ParamSeq = aMapIt.Value();
ParamSeq.Append(f);
ParamSeq.Append(l);
ParamSeq.Append(Params);
//ParamSeq.Append(Params);
//sort parameters
NCollection_QuickSort<NCollection_Sequence<double>, double>::Perform(ParamSeq, NCollection_Comparator<double>(), ParamSeq.Lower(), ParamSeq.Upper());
NCollection_Sequence<TopoDS_Vertex> aVOnEdge; //Vertexes on the edge which divide it in the intersection points into sequence of edges
NCollection_Sequence<TopoDS_Edge> NewEdgeSeq;
TopoDS_Vertex VF, VL;
VF = TopExp::FirstVertex(E);
VL = TopExp::LastVertex(E);
@@ -3186,13 +3171,14 @@ static bool RemoveLoops(TopoDS_Shape& theInputSh, const TopoDS_Face& theWorkSpin
aVOnEdge.Append(VL);
//Split old edge => Construct a new sequence of new edges
NCollection_Array1<TopoDS_Edge> NewEdgeSeq (1, aVOnEdge.Length() - 1);
TopoDS_Edge DE;
for (int j = 1; j < aVOnEdge.Length(); j++)
{
DE = BRepBuilderAPI_MakeEdge(aCur, aVOnEdge(j), aVOnEdge(j+1), ParamSeq(j), ParamSeq(j+1));
BRep_Builder BB;
BB.UpdateEdge(DE, BRep_Tool::Tolerance(E));
NewEdgeSeq.Append(DE);
NewEdgeSeq.SetValue(j, DE);
}
BRepBuilderAPI_MakeWire MW;
@@ -3208,10 +3194,17 @@ static bool RemoveLoops(TopoDS_Shape& theInputSh, const TopoDS_Face& theWorkSpin
}
aW = TopoDS::Wire(reshape->Apply(aW));
return true;
}
static bool AddAdditionalVertices( Handle(BRepTools_ReShape)& reshape,
TopoDS_Wire& aW,
TopTools_IndexedMapOfShape& EdgesInInter,
TopTools_MapOfShape& InterV )
{
bool Stat = true;
// Prepare wire for Poly_MakeLoops algo:
// Insert neccesary vertices if two edges shares same (two) vertices
bool Stat = true;
for (int i = 1; i <= EdgesInInter.Extent() && Stat; i++)
for (int j = i; j <= EdgesInInter.Extent() && Stat; j++)
{
@@ -3258,7 +3251,7 @@ static bool RemoveLoops(TopoDS_Shape& theInputSh, const TopoDS_Face& theWorkSpin
aW = TopoDS::Wire(reshape->Apply(aW));
// If edges contains only one vertex => insert another two vertices
ExpE.Init( aW, TopAbs_EDGE );
TopExp_Explorer ExpE( aW, TopAbs_EDGE );
for (; ExpE.More() && Stat; ExpE.Next())
{
TopoDS_Edge E = TopoDS::Edge(ExpE.Current());
@@ -3308,9 +3301,12 @@ static bool RemoveLoops(TopoDS_Shape& theInputSh, const TopoDS_Face& theWorkSpin
reshape->Replace(E, W.Oriented(E.Orientation()));
}
}
if (!Stat)
continue;
return Stat;
}
bool DoReorder( Handle(BRepTools_ReShape)& reshape,
TopoDS_Wire& aW)
{
//Perform reorder of wire
aW = TopoDS::Wire(reshape->Apply(aW));
Handle(ShapeExtend_WireData) aWireData = new ShapeExtend_WireData;
@@ -3338,18 +3334,21 @@ static bool RemoveLoops(TopoDS_Shape& theInputSh, const TopoDS_Face& theWorkSpin
bool IsDone = !aShFixWire->StatusReorder(ShapeExtend_FAIL);
if (!IsDone)
continue;
aW = aWireData->Wire();
if (Stat)
return false;
else
{
aW = TopoDS::Wire(reshape->Apply(aW));
aW = aWireData->Wire();
return true;
}
}
static bool ExtractLoopsFromWire(TopoDS_Wire& aW,
const TopoDS_Face& theWorkSpine,
NCollection_Vector<TopoDS_Wire>& aLoops)
{
// Prepare 'TopoLink' info for Poly_MakeLoops algo => Calculate derivatives of the edges
NCollection_DataMap<TopoDS_Edge, TopoLink> mE2EInfo;
ExpE.Init(aW, TopAbs_EDGE);
TopExp_Explorer ExpE(aW, TopAbs_EDGE);
for (; ExpE.More(); ExpE.Next())
{
TopoLink anEngeInfo;
@@ -3433,9 +3432,8 @@ static bool RemoveLoops(TopoDS_Shape& theInputSh, const TopoDS_Face& theWorkSpin
int NbHangs = aLoopMaker.GetNbHanging();
if (NbLoops == 0 || NbHangs != 0 )
continue;
return false;
NCollection_Sequence<TopoDS_Wire> aLoops;
for (int i = 1; i <= NbLoops; i++) //try to construct loops
{
Poly_MakeLoops2D::Loop aLoop = aLoopMaker.GetLoop(i);
@@ -3451,21 +3449,22 @@ static bool RemoveLoops(TopoDS_Shape& theInputSh, const TopoDS_Face& theWorkSpin
{
TopoDS_Wire W = aWM.Wire();
if (!W.Closed())
{
Stat = false;
break;
}
return false;
aLoops.Append(W);
}
}
return true;
}
if (!Stat)
continue;
static bool CollectNeccessaryLoops(const NCollection_Vector<TopoDS_Wire>& aLoops,
const Handle(Geom_Plane)& theRefPlane,
const TopoDS_Face& theWorkSpine,
TopoDS_Compound& Co)
{
// try to classify wires
NCollection_Sequence<TopoDS_Wire> InnerMWires; // interior wires
NCollection_Sequence<TopoDS_Wire> ExtMWires; //wires which defines a hole
for (int i = 1; i <= aLoops.Length(); i++)
NCollection_Vector<TopoDS_Wire> InnerMWires; // interior wires
NCollection_Vector<TopoDS_Wire> ExtMWires; //wires which defines a hole
for (int i = 0; i < aLoops.Length(); i++)
{
TopoDS_Face af = BRepBuilderAPI_MakeFace (theRefPlane, Precision::Confusion() ); //TopoDS::Face ( myWorkSpine.EmptyCopied() );
af.Orientation ( TopAbs_REVERSED );
@@ -3480,20 +3479,20 @@ static bool RemoveLoops(TopoDS_Shape& theInputSh, const TopoDS_Face& theWorkSpin
}
if (InnerMWires.Length() == ExtMWires.Length())
continue;
return false;
if (InnerMWires.Length() < ExtMWires.Length())
//probably incorrect orientation
continue;
return false;
//try to find an outer wire
int IndOfOuterW = -1;
for (int i = 1; i <= InnerMWires.Length(); i++)
for (int i = 0; i < InnerMWires.Length(); i++)
{
bool IsInside = true;
BRepBuilderAPI_MakeFace aDB(theRefPlane, InnerMWires(i));
TopoDS_Face aDummyFace = TopoDS::Face(aDB.Shape());
BRepTopAdaptor_FClass2d FClass(aDummyFace, Precision::PConfusion());
for (int j = 1; j <= InnerMWires.Length(); j++)
for (int j = 0; j < InnerMWires.Length(); j++)
{
if ( i == j )
continue;
@@ -3517,20 +3516,66 @@ static bool RemoveLoops(TopoDS_Shape& theInputSh, const TopoDS_Face& theWorkSpin
}
if (IndOfOuterW == -1)
continue; //cant find an outer wire
return false; //cant find an outer wire
TopoDS_Wire OuterWire = InnerMWires(IndOfOuterW);
//make compound: outer wire + holes
BRep_Builder BBC;
TopoDS_Compound Co;
BBC.MakeCompound(Co);
BBC.Add(Co, OuterWire);
for (int i = 1; i <= ExtMWires.Length(); i++)
for (int i = 0; i < ExtMWires.Length(); i++)
BBC.Add(Co, ExtMWires(i));
ExtReShape->Replace(InitialW, Co);
return true;
}
//! Used to remove loops from offset result
static bool RemoveLoops(TopoDS_Shape& theInputSh, const TopoDS_Face& theWorkSpine, const Handle(Geom_Plane)& theRefPlane )
{
Handle(BRepTools_ReShape) ExtReShape = new BRepTools_ReShape;
TopExp_Explorer Exp( theInputSh, TopAbs_WIRE );
for (; Exp.More(); Exp.Next())
{
Handle(BRepTools_ReShape) reshape = new BRepTools_ReShape;
TopoDS_Wire InitialW = TopoDS::Wire( Exp.Current() );
if (!InitialW.Closed())
continue;
TopoDS_Wire aW = TopoDS::Wire( Exp.Current() );
int NbEdges = 0;
TopExp_Explorer ExpE( aW, TopAbs_EDGE );
for (; ExpE.More(); ExpE.Next())
NbEdges++;
TopTools_Array1OfShape Seq (1, NbEdges);
ExpE.Init( aW, TopAbs_EDGE );
for (int i = 1; ExpE.More(); ExpE.Next(), i++ )
Seq.SetValue(i, ExpE.Current() );
TopTools_IndexedMapOfShape EdgesInInter;
TopTools_MapOfShape InterV;
if (!AddIntersectionVertices(theRefPlane, theWorkSpine, Seq, reshape, aW, EdgesInInter, InterV))
continue;
if (!AddAdditionalVertices(reshape, aW, EdgesInInter, InterV))
continue;
if (!DoReorder(reshape, aW))
continue;
NCollection_Vector<TopoDS_Wire> aLoops;
if (!ExtractLoopsFromWire (aW, theWorkSpine, aLoops))
continue;
TopoDS_Compound Co;
if (!CollectNeccessaryLoops(aLoops, theRefPlane, theWorkSpine, Co))
continue;
ExtReShape->Replace(InitialW, Co);
}
theInputSh = ExtReShape->Apply(theInputSh);