Loading files
// Created by: Peter KURNEV
// Copyright (c) 2010-2014 OPEN CASCADE SAS
// Copyright (c) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
// Copyright (c) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, CEDRAT,
// EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <BOPAlgo_PaveFiller.hxx>
#include <BOPDS_DS.hxx>
#include <BOPDS_FaceInfo.hxx>
#include <BOPDS_Pave.hxx>
#include <BOPDS_PaveBlock.hxx>
#include <BOPDS_ShapeInfo.hxx>
#include <BRep_Builder.hxx>
#include <BRep_Tool.hxx>
#include <Geom2d_Curve.hxx>
#include <Geom2d_Line.hxx>
#include <Geom2dAPI_ProjectPointOnCurve.hxx>
#include <Geom2dInt_GInter.hxx>
#include <gp_Pnt2d.hxx>
#include <IntRes2d_IntersectionPoint.hxx>
#include <IntTools_Context.hxx>
#include <Precision.hxx>
#include <Standard_Integer.hxx>
#include <NCollection_List.hxx>
#include <TopoDS_Edge.hxx>
#include <TopoDS_Face.hxx>
#include <TopoDS_Vertex.hxx>
static void MakeSplitEdge1(const TopoDS_Edge& aE,
const TopoDS_Face& aF,
const TopoDS_Vertex& aV1,
const double aP1,
const TopoDS_Vertex& aV2,
const double aP2,
TopoDS_Edge& aNewEdge);
static bool AddSplitPoint(const occ::handle<BOPDS_PaveBlock>& thePBD,
const BOPDS_Pave& thePave,
const double theTol);
//=================================================================================================
void BOPAlgo_PaveFiller::ProcessDE(const Message_ProgressRange& theRange)
{
Message_ProgressScope aPSOuter(theRange, nullptr, 1);
//
// 1. Find degenerated edges
//-----------------------------------------------------scope f
//
for (int anEdgeIndex = 0; anEdgeIndex < myDS->NbSourceShapes(); ++anEdgeIndex)
{
const BOPDS_ShapeInfo& anEdgeInfo = myDS->ShapeInfo(anEdgeIndex);
if (anEdgeInfo.ShapeType() != TopAbs_EDGE)
{
continue;
}
if (int nF = 0; anEdgeInfo.HasFlag(nF))
{
const BOPDS_ShapeInfo& aSIF = myDS->ShapeInfo(nF);
int nV = anEdgeInfo.SubShapes().First();
if (int nVSD = 0; myDS->HasShapeSD(nV, nVSD))
{
nV = nVSD;
}
if (aSIF.ShapeType() == TopAbs_FACE)
{
// 1. Find PaveBlocks that go through nV for nF
NCollection_List<occ::handle<BOPDS_PaveBlock>> aLPBOut(
NCollection_BaseAllocator::CommonBaseAllocator());
FindPaveBlocks(nV, nF, aLPBOut);
if (!aLPBOut.IsEmpty())
{
//
// 2.
NCollection_List<occ::handle<BOPDS_PaveBlock>>& aLPBD =
myDS->ChangePaveBlocks(anEdgeIndex);
Standard_ASSERT_VOID(!aLPBD.IsEmpty(), "ListOfPaveBlock is unexpectedly empty");
if (aLPBD.IsEmpty())
{
continue;
}
occ::handle<BOPDS_PaveBlock> aPBD = aLPBD.First();
//
FillPaves(nV, anEdgeIndex, nF, aLPBOut, aPBD);
//
myDS->UpdatePaveBlock(aPBD);
}
//
MakeSplitEdge(anEdgeIndex, nF);
}
if (aSIF.ShapeType() == TopAbs_EDGE)
{
const TopoDS_Edge& aDE = (*(TopoDS_Edge*)(&myDS->Shape(anEdgeIndex)));
const TopoDS_Vertex& aVn = (*(TopoDS_Vertex*)(&myDS->Shape(nV)));
//
TopoDS_Edge aE = aDE;
aE.EmptyCopy();
BRep_Builder BB;
BB.Add(aE, aVn);
BB.Degenerated(aE, true);
BB.UpdateEdge(aE, Precision::Confusion());
BOPDS_ShapeInfo aSI;
aSI.SetShapeType(TopAbs_EDGE);
aSI.SetShape(aE);
const int nEn = myDS->Append(aSI);
NCollection_List<occ::handle<BOPDS_PaveBlock>>& aLPBD = myDS->ChangePaveBlocks(anEdgeIndex);
occ::handle<BOPDS_PaveBlock> aPBD = aLPBD.First();
aPBD->SetEdge(nEn);
}
}
if (UserBreak(aPSOuter))
{
return;
}
}
}
//=================================================================================================
void BOPAlgo_PaveFiller::FindPaveBlocks(
const int thePaveIndex,
const int theFaceInfoIndex,
NCollection_List<occ::handle<BOPDS_PaveBlock>>& theFoundBlocks)
{
auto processPaveBlocks =
[thePaveIndex, &theFoundBlocks](
const NCollection_IndexedMap<occ::handle<BOPDS_PaveBlock>>& thePaveBlocksMap) {
for (int aBlockIndex = 1; aBlockIndex <= thePaveBlocksMap.Length(); ++aBlockIndex)
{
const occ::handle<BOPDS_PaveBlock>& aPaveBlock = thePaveBlocksMap(aBlockIndex);
int nV1, nV2;
aPaveBlock->Indices(nV1, nV2);
if (thePaveIndex == nV1 || thePaveIndex == nV2)
{
theFoundBlocks.Append(aPaveBlock);
}
}
};
const BOPDS_FaceInfo& aFaceInfo = myDS->ChangeFaceInfo(theFaceInfoIndex);
processPaveBlocks(aFaceInfo.PaveBlocksIn());
processPaveBlocks(aFaceInfo.PaveBlocksOn());
processPaveBlocks(aFaceInfo.PaveBlocksSc());
}
//=================================================================================================
void BOPAlgo_PaveFiller::MakeSplitEdge(const int nDE, const int nDF)
{
int nSp, nV1, nV2, aNbPB;
double aT1, aT2;
TopoDS_Edge aDE, aSp;
TopoDS_Vertex aV1, aV2;
NCollection_List<occ::handle<BOPDS_PaveBlock>>::Iterator aItLPB;
BOPDS_ShapeInfo aSI;
//
aSI.SetShapeType(TopAbs_EDGE);
//
aDE = (*(TopoDS_Edge*)(&myDS->Shape(nDE)));
aDE.Orientation(TopAbs_FORWARD);
//
const TopoDS_Face& aDF = (*(TopoDS_Face*)(&myDS->Shape(nDF)));
//
NCollection_List<occ::handle<BOPDS_PaveBlock>>& aLPB = myDS->ChangePaveBlocks(nDE);
aNbPB = aLPB.Extent();
//
aItLPB.Initialize(aLPB);
for (; aItLPB.More(); aItLPB.Next())
{
occ::handle<BOPDS_PaveBlock>& aPB = aItLPB.ChangeValue();
//
const BOPDS_Pave& aPave1 = aPB->Pave1();
aPave1.Contents(nV1, aT1);
//
const BOPDS_Pave& aPave2 = aPB->Pave2();
aPave2.Contents(nV2, aT2);
//
if (myDS->IsNewShape(nV1) || aNbPB > 1)
{
aV1 = (*(TopoDS_Vertex*)(&myDS->Shape(nV1)));
aV1.Orientation(TopAbs_FORWARD);
//
aV2 = (*(TopoDS_Vertex*)(&myDS->Shape(nV2)));
aV2.Orientation(TopAbs_REVERSED);
//
MakeSplitEdge1(aDE, aDF, aV1, aT1, aV2, aT2, aSp);
//
aSI.SetShape(aSp);
nSp = myDS->Append(aSI);
aPB->SetEdge(nSp);
}
else
{
myDS->ChangeShapeInfo(nDE).SetReference(-1);
aLPB.Clear();
break;
}
}
}
//=======================================================================
// function : FillPaves
// purpose : Find all pave blocks passing through the vertex <nVD> and
// intersecting the 2D curve of the degenerated edge
// somewhere in the middle. Save intersection points into
// Extra paves of the pave block of degenerated edge for future
// splitting.
//=======================================================================
void BOPAlgo_PaveFiller::FillPaves(const int nVD,
const int nED,
const int nFD,
const NCollection_List<occ::handle<BOPDS_PaveBlock>>& aLPBOut,
const occ::handle<BOPDS_PaveBlock>& aPBD)
{
// Prepare pave to put to pave block as an Extra pave
BOPDS_Pave aPave;
aPave.SetIndex(nVD);
//
const TopoDS_Vertex& aDV = (*(TopoDS_Vertex*)(&myDS->Shape(nVD)));
const TopoDS_Edge& aDE = (*(TopoDS_Edge*)(&myDS->Shape(nED)));
const TopoDS_Face& aDF = (*(TopoDS_Face*)(&myDS->Shape(nFD)));
//
double aTolV = BRep_Tool::Tolerance(aDV);
const BRepAdaptor_Surface& aBAS = myContext->SurfaceAdaptor(aDF);
//
// 2D intersection tolerance should be computed as a resolution
// from the tolerance of vertex to resolve the touching cases
double aTolInt = Precision::PConfusion();
// UResolution from the tolerance of the vertex
double aURes = aBAS.UResolution(aTolV);
// VResolution from the tolerance of the vertex
double aVRes = aBAS.VResolution(aTolV);
//
aTolInt = std::max(aTolInt, std::max(aURes, aVRes));
//
// Parametric tolerance to compare intersection point with boundaries
// should be computed as a resolution from the tolerance of vertex
// in the direction of the 2D curve of degenerated edge
double aTolCmp = Precision::PConfusion();
// Get 2D curve
double aTD1, aTD2;
occ::handle<Geom2d_Curve> aC2DDE = BRep_Tool::CurveOnSurface(aDE, aDF, aTD1, aTD2);
if (aC2DDE.IsNull())
{
return;
}
// Get direction of the curve
bool bUDir =
std::abs(aC2DDE->Value(aTD1).Y() - aC2DDE->Value(aTD2).Y()) < Precision::PConfusion();
//
aTolCmp = std::max(aTolCmp, (bUDir ? aURes : aVRes));
//
// Prepare adaptor for the degenerated edge for intersection
Geom2dAdaptor_Curve aGAC1;
aGAC1.Load(aC2DDE, aTD1, aTD2);
//
NCollection_List<occ::handle<BOPDS_PaveBlock>>::Iterator aItLPB(aLPBOut);
for (; aItLPB.More(); aItLPB.Next())
{
const occ::handle<BOPDS_PaveBlock>& aPB = aItLPB.Value();
int nE = aPB->Edge();
if (nE < 0)
{
continue;
}
const TopoDS_Edge& aE = (*(TopoDS_Edge*)(&myDS->Shape(nE)));
double aT1, aT2;
occ::handle<Geom2d_Curve> aC2D = BRep_Tool::CurveOnSurface(aE, aDF, aT1, aT2);
if (aC2D.IsNull())
{
continue;
}
//
// Prepare adaptor for the passing edge for intersection
Geom2dAdaptor_Curve aGAC2;
//
occ::handle<Geom2d_Line> aL2D = occ::down_cast<Geom2d_Line>(aC2D);
if (!aL2D.IsNull())
{
aGAC2.Load(aC2D);
}
else
{
aGAC2.Load(aC2D, aT1, aT2);
}
// Intersection
Geom2dInt_GInter aGInter(aGAC1, aGAC2, aTolInt, aTolInt);
if (aGInter.IsDone() && aGInter.NbPoints())
{
// Analyze intersection points
int i, aNbPoints = aGInter.NbPoints();
for (i = 1; i <= aNbPoints; ++i)
{
double aX = aGInter.Point(i).ParamOnFirst();
aPave.SetParameter(aX);
AddSplitPoint(aPBD, aPave, aTolCmp);
}
}
else
{
// If the intersection did not succeed, try the projection of the end point
// of the curve corresponding to the vertex of degenerated edge
double aT =
(nVD == aPB->Pave1().Index() ? aPB->Pave1().Parameter() : aPB->Pave2().Parameter());
gp_Pnt2d aP2d = aC2D->Value(aT);
Geom2dAPI_ProjectPointOnCurve aProj2d(aP2d, aC2DDE, aTD1, aTD2);
if (aProj2d.NbPoints())
{
double aX = aProj2d.LowerDistanceParameter();
aPave.SetParameter(aX);
AddSplitPoint(aPBD, aPave, aTolCmp);
}
}
}
}
//=================================================================================================
void MakeSplitEdge1(const TopoDS_Edge& aE,
const TopoDS_Face& aF,
const TopoDS_Vertex& aV1,
const double aP1,
const TopoDS_Vertex& aV2,
const double aP2,
TopoDS_Edge& aNewEdge)
{
double aTol = 1.e-7;
TopoDS_Edge E = aE;
E.EmptyCopy();
BRep_Builder BB;
BB.Add(E, aV1);
BB.Add(E, aV2);
BB.Range(E, aF, aP1, aP2);
BB.Degenerated(E, true);
BB.UpdateEdge(E, aTol);
aNewEdge = E;
}
//=======================================================================
// function: AddSplitPoint
// purpose: Validates the point represented by the pave <thePave>
// for the Pave Block <thePBD>.
// In case the point passes the checks it is added as an
// Extra Pave to the Pave Block for further splitting of the latter.
// Returns TRUE if the point is added, otherwise returns FALSE.
//=======================================================================
bool AddSplitPoint(const occ::handle<BOPDS_PaveBlock>& thePBD,
const BOPDS_Pave& thePave,
const double theTol)
{
double aTD1, aTD2;
thePBD->Range(aTD1, aTD2);
double aT = thePave.Parameter();
// Check that the parameter is inside the Pave Block
if (aT - aTD1 < theTol || aTD2 - aT < theTol)
{
return false;
}
// Check that the pave block does not contain the same parameter
int anInd;
if (thePBD->ContainsParameter(aT, theTol, anInd))
{
return false;
}
// Add the point as an Extra pave to the Pave Block for further
// splitting of the latter
thePBD->AppendExtPave1(thePave);
return true;
}
3d097a032This file is pinned to the selected release. Download the original to open it in your design tool.