//---------------------------------------------------------------------------- // EgalTech 2024-2024 //---------------------------------------------------------------------------- // File : EXE_TestObjSurface.cpp Data : 24.03.24 Versione : 2.6c2 // Contenuto : Funzioni per verificare collisioni tra // Objects e Superfici (TriMesh). // // // Modifiche : 09.01.20 DS Creazione modulo. // // //---------------------------------------------------------------------------- //--------------------------- Include ---------------------------------------- #include "stdafx.h" #include "EXE.h" #include "EXE_Macro.h" #include "EXE_Const.h" #include "AuxTools.h" #include "GeoTools.h" #include "/EgtDev/Include/EXeExecutor.h" #include "/EgtDev/Include/EXeConst.h" #include "/EgtDev/Include/EGkCDeBoxClosedSurfTm.h" #include "/EgtDev/Include/EGkCDeRectPrismoidClosedSurfTm.h" #include "/EgtDev/Include/EGkCDeCylClosedSurfTm.h" #include "/EgtDev/Include/EGkCDeConeFrustumClosedSurfTm.h" #include "/EgtDev/Include/EGkCDeSpheClosedSurfTm.h" #include "/EgtDev/Include/EGkCDeClosedSurfTmClosedSurfTm.h" #include "/EgtDev/Include/EGkSurfLocal.h" #include "/EgtDev/Include/EGkStringUtils3d.h" using namespace std ; //---------------------------------------------------------------------------- static int MyTestBoxSurfTm( const Frame3d& frBox, const Vector3d& vtDiag, int nSurfTmId, double dSafeDist, int nRefType) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, -1) // recupero la superficie TriMesh const ISurfTriMesh* pStm = GetSurfTriMesh( pGeomDB->GetGeoObj( nSurfTmId)) ; if ( pStm == nullptr) return -1 ; // recupero il riferimento della superficie Frame3d frSurf ; if ( ! pGeomDB->GetGlobFrame( nSurfTmId, frSurf)) return -1 ; // porto in locale alla superficie il riferimento del box (il vettore è già in questo stesso riferimento) Frame3d frBoxL = GetFrameLocal( pGeomDB, frBox, nRefType, frSurf) ; // verifico l'a collisione'interferenza return ( TestBoxSurfTm( frBoxL, vtDiag, *pStm, dSafeDist) ? 1 : 0) ; } //---------------------------------------------------------------------------- int ExeTestBoxSurface( const Frame3d& frBox, const Vector3d& vtDiag, int nSurfId, double dSafeDist, int nRefType) { IGeomDB* pGeomDB = GetCurrGeomDB() ; int nRes = -1 ; if ( pGeomDB != nullptr && pGeomDB->GetGeoType( nSurfId) == SRF_TRIMESH) nRes = MyTestBoxSurfTm( frBox, vtDiag, nSurfId, dSafeDist, nRefType) ; // è da aggiungere il test con le superfici di Bezier // se richiesto, salvo il comando Lua equivalente if ( IsCmdLog()) { string sLua = "EgtTestBoxSurface({{" + ToString( frBox.Orig()) + "},{" + ToString( frBox.VersX()) + "},{" + ToString( frBox.VersY()) + "},{" + ToString( frBox.VersZ()) + "}},{" + ToString( vtDiag) + "}," + IdToString( nSurfId) + "," + ToString( dSafeDist) + "," + RefTypeToString( nRefType) + ")" + " -- Res=" + ToString( nRes) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; } // restituisco risultato return nRes ; } //---------------------------------------------------------------------------- static int MyTestRectPrismoidSurfTm( const Frame3d& frPrismoid, double dBaseLenX, double dBaseLenY, double dTopLenX, double dTopLenY, double dHeight, int nSurfTmId, double dSafeDist, int nRefType) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, -1) // recupero la superficie TriMesh const ISurfTriMesh* pStm = GetSurfTriMesh( pGeomDB->GetGeoObj( nSurfTmId)) ; if ( pStm == nullptr) return -1 ; // recupero il riferimento della superficie Frame3d frSurf ; if ( ! pGeomDB->GetGlobFrame( nSurfTmId, frSurf)) return -1 ; // porto in locale alla superficie il riferimento del prismoide rettangolare Frame3d frPrismoidL = GetFrameLocal( pGeomDB, frPrismoid, nRefType, frSurf) ; // verifico l'a collisione'interferenza return ( TestRectPrismoidSurfTm( frPrismoidL, dBaseLenX, dBaseLenY, dTopLenX, dTopLenY, dHeight, *pStm, dSafeDist) ? 1 : 0) ; } //---------------------------------------------------------------------------- int ExeTestRectPrismoidSurface( const Frame3d& frPrismoid, double dBaseLenX, double dBaseLenY, double dTopLenX, double dTopLenY, double dHeight, int nSurfId, double dSafeDist, int nRefType) { IGeomDB* pGeomDB = GetCurrGeomDB() ; int nRes = -1 ; if ( pGeomDB != nullptr && pGeomDB->GetGeoType( nSurfId) == SRF_TRIMESH) nRes = MyTestRectPrismoidSurfTm( frPrismoid, dBaseLenX, dBaseLenY, dTopLenX, dTopLenY, dHeight, nSurfId, dSafeDist, nRefType) ; // è da aggiungere il test con le superfici di Bezier // se richiesto, salvo il comando Lua equivalente if ( IsCmdLog()) { string sLua = "EgtTestRectPrismoidSurface({{" + ToString( frPrismoid.Orig()) + "},{" + ToString( frPrismoid.VersX()) + "},{" + ToString( frPrismoid.VersY()) + "},{" + ToString( frPrismoid.VersZ()) + "}}," + ToString( dBaseLenX) + "," + ToString( dBaseLenY) + "," + ToString( dTopLenX) + "," + ToString( dTopLenY) + "," + ToString( dHeight) + "," + IdToString( nSurfId) + "," + ToString( dSafeDist) + "," + RefTypeToString( nRefType) + ")" + " -- Res=" + ToString( nRes) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; } // restituisco risultato return nRes ; } //---------------------------------------------------------------------------- static int MyTestCylSurfTm( const Frame3d& frCyl, double dR, double dH, int nSurfTmId, double dSafeDist, int nRefType) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, -1) // recupero la superficie TriMesh const ISurfTriMesh* pStm = GetSurfTriMesh( pGeomDB->GetGeoObj( nSurfTmId)) ; if ( pStm == nullptr) return -1 ; // recupero il riferimento della superficie Frame3d frSurf ; if ( ! pGeomDB->GetGlobFrame( nSurfTmId, frSurf)) return -1 ; // porto in locale alla superficie il riferimento del cilindro Frame3d frCylL = GetFrameLocal( pGeomDB, frCyl, nRefType, frSurf) ; // verifico l'interferenza return ( TestCylSurfTm( frCylL, dR, dH, *pStm, dSafeDist) ? 1 : 0) ; } //---------------------------------------------------------------------------- int ExeTestCylSurface( const Frame3d& frCyl, double dR, double dH, int nSurfId, double dSafeDist, int nRefType) { IGeomDB* pGeomDB = GetCurrGeomDB() ; int nRes = -1 ; if ( pGeomDB != nullptr && pGeomDB->GetGeoType( nSurfId) == SRF_TRIMESH) nRes = MyTestCylSurfTm( frCyl, dR, dH, nSurfId, dSafeDist, nRefType) ; // è da aggiungere il test con le superfici di Bezier // se richiesto, salvo il comando Lua equivalente if ( IsCmdLog()) { string sLua = "EgtTestCylSurface({{" + ToString( frCyl.Orig()) + "},{" + ToString( frCyl.VersX()) + "},{" + ToString( frCyl.VersY()) + "},{" + ToString( frCyl.VersZ()) + "}}," + ToString( dR) + "," + ToString( dH) + "," + IdToString( nSurfId) + "," + ToString( dSafeDist) + "," + RefTypeToString( nRefType) + ")" + " -- Res=" + ToString( nRes) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; } // restituisco risultato return nRes ; } //---------------------------------------------------------------------------- static int MyTestConeSurfTm( const Frame3d& frCone, double dR1, double dR2, double dH, int nSurfTmId, double dSafeDist, int nRefType) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, -1) // recupero la superficie TriMesh const ISurfTriMesh* pStm = GetSurfTriMesh( pGeomDB->GetGeoObj( nSurfTmId)) ; if ( pStm == nullptr) return -1 ; // recupero il riferimento della superficie Frame3d frSurf ; if ( ! pGeomDB->GetGlobFrame( nSurfTmId, frSurf)) return -1 ; // porto in locale alla superficie il riferimento del cilindro Frame3d frConeL = GetFrameLocal( pGeomDB, frCone, nRefType, frSurf) ; // verifico l'interferenza return ( TestConeFrustumSurfTm( frConeL, dR1, dR2, dH, *pStm, dSafeDist) ? 1 : 0) ; } //---------------------------------------------------------------------------- int ExeTestConeSurface( const Frame3d& frCone, double dR1, double dR2, double dH, int nSurfId, double dSafeDist, int nRefType) { IGeomDB* pGeomDB = GetCurrGeomDB() ; int nRes = -1 ; if ( pGeomDB != nullptr && pGeomDB->GetGeoType( nSurfId) == SRF_TRIMESH) nRes = MyTestConeSurfTm( frCone, dR1, dR2, dH, nSurfId, dSafeDist, nRefType) ; // è da aggiungere il test con le superfici di Bezier // se richiesto, salvo il comando Lua equivalente if ( IsCmdLog()) { string sLua = "EgtTestConeSurface({{" + ToString( frCone.Orig()) + "},{" + ToString( frCone.VersX()) + "},{" + ToString( frCone.VersY()) + "},{" + ToString( frCone.VersZ()) + "}}," + ToString( dR1) + "," + ToString( dR2) + "," + ToString( dH) + "," + IdToString( nSurfId) + "," + ToString( dSafeDist) + "," + RefTypeToString( nRefType) + ")" + " -- Res=" + ToString( nRes) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; } // restituisco risultato return nRes ; } //---------------------------------------------------------------------------- static int MyTestSpheSurfTm( const Point3d& ptCen, double dR, int nSurfTmId, double dSafeDist, int nRefType) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, -1) // recupero la superficie TriMesh const ISurfTriMesh* pStm = GetSurfTriMesh( pGeomDB->GetGeoObj( nSurfTmId)) ; if ( pStm == nullptr) return -1 ; // recupero il riferimento della superficie Frame3d frSurf ; if ( ! pGeomDB->GetGlobFrame( nSurfTmId, frSurf)) return -1 ; // porto in locale alla superficie il centro della sfera Point3d ptCenL = GetPointLocal( pGeomDB, ptCen, nRefType, frSurf) ; // verifico l'interferenza return ( TestSpheSurfTm( ptCenL, dR, *pStm, dSafeDist) ? 1 : 0) ; } //---------------------------------------------------------------------------- int ExeTestSpheSurface( const Point3d& ptCen, double dR, int nSurfId, double dSafeDist, int nRefType) { IGeomDB* pGeomDB = GetCurrGeomDB() ; int nRes = -1 ; if ( pGeomDB != nullptr && pGeomDB->GetGeoType( nSurfId) == SRF_TRIMESH) nRes = MyTestSpheSurfTm( ptCen, dR, nSurfId, dSafeDist, nRefType) ; // è da aggiungere il test con le superfici di Bezier // se richiesto, salvo il comando Lua equivalente if ( IsCmdLog()) { string sLua = "EgtTestSpheSurface({" + ToString( ptCen) + "}," + ToString( dR) + "," + IdToString( nSurfId) + "," + ToString( dSafeDist) + "," + RefTypeToString( nRefType) + ")" + " -- Res=" + ToString( nRes) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; } // restituisco risultato return nRes ; } //---------------------------------------------------------------------------- static int MyTestSurfTmSurfTm( int nSurfTm1Id, int nSurfTm2Id, double dSafeDist, bool bTestEnclosion) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, -1) // recupero il riferimento della seconda superficie Frame3d frSurf2 ; if ( ! pGeomDB->GetGlobFrame( nSurfTm2Id, frSurf2)) return -1 ; // recupero la prima superficie in locale alla seconda SurfLocal Surf1Loc( pGeomDB, nSurfTm1Id, frSurf2) ; const ISurfTriMesh* pStm1 = GetSurfTriMesh( Surf1Loc) ; if ( pStm1 == nullptr) return -1 ; // recupero la seconda superficie TriMesh const ISurfTriMesh* pStm2 = GetSurfTriMesh( pGeomDB->GetGeoObj( nSurfTm2Id)) ; if ( pStm2 == nullptr) return -1 ; // verifico l'interferenza return ( TestSurfTmSurfTm( *pStm1, *pStm2, dSafeDist, bTestEnclosion) ? 1 : 0) ; } //---------------------------------------------------------------------------- int ExeTestSurfaceSurface( int nSurf1Id, int nSurf2Id, double dSafeDist, bool bTestEnclosion) { IGeomDB* pGeomDB = GetCurrGeomDB() ; int nRes = -1 ; if ( pGeomDB != nullptr) { if ( pGeomDB->GetGeoType( nSurf1Id) == SRF_TRIMESH && pGeomDB->GetGeoType( nSurf2Id) == SRF_TRIMESH) nRes = MyTestSurfTmSurfTm( nSurf1Id, nSurf2Id, dSafeDist, bTestEnclosion) ; // è da aggiungere il test con le superfici di Bezier } // se richiesto, salvo il comando Lua equivalente if ( IsCmdLog()) { string sLua = "EgtTestSurfaceSurface({" + IdToString( nSurf1Id) + "," + IdToString( nSurf2Id) + "," + ToString( dSafeDist) + "," + ( bTestEnclosion ? "true" : "false") + ")" + " -- Res=" + ToString( nRes) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; } // restituisco risultato return nRes ; }