EgtGeomKernel :

- miglioramenti a calcolo silhouette con CollisionAvoid compresa parallelizzazione
- piccole migliorie a CollisionAvoid
- migliorie e correzioni a CalcPocketing.
This commit is contained in:
Dario Sassi
2024-06-29 18:45:19 +02:00
parent 0f4be10330
commit dea96ccbcc
5 changed files with 193 additions and 79 deletions
+159 -39
View File
@@ -16,6 +16,8 @@
#include "GeoConst.h"
#include "/EgtDev/Include/EGkChainCurves.h"
#include "/EgtDev/Include/EGkOffsetCurve.h"
#include <thread>
#include <future>
using namespace std ;
@@ -43,7 +45,7 @@ CalcPoint( const Point3d& ptS, const Point3d& ptE, double dLevel,
double dDist = max( abs( ptS.x - ptE.x), abs( ptS.y - ptE.y)) ;
// Ricerca con metodo di bisezione (si arresta quando il medio è allineato agli estremi)
const int MAX_ITER = 8 ;
const int MAX_ITER = 10 ;
int nCount = 0 ;
Point3d ptP1 = ptS ;
Point3d ptP2 = ptE ;
@@ -53,10 +55,10 @@ CalcPoint( const Point3d& ptS, const Point3d& ptE, double dLevel,
ptMid.z = 0 ;
Point3d ptTest = GetToGlob( ptMid + cavTstm.GetToolHeight() * Z_AX, frGrid) ;
double dMove ;
const_cast<ICAvToolSurfTm*>( &cavTstm)->TestPosition( ptTest, frGrid.VersZ(), frGrid.VersZ(), dMove) ;
cavTstm.TestPosition( ptTest, frGrid.VersZ(), frGrid.VersZ(), dMove) ;
ptMid.z = dMove ;
// se sta sulla linea che unisce gli estremi, basta interpolazione lineare
if ( abs( ptMid.z - ( ptP1.z + ptP2.z) / 2) < 0.004 * dDist)
if ( abs( ptMid.z - ( ptP1.z + ptP2.z) / 2) < EPS_SMALL / 2)
return Media( ptP1, ptP2, ( ptP1.z - dLevel) / ( ptP1.z - ptP2.z)) ;
// altrimenti nuova suddivisione della parte con estremi da parte opposta rispetto al livello
bool b1On = ( ptP1.z > dLevel) ;
@@ -74,9 +76,7 @@ CalcPoint( const Point3d& ptS, const Point3d& ptE, double dLevel,
//----------------------------------------------------------------------------
static int
ProcessSquare( int nFlag, const Point3d ptP[4], double dLevel,
const ICAvToolSurfTm& cavTstm, const Frame3d &frGrid,
Point3d& ptL1s, Point3d& ptL1e, Point3d& ptL2s, Point3d& ptL2e)
ProcessSquare( int nFlag, int& nI1s, int& nI1e, int& nI2s, int& nI2e)
{
static int LineTable[16][5] = { { 0, -1, -1, -1, -1},
{ 1, 0, 3, -1, -1},
@@ -102,22 +102,16 @@ ProcessSquare( int nFlag, const Point3d ptP[4], double dLevel,
return 0 ;
// una linea
else if ( LineTable[nFlag][0] == 1) {
int nI1s = LineTable[nFlag][1] ;
int nI1e = LineTable[nFlag][2] ;
ptL1s = CalcPoint( ptP[nI1s], ptP[( nI1s + 1) % 4], dLevel, cavTstm, frGrid) ;
ptL1e = CalcPoint( ptP[nI1e], ptP[( nI1e + 1) % 4], dLevel, cavTstm, frGrid) ;
return ( AreSamePointApprox( ptL1s, ptL1e) ? 0 : 1) ;
nI1s = LineTable[nFlag][1] ;
nI1e = LineTable[nFlag][2] ;
return 1 ;
}
// due linee
else if ( LineTable[nFlag][0] == 2) {
int nI1s = LineTable[nFlag][1] ;
int nI1e = LineTable[nFlag][2] ;
ptL1s = CalcPoint( ptP[nI1s], ptP[( nI1s + 1) % 4], dLevel, cavTstm, frGrid) ;
ptL1e = CalcPoint( ptP[nI1e], ptP[( nI1e + 1) % 4], dLevel, cavTstm, frGrid) ;
int nI2s = LineTable[nFlag][3] ;
int nI2e = LineTable[nFlag][4] ;
ptL2s = CalcPoint( ptP[nI2s], ptP[( nI2s + 1) % 4], dLevel, cavTstm, frGrid) ;
ptL2e = CalcPoint( ptP[nI2e], ptP[( nI2e + 1) % 4], dLevel, cavTstm, frGrid) ;
nI1s = LineTable[nFlag][1] ;
nI1e = LineTable[nFlag][2] ;
nI2s = LineTable[nFlag][3] ;
nI2e = LineTable[nFlag][4] ;
return 2 ;
}
return -1 ;
@@ -125,15 +119,125 @@ ProcessSquare( int nFlag, const Point3d ptP[4], double dLevel,
//----------------------------------------------------------------------------
static bool
MarchingSquares( const DBLVECTOR& vdGrid, int nStepX, int nStepY, double dStep, double dLevel,
const ICAvToolSurfTm& cavTstm, const Frame3d &frGrid, POLYLINEVECTOR& vPL)
TestSubEdges( unordered_map<int, Point3d>& umEdgePnt, const INTVECTOR& vEdgeInd, int nFirst, int nLast,
const DBLVECTOR& vdGrid, int nStepX, double dStep,
double dLevel, const ICAvToolSurfTm& cavTstm, const Frame3d &frGrid)
{
for ( int k = nFirst ; k <= nLast ; ++ k) {
// recupero i differenti indici
int nKey = vEdgeInd[k] ;
int nInd = nKey / 2 ;
bool bOnX = ( ( nKey % 2) == 0) ;
int j = nInd / ( nStepX + 1) ;
int i = nInd % ( nStepX + 1) ;
// determino i punti estremi dell'edge
Point3d ptS{ i * dStep, j * dStep, vdGrid[nInd]} ;
Point3d ptE{ ptS.x + ( bOnX ? dStep : 0), ptS.y + ( bOnX ? 0 : dStep), vdGrid[nInd + ( bOnX ? 1 : nStepX + 1)]} ;
// calcolo il punto
Point3d ptQ = CalcPoint( ptS, ptE, dLevel, cavTstm, frGrid) ;
umEdgePnt[ nKey] = ptQ ;
}
return true ;
}
//----------------------------------------------------------------------------
static bool
MarchingSquares( const DBLVECTOR& vdGrid, int nStepX, int nStepY, double dStep, double dRad,
double dLevel, const ICAvToolSurfTm& cavTstm, const Frame3d &frGrid, POLYLINEVECTOR& vPL)
{
// Analizzo gli edge da cui passano le curve cercate
unordered_map<int, Point3d> umEdgePnt( 4 * ( nStepX + nStepY)) ;
INTVECTOR vEdgeInd ;
vEdgeInd.reserve( 4 * ( nStepX + nStepY)) ;
for ( int j = 0 ; j < nStepY ; ++ j) {
for ( int i = 0 ; i < nStepX ; ++ i) {
// indici dei vertici nella griglia
int nInd0 = i + j * ( nStepX + 1) ;
int nInd1 = ( i + 1) + j * ( nStepX + 1) ;
int nInd2 = ( i + 1) + ( j + 1) * ( nStepX + 1) ;
int nInd3 = i + ( j + 1) * ( nStepX + 1) ;
// flag del quadrato
bool bUp0 = ( vdGrid[nInd0] > dLevel) ;
bool bUp1 = ( vdGrid[nInd1] > dLevel) ;
bool bUp2 = ( vdGrid[nInd2] > dLevel) ;
bool bUp3 = ( vdGrid[nInd3] > dLevel) ;
// se tutti uguali, passo al successivo
if ( bUp0 == bUp1 && bUp0 == bUp2 && bUp0 == bUp3)
continue ;
// verifico quali calcolare
if ( bUp0 != bUp1) {
int nKey = 2 * nInd0 ;
if ( umEdgePnt.find( nKey) == umEdgePnt.end()) {
umEdgePnt[ nKey] = P_INVALID ;
vEdgeInd.emplace_back( nKey) ;
}
}
if ( bUp3 != bUp2) {
int nKey = 2 * nInd3 ;
if ( umEdgePnt.find( nKey) == umEdgePnt.end()) {
umEdgePnt[ nKey] = P_INVALID ;
vEdgeInd.emplace_back( nKey) ;
}
}
if ( bUp0 != bUp3) {
int nKey = 2 * nInd0 + 1 ;
if ( umEdgePnt.find( nKey) == umEdgePnt.end()) {
umEdgePnt[ nKey] = P_INVALID ;
vEdgeInd.emplace_back( nKey) ;
}
}
if ( bUp1 != bUp2) {
int nKey = 2 * nInd1 + 1 ;
if ( umEdgePnt.find( nKey) == umEdgePnt.end()) {
umEdgePnt[ nKey] = P_INVALID ;
vEdgeInd.emplace_back( nKey) ;
}
}
}
}
// Numero di edge da valutare
int nEdgeCnt = int( vEdgeInd.size()) ;
// Recupero il numero massimo di thread concorrenti
int nThreadMax = thread::hardware_concurrency() ;
bool bOk = true ;
// Se un solo thread o pochi punti
if ( nThreadMax <= 1 || nEdgeCnt < 50) {
TestSubEdges( umEdgePnt, vEdgeInd, 0, nEdgeCnt - 1, vdGrid, nStepX, dStep, dLevel, cavTstm, frGrid) ;
}
// altrimenti
else {
const int MAX_PARTS = 32 ;
INTINTVECTOR vFstLst( MAX_PARTS) ;
// calcolo le parti del vettore
int nPartCnt = min( nThreadMax, MAX_PARTS) ;
int nPartDim = nEdgeCnt / nPartCnt + 1 ;
for ( int i = 0 ; i < nPartCnt ; ++ i) {
vFstLst[i].first = i * nPartDim ;
vFstLst[i].second = min( ( i + 1) * nPartDim, nEdgeCnt) - 1 ;
}
// processo le parti
future<bool> vRes[MAX_PARTS] ;
for ( int i = 0 ; i < nPartCnt ; ++ i)
vRes[i] = async( launch::async, &TestSubEdges, ref( umEdgePnt), cref( vEdgeInd), vFstLst[i].first, vFstLst[i].second,
cref( vdGrid), nStepX, dStep, dLevel, cref( cavTstm), cref( frGrid)) ;
// attendo i risultati
int nFin = 0 ;
while ( nFin < nPartCnt) {
for ( int i = 0 ; i < nPartCnt ; ++ i) {
if ( vRes[i].valid() && vRes[i].wait_for( chrono::nanoseconds{ 1}) == future_status::ready) {
bOk = vRes[i].get() && bOk ;
++ nFin ;
}
}
}
}
// Predispongo il concatenamento
BIPNTVECTOR vBiPnt ;
vBiPnt.reserve( 2 * ( nStepX + nStepY)) ;
ChainCurves chainC ;
chainC.Init( false, EPS_SMALL, 2 * ( nStepX + nStepY)) ;
// Ciclo sui quadrati della griglia
// Ciclo sui quadrati da analizzare
for ( int j = 0 ; j < nStepY ; ++ j) {
for ( int i = 0 ; i < nStepX ; ++ i) {
// indici dei vertici nella griglia
@@ -146,25 +250,31 @@ MarchingSquares( const DBLVECTOR& vdGrid, int nStepX, int nStepY, double dStep,
( vdGrid[nInd1] > dLevel ? 2 : 0) +
( vdGrid[nInd2] > dLevel ? 4 : 0) +
( vdGrid[nInd3] > dLevel ? 8 : 0) ;
// punti di vertice del quadrato
Point3d ptP[4] = { { i * dStep, j * dStep, vdGrid[nInd0]},
{ ( i + 1) * dStep, j * dStep, vdGrid[nInd1]},
{ ( i + 1) * dStep, ( j + 1) * dStep, vdGrid[nInd2]},
{ i * dStep, ( j + 1) * dStep, vdGrid[nInd3]}} ;
// se quadrato con vertici tutti dello stesso tipo, passo al successivo
if ( nFlag == 0 || nFlag == 15)
continue ;
// chiavi
int vKey[4] = { 2 * nInd0, 2 * nInd1 + 1, 2 * nInd3, 2 * nInd0 + 1} ;
// calcolo segmenti da inserire
Point3d ptL1s, ptL1e, ptL2s, ptL2e ;
int nSegCnt = ProcessSquare( nFlag, ptP, dLevel, cavTstm, frGrid, ptL1s, ptL1e, ptL2s, ptL2e) ;
int nI1s, nI1e, nI2s, nI2e ;
int nSegCnt = ProcessSquare( nFlag, nI1s, nI1e, nI2s, nI2e) ;
if ( nSegCnt == -1)
return false ;
else if ( nSegCnt == 1) {
Point3d ptL1s = umEdgePnt.find( vKey[nI1s])->second ;
Point3d ptL1e = umEdgePnt.find( vKey[nI1e])->second ;
vBiPnt.emplace_back( ptL1s, ptL1e) ;
Vector3d vtDir1 = ptL1e - ptL1s ; vtDir1.Normalize() ;
chainC.AddCurve( int( vBiPnt.size()), ptL1s, vtDir1, ptL1e, vtDir1) ;
}
else if ( nSegCnt == 2) {
Point3d ptL1s = umEdgePnt.find( vKey[nI1s])->second ;
Point3d ptL1e = umEdgePnt.find( vKey[nI1e])->second ;
vBiPnt.emplace_back( ptL1s, ptL1e) ;
Vector3d vtDir1 = ptL1e - ptL1s ; vtDir1.Normalize() ;
chainC.AddCurve( int( vBiPnt.size()), ptL1s, vtDir1, ptL1e, vtDir1) ;
Point3d ptL2s = umEdgePnt.find( vKey[nI2s])->second ;
Point3d ptL2e = umEdgePnt.find( vKey[nI2e])->second ;
vBiPnt.emplace_back( ptL2s, ptL2e) ;
Vector3d vtDir2 = ptL2e - ptL2s ; vtDir2.Normalize() ;
chainC.AddCurve( int( vBiPnt.size()), ptL2s, vtDir2, ptL2e, vtDir2) ;
@@ -186,6 +296,10 @@ MarchingSquares( const DBLVECTOR& vdGrid, int nStepX, int nStepY, double dStep,
crvCompo.Close() ;
// elimino le parti allineate
crvCompo.MergeCurves( 10 * EPS_SMALL, ANG_TOL_STD_DEG) ;
// salto i contorni orari con area inferiore al doppio del quadrato
double dCmpArea ;
if ( ! crvCompo.GetAreaXY( dCmpArea) || ( dCmpArea < 0 && abs( dCmpArea) < 2 * dStep * dStep))
continue ;
// per test mettere a 1
#if 0
vPL.emplace_back( PolyLine()) ;
@@ -193,7 +307,7 @@ MarchingSquares( const DBLVECTOR& vdGrid, int nStepX, int nStepY, double dStep,
#else
// eseguo offset a sinistra pari allo step
OffsetCurve offsCompo ;
offsCompo.Make( &crvCompo, -( dStep - 10 * EPS_SMALL), ICurve::OFF_CHAMFER) ;
offsCompo.Make( &crvCompo, -( dRad - 2 * EPS_SMALL), ICurve::OFF_CHAMFER) ;
PtrOwner<ICurve> pCrvOffset( offsCompo.GetLongerCurve()) ;
if ( ! IsNull( pCrvOffset)) {
vPL.emplace_back( PolyLine()) ;
@@ -256,8 +370,9 @@ CAvSilhouetteSurfTm( const ISurfTriMesh& Stm, const Plane3d& plPlane, double dTo
}
// esecuzione della verifica
double dRad = SQRT1_2 * dTol ;
CAvToolSurfTm cavTstm ;
cavTstm.SetStdTool( dDimZ, dTol, 0) ;
cavTstm.SetStdTool( dDimZ, dRad, 0) ;
cavTstm.SetSurfTm( Stm) ;
if ( ! cavTstm.TestSeries( vPntM, frGrid.VersZ(), frGrid.VersZ(), -1))
return false ;
@@ -273,7 +388,7 @@ CAvSilhouetteSurfTm( const ISurfTriMesh& Stm, const Plane3d& plPlane, double dTo
// calcolo della silhouette con il metodo MarchingSquares
double dLevel = dLevelOffs ;
if ( ! MarchingSquares( vdGrid, nStepX, nStepY, dTol, dLevel, cavTstm, frGrid, vPL))
if ( ! MarchingSquares( vdGrid, nStepX, nStepY, dTol, dRad, dLevel, cavTstm, frGrid, vPL))
return false ;
// riporto nella corretta posizione le curve trovate
for ( auto& PL : vPL)
@@ -283,6 +398,8 @@ CAvSilhouetteSurfTm( const ISurfTriMesh& Stm, const Plane3d& plPlane, double dTo
}
//----------------------------------------------------------------------------
// Silhouette rispetto ad una direzione e sopra diverse quote di una superficie TriMesh
//----------------------------------------------------------------------------
ICAvParSilhouettesSurfTm*
CreateCAvParSilhouettesSurfTm( void)
@@ -290,11 +407,9 @@ CreateCAvParSilhouettesSurfTm( void)
return static_cast<ICAvParSilhouettesSurfTm*> ( new(nothrow) CAvParSilhouettesSurfTm) ;
}
//----------------------------------------------------------------------------
// Silhouette rispetto ad una direzione e sopra diverse quote di una superficie TriMesh
//----------------------------------------------------------------------------
CAvParSilhouettesSurfTm::CAvParSilhouettesSurfTm( void)
: m_dTol( 100 * EPS_SMALL), m_nStepX( 0), m_nStepY( 0), m_dLevelOffs( 0), m_bGridOk( false)
: m_dTol( 100 * EPS_SMALL), m_nStepX( 0), m_nStepY( 0), m_dRad( m_dTol), m_dLevelOffs( 0), m_bGridOk( false)
{
}
@@ -305,6 +420,7 @@ CAvParSilhouettesSurfTm::SetData( const CISURFTMPVECTOR& vpStm, const Frame3d& f
m_vpStm = vpStm ;
m_frGrid = frPlanes ;
m_dTol = max( dTol, 100 * EPS_SMALL) ;
m_dRad = SQRT1_2 * m_dTol ;
m_nStepX = 0 ;
m_nStepY = 0 ;
m_dDimZ = 0 ;
@@ -317,7 +433,7 @@ CAvParSilhouettesSurfTm::SetData( const CISURFTMPVECTOR& vpStm, const Frame3d& f
bool
CAvParSilhouettesSurfTm::Prepare( void)
{
// ingombro delle superfici nel riferimento dei piani
// ingombro delle superfici nel riferimento dei piani
BBox3d b3All ;
Frame3d frInv = GetInvert( m_frGrid) ;
for ( auto pStm : m_vpStm) {
@@ -348,7 +464,7 @@ CAvParSilhouettesSurfTm::Prepare( void)
}
// esecuzione della verifica
if ( ! m_cavTstm.SetStdTool( m_dDimZ, m_dTol, 0))
if ( ! m_cavTstm.SetStdTool( m_dDimZ, m_dRad, 0))
return false ;
if ( m_vpStm.empty() || ! m_cavTstm.SetSurfTm( *( m_vpStm[0])))
return false ;
@@ -384,10 +500,14 @@ CAvParSilhouettesSurfTm::GetSilhouette( double dLevel, POLYLINEVECTOR& vPL)
// calcolo della silhouette con il metodo MarchingSquares
dLevel += m_dLevelOffs ;
if ( ! MarchingSquares( m_vdGrid, m_nStepX, m_nStepY, m_dTol, dLevel, m_cavTstm, m_frGrid, vPL))
double dCalcLevel = max( dLevel, 0.) ;
if ( ! MarchingSquares( m_vdGrid, m_nStepX, m_nStepY, m_dTol, m_dRad, dCalcLevel, m_cavTstm, m_frGrid, vPL))
return false ;
// riporto nella corretta posizione le curve trovate
for ( auto& PL : vPL)
for ( auto& PL : vPL) {
if ( dLevel < dCalcLevel - EPS_SMALL)
PL.Translate( Vector3d{ 0, 0, dLevel - dCalcLevel}) ;
PL.ToGlob( m_frGrid) ;
}
return true ;
}
+1
View File
@@ -36,6 +36,7 @@ class CAvParSilhouettesSurfTm : public ICAvParSilhouettesSurfTm
double m_dTol ;
int m_nStepX ;
int m_nStepY ;
double m_dRad ;
double m_dDimZ ;
double m_dLevelOffs ;
bool m_bGridOk ;
+5 -5
View File
@@ -121,7 +121,7 @@ CAvToolSurfTm::SetGenTool( const ICurveComposite* pToolOutline)
//----------------------------------------------------------------------------
bool
CAvToolSurfTm::TestPosition( const Point3d& ptT, const Vector3d& vtDir, const Vector3d& vtMove, double& dTotDist)
CAvToolSurfTm::TestPosition( const Point3d& ptT, const Vector3d& vtDir, const Vector3d& vtMove, double& dTotDist) const
{
// Se utensile non definito, errore
if ( m_Tool.GetType() == Tool::UNDEF)
@@ -387,7 +387,7 @@ CAvToolSurfTm::TestSubPath( int nId, PNTULIST& lPntM, const Vector3d& vtDir, dou
//----------------------------------------------------------------------------
bool
CAvToolSurfTm::MyTestMidPointHG( PNTULIST& lPntM, const PNTULIST::iterator& itPntMPrev, const PNTULIST::iterator& itPntMCurr,
const Point3d& ptPrev, const Point3d& ptCurr, const Vector3d& vtDir, double dLinTol, int nLev)
const Point3d& ptPrev, const Point3d& ptCurr, const Vector3d& vtDir, double dLinTol, int nLev) const
{
// se superato limite di ricursione, esco
const int MAX_LEV = 10 ;
@@ -419,7 +419,7 @@ CAvToolSurfTm::MyTestMidPointHG( PNTULIST& lPntM, const PNTULIST::iterator& itPn
//----------------------------------------------------------------------------
double
CAvToolSurfTm::MyTestPosition( Point3d& ptT, const Vector3d& vtDir, const Vector3d& vtMove)
CAvToolSurfTm::MyTestPosition( Point3d& ptT, const Vector3d& vtDir, const Vector3d& vtMove) const
{
double dTotDist = 0 ;
for ( auto pStm : m_vSTM) {
@@ -441,7 +441,7 @@ CAvToolSurfTm::MyTestPosition( Point3d& ptT, const Vector3d& vtDir, const Vector
//----------------------------------------------------------------------------
double
CAvToolSurfTm::MyTestPositionHG( Point3d& ptT, const Vector3d& vtDir)
CAvToolSurfTm::MyTestPositionHG( Point3d& ptT, const Vector3d& vtDir) const
{
// calcolo box utensile nel riferimento di movimento
BBox3d b3Tool ;
@@ -520,7 +520,7 @@ CAvToolSurfTm::PrepareHashGrid( void)
//----------------------------------------------------------------------------
int
CAvToolSurfTm::GetSurfInd( int nT)
CAvToolSurfTm::GetSurfInd( int nT) const
{
// verifico la presenza di almeno un intervallo
if ( m_vBaseInd.size() < 2)
+5 -5
View File
@@ -36,7 +36,7 @@ class CAvToolSurfTm : public ICAvToolSurfTm
{ return m_Tool.GetHeigth() ; }
const ICurveComposite& GetToolOutline( bool bApprox = false) const override
{ return ( bApprox ? m_Tool.GetApproxOutline() : m_Tool.GetOutline()) ;}
bool TestPosition( const Point3d& ptT, const Vector3d& vtDir, const Vector3d& vtMove, double& dTotDist) override ;
bool TestPosition( const Point3d& ptT, const Vector3d& vtDir, const Vector3d& vtMove, double& dTotDist) const override ;
bool TestSeries( PNTUVECTOR& vPntM, const Vector3d& vtDir, const Vector3d& vtMove, double dProgCoeff = 1) override ;
bool TestPath( PNTULIST& lPntM, const Vector3d& vtDir, const Vector3d& vtMove, double dLinTol, double dProgCoeff = 1) override ;
@@ -47,12 +47,12 @@ class CAvToolSurfTm : public ICAvToolSurfTm
private :
bool TestSubSeries( int nId, PNTUVECTOR& vPntM, const Vector3d& vtDir, int nFirst, int nLast, double dProgCoeff) ;
bool TestSubPath( int nId, PNTULIST& lPntM, const Vector3d& vtDir, double dLinTol, double dProgCoeff) ;
double MyTestPosition( Point3d& ptT, const Vector3d& vtDir, const Vector3d& vtMove) ;
double MyTestPositionHG( Point3d& ptT, const Vector3d& vtDir) ;
double MyTestPosition( Point3d& ptT, const Vector3d& vtDir, const Vector3d& vtMove) const ;
double MyTestPositionHG( Point3d& ptT, const Vector3d& vtDir) const ;
bool MyTestMidPointHG( PNTULIST& lPntM, const PNTULIST::iterator& itPntMPrev, const PNTULIST::iterator& itPntMCurr,
const Point3d& ptPrev, const Point3d& ptCurr, const Vector3d& vtDir, double dLinTol, int nLev) ;
const Point3d& ptPrev, const Point3d& ptCurr, const Vector3d& vtDir, double dLinTol, int nLev) const ;
bool PrepareHashGrid( void) ;
int GetSurfInd( int nT) ;
int GetSurfInd( int nT) const ;
private :
typedef std::vector<const SurfTriMesh*> CSURFTMPVECTOR ; // vettore di puntatori a const SurfTriMesh
+23 -30
View File
@@ -592,7 +592,7 @@ ExistOpenEdges( ISurfFlatRegion* pSfr, const PocketParams& PockParam, bool& bExi
//----------------------------------------------------
static bool
ComputeTrapezoidSpiralLeadInLeadOut( ICurveComposite* pCompo, const Vector3d& vtMainDir, bool bLeadIn,
PocketParams PockParams, bool& bIsOutsideRaw)
const PocketParams& PockParams, bool& bIsOutsideRaw)
{
// inizializzazione come interno al grezzo
bIsOutsideRaw = false ;
@@ -648,7 +648,7 @@ ComputeTrapezoidSpiralLeadInLeadOut( ICurveComposite* pCompo, const Vector3d& vt
//----------------------------------------------------
static bool
AdjustTrapezoidSpiralForLeadInLeadOut( ICurveComposite* pCompo, PocketParams PockParams)
AdjustTrapezoidSpiralForLeadInLeadOut( ICurveComposite* pCompo, const PocketParams& PockParams)
{
// recupero la direzione principale della svuotatura
Vector3d vtMainDir ;
@@ -675,8 +675,6 @@ AdjustTrapezoidSpiralForLeadInLeadOut( ICurveComposite* pCompo, PocketParams Poc
return true ;
}
//----------------------------------------------------------------------------
static bool
ExtendPathOnOpenEdge( ICurveComposite* pCrvPath, const PocketParams& PockParams, const Vector3d& vtN,
@@ -1668,7 +1666,7 @@ SetSpecialPtStartForOpenEdges( const ICurveComposite* pCrvOrig, const Frame3d& f
//----------------------------------------------------------------------------
static bool
AssignOpenCloseTmpPropToFirstOffsCurve( ICurveComposite* pCrv, const PocketParams PockParams,
AssignOpenCloseTmpPropToFirstOffsCurve( ICurveComposite* pCrv, const PocketParams& PockParams,
ICRVCOMPOPOVECTOR& vCrvLoops, INTVECTOR& vIndex, bool& bSomeOpen)
{
// controllo dei parametri
@@ -1742,7 +1740,7 @@ AssignOpenCloseTmpPropToFirstOffsCurve( ICurveComposite* pCrv, const PocketParam
static bool
SetPtStartForPath( ICurveComposite* pCrvOffsAct, const PocketParams& PockParams, const ISurfFlatRegion* pSrfToWork,
const Point3d& ptEndPrec, const Frame3d& frPocket, Point3d& ptStart,
Vector3d& vtMidOut, bool& bMidOut, int nOffs, ICurveComposite* pCrvOrig)
Vector3d& vtMidOut, bool& bMidOut, int nOffs, const ICurveComposite* pCrvOrig)
{
// ============================= INFO ==============================================================
// pCrvOffsAct -> Curva di Offset su cui cercare ptStart, vtMidOut, bMidOpen
@@ -1909,7 +1907,7 @@ SetAdvancedPtStartForPath( ICRVCOMPOPOVECTOR& vCrvOffsAct, const PocketParams& P
// cambio il suo punto d'inizio dell'Offset attuale
if ( SetPtStartForPath( vCrvOffsAct[i], PockParams, pSrfToWork, ptEndPrec, frPocket, ptStart,
vtMidOut, bMidOut, nOffs,
( int( vCrvOrigChunkLoops.size()) < i) ? vCrvOrigChunkLoops[i]->Clone() : nullptr))
( int( vCrvOrigChunkLoops.size()) < i ? Get( vCrvOrigChunkLoops[i]) : nullptr)))
vCrvOffsAct[i]->GetStartPoint( ptStart) ;
else
return false ;
@@ -3767,9 +3765,9 @@ ModifyBiArc( ICurve* pBiArcLink, double dToll, ICurveComposite* pNewBiArc)
//------------------------------------------------------------------------------
static bool
CalcBoundedSmootedLink( const Point3d& ptStart, const Vector3d& vtStart, const Point3d& ptEnd,
const Vector3d& vtEnd, double dParMeet, const ICRVCOMPOPOVECTOR& vOffIslands,
const PocketParams& PockParams, ICurveComposite* pCrvLink)
CalcBoundedSmoothedLink( const Point3d& ptStart, const Vector3d& vtStart, const Point3d& ptEnd,
const Vector3d& vtEnd, double dParMeet, const ICRVCOMPOPOVECTOR& vOffIslands,
const PocketParams& PockParams, ICurveComposite* pCrvLink)
{
// se senza smusso, ritorno tratto lineare
if ( ! PockParams.bSmooth)
@@ -3943,7 +3941,7 @@ CutCurveToConnect( ICurveComposite* pCrvS, ICurveComposite* pCrvE, const ICRVCOM
// calcolo il BiArco
PtrOwner<CurveComposite> ptBiArc( CreateBasicCurveComposite()) ;
if ( ! CalcBoundedSmootedLink( ptSE, vS, ptES, vE, 0.5, vFirstOffset, PockParams, ptBiArc) ||
if ( ! CalcBoundedSmoothedLink( ptSE, vS, ptES, vE, 0.5, vFirstOffset, PockParams, ptBiArc) ||
ptBiArc->GetCurveCount() == 0)
return false ;
@@ -4309,7 +4307,7 @@ RemoveExtraPartByMedialAxis( const ISurfFlatRegion* pChunkToCut, ICRVCOMPOPOVECT
if ( IsNull( pCrvLink))
return false ;
if ( ! CalcBoundedSmootedLink( ptS, vtS, ptE, vtE, 0.5, vOffsFirstCurve, PockParams, pCrvLink))
if ( ! CalcBoundedSmoothedLink( ptS, vtS, ptE, vtE, 0.5, vOffsFirstCurve, PockParams, pCrvLink))
if ( ! CalcBoundedLink( ptS, ptE, vOffsFirstCurve, pCrvLink))
return false ;
@@ -4318,8 +4316,8 @@ RemoveExtraPartByMedialAxis( const ISurfFlatRegion* pChunkToCut, ICRVCOMPOPOVECT
}
if ( ! AreSamePointEpsilon( ptEOriginal, ptSOriginal, EPS_SMALL) &&
! CalcBoundedSmootedLink( ptEOriginal, vtEOriginal, ptSOriginal, vtSOriginal, 0.5, vOffsFirstCurve,
PockParams, pCrvCoBackLink) &&
! CalcBoundedSmoothedLink( ptEOriginal, vtEOriginal, ptSOriginal, vtSOriginal, 0.5, vOffsFirstCurve,
PockParams, pCrvCoBackLink) &&
! CalcBoundedLink( ptEOriginal, ptSOriginal, vOffsFirstCurve, pCrvCoBackLink))
return false ;
@@ -4352,8 +4350,8 @@ RemoveExtraPartByMedialAxis( const ISurfFlatRegion* pChunkToCut, ICRVCOMPOPOVECT
if ( IsNull( pCrvPath1))
return false ;
if ( ! CalcBoundedSmootedLink( ptClosestOnPath, vtTanCpt, vPtCentroid[i], vtTanCpt, 0,
vOffsFirstCurve, PockParams, pCrvPath1) &&
if ( ! CalcBoundedSmoothedLink( ptClosestOnPath, vtTanCpt, vPtCentroid[i], vtTanCpt, 0,
vOffsFirstCurve, PockParams, pCrvPath1) &&
! CalcBoundedLink( ptClosestOnPath, vPtCentroid[i], vOffsFirstCurve, pCrvPath1))
return false ;
@@ -4619,7 +4617,7 @@ GetNewCurvetWithCentroid( const ICurveComposite* pCrvH1, const ICurveComposite*
}
// creo la circonferenza
if ( ! CalcBoundedSmootedLink( ptS, vtTanS, ptE, vtTanE, 0, VFirstOff, PockParams, pPath1))
if ( ! CalcBoundedSmoothedLink( ptS, vtTanS, ptE, vtTanE, 0, VFirstOff, PockParams, pPath1))
return false ;
Vector3d vtS_cir ; pPath1->GetStartDir( vtS_cir) ;
Vector3d vtS_CrvH1 ; pCrvH1->GetEndDir( vtS_CrvH1) ;
@@ -4664,8 +4662,8 @@ GetNewCurvetWithCentroid( const ICurveComposite* pCrvH1, const ICurveComposite*
}
// creo i due Biarchi
if ( ! CalcBoundedSmootedLink( ptS, vtTanS, ptE, vtTanS, 0.5, VFirstOff, PockParams, pPath1) ||
! CalcBoundedSmootedLink( ptE, vtTanS, ptS, vtTanS, 0.5, VFirstOff, PockParams, pPath2))
if ( ! CalcBoundedSmoothedLink( ptS, vtTanS, ptE, vtTanS, 0.5, VFirstOff, PockParams, pPath1) ||
! CalcBoundedSmoothedLink( ptE, vtTanS, ptS, vtTanS, 0.5, VFirstOff, PockParams, pPath2))
return false ;
// creo la nuova curva con il doppio Biarco
@@ -4817,10 +4815,10 @@ GetNewCurvetWithPath( const ICurveComposite* pCrvH1, const ICurveComposite* pCrv
}
// creo i due Biarchi
if ( ! CalcBoundedSmootedLink( ptS, vtTanS, ptE, vtTanE, 0.5, VFirstOff, PockParams, pPath1))
if ( ! CalcBoundedSmoothedLink( ptS, vtTanS, ptE, vtTanE, 0.5, VFirstOff, PockParams, pPath1))
if ( ! CalcBoundedLink( ptS, ptE, VFirstOff, pPath1))
return false ;
if ( ! CalcBoundedSmootedLink( ptH, vtH, ptS, vtTanS, 0.5, VFirstOff, PockParams, pPath2))
if ( ! CalcBoundedSmoothedLink( ptH, vtH, ptS, vtTanS, 0.5, VFirstOff, PockParams, pPath2))
if ( ! CalcBoundedLink( ptH, ptS, VFirstOff, pPath2))
return false ;
@@ -4850,7 +4848,7 @@ GetNewCurvetWithPath( const ICurveComposite* pCrvH1, const ICurveComposite* pCrv
pCrvToAdd->GetStartPoint( ptHE) ;
pCrvToAdd->GetStartDir( vtHE) ;
PtrOwner<ICurveComposite> pCrvBiArcHelper( CreateCurveComposite()) ;
if ( ! CalcBoundedSmootedLink( ptHS, vtHS, ptHE, vtHE, 0.5, VFirstOff, PockParams, pCrvBiArcHelper))
if ( ! CalcBoundedSmoothedLink( ptHS, vtHS, ptHE, vtHE, 0.5, VFirstOff, PockParams, pCrvBiArcHelper))
if ( ! CalcBoundedLink( ptHS, ptHE, VFirstOff, pCrvBiArcHelper))
return false ;
@@ -4870,7 +4868,7 @@ GetNewCurvetWithPath( const ICurveComposite* pCrvH1, const ICurveComposite* pCrv
pCrvH2->GetStartPoint( ptHE) ;
pCrvH2->GetStartDir( vtHE) ;
PtrOwner<ICurveComposite> pCrvBiArcHelper( CreateCurveComposite()) ;
if ( ! CalcBoundedSmootedLink( ptHS, vtHS, ptHE, vtHE, 0.5, VFirstOff, PockParams, pCrvBiArcHelper))
if ( ! CalcBoundedSmoothedLink( ptHS, vtHS, ptHE, vtHE, 0.5, VFirstOff, PockParams, pCrvBiArcHelper))
if ( ! CalcBoundedLink( ptHS, ptHE, VFirstOff, pCrvBiArcHelper) )
return false ;
@@ -5258,7 +5256,7 @@ CreateSpiralPocketingPath( ICRVCOMPOPOVECTOR& vOffs, ICURVEPOVECTOR& vLinks, con
if ( ! vOffs[i]->GetStartDir( vtS) || ! vOffs[i+1]->GetStartDir( vtE))
return false ;
// creo il bi-arco tra esse
if ( CalcBoundedSmootedLink( ptS, vtS, ptStartNext, vtE, 0.5, vOffsFirstCurve, PockParams, pCrvLink))
if ( CalcBoundedSmoothedLink( ptS, vtS, ptStartNext, vtE, 0.5, vOffsFirstCurve, PockParams, pCrvLink))
vLinks[i + 1].Set( pCrvLink) ; // aggiorno il collegamento
else
return false ;
@@ -5285,9 +5283,7 @@ CreateSpiralPocketingPath( ICRVCOMPOPOVECTOR& vOffs, ICURVEPOVECTOR& vLinks, con
// aggiorno il collegamento
vLinks[i+1].Set( Release( pCrvLink)) ;
}
}
return true ;
@@ -5418,7 +5414,7 @@ CalcSpiral( const ISurfFlatRegion* pSrfPock, const PocketParams& PockParams, int
bool bIsCircle = false ;
if ( ! OptimizedSpiralCirle( pCrvBorder, 50 * EPS_SMALL, dRad, ptCen, bIsCircle))
return false ;
if ( bIsCircle) {
if ( bIsCircle && dRad - dOffs > 10 * EPS_SMALL) {
double dIntRad = 0 ;
if ( nReg == 0) {
bool bOk = CalcCircleSpiral( ptCen, vtN, dRad - dOffs, dIntRad, PockParams, pMCrv, pRCrv) ;
@@ -5459,7 +5455,6 @@ CalcSpiral( const ISurfFlatRegion* pSrfPock, const PocketParams& PockParams, int
else
return true ;
}
}
// porto la superficie nel frame corrente
@@ -6202,9 +6197,7 @@ AddSpiralIn( const ISurfFlatRegion* pSrfPock, const ISurfFlatRegion* pSfrOrig,
// inserisco le curve nel vettore
vCrvCompoRes.emplace_back( Release( pMCrv)) ;
++ nReg ; // incremento il numero di regione progressiva
}
}
return true ;