EgtGeomKernel 2.6b3 :

- standardizzate le funzione Collision Detection sia per trimesh sia per Zmap (ex Avoid...)
- nelle funzioni Cde ora se arrivano geometrie errate si ritorna collisione (maggior sicurezza).
This commit is contained in:
Dario Sassi
2024-02-16 08:43:15 +01:00
parent c8ce0a242e
commit ddade325c4
28 changed files with 334 additions and 279 deletions
+203 -186
View File
@@ -411,7 +411,7 @@ VolZmap::GetDepthWithVoxel( const Point3d& ptP, const Vector3d& vtD, double& dIn
//----------------------------------------------------------------------------
bool
VolZmap::AvoidSimpleBox( const Frame3d& frBox, const Vector3d& vtDiag, bool bPrecise) const
VolZmap::CDeSimpleBox( const Frame3d& frBox, const Vector3d& vtDiag, bool bPrecise) const
{
// BBox
BBox3d b3BoxL( ORIG, ORIG + vtDiag) ;
@@ -425,10 +425,10 @@ VolZmap::AvoidSimpleBox( const Frame3d& frBox, const Vector3d& vtDiag, bool bPre
// Se non interferiscono, posso uscire
if ( ! b3Zmap.Overlaps( b3Box) || ! b3Zmap.Overlaps( frBoxInt, b3BoxL))
return true ;
return false ;
BBox3d b3Int ;
if ( ! b3Zmap.FindIntersection( b3Box, b3Int))
return true ;
return false ;
// Se verifico solo prima mappa
if ( ! bPrecise || m_nMapNum == 1) {
@@ -470,7 +470,7 @@ VolZmap::AvoidSimpleBox( const Frame3d& frBox, const Vector3d& vtDiag, bool bPre
for ( int nIndex = 0 ; nIndex < nSize ; nIndex += 1) {
if ( dZmax > m_Values[0][nPos][nIndex].dMin - EPS_SMALL &&
dZmin < m_Values[0][nPos][nIndex].dMax + EPS_SMALL)
return false ;
return true ;
}
}
}
@@ -533,7 +533,7 @@ VolZmap::AvoidSimpleBox( const Frame3d& frBox, const Vector3d& vtDiag, bool bPre
// Se il segmento è interno all'intervallo d'intersezione, ho finito.
if ( dMaxU > m_Values[nMap][nPos][nIndex].dMin - EPS_SMALL &&
dMinU < m_Values[nMap][nPos][nIndex].dMax + EPS_SMALL)
return false ;
return true ;
}
}
}
@@ -541,32 +541,36 @@ VolZmap::AvoidSimpleBox( const Frame3d& frBox, const Vector3d& vtDiag, bool bPre
}
}
return true ;
return false ;
}
//----------------------------------------------------------------------------
bool
VolZmap::AvoidBox( const Frame3d& frBox, const Vector3d& vtDiag, double dSafeDist, bool bPrecise) const
VolZmap::CDeBox( const Frame3d& frBox, const Vector3d& vtDiag, double dSafeDist, bool bPrecise) const
{
// Se il box non è ben definito non ha senso proseguire
if ( vtDiag.IsSmall())
return true ;
// Se distanza di sicurezza nulla
if ( dSafeDist < EPS_SMALL)
return AvoidSimpleBox( frBox, vtDiag, bPrecise) ;
return CDeSimpleBox( frBox, vtDiag, bPrecise) ;
// Verifica preliminare con box esteso
Frame3d frEst = frBox ; frEst.Translate( -dSafeDist * ( frBox.VersX() + frBox.VersY() + frBox.VersZ())) ;
if ( AvoidSimpleBox( frEst, vtDiag + 2 * Vector3d( dSafeDist, dSafeDist, dSafeDist), bPrecise))
return true ;
if ( ! CDeSimpleBox( frEst, vtDiag + 2 * Vector3d( dSafeDist, dSafeDist, dSafeDist), bPrecise))
return false ;
// Tre box aumentati con distanza di sicurezza in un sola dimensione
Frame3d frTmp = frBox ; frTmp.Translate( -dSafeDist * frBox.VersX()) ;
if ( ! AvoidSimpleBox( frTmp, vtDiag + 2 * dSafeDist * X_AX, bPrecise))
return false ;
if ( CDeSimpleBox( frTmp, vtDiag + 2 * dSafeDist * X_AX, bPrecise))
return true ;
frTmp = frBox ; frTmp.Translate( -dSafeDist * frBox.VersY()) ;
if ( ! AvoidSimpleBox( frTmp, vtDiag + 2 * dSafeDist * Y_AX, bPrecise))
return false ;
if ( CDeSimpleBox( frTmp, vtDiag + 2 * dSafeDist * Y_AX, bPrecise))
return true ;
frTmp = frBox ; frTmp.Translate( -dSafeDist * frBox.VersZ()) ;
if ( ! AvoidSimpleBox( frTmp, vtDiag + 2 * dSafeDist * Z_AX, bPrecise))
return false ;
if ( CDeSimpleBox( frTmp, vtDiag + 2 * dSafeDist * Z_AX, bPrecise))
return true ;
// Vertici del box
Point3d ptVert0 = frBox.Orig() ;
@@ -579,67 +583,67 @@ VolZmap::AvoidBox( const Frame3d& frBox, const Vector3d& vtDiag, double dSafeDis
Point3d ptVert7 = ptVert3 + vtDiag.z * frBox.VersZ() ;
// Sfere centrate negli otto vertici
if ( ! AvoidSimpleSphere( ptVert0, dSafeDist, bPrecise))
return false ;
if ( ! AvoidSimpleSphere( ptVert1, dSafeDist, bPrecise))
return false ;
if ( ! AvoidSimpleSphere( ptVert2, dSafeDist, bPrecise))
return false ;
if ( ! AvoidSimpleSphere( ptVert3, dSafeDist, bPrecise))
return false ;
if ( ! AvoidSimpleSphere( ptVert4, dSafeDist, bPrecise))
return false ;
if ( ! AvoidSimpleSphere( ptVert5, dSafeDist, bPrecise))
return false ;
if ( ! AvoidSimpleSphere( ptVert6, dSafeDist, bPrecise))
return false ;
if ( ! AvoidSimpleSphere( ptVert7, dSafeDist, bPrecise))
return false ;
if ( CDeSimpleSphere( ptVert0, dSafeDist, bPrecise))
return true ;
if ( CDeSimpleSphere( ptVert1, dSafeDist, bPrecise))
return true ;
if ( CDeSimpleSphere( ptVert2, dSafeDist, bPrecise))
return true ;
if ( CDeSimpleSphere( ptVert3, dSafeDist, bPrecise))
return true ;
if ( CDeSimpleSphere( ptVert4, dSafeDist, bPrecise))
return true ;
if ( CDeSimpleSphere( ptVert5, dSafeDist, bPrecise))
return true ;
if ( CDeSimpleSphere( ptVert6, dSafeDist, bPrecise))
return true ;
if ( CDeSimpleSphere( ptVert7, dSafeDist, bPrecise))
return true ;
// Cilindri centrati sui dodici spigoli
frTmp.Set( ptVert0, frBox.VersX()) ;
if ( ! AvoidSimpleCylinder( frTmp, dSafeDist, vtDiag.x, bPrecise))
return false ;
if ( CDeSimpleCylinder( frTmp, dSafeDist, vtDiag.x, bPrecise))
return true ;
frTmp.Set( ptVert2, frBox.VersX()) ;
if ( ! AvoidSimpleCylinder( frTmp, dSafeDist, vtDiag.x, bPrecise))
return false ;
if ( CDeSimpleCylinder( frTmp, dSafeDist, vtDiag.x, bPrecise))
return true ;
frTmp.Set( ptVert0, frBox.VersY()) ;
if ( ! AvoidSimpleCylinder( frTmp, dSafeDist, vtDiag.y, bPrecise))
return false ;
if ( CDeSimpleCylinder( frTmp, dSafeDist, vtDiag.y, bPrecise))
return true ;
frTmp.Set( ptVert1, frBox.VersY()) ;
if ( ! AvoidSimpleCylinder( frTmp, dSafeDist, vtDiag.y, bPrecise))
return false ;
if ( CDeSimpleCylinder( frTmp, dSafeDist, vtDiag.y, bPrecise))
return true ;
frTmp.Set( ptVert4, frBox.VersX()) ;
if ( ! AvoidSimpleCylinder( frTmp, dSafeDist, vtDiag.x, bPrecise))
return false ;
if ( CDeSimpleCylinder( frTmp, dSafeDist, vtDiag.x, bPrecise))
return true ;
frTmp.Set( ptVert6, frBox.VersX()) ;
if ( ! AvoidSimpleCylinder( frTmp, dSafeDist, vtDiag.x, bPrecise))
return false ;
if ( CDeSimpleCylinder( frTmp, dSafeDist, vtDiag.x, bPrecise))
return true ;
frTmp.Set( ptVert4, frBox.VersY()) ;
if ( ! AvoidSimpleCylinder( frTmp, dSafeDist, vtDiag.y, bPrecise))
return false ;
if ( CDeSimpleCylinder( frTmp, dSafeDist, vtDiag.y, bPrecise))
return true ;
frTmp.Set( ptVert5, frBox.VersY()) ;
if ( ! AvoidSimpleCylinder( frTmp, dSafeDist, vtDiag.y, bPrecise))
return false ;
if ( CDeSimpleCylinder( frTmp, dSafeDist, vtDiag.y, bPrecise))
return true ;
frTmp.Set( ptVert0, frBox.VersZ()) ;
if ( ! AvoidSimpleCylinder( frTmp, dSafeDist, vtDiag.z, bPrecise))
return false ;
if ( CDeSimpleCylinder( frTmp, dSafeDist, vtDiag.z, bPrecise))
return true ;
frTmp.Set( ptVert1, frBox.VersZ()) ;
if ( ! AvoidSimpleCylinder( frTmp, dSafeDist, vtDiag.z, bPrecise))
return false ;
if ( CDeSimpleCylinder( frTmp, dSafeDist, vtDiag.z, bPrecise))
return true ;
frTmp.Set( ptVert2, frBox.VersZ()) ;
if ( ! AvoidSimpleCylinder( frTmp, dSafeDist, vtDiag.z, bPrecise))
return false ;
if ( CDeSimpleCylinder( frTmp, dSafeDist, vtDiag.z, bPrecise))
return true ;
frTmp.Set( ptVert3, frBox.VersZ()) ;
if ( ! AvoidSimpleCylinder( frTmp, dSafeDist, vtDiag.z, bPrecise))
return false ;
if ( CDeSimpleCylinder( frTmp, dSafeDist, vtDiag.z, bPrecise))
return true ;
return true ;
return false ;
}
//----------------------------------------------------------------------------
bool
VolZmap::AvoidSimpleSphere( const Point3d& ptCenter, double dRad, bool bPrecise) const
VolZmap::CDeSimpleSphere( const Point3d& ptCenter, double dRad, bool bPrecise) const
{
// Porto la sfera nel riferimento intrinseco dello Zmap
Point3d ptC = ptCenter ;
@@ -655,7 +659,7 @@ VolZmap::AvoidSimpleSphere( const Point3d& ptCenter, double dRad, bool bPrecise)
// Se non interferiscono, posso uscire
BBox3d b3Int ;
if ( ! b3Zmap.FindIntersection( b3Box, b3Int))
return true ;
return false ;
// Se verifico solo prima mappa
if ( ! bPrecise || m_nMapNum == 1) {
@@ -693,7 +697,7 @@ VolZmap::AvoidSimpleSphere( const Point3d& ptCenter, double dRad, bool bPrecise)
for ( int nIndex = 0 ; nIndex < nSize ; nIndex += 1) {
if ( dZmax > m_Values[0][nPos][nIndex].dMin - EPS_SMALL &&
dZmin < m_Values[0][nPos][nIndex].dMax + EPS_SMALL)
return false ;
return true ;
}
}
}
@@ -765,7 +769,7 @@ VolZmap::AvoidSimpleSphere( const Point3d& ptCenter, double dRad, bool bPrecise)
// Se il segmento è interno all'intervallo d'intersezione, ho finito.
if ( dMaxU > m_Values[nMap][nPos][nIndex].dMin - EPS_SMALL &&
dMinU < m_Values[nMap][nPos][nIndex].dMax + EPS_SMALL)
return false ;
return true ;
}
}
}
@@ -773,19 +777,23 @@ VolZmap::AvoidSimpleSphere( const Point3d& ptCenter, double dRad, bool bPrecise)
}
}
return true ;
return false ;
}
//----------------------------------------------------------------------------
bool
VolZmap::AvoidSphere( const Point3d& ptCenter, double dRad, double dSafeDist, bool bPrecise) const
VolZmap::CDeSphere( const Point3d& ptCenter, double dRad, double dSafeDist, bool bPrecise) const
{
return AvoidSimpleSphere( ptCenter, dRad + max( 0., dSafeDist), bPrecise) ;
// Il raggio deve essere non nullo
if ( dRad < EPS_SMALL)
return true ;
return CDeSimpleSphere( ptCenter, dRad + max( 0., dSafeDist), bPrecise) ;
}
//----------------------------------------------------------------------------
bool
VolZmap::AvoidSimpleCylinder( const Frame3d& frCyl, double dR, double dH, bool bPrecise) const
VolZmap::CDeSimpleCylinder( const Frame3d& frCyl, double dR, double dH, bool bPrecise) const
{
// BBox del cilindro in locale
BBox3d b3CylL( Point3d( -dR, -dR, 0), Point3d( dR, dR, dH)) ;
@@ -799,7 +807,7 @@ VolZmap::AvoidSimpleCylinder( const Frame3d& frCyl, double dR, double dH, bool b
// Se non interferiscono, posso uscire
if ( ! b3Zmap.Overlaps( b3CylI) || ! b3Zmap.Overlaps( frCylInt, b3CylL))
return true ;
return false ;
// BBox del cilindro ottimizzato nel riferimento intrinseco dello Zmap
Point3d ptMyCen = frCylInt.Orig() ;
@@ -822,7 +830,7 @@ VolZmap::AvoidSimpleCylinder( const Frame3d& frCyl, double dR, double dH, bool b
// Se non interferiscono, posso uscire
BBox3d b3Int ;
if ( ! b3Zmap.FindIntersection( b3Cyl, b3Int))
return true ;
return false ;
// Se verifico solo prima mappa
if ( ! bPrecise || m_nMapNum == 1) {
@@ -866,7 +874,7 @@ VolZmap::AvoidSimpleCylinder( const Frame3d& frCyl, double dR, double dH, bool b
for ( int nIndex = 0 ; nIndex < nSize ; nIndex += 1) {
if ( dZmax > m_Values[0][nPos][nIndex].dMin - EPS_SMALL &&
dZmin < m_Values[0][nPos][nIndex].dMax + EPS_SMALL)
return false ;
return true ;
}
}
}
@@ -931,7 +939,7 @@ VolZmap::AvoidSimpleCylinder( const Frame3d& frCyl, double dR, double dH, bool b
// Se il segmento è interno all'intervallo d'intersezione, ho finito.
if ( dMaxU > m_Values[nMap][nPos][nIndex].dMin - EPS_SMALL &&
dMinU < m_Values[nMap][nPos][nIndex].dMax + EPS_SMALL)
return false ;
return true ;
}
}
}
@@ -939,13 +947,17 @@ VolZmap::AvoidSimpleCylinder( const Frame3d& frCyl, double dR, double dH, bool b
}
}
return true ;
return false ;
}
//----------------------------------------------------------------------------
bool
VolZmap::AvoidCylinder( const Frame3d& frCyl, double dR, double dH, double dSafeDist, bool bPrecise) const
VolZmap::CDeCylinder( const Frame3d& frCyl, double dR, double dH, double dSafeDist, bool bPrecise) const
{
// Il cilindro deve essere ben definito
if ( dR < EPS_SMALL || dH < EPS_SMALL)
return true ;
// Se altezza negativa, sposto riferimento da faccia sopra a quella sotto
Frame3d frMyCyl = frCyl ;
if ( dH < 0) {
@@ -955,34 +967,34 @@ VolZmap::AvoidCylinder( const Frame3d& frCyl, double dR, double dH, double dSafe
// Se distanza di sicurezza nulla
if ( dSafeDist < EPS_SMALL)
return AvoidSimpleCylinder( frMyCyl, dR, dH, bPrecise) ;
return CDeSimpleCylinder( frMyCyl, dR, dH, bPrecise) ;
// Verifica preliminare con cilindro esteso
Frame3d frEst = frMyCyl ; frEst.Translate( -dSafeDist * frMyCyl.VersZ()) ;
if ( AvoidSimpleCylinder( frEst, dR + dSafeDist, dH + 2 * dSafeDist, bPrecise))
return true ;
if ( ! CDeSimpleCylinder( frEst, dR + dSafeDist, dH + 2 * dSafeDist, bPrecise))
return false ;
// Cilindro allargato
if ( ! AvoidSimpleCylinder( frMyCyl, dR + dSafeDist, dH, bPrecise))
return false ;
if ( CDeSimpleCylinder( frMyCyl, dR + dSafeDist, dH, bPrecise))
return true ;
// Cilindro allungato
Frame3d frTmp = frMyCyl ; frTmp.Translate( - dSafeDist * frMyCyl.VersZ()) ;
if ( ! AvoidSimpleCylinder( frTmp, dR, dH + 2 * dSafeDist, bPrecise))
return false ;
if ( CDeSimpleCylinder( frTmp, dR, dH + 2 * dSafeDist, bPrecise))
return true ;
// Toro inferiore
if ( ! AvoidSimpleTorus( frMyCyl, dR, dSafeDist, bPrecise))
return false ;
if ( CDeSimpleTorus( frMyCyl, dR, dSafeDist, bPrecise))
return true ;
// Toro superiore
frTmp = frMyCyl ; frTmp.Translate( dH * frMyCyl.VersZ()) ;
if ( ! AvoidSimpleTorus( frTmp, dR, dSafeDist, bPrecise))
return false ;
if ( CDeSimpleTorus( frTmp, dR, dSafeDist, bPrecise))
return true ;
return true ;
return false ;
}
//----------------------------------------------------------------------------
bool
VolZmap::AvoidSimpleConeFrustum( const Frame3d& frCone, double dMinRad, double dMaxRad, double dHeight, bool bPrecise) const
VolZmap::CDeSimpleConeFrustum( const Frame3d& frCone, double dMinRad, double dMaxRad, double dHeight, bool bPrecise) const
{
// BBox del tronco di cono in locale
BBox3d b3ConeL( Point3d( -dMaxRad, -dMaxRad, 0), Point3d( dMaxRad, dMaxRad, dHeight)) ;
@@ -996,7 +1008,7 @@ VolZmap::AvoidSimpleConeFrustum( const Frame3d& frCone, double dMinRad, double d
// Se non interferiscono, posso uscire
if ( ! b3Zmap.Overlaps( b3ConeI) || ! b3Zmap.Overlaps( frConeInt, b3ConeL))
return true ;
return false ;
// BBox del tronco di cono ottimizzato nel riferimento intrinseco dello Zmap
Point3d ptRefPoint = frConeInt.Orig() ;
@@ -1025,7 +1037,7 @@ VolZmap::AvoidSimpleConeFrustum( const Frame3d& frCone, double dMinRad, double d
// Se non interferiscono, posso uscire
BBox3d b3Int ;
if ( ! b3Zmap.FindIntersection( b3Cone, b3Int))
return true ;
return false ;
// Uso solo la prima mappa
if ( ! bPrecise || m_nMapNum == 1) {
@@ -1068,7 +1080,7 @@ VolZmap::AvoidSimpleConeFrustum( const Frame3d& frCone, double dMinRad, double d
for ( int nIndex = 0 ; nIndex < nSize ; nIndex += 1) {
if ( dZmax > m_Values[0][nPos][nIndex].dMin - EPS_SMALL &&
dZmin < m_Values[0][nPos][nIndex].dMax + EPS_SMALL)
return false ;
return true ;
}
}
}
@@ -1133,14 +1145,14 @@ VolZmap::AvoidSimpleConeFrustum( const Frame3d& frCone, double dMinRad, double d
// Se il segmento è interno all'intervallo d'intersezione, ho finito.
if ( dMaxU > m_Values[nMap][nPos][nIndex].dMin - EPS_SMALL &&
dMinU < m_Values[nMap][nPos][nIndex].dMax + EPS_SMALL)
return false ;
return true ;
}
}
}
}
}
}
return true ;
return false ;
}
//----------------------------------------------------------------------------
@@ -1149,12 +1161,16 @@ VolZmap::AvoidSimpleConeFrustum( const Frame3d& frCone, double dMinRad, double d
// Se è un tronco di cono l'origine è nel centro della base Bot e l'asse Z è diretto verso
// la base Top, a prescindere da quale base abbia raggio maggiore.
bool
VolZmap::AvoidConeFrustum( const Frame3d& frCone, double dRadBot, double dRadTop, double dHeight,
VolZmap::CDeConeFrustum( const Frame3d& frCone, double dRadBot, double dRadTop, double dHeight,
double dSafeDist, bool bPrecise) const
{
// Se il tronco di cono non è ben definito non ha senso proseguire
if ( max( dRadBot, dRadTop) < EPS_SMALL || dHeight < EPS_SMALL)
return true ;
// Se cilindro
if ( abs( dRadBot - dRadTop) < EPS_SMALL)
return AvoidCylinder( frCone, max( dRadBot, dRadTop), dHeight, dSafeDist, bPrecise) ;
return CDeCylinder( frCone, max( dRadBot, dRadTop), dHeight, dSafeDist, bPrecise) ;
// Verifico che la base minore sia in basso nel suo riferimento
Frame3d frMyCone = frCone ;
@@ -1167,7 +1183,7 @@ VolZmap::AvoidConeFrustum( const Frame3d& frCone, double dRadBot, double dRadTop
// Se distanza di sicurezza nulla
if ( dSafeDist < EPS_SMALL)
return AvoidSimpleConeFrustum( frMyCone, dMinRad, dMaxRad, dHeight, bPrecise) ;
return CDeSimpleConeFrustum( frMyCone, dMinRad, dMaxRad, dHeight, bPrecise) ;
// Se vero e proprio cono
if ( dMinRad < EPS_SMALL) {
@@ -1177,28 +1193,28 @@ VolZmap::AvoidConeFrustum( const Frame3d& frCone, double dRadBot, double dRadTop
double dRadExt = dMaxRad * dHeightExt / dHeight ;
Frame3d frFrame = frMyCone ;
frFrame.Translate( -dDeltaVert * frFrame.VersZ()) ;
if ( AvoidSimpleConeFrustum( frFrame, 0., dRadExt, dHeightExt, bPrecise))
return true ;
if ( ! CDeSimpleConeFrustum( frFrame, 0., dRadExt, dHeightExt, bPrecise))
return false ;
// Sfera nel vertice in basso
frFrame = frMyCone ;
if ( ! AvoidSimpleSphere( frMyCone.Orig(), dSafeDist, bPrecise))
return false ;
if ( CDeSimpleSphere( frMyCone.Orig(), dSafeDist, bPrecise))
return true ;
// Tronco di cono intermedio
double dHypo = sqrt( dMaxRad * dMaxRad + dHeight * dHeight ) ;
double dDeltaH = dSafeDist * dMaxRad / dHypo ;
double dDeltaR = dSafeDist * dHeight / dHypo ;
frFrame = frMyCone ; frFrame.Translate( -dDeltaH * frFrame.VersZ()) ;
if ( ! AvoidSimpleConeFrustum( frFrame, dDeltaR, dMaxRad + dDeltaR, dHeight, bPrecise))
return false ;
if ( CDeSimpleConeFrustum( frFrame, dDeltaR, dMaxRad + dDeltaR, dHeight, bPrecise))
return true ;
// Cilindro nel toro in alto
frFrame = frMyCone ; frFrame.Translate( ( dHeight - dSafeDist) * frFrame.VersZ()) ;
if ( ! AvoidSimpleCylinder( frFrame, dMaxRad, 2 * dSafeDist, bPrecise))
return false ;
if ( CDeSimpleCylinder( frFrame, dMaxRad, 2 * dSafeDist, bPrecise))
return true ;
// Toro in alto
frFrame = frMyCone ; frFrame.Translate( dHeight * frFrame.VersZ()) ;
if ( ! AvoidSimpleTorus( frFrame, dMaxRad, dSafeDist, bPrecise))
return false ;
return true ;
if ( CDeSimpleTorus( frFrame, dMaxRad, dSafeDist, bPrecise))
return true ;
return false ;
}
// Tronco di cono
@@ -1210,33 +1226,33 @@ VolZmap::AvoidConeFrustum( const Frame3d& frCone, double dRadBot, double dRadTop
double dDeltaMaxRad = ( dDeltaVert + dSafeDist) * dDiffRad / dHeight ;
double dDeltaMinRad = ( dDeltaVert - dSafeDist) * dDiffRad / dHeight ;
Frame3d frFrame = frMyCone ; frFrame.Translate( -dSafeDist * frFrame.VersZ()) ;
if ( AvoidSimpleConeFrustum( frFrame, dMinRad + dDeltaMinRad, dMaxRad + dDeltaMaxRad, dHeight + 2 * dSafeDist, bPrecise))
return true ;
if ( ! CDeSimpleConeFrustum( frFrame, dMinRad + dDeltaMinRad, dMaxRad + dDeltaMaxRad, dHeight + 2 * dSafeDist, bPrecise))
return false ;
// Tronco di cono intermedio
double dHypo = sqrt( dDiffRad * dDiffRad + dHeight * dHeight ) ;
double dDeltaH = dSafeDist * dDiffRad / dHypo ;
double dDeltaR = dSafeDist * dHeight / dHypo ;
frFrame = frMyCone ; frFrame.Translate( -dDeltaH * frFrame.VersZ()) ;
if ( ! AvoidSimpleConeFrustum( frFrame, dMinRad + dDeltaR, dMaxRad + dDeltaR, dHeight, bPrecise))
return false ;
if ( CDeSimpleConeFrustum( frFrame, dMinRad + dDeltaR, dMaxRad + dDeltaR, dHeight, bPrecise))
return true ;
// Cilindro sotto
frFrame = frMyCone ; frFrame.Translate( - dSafeDist * frFrame.VersZ()) ;
if ( ! AvoidSimpleCylinder( frFrame, dMinRad, 2 * dSafeDist, bPrecise))
return false ;
if ( CDeSimpleCylinder( frFrame, dMinRad, 2 * dSafeDist, bPrecise))
return true ;
// Cilindro sopra
frFrame.Translate( dHeight * frFrame.VersZ()) ;
if ( ! AvoidSimpleCylinder( frFrame, dMaxRad, 2 * dSafeDist, bPrecise))
return false ;
if ( CDeSimpleCylinder( frFrame, dMaxRad, 2 * dSafeDist, bPrecise))
return true ;
// Toro sotto
frFrame = frMyCone ;
if ( ! AvoidSimpleTorus( frFrame, dMinRad, dSafeDist, bPrecise))
return false ;
if ( CDeSimpleTorus( frFrame, dMinRad, dSafeDist, bPrecise))
return true ;
// Toro sopra
frFrame.Translate( dHeight * frFrame.VersZ()) ;
if ( ! AvoidSimpleTorus( frFrame, dMaxRad, dSafeDist, bPrecise))
return false ;
if ( CDeSimpleTorus( frFrame, dMaxRad, dSafeDist, bPrecise))
return true ;
return true ;
return false ;
}
//----------------------------------------------------------------------------
@@ -1380,8 +1396,8 @@ RectPrismoidSegmentCollisionPlus( const Frame3d& frPrismoid, double dLenghtBaseX
//----------------------------------------------------------------------------
bool
VolZmap::AvoidSimpleRectPrismoid( const Frame3d& frPrismoid, double dLenghtBaseX, double dLenghtBaseY,
double dLenghtTopX, double dLenghtTopY, double dHeight, bool bPrecise) const
VolZmap::CDeSimpleRectPrismoid( const Frame3d& frPrismoid, double dLenghtBaseX, double dLenghtBaseY,
double dLenghtTopX, double dLenghtTopY, double dHeight, bool bPrecise) const
{
// Box del tronco di prismoide nel suo sistema locale
double dMaxLenX = max( dLenghtBaseX, dLenghtTopX) ;
@@ -1398,7 +1414,7 @@ VolZmap::AvoidSimpleRectPrismoid( const Frame3d& frPrismoid, double dLenghtBaseX
// Se i box non interferiscono, posso uscire
if ( ! b3Zmap.Overlaps( b3PrismI) || ! b3Zmap.Overlaps( frPrismInt, b3PrismL))
return true ;
return false ;
// BBox del tronco di prismoide ottimizzato nel riferimento intrinseco dello Zmap
Point3d ptMyCen = frPrismInt.Orig() ;
@@ -1418,7 +1434,7 @@ VolZmap::AvoidSimpleRectPrismoid( const Frame3d& frPrismoid, double dLenghtBaseX
// Se i box non interferiscono, posso uscire
BBox3d b3Int ;
if ( ! b3Zmap.FindIntersection( b3Prism, b3Int))
return true ;
return false ;
// Se verifico solo prima mappa
if ( ! bPrecise || m_nMapNum == 1) {
@@ -1456,7 +1472,7 @@ VolZmap::AvoidSimpleRectPrismoid( const Frame3d& frPrismoid, double dLenghtBaseX
dHeight, ptSegSt, ptSegEn, dStU, dEnU)) {
for ( int nIndex = 0 ; nIndex < nSize ; nIndex += 1) {
if ( m_Values[0][nPos][nIndex].dMax >= dStU && m_Values[0][nPos][nIndex].dMin <= dEnU)
return false ;
return true ;
}
}
}
@@ -1523,30 +1539,30 @@ VolZmap::AvoidSimpleRectPrismoid( const Frame3d& frPrismoid, double dLenghtBaseX
dHeight, ptSegSt, ptSegEn, dStU, dEnU)) {
for ( int nIndex = 0 ; nIndex < nSize ; nIndex += 1) {
if ( m_Values[nMap][nDex][nIndex].dMax >= dStU && m_Values[nMap][nDex][nIndex].dMin <= dEnU)
return false ;
return true ;
}
}
}
}
}
return true ;
return false ;
}
//----------------------------------------------------------------------------
bool
VolZmap::AvoidRectPrismoid( const Frame3d& frPrismoid, double dLenghtBaseX, double dLenghtBaseY,
double dLenghtTopX, double dLenghtTopY, double dHeight,
double dSafeDist, bool bPrecise) const
VolZmap::CDeRectPrismoid( const Frame3d& frPrismoid, double dLenghtBaseX, double dLenghtBaseY,
double dLenghtTopX, double dLenghtTopY, double dHeight,
double dSafeDist, bool bPrecise) const
{
// Se il tronco di piramide non è ben definito non procedo
if ( max( dLenghtBaseX, dLenghtTopX) < EPS_SMALL ||
max( dLenghtBaseY, dLenghtTopY) < EPS_SMALL ||
dHeight < EPS_SMALL)
return false ;
return true ;
// Se distanza di sicurezza nulla
if ( dSafeDist < EPS_SMALL)
return AvoidSimpleRectPrismoid( frPrismoid, dLenghtBaseX, dLenghtBaseY, dLenghtTopX, dLenghtTopY, dHeight, bPrecise) ;
return CDeSimpleRectPrismoid( frPrismoid, dLenghtBaseX, dLenghtBaseY, dLenghtTopX, dLenghtTopY, dHeight, bPrecise) ;
// Verifica preliminare con offset esteso
double dHDiffX = ( dLenghtBaseX - dLenghtTopX) / 2 ;
@@ -1560,9 +1576,9 @@ VolZmap::AvoidRectPrismoid( const Frame3d& frPrismoid, double dLenghtBaseX, doub
double dOffsBaseY = dSafeDist * ( dSecAy + dTgAy) ;
double dOffsTopY = dSafeDist * ( dSecAy - dTgAy) ;
Frame3d frFrame = frPrismoid ; frFrame.Translate( -dSafeDist * frFrame.VersZ()) ;
if ( AvoidSimpleRectPrismoid( frFrame, dLenghtBaseX + 2 * dOffsBaseX, dLenghtBaseY + 2 * dOffsBaseY,
if ( ! CDeSimpleRectPrismoid( frFrame, dLenghtBaseX + 2 * dOffsBaseX, dLenghtBaseY + 2 * dOffsBaseY,
dLenghtTopX + 2 * dOffsTopX, dLenghtTopY + 2 * dOffsTopY, dHeight + 2 * dSafeDist, bPrecise))
return true ;
return false ;
// Offset fine
// Sfere centrate nei vertici
@@ -1580,85 +1596,85 @@ VolZmap::AvoidRectPrismoid( const Frame3d& frPrismoid, double dLenghtBaseX, doub
Point3d( -dHalfTopX, dHalfTopY, dHeight)} ;
for ( auto& ptV : vVert) {
ptV.ToGlob( frPrismoid) ;
if ( ! AvoidSimpleSphere( ptV, dSafeDist, bPrecise))
return false ;
if ( CDeSimpleSphere( ptV, dSafeDist, bPrecise))
return true ;
}
// Cilindri con i segmenti come asse
frFrame.Set( vVert[0], frPrismoid.VersX()) ;
if ( ! AvoidSimpleCylinder( frFrame, dSafeDist, dLenghtBaseX, bPrecise))
return false ;
if ( CDeSimpleCylinder( frFrame, dSafeDist, dLenghtBaseX, bPrecise))
return true ;
frFrame.Set( vVert[1], frPrismoid.VersY()) ;
if ( ! AvoidSimpleCylinder( frFrame, dSafeDist, dLenghtBaseY, bPrecise))
return false ;
if ( CDeSimpleCylinder( frFrame, dSafeDist, dLenghtBaseY, bPrecise))
return true ;
frFrame.Set( vVert[2], -frPrismoid.VersX()) ;
if ( ! AvoidSimpleCylinder( frFrame, dSafeDist, dLenghtBaseX, bPrecise))
return false ;
if ( CDeSimpleCylinder( frFrame, dSafeDist, dLenghtBaseX, bPrecise))
return true ;
frFrame.Set( vVert[3], -frPrismoid.VersY()) ;
if ( ! AvoidSimpleCylinder( frFrame, dSafeDist, dLenghtBaseY, bPrecise))
return false ;
if ( CDeSimpleCylinder( frFrame, dSafeDist, dLenghtBaseY, bPrecise))
return true ;
frFrame.Set( vVert[4], frPrismoid.VersX()) ;
if ( ! AvoidSimpleCylinder( frFrame, dSafeDist, dLenghtTopX, bPrecise))
return false ;
if ( CDeSimpleCylinder( frFrame, dSafeDist, dLenghtTopX, bPrecise))
return true ;
frFrame.Set( vVert[5], frPrismoid.VersY()) ;
if ( ! AvoidSimpleCylinder( frFrame, dSafeDist, dLenghtTopY, bPrecise))
return false ;
if ( CDeSimpleCylinder( frFrame, dSafeDist, dLenghtTopY, bPrecise))
return true ;
frFrame.Set( vVert[6], -frPrismoid.VersX()) ;
if ( ! AvoidSimpleCylinder( frFrame, dSafeDist, dLenghtTopX, bPrecise))
return false ;
if ( CDeSimpleCylinder( frFrame, dSafeDist, dLenghtTopX, bPrecise))
return true ;
frFrame.Set( vVert[7], -frPrismoid.VersY()) ;
if ( ! AvoidSimpleCylinder( frFrame, dSafeDist, dLenghtTopY, bPrecise))
return false ;
if ( CDeSimpleCylinder( frFrame, dSafeDist, dLenghtTopY, bPrecise))
return true ;
Vector3d vtSeg04 = vVert[4] - vVert[0] ;
double dLenSeg04 = vtSeg04.Len() ;
frFrame.Set( vVert[0], vtSeg04) ;
if ( ! AvoidSimpleCylinder( frFrame, dSafeDist, dLenSeg04, bPrecise))
return false ;
if ( CDeSimpleCylinder( frFrame, dSafeDist, dLenSeg04, bPrecise))
return true ;
Vector3d vtSeg15 = vVert[5] - vVert[1] ;
double dLenSeg15 = vtSeg15.Len() ;
frFrame.Set( vVert[1], vtSeg15) ;
if ( ! AvoidSimpleCylinder( frFrame, dSafeDist, dLenSeg15, bPrecise))
return false ;
if ( CDeSimpleCylinder( frFrame, dSafeDist, dLenSeg15, bPrecise))
return true ;
Vector3d vtSeg26 = vVert[6] - vVert[2] ;
double dLenSeg26 = vtSeg26.Len() ;
frFrame.Set( vVert[2], vtSeg26) ;
if ( ! AvoidSimpleCylinder( frFrame, dSafeDist, dLenSeg26, bPrecise))
return false ;
if ( CDeSimpleCylinder( frFrame, dSafeDist, dLenSeg26, bPrecise))
return true ;
Vector3d vtSeg37 = vVert[7] - vVert[3] ;
double dLenSeg37 = vtSeg37.Len();
frFrame.Set( vVert[3], vtSeg37) ;
if ( ! AvoidSimpleCylinder( frFrame, dSafeDist, dLenSeg37, bPrecise))
return false ;
if ( CDeSimpleCylinder( frFrame, dSafeDist, dLenSeg37, bPrecise))
return true ;
// Box sotto
frFrame = frPrismoid ; frFrame.Translate( -dSafeDist * frFrame.VersZ()) ;
if ( ! AvoidSimpleBox( frFrame, Vector3d( dLenghtBaseX, dLenghtBaseY, dSafeDist), bPrecise))
return false ;
if ( CDeSimpleBox( frFrame, Vector3d( dLenghtBaseX, dLenghtBaseY, dSafeDist), bPrecise))
return true ;
// Box sopra
frFrame = frPrismoid ; frFrame.Translate( dHeight * frFrame.VersZ()) ;
if ( ! AvoidSimpleBox( frFrame, Vector3d( dLenghtBaseX, dLenghtBaseY, dSafeDist), bPrecise))
return false ;
if ( CDeSimpleBox( frFrame, Vector3d( dLenghtBaseX, dLenghtBaseY, dSafeDist), bPrecise))
return true ;
// Prismoide allungato in X
double dHypoX = sqrt( dHDiffX * dHDiffX + dHeight * dHeight) ;
double dOffsX = dSafeDist * dHeight / dHypoX ;
double dMoveXZ = dSafeDist * dHDiffX / dHypoX ;
frFrame = frPrismoid ; frFrame.Translate( dMoveXZ * frFrame.VersZ()) ;
if ( ! AvoidSimpleRectPrismoid( frFrame, dLenghtBaseX + 2 * dOffsX, dLenghtBaseY,
if ( CDeSimpleRectPrismoid( frFrame, dLenghtBaseX + 2 * dOffsX, dLenghtBaseY,
dLenghtTopX + 2 * dOffsX, dLenghtTopY, dHeight, bPrecise))
return false ;
return true ;
// Prismoide allungato in Y
double dHypoY = sqrt( dHDiffY * dHDiffY + dHeight * dHeight) ;
double dOffsY = dSafeDist * dHeight / dHypoY ;
double dMoveYZ = dSafeDist * dHDiffY / dHypoY ;
frFrame = frPrismoid ; frFrame.Translate( dMoveYZ * frFrame.VersZ()) ;
if ( ! AvoidSimpleRectPrismoid( frFrame, dLenghtBaseX, dLenghtBaseY + 2 * dOffsY,
if ( CDeSimpleRectPrismoid( frFrame, dLenghtBaseX, dLenghtBaseY + 2 * dOffsY,
dLenghtTopX, dLenghtTopY + 2 * dOffsY, dHeight, bPrecise))
return false ;
return true ;
return true ;
return false ;
}
//----------------------------------------------------------------------------
bool
VolZmap::AvoidSimpleTorus( const Frame3d& frTorus, double dMaxRad, double dMinRad, bool bPrecise) const
VolZmap::CDeSimpleTorus( const Frame3d& frTorus, double dMaxRad, double dMinRad, bool bPrecise) const
{
// BBox del toro in locale
BBox3d b3TorusL( Point3d( -dMaxRad - dMinRad, -dMaxRad - dMinRad, -dMinRad),
@@ -1673,7 +1689,7 @@ VolZmap::AvoidSimpleTorus( const Frame3d& frTorus, double dMaxRad, double dMinRa
// Se non interferiscono, posso uscire
if ( ! b3Zmap.Overlaps( b3TorusI) || ! b3Zmap.Overlaps( frTorusInt, b3TorusL))
return true ;
return false ;
// BBox del toro ottimizzato nel riferimento intrinseco dello Zmap
Point3d ptMyCen = frTorusInt.Orig() ;
@@ -1698,7 +1714,7 @@ VolZmap::AvoidSimpleTorus( const Frame3d& frTorus, double dMaxRad, double dMinRa
// Se non interferiscono, posso uscire
BBox3d b3Int ;
if ( ! b3Zmap.FindIntersection( b3Torus, b3Int))
return true ;
return false ;
// Se verifico solo prima mappa
if ( ! bPrecise || m_nMapNum == 1) {
@@ -1736,13 +1752,13 @@ VolZmap::AvoidSimpleTorus( const Frame3d& frTorus, double dMaxRad, double dMinRa
int nIntType = SegmentTorus( ptSegSt, Z_AX, dParMax - dParMin, ptMyCen, vtMyAx, dMinRad, dMaxRad,
vbType, vdPar) ;
if ( nIntType == LinCompTorusIntersType::T_ERROR)
return false ;
return true ;
else if ( nIntType != LinCompTorusIntersType::T_NO_INT) {
double dUmin = vdPar.front() ;
double dUmax = vdPar.back() ;
for ( int nIndex = 0 ; nIndex < nSize ; nIndex += 1) {
if ( m_Values[0][nPos][nIndex].dMax >= dUmin && m_Values[0][nPos][nIndex].dMin <= dUmax)
return false ;
return true ;
}
}
}
@@ -1810,31 +1826,31 @@ VolZmap::AvoidSimpleTorus( const Frame3d& frTorus, double dMaxRad, double dMinRa
int nIntType = SegmentTorus( ptSegSt, vtLineDir, dParMax - dParMin, ptMyCen, vtMyAx, dMinRad, dMaxRad,
vbType, vdPar) ;
if ( nIntType == LinCompTorusIntersType::T_ERROR)
return false ;
return true ;
else if ( nIntType != LinCompTorusIntersType::T_NO_INT) {
double dUmin = vdPar.front() ;
double dUmax = vdPar.back() ;
for ( int nIndex = 0 ; nIndex < nSize ; nIndex += 1) {
if ( m_Values[nMap][nDex][nIndex].dMax >= dUmin && m_Values[nMap][nDex][nIndex].dMin <= dUmax)
return false ;
return true ;
}
}
}
}
}
return true ;
return false ;
}
//----------------------------------------------------------------------------
bool
VolZmap::AvoidTorus( const Frame3d& frTorus, double dMaxRad, double dMinRad,
VolZmap::CDeTorus( const Frame3d& frTorus, double dMaxRad, double dMinRad,
double dSafeDist, bool bPrecise) const
{
// I raggi devono essere non nulli
if ( dMaxRad < EPS_SMALL || dMinRad < EPS_SMALL)
return true ;
return AvoidSimpleTorus( frTorus, dMaxRad, dMinRad + max( 0., dSafeDist), bPrecise) ;
return CDeSimpleTorus( frTorus, dMaxRad, dMinRad + max( 0., dSafeDist), bPrecise) ;
}
//----------------------------------------------------------------------------
@@ -1844,12 +1860,13 @@ VolZmap::AvoidTorus( const Frame3d& frTorus, double dMaxRad, double dMinRad,
// quelli di intersezione segmento triangolo vengono eseguiti nel sistema locale. Questo perché
// è più veloce trasformare le coordinate degli estremi del segmento piuttosto che quelle del
// triangolo.
//----------------------------------------------------------------------------
bool
VolZmap::AvoidSurfTm( const ISurfTriMesh& tmSurf, double dSafeDist, bool bPrecise) const
VolZmap::CDeSurfTm( const ISurfTriMesh& tmSurf, double dSafeDist, bool bPrecise) const
{
// Controllo sulla validità della superficie ed eventualmente sulla sua chiusura
if ( ! ( tmSurf.IsValid() && tmSurf.IsClosed()))
return false ;
// Controllo sulla validità della superficie e sulla sua chiusura
if ( ! tmSurf.IsValid() || ! tmSurf.IsClosed())
return true ;
// Bounding box della superficie espresso nel sistema locale
BBox3d b3SurfBox ;
tmSurf.GetLocalBBox( b3SurfBox) ;
@@ -1862,7 +1879,7 @@ VolZmap::AvoidSurfTm( const ISurfTriMesh& tmSurf, double dSafeDist, bool bPrecis
// Box intersezione: se non c'è intersezione ho finito.
BBox3d b3IntBox ;
if ( ! b3ZmapBox.FindIntersection( b3SurfBox, b3IntBox))
return true ;
return false ;
// Recupero i triangoli della superficie che cadono nel box intersezione.
INTVECTOR vTriaIndex ;
tmSurf.GetAllTriaOverlapBox( b3IntBox, vTriaIndex) ;
@@ -1923,7 +1940,7 @@ VolZmap::AvoidSurfTm( const ISurfTriMesh& tmSurf, double dSafeDist, bool bPrecis
for ( int nIndex = 0 ; nIndex < nSize ; nIndex += 1) {
if ( dZmax > m_Values[0][nPos][nIndex].dMin - EPS_SMALL &&
dZmin < m_Values[0][nPos][nIndex].dMax + EPS_SMALL)
return false ;
return true ;
}
}
}
@@ -1939,7 +1956,7 @@ VolZmap::AvoidSurfTm( const ISurfTriMesh& tmSurf, double dSafeDist, bool bPrecis
for ( int nIndex = 0 ; nIndex < nSize ; nIndex += 1) {
if ( dZmax > m_Values[0][nPos][nIndex].dMin - EPS_SMALL &&
dZmin < m_Values[0][nPos][nIndex].dMax + EPS_SMALL)
return false ;
return true ;
}
}
}
@@ -2030,11 +2047,11 @@ VolZmap::AvoidSurfTm( const ISurfTriMesh& tmSurf, double dSafeDist, bool bPrecis
double dU1, dU2 ;
int nIntersType = SegmentSphere( ptSegSt, vtLineDir, dSegLen, ptVertP, dSafeDist, dU1, dU2) ;
if ( nIntersType != LinCompSphereIntersType::S_NO_INTERS)
return false ;
return true ;
nIntersType = IntersSegmentCylinder( ptSegSt, vtLineDir, dSegLen, ptVertP, vtEdgeV,
dSafeDist, dEdgeLen, dU1, dU2) ;
if ( nIntersType != LinCompCCIntersType::CC_NO_INTERS)
return false ;
return true ;
}
// Traslo il triangolo.
trNewTria.Translate( dSafeDist * trTria.GetN()) ;
@@ -2044,14 +2061,14 @@ VolZmap::AvoidSurfTm( const ISurfTriMesh& tmSurf, double dSafeDist, bool bPrecis
int nIntersType = IntersLineTria( ptSegSt, vtLineDir, dSegLen, trNewTria, ptInt, ptInt2) ;
// Collisione
if ( nIntersType != IntLineTriaType::ILTT_NO)
return false ;
return true ;
}
}
}
}
}
return true ;
return false ;
}
//----------------------------------------------------------------------------