diff --git a/EXE_GeoInters.cpp b/EXE_GeoInters.cpp index 25c6a6a..2ac6a3f 100644 --- a/EXE_GeoInters.cpp +++ b/EXE_GeoInters.cpp @@ -35,6 +35,7 @@ #include "/EgtDev/Include/EGkIntersPlaneSurfTm.h" #include "/EgtDev/Include/EGkIntersSurfTmSurfTm.h" #include "/EgtDev/Include/EGkStringUtils3d.h" +#include "/EgtDev/Include/EgtNumUtils.h" #include "/EgtDev/Include/EgtPointerOwner.h" using namespace std ; @@ -370,7 +371,7 @@ ExeLineSurfTmInters( const Point3d& ptP, const Vector3d& vtDir, int nId, int nRe //------------------------------------------------------------------------------- static int -MyPlaneSurfTmInters( const Point3d& ptOn, const Vector3d& vtN, int nId, int nDestGrpId, int nRefType, +MyPlaneSurfTmInters( const Point3d& ptOn, const Vector3d& vtN, int nId, int nDestGrpId, int nRefType, double dToler, int& nPntCount, int& nCrvCount, int& nSrfCount) { IGeomDB* pGeomDB = GetCurrGeomDB() ; @@ -425,7 +426,6 @@ MyPlaneSurfTmInters( const Point3d& ptOn, const Vector3d& vtN, int nId, int nDes ++ nPntCount ; } // Inserisco le curve nel DB (dopo averle concatenate) - double dToler = 20 * EPS_SMALL ; ChainCurves chainC ; chainC.Init( false, dToler, int( vBpt.size())) ; for ( int i = 0 ; i < int( vBpt.size()) ; ++ i) { @@ -443,22 +443,22 @@ MyPlaneSurfTmInters( const Point3d& ptOn, const Vector3d& vtN, int nId, int nDes if ( IsNull( pCrvCompo)) return GDB_ID_NULL ; // recupero gli estremi dei segmenti, creo le linee e le inserisco nella composita + bool bAdded = true ; for ( int i = 0 ; i < int( vId.size()) ; ++ i) { - // creo una segmento di retta - int nInd = abs( vId[i]) - 1 ; - bool bInvert = ( vId[i] < 0) ; + // creo un segmento di retta PtrOwner pLine( CreateCurveLine()) ; - if ( IsNull( pLine) || ! pLine->Set( vBpt[nInd].first, vBpt[nInd].second)) + if ( IsNull( pLine)) 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 ; + // recupero gli estremi (non vanno mai invertiti per opzione di concatenamento) + int nInd = abs( vId[i]) - 1 ; + Point3d ptStart = ( bAdded ? vBpt[nInd].first : ptNear) ; + Point3d ptEnd = vBpt[nInd].second ; + // provo ad accodarlo alla composita + bAdded = ( pLine->Set( ptStart, ptEnd) && + pCrvCompo->AddCurve( Release( pLine), true, dToler)) ; + ptNear = ( bAdded ? ptEnd : ptStart) ; } - // se lunghezza curva inferiore a 5 volte la tolleranza, la salto + // se lunghezza curva inferiore a 5 volte la tolleranza, la ignoro double dCrvLen ; if ( ! pCrvCompo->GetLength( dCrvLen) || dCrvLen < 5. * dToler) continue ; @@ -522,12 +522,12 @@ MyPlaneSurfTmInters( const Point3d& ptOn, const Vector3d& vtN, int nId, int nDes //------------------------------------------------------------------------------- int -ExePlaneSurfTmInters( const Point3d& ptOn, const Vector3d& vtN, int nId, int nDestGrpId, int nRefType, +ExePlaneSurfTmInters( const Point3d& ptOn, const Vector3d& vtN, int nId, int nDestGrpId, int nRefType, double dToler, int* pnPntCount, int* pnCrvCount, int* pnSrfCount) { // eseguo int nPntCount{ 0}, nCrvCount{ 0}, nSrfCount{ 0} ; - int nFirstId = MyPlaneSurfTmInters( ptOn, vtN, nId, nDestGrpId, nRefType, nPntCount, nCrvCount, nSrfCount) ; + int nFirstId = MyPlaneSurfTmInters( ptOn, vtN, nId, nDestGrpId, nRefType, dToler, nPntCount, nCrvCount, nSrfCount) ; // aggiorno contatori if ( nFirstId != GDB_ID_NULL) { if ( pnPntCount != nullptr) @@ -544,7 +544,8 @@ ExePlaneSurfTmInters( const Point3d& ptOn, const Vector3d& vtN, int nId, int nDe ToString( vtN) + "}," + ToString( nId) + "," + ToString( nDestGrpId) + "," + - RefTypeToString( nRefType) + ")" + + RefTypeToString( nRefType) + "," + + ToString( dToler) + ")" + " -- Id1=" + ToString( nFirstId) + ", PntNbr=" + ToString( nPntCount) + ", CrvNbr=" + ToString( nCrvCount) + ", SrfNbr=" + ToString( nSrfCount) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; @@ -555,10 +556,10 @@ ExePlaneSurfTmInters( const Point3d& ptOn, const Vector3d& vtN, int nId, int nDe //------------------------------------------------------------------------------- static bool -MyChainCurvesForSurfSurfInters( const BIPNTVECTOR& vBpt, IGeomDB* pGeomDB, int nDestGrpId, int nId1, int& nFirstId, int& nCrvCount) +MyChainCurvesForSurfSurfInters( const BIPNTVECTOR& vBpt, IGeomDB* pGeomDB, int nDestGrpId, int nId1, double dToler, + int& nFirstId, int& nCrvCount) { // Concateno i tratti di curva - const double dToler = 20 * EPS_SMALL ; ChainCurves chainC ; chainC.Init( false, dToler, int( vBpt.size())) ; for ( int i = 0 ; i < int( vBpt.size()) ; ++ i) { @@ -577,21 +578,20 @@ MyChainCurvesForSurfSurfInters( const BIPNTVECTOR& vBpt, IGeomDB* pGeomDB, int n if ( IsNull( pCrvCompo)) return false ; // recupero gli estremi dei segmenti, creo le linee e le inserisco nella composita + bool bAdded = true ; for ( int i = 0 ; i < int( vId.size()) ; ++ i) { // creo un segmento di retta - int nInd = abs( vId[i]) - 1 ; - bool bInvert = ( vId[i] < 0) ; PtrOwner pLine( CreateCurveLine()) ; - if ( IsNull( pLine) || ! pLine->Set( vBpt[nInd].first, vBpt[nInd].second)) - return false ; - if ( bInvert) - pLine->Invert() ; - // lo accodo alla composita - if ( ! pCrvCompo->AddCurve( Release( pLine), true, 1.1 * dToler) && - ! AreSamePointApprox( ptNear, ( bInvert ? vBpt[nInd].first : vBpt[nInd].second))) - return false ; - // aggiorno il prossimo near - ptNear = ( bInvert ? vBpt[nInd].first : vBpt[nInd].second) ; + if ( IsNull( pLine)) + return GDB_ID_NULL ; + // recupero gli estremi (non vanno mai invertiti per opzione di concatenamento) + int nInd = abs( vId[i]) - 1 ; + Point3d ptStart = ( bAdded ? vBpt[nInd].first : ptNear) ; + Point3d ptEnd = vBpt[nInd].second ; + // provo ad accodarlo alla composita + bAdded = ( pLine->Set( ptStart, ptEnd) && + pCrvCompo->AddCurve( Release( pLine), true, dToler)) ; + ptNear = ( bAdded ? ptEnd : ptStart) ; } // se lunghezza curva inferiore a 5 volte la tolleranza, la salto double dCrvLen ; @@ -663,7 +663,7 @@ MyChainCurvesForSurfSurfInters( const BIPNTVECTOR& vBpt, IGeomDB* pGeomDB, int n //------------------------------------------------------------------------------- static int -MySurfTmSurfTmInters( int nId1, int nId2, int nDestGrpId, +MySurfTmSurfTmInters( int nId1, int nId2, int nDestGrpId, double dToler, int& nPntCount, int& nCrvCount, int& nSrfCount) { IGeomDB* pGeomDB = GetCurrGeomDB() ; @@ -711,7 +711,7 @@ MySurfTmSurfTmInters( int nId1, int nId2, int nDestGrpId, ++ nPntCount ; } // Inserisco le curve nel DB (dopo averle concatenate) - if ( ! MyChainCurvesForSurfSurfInters( vBpt, pGeomDB, nDestGrpId, nId1, nFirstId, nCrvCount)) + if ( ! MyChainCurvesForSurfSurfInters( vBpt, pGeomDB, nDestGrpId, nId1, dToler, nFirstId, nCrvCount)) return GDB_ID_NULL ; // Inserisco i triangoli nel DB (dopo averli uniti in una superficie trimesh) StmFromTriangleSoup StmFts ; @@ -744,12 +744,12 @@ MySurfTmSurfTmInters( int nId1, int nId2, int nDestGrpId, //------------------------------------------------------------------------------- int -ExeSurfTmSurfTmInters( int nId1, int nId2, int nDestGrpId, +ExeSurfTmSurfTmInters( int nId1, int nId2, int nDestGrpId, double dToler, int* pnPntCount, int* pnCrvCount, int* pnSrfCount) { // eseguo int nPntCount{ 0}, nCrvCount{ 0}, nSrfCount{ 0} ; - int nFirstId = MySurfTmSurfTmInters( nId1, nId2, nDestGrpId, nPntCount, nCrvCount, nSrfCount) ; + int nFirstId = MySurfTmSurfTmInters( nId1, nId2, nDestGrpId, dToler, nPntCount, nCrvCount, nSrfCount) ; // aggiorno contatori if ( nFirstId != GDB_ID_NULL) { if ( pnPntCount != nullptr) @@ -764,7 +764,8 @@ ExeSurfTmSurfTmInters( int nId1, int nId2, int nDestGrpId, if ( IsCmdLog()) { string sLua = "EgtSurfTmSurfTmInters(" + ToString( nId1) + "," + ToString( nId2) + "," + - ToString( nDestGrpId) + ")" + + ToString( nDestGrpId) + "," + + ToString( dToler) + ")" + " -- Id1=" + ToString( nFirstId) + ", PntNbr=" + ToString( nPntCount) + ", CrvNbr=" + ToString( nCrvCount) + ", SrfNbr=" + ToString( nSrfCount) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; diff --git a/EgtExecutor.rc b/EgtExecutor.rc index d28f99b..3eb3697 100644 Binary files a/EgtExecutor.rc and b/EgtExecutor.rc differ diff --git a/LUA_GeoInters.cpp b/LUA_GeoInters.cpp index c812b93..a9d3a1d 100644 --- a/LUA_GeoInters.cpp +++ b/LUA_GeoInters.cpp @@ -124,7 +124,7 @@ LuaLineSurfTmInters( lua_State* L) static int LuaPlaneSurfTmInters( lua_State* L) { - // 4 o 5 parametri : ptOn, vtN, Id, nDestGrpId [, nRefType] + // 4 o 5 o 6 parametri : ptOn, vtN, Id, nDestGrpId [, nRefType] [, dToler] Point3d ptOn ; LuaCheckParam( L, 1, ptOn) Vector3d vtN ; @@ -134,13 +134,15 @@ LuaPlaneSurfTmInters( lua_State* L) int nDestGrpId ; LuaGetParam( L, 4, nDestGrpId) ; int nRefType = RTY_DEFAULT ; - LuaGetParam( L, 5, nRefType) ; + double dToler = 20 * EPS_SMALL ; + if ( LuaGetParam( L, 5, nRefType)) + LuaGetParam( L, 6, dToler) ; LuaClearStack( L) ; // eseguo l'intersezione int nPntCount = 0 ; int nCrvCount = 0 ; int nSrfCount = 0 ; - int nNewId = ExePlaneSurfTmInters( ptOn, vtN, nId, nDestGrpId, nRefType, &nPntCount, &nCrvCount, &nSrfCount) ; + int nNewId = ExePlaneSurfTmInters( ptOn, vtN, nId, nDestGrpId, nRefType, dToler, &nPntCount, &nCrvCount, &nSrfCount) ; // restituisco il risultato if ( nNewId != GDB_ID_NULL) LuaSetParam( L, nNewId) ; @@ -156,19 +158,21 @@ LuaPlaneSurfTmInters( lua_State* L) static int LuaSurfTmSurfTmInters( lua_State* L) { - // 3 parametri : Id1, nId2, nDestGrpId + // 3 o 4 parametri : Id1, nId2, nDestGrpId [, dToler] int nId1 ; LuaCheckParam( L, 1, nId1) int nId2 ; LuaCheckParam( L, 2, nId2) int nDestGrpId ; LuaCheckParam( L, 3, nDestGrpId) ; + double dToler = 20 * EPS_SMALL ; + LuaGetParam( L, 4, dToler) ; LuaClearStack( L) ; // eseguo l'intersezione int nPntCount = 0 ; int nCrvCount = 0 ; int nSrfCount = 0 ; - int nNewId = ExeSurfTmSurfTmInters( nId1, nId2, nDestGrpId, &nPntCount, &nCrvCount, &nSrfCount) ; + int nNewId = ExeSurfTmSurfTmInters( nId1, nId2, nDestGrpId, dToler, &nPntCount, &nCrvCount, &nSrfCount) ; // restituisco il risultato if ( nNewId != GDB_ID_NULL) LuaSetParam( L, nNewId) ;