EgtGeomKernel 2.5g3 :
- migliorata gestione approssimazione con archi.
This commit is contained in:
+23
-11
@@ -20,6 +20,7 @@
|
||||
#include "/EgtDev/Include/EGkCurveComposite.h"
|
||||
#include "/EgtDev/Include/EGkArcSpecial.h"
|
||||
#include "/EgtDev/Include/EGkDistPointCurve.h"
|
||||
#include "/EgtDev/Include/EgtNumUtils.h"
|
||||
#include "/EgtDev/Include/EgtPointerOwner.h"
|
||||
|
||||
using namespace std ;
|
||||
@@ -97,7 +98,7 @@ GetBiArc( const Point3d& ptP0, double dDir0Deg, const Point3d& ptP1, double dDir
|
||||
CurveArc* pArc = GetBasicCurveArc( pJCrv) ;
|
||||
if ( pArc == nullptr)
|
||||
return nullptr ;
|
||||
double dU = - 1 ;
|
||||
double dU = -1 ;
|
||||
double dRad = pArc->GetRadius() ;
|
||||
double dSqRad = dRad * dRad ;
|
||||
Point3d ptCen = pArc->GetCenter() ;
|
||||
@@ -121,9 +122,11 @@ GetBiArc( const Point3d& ptP0, double dDir0Deg, const Point3d& ptP1, double dDir
|
||||
}
|
||||
}
|
||||
}
|
||||
// elimino casi vicino agli estremi, danno solo problemi
|
||||
if ( dU < 0.1 || dU > 0.9)
|
||||
// non c'è intersezione, assegno valore medio
|
||||
if ( dU < -0.5)
|
||||
dU = 0.5 ;
|
||||
// elimino casi vicino agli estremi, danno solo problemi
|
||||
dU = Clamp( dU, 0.1, 0.9) ;
|
||||
pBiArc.Set( GetBiArc( ptP0, dDir0Deg, ptP1, dDir1Deg, dU)) ;
|
||||
}
|
||||
|
||||
@@ -132,15 +135,24 @@ GetBiArc( const Point3d& ptP0, double dDir0Deg, const Point3d& ptP1, double dDir
|
||||
return nullptr ;
|
||||
|
||||
// determino la massima distanza tra la curva e il biarco
|
||||
Point3d ptP ;
|
||||
double dSqDist = 0 ;
|
||||
for ( bool bPnt = PL.GetFirstPoint( ptP) ;
|
||||
bPnt ;
|
||||
bPnt = PL.GetNextPoint( ptP)) {
|
||||
DistPointCurve dstPC( ptP, *pBiArc) ;
|
||||
double dSqDistPC ;
|
||||
if ( dstPC.GetSqDist( dSqDistPC) && dSqDistPC > dSqDist)
|
||||
dSqDist = dSqDistPC ;
|
||||
const double STEP = 10 ;
|
||||
Point3d ptCurr ;
|
||||
bool bPnt = PL.GetFirstPoint( ptCurr) ;
|
||||
Point3d ptPrev = ptCurr ;
|
||||
while ( bPnt) {
|
||||
double dLen = Dist( ptCurr, ptPrev) ;
|
||||
int nStep = ( dLen < STEP ? 2 : 1) * int( dLen / STEP) + 1 ;
|
||||
for ( int i = 1 ; i <= nStep ; ++ i) {
|
||||
double dCoeff = double( i) / nStep ;
|
||||
Point3d ptP = Media( ptPrev, ptCurr, dCoeff) ;
|
||||
DistPointCurve dstPC( ptP, *pBiArc) ;
|
||||
double dSqDistPC ;
|
||||
if ( dstPC.GetSqDist( dSqDistPC) && dSqDistPC > dSqDist)
|
||||
dSqDist = dSqDistPC ;
|
||||
}
|
||||
ptPrev = ptCurr ;
|
||||
bPnt = PL.GetNextPoint( ptCurr) ;
|
||||
}
|
||||
dDist = sqrt( dSqDist) ;
|
||||
|
||||
|
||||
+53
-5
@@ -57,11 +57,17 @@ ICurve*
|
||||
CurveByApprox::GetCurve( int nType, double dLinTol, double dAngTolDeg, double dLinFea)
|
||||
{
|
||||
// se da approssimare con archi
|
||||
if ( nType == ARCS_CORNER) {
|
||||
if ( nType == ARCS || nType == ARCS_CORNER) {
|
||||
// calcolo approssimazione
|
||||
PolyArc PA ;
|
||||
if ( ! GetArcs( dLinTol, dAngTolDeg, dLinFea, PA))
|
||||
return nullptr ;
|
||||
if ( nType == ARCS) {
|
||||
if ( ! GetArcs( dLinTol, dAngTolDeg, PA))
|
||||
return nullptr ;
|
||||
}
|
||||
else {
|
||||
if ( ! GetArcsCorner( dLinTol, dAngTolDeg, dLinFea, PA))
|
||||
return nullptr ;
|
||||
}
|
||||
// creo la composita formata da questa approssimazione
|
||||
PtrOwner<CurveComposite> pCC( CreateBasicCurveComposite()) ;
|
||||
if ( ! pCC->FromPolyArc( PA))
|
||||
@@ -74,13 +80,55 @@ CurveByApprox::GetCurve( int nType, double dLinTol, double dAngTolDeg, double dL
|
||||
return Release( pCC) ;
|
||||
}
|
||||
// altrimenti con curve di Bezier cubiche
|
||||
// !!! NON ANCORA IMPLEMENTATA !!!
|
||||
else if ( nType == CUBIC_BEZIERS) {
|
||||
// !!! NON ANCORA IMPLEMENTATA !!!
|
||||
return nullptr ;
|
||||
}
|
||||
// tipi non previsti
|
||||
return nullptr ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
CurveByApprox::GetArcs( double dLinTol, double dAngTolDeg, double dLinFea, PolyArc& PA)
|
||||
CurveByApprox::GetArcs( double dLinTol, double dAngTolDeg, PolyArc& PA)
|
||||
{
|
||||
// pulisco il poliarco
|
||||
PA.Clear() ;
|
||||
|
||||
// calcolo una parametrizzazione
|
||||
if ( ! CalcParameterization())
|
||||
return false ;
|
||||
|
||||
// calcolo le tangenti
|
||||
if ( ! CalcAkimaTangents( false))
|
||||
return false ;
|
||||
|
||||
// approssimo come unico tratto
|
||||
|
||||
// creo la polilinea che unisce i punti
|
||||
PolyLine PL ;
|
||||
int nPnt = int( m_vPnt.size()) ;
|
||||
for ( int j = 0 ; j < nPnt ; ++ j)
|
||||
PL.AddUPoint( j, m_vPnt[j]) ;
|
||||
// verifico se retta verticale
|
||||
BBox3d b3PL ;
|
||||
if ( ! PL.GetLocalBBox( b3PL))
|
||||
return false ;
|
||||
if ( b3PL.GetDimX() < EPS_SMALL && b3PL.GetDimY() < EPS_SMALL) {
|
||||
PA.AddUPoint( 0, m_vPnt[0], 0) ;
|
||||
PA.AddUPoint( nPnt - 1, m_vPnt[nPnt - 1], 0) ;
|
||||
}
|
||||
// altrimenti eseguo l'approssimazione con archi
|
||||
else {
|
||||
if ( ! BiArcOrSplit( 0, PL, dLinTol, dAngTolDeg, PA))
|
||||
return false ;
|
||||
}
|
||||
return true ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
CurveByApprox::GetArcsCorner( double dLinTol, double dAngTolDeg, double dLinFea, PolyArc& PA)
|
||||
{
|
||||
// pulisco il poliarco
|
||||
PA.Clear() ;
|
||||
|
||||
+2
-9
@@ -1487,13 +1487,6 @@ CurveComposite::ApproxWithArcsEx( double dLinTol, double dAngTolDeg, double dLin
|
||||
crvByApprox.Reset() ;
|
||||
crvByApprox.AddPoint( pLine->GetStart()) ;
|
||||
}
|
||||
// aggiungo punti a distanza opportuna
|
||||
const double STEP = 5 ;
|
||||
int nStep = int( dLen / STEP) ;
|
||||
for ( int i = 1 ; i < nStep ; ++ i) {
|
||||
double dCoeff = i / double( nStep) ;
|
||||
crvByApprox.AddPoint( Media( pLine->GetStart(), pLine->GetEnd(), dCoeff)) ;
|
||||
}
|
||||
// aggiungo il punto finale
|
||||
crvByApprox.AddPoint( pLine->GetEnd()) ;
|
||||
}
|
||||
@@ -1503,7 +1496,7 @@ CurveComposite::ApproxWithArcsEx( double dLinTol, double dAngTolDeg, double dLin
|
||||
if ( bMultiLine) {
|
||||
bMultiLine = false ;
|
||||
PolyArc PASmpl ;
|
||||
if ( ! crvByApprox.GetArcs( dLinTol, dAngTolDeg, dLinFea, PASmpl))
|
||||
if ( ! crvByApprox.GetArcsCorner( dLinTol, dAngTolDeg, dLinFea, PASmpl))
|
||||
return false ;
|
||||
// la accodo opportunamente a quella della curva composita
|
||||
if ( ! PA.Join( PASmpl, dMlStartPar))
|
||||
@@ -1524,7 +1517,7 @@ CurveComposite::ApproxWithArcsEx( double dLinTol, double dAngTolDeg, double dLin
|
||||
if ( bMultiLine) {
|
||||
bMultiLine = false ;
|
||||
PolyArc PASmpl ;
|
||||
if ( ! crvByApprox.GetArcs( dLinTol, dAngTolDeg, dLinFea, PASmpl))
|
||||
if ( ! crvByApprox.GetArcsCorner( dLinTol, dAngTolDeg, dLinFea, PASmpl))
|
||||
return false ;
|
||||
// la accodo opportunamente a quella della curva composita
|
||||
if ( ! PA.Join( PASmpl, dMlStartPar))
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user