EgtExecutor 2.1f1 :

-aggiunta funzione Exe e Lua PlaneBoxInters.
This commit is contained in:
Dario Sassi
2019-06-12 10:58:56 +00:00
parent b7c42d4939
commit b4130e6e24
3 changed files with 206 additions and 1 deletions
+173 -1
View File
@@ -134,6 +134,178 @@ ExeLineBoxInters( const Point3d& ptP, const Vector3d& vtDir, const BBox3d& b3Box
return bOk ;
}
//-------------------------------------------------------------------------------
static int
MyPlaneBoxInters( const Point3d& ptOn, const Vector3d& vtN, const BBox3d& b3Box, int nDestGrpId, int nRefType,
int& nPntCount, int& nCrvCount, int& nSrfCount)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
// recupero il riferimento del gruppo di destinazione
Frame3d frDest ;
if ( ! pGeomDB->GetGroupGlobFrame( nDestGrpId, frDest))
return GDB_ID_NULL ;
// porto in locale il punto e la normale del piano
Point3d ptOnL = GetPointLocal( pGeomDB, ptOn, nRefType, frDest) ;
Vector3d vtNL = GetVectorLocal( pGeomDB, vtN, nRefType, frDest) ;
// calcolo il piano di intersezione
Plane3d plPlane ;
if ( ! plPlane.Set( ptOnL, vtNL))
return GDB_ID_NULL ;
// Creo la superficie trimesh e la porto in locale
Point3d ptMin ;
double dDimX, dDimY, dDimZ ;
if ( ! b3Box.GetMinDim( ptMin, dDimX, dDimY, dDimZ))
return false ;
PtrOwner<ISurfTriMesh> pStm( GetSurfTriMeshBox( dDimX, dDimY, dDimZ)) ;
if ( IsNull( pStm))
return false ;
pStm->Translate( ptMin - ORIG) ;
pStm->ToLoc( frDest) ;
// eseguo l'intersezione
PNTVECTOR vPnt ;
BIPNTVECTOR vBpt ;
TRIA3DVECTOR vTria ;
if ( ! IntersPlaneSurfTm( plPlane, *pStm, vPnt, vBpt, vTria))
return GDB_ID_NULL ;
// Inserisco il risultato nel DB
int nFirstId = GDB_ID_NULL ;
// Inserisco i punti nel DB
for ( size_t i = 0 ; i < vPnt.size() ; ++ i) {
// creo il punto
PtrOwner<IGeoPoint3d> pGeoPnt( CreateGeoPoint3d()) ;
if ( IsNull( pGeoPnt))
return GDB_ID_NULL ;
// setto il punto
pGeoPnt->Set( vPnt[i]) ;
// lo inserisco nel DB geometrico
int nNewId = pGeomDB->AddGeoObj( GDB_ID_NULL, nDestGrpId, Release( pGeoPnt)) ;
if ( nNewId == GDB_ID_NULL)
return GDB_ID_NULL ;
// aggiorno contatori
if ( nFirstId == GDB_ID_NULL)
nFirstId = nNewId ;
++ nPntCount ;
}
// Concateno i tratti di curva
double dToler = 20 * EPS_SMALL ;
ChainCurves chainC ;
chainC.Init( false, dToler, int( vBpt.size())) ;
for ( size_t i = 0 ; i < vBpt.size() ; ++ i) {
Vector3d vtDir = vBpt[i].second - vBpt[i].first ;
vtDir.Normalize() ;
if ( ! chainC.AddCurve( int( i) + 1, vBpt[i].first, vtDir, vBpt[i].second, vtDir))
return GDB_ID_NULL ;
}
// recupero i percorsi concatenati
Point3d ptNear = ( vBpt.empty() ? ORIG : vBpt[0].first) ;
INTVECTOR vId ;
while ( chainC.GetChainFromNear( ptNear, false, vId)) {
// creo una curva composita
PtrOwner<ICurveComposite> pCrvCompo( CreateCurveComposite()) ;
if ( IsNull( pCrvCompo))
return GDB_ID_NULL ;
// recupero gli estremi dei segmenti, creo le linee e le inserisco nella composita
for ( size_t i = 0 ; i < vId.size() ; ++ i) {
// creo una segmento di retta
int nInd = abs( vId[i]) - 1 ;
bool bInvert = ( vId[i] < 0) ;
PtrOwner<ICurveLine> pLine( CreateCurveLine()) ;
if ( IsNull( pLine) || ! pLine->Set( vBpt[nInd].first, vBpt[nInd].second))
return GDB_ID_NULL ;
if ( bInvert)
pLine->Invert() ;
// lo accodo alla composita
if ( ! pCrvCompo->AddCurve( Release( pLine), true, dToler))
return GDB_ID_NULL ;
// aggiorno il prossimo near
ptNear = vBpt[nInd].second ;
}
// se lunghezza curva inferiore a 5 volte la tolleranza, la salto
double dCrvLen ;
if ( ! pCrvCompo->GetLength( dCrvLen) || dCrvLen < 5. * dToler)
continue ;
// se curva chiusa entro 5 volte la tolleranza ma considerata aperta, la chiudo bene
Point3d ptStart, ptEnd ;
if ( pCrvCompo->GetStartPoint( ptStart) &&
pCrvCompo->GetEndPoint( ptEnd) &&
AreSamePointEpsilon( ptStart, ptEnd, 5. * dToler) &&
! AreSamePointApprox( ptStart, ptEnd)) {
// porto il punto finale a coincidere esattamente con l'inizio
pCrvCompo->ModifyEnd( ptStart) ;
}
// assegno estrusione come direzione normale al piano
pCrvCompo->SetExtrusion( plPlane.GetVersN()) ;
// unisco segmenti allineati
pCrvCompo->MergeCurves( 0.5 * dToler, ANG_TOL_STD_DEG) ;
// la inserisco nel DB geometrico
int nNewId = pGeomDB->AddGeoObj( GDB_ID_NULL, nDestGrpId, Release( pCrvCompo)) ;
if ( nNewId == GDB_ID_NULL)
return GDB_ID_NULL ;
// aggiorno contatori
if ( nFirstId == GDB_ID_NULL)
nFirstId = nNewId ;
++ nCrvCount ;
}
// Costruisco una superficie trimesh dall'insieme di triangoli
StmFromTriangleSoup StmFts ;
if ( ! StmFts.Start())
return GDB_ID_NULL ;
for ( size_t i = 0 ; i < vTria.size() ; ++ i)
// inserisco il triangolo nella nuova superficie
StmFts.AddTriangle( vTria[i]) ;
// valido la superficie e calcolo le adiacenze
if ( ! StmFts.End())
return GDB_ID_NULL ;
// se superficie con triangoli
PtrOwner<ISurfTriMesh> pNewStm( StmFts.GetSurf()) ;
if ( ! IsNull( pNewStm) && pNewStm->GetTriangleCount() > 0) {
// la inserisco nel DB
int nNewId = pGeomDB->AddGeoObj( GDB_ID_NULL, nDestGrpId, Release( pNewStm)) ;
if ( nNewId == GDB_ID_NULL)
return GDB_ID_NULL ;
// aggiorno contatori
if ( nFirstId == GDB_ID_NULL)
nFirstId = nNewId ;
++ nSrfCount ;
}
// restituisco l'identificativo della prima nuova entità
return nFirstId ;
}
//-------------------------------------------------------------------------------
int
ExePlaneBoxInters( const Point3d& ptOn, const Vector3d& vtN, const BBox3d& b3Box, int nDestGrpId, int nRefType,
int* pnPntCount, int* pnCrvCount, int* pnSrfCount)
{
// eseguo
int nPntCount{ 0}, nCrvCount{ 0}, nSrfCount{ 0} ;
int nFirstId = MyPlaneBoxInters( ptOn, vtN, b3Box, nDestGrpId, nRefType, nPntCount, nCrvCount, nSrfCount) ;
// aggiorno contatori
if ( nFirstId != GDB_ID_NULL) {
if ( pnPntCount != nullptr)
*pnPntCount = nPntCount ;
if ( pnCrvCount != nullptr)
*pnCrvCount = nCrvCount ;
if ( pnSrfCount != nullptr)
*pnSrfCount = nSrfCount ;
ExeSetModified() ;
}
// se richiesto, salvo il comando Lua equivalente
if ( IsCmdLog()) {
string sLua = "EgtPlaneBoxInters({" + ToString( ptOn) + "},{" +
ToString( vtN) + "},{" +
ToString( b3Box) + "}," +
ToString( nDestGrpId) + "," +
RefTypeToString( nRefType) + ")" +
" -- Id1=" + ToString( nFirstId) + ", PntNbr=" + ToString( nPntCount) +
", CrvNbr=" + ToString( nCrvCount) + ", SrfNbr=" + ToString( nSrfCount) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
// restituisco l'identificativo della prima nuova entità
return nFirstId ;
}
//-------------------------------------------------------------------------------
static bool
MyLineSurfTmInters( const Point3d& ptP, const Vector3d& vtDir, int nId, int nRefType, INTDBLVECTOR& vInters)
@@ -279,7 +451,7 @@ MyPlaneSurfTmInters( const Point3d& ptOn, const Vector3d& vtN, int nId, int nDes
for ( size_t i = 0 ; i < vPnt.size() ; ++ i) {
// creo il punto
PtrOwner<IGeoPoint3d> pGeoPnt( CreateGeoPoint3d()) ;
if ( ! IsNull( pGeoPnt))
if ( IsNull( pGeoPnt))
return GDB_ID_NULL ;
// setto il punto
pGeoPnt->Set( vPnt[i]) ;
BIN
View File
Binary file not shown.
+33
View File
@@ -53,6 +53,38 @@ LuaLineBoxInters( lua_State* L)
return 3 ;
}
//----------------------------------------------------------------------------
static int
LuaPlaneBoxInters( lua_State* L)
{
// 4 o 5 parametri : ptOn, vtN, b3Box, nDestGrpId [, nRefType]
Point3d ptOn ;
LuaCheckParam( L, 1, ptOn)
Vector3d vtN ;
LuaCheckParam( L, 2, vtN)
BBox3d b3Box ;
LuaCheckParam( L, 3, b3Box)
int nDestGrpId ;
LuaGetParam( L, 4, nDestGrpId) ;
int nRefType = RTY_DEFAULT ;
LuaGetParam( L, 5, nRefType) ;
LuaClearStack( L) ;
// eseguo l'intersezione
int nPntCount = 0 ;
int nCrvCount = 0 ;
int nSrfCount = 0 ;
int nNewId = ExePlaneBoxInters( ptOn, vtN, b3Box, nDestGrpId, nRefType, &nPntCount, &nCrvCount, &nSrfCount) ;
// restituisco il risultato
if ( nNewId != GDB_ID_NULL)
LuaSetParam( L, nNewId) ;
else
LuaSetParam( L) ;
LuaSetParam( L, nPntCount) ;
LuaSetParam( L, nCrvCount) ;
LuaSetParam( L, nSrfCount) ;
return 4 ;
}
//----------------------------------------------------------------------------
static int
LuaLineSurfTmInters( lua_State* L)
@@ -220,6 +252,7 @@ LuaInstallGeoInters( LuaMgr& luaMgr)
{
bool bOk = ( &luaMgr != nullptr) ;
bOk = bOk && luaMgr.RegisterFunction( "EgtLineBoxInters", LuaLineBoxInters) ;
bOk = bOk && luaMgr.RegisterFunction( "EgtPlaneBoxInters", LuaPlaneBoxInters) ;
bOk = bOk && luaMgr.RegisterFunction( "EgtLineSurfTmInters", LuaLineSurfTmInters) ;
bOk = bOk && luaMgr.RegisterFunction( "EgtPlaneSurfTmInters", LuaPlaneSurfTmInters) ;
bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmSurfTmInters", LuaSurfTmSurfTmInters) ;