EgtExecutor 1.9h3 :

- aggiunte funzioni Exe e Lua GetSurfTmSurfTmInters
- rinominate funzioni Exe e Lua CutSurfTm in CutSurfTmPlane.
This commit is contained in:
Dario Sassi
2018-08-30 07:28:06 +00:00
parent 54ccef35d1
commit cadbc1e67b
3 changed files with 227 additions and 16 deletions
+194 -12
View File
@@ -30,6 +30,7 @@
#include "/EgtDev/Include/EGkStmFromTriangleSoup.h"
#include "/EgtDev/Include/EGkCAvSimpleSurfFrMove.h"
#include "/EgtDev/Include/EGkIntersPlaneSurfTm.h"
#include "/EgtDev/Include/EGkIntersSurfTmSurfTm.h"
#include "/EgtDev/Include/EGkStringUtils3d.h"
#include "/EgtDev/Include/EgtPointerOwner.h"
@@ -776,13 +777,15 @@ ExeGetSurfTmPlaneInters( int nId, const Point3d& ptOn, const Vector3d& vtN, int
int nSrfCount = 0 ;
int nFirstId = MyGetSurfTmPlaneInters( nId, ptOn, vtN, nDestGrpId, nRefType, &nPntCount, &nCrvCount, &nSrfCount) ;
// aggiorno contatori
if ( pnPntCount != nullptr)
*pnPntCount = nPntCount ;
if ( pnCrvCount != nullptr)
*pnCrvCount = nCrvCount ;
if ( pnSrfCount != nullptr)
*pnSrfCount = nSrfCount ;
ExeSetModified() ;
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 = "EgtGetSurfTmPlaneInters(" + ToString( nId) + ",{" +
@@ -798,9 +801,188 @@ ExeGetSurfTmPlaneInters( int nId, const Point3d& ptOn, const Vector3d& vtN, int
return nFirstId ;
}
//-------------------------------------------------------------------------------
static int
MyGetSurfTmSurfTmInters( int nId1, int nId2, int nDestGrpId,
int* pnPntCount, int* pnCrvCount, int* pnSrfCount)
{
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 ;
// recupero la prima superficie TriMesh espressa nel riferimento destinazione
SurfLocal Surf1Loc( pGeomDB, nId1, frDest) ;
const ISurfTriMesh* pStm1L = GetSurfTriMesh( Surf1Loc) ;
if ( pStm1L == nullptr)
return GDB_ID_NULL ;
// recupero la seconda superficie TriMesh espressa nel riferimento destinazione
SurfLocal Surf2Loc( pGeomDB, nId2, frDest) ;
const ISurfTriMesh* pStm2L = GetSurfTriMesh( Surf2Loc) ;
if ( pStm2L == nullptr)
return GDB_ID_NULL ;
// eseguo l'intersezione (già espressa nel riferimento destinazione)
PNTVECTOR vPnt ;
BIPNTVECTOR vBpt ;
TRIA3DVECTOR vTria ;
if ( ! IntersSurfTmSurfTm( *pStm1L, *pStm2L, vPnt, vBpt, vTria))
return GDB_ID_NULL ;
// Inserisco il risultato nel DB
int nFirstId = GDB_ID_NULL ;
int nPntCount = 0 ;
int nCrvCount = 0 ;
int nSrfCount = 0 ;
// 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 ;
// copio il materiale
if ( ! pGeomDB->CopyMaterial( nId1, nNewId))
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 = vId[i] - 1 ;
PtrOwner<ICurveLine> pLine( CreateCurveLine()) ;
if ( IsNull( pLine) || ! pLine->Set( vBpt[nInd].first, vBpt[nInd].second))
return GDB_ID_NULL ;
// 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) ;
}
// 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 ;
// copio il materiale
if ( ! pGeomDB->CopyMaterial( nId1, nNewId))
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 ;
// copio il materiale
if ( ! pGeomDB->CopyMaterial( nId1, nNewId))
return GDB_ID_NULL ;
// aggiorno contatori
if ( nFirstId == GDB_ID_NULL)
nFirstId = nNewId ;
++ nSrfCount ;
}
// aggiorno contatori
if ( pnPntCount != nullptr)
*pnPntCount = nPntCount ;
if ( pnCrvCount != nullptr)
*pnCrvCount = nCrvCount ;
if ( pnSrfCount != nullptr)
*pnSrfCount = nSrfCount ;
// restituisco l'identificativo della prima nuova entità
return nFirstId ;
}
//-------------------------------------------------------------------------------
int
ExeGetSurfTmSurfTmInters( int nId1, int nId2, int nDestGrpId,
int* pnPntCount, int* pnCrvCount, int* pnSrfCount)
{
// eseguo
int nPntCount = 0 ;
int nCrvCount = 0 ;
int nSrfCount = 0 ;
int nFirstId = MyGetSurfTmSurfTmInters( nId1, nId2, nDestGrpId, &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 = "EgtGetSurfTmSurfTmInters(" + ToString( nId1) + "," +
ToString( nId2) + "," +
ToString( nDestGrpId) + ")" +
" -- 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 ;
}
//-------------------------------------------------------------------------------
bool
ExeCutSurfTm( int nId, const Point3d& ptOn, const Vector3d& vtN, bool bSaveOnEq, int nRefType)
ExeCutSurfTmPlane( int nId, const Point3d& ptOn, const Vector3d& vtN, bool bSaveOnEq, int nRefType)
{
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
@@ -821,10 +1003,10 @@ ExeCutSurfTm( int nId, const Point3d& ptOn, const Vector3d& vtN, bool bSaveOnEq,
ExeSetModified() ;
// se richiesto, salvo il comando Lua equivalente
if ( IsCmdLog()) {
string sLua = "EgtCutSurfTm(" + ToString( nId) + ",{" +
ToString( ptOn) + "},{" +
ToString( vtN) + "}," +
RefTypeToString( nRefType) + ")" +
string sLua = "EgtCutSurfTmPlane(" + ToString( nId) + ",{" +
ToString( ptOn) + "},{" +
ToString( vtN) + "}," +
RefTypeToString( nRefType) + ")" +
" -- Ok=" + ToString( bOk) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}