c57a6db4ae
- aggiunta funzione CurveSimpleMedialAxis (primi sviluppi).
87 lines
2.6 KiB
C++
87 lines
2.6 KiB
C++
//----------------------------------------------------------------------------
|
|
// EgalTech 2022-2022
|
|
//----------------------------------------------------------------------------
|
|
// File : MedialAxis.cpp Data : 22.08.22 Versione : 2.4h2
|
|
// Contenuto : Funzione calcolo approssimato MedialAxis principale.
|
|
//
|
|
//
|
|
//
|
|
// Modifiche : 22.08.22 DS Creazione modulo.
|
|
//
|
|
//
|
|
//
|
|
//----------------------------------------------------------------------------
|
|
|
|
//--------------------------- Include ----------------------------------------
|
|
#include "stdafx.h"
|
|
#include "GeoConst.h"
|
|
#include "CurveArc.h"
|
|
#include "CurveBezier.h"
|
|
#include "CurveComposite.h"
|
|
#include "/EgtDev/Include/EGkBBox3d.h"
|
|
#include "/EgtDev/Include/EGkMedialAxis.h"
|
|
|
|
using namespace std ;
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
CurveSimpleMedialAxis( const ICurve* pCrv, PolyLine& PL)
|
|
{
|
|
// pulizia della polilinea
|
|
PL.Clear() ;
|
|
// verifico che la curva esista
|
|
if ( pCrv == nullptr)
|
|
return false ;
|
|
// verifico che la curva sia chiusa
|
|
if ( ! pCrv->IsClosed())
|
|
return false ;
|
|
// verifico che la curva sia piana
|
|
Plane3d plPlane ;
|
|
if ( ! pCrv->IsFlat( plPlane, false, 10 * EPS_SMALL))
|
|
return false ;
|
|
// eventuali trasformazioni in composita
|
|
CurveComposite crvCompo ;
|
|
if ( pCrv->GetType() == CRV_ARC) {
|
|
const CurveArc* pArc = GetBasicCurveArc( pCrv) ;
|
|
crvCompo.AddCurve( *pArc) ;
|
|
}
|
|
else if ( pCrv->GetType() == CRV_BEZIER) {
|
|
const CurveBezier* pBez = GetBasicCurveBezier( pCrv) ;
|
|
PolyArc PA ;
|
|
if ( ! pBez->ApproxWithArcs( 10 * EPS_SMALL, ANG_TOL_STD_DEG, PA) || ! crvCompo.FromPolyArc( PA))
|
|
return false ;
|
|
}
|
|
else if ( pCrv->GetType() == CRV_COMPO) {
|
|
crvCompo.AddCurve( *pCrv) ;
|
|
}
|
|
else
|
|
return false ;
|
|
// se è una circonferenza
|
|
Point3d ptCen ; Vector3d vtN ; double dRad ; bool bCCW ;
|
|
if ( crvCompo.IsACircle( 10 * EPS_SMALL, ptCen, vtN, dRad, bCCW)) {
|
|
PL.AddUPoint( 0, ptCen) ;
|
|
return true ;
|
|
}
|
|
// la porto nel riferimento del piano
|
|
Frame3d frLoc ;
|
|
frLoc.Set( ORIG, plPlane.GetVersN()) ;
|
|
crvCompo.ToLoc( frLoc) ;
|
|
// ne calcolo il box
|
|
BBox3d b3Compo ;
|
|
if ( ! crvCompo.GetLocalBBox( b3Compo, BBF_STANDARD))
|
|
return false ;
|
|
// per prova
|
|
PL.AddUPoint( 0, GetToGlob( b3Compo.GetMin(), frLoc)) ;
|
|
PL.AddUPoint( 1, GetToGlob( b3Compo.GetMax(), frLoc)) ;
|
|
|
|
// ricerca di un punto di partenza
|
|
//CurveArc Circle ;
|
|
//Point3d ptStart ; crvCompo.GetStartPoint( ptStart) ;
|
|
//double dDiam ; b3Compo.GetDiameter( dDiam) ;
|
|
//Circle.Set( ptStart, Z_AX, dDiam / 8.0) ;
|
|
|
|
|
|
|
|
return true ;
|
|
}
|