EgtGeomKernel 1.5h3 :
- aggiunta IsFlat a tutte le Curve - aggiunta ApproxWithArcs a tutte le Curve - aggiunto oggetto PolyArc (raccolta ordinata di linee e archi con bulge) - aggiunto oggetto PointsPCA per stima componenti principali di un insieme di punti - FromSpheriical e FromPolar di Vector3d sono diventati funzioni e aggiunto FromUprightOrtho - aggiunte Invert e a Vector3d.
This commit is contained in:
+132
-12
@@ -15,14 +15,14 @@
|
||||
#include "stdafx.h"
|
||||
#include "CurveComposite.h"
|
||||
#include "DistPointCrvComposite.h"
|
||||
#include "CurveLine.h"
|
||||
#include "CurveArc.h"
|
||||
#include "CurveBezier.h"
|
||||
#include "GeoConst.h"
|
||||
#include "GeoObjFactory.h"
|
||||
#include "NgeWriter.h"
|
||||
#include "NgeReader.h"
|
||||
#include "/EgtDev/Include/EGkStringUtils3d.h"
|
||||
#include "/EgtDev/Include/EGkCurveLine.h"
|
||||
#include "/EgtDev/Include/EGkCurveArc.h"
|
||||
#include "/EgtDev/Include/EGkCurveBezier.h"
|
||||
#include "/EgtDev/Include/EgtPointerOwner.h"
|
||||
#include <algorithm>
|
||||
|
||||
@@ -325,7 +325,7 @@ CurveComposite::FromPointBulgeVector( const UPNTVECTOR& vUPnt, const Vector3d& v
|
||||
// se retta
|
||||
if ( fabs( vUPnt[i-1].first) < EPS_SMALL) {
|
||||
// creo la retta
|
||||
PtrOwner<ICurveLine> pCrvLine( CreateCurveLine()) ;
|
||||
PtrOwner<CurveLine> pCrvLine( CreateBasicCurveLine()) ;
|
||||
if ( ! ::IsValid( pCrvLine))
|
||||
return false ;
|
||||
// setto la linea
|
||||
@@ -338,7 +338,7 @@ CurveComposite::FromPointBulgeVector( const UPNTVECTOR& vUPnt, const Vector3d& v
|
||||
// altrimenti arco
|
||||
else {
|
||||
// creo l'arco
|
||||
PtrOwner<ICurveArc> pCrvArc( CreateCurveArc()) ;
|
||||
PtrOwner<CurveArc> pCrvArc( CreateBasicCurveArc()) ;
|
||||
if ( ! ::IsValid( pCrvArc))
|
||||
return false ;
|
||||
// setto l'arco
|
||||
@@ -384,7 +384,7 @@ CurveComposite::PolygonCenterCorner( int nSides, const Point3d& ptCen, const Poi
|
||||
return false ;
|
||||
}
|
||||
// creo il segmento di retta
|
||||
PtrOwner<ICurveLine> pCrvLine( CreateCurveLine()) ;
|
||||
PtrOwner<CurveLine> pCrvLine( CreateBasicCurveLine()) ;
|
||||
if ( ! ::IsValid( pCrvLine))
|
||||
return false ;
|
||||
// assegno i punti estremi
|
||||
@@ -473,11 +473,11 @@ bool
|
||||
CurveComposite::CopyFrom( const IGeoObj* pGObjSrc)
|
||||
{
|
||||
// se sorgente è una curva composita
|
||||
const CurveComposite* pCC = dynamic_cast<const CurveComposite*>( pGObjSrc) ;
|
||||
const CurveComposite* pCC = GetBasicCurveComposite( pGObjSrc) ;
|
||||
if ( pCC != nullptr)
|
||||
return CopyFrom( *pCC) ;
|
||||
// se sorgente è un'altro tipo di curva
|
||||
const ICurve* pCrv = dynamic_cast<const ICurve*>( pGObjSrc) ;
|
||||
const ICurve* pCrv = GetCurve( pGObjSrc) ;
|
||||
if ( pCrv != nullptr) {
|
||||
Clear() ;
|
||||
return AddCurve( *pCrv) ;
|
||||
@@ -716,6 +716,89 @@ CurveComposite::Validate( void)
|
||||
return ( m_nStatus == OK) ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
CurveComposite::IsFlat( Plane3d& plPlane, double dToler) const
|
||||
{
|
||||
// verifico lo stato
|
||||
if ( m_nStatus != OK)
|
||||
return false ;
|
||||
|
||||
// polilinea dei punti rappresentativi
|
||||
PolyLine shPL ;
|
||||
// punto iniziale
|
||||
Point3d ptP ;
|
||||
if ( ! GetStartPoint( ptP) ||
|
||||
! shPL.AddUPoint( 0, ptP))
|
||||
return false ;
|
||||
// ciclo sulle curve semplici (aggiungo solo eventuali punti intermedi e finali)
|
||||
int nCount = 0 ;
|
||||
for ( const ICurve* pCrv = GetFirstCurve() ;
|
||||
pCrv != nullptr ;
|
||||
pCrv = GetNextCurve(), ++ nCount) {
|
||||
switch ( pCrv->GetType()) {
|
||||
case CRV_LINE :
|
||||
// punto finale
|
||||
if ( ! pCrv->GetEndPoint( ptP) ||
|
||||
! shPL.AddUPoint( nCount + 1, ptP))
|
||||
return false ;
|
||||
break ;
|
||||
case CRV_ARC :
|
||||
// punto a 1/3
|
||||
if ( ! pCrv->GetPointD1D2( 0.3333, ICurve::FROM_MINUS, ptP) ||
|
||||
! shPL.AddUPoint( nCount + 0.3333, ptP))
|
||||
return false ;
|
||||
// punto a 7/11
|
||||
if ( ! pCrv->GetPointD1D2( 0.6363, ICurve::FROM_MINUS, ptP) ||
|
||||
! shPL.AddUPoint( nCount + 0.6363, ptP))
|
||||
return false ;
|
||||
// punto finale
|
||||
if ( ! pCrv->GetEndPoint( ptP) ||
|
||||
! shPL.AddUPoint( nCount + 1, ptP))
|
||||
return false ;
|
||||
break ;
|
||||
case CRV_BEZ :
|
||||
{ const CurveBezier* pBez = GetBasicCurveBezier( pCrv) ;
|
||||
// inserisco tutti i punti di controllo tranne il primo
|
||||
int nLastPC = pBez->GetDegree() ;
|
||||
for ( int i = 1 ; i <= nLastPC ; ++ i) {
|
||||
double dU = nCount + i / double( nLastPC) ;
|
||||
if ( ! shPL.AddUPoint( dU, pBez->GetControlPoint( i)))
|
||||
return false ;
|
||||
}
|
||||
} break ;
|
||||
}
|
||||
}
|
||||
// recupero dati sulla planarità della polilinea
|
||||
int nRank ;
|
||||
Point3d ptCen ;
|
||||
Vector3d vtDir ;
|
||||
bool bFlat = shPL.IsFlat( nRank, ptCen, vtDir, dToler) ;
|
||||
// se punto
|
||||
switch ( nRank) {
|
||||
case 0 : // punto
|
||||
if ( bFlat) {
|
||||
plPlane.vtN = Z_AX ;
|
||||
plPlane.dDist = ( ptCen - ORIG) * plPlane.vtN ;
|
||||
}
|
||||
else {
|
||||
plPlane.vtN = V_NULL ;
|
||||
plPlane.dDist = 0 ;
|
||||
}
|
||||
break ;
|
||||
case 1 : // linea
|
||||
plPlane.vtN = FromUprightOrtho( vtDir) ;
|
||||
plPlane.dDist = ( ptCen - ORIG) * plPlane.vtN ;
|
||||
break ;
|
||||
default : // piana o 3d
|
||||
plPlane.vtN = vtDir ;
|
||||
plPlane.dDist = ( ptCen - ORIG) * plPlane.vtN ;
|
||||
break ;
|
||||
}
|
||||
|
||||
return bFlat ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
CurveComposite::GetStartPoint( Point3d& ptStart) const
|
||||
@@ -999,6 +1082,43 @@ CurveComposite::ApproxWithLines( double dLinTol, double dAngTolDeg, PolyLine& PL
|
||||
return true ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
CurveComposite::ApproxWithArcs( double dLinTol, double dAngTolDeg, PolyArc& PA) const
|
||||
{
|
||||
// pulisco il poliarco
|
||||
PA.Clear() ;
|
||||
|
||||
// verifico lo stato
|
||||
if ( m_nStatus != OK)
|
||||
return false ;
|
||||
|
||||
// eseguo approssimazione
|
||||
bool bFirst = true ;
|
||||
double dStartPar = 0 ;
|
||||
PolyArc PASmpl ;
|
||||
PCRVSMPL_DEQUE::const_iterator Iter ;
|
||||
for ( Iter = m_CrvSmplS.begin() ; Iter != m_CrvSmplS.end() ; ++Iter) {
|
||||
// recupero approssimazione per curva semplice
|
||||
if ( ! (*Iter)->ApproxWithArcs( dLinTol, dAngTolDeg, PASmpl))
|
||||
return false ;
|
||||
// la accodo opportunamente a quella della curva composita
|
||||
if ( bFirst) {
|
||||
PA.Splice( PASmpl) ;
|
||||
bFirst = false ;
|
||||
}
|
||||
else {
|
||||
PA.EraseLastUPoint() ;
|
||||
PASmpl.AddOffsetToU( dStartPar) ;
|
||||
PA.Splice( PASmpl) ;
|
||||
}
|
||||
// incremento inizio parametro per prossima curva semplice
|
||||
dStartPar += 1 ;
|
||||
}
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
ICurve*
|
||||
CurveComposite::CopyParamRange( double dUStart, double dUEnd) const
|
||||
@@ -1230,10 +1350,11 @@ CurveComposite::TrimStartEndAtParam( double dUStartTrim, double dUEndTrim)
|
||||
if ( dUStartTrim < - EPS_PARAM || dUStartTrim > m_nCounter + EPS_PARAM ||
|
||||
dUEndTrim < - EPS_PARAM || dUEndTrim > m_nCounter + EPS_PARAM)
|
||||
return false ;
|
||||
#if 0
|
||||
// verifico che i trim non cancellino interamente la curva
|
||||
if ( dUStartTrim > dUEndTrim - EPS_PARAM)
|
||||
return false ;
|
||||
#if 0
|
||||
#endif
|
||||
// se il parametro start supera quello di end
|
||||
if ( dUStartTrim > dUEndTrim - EPS_PARAM) {
|
||||
// se curva aperta, il trim la cancella completamente quindi errore
|
||||
@@ -1252,7 +1373,6 @@ CurveComposite::TrimStartEndAtParam( double dUStartTrim, double dUEndTrim)
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
// per parametro start : determino la curva di appartenenza e il valore locale del parametro
|
||||
int nCs ;
|
||||
double dUcs ;
|
||||
@@ -1757,11 +1877,11 @@ CurveComposite::ArcsToBezierCurves( void)
|
||||
for ( Iter = m_CrvSmplS.begin() ; Iter != m_CrvSmplS.end() ; ++Iter) {
|
||||
// se arco, devo trasformare in una o più curve di Bezier
|
||||
if ( (*Iter)->GetType() == CRV_ARC) {
|
||||
const ICurveArc* pArc = GetCurveArc( (*Iter)) ;
|
||||
const CurveArc* pArc = GetBasicCurveArc( (*Iter)) ;
|
||||
// se angolo al centro sotto il limite, basta una curva
|
||||
if ( fabs( pArc->GetAngCenter()) <= BEZARC_ANG_CEN_MAX + EPS_ANG_SMALL) {
|
||||
// creo la curva di Bezier
|
||||
PtrOwner<ICurveBezier> pCrvBez( CreateCurveBezier()) ;
|
||||
PtrOwner<CurveBezier> pCrvBez( CreateBasicCurveBezier()) ;
|
||||
if ( ! ::IsValid( pCrvBez))
|
||||
return false ;
|
||||
if ( ! pCrvBez->FromArc( *pArc))
|
||||
|
||||
Reference in New Issue
Block a user