EgtExecutor 2.2d2 :

- aggiustamenti vari per IsFlat, FromPlaneTrimmedWithBox e GetSurfTriMeshPlaneInBox
- aggiunta funzione Exe e Lua TrimFlatCurveWithBox.
This commit is contained in:
Dario Sassi
2020-04-13 09:07:32 +00:00
parent 8824491888
commit 54c8818cc5
6 changed files with 148 additions and 8 deletions
+110
View File
@@ -35,6 +35,7 @@
#include "/EgtDev/Include/EGkGdbIterator.h"
#include "/EgtDev/Include/EGkStringUtils3d.h"
#include "/EgtDev/Include/EGkIntervals.h"
#include "/EgtDev/Include/EGkPolygon3d.h"
#include "/EgtDev/Include/EgtPointerOwner.h"
#include <functional>
@@ -801,6 +802,115 @@ ExeTrimCurveWithRegion( int nCrvId, int nRegId, bool bInVsOut, bool bOn, int* pn
return nFirstId ;
}
//----------------------------------------------------------------------------
static int
MyTrimFlatCurveWithBox( int nCrvId, const Frame3d& frBox, const Vector3d& vtDiag, bool bInVsOut, bool bOn, int nRefType, int& nCount)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
// recupero la curva
ICurve* pCrv = GetCurve( pGeomDB->GetGeoObj( nCrvId)) ;
if ( pCrv == nullptr)
return GDB_ID_NULL ;
// recupero il riferimento della curva
Frame3d frCrv ;
if ( ! pGeomDB->GetGlobFrame( nCrvId, frCrv))
return GDB_ID_NULL ;
// determino il piano della curva (annullo temporaneamente l'estrusione per non avere problemi)
Plane3d plPlane ;
if ( ! pCrv->IsFlat( plPlane, false, 10 * EPS_SMALL))
return GDB_ID_NULL ;
// porto in locale alla curva il riferimento del box (il vettore è già in locale a questo stesso riferimento)
Frame3d frBoxL = GetFrameLocal( pGeomDB, frBox, nRefType, frCrv) ;
// determino la parte di piano (poligono) compresa nel box (applicando le opportune trasformazioni di riferimento)
plPlane.ToLoc( frBoxL) ;
Polygon3d Polyg ;
if ( ! Polyg.FromPlaneTrimmedWithBox( plPlane, ORIG, ORIG + vtDiag, bOn, bOn))
return GDB_ID_NULL ;
Polyg.ToGlob( frBoxL) ;
// se poligono vuoto, la curva non interseca il box
if ( Polyg.GetSideCount() == 0) {
if ( bInVsOut) {
pGeomDB->Erase( nCrvId) ;
nCount = 0 ;
}
else
nCount = 1 ;
return nCrvId ;
}
// creo la regione corrispondente
PtrOwner<ICurveComposite> pContour( CreateCurveComposite()) ;
if ( IsNull( pContour) || ! pContour->FromPolyLine( Polyg.GetPolyLine()))
return false ;
PtrOwner<ISurfFlatRegion> pSfr( CreateSurfFlatRegion()) ;
if ( IsNull( pSfr) || ! pSfr->AddExtLoop( Release( pContour)))
return false ;
// calcolo la classificazione della curva rispetto alla regione
CRVCVECTOR ccClass ;
if ( ! pSfr->GetCurveClassification( *pCrv, ccClass))
return GDB_ID_NULL ;
// determino gli intervalli di curva da conservare
Intervals inOk ;
for ( auto& ccOne : ccClass) {
if ( ( bInVsOut && ccOne.nClass == CRVC_IN) ||
( ! bInVsOut && ccOne.nClass == CRVC_OUT) ||
( bOn && ( ccOne.nClass == CRVC_ON_P || ccOne.nClass == CRVC_ON_M)))
inOk.Add( ccOne.dParS, ccOne.dParE) ;
}
// recupero un intervallo di id contigui per tutte le parti
int nFirstId = pGeomDB->GetNewId() ;
if ( ! pGeomDB->ChangeId( nCrvId, nFirstId))
return GDB_ID_NULL ;
int nCurrId = nFirstId ;
// eseguo la divisione
nCount = 0 ;
double dParS, dParE ;
bool bFound = inOk.GetFirst( dParS, dParE) ;
while ( bFound) {
// copio la curva
int nCopyId = pGeomDB->Copy( nCurrId, GDB_ID_NULL, nCurrId, GDB_AFTER) ;
ICurve* pCopyCrv = GetCurve( pGeomDB->GetGeoObj( nCopyId)) ;
if ( pCopyCrv == nullptr)
return GDB_ID_NULL ;
++ nCount ;
// modifico l'originale
if ( ! pCrv->TrimStartEndAtParam( dParS, dParE))
return GDB_ID_NULL ;
// la copia diventa il nuovo corrente
nCurrId = nCopyId ;
pCrv = pCopyCrv ;
// passo alla successiva divisione
bFound = inOk.GetNext( dParS, dParE) ;
}
// cancello l'ultima copia (se non c'erano intervalli validi è l'originale)
pGeomDB->Erase( nCurrId) ;
return nFirstId ;
}
//----------------------------------------------------------------------------
int
ExeTrimFlatCurveWithBox( int nCrvId, const Frame3d& frBox, const Vector3d& vtDiag, bool bInVsOut, bool bOn, int nRefType, int* pnCount)
{
int nCount ;
int nFirstId = MyTrimFlatCurveWithBox( nCrvId, frBox, vtDiag, bInVsOut, bOn, nRefType, nCount) ;
ExeSetModified() ;
// se richiesto, salvo il comando Lua equivalente
if ( IsCmdLog()) {
string sLua = "EgtTrimFlatCurveWithBox(" + ToString( nCrvId) + "," +
ToString( frBox) + "," +
ToString( vtDiag) + "," +
ToString( bInVsOut) + "," +
ToString( bOn) + "," +
RefTypeToString( nRefType) + ")" +
" -- Id1=" + ToString( nFirstId) + ",Nbr=" + ToString( nCount) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
// restituisco risultati
if ( pnCount != nullptr)
*pnCount = nCount ;
return nFirstId ;
}
//----------------------------------------------------------------------------
int
ExeSplitCurve( int nId, int nParts)