EgtGeomKernel :
- correzione per memory leaks a offset semplice di curve composite - aggiunta creazione regione da curva ingrossata - collisione tra regioni estesa a contorni sia con curve composite sia con singola curva.
This commit is contained in:
+110
@@ -13,9 +13,11 @@
|
||||
|
||||
//--------------------------- Include ----------------------------------------
|
||||
#include "stdafx.h"
|
||||
#include "CurveLine.h"
|
||||
#include "CurveArc.h"
|
||||
#include "CurveComposite.h"
|
||||
#include "SurfFlatRegion.h"
|
||||
#include "GeoConst.h"
|
||||
#include "/EgtDev/Include/EGkSfrCreate.h"
|
||||
#include "/EgtDev/Include/EgtPointerOwner.h"
|
||||
#include <algorithm>
|
||||
@@ -106,6 +108,114 @@ GetSurfFlatRegionDisk( double dRadius)
|
||||
return Release( pSfr) ;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------
|
||||
ISurfFlatRegion*
|
||||
GetSurfFlatRegionFromFatCurve( ICurve* pCrv, double dRadius, bool bSquareEnds, bool bSquareMids)
|
||||
{
|
||||
// mi impossesso della curva
|
||||
PtrOwner<ICurve> pCurve( pCrv) ;
|
||||
if ( IsNull( pCurve))
|
||||
return nullptr ;
|
||||
// la inserisco in una curva composita
|
||||
PtrOwner<CurveComposite> pCompo1( CreateBasicCurveComposite()) ;
|
||||
if ( IsNull( pCompo1) || ! pCompo1->AddCurve( Release( pCurve)))
|
||||
return nullptr ;
|
||||
// se distanza tra gli estremi minore di due volte il raggio la chiudo
|
||||
Point3d ptStart, ptEnd ;
|
||||
pCompo1->GetStartPoint( ptStart) ;
|
||||
pCompo1->GetEndPoint( ptEnd) ;
|
||||
if ( Dist( ptStart, ptEnd) <= 2 * dRadius)
|
||||
pCompo1->Close() ;
|
||||
// tipo di offset
|
||||
int nOffsType = ( bSquareMids ? ICurve::OFF_EXTEND : ICurve::OFF_FILLET) ;
|
||||
// se curva chiusa
|
||||
if ( pCompo1->IsClosed()) {
|
||||
// fondo le curve allineate
|
||||
pCompo1->MergeCurves( LIN_TOL_SFR, ANG_TOL_STD_DEG) ;
|
||||
// ne faccio una copia e la inverto
|
||||
PtrOwner<ICurveComposite> pCompo2( GetCurveComposite( pCompo1->Clone())) ;
|
||||
if ( IsNull( pCompo2) || ! pCompo2->Invert())
|
||||
return nullptr ;
|
||||
// per creare la regione
|
||||
SurfFlatRegionByContours SfrCntr( false, false) ;
|
||||
// offset della prima curva a destra del raggio
|
||||
if ( pCompo1->SimpleOffset( dRadius, nOffsType))
|
||||
SfrCntr.AddCurve( Release( pCompo1)) ;
|
||||
// offset della seconda curva a destra del raggio
|
||||
if ( pCompo2->SimpleOffset( dRadius, nOffsType))
|
||||
SfrCntr.AddCurve( Release( pCompo2)) ;
|
||||
// creo la regione
|
||||
return SfrCntr.GetSurf() ;
|
||||
}
|
||||
// altrimenti
|
||||
else {
|
||||
// se richiesti estremi squadrati, la allungo del raggio alle due estremità
|
||||
if ( bSquareEnds) {
|
||||
pCompo1->ExtendStartByLen( dRadius) ;
|
||||
pCompo1->ExtendEndByLen( dRadius) ;
|
||||
}
|
||||
// fondo le curve allineate
|
||||
pCompo1->MergeCurves( LIN_TOL_SFR, ANG_TOL_STD_DEG) ;
|
||||
// ne faccio una copia e la inverto
|
||||
PtrOwner<ICurveComposite> pCompo2( GetCurveComposite( pCompo1->Clone())) ;
|
||||
if ( IsNull( pCompo2) || ! pCompo2->Invert())
|
||||
return nullptr ;
|
||||
// offset della prima curva a destra del raggio
|
||||
if ( ! pCompo1->SimpleOffset( dRadius, nOffsType))
|
||||
return nullptr ;
|
||||
// offset della seconda curva a destra del raggio
|
||||
if ( ! pCompo2->SimpleOffset( dRadius, nOffsType))
|
||||
return nullptr ;
|
||||
// se estremi squadrati
|
||||
if ( bSquareEnds) {
|
||||
// aggiungo alla prima curva una linea che la unisca alla seconda
|
||||
PtrOwner<CurveLine> pLine( CreateBasicCurveLine()) ;
|
||||
Point3d ptEnd1, ptStart2 ;
|
||||
if ( IsNull( pLine) ||
|
||||
! pCompo1->GetEndPoint( ptEnd1) ||
|
||||
! pCompo2->GetStartPoint( ptStart2) ||
|
||||
! pLine->Set( ptEnd1, ptStart2) ||
|
||||
! pCompo1->AddCurve( Release( pLine)))
|
||||
return nullptr ;
|
||||
// unisco le due curve composite e le chiudo
|
||||
if ( ! pCompo1->AddCurve( Release( pCompo2)) || ! pCompo1->Close())
|
||||
return nullptr ;
|
||||
}
|
||||
// altrimenti estremi arrotondati
|
||||
else {
|
||||
// aggiungo alla prima curva un arco che la unisca alla seconda
|
||||
PtrOwner<CurveArc> pArc1( CreateBasicCurveArc()) ;
|
||||
Point3d ptEnd1, ptStart2 ;
|
||||
Vector3d vtDirEnd1 ;
|
||||
if ( IsNull( pArc1) ||
|
||||
! pCompo1->GetEndPoint( ptEnd1) ||
|
||||
! pCompo1->GetEndDir( vtDirEnd1) ||
|
||||
! pCompo2->GetStartPoint( ptStart2) ||
|
||||
! pArc1->Set2PVN( ptEnd1, ptStart2, vtDirEnd1, Z_AX) ||
|
||||
! pCompo1->AddCurve( Release( pArc1)))
|
||||
return nullptr ;
|
||||
// aggiungo alla seconda curva un arco che la unisca alla prima
|
||||
PtrOwner<CurveArc> pArc2( CreateBasicCurveArc()) ;
|
||||
Point3d ptEnd2, ptStart1 ;
|
||||
Vector3d vtDirEnd2 ;
|
||||
if ( IsNull( pArc2) ||
|
||||
! pCompo2->GetEndPoint( ptEnd2) ||
|
||||
! pCompo2->GetEndDir( vtDirEnd2) ||
|
||||
! pCompo1->GetStartPoint( ptStart1) ||
|
||||
! pArc2->Set2PVN( ptEnd2, ptStart1, vtDirEnd2, Z_AX) ||
|
||||
! pCompo2->AddCurve( Release( pArc2)))
|
||||
return nullptr ;
|
||||
// unisco le due curve composite
|
||||
if ( ! pCompo1->AddCurve( Release( pCompo2)))
|
||||
return nullptr ;
|
||||
}
|
||||
// creo la regione
|
||||
SurfFlatRegionByContours SfrCntr( false, false) ;
|
||||
SfrCntr.AddCurve( Release( pCompo1)) ;
|
||||
return SfrCntr.GetSurf() ;
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------
|
||||
// Classe SurfFlatRegionByContours
|
||||
//-------------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user